upgrade layer7 to the latest version and add fixes for 2.6.21 and 2.6.22-rc - compile...
[openwrt/staging/yousong.git] / target / linux / generic-2.6 / patches-2.6.22 / 101-netfilter_layer7_pktmatch.patch
1 Index: linux-2.6.22-rc6/include/linux/netfilter_ipv4/ipt_layer7.h
2 ===================================================================
3 --- linux-2.6.22-rc6.orig/include/linux/netfilter_ipv4/ipt_layer7.h 2007-07-02 03:23:28.597194750 +0200
4 +++ linux-2.6.22-rc6/include/linux/netfilter_ipv4/ipt_layer7.h 2007-07-02 03:23:44.730203000 +0200
5 @@ -21,6 +21,7 @@
6 char protocol[MAX_PROTOCOL_LEN];
7 char invert:1;
8 char pattern[MAX_PATTERN_LEN];
9 + char pkt;
10 };
11
12 #endif /* _IPT_LAYER7_H */
13 Index: linux-2.6.22-rc6/net/ipv4/netfilter/ipt_layer7.c
14 ===================================================================
15 --- linux-2.6.22-rc6.orig/net/ipv4/netfilter/ipt_layer7.c 2007-07-02 03:23:28.609195500 +0200
16 +++ linux-2.6.22-rc6/net/ipv4/netfilter/ipt_layer7.c 2007-07-02 03:23:54.234797000 +0200
17 @@ -300,33 +300,34 @@
18 }
19
20 /* add the new app data to the conntrack. Return number of bytes added. */
21 -static int add_data(struct nf_conn * master_conntrack,
22 - char * app_data, int appdatalen)
23 +static int add_datastr(char *target, int offset, char *app_data, int len)
24 {
25 int length = 0, i;
26 - int oldlength = master_conntrack->layer7.app_data_len;
27 -
28 - // This is a fix for a race condition by Deti Fliegl. However, I'm not
29 - // clear on whether the race condition exists or whether this really
30 - // fixes it. I might just be being dense... Anyway, if it's not really
31 - // a fix, all it does is waste a very small amount of time.
32 - if(!master_conntrack->layer7.app_data) return 0;
33 + if(!target) return 0;
34
35 /* Strip nulls. Make everything lower case (our regex lib doesn't
36 do case insensitivity). Add it to the end of the current data. */
37 - for(i = 0; i < maxdatalen-oldlength-1 &&
38 - i < appdatalen; i++) {
39 + for(i = 0; i < maxdatalen-offset-1 && i < len; i++) {
40 if(app_data[i] != '\0') {
41 - master_conntrack->layer7.app_data[length+oldlength] =
42 + target[length+offset] =
43 /* the kernel version of tolower mungs 'upper ascii' */
44 isascii(app_data[i])? tolower(app_data[i]) : app_data[i];
45 length++;
46 }
47 }
48 + target[length+offset] = '\0';
49 +
50 + return length;
51 +}
52
53 - master_conntrack->layer7.app_data[length+oldlength] = '\0';
54 - master_conntrack->layer7.app_data_len = length + oldlength;
55 +/* add the new app data to the conntrack. Return number of bytes added. */
56 +static int add_data(struct nf_conn * master_conntrack,
57 + char * app_data, int appdatalen)
58 +{
59 + int length;
60
61 + length = add_datastr(master_conntrack->layer7.app_data, master_conntrack->layer7.app_data_len, app_data, appdatalen);
62 + master_conntrack->layer7.app_data_len += length;
63 return length;
64 }
65
66 @@ -343,7 +344,7 @@
67 enum ip_conntrack_info master_ctinfo, ctinfo;
68 struct nf_conn *master_conntrack;
69 struct nf_conn *conntrack;
70 - unsigned char * app_data;
71 + unsigned char *app_data, *tmp_data;
72 unsigned int pattern_result, appdatalen;
73 regexp * comppattern;
74
75 @@ -365,8 +366,8 @@
76 master_conntrack = master_ct(master_conntrack);
77
78 /* if we've classified it or seen too many packets */
79 - if(TOTAL_PACKETS > num_packets ||
80 - master_conntrack->layer7.app_proto) {
81 + if(!info->pkt && (TOTAL_PACKETS > num_packets ||
82 + master_conntrack->layer7.app_proto)) {
83
84 pattern_result = match_no_append(conntrack, master_conntrack, ctinfo, master_ctinfo, info);
85
86 @@ -396,6 +397,23 @@
87 comppattern = compile_and_cache(info->pattern, info->protocol);
88 spin_unlock_bh(&list_lock);
89
90 + if (info->pkt) {
91 + tmp_data = kmalloc(maxdatalen, GFP_ATOMIC);
92 + if(!tmp_data){
93 + if (net_ratelimit())
94 + printk(KERN_ERR "layer7: out of memory in match, bailing.\n");
95 + return info->invert;
96 + }
97 +
98 + tmp_data[0] = '\0';
99 + add_datastr(tmp_data, 0, app_data, appdatalen);
100 + pattern_result = ((comppattern && regexec(comppattern, tmp_data)) ? 1 : 0);
101 + kfree(tmp_data);
102 + tmp_data = NULL;
103 +
104 + return (pattern_result ^ info->invert);
105 + }
106 +
107 /* On the first packet of a connection, allocate space for app data */
108 write_lock(&ct_lock);
109 if(TOTAL_PACKETS == 1 && !skb->cb[0] && !master_conntrack->layer7.app_data) {