aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/sock.h
diff options
context:
space:
mode:
authorGu Zheng <guz.fnst@cn.fujitsu.com>2014-03-09 21:57:34 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-10 16:29:48 -0400
commit5812521be0f79583a26e203ac5f23de679cbdd94 (patch)
treea57bf248f7ffba9d37e7999dc3b2c215df999cea /include/net/sock.h
parent431a91242d8d7876d33ab91b1f3ccdcd56b14f66 (diff)
net: add a pre-check of net_ns in sk_change_net()
We 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. Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/sock.h')
-rw-r--r--include/net/sock.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index 5c3f7c3624aa..967856970a51 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2252,8 +2252,12 @@ void sock_net_set(struct sock *sk, struct net *net)
2252 */ 2252 */
2253static inline void sk_change_net(struct sock *sk, struct net *net) 2253static inline void sk_change_net(struct sock *sk, struct net *net)
2254{ 2254{
2255 put_net(sock_net(sk)); 2255 struct net *current_net = sock_net(sk);
2256 sock_net_set(sk, hold_net(net)); 2256
2257 if (!net_eq(current_net, net)) {
2258 put_net(current_net);
2259 sock_net_set(sk, hold_net(net));
2260 }
2257} 2261}
2258 2262
2259static inline struct sock *skb_steal_sock(struct sk_buff *skb) 2263static inline struct sock *skb_steal_sock(struct sk_buff *skb)