Add a driver for Atheros AR8216 switches Thanks to Vertical Communications, Inc....
[oweals/openwrt.git] / target / linux / generic-2.6 / patches-2.6.29 / 110-netfilter_match_speedup.patch
1 --- a/include/linux/netfilter_ipv4/ip_tables.h
2 +++ b/include/linux/netfilter_ipv4/ip_tables.h
3 @@ -62,6 +62,7 @@ struct ipt_ip {
4  #define IPT_F_FRAG             0x01    /* Set if rule is a fragment rule */
5  #define IPT_F_GOTO             0x02    /* Set if jump is a goto */
6  #define IPT_F_MASK             0x03    /* All possible flag bits mask. */
7 +#define IPT_F_NO_DEF_MATCH     0x80    /* Internal: no default match rules present */
8  
9  /* Values for "inv" field in struct ipt_ip. */
10  #define IPT_INV_VIA_IN         0x01    /* Invert the sense of IN IFACE. */
11 --- a/net/ipv4/netfilter/ip_tables.c
12 +++ b/net/ipv4/netfilter/ip_tables.c
13 @@ -88,6 +88,9 @@ ip_packet_match(const struct iphdr *ip,
14  
15  #define FWINV(bool, invflg) ((bool) ^ !!(ipinfo->invflags & (invflg)))
16  
17 +       if (ipinfo->flags & IPT_F_NO_DEF_MATCH)
18 +               return true;
19 +
20         if (FWINV((ip->saddr&ipinfo->smsk.s_addr) != ipinfo->src.s_addr,
21                   IPT_INV_SRCIP)
22             || FWINV((ip->daddr&ipinfo->dmsk.s_addr) != ipinfo->dst.s_addr,
23 @@ -147,13 +150,32 @@ ip_packet_match(const struct iphdr *ip,
24                 return false;
25         }
26  
27 +#undef FWINV
28         return true;
29  }
30  
31  static bool
32 -ip_checkentry(const struct ipt_ip *ip)
33 +ip_checkentry(struct ipt_ip *ip)
34  {
35 -       if (ip->flags & ~IPT_F_MASK) {
36 +#define FWINV(bool, invflg) ((bool) || (ip->invflags & (invflg)))
37 +
38 +       if (FWINV(ip->smsk.s_addr, IPT_INV_SRCIP) ||
39 +               FWINV(ip->dmsk.s_addr, IPT_INV_DSTIP))
40 +               goto has_match_rules;
41 +
42 +       if (FWINV(!!((const unsigned long *)ip->iniface_mask)[0],
43 +               IPT_INV_VIA_IN) ||
44 +           FWINV(!!((const unsigned long *)ip->outiface_mask)[0],
45 +               IPT_INV_VIA_OUT))
46 +               goto has_match_rules;
47 +
48 +       if (FWINV(ip->flags&IPT_F_FRAG, IPT_INV_FRAG))
49 +               goto has_match_rules;
50 +
51 +       ip->flags |= IPT_F_NO_DEF_MATCH;
52 +
53 +has_match_rules:
54 +       if (ip->flags & ~(IPT_F_MASK|IPT_F_NO_DEF_MATCH)) {
55                 duprintf("Unknown flag bits set: %08X\n",
56                          ip->flags & ~IPT_F_MASK);
57                 return false;
58 @@ -163,6 +185,8 @@ ip_checkentry(const struct ipt_ip *ip)
59                          ip->invflags & ~IPT_INV_MASK);
60                 return false;
61         }
62 +
63 +#undef FWINV
64         return true;
65  }
66  
67 @@ -210,7 +234,6 @@ unconditional(const struct ipt_ip *ip)
68                         return 0;
69  
70         return 1;
71 -#undef FWINV
72  }
73  
74  #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \