netfilter: Use nf_hook_state.net
authorEric W. Biederman <ebiederm@xmission.com>
Wed, 16 Sep 2015 01:04:17 +0000 (20:04 -0500)
committerDavid S. Miller <davem@davemloft.net>
Fri, 18 Sep 2015 00:18:37 +0000 (17:18 -0700)
Instead of saying "net = dev_net(state->in?state->in:state->out)"
just say "state->net".  As that information is now availabe,
much less confusing and much less error prone.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
21 files changed:
net/bridge/netfilter/ebtable_filter.c
net/bridge/netfilter/ebtable_nat.c
net/ipv4/netfilter/arptable_filter.c
net/ipv4/netfilter/ip_tables.c
net/ipv4/netfilter/ipt_CLUSTERIP.c
net/ipv4/netfilter/ipt_SYNPROXY.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/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
net/ipv6/netfilter/ip6_tables.c
net/ipv6/netfilter/ip6t_SYNPROXY.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
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c
net/netfilter/nfnetlink_queue_core.c

index 8a3f63b2e8073d8081df5fbaac3bf63c348c0447..ab20d6ed6e2f9a693cef4f1f017ad9d55637130c 100644 (file)
@@ -61,7 +61,7 @@ ebt_in_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
            const struct nf_hook_state *state)
 {
        return ebt_do_table(ops->hooknum, skb, state->in, state->out,
-                           dev_net(state->in)->xt.frame_filter);
+                           state->net->xt.frame_filter);
 }
 
 static unsigned int
@@ -69,7 +69,7 @@ ebt_out_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
             const struct nf_hook_state *state)
 {
        return ebt_do_table(ops->hooknum, skb, state->in, state->out,
-                           dev_net(state->out)->xt.frame_filter);
+                           state->net->xt.frame_filter);
 }
 
 static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
index c5ef5b1ab6786814830983d76ef46c6fd0051f51..ad81a5a65644ef23af545d5375beae883b60c9c3 100644 (file)
@@ -61,7 +61,7 @@ ebt_nat_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
           const struct nf_hook_state *state)
 {
        return ebt_do_table(ops->hooknum, skb, state->in, state->out,
-                           dev_net(state->in)->xt.frame_nat);
+                           state->net->xt.frame_nat);
 }
 
 static unsigned int
@@ -69,7 +69,7 @@ ebt_nat_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
            const struct nf_hook_state *state)
 {
        return ebt_do_table(ops->hooknum, skb, state->in, state->out,
-                           dev_net(state->out)->xt.frame_nat);
+                           state->net->xt.frame_nat);
 }
 
 static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
index 93876d03120ca85fbc1e5aaa689d245d4508f01e..d217e4c196454e45e91eb1bf472614d3756961ca 100644 (file)
@@ -30,10 +30,8 @@ static unsigned int
 arptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       const struct net *net = dev_net(state->in ? state->in : state->out);
-
        return arpt_do_table(skb, ops->hooknum, state,
-                            net->ipv4.arptable_filter);
+                            state->net->ipv4.arptable_filter);
 }
 
 static struct nf_hook_ops *arpfilter_ops __read_mostly;
index b0a86e73451c1f2ee99e209eb8a6556414b02e46..5d514eac4c3131c1327f3561ac607fbf6fe52517 100644 (file)
@@ -246,7 +246,8 @@ get_chainname_rulenum(const struct ipt_entry *s, const struct ipt_entry *e,
        return 0;
 }
 
