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
6 char protocol[MAX_PROTOCOL_LEN];
8 char pattern[MAX_PATTERN_LEN];
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
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)
26 - int oldlength = master_conntrack->layer7.app_data_len;
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;
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];
48 + target[length+offset] = '\0';
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)
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;
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;
76 master_conntrack = master_ct(master_conntrack);
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)) {
84 pattern_result = match_no_append(conntrack, master_conntrack, ctinfo, master_ctinfo, info);
87 comppattern = compile_and_cache(info->pattern, info->protocol);
88 spin_unlock_bh(&list_lock);
91 + tmp_data = kmalloc(maxdatalen, GFP_ATOMIC);
93 + if (net_ratelimit())
94 + printk(KERN_ERR "layer7: out of memory in match, bailing.\n");
95 + return info->invert;
99 + add_datastr(tmp_data, 0, app_data, appdatalen);
100 + pattern_result = ((comppattern && regexec(comppattern, tmp_data)) ? 1 : 0);
104 + return (pattern_result ^ info->invert);
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) {