Skip to content

Commit

Permalink
net: add a pre-check of net_ns in sk_change_net()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Gu Zheng authored and David S. Miller committed Mar 10, 2014
1 parent 431a912 commit 5812521
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5812521

Please sign in to comment.