AR8216: complement MIB counters with info in GiB / MiB / KiB
[openwrt.git] / target / linux / generic / patches-4.4 / 611-netfilter_match_bypass_default_table.patch
1 --- a/net/ipv4/netfilter/ip_tables.c
2 +++ b/net/ipv4/netfilter/ip_tables.c
3 @@ -308,6 +308,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 @@ -328,28 +355,8 @@ ipt_do_table(struct sk_buff *skb,
38         unsigned int addend;
39  
40         /* Initialization */
41 -       stackidx = 0;
42 -       ip = ip_hdr(skb);
43 -       indev = state->in ? state->in->name : nulldevname;
44 -       outdev = state->out ? state->out->name : nulldevname;
45 -       /* We handle fragments by dealing with the first fragment as
46 -        * if it was a normal packet.  All other fragments are treated
47 -        * normally, except that they will NEVER match rules that ask
48 -        * things we don't know, ie. tcp syn flag or ports).  If the
49 -        * rule is also a fragment-specific rule, non-fragments won't
50 -        * match it. */
51 -       acpar.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
52 -       acpar.thoff   = ip_hdrlen(skb);
53 -       acpar.hotdrop = false;
54 -       acpar.net     = state->net;
55 -       acpar.in      = state->in;
56 -       acpar.out     = state->out;
57 -       acpar.family  = NFPROTO_IPV4;
58 -       acpar.hooknum = hook;
59 -
60         IP_NF_ASSERT(table->valid_hooks & (1 << hook));
61         local_bh_disable();
62 -       addend = xt_write_recseq_begin();
63         private = table->private;
64         cpu        = smp_processor_id();
65         /*
66 @@ -358,6 +365,23 @@ ipt_do_table(struct sk_buff *skb,
67          */
68         smp_read_barrier_depends();
69         table_base = private->entries;
70 +
71 +       e = get_entry(table_base, private->hook_entry[hook]);
72 +       if (ipt_handle_default_rule(e, &verdict)) {
73 +               struct xt_counters *counter;
74 +
75 +               counter = xt_get_this_cpu_counter(&e->counters);
76 +               ADD_COUNTER(*counter, skb->len, 1);
77 +               local_bh_enable();
78 +               return verdict;
79 +       }
80 +
81 +       stackidx = 0;
82 +       ip = ip_hdr(skb);
83 +       indev = state->in ? state->in->name : nulldevname;
84 +       outdev = state->out ? state->out->name : nulldevname;
85 +
86 +       addend = xt_write_recseq_begin();
87         jumpstack  = (struct ipt_entry **)private->jumpstack[cpu];
88  
89         /* Switch to alternate jumpstack if we're being invoked via TEE.
90 @@ -370,7 +394,20 @@ ipt_do_table(struct sk_buff *skb,
91         if (static_key_false(&xt_tee_enabled))
92                 jumpstack += private->stacksize * __this_cpu_read(nf_skb_duplicated);
93  
94 -       e = get_entry(table_base, private->hook_entry[hook]);
95 +       /* We handle fragments by dealing with the first fragment as
96 +        * if it was a normal packet.  All other fragments are treated
97 +        * normally, except that they will NEVER match rules that ask
98 +        * things we don't know, ie. tcp syn flag or ports).  If the
99 +        * rule is also a fragment-specific rule, non-fragments won't
100 +        * match it. */
101 +       acpar.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
102 +       acpar.thoff   = ip_hdrlen(skb);
103 +       acpar.hotdrop = false;
104 +       acpar.net     = state->net;
105 +       acpar.in      = state->in;
106 +       acpar.out     = state->out;
107 +       acpar.family  = NFPROTO_IPV4;
108 +       acpar.hooknum = hook;
109  
110         pr_debug("Entering %s(hook %u), UF %p\n",
111                  table->name, hook,