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