-static void trace_packet(const struct sk_buff *skb,
+static void trace_packet(struct net *net,
+                        const struct sk_buff *skb,
                         unsigned int hook,
                         const struct net_device *in,
                         const struct net_device *out,
@@ -258,7 +259,6 @@ static void trace_packet(const struct sk_buff *skb,
        const char *hookname, *chainname, *comment;
        const struct ipt_entry *iter;
        unsigned int rulenum = 0;
-       struct net *net = dev_net(in ? in : out);
 
        root = get_entry(private->entries, private->hook_entry[hook]);
 
@@ -378,8 +378,8 @@ ipt_do_table(struct sk_buff *skb,
 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
                /* The packet is traced: log it */
                if (unlikely(skb->nf_trace))
-                       trace_packet(skb, hook, state->in, state->out,
-                                    table->name, private, e);
+                       trace_packet(state->net, skb, hook, state->in,
+                                    state->out, table->name, private, e);
 #endif
                /* Standard target? */
                if (!t->u.kernel.target->target) {
index 45cb16a6a4a337c564d880485c45ca46229cb152..69157d8eba953bb7c175ecf57eebd789f6a91b3e 100644 (file)
@@ -514,7 +514,7 @@ arp_mangle(const struct nf_hook_ops *ops,
        struct arphdr *arp = arp_hdr(skb);
        struct arp_payload *payload;
        struct clusterip_config *c;
-       struct net *net = dev_net(state->in ? state->in : state->out);
+       struct net *net = state->net;
 
        /* we don't care about non-ethernet and non-ipv4 ARP */
        if (arp->ar_hrd != htons(ARPHRD_ETHER) ||
index 95ea633e8356eb9b419e4027f9954810194aa23c..f471a0628c7507be9bdc003305031913b278934a 100644 (file)
@@ -303,7 +303,7 @@ static unsigned int ipv4_synproxy_hook(const struct nf_hook_ops *ops,
                                       struct sk_buff *skb,
                                       const struct nf_hook_state *nhs)
 {
-       struct synproxy_net *snet = synproxy_pernet(dev_net(nhs->in ? : nhs->out));
+       struct synproxy_net *snet = synproxy_pernet(nhs->net);
        enum ip_conntrack_info ctinfo;
        struct nf_conn *ct;
        struct nf_conn_synproxy *synproxy;
index a0f3beca52d2107b12ae748a4328d5491e7553c3..32feff32b116f92eb0526b4bc764d75e763dc1f1 100644 (file)
@@ -36,16 +36,14 @@ static unsigned int
 iptable_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                    const struct nf_hook_state *state)
 {
-       const struct net *net;
-
        if (ops->hooknum == NF_INET_LOCAL_OUT &&
            (skb->len < sizeof(struct iphdr) ||
             ip_hdrlen(skb) < sizeof(struct iphdr)))
                /* root is playing with raw sockets. */
                return NF_ACCEPT;
 
-       net = dev_net(state->in ? state->in : state->out);
-       return ipt_do_table(skb, ops->hooknum, state, net->ipv4.iptable_filter);
+       return ipt_do_table(skb, ops->hooknum, state,
+                           state->net->ipv4.iptable_filter);
 }
 
 static struct nf_hook_ops *filter_ops __read_mostly;
index 62cbb8c5f4a8f246428599186e0e9b498ae460a6..4a5150fc9510ff617ab41998862a1495518e90cc 100644 (file)
@@ -39,7 +39,6 @@ static const struct xt_table packet_mangler = {
 static unsigned int
 ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
 {
-       struct net_device *out = state->out;
        unsigned int ret;
        const struct iphdr *iph;
        u_int8_t tos;
@@ -60,7 +59,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
        tos = iph->tos;
 
        ret = ipt_do_table(skb, NF_INET_LOCAL_OUT, state,
-                          dev_net(out)->ipv4.iptable_mangle);
+                          state->net->ipv4.iptable_mangle);
        /* Reroute for ANY change. */
        if (ret != NF_DROP && ret != NF_STOLEN) {
                iph = ip_hdr(skb);
@@ -88,10 +87,10 @@ iptable_mangle_hook(const struct nf_hook_ops *ops,
                return ipt_mangle_out(skb, state);
        if (ops->hooknum == NF_INET_POST_ROUTING)
                return ipt_do_table(skb, ops->hooknum, state,
-                                   dev_net(state->out)->ipv4.iptable_mangle);
+                                   state->net->ipv4.iptable_mangle);
        /* PREROUTING/INPUT/FORWARD: */
        return ipt_do_table(skb, ops->hooknum, state,
-                           dev_net(state->in)->ipv4.iptable_mangle);
+                           state->net->ipv4.iptable_mangle);
 }
 
 static struct nf_hook_ops *mangle_ops __read_mostly;
index 0d4d9cdf98a4c0dcb2da3fbebe9264efeb99d4c7..4f4c64f81169ccea09f147834b5864d8ecdd08ee 100644 (file)
@@ -33,9 +33,8 @@ static unsigned int iptable_nat_do_chain(const struct nf_hook_ops *ops,
                                         const struct nf_hook_state *state,
                                         struct nf_conn *ct)
 {
-       struct net *net = nf_ct_net(ct);
-
-       return ipt_do_table(skb, ops->hooknum, state, net->ipv4.nat_table);
+       return ipt_do_table(skb, ops->hooknum, state,
+                           state->net->ipv4.nat_table);
 }
 
 static unsigned int iptable_nat_ipv4_fn(const struct nf_hook_ops *ops,
index 0356e6da4bb749ba1dcfa07667dcac7b0aa92878..20126e469ffb41f547c0d13f3d69ba30f601281c 100644 (file)
@@ -23,16 +23,14 @@ static unsigned int
 iptable_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                 const struct nf_hook_state *state)
 {
-       const struct net *net;
-
        if (ops->hooknum == NF_INET_LOCAL_OUT &&
            (skb->len < sizeof(struct iphdr) ||
             ip_hdrlen(skb) < sizeof(struct iphdr)))
                /* root is playing with raw sockets. */
                return NF_ACCEPT;
 
-       net = dev_net(state->in ? state->in : state->out);
-       return ipt_do_table(skb, ops->hooknum, state, net->ipv4.iptable_raw);
+       return ipt_do_table(skb, ops->hooknum, state,
+                           state->net->ipv4.iptable_raw);
 }
 
 static struct nf_hook_ops *rawtable_ops __read_mostly;
index 4bce3980ccd935f891c55329c127478dc031ed77..82fefd609b85b3130583c4477cc51a34f0e6e458 100644 (file)
@@ -40,17 +40,14 @@ static unsigned int
 iptable_security_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                      const struct nf_hook_state *state)
 {
-       const struct net *net;
-
        if (ops->hooknum == NF_INET_LOCAL_OUT &&
            (skb->len < sizeof(struct iphdr) ||
             ip_hdrlen(skb) < sizeof(struct iphdr)))
                /* Somebody is playing with raw sockets. */
                return NF_ACCEPT;
 
-       net = dev_net(state->in ? state->in : state->out);
        return ipt_do_table(skb, ops->hooknum, state,
-                           net->ipv4.iptable_security);
+                           state->net->ipv4.iptable_security);
 }
 
 static struct nf_hook_ops *sectbl_ops __read_mostly;
index 8a2caaf3940bedaa9abba13352594a29341d287e..9564684876c9729d5cf27cb7370d3d6b56afcbc7 100644 (file)
@@ -147,7 +147,7 @@ static unsigned int ipv4_conntrack_in(const struct nf_hook_ops *ops,
                                      struct sk_buff *skb,
                                      const struct nf_hook_state *state)
 {
-       return nf_conntrack_in(dev_net(state->in), PF_INET, ops->hooknum, skb);
+       return nf_conntrack_in(state->net, PF_INET, ops->hooknum, skb);
 }
 
 static unsigned int ipv4_conntrack_local(const struct nf_hook_ops *ops,
@@ -158,7 +158,7 @@ static unsigned int ipv4_conntrack_local(const struct nf_hook_ops *ops,
        if (skb->len < sizeof(struct iphdr) ||
            ip_hdrlen(skb) < sizeof(struct iphdr))
                return NF_ACCEPT;
-       return nf_conntrack_in(dev_net(state->out), PF_INET, ops->hooknum, skb);
+       return nf_conntrack_in(state->net, PF_INET, ops->hooknum, skb);
 }
 
 /* Connection tracking may drop packets, but never alters them, so
index 0771991ed812aebef403e60ace6e7df1dd6f550c..cd9b401231d30c5304d3c753631d45ef42786e23 100644 (file)
@@ -275,7 +275,8 @@ get_chainname_rulenum(const struct ip6t_entry *s, const struct ip6t_entry *e,
        return 0;
 }
 
-static void trace_packet(const struct sk_buff *skb,
+static void trace_packet(struct net *net,
+                        const struct sk_buff *skb,
                         unsigned int hook,
                         const struct net_device *in,
                         const struct net_device *out,
@@ -287,7 +288,6 @@ static void trace_packet(const struct sk_buff *skb,
        const char *hookname, *chainname, *comment;
        const struct ip6t_entry *iter;
        unsigned int rulenum = 0;
-       struct net *net = dev_net(in ? in : out);
 
        root = get_entry(private->entries, private->hook_entry[hook]);
 
@@ -401,8 +401,8 @@ ip6t_do_table(struct sk_buff *skb,
 #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
                /* The packet is traced: log it */
                if (unlikely(skb->nf_trace))
-                       trace_packet(skb, hook, state->in, state->out,
-                                    table->name, private, e);
+                       trace_packet(state->net, skb, hook, state->in,
+                                    state->out, table->name, private, e);
 #endif
                /* Standard target? */
                if (!t->u.kernel.target->target) {
index 1e4bf99ed16e68c68ca87e997895f66dbca4e789..4c9f3e79d75f1185d5ccec41184fec1b9ae4f83f 100644 (file)
@@ -320,7 +320,7 @@ static unsigned int ipv6_synproxy_hook(const struct nf_hook_ops *ops,
                                       struct sk_buff *skb,
                                       const struct nf_hook_state *nhs)
 {
-       struct synproxy_net *snet = synproxy_pernet(dev_net(nhs->in ? : nhs->out));
+       struct synproxy_net *snet = synproxy_pernet(nhs->net);
        enum ip_conntrack_info ctinfo;
        struct nf_conn *ct;
        struct nf_conn_synproxy *synproxy;
index 5c33d8abc0774e52a99c20273f3349b0b5374fc7..2449005fb5dc896667740a86f5daa3b643e4bac7 100644 (file)
@@ -35,9 +35,8 @@ static unsigned int
 ip6table_filter_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                     const struct nf_hook_state *state)
 {
-       const struct net *net = dev_net(state->in ? state->in : state->out);
-
-       return ip6t_do_table(skb, ops->hooknum, state, net->ipv6.ip6table_filter);
+       return ip6t_do_table(skb, ops->hooknum, state,
+                            state->net->ipv6.ip6table_filter);
 }
 
 static struct nf_hook_ops *filter_ops __read_mostly;
index b551f5b79fe2b7fa62278ae1f7d9327e82795253..a46dbf097d29ce5b41a496310e90dac9d29301d4 100644 (file)
@@ -58,7 +58,7 @@ ip6t_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state)
        flowlabel = *((u_int32_t *)ipv6_hdr(skb));
 
        ret = ip6t_do_table(skb, NF_INET_LOCAL_OUT, state,
-                           dev_net(state->out)->ipv6.ip6table_mangle);
+                           state->net->ipv6.ip6table_mangle);
 
        if (ret != NF_DROP && ret != NF_STOLEN &&
            (!ipv6_addr_equal(&ipv6_hdr(skb)->saddr, &saddr) ||
@@ -83,10 +83,10 @@ ip6table_mangle_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                return ip6t_mangle_out(skb, state);
        if (ops->hooknum == NF_INET_POST_ROUTING)
                return ip6t_do_table(skb, ops->hooknum, state,
-                                    dev_net(state->out)->ipv6.ip6table_mangle);
+                                    state->net->ipv6.ip6table_mangle);
        /* INPUT/FORWARD */
        return ip6t_do_table(skb, ops->hooknum, state,
-                            dev_net(state->in)->ipv6.ip6table_mangle);
+                            state->net->ipv6.ip6table_mangle);
 }
 
 static struct nf_hook_ops *mangle_ops __read_mostly;
index c3a7f7af0ed4d183d00a5f50307f44fa44399460..a56451de127f1ccaef91605c42eb7be2a1c2c2f2 100644 (file)
@@ -35,9 +35,8 @@ static unsigned int ip6table_nat_do_chain(const struct nf_hook_ops *ops,
                                          const struct nf_hook_state *state,
                                          struct nf_conn *ct)
 {
-       struct net *net = nf_ct_net(ct);
-
-       return ip6t_do_table(skb, ops->hooknum, state, net->ipv6.ip6table_nat);
+       return ip6t_do_table(skb, ops->hooknum, state,
+                            state->net->ipv6.ip6table_nat);
 }
 
 static unsigned int ip6table_nat_fn(const struct nf_hook_ops *ops,
index 0b33caad2b69254e29af5ff38484e37a0dc6c711..18e831e35782b37827d0909c8104f63480d4fe74 100644 (file)
@@ -22,9 +22,8 @@ static unsigned int
 ip6table_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                  const struct nf_hook_state *state)
 {
-       const struct net *net = dev_net(state->in ? state->in : state->out);
-
-       return ip6t_do_table(skb, ops->hooknum, state, net->ipv6.ip6table_raw);
+       return ip6t_do_table(skb, ops->hooknum, state,
+                            state->net->ipv6.ip6table_raw);
 }
 
 static struct nf_hook_ops *rawtable_ops __read_mostly;
index fcef83c25f7b3281a92a2d5be27512e057dddfff..83bc96ae5d73845d8f6871c142168437623af61a 100644 (file)
@@ -39,10 +39,8 @@ static unsigned int
 ip6table_security_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
                       const struct nf_hook_state *state)
 {
-       const struct net *net = dev_net(state->in ? state->in : state->out);
-
        return ip6t_do_table(skb, ops->hooknum, state,
-                            net->ipv6.ip6table_security);
+                            state->net->ipv6.ip6table_security);
 }
 
 static struct nf_hook_ops *sectbl_ops __read_mostly;
index 7302900c321aff58fcb7dc21794b50e04b1942d8..1ef1b79def5689b720c9ea23e1d060182569d57f 100644 (file)
@@ -169,7 +169,7 @@ static unsigned int ipv6_conntrack_in(const struct nf_hook_ops *ops,
                                      struct sk_buff *skb,
                                      const struct nf_hook_state *state)
 {
-       return nf_conntrack_in(dev_net(state->in), PF_INET6, ops->hooknum, skb);
+       return nf_conntrack_in(state->net, PF_INET6, ops->hooknum, skb);
 }
 
 static unsigned int ipv6_conntrack_local(const struct nf_hook_ops *ops,
@@ -181,7 +181,7 @@ static unsigned int ipv6_conntrack_local(const struct nf_hook_ops *ops,
                net_notice_ratelimited("ipv6_conntrack_local: packet too short\n");
                return NF_ACCEPT;
        }
-       return nf_conntrack_in(dev_net(state->out), PF_INET6, ops->hooknum, skb);
+       return nf_conntrack_in(state->net, PF_INET6, ops->hooknum, skb);
 }
 
 static struct nf_hook_ops ipv6_conntrack_ops[] __read_mostly = {
index a5cd6d90b78b16ebd0c96c4d1d426ad7aea6e86b..41583e30051b823bd401b23392875f7fd8079d45 100644 (file)
@@ -670,8 +670,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
        struct nfqnl_instance *queue;
        struct sk_buff *skb, *segs;
        int err = -ENOBUFS;
-       struct net *net = dev_net(entry->state.in ?
-                                 entry->state.in : entry->state.out);
+       struct net *net = entry->state.net;
        struct nfnl_queue_net *q = nfnl_queue_pernet(net);
 
        /* rcu_read_lock()ed by nf_hook_slow() */