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 @@ -314,34 +314,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 @@ -438,7 +440,7 @@ match(const struct sk_buff *skbin,
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 @@ -466,9 +468,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_acct_packets(master_conntrack) > num_packets ||
78 - master_conntrack->layer7.app_proto) {
80 + if(!info->pkt && (total_acct_packets(master_conntrack) > num_packets ||
81 + master_conntrack->layer7.app_proto)) {
82 pattern_result = match_no_append(conntrack, master_conntrack,
83 ctinfo, master_ctinfo, info);
85 @@ -500,6 +501,25 @@ match(const struct sk_buff *skbin,
86 /* the return value gets checked later, when we're ready to use it */
87 comppattern = compile_and_cache(info->pattern, info->protocol);
90 + tmp_data = kmalloc(maxdatalen, GFP_ATOMIC);
92 + if (net_ratelimit())
93 + printk(KERN_ERR "layer7: out of memory in match, bailing.\n");
94 + return info->invert;
98 + add_datastr(tmp_data, 0, app_data, appdatalen);
99 + pattern_result = ((comppattern && regexec(comppattern, tmp_data)) ? 1 : 0);
103 + spin_unlock_bh(&l7_lock);
105 + return (pattern_result ^ info->invert);
108 /* On the first packet of a connection, allocate space for app data */
109 if(total_acct_packets(master_conntrack) == 1 && !skb->cb[0] &&
110 !master_conntrack->layer7.app_data){