[generic]: add initial 3.13 support
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.13 / 611-netfilter_match_bypass_default_table.patch
1 --- a/net/ipv4/netfilter/ip_tables.c
2 +++ b/net/ipv4/netfilter/ip_tables.c
3 @@ -310,6 +310,33 @@ struct ipt_entry *ipt_next_entry(const s
4 return (void *)entry + entry->next_offset;
5 }
6
7 +static bool
8 +ipt_handle_default_rule(struct ipt_entry *e, unsigned int *verdict)
9 +{
10 + struct xt_entry_target *t;
11 + struct xt_standard_target *st;
12 +
13 + if (e->target_offset != sizeof(struct ipt_entry))
14 + return false;
15 +
16 + if (!(e->ip.flags & IPT_F_NO_DEF_MATCH))
17 + return false;
18 +
19 + t = ipt_get_target(e);
20 + if (t->u.kernel.target->target)
21 + return false;
22 +
23 + st = (struct xt_standard_target *) t;
24 + if (st->verdict == XT_RETURN)
25 + return false;
26 +
27 + if (st->verdict >= 0)
28 + return false;
29 +
30 + *verdict = (unsigned)(-st->verdict) - 1;
31 + return true;
32 +}
33 +
34 /* Returns one of the generic firewall policies, like NF_ACCEPT. */
35 unsigned int
36 ipt_do_table(struct sk_buff *skb,
37 @@ -334,19 +361,6 @@ ipt_do_table(struct sk_buff *skb,
38 ip = ip_hdr(skb);
39 indev = in ? in->name : nulldevname;
40 outdev = out ? out->name : nulldevname;
41 - /* We handle fragments by dealing with the first fragment as
42 - * if it was a normal packet. All other fragments are treated
43 - * normally, except that they will NEVER match rules that ask
44 - * things we don't know, ie. tcp syn flag or ports). If the
45 - * rule is also a fragment-specific rule, non-fragments won't
46 - * match it. */
47 - acpar.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
48 - acpar.thoff = ip_hdrlen(skb);
49 - acpar.hotdrop = false;
50 - acpar.in = in;
51 - acpar.out = out;
52 - acpar.family = NFPROTO_IPV4;
53 - acpar.hooknum = hook;
54
55 IP_NF_ASSERT(table->valid_hooks & (1 << hook));
56 local_bh_disable();
57 @@ -364,6 +378,26 @@ ipt_do_table(struct sk_buff *skb,
58 origptr = *stackptr;
59
60 e = get_entry(table_base, private->hook_entry[hook]);
61 + if (ipt_handle_default_rule(e, &verdict)) {
62 + ADD_COUNTER(e->counters, skb->len, 1);
63 + xt_write_recseq_end(addend);
64 + local_bh_enable();
65 + return verdict;
66 + }
67 +
68 + /* We handle fragments by dealing with the first fragment as
69 + * if it was a normal packet. All other fragments are treated
70 + * normally, except that they will NEVER match rules that ask
71 + * things we don't know, ie. tcp syn flag or ports). If the
72 + * rule is also a fragment-specific rule, non-fragments won't
73 + * match it. */
74 + acpar.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
75 + acpar.thoff = ip_hdrlen(skb);
76 + acpar.hotdrop = false;
77 + acpar.in = in;
78 + acpar.out = out;
79 + acpar.family = NFPROTO_IPV4;
80 + acpar.hooknum = hook;
81
82 pr_debug("Entering %s(hook %u); sp at %u (UF %p)\n",
83 table->name, hook, origptr,