]> git.karo-electronics.de Git - linux-beck.git/commitdiff
inet netfilter: Remove hook from ip6t_do_table, arp_do_table, ipt_do_table
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 18 Sep 2015 19:32:55 +0000 (14:32 -0500)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 18 Sep 2015 19:57:43 +0000 (21:57 +0200)
The values of ops->hooknum and state->hook are guaraneted to be equal
making the hook argument to ip6t_do_table, arp_do_table, and
ipt_do_table is unnecessary. Remove the unnecessary hook argument.

In the callers use state->hook instead of ops->hooknum for clarity and
to reduce the number of cachelines the callers touch.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
17 files changed:
include/linux/netfilter_arp/arp_tables.h
include/linux/netfilter_ipv4/ip_tables.h
include/linux/netfilter_ipv6/ip6_tables.h
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/arptable_filter.c
net/ipv4/netfilter/ip_tables.c
net/ipv4/netfilter/iptable_filter.c
net/ipv4/netfilter/iptable_mangle.c
net/ipv4/netfilter/iptable_nat.c
net/ipv4/netfilter/iptable_raw.c
net/ipv4/netfilter/iptable_security.c
net/ipv6/netfilter/ip6_tables.c
net/ipv6/netfilter/ip6table_filter.c
net/ipv6/netfilter/ip6table_mangle.c
net/ipv6/netfilter/ip6table_nat.c
net/ipv6/netfilter/ip6table_raw.c
net/ipv6/netfilter/ip6table_security.c

index c22a7fb8d0df08155857d8ca01ce4c67bfa01988..6f074db2f23def7befbf60dd41792e554503db6c 100644 (file)
@@ -53,7 +53,6 @@ extern struct xt_table *arpt_register_table(struct net *net,
                                            const struct arpt_replace *repl);
 extern void arpt_unregister_table(struct xt_table *table);
 extern unsigned int arpt_do_table(struct sk_buff *skb,
-                                 unsigned int hook,
                                  const struct nf_hook_state *state,
                                  struct xt_table *table);
 
index 4073510da485fbad83ba5236d7ba5794b599653a..aa598f942c01a8d549302d570d17b6fa95198569 100644 (file)
@@ -64,7 +64,6 @@ struct ipt_error {
 
 extern void *ipt_alloc_initial_table(const struct xt_table *);
 extern unsigned int ipt_do_table(struct sk_buff *skb,
-                                unsigned int hook,
                                 const struct nf_hook_state *state,
                                 struct xt_table *table);
 
index b40d2b635778372f46870d00fd06a10266359f67..0f76e5c674f9920ecc8ccb56635fa4353ea2136c 100644 (file)
@@ -30,7 +30,6 @@ extern struct xt_table *ip6t_register_table(struct net *net,
                                            const struct ip6t_replace *repl);
 extern void ip6t_unregister_table(struct net *net, struct xt_table *table);
 extern unsigned int ip6t_do_table(struct sk_buff *skb,
-                                 unsigned int hook,
                                  const struct nf_hook_state *state,
                                  struct xt_table *table);
 
index 8f87fc38ccde3a4a55dc3b2ebb8f0ec5f0ecf4c9..10eb2b297450d5204bac057292b2820e35e2b484 100644 (file)
@@ -247,10 +247,10 @@ struct arpt_entry *arpt_next_entry(const struct arpt_entry *entry)
 }
 
 unsigned int arpt_do_table(struct sk_buff *skb,
-                          unsigned int hook,
                           const struct nf_hook_state *state,
                           struct xt_table *table)
 {
+       unsigned int hook = state->hook;
        static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
        unsigned int verdict = NF_DROP;
        const struct arphdr *arp;
index d217e4c196454e45e91eb1bf472614d3756961ca..1352e12d406830ae02735a6fcddddc980942b013 100644 (file)
@@ -30,8 +30,7 @@ static unsigned int
 arptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       return arpt_do_table(skb, ops->hooknum, state,
-                            state->net->ipv4.arptable_filter);
+       return arpt_do_table(skb, state, state->net->ipv4.arptable_filter);
 }
 
 static struct nf_hook_ops *arpfilter_ops __read_mostly;
