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