nfnetlink: add netns support
Subsystems (2)
PATCH 1/2 nfnetlink: add netns support
Make nfnetlink socket per-netns.
---
include/linux/netfilter/nfnetlink.h | 8 ++-- include/net/net_namespace.h | 2 + net/netfilter/nf_conntrack_netlink.c | 13 +++---- net/netfilter/nfnetlink.c | 65 +++++++++++++++++++++++------------ net/netfilter/nfnetlink_log.c | 2 - net/netfilter/nfnetlink_queue.c | 2 - 6 files changed, 58 insertions(+), 34 deletions(-)
include/linux/netfilter/nfnetlink.h +4 -4
@@ -73,11 +73,11 @@ struct nfnetlink_subsystem {extern int nfnetlink_subsys_register (const struct nfnetlink_subsystem *n);extern int nfnetlink_subsys_unregister (const struct nfnetlink_subsystem *n); -extern int nfnetlink_has_listeners (unsigned int group); -extern int nfnetlink_send (struct sk_buff *skb,u32 pid,unsigned group, +extern int nfnetlink_has_listeners (struct net *net,unsigned int group); +extern int nfnetlink_send (struct sk_buff *skb,struct net *net,u32 pid,unsigned group,int echo,gfp_t flags); -extern void nfnetlink_set_err (u32 pid,u32 group,int error); -extern int nfnetlink_unicast (struct sk_buff *skb,u_int32_t pid,int flags); +extern void nfnetlink_set_err (struct net *net,u32 pid,u32 group,int error); +extern int nfnetlink_unicast (struct sk_buff *skb,struct net *net,u_int32_t pid,int flags);extern void nfnl_lock (void );extern void nfnl_unlock (void );
include/net/net_namespace.h +2 -0
@@ -81,6 +81,8 @@ struct net {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )struct netns_ct ct;#endif +struct sock *nfnl; +struct sock *nfnl_stash;#endif #ifdef CONFIG_XFRM struct netns_xfrm xfrm;
net/netfilter/nf_conntrack_netlink.c +7 -6
@@ -482,7 +482,7 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) }else return 0 ; -if (!item->report && !nfnetlink_has_listeners (group)) +if (!item->report && !nfnetlink_has_listeners (&init_net, group))return 0 ; skb =nlmsg_new (ctnetlink_nlmsg_size (ct),GFP_ATOMIC );
@@ -559,7 +559,8 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)rcu_read_unlock ();nlmsg_end (skb, nlh); - err =nfnetlink_send (skb, item->pid, group, item->report,GFP_ATOMIC ); + err =nfnetlink_send (skb, &init_net, item->pid, group, item->report, +GFP_ATOMIC );if (err == -ENOBUFS || err == -EAGAIN )return -ENOBUFS ;
@@ -571,7 +572,7 @@ nla_put_failure: nlmsg_failure:kfree_skb (skb); errout: -nfnetlink_set_err (0 , group, -ENOBUFS ); +nfnetlink_set_err (&init_net,0 , group, -ENOBUFS ); return 0; }#endif /* CONFIG_NF_CONNTRACK_EVENTS */
@@ -1539,7 +1540,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)return 0 ;if (!item->report && - !nfnetlink_has_listeners (NFNLGRP_CONNTRACK_EXP_NEW )) + !nfnetlink_has_listeners (&init_net,NFNLGRP_CONNTRACK_EXP_NEW ))return 0 ; skb =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_ATOMIC );
@@ -1562,7 +1563,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)rcu_read_unlock ();nlmsg_end (skb, nlh); -nfnetlink_send (skb, item->pid,NFNLGRP_CONNTRACK_EXP_NEW , +nfnetlink_send (skb, &init_net, item->pid,NFNLGRP_CONNTRACK_EXP_NEW , item->report,GFP_ATOMIC );return 0 ;
@@ -1572,7 +1573,7 @@ nla_put_failure: nlmsg_failure:kfree_skb (skb); errout: -nfnetlink_set_err (0 ,0 , -ENOBUFS ); +nfnetlink_set_err (&init_net,0 ,0 , -ENOBUFS ); return 0; }#endif
net/netfilter/nfnetlink.c +43 -22
117 lines not on this page · raw message
net/netfilter/nfnetlink_log.c +1 -1
@@ -323,7 +323,7 @@ __nfulnl_send(struct nfulnl_instance *inst)NLMSG_DONE , sizeof(struct nfgenmsg)); - status =nfnetlink_unicast (inst->skb, inst->peer_pid,MSG_DONTWAIT ); + status =nfnetlink_unicast (inst->skb, &init_net, inst->peer_pid,MSG_DONTWAIT ); inst->qlen =0 ; inst->skb =NULL ;
net/netfilter/nfnetlink_queue.c +1 -1
@@ -420,7 +420,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) }/* nfnetlink_unicast will either free the nskb or add it to a socket */ - err =nfnetlink_unicast (nskb, queue->peer_pid,MSG_DONTWAIT ); + err =nfnetlink_unicast (nskb, &init_net, queue->peer_pid,MSG_DONTWAIT );if (err <0 ) { queue->queue_user_dropped++; goto err_out_unlock;
include/net/net_namespace.h struct net { · line 85
Quoted 10 lines · Alexey Dobriyan
Make nfnetlink socket per-netns.
include/net/net_namespace.h +2
-0@@ -81,6 +81,8 @@ struct net {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )struct netns_ct ct;#endif +struct sock *nfnl; +struct sock *nfnl_stash;
Shouldn't this be contained in an ifdef(CONFIG_NETFILTER_NETLINK) (_MODULE) ?
Quoted 9 lines
include/net/net_namespace.h +2
-3#endif +static void __net_exit nfnetlink_net_exit_batch(struct list_head *net_exit_list) { -printk ("Netfilter messages via NETLINK v%s.\n" , nfversion); +struct net *net; - nfnl =netlink_kernel_create (&init_net,NETLINK_NETFILTER ,NFNLGRP_MAX , - nfnetlink_rcv,NULL ,THIS_MODULE );
include/net/net_namespace.h struct net {
Quoted 10 lines
include/net/net_namespace.h +6
-3-if (!nfnl) { -printk (KERN_ERR "cannot initialize nfnetlink!\n" ); -return -ENOMEM ; +list_for_each_entry (net, net_exit_list, exit_list) { +rcu_assign_pointer (net->nfnl,NULL ); + } +synchronize_net (); +list_for_each_entry (net, net_exit_list, exit_list) { +netlink_kernel_release (net->nfnl_stash); }
No parenthesis around single statements please.
net/netfilter/nfnetlink_log.c __nfulnl_send(struct nfulnl_instance *inst) · line 326
Quoted 8 lines
net/netfilter/nfnetlink_log.c +1
-1@@ -323,7 +323,7 @@ __nfulnl_send(struct nfulnl_instance *inst)NLMSG_DONE , sizeof(struct nfgenmsg)); - status =nfnetlink_unicast (inst->skb, inst->peer_pid,MSG_DONTWAIT ); + status =nfnetlink_unicast (inst->skb, &init_net, inst->peer_pid,MSG_DONTWAIT );
Overly long line.
The remaining parts look good to me.
include/net/net_namespace.h struct net { · line 85
Quoted 10 lines · Alexey Dobriyan
Make nfnetlink socket per-netns.
include/net/net_namespace.h +2
-0@@ -81,6 +81,8 @@ struct net {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )struct netns_ct ct;#endif +struct sock *nfnl; +struct sock *nfnl_stash;
Shouldn't this be contained in an ifdef(CONFIG_NETFILTER_NETLINK) (_MODULE) ?
Quoted 9 lines
include/net/net_namespace.h +2
-3#endif +static void __net_exit nfnetlink_net_exit_batch(struct list_head *net_exit_list) { -printk ("Netfilter messages via NETLINK v%s.\n" , nfversion); +struct net *net; - nfnl =netlink_kernel_create (&init_net,NETLINK_NETFILTER ,NFNLGRP_MAX , - nfnetlink_rcv,NULL ,THIS_MODULE );
include/net/net_namespace.h struct net {
Quoted 10 lines
include/net/net_namespace.h +6
-3-if (!nfnl) { -printk (KERN_ERR "cannot initialize nfnetlink!\n" ); -return -ENOMEM ; +list_for_each_entry (net, net_exit_list, exit_list) { +rcu_assign_pointer (net->nfnl,NULL ); + } +synchronize_net (); +list_for_each_entry (net, net_exit_list, exit_list) { +netlink_kernel_release (net->nfnl_stash); }
No parenthesis around single statements please.
net/netfilter/nfnetlink_log.c __nfulnl_send(struct nfulnl_instance *inst) · line 326
Quoted 8 lines
net/netfilter/nfnetlink_log.c +1
-1@@ -323,7 +323,7 @@ __nfulnl_send(struct nfulnl_instance *inst)NLMSG_DONE , sizeof(struct nfgenmsg)); - status =nfnetlink_unicast (inst->skb, inst->peer_pid,MSG_DONTWAIT ); + status =nfnetlink_unicast (inst->skb, &init_net, inst->peer_pid,MSG_DONTWAIT );
Overly long line.
The remaining parts look good to me.
Quoted 7 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?
No, otherwise you won't be able to start using, e. g., nfnetlink_log module on NETFILTER_NETLINK=n kernels without reboot.
Quoted 1 line
The remaining parts look good to me.
OK, I'll resend shortly.
Quoted 7 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?
No, otherwise you won't be able to start using, e. g., nfnetlink_log module on NETFILTER_NETLINK=n kernels without reboot.
Quoted 1 line
The remaining parts look good to me.
OK, I'll resend shortly.
Quoted 10 lines · Alexey Dobriyan
Quoted 6 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.
You mean after enabling CONFIG_NETFILTER_NETLINK? That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
Quoted 3 lines
Quoted 1 line
The remaining parts look good to me.
OK, I'll resend shortly.
Thanks.
Quoted 10 lines · Alexey Dobriyan
Quoted 6 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.
You mean after enabling CONFIG_NETFILTER_NETLINK? That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
Quoted 3 lines
Quoted 1 line
The remaining parts look good to me.
OK, I'll resend shortly.
Thanks.
Quoted 9 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?
Quoted 4 lines
Quoted 2 lines
No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?
Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Quoted 9 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?
Quoted 4 lines
Quoted 2 lines
No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?
Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Quoted 12 lines · Alexey Dobriyan
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 5 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?
Quoted 7 lines
Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Yes, I don't mind much, but I still think this is not an argument at all. Whether you have to reboot after changing your configuration has never been "stable" and we don't consider it when making changes.
Quoted 12 lines · Alexey Dobriyan
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 5 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?
Quoted 7 lines
Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Yes, I don't mind much, but I still think this is not an argument at all. Whether you have to reboot after changing your configuration has never been "stable" and we don't consider it when making changes.
Quoted 18 lines · Patrick McHardy
Quoted 17 lines · Alexey Dobriyan
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 5 lines · Patrick McHardy
Review
Quoted 2 lines · Alexey Dobriyan
(quoted diff) +2
-0+ struct sock *nfnl; + struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
Quoted 6 lines
Quoted 2 lines
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Yes, I don't mind much, but I still think this is not an argument at all. Whether you have to reboot after changing your configuration has never been "stable" and we don't consider it when making changes.
Perhaps we should start considering it.
What's bool is bool and fair game.
What's tristate better be fully tristate.
Quoted 18 lines · Patrick McHardy
Quoted 17 lines · Alexey Dobriyan
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 5 lines · Patrick McHardy
include/net/net_namespace.h struct net { · line 85
Quoted 2 lines · Alexey Dobriyan
include/net/net_namespace.h +2
-0+struct sock *nfnl; +struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
Quoted 6 lines
Quoted 2 lines
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Yes, I don't mind much, but I still think this is not an argument at all. Whether you have to reboot after changing your configuration has never been "stable" and we don't consider it when making changes.
Perhaps we should start considering it.
What's bool is bool and fair game.
What's tristate better be fully tristate.
Quoted 19 lines · Alexey Dobriyan
Quoted 18 lines · Patrick McHardy
Quoted 17 lines · Alexey Dobriyan
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 5 lines · Patrick McHardy
Review
Quoted 2 lines · Alexey Dobriyan
(quoted diff) +2
-0+ struct sock *nfnl; + struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Quoted 8 lines
Quoted 3 lines
Yes, I don't mind much, but I still think this is not an argument at all. Whether you have to reboot after changing your configuration has never been "stable" and we don't consider it when making changes.
Perhaps we should start considering it.
What's bool is bool and fair game.
What's tristate better be fully tristate.
That's silly. Any configuration option is allowed to change data structure layout, at which point you'll often need to reboot.
Quoted 19 lines · Alexey Dobriyan
Quoted 18 lines · Patrick McHardy
Quoted 17 lines · Alexey Dobriyan
Quoted 10 lines · Patrick McHardy
Quoted 8 lines · Alexey Dobriyan
Quoted 5 lines · Patrick McHardy
Review
Quoted 2 lines · Alexey Dobriyan
(quoted diff) +2
-0+ struct sock *nfnl; + struct sock *nfnl_stash;Shouldn't this be contained in an
ifdef(CONFIG_NETFILTER_NETLINK)(_MODULE) ?No, otherwise you won't be able to start using, e. g.,
nfnetlink_logmodule on NETFILTER_NETLINK=n kernels without reboot.You mean after enabling
CONFIG_NETFILTER_NETLINK?Yes, and it can't be directly enabled, because it's hidden option.
Quoted 2 lines
That seems like a pretty poor argument, you have to do a reboot after changing a lot of config options.
It's still a step back if I add #ifdef and a regression if you ask me. The price is only two pointers per-netns.
Quoted 8 lines
Quoted 3 lines
Yes, I don't mind much, but I still think this is not an argument at all. Whether you have to reboot after changing your configuration has never been "stable" and we don't consider it when making changes.
Perhaps we should start considering it.
What's bool is bool and fair game.
What's tristate better be fully tristate.
That's silly. Any configuration option is allowed to change data structure layout, at which point you'll often need to reboot.