remove linux 2.4 specific build system code
[15.05/openwrt.git] / target / linux / generic-2.6 / patches-2.6.25 / 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 @@ -314,34 +314,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 @@ -438,7 +440,7 @@ match(const struct sk_buff *skbin,
65  
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 @@ -466,9 +468,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_acct_packets(master_conntrack) > num_packets ||
78 -          master_conntrack->layer7.app_proto) {
79 -
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);
84  
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);
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 +
101 +               kfree(tmp_data);
102 +               tmp_data = NULL;
103 +               spin_unlock_bh(&l7_lock);
104 +
105 +               return (pattern_result ^ info->invert);
106 +       }
107 +
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){