From: Josh G. <ja...@us...> - 2004-09-08 09:06:34
|
Update of /cvsroot/iptables-p2p/iptables-p2p/kernel In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9344 Modified Files: main.c match_bittorrent.c match_dc.c match_edonkey.c match_http.c utils.c Log Message: major formatting cleanups Index: match_bittorrent.c =================================================================== RCS file: /cvsroot/iptables-p2p/iptables-p2p/kernel/match_bittorrent.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- match_bittorrent.c 19 Mar 2004 17:33:45 -0000 1.4 +++ match_bittorrent.c 8 Sep 2004 09:06:24 -0000 1.5 @@ -18,18 +18,22 @@ #include <linux/module.h> #include <linux/string.h> +/*****************************************************************************/ #define SIZE_MIN (20) #define SIZE_MAX (500) +/*****************************************************************************/ + const unsigned char bittorrent_string[] = "\x13" "BitTorrent protocol" "\x0\x0\x0\x0\x0\x0\x0\x0"; -int -match_bittorrent(const unsigned char *data, - const unsigned char *end) +/*****************************************************************************/ + +int match_bittorrent(const unsigned char *data, + const unsigned char *end) { /* Only match if the header is within a certain size range, for efficiency purposes. */ Index: match_edonkey.c =================================================================== RCS file: /cvsroot/iptables-p2p/iptables-p2p/kernel/match_edonkey.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- match_edonkey.c 7 Dec 2003 06:53:31 -0000 1.4 +++ match_edonkey.c 8 Sep 2004 09:06:24 -0000 1.5 @@ -17,10 +17,14 @@ #include <linux/config.h> #include <linux/module.h> +/*****************************************************************************/ + #define get_u8(X,O) (*(__u8 *)(X + O)) #define get_u16(X,O) (*(__u16 *)(X + O)) #define get_u32(X,O) (*(__u32 *)(X + O)) +/*****************************************************************************/ + #define EDONKEY_PACKET (0xe3) #define TYPE_HELLO (0x01) @@ -43,19 +47,25 @@ #define SIZE_MIN (30) #define SIZE_MAX (400) -int -match_edonkey(const unsigned char *data, - const unsigned char *end) +/*****************************************************************************/ + +int match_edonkey(const unsigned char *data, + const unsigned char *end) { int packet_len; int tag_count; int type; - if (end - data < POS_FIRSTTAG) return 0; - if (get_u8(data, POS_MAGIC) != EDONKEY_PACKET) return 0; + if (end - data < POS_FIRSTTAG) + return 0; + + if (get_u8(data, POS_MAGIC) != EDONKEY_PACKET) + return 0; + packet_len = get_u32(data, POS_LEN); - if (packet_len < SIZE_MIN || packet_len > SIZE_MAX) return 0; + if (packet_len < SIZE_MIN || packet_len > SIZE_MAX) + return 0; type = get_u8(data, POS_TYPE); @@ -65,35 +75,43 @@ return 0; tag_count = get_u32(data, POS_TAGCOUNT); - if (tag_count < 2 || tag_count >= 6) { + + if (tag_count < 2 || tag_count >= 6) + { data++; tag_count = get_u32(data, POS_TAGCOUNT); - if(tag_count < 2 || tag_count >= 6) return 0; + if (tag_count < 2 || tag_count >= 6) + return 0; } data += POS_FIRSTTAG; - while(tag_count--) { + while (tag_count--) + { int tag_type = get_u8(data, 0); int tag_len = get_u16(data, 1); data += 3 + tag_len; - if (data > end) return 0; + if (data > end) + return 0; - switch(tag_type) { + switch(tag_type) + { case TYPE_STRING: data += 2 + get_u16(data, 0); break; case TYPE_DWORD: case TYPE_FLOAT: data += 4; - if (data > end) return 0; + if (data > end) + return 0; break; default: return 0; } - if (data > end) return 0; + if (data > end) + return 0; } return 1; Index: match_dc.c =================================================================== RCS file: /cvsroot/iptables-p2p/iptables-p2p/kernel/match_dc.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- match_dc.c 19 Mar 2004 17:33:45 -0000 1.5 +++ match_dc.c 8 Sep 2004 09:06:24 -0000 1.6 @@ -20,10 +20,13 @@ #include <linux/netfilter_ipv4/ip_tables.h> +/*****************************************************************************/ #define SIZE_MIN (30) #define SIZE_MAX (200) +/*****************************************************************************/ + static const unsigned char *dc_cmd[] = { "MyNick", @@ -43,13 +46,15 @@ return NULL; } -int -match_dc(const unsigned char *data, - const unsigned char *end) +/*****************************************************************************/ + +int match_dc(const unsigned char *data, + const unsigned char *end) { - int count=0; + int count = 0; - if (end - data < SIZE_MIN || end - data > SIZE_MAX) return 0; + if (end - data < SIZE_MIN || end - data > SIZE_MAX) + return 0; while (dc_cmd[count]) { @@ -63,7 +68,7 @@ if (memcmp(data + 1, dc_cmd[count], strlen(dc_cmd[count])) != 0) return 0; - if (!(data = next_cmd(data, end))) + if ((data = next_cmd(data, end)) == NULL) return 0; count++; Index: match_http.c =================================================================== RCS file: /cvsroot/iptables-p2p/iptables-p2p/kernel/match_http.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- match_http.c 22 Jun 2004 12:43:25 -0000 1.27 +++ match_http.c 8 Sep 2004 09:06:24 -0000 1.28 @@ -29,8 +29,9 @@ /*****************************************************************************/ -#define EOH -2 /* End of Headers */ +#define EOH (-2) /* End of Headers */ +/*****************************************************************************/ static unsigned char * method_strings[] = { @@ -100,12 +101,14 @@ #define HEADERS_LEN (((sizeof(header_strings))/(sizeof(header_strings[0]))) - 1) +/*****************************************************************************/ + static treenode *methods; static treenode *headers; /*****************************************************************************/ -void init_match_http() +void init_match_http (void) { unsigned char **list; unsigned char *s; @@ -116,32 +119,35 @@ i = 0; list = method_strings; - while((s = *list++)) { + + while ((s = *list++)) + { methods = fill_strtree(s, methods, i); i++; } i = 0; list = header_strings; - while((s = *list++)) { + + while ((s = *list++)) + { headers = fill_strtree(s, headers, i); i++; } } -void destroy_match_http() +void destroy_match_http (void) { destroy_strtree(headers); destroy_strtree(methods); } -static inline const unsigned char * -next_line(const unsigned char *data, - const unsigned char *end) +static inline const unsigned char *next_line(const unsigned char *data, + const unsigned char *end) { while (data <= end) { - if (*data++ == '\n') + if (*data++ == '\n') return data; } @@ -152,9 +158,8 @@ #define MM(x) (method_matched == x) #define HM(x) headers_matched[x] -int -match_http(const unsigned char *data, - const unsigned char *end) +int match_http(const unsigned char *data, + const unsigned char *end) { unsigned int method_matched; /* Methods matched */ unsigned int headers_matched[HEADERS_LEN]; /* Headers matched */ @@ -175,14 +180,13 @@ /* Skip if end of headers */ if(*data == '\n' || *data == '\r') break; - + header = search_strtree(data, end, headers); if (header != -1) headers_matched[header] = 1; } - /* * FastTrack */ @@ -199,7 +203,6 @@ if (MM(MM_GIVE)) return IPT_P2P_PROTO_FASTTRACK; - /* * Gnutella */ @@ -225,7 +228,6 @@ /* * ARES */ - /* warez.com client */ if ((MM(MM_GET_SHA1) || MM(MM_HTTP11)) && HM(HM_X_MYLIP)) return IPT_P2P_PROTO_ARES; Index: main.c =================================================================== RCS file: /cvsroot/iptables-p2p/iptables-p2p/kernel/main.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- main.c 22 Jun 2004 12:43:24 -0000 1.16 +++ main.c 8 Sep 2004 09:06:24 -0000 1.17 @@ -21,7 +21,7 @@ #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/version.h> -#ifdef CONFIG_MODVERSIONS +#ifdef CONFIG_MODVERSIONS #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) #include <linux/modversions.h> #endif @@ -29,10 +29,14 @@ #include "ipt_p2p.h" +/*****************************************************************************/ + MODULE_AUTHOR("Filipe Almeida <fi...@rn...>"); MODULE_DESCRIPTION("IP tables P2P match module"); MODULE_LICENSE("GPL"); +/*****************************************************************************/ + /* WARNING: The return value differs from the rest of the match_ functions. */ int match_http(const unsigned char *data, const unsigned char *end); @@ -46,10 +50,11 @@ int match_bittorrent(const unsigned char *data, const unsigned char *end); -static int -match_selected(const struct ipt_p2p_info *pinfo, - const unsigned char *data, - const unsigned char *end) +/*****************************************************************************/ + +static int match_selected(const struct ipt_p2p_info *pinfo, + const unsigned char *data, + const unsigned char *end) { if (pinfo->proto & IPT_P2P_PROTO_FASTTRACK || pinfo->proto & IPT_P2P_PROTO_GNUTELLA || @@ -80,19 +85,18 @@ return 0; } -static int -match(const struct sk_buff *skb, - const struct net_device *in, - const struct net_device *out, - const void *matchinfo, - int offset, +static int match(const struct sk_buff *skb, + const struct net_device *in, + const struct net_device *out, + const void *matchinfo, + int offset, #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) - const void *hdr, - u_int16_t datalen, + const void *hdr, + u_int16_t datalen, #endif /* Linux < 2.6.0 */ - int *hotdrop) + int *hotdrop) { const struct ipt_p2p_info *pinfo = matchinfo; const struct iphdr *iph = skb->nh.iph; @@ -117,12 +121,11 @@ return match_selected(pinfo, data, end); } -static int -checkentry(const char *tablename, - const struct ipt_ip *ip, - void *matchinfo, - unsigned int matchsize, - unsigned int hook_mask) +static int checkentry(const char *tablename, + const struct ipt_ip *ip, + void *matchinfo, + unsigned int matchsize, + unsigned int hook_mask) { if (matchsize != IPT_ALIGN(sizeof(struct ipt_p2p_info))) return 0; @@ -130,7 +133,8 @@ return 1; } -static struct ipt_match p2p_match = { +static struct ipt_match p2p_match = +{ .name = "p2p", .match = &match, .checkentry = &checkentry, Index: utils.c =================================================================== RCS file: /cvsroot/iptables-p2p/iptables-p2p/kernel/utils.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- utils.c 22 Jun 2004 12:43:25 -0000 1.3 +++ utils.c 8 Sep 2004 09:06:24 -0000 1.4 @@ -22,37 +22,49 @@ #include <linux/mm.h> #include "utils.h" -treenode *fill_strtree(const unsigned char *s, treenode *t, int v) { +/*****************************************************************************/ + +treenode *fill_strtree(const unsigned char *s, treenode *t, int v) +{ unsigned char c; treenode *parent = NULL; treenode *last = t; treenode *node = t; c = *s++; - while(c) { - if(!node) { - node = (treenode *)kmalloc(sizeof(treenode), GFP_KERNEL); + + while (c) + { + if (node == NULL) + { + node = kmalloc(sizeof(treenode), GFP_KERNEL); + assert (node != NULL); + node->c = c; node->child = NULL; node->next = NULL; node->v = -1; - if(last == NULL) { + + if (last == NULL) t = node; - } else if(last == parent) { + else if (last == parent) last->child = node; - } else { + else last->next = node; - } } + last = node; - if(node->c == c) { + + if (node->c != c) + node = node->next; + else + { parent = node; node = node->child; c = *s++; - } else { - node = node->next; } } + parent->v = v; return t; @@ -60,31 +72,36 @@ int search_strtree(const unsigned char *data, const unsigned char *end, - treenode *node) { + treenode *node) +{ int c; int v = -1; - while((c = *data++)) { + + while (c = *data++)) + { if (data >= end) return -1; - while(node && c != node->c) + while (node && c != node->c) node = node->next; - if(!node) + if (node == NULL) return v; - else if(node->v != -1) + else if (node->v != -1) v = node->v; + node = node->child; } + return v; } -void destroy_strtree(treenode *t) { - if(!t) +void destroy_strtree(treenode *t) +{ + if (t == NULL) return; destroy_strtree(t->child); destroy_strtree(t->next); kfree(t); } - |