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];
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
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)
22 - int oldlength = master_conntrack->layer7.app_data_len;
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;
30 + if (!target) return 0;
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] =
42 tolower(app_data[i]) : app_data[i];
46 + target[length+offset] = '\0';
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)
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;
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;
73 @@ -439,8 +441,8 @@ match(const struct sk_buff *skbin,
74 master_conntrack = master_ct(master_conntrack);
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)) {
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);
89 + tmp_data = kmalloc(maxdatalen, GFP_ATOMIC);
91 + if (net_ratelimit())
92 + printk(KERN_ERR "layer7: out of memory in match, bailing.\n");
93 + return info->invert;
97 + add_datastr(tmp_data, 0, app_data, appdatalen);
98 + pattern_result = ((comppattern && regexec(comppattern, tmp_data)) ? 1 : 0);
102 + spin_unlock_bh(&l7_lock);
104 + return (pattern_result ^ info->invert);
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){