index 5d514eac4c3131c1327f3561ac607fbf6fe52517..2b049e135de81f0686bfdff49bb70fc683cd6397 100644 (file)
@@ -285,10 +285,10 @@ struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry)
 /* Returns one of the generic firewall policies, like NF_ACCEPT. */
 unsigned int
 ipt_do_table(struct sk_buff *skb,
-            unsigned int hook,
             const struct nf_hook_state *state,
             struct xt_table *table)
 {
+       unsigned int hook = state->hook;
        static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
        const struct iphdr *ip;
        /* Initializing verdict to NF_DROP keeps gcc happy. */
index 32feff32b116f92eb0526b4bc764d75e763dc1f1..02d4c5395d6ebf867b0d95ccd4bc27fb0395e8f5 100644 (file)
@@ -36,14 +36,13 @@ static unsigned int
 iptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                    const struct nf_hook_state *state)
 {
-       if (ops->hooknum == NF_INET_LOCAL_OUT &&
+       if (state->hook == NF_INET_LOCAL_OUT &&
            (skb->len < sizeof(struct iphdr) ||
             ip_hdrlen(skb) < sizeof(struct iphdr)))
                /* root is playing with raw sockets. */
                return NF_ACCEPT;
 
-       return ipt_do_table(skb, ops->hooknum, state,
-                           state->net->ipv4.iptable_filter);
+       return ipt_do_table(skb, state, state->net->ipv4.iptable_filter);
 }
 
 static struct nf_hook_ops *filter_ops __read_mostly;
index 4a5150fc9510ff617ab41998862a1495518e90cc..dc2ff6884999f97b17392b8331ae632eca376881 100644 (file)
@@ -58,8 +58,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
        daddr = iph->daddr;
        tos = iph->tos;
 
-       ret = ipt_do_table(skb, NF_INET_LOCAL_OUT, state,
-                          state->net->ipv4.iptable_mangle);
+       ret = ipt_do_table(skb, state, state->net->ipv4.iptable_mangle);
        /* Reroute for ANY change. */
        if (ret != NF_DROP && ret != NF_STOLEN) {
                iph = ip_hdr(skb);
@@ -83,14 +82,13 @@ iptable_mangle_hook(const struct nf_hook_ops *ops,
                     struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       if (ops->hooknum == NF_INET_LOCAL_OUT)
+       if (state->hook == NF_INET_LOCAL_OUT)
                return ipt_mangle_out(skb, state);
-       if (ops->hooknum == NF_INET_POST_ROUTING)
-               return ipt_do_table(skb, ops->hooknum, state,
+       if (state->hook == NF_INET_POST_ROUTING)
+               return ipt_do_table(skb, state,
                                    state->net->ipv4.iptable_mangle);
        /* PREROUTING/INPUT/FORWARD: */
-       return ipt_do_table(skb, ops->hooknum, state,
-                           state->net->ipv4.iptable_mangle);
+       return ipt_do_table(skb, state, state->net->ipv4.iptable_mangle);
 }
 
 static struct nf_hook_ops *mangle_ops __read_mostly;
index 4f4c64f81169ccea09f147834b5864d8ecdd08ee..8ff63ac1f0d6ff559165a58ec427477da77853f5 100644 (file)
@@ -33,8 +33,7 @@ static unsigned int iptable_nat_do_chain(const struct nf_hook_ops *ops,
                                         const struct nf_hook_state *state,
                                         struct nf_conn *ct)
 {
-       return ipt_do_table(skb, ops->hooknum, state,
-                           state->net->ipv4.nat_table);
+       return ipt_do_table(skb, state, state->net->ipv4.nat_table);
 }
 
 static unsigned int iptable_nat_ipv4_fn(const struct nf_hook_ops *ops,
index 20126e469ffb41f547c0d13f3d69ba30f601281c..bbb0523d87decf566c1584692f3f38a8668108a9 100644 (file)
@@ -23,14 +23,13 @@ static unsigned int
 iptable_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                 const struct nf_hook_state *state)
 {
-       if (ops->hooknum == NF_INET_LOCAL_OUT &&
+       if (state->hook == NF_INET_LOCAL_OUT &&
            (skb->len < sizeof(struct iphdr) ||
             ip_hdrlen(skb) < sizeof(struct iphdr)))
                /* root is playing with raw sockets. */
                return NF_ACCEPT;
 
-       return ipt_do_table(skb, ops->hooknum, state,
-                           state->net->ipv4.iptable_raw);
+       return ipt_do_table(skb, state, state->net->ipv4.iptable_raw);
 }
 
 static struct nf_hook_ops *rawtable_ops __read_mostly;
index 82fefd609b85b3130583c4477cc51a34f0e6e458..b92417038705b1fc52005bbbfa1a27f40a028a35 100644 (file)
@@ -40,14 +40,13 @@ static unsigned int
 iptable_security_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                      const struct nf_hook_state *state)
 {
-       if (ops->hooknum == NF_INET_LOCAL_OUT &&
+       if (state->hook == NF_INET_LOCAL_OUT &&
            (skb->len < sizeof(struct iphdr) ||
             ip_hdrlen(skb) < sizeof(struct iphdr)))
                /* Somebody is playing with raw sockets. */
                return NF_ACCEPT;
 
-       return ipt_do_table(skb, ops->hooknum, state,
-                           state->net->ipv4.iptable_security);
+       return ipt_do_table(skb, state, state->net->ipv4.iptable_security);
 }
 
 static struct nf_hook_ops *sectbl_ops __read_mostly;
index cd9b401231d30c5304d3c753631d45ef42786e23..da6446b6e3f95cf046d0661629aa5f227233f4e0 100644 (file)
@@ -314,10 +314,10 @@ ip6t_next_entry(const struct ip6t_entry *entry)
 /* Returns one of the generic firewall policies, like NF_ACCEPT. */
 unsigned int
 ip6t_do_table(struct sk_buff *skb,
-             unsigned int hook,
              const struct nf_hook_state *state,
              struct xt_table *table)
 {
+       unsigned int hook = state->hook;
        static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
        /* Initializing verdict to NF_DROP keeps gcc happy. */
        unsigned int verdict = NF_DROP;
index 2449005fb5dc896667740a86f5daa3b643e4bac7..a7327f61b90c3cc3293997fb14578308d5e310ab 100644 (file)
@@ -35,8 +35,7 @@ static unsigned int
 ip6table_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       return ip6t_do_table(skb, ops->hooknum, state,
-                            state->net->ipv6.ip6table_filter);
+       return ip6t_do_table(skb, state, state->net->ipv6.ip6table_filter);
 }
 
 static struct nf_hook_ops *filter_ops __read_mostly;
index a46dbf097d29ce5b41a496310e90dac9d29301d4..c2e061dcedf3d884094f9385a2d37a5eb7bedb5a 100644 (file)
@@ -57,8 +57,7 @@ ip6t_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
        /* flowlabel and prio (includes version, which shouldn't change either */
        flowlabel = *((u_int32_t *)ipv6_hdr(skb));
 
-       ret = ip6t_do_table(skb, NF_INET_LOCAL_OUT, state,
-                           state->net->ipv6.ip6table_mangle);
+       ret = ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
 
        if (ret != NF_DROP && ret != NF_STOLEN &&
            (!ipv6_addr_equal(&ipv6_hdr(skb)->saddr, &saddr) ||
@@ -79,14 +78,13 @@ static unsigned int
 ip6table_mangle_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       if (ops->hooknum == NF_INET_LOCAL_OUT)
+       if (state->hook == NF_INET_LOCAL_OUT)
                return ip6t_mangle_out(skb, state);
-       if (ops->hooknum == NF_INET_POST_ROUTING)
-               return ip6t_do_table(skb, ops->hooknum, state,
+       if (state->hook == NF_INET_POST_ROUTING)
+               return ip6t_do_table(skb, state,
                                     state->net->ipv6.ip6table_mangle);
        /* INPUT/FORWARD */
-       return ip6t_do_table(skb, ops->hooknum, state,
-                            state->net->ipv6.ip6table_mangle);
+       return ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
 }
 
 static struct nf_hook_ops *mangle_ops __read_mostly;
index a56451de127f1ccaef91605c42eb7be2a1c2c2f2..efa6754c4d06c06f44bafa2346196e22cc10bb3e 100644 (file)
@@ -35,8 +35,7 @@ static unsigned int ip6table_nat_do_chain(const struct nf_hook_ops *ops,
                                          const struct nf_hook_state *state,
                                          struct nf_conn *ct)
 {
-       return ip6t_do_table(skb, ops->hooknum, state,
-                            state->net->ipv6.ip6table_nat);
+       return ip6t_do_table(skb, state, state->net->ipv6.ip6table_nat);
 }
 
 static unsigned int ip6table_nat_fn(const struct nf_hook_ops *ops,
index 18e831e35782b37827d0909c8104f63480d4fe74..fac6ad7c0a7c35e19d5d6f51f28928206436e541 100644 (file)
@@ -22,8 +22,7 @@ static unsigned int
 ip6table_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                  const struct nf_hook_state *state)
 {
-       return ip6t_do_table(skb, ops->hooknum, state,
-                            state->net->ipv6.ip6table_raw);
+       return ip6t_do_table(skb, state, state->net->ipv6.ip6table_raw);
 }
 
 static struct nf_hook_ops *rawtable_ops __read_mostly;
index 83bc96ae5d73845d8f6871c142168437623af61a..96c94fc240c8b37277aebc5a245d6554aaf757dc 100644 (file)
@@ -39,8 +39,7 @@ static unsigned int
 ip6table_security_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                       const struct nf_hook_state *state)
 {
-       return ip6t_do_table(skb, ops->hooknum, state,
-                            state->net->ipv6.ip6table_security);
+       return ip6t_do_table(skb, state, state->net->ipv6.ip6table_security);
 }
 
 static struct nf_hook_ops *sectbl_ops __read_mostly;