diff --git a/include/net/inet_timewait_sock.h b/include/net/inet_timewait_sock.h index 296547b..c825c2d 100644 --- a/include/net/inet_timewait_sock.h +++ b/include/net/inet_timewait_sock.h @@ -115,7 +115,9 @@ struct inet_timewait_sock { #define tw_refcnt __tw_common.skc_refcnt #define tw_hash __tw_common.skc_hash #define tw_prot __tw_common.skc_prot +#ifdef CONFIG_NET_NS #define tw_net __tw_common.skc_net +#endif int tw_timeout; volatile unsigned char tw_substate; /* 3 bits hole, try to pack */ @@ -187,6 +189,24 @@ static inline struct inet_timewait_sock *inet_twsk(const struct sock *sk) return (struct inet_timewait_sock *)sk; } +static inline +struct net *tw_sock_net(struct inet_timewait_sock *twsk) +{ +#ifdef CONFIG_NET_NS + return twsk->tw_net; +#else + return &init_net; +#endif +} + +static inline void tw_sock_net_set(struct inet_timewait_sock *twsk, + struct net *net) +{ +#ifdef CONFIG_NET_NS + twsk->tw_net = net; +#endif +} + static inline __be32 inet_rcv_saddr(const struct sock *sk) { return likely(sk->sk_state != TCP_TIME_WAIT) ? diff --git a/include/net/sock.h b/include/net/sock.h index 7e0d4a0..eb1f065 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -211,7 +211,9 @@ struct sock { #define sk_refcnt __sk_common.skc_refcnt #define sk_hash __sk_common.skc_hash #define sk_prot __sk_common.skc_prot +#ifdef CONFIG_NET_NS #define sk_net __sk_common.skc_net +#endif unsigned char sk_shutdown : 2, sk_no_check : 2, sk_userlocks : 4; diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index a60db37..3524dcd 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c @@ -124,7 +124,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat tw->tw_hash = sk->sk_hash; tw->tw_ipv6only = 0; tw->tw_prot = sk->sk_prot_creator; - tw->tw_net = sock_net(sk); + tw_sock_net_set(tw, sock_net(sk)); atomic_set(&tw->tw_refcnt, 1); inet_twsk_dead_node_init(tw); __module_get(tw->tw_prot->owner); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index b92f789..a157027 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2059,7 +2059,7 @@ static void *established_get_first(struct seq_file *seq) inet_twsk_for_each(tw, node, &tcp_hashinfo.ehash[st->bucket].twchain) { if (tw->tw_family != st->family || - tw->tw_net != net) { + tw_sock_net(tw) != net) { continue; } rc = tw; @@ -2086,7 +2086,8 @@ static void *established_get_next(struct seq_file *seq, void *cur) tw = cur; tw = tw_next(tw); get_tw: - while (tw && (tw->tw_family != st->family || tw->tw_net != net)) { + while (tw && (tw->tw_family != st->family || + tw_sock_net(tw) != net)) { tw = tw_next(tw); } if (tw) {