netlink: switch net_ns only if net is not init_net
Subsystems (3)
PATCH 1/1 netlink: switch net_ns only if net is not init_net
Many netlink users create netlink sock in the init_net, and the switching nes_ns(init_net-->net) is needless in this case. So here we add a pre-check to avoid this.
--- net/netlink/af_netlink.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
net/netlink/af_netlink.c +2 -1
@@ -2429,7 +2429,8 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module, goto out_sock_release_nosk; sk = sock->sk; -sk_change_net (sk, net); +if (!net_eq (net, &init_net)) +sk_change_net (sk, net);if (!cfg || cfg->groups <32 ) groups =32 ;
Signature · 1 line
1.7.7
David Miller
maintainerFrom: Gu Zheng <[email protected]>
Date: Fri, 07 Mar 2014 18:47:30 +0800
Quoted 5 lines
Many netlink users create netlink sock in the
init_net, and the switchingnes_ns(init_net-->net)is needless in this case. So here we add a pre-check to avoid this.Signed-off-by Gu Zheng <[email protected]>
This check is more appropriately placed into sk_change_net() itself.
Quoted 10 lines · David Miller
From: Gu Zheng <[email protected]>
Date: Fri, 07 Mar 2014 18:47:30 +0800Quoted 5 lines
Many netlink users create netlink sock in the
init_net, and the switchingnes_ns(init_net-->net)is needless in this case. So here we add a pre-check to avoid this.Signed-off-by Gu Zheng <[email protected]>This check is more appropriately placed into
sk_change_net()itself.
Agree. I'll update it soon.
Regards,
Gu
Quoted 1 line
PATCH 1/1 net: add a pre-check of net_ns in sk_change_net()
In reply to David MillerWe do not need to switch the net_ns if the target net_ns the same as the current one, so here we add a pre-check of net_ns to avoid this as David suggested.
--- include/net/sock.h | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
include/net/sock.h +6 -2
@@ -2252,8 +2252,12 @@ void sock_net_set(struct sock *sk, struct net *net)*/ static inline void sk_change_net (struct sock *sk,struct net *net) { -put_net (sock_net (sk)); -sock_net_set (sk,hold_net (net)); +struct net *current_net =sock_net (sk); + +if (!net_eq (current_net, net)) { +put_net (current_net); +sock_net_set (sk,hold_net (net)); + } }static inline struct sock *skb_steal_sock (struct sk_buff *skb)
Signature · 1 line
1.7.7
Re: [PATCH] net: add a pre-check of net_ns in sk_change_net()
From: Gu Zheng <[email protected]>
Date: Mon, 10 Mar 2014 09:57:34 +0800
Quoted 5 lines
We do not need to switch the
net_nsif the targetnet_nsthe same as the current one, so here we add a pre-check ofnet_nsto avoid this as David suggested.Signed-off-by Gu Zheng <[email protected]>
Applied to net-next, thank you.