aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-03-25 13:26:21 -0400
committerYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-03-25 15:39:55 -0400
commit3b1e0a655f8eba44ab1ee2a1068d169ccfb853b9 (patch)
tree09edb35f32ebcfb1b4dad904425128a110ef16ee
parentc346dca10840a874240c78efe3f39acf4312a1f2 (diff)
[NET] NETNS: Omit sock->sk_net without CONFIG_NET_NS.
Introduce per-sock inlines: sock_net(), sock_net_set() and per-inet_timewait_sock inlines: twsk_net(), twsk_net_set(). Without CONFIG_NET_NS, no namespace other than &init_net exists. Let's explicitly define them to help compiler optimizations. Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
-rw-r--r--include/linux/ipv6.h4
-rw-r--r--include/net/inet_hashtables.h8
-rw-r--r--include/net/inet_timewait_sock.h18
-rw-r--r--include/net/route.h4
-rw-r--r--include/net/sock.h24
-rw-r--r--net/atm/svc.c2
-rw-r--r--net/ax25/af_ax25.c2
-rw-r--r--net/bluetooth/l2cap.c2
-rw-r--r--net/bluetooth/rfcomm/sock.c2
-rw-r--r--net/bluetooth/sco.c2
-rw-r--r--net/bridge/br_netlink.c4
-rw-r--r--net/core/fib_rules.c6
-rw-r--r--net/core/neighbour.c10
-rw-r--r--net/core/rtnetlink.c12
-rw-r--r--net/core/sock.c10
-rw-r--r--net/decnet/af_decnet.c2
-rw-r--r--net/decnet/dn_dev.c6
-rw-r--r--net/decnet/dn_fib.c4
-rw-r--r--net/decnet/dn_route.c4
-rw-r--r--net/decnet/dn_table.c2
-rw-r--r--net/ipv4/af_inet.c6
-rw-r--r--net/ipv4/devinet.c6
-rw-r--r--net/ipv4/fib_frontend.c8
-rw-r--r--net/ipv4/fib_rules.c2
-rw-r--r--net/ipv4/igmp.c14
-rw-r--r--net/ipv4/inet_connection_sock.c4
-rw-r--r--net/ipv4/inet_hashtables.c8
-rw-r--r--net/ipv4/inet_timewait_sock.c2
-rw-r--r--net/ipv4/ip_input.c2
-rw-r--r--net/ipv4/ip_output.c4
-rw-r--r--net/ipv4/ip_sockglue.c6
-rw-r--r--net/ipv4/ipmr.c4
-rw-r--r--net/ipv4/netfilter/arp_tables.c16
-rw-r--r--net/ipv4/netfilter/ip_tables.c16
-rw-r--r--net/ipv4/raw.c12
-rw-r--r--net/ipv4/route.c4
-rw-r--r--net/ipv4/tcp_ipv4.c14
-rw-r--r--net/ipv4/udp.c16
-rw-r--r--net/ipv6/addrconf.c10
-rw-r--r--net/ipv6/addrlabel.c6
-rw-r--r--net/ipv6/af_inet6.c4
-rw-r--r--net/ipv6/fib6_rules.c2
-rw-r--r--net/ipv6/icmp.c2
-rw-r--r--net/ipv6/inet6_hashtables.c4
-rw-r--r--net/ipv6/ip6_fib.c2
-rw-r--r--net/ipv6/ip6_output.c2
-rw-r--r--net/ipv6/ipv6_sockglue.c2
-rw-r--r--net/ipv6/mcast.c12
-rw-r--r--net/ipv6/netfilter/ip6_tables.c16
-rw-r--r--net/ipv6/raw.c6
-rw-r--r--net/ipv6/route.c4
-rw-r--r--net/ipv6/tcp_ipv6.c2
-rw-r--r--net/ipv6/udp.c4
-rw-r--r--net/irda/af_irda.c2
-rw-r--r--net/llc/llc_conn.c2
-rw-r--r--net/netfilter/nf_sockopt.c2
-rw-r--r--net/netlink/af_netlink.c30
-rw-r--r--net/netrom/af_netrom.c2
-rw-r--r--net/packet/af_packet.c28
-rw-r--r--net/rose/af_rose.c2
-rw-r--r--net/sched/act_api.c4
-rw-r--r--net/sched/cls_api.c4
-rw-r--r--net/sched/sch_api.c10
-rw-r--r--net/sctp/ipv6.c2
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--net/socket.c4
-rw-r--r--net/tipc/socket.c2
-rw-r--r--net/unix/af_unix.c20
-rw-r--r--net/x25/af_x25.c2
69 files changed, 253 insertions, 215 deletions
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index c9ba0da16ce9..b90d3d461d4e 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -481,7 +481,7 @@ static inline struct raw6_sock *raw6_sk(const struct sock *sk)
481#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ 481#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
482 482
483#define INET6_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif)\ 483#define INET6_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif)\
484 (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \ 484 (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
485 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \ 485 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
486 ((__sk)->sk_family == AF_INET6) && \ 486 ((__sk)->sk_family == AF_INET6) && \
487 ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr)) && \ 487 ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr)) && \
@@ -489,7 +489,7 @@ static inline struct raw6_sock *raw6_sk(const struct sock *sk)
489 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 489 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
490 490
491#define INET6_TW_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif) \ 491#define INET6_TW_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif) \
492 (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \ 492 (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
493 (*((__portpair *)&(inet_twsk(__sk)->tw_dport)) == (__ports)) && \ 493 (*((__portpair *)&(inet_twsk(__sk)->tw_dport)) == (__ports)) && \
494 ((__sk)->sk_family == PF_INET6) && \ 494 ((__sk)->sk_family == PF_INET6) && \
495 (ipv6_addr_equal(&inet6_twsk(__sk)->tw_v6_daddr, (__saddr))) && \ 495 (ipv6_addr_equal(&inet6_twsk(__sk)->tw_v6_daddr, (__saddr))) && \
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index d99c1ba2ece0..5525227c5e92 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -314,25 +314,25 @@ typedef __u64 __bitwise __addrpair;
314 ((__force __u64)(__be32)(__saddr))); 314 ((__force __u64)(__be32)(__saddr)));
315#endif /* __BIG_ENDIAN */ 315#endif /* __BIG_ENDIAN */
316#define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ 316#define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
317 (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \ 317 (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
318 ((*((__addrpair *)&(inet_sk(__sk)->daddr))) == (__cookie)) && \ 318 ((*((__addrpair *)&(inet_sk(__sk)->daddr))) == (__cookie)) && \
319 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \ 319 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
320 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 320 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
321#define INET_TW_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ 321#define INET_TW_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
322 (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \ 322 (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
323 ((*((__addrpair *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \ 323 ((*((__addrpair *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \
324 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ 324 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
325 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 325 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
326#else /* 32-bit arch */ 326#else /* 32-bit arch */
327#define INET_ADDR_COOKIE(__name, __saddr, __daddr) 327#define INET_ADDR_COOKIE(__name, __saddr, __daddr)
328#define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif) \ 328#define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif) \
329 (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \ 329 (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
330 (inet_sk(__sk)->daddr == (__saddr)) && \ 330 (inet_sk(__sk)->daddr == (__saddr)) && \
331 (inet_sk(__sk)->rcv_saddr == (__daddr)) && \ 331 (inet_sk(__sk)->rcv_saddr == (__daddr)) && \
332 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \ 332 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
333 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 333 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
334#define INET_TW_MATCH(__sk, __net, __hash,__cookie, __saddr, __daddr, __ports, __dif) \ 334#define INET_TW_MATCH(__sk, __net, __hash,__cookie, __saddr, __daddr, __ports, __dif) \
335 (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \ 335 (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
336 (inet_twsk(__sk)->tw_daddr == (__saddr)) && \ 336 (inet_twsk(__sk)->tw_daddr == (__saddr)) && \
337 (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \ 337 (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \
338 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ 338 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
diff --git a/include/net/inet_timewait_sock.h b/include/net/inet_timewait_sock.h
index 296547bfb0b7..07fe0d1a4f03 100644
--- a/include/net/inet_timewait_sock.h
+++ b/include/net/inet_timewait_sock.h
@@ -207,4 +207,22 @@ extern void inet_twsk_schedule(struct inet_timewait_sock *tw,
207 const int timeo, const int timewait_len); 207 const int timeo, const int timewait_len);
208extern void inet_twsk_deschedule(struct inet_timewait_sock *tw, 208extern void inet_twsk_deschedule(struct inet_timewait_sock *tw,
209 struct inet_timewait_death_row *twdr); 209 struct inet_timewait_death_row *twdr);
210
211static inline
212struct net *twsk_net(const struct inet_timewait_sock *twsk)
213{
214#ifdef CONFIG_NET_NS
215 return twsk->tw_net;
216#else
217 return &init_net;
218#endif
219}
220
221static inline
222void twsk_net_set(struct inet_timewait_sock *twsk, const struct net *net)
223{
224#ifdef CONFIG_NET_NS
225 twsk->tw_net = net;
226#endif
227}
210#endif /* _INET_TIMEWAIT_SOCK_ */ 228#endif /* _INET_TIMEWAIT_SOCK_ */
diff --git a/include/net/route.h b/include/net/route.h
index 28dba925663c..c6338802e8f1 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -160,7 +160,7 @@ static inline int ip_route_connect(struct rtable **rp, __be32 dst,
160 .dport = dport } } }; 160 .dport = dport } } };
161 161
162 int err; 162 int err;
163 struct net *net = sk->sk_net; 163 struct net *net = sock_net(sk);
164 if (!dst || !src) { 164 if (!dst || !src) {
165 err = __ip_route_output_key(net, rp, &fl); 165 err = __ip_route_output_key(net, rp, &fl);
166 if (err) 166 if (err)
@@ -188,7 +188,7 @@ static inline int ip_route_newports(struct rtable **rp, u8 protocol,
188 ip_rt_put(*rp); 188 ip_rt_put(*rp);
189 *rp = NULL; 189 *rp = NULL;
190 security_sk_classify_flow(sk, &fl); 190 security_sk_classify_flow(sk, &fl);
191 return ip_route_output_flow(sk->sk_net, rp, &fl, sk, 0); 191 return ip_route_output_flow(sock_net(sk), rp, &fl, sk, 0);
192 } 192 }
193 return 0; 193 return 0;
194} 194}
diff --git a/include/net/sock.h b/include/net/sock.h
index b433b1ed203d..7e0d4a0c4d12 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -126,7 +126,9 @@ struct sock_common {
126 atomic_t skc_refcnt; 126 atomic_t skc_refcnt;
127 unsigned int skc_hash; 127 unsigned int skc_hash;
128 struct proto *skc_prot; 128 struct proto *skc_prot;
129#ifdef CONFIG_NET_NS
129 struct net *skc_net; 130 struct net *skc_net;
131#endif
130}; 132};
131 133
132/** 134/**
@@ -1345,6 +1347,24 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_e
1345} 1347}
1346#endif 1348#endif
1347 1349
1350static inline
1351struct net *sock_net(const struct sock *sk)
1352{
1353#ifdef CONFIG_NET_NS
1354 return sk->sk_net;
1355#else
1356 return &init_net;
1357#endif
1358}
1359
1360static inline
1361void sock_net_set(struct sock *sk, const struct net *net)
1362{
1363#ifdef CONFIG_NET_NS
1364 sk->sk_net = net;
1365#endif
1366}
1367
1348/* 1368/*
1349 * Kernel sockets, f.e. rtnl or icmp_socket, are a part of a namespace. 1369 * Kernel sockets, f.e. rtnl or icmp_socket, are a part of a namespace.
1350 * They should not hold a referrence to a namespace in order to allow 1370 * They should not hold a referrence to a namespace in order to allow
@@ -1353,8 +1373,8 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_e
1353 */ 1373 */
1354static inline void sk_change_net(struct sock *sk, struct net *net) 1374static inline void sk_change_net(struct sock *sk, struct net *net)
1355{ 1375{
1356 put_net(sk->sk_net); 1376 put_net(sock_net(sk));
1357 sk->sk_net = net; 1377 sock_net_set(sk, net);
1358} 1378}
1359 1379
1360extern void sock_enable_timestamp(struct sock *sk); 1380extern void sock_enable_timestamp(struct sock *sk);
diff --git a/net/atm/svc.c b/net/atm/svc.c
index daf9a48a7db0..de1e4f2f3a43 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -326,7 +326,7 @@ static int svc_accept(struct socket *sock,struct socket *newsock,int flags)
326 326
327 lock_sock(sk); 327 lock_sock(sk);
328 328
329 error = svc_create(sk->sk_net, newsock,0); 329 error = svc_create(sock_net(sk), newsock,0);
330 if (error) 330 if (error)
331 goto out; 331 goto out;
332 332
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index ee9dd83e7561..2712544cf0ca 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -869,7 +869,7 @@ struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
869 struct sock *sk; 869 struct sock *sk;
870 ax25_cb *ax25, *oax25; 870 ax25_cb *ax25, *oax25;
871 871
872 sk = sk_alloc(osk->sk_net, PF_AX25, GFP_ATOMIC, osk->sk_prot); 872 sk = sk_alloc(sock_net(osk), PF_AX25, GFP_ATOMIC, osk->sk_prot);
873 if (sk == NULL) 873 if (sk == NULL)
874 return NULL; 874 return NULL;
875 875
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 34f8bf98bc05..6b995ac832f5 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -1499,7 +1499,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
1499 goto response; 1499 goto response;
1500 } 1500 }
1501 1501
1502 sk = l2cap_sock_alloc(parent->sk_net, NULL, BTPROTO_L2CAP, GFP_ATOMIC); 1502 sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP, GFP_ATOMIC);
1503 if (!sk) 1503 if (!sk)
1504 goto response; 1504 goto response;
1505 1505
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index c46d51035e77..c103fa02893b 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -868,7 +868,7 @@ int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc *
868 goto done; 868 goto done;
869 } 869 }
870 870
871 sk = rfcomm_sock_alloc(parent->sk_net, NULL, BTPROTO_RFCOMM, GFP_ATOMIC); 871 sk = rfcomm_sock_alloc(sock_net(parent), NULL, BTPROTO_RFCOMM, GFP_ATOMIC);
872 if (!sk) 872 if (!sk)
873 goto done; 873 goto done;
874 874
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index b91d3c81a73c..2a5953b4405d 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -803,7 +803,7 @@ static void sco_conn_ready(struct sco_conn *conn)
803 803
804 bh_lock_sock(parent); 804 bh_lock_sock(parent);
805 805
806 sk = sco_sock_alloc(parent->sk_net, NULL, BTPROTO_SCO, GFP_ATOMIC); 806 sk = sco_sock_alloc(sock_net(parent), NULL, BTPROTO_SCO, GFP_ATOMIC);
807 if (!sk) { 807 if (!sk) {
808 bh_unlock_sock(parent); 808 bh_unlock_sock(parent);
809 goto done; 809 goto done;
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index f5d69336d97b..f155e6ce8a21 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -108,7 +108,7 @@ errout:
108 */ 108 */
109static int br_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) 109static int br_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
110{ 110{
111 struct net *net = skb->sk->sk_net; 111 struct net *net = sock_net(skb->sk);
112 struct net_device *dev; 112 struct net_device *dev;
113 int idx; 113 int idx;
114 114
@@ -140,7 +140,7 @@ skip:
140 */ 140 */
141static int br_rtm_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 141static int br_rtm_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
142{ 142{
143 struct net *net = skb->sk->sk_net; 143 struct net *net = sock_net(skb->sk);
144 struct ifinfomsg *ifm; 144 struct ifinfomsg *ifm;
145 struct nlattr *protinfo; 145 struct nlattr *protinfo;
146 struct net_device *dev; 146 struct net_device *dev;
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 942be93a2eb0..540c07283e31 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -214,7 +214,7 @@ errout:
214 214
215static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 215static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
216{ 216{
217 struct net *net = skb->sk->sk_net; 217 struct net *net = sock_net(skb->sk);
218 struct fib_rule_hdr *frh = nlmsg_data(nlh); 218 struct fib_rule_hdr *frh = nlmsg_data(nlh);
219 struct fib_rules_ops *ops = NULL; 219 struct fib_rules_ops *ops = NULL;
220 struct fib_rule *rule, *r, *last = NULL; 220 struct fib_rule *rule, *r, *last = NULL;
@@ -352,7 +352,7 @@ errout:
352 352
353static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 353static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
354{ 354{
355 struct net *net = skb->sk->sk_net; 355 struct net *net = sock_net(skb->sk);
356 struct fib_rule_hdr *frh = nlmsg_data(nlh); 356 struct fib_rule_hdr *frh = nlmsg_data(nlh);
357 struct fib_rules_ops *ops = NULL; 357 struct fib_rules_ops *ops = NULL;
358 struct fib_rule *rule, *tmp; 358 struct fib_rule *rule, *tmp;
@@ -534,7 +534,7 @@ skip:
534 534
535static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb) 535static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb)
536{ 536{
537 struct net *net = skb->sk->sk_net; 537 struct net *net = sock_net(skb->sk);
538 struct fib_rules_ops *ops; 538 struct fib_rules_ops *ops;
539 int idx = 0, family; 539 int idx = 0, family;
540 540
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index c978bd1cd659..065fbac7ecd3 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1478,7 +1478,7 @@ int neigh_table_clear(struct neigh_table *tbl)
1478 1478
1479static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1479static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1480{ 1480{
1481 struct net *net = skb->sk->sk_net; 1481 struct net *net = sock_net(skb->sk);
1482 struct ndmsg *ndm; 1482 struct ndmsg *ndm;
1483 struct nlattr *dst_attr; 1483 struct nlattr *dst_attr;
1484 struct neigh_table *tbl; 1484 struct neigh_table *tbl;
@@ -1544,7 +1544,7 @@ out:
1544 1544
1545static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1545static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1546{ 1546{
1547 struct net *net = skb->sk->sk_net; 1547 struct net *net = sock_net(skb->sk);
1548 struct ndmsg *ndm; 1548 struct ndmsg *ndm;
1549 struct nlattr *tb[NDA_MAX+1]; 1549 struct nlattr *tb[NDA_MAX+1];
1550 struct neigh_table *tbl; 1550 struct neigh_table *tbl;
@@ -1812,7 +1812,7 @@ static const struct nla_policy nl_ntbl_parm_policy[NDTPA_MAX+1] = {
1812 1812
1813static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1813static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1814{ 1814{
1815 struct net *net = skb->sk->sk_net; 1815 struct net *net = sock_net(skb->sk);
1816 struct neigh_table *tbl; 1816 struct neigh_table *tbl;
1817 struct ndtmsg *ndtmsg; 1817 struct ndtmsg *ndtmsg;
1818 struct nlattr *tb[NDTA_MAX+1]; 1818 struct nlattr *tb[NDTA_MAX+1];
@@ -1937,7 +1937,7 @@ errout:
1937 1937
1938static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb) 1938static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
1939{ 1939{
1940 struct net *net = skb->sk->sk_net; 1940 struct net *net = sock_net(skb->sk);
1941 int family, tidx, nidx = 0; 1941 int family, tidx, nidx = 0;
1942 int tbl_skip = cb->args[0]; 1942 int tbl_skip = cb->args[0];
1943 int neigh_skip = cb->args[1]; 1943 int neigh_skip = cb->args[1];
@@ -2037,7 +2037,7 @@ static void neigh_update_notify(struct neighbour *neigh)
2037static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, 2037static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
2038 struct netlink_callback *cb) 2038 struct netlink_callback *cb)
2039{ 2039{
2040 struct net * net = skb->sk->sk_net; 2040 struct net * net = sock_net(skb->sk);
2041 struct neighbour *n; 2041 struct neighbour *n;
2042 int rc, h, s_h = cb->args[1]; 2042 int rc, h, s_h = cb->args[1];
2043 int idx, s_idx = idx = cb->args[2]; 2043 int idx, s_idx = idx = cb->args[2];
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 09250a0800f6..da99ac0871bf 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -662,7 +662,7 @@ nla_put_failure:
662 662
663static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) 663static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
664{ 664{
665 struct net *net = skb->sk->sk_net; 665 struct net *net = sock_net(skb->sk);
666 int idx; 666 int idx;
667 int s_idx = cb->args[0]; 667 int s_idx = cb->args[0];
668 struct net_device *dev; 668 struct net_device *dev;
@@ -879,7 +879,7 @@ errout:
879 879
880static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 880static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
881{ 881{
882 struct net *net = skb->sk->sk_net; 882 struct net *net = sock_net(skb->sk);
883 struct ifinfomsg *ifm; 883 struct ifinfomsg *ifm;
884 struct net_device *dev; 884 struct net_device *dev;
885 int err; 885 int err;
@@ -921,7 +921,7 @@ errout:
921 921
922static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 922static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
923{ 923{
924 struct net *net = skb->sk->sk_net; 924 struct net *net = sock_net(skb->sk);
925 const struct rtnl_link_ops *ops; 925 const struct rtnl_link_ops *ops;
926 struct net_device *dev; 926 struct net_device *dev;
927 struct ifinfomsg *ifm; 927 struct ifinfomsg *ifm;
@@ -1000,7 +1000,7 @@ err:
1000 1000
1001static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 1001static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1002{ 1002{
1003 struct net *net = skb->sk->sk_net; 1003 struct net *net = sock_net(skb->sk);
1004 const struct rtnl_link_ops *ops; 1004 const struct rtnl_link_ops *ops;
1005 struct net_device *dev; 1005 struct net_device *dev;
1006 struct ifinfomsg *ifm; 1006 struct ifinfomsg *ifm;
@@ -1132,7 +1132,7 @@ replay:
1132 1132
1133static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 1133static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
1134{ 1134{
1135 struct net *net = skb->sk->sk_net; 1135 struct net *net = sock_net(skb->sk);
1136 struct ifinfomsg *ifm; 1136 struct ifinfomsg *ifm;
1137 struct nlattr *tb[IFLA_MAX+1]; 1137 struct nlattr *tb[IFLA_MAX+1];
1138 struct net_device *dev = NULL; 1138 struct net_device *dev = NULL;
@@ -1227,7 +1227,7 @@ static int rtattr_max;
1227 1227
1228static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) 1228static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1229{ 1229{
1230 struct net *net = skb->sk->sk_net; 1230 struct net *net = sock_net(skb->sk);
1231 rtnl_doit_func doit; 1231 rtnl_doit_func doit;
1232 int sz_idx, kind; 1232 int sz_idx, kind;
1233 int min_len; 1233 int min_len;
diff --git a/net/core/sock.c b/net/core/sock.c
index b1a6ed4d33c1..3ee95060dbd0 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -372,7 +372,7 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
372{ 372{
373 int ret = -ENOPROTOOPT; 373 int ret = -ENOPROTOOPT;
374#ifdef CONFIG_NETDEVICES 374#ifdef CONFIG_NETDEVICES
375 struct net *net = sk->sk_net; 375 struct net *net = sock_net(sk);
376 char devname[IFNAMSIZ]; 376 char devname[IFNAMSIZ];
377 int index; 377 int index;
378 378
@@ -958,7 +958,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
958 */ 958 */
959 sk->sk_prot = sk->sk_prot_creator = prot; 959 sk->sk_prot = sk->sk_prot_creator = prot;
960 sock_lock_init(sk); 960 sock_lock_init(sk);
961 sk->sk_net = get_net(net); 961 sock_net_set(sk, get_net(net));
962 } 962 }
963 963
964 return sk; 964 return sk;
@@ -983,7 +983,7 @@ void sk_free(struct sock *sk)
983 printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n", 983 printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n",
984 __func__, atomic_read(&sk->sk_omem_alloc)); 984 __func__, atomic_read(&sk->sk_omem_alloc));
985 985
986 put_net(sk->sk_net); 986 put_net(sock_net(sk));
987 sk_prot_free(sk->sk_prot_creator, sk); 987 sk_prot_free(sk->sk_prot_creator, sk);
988} 988}
989 989
@@ -1001,7 +1001,7 @@ void sk_release_kernel(struct sock *sk)
1001 1001
1002 sock_hold(sk); 1002 sock_hold(sk);
1003 sock_release(sk->sk_socket); 1003 sock_release(sk->sk_socket);
1004 sk->sk_net = get_net(&init_net); 1004 sock_net_set(sk, get_net(&init_net));
1005 sock_put(sk); 1005 sock_put(sk);
1006} 1006}
1007EXPORT_SYMBOL(sk_release_kernel); 1007EXPORT_SYMBOL(sk_release_kernel);
@@ -1017,7 +1017,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
1017 sock_copy(newsk, sk); 1017 sock_copy(newsk, sk);
1018 1018
1019 /* SANITY */ 1019 /* SANITY */
1020 get_net(newsk->sk_net); 1020 get_net(sock_net(newsk));
1021 sk_node_init(&newsk->sk_node); 1021 sk_node_init(&newsk->sk_node);
1022 sock_lock_init(newsk); 1022 sock_lock_init(newsk);
1023 bh_lock_sock(newsk); 1023 bh_lock_sock(newsk);
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index 3554fb3d251c..fc2efe899e91 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -1094,7 +1094,7 @@ static int dn_accept(struct socket *sock, struct socket *newsock, int flags)
1094 1094
1095 cb = DN_SKB_CB(skb); 1095 cb = DN_SKB_CB(skb);
1096 sk->sk_ack_backlog--; 1096 sk->sk_ack_backlog--;
1097 newsk = dn_alloc_sock(sk->sk_net, newsock, sk->sk_allocation); 1097 newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation);
1098 if (newsk == NULL) { 1098 if (newsk == NULL) {
1099 release_sock(sk); 1099 release_sock(sk);
1100 kfree_skb(skb); 1100 kfree_skb(skb);
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 1bbfce5f7a2d..2f0ac3c3eb71 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -625,7 +625,7 @@ static const struct nla_policy dn_ifa_policy[IFA_MAX+1] = {
625 625
626static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 626static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
627{ 627{
628 struct net *net = skb->sk->sk_net; 628 struct net *net = sock_net(skb->sk);
629 struct nlattr *tb[IFA_MAX+1]; 629 struct nlattr *tb[IFA_MAX+1];
630 struct dn_dev *dn_db; 630 struct dn_dev *dn_db;
631 struct ifaddrmsg *ifm; 631 struct ifaddrmsg *ifm;
@@ -663,7 +663,7 @@ errout:
663 663
664static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 664static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
665{ 665{
666 struct net *net = skb->sk->sk_net; 666 struct net *net = sock_net(skb->sk);
667 struct nlattr *tb[IFA_MAX+1]; 667 struct nlattr *tb[IFA_MAX+1];
668 struct net_device *dev; 668 struct net_device *dev;
669 struct dn_dev *dn_db; 669 struct dn_dev *dn_db;
@@ -779,7 +779,7 @@ errout:
779 779
780static int dn_nl_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) 780static int dn_nl_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
781{ 781{
782 struct net *net = skb->sk->sk_net; 782 struct net *net = sock_net(skb->sk);
783 int idx, dn_idx = 0, skip_ndevs, skip_naddr; 783 int idx, dn_idx = 0, skip_ndevs, skip_naddr;
784 struct net_device *dev; 784 struct net_device *dev;
785 struct dn_dev *dn_db; 785 struct dn_dev *dn_db;
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c
index 4aa9a423e606..27ea2e9b080a 100644
--- a/net/decnet/dn_fib.c
+++ b/net/decnet/dn_fib.c
@@ -504,7 +504,7 @@ static int dn_fib_check_attr(struct rtmsg *r, struct rtattr **rta)
504 504
505static int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 505static int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
506{ 506{
507 struct net *net = skb->sk->sk_net; 507 struct net *net = sock_net(skb->sk);
508 struct dn_fib_table *tb; 508 struct dn_fib_table *tb;
509 struct rtattr **rta = arg; 509 struct rtattr **rta = arg;
510 struct rtmsg *r = NLMSG_DATA(nlh); 510 struct rtmsg *r = NLMSG_DATA(nlh);
@@ -524,7 +524,7 @@ static int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *
524 524
525static int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 525static int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
526{ 526{
527 struct net *net = skb->sk->sk_net; 527 struct net *net = sock_net(skb->sk);
528 struct dn_fib_table *tb; 528 struct dn_fib_table *tb;
529 struct rtattr **rta = arg; 529 struct rtattr **rta = arg;
530 struct rtmsg *r = NLMSG_DATA(nlh); 530 struct rtmsg *r = NLMSG_DATA(nlh);
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 0a46b6c10e51..2f665a516476 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1512,7 +1512,7 @@ rtattr_failure:
1512 */ 1512 */
1513static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg) 1513static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
1514{ 1514{
1515 struct net *net = in_skb->sk->sk_net; 1515 struct net *net = sock_net(in_skb->sk);
1516 struct rtattr **rta = arg; 1516 struct rtattr **rta = arg;
1517 struct rtmsg *rtm = NLMSG_DATA(nlh); 1517 struct rtmsg *rtm = NLMSG_DATA(nlh);
1518 struct dn_route *rt = NULL; 1518 struct dn_route *rt = NULL;
@@ -1601,7 +1601,7 @@ out_free:
1601 */ 1601 */
1602int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb) 1602int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
1603{ 1603{
1604 struct net *net = skb->sk->sk_net; 1604 struct net *net = sock_net(skb->sk);
1605 struct dn_route *rt; 1605 struct dn_route *rt;
1606 int h, s_h; 1606 int h, s_h;
1607 int idx, s_idx; 1607 int idx, s_idx;
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index e09d915dbd77..3a2830ac89c2 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -463,7 +463,7 @@ static int dn_fib_table_dump(struct dn_fib_table *tb, struct sk_buff *skb,
463 463
464int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb) 464int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb)
465{ 465{
466 struct net *net = skb->sk->sk_net; 466 struct net *net = sock_net(skb->sk);
467 unsigned int h, s_h; 467 unsigned int h, s_h;
468 unsigned int e = 0, s_e; 468 unsigned int e = 0, s_e;
469 struct dn_fib_table *tb; 469 struct dn_fib_table *tb;
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 06cfb0bed631..5882a1316441 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -464,7 +464,7 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
464 if (addr_len < sizeof(struct sockaddr_in)) 464 if (addr_len < sizeof(struct sockaddr_in))
465 goto out; 465 goto out;
466 466
467 chk_addr_ret = inet_addr_type(sk->sk_net, addr->sin_addr.s_addr); 467 chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
468 468
469 /* Not specified by any standard per-se, however it breaks too 469 /* Not specified by any standard per-se, however it breaks too
470 * many applications when removed. It is unfortunate since 470 * many applications when removed. It is unfortunate since
@@ -802,7 +802,7 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
802{ 802{
803 struct sock *sk = sock->sk; 803 struct sock *sk = sock->sk;
804 int err = 0; 804 int err = 0;
805 struct net *net = sk->sk_net; 805 struct net *net = sock_net(sk);
806 806
807 switch (cmd) { 807 switch (cmd) {
808 case SIOCGSTAMP: 808 case SIOCGSTAMP:
@@ -1132,7 +1132,7 @@ int inet_sk_rebuild_header(struct sock *sk)
1132 }; 1132 };
1133 1133
1134 security_sk_classify_flow(sk, &fl); 1134 security_sk_classify_flow(sk, &fl);
1135 err = ip_route_output_flow(sk->sk_net, &rt, &fl, sk, 0); 1135 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 0);
1136} 1136}
1137 if (!err) 1137 if (!err)
1138 sk_setup_caps(sk, &rt->u.dst); 1138 sk_setup_caps(sk, &rt->u.dst);
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 823c724a8593..6848e4760f34 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -437,7 +437,7 @@ struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
437 437
438static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 438static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
439{ 439{
440 struct net *net = skb->sk->sk_net; 440 struct net *net = sock_net(skb->sk);
441 struct nlattr *tb[IFA_MAX+1]; 441 struct nlattr *tb[IFA_MAX+1];
442 struct in_device *in_dev; 442 struct in_device *in_dev;
443 struct ifaddrmsg *ifm; 443 struct ifaddrmsg *ifm;
@@ -552,7 +552,7 @@ errout:
552 552
553static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 553static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
554{ 554{
555 struct net *net = skb->sk->sk_net; 555 struct net *net = sock_net(skb->sk);
556 struct in_ifaddr *ifa; 556 struct in_ifaddr *ifa;
557 557
558 ASSERT_RTNL(); 558 ASSERT_RTNL();
@@ -1158,7 +1158,7 @@ nla_put_failure:
1158 1158
1159static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) 1159static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
1160{ 1160{
1161 struct net *net = skb->sk->sk_net; 1161 struct net *net = sock_net(skb->sk);
1162 int idx, ip_idx; 1162 int idx, ip_idx;
1163 struct net_device *dev; 1163 struct net_device *dev;
1164 struct in_device *in_dev; 1164 struct in_device *in_dev;
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 0e4b34b07cb5..0f1557a4ac7a 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -583,7 +583,7 @@ errout:
583 583
584static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 584static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
585{ 585{
586 struct net *net = skb->sk->sk_net; 586 struct net *net = sock_net(skb->sk);
587 struct fib_config cfg; 587 struct fib_config cfg;
588 struct fib_table *tb; 588 struct fib_table *tb;
589 int err; 589 int err;
@@ -605,7 +605,7 @@ errout:
605 605
606static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) 606static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
607{ 607{
608 struct net *net = skb->sk->sk_net; 608 struct net *net = sock_net(skb->sk);
609 struct fib_config cfg; 609 struct fib_config cfg;
610 struct fib_table *tb; 610 struct fib_table *tb;
611 int err; 611 int err;
@@ -627,7 +627,7 @@ errout:
627 627
628static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) 628static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
629{ 629{
630 struct net *net = skb->sk->sk_net; 630 struct net *net = sock_net(skb->sk);
631 unsigned int h, s_h; 631 unsigned int h, s_h;
632 unsigned int e = 0, s_e; 632 unsigned int e = 0, s_e;
633 struct fib_table *tb; 633 struct fib_table *tb;
@@ -857,7 +857,7 @@ static void nl_fib_input(struct sk_buff *skb)
857 struct fib_table *tb; 857 struct fib_table *tb;
858 u32 pid; 858 u32 pid;
859 859
860 net = skb->sk->sk_net; 860 net = sock_net(skb->sk);
861 nlh = nlmsg_hdr(skb); 861 nlh = nlmsg_hdr(skb);
862 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len || 862 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
863 nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) 863 nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn)))
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 19274d01afa4..1fb56876be54 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -137,7 +137,7 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
137 struct nlmsghdr *nlh, struct fib_rule_hdr *frh, 137 struct nlmsghdr *nlh, struct fib_rule_hdr *frh,
138 struct nlattr **tb) 138 struct nlattr **tb)
139{ 139{
140 struct net *net = skb->sk->sk_net; 140 struct net *net = sock_net(skb->sk);
141 int err = -EINVAL; 141 int err = -EINVAL;
142 struct fib4_rule *rule4 = (struct fib4_rule *) rule; 142 struct fib4_rule *rule4 = (struct fib4_rule *) rule;
143 143
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 682f632bfb77..6250f4239b61 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1762,7 +1762,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1762 if (!ipv4_is_multicast(addr)) 1762 if (!ipv4_is_multicast(addr))
1763 return -EINVAL; 1763 return -EINVAL;
1764 1764
1765 if (sk->sk_net != &init_net) 1765 if (sock_net(sk) != &init_net)
1766 return -EPROTONOSUPPORT; 1766 return -EPROTONOSUPPORT;
1767 1767
1768 rtnl_lock(); 1768 rtnl_lock();
@@ -1833,7 +1833,7 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
1833 u32 ifindex; 1833 u32 ifindex;
1834 int ret = -EADDRNOTAVAIL; 1834 int ret = -EADDRNOTAVAIL;
1835 1835
1836 if (sk->sk_net != &init_net) 1836 if (sock_net(sk) != &init_net)
1837 return -EPROTONOSUPPORT; 1837 return -EPROTONOSUPPORT;
1838 1838
1839 rtnl_lock(); 1839 rtnl_lock();
@@ -1881,7 +1881,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
1881 if (!ipv4_is_multicast(addr)) 1881 if (!ipv4_is_multicast(addr))
1882 return -EINVAL; 1882 return -EINVAL;
1883 1883
1884 if (sk->sk_net != &init_net) 1884 if (sock_net(sk) != &init_net)
1885 return -EPROTONOSUPPORT; 1885 return -EPROTONOSUPPORT;
1886 1886
1887 rtnl_lock(); 1887 rtnl_lock();
@@ -2017,7 +2017,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
2017 msf->imsf_fmode != MCAST_EXCLUDE) 2017 msf->imsf_fmode != MCAST_EXCLUDE)
2018 return -EINVAL; 2018 return -EINVAL;
2019 2019
2020 if (sk->sk_net != &init_net) 2020 if (sock_net(sk) != &init_net)
2021 return -EPROTONOSUPPORT; 2021 return -EPROTONOSUPPORT;
2022 2022
2023 rtnl_lock(); 2023 rtnl_lock();
@@ -2100,7 +2100,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
2100 if (!ipv4_is_multicast(addr)) 2100 if (!ipv4_is_multicast(addr))
2101 return -EINVAL; 2101 return -EINVAL;
2102 2102
2103 if (sk->sk_net != &init_net) 2103 if (sock_net(sk) != &init_net)
2104 return -EPROTONOSUPPORT; 2104 return -EPROTONOSUPPORT;
2105 2105
2106 rtnl_lock(); 2106 rtnl_lock();
@@ -2165,7 +2165,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
2165 if (!ipv4_is_multicast(addr)) 2165 if (!ipv4_is_multicast(addr))
2166 return -EINVAL; 2166 return -EINVAL;
2167 2167
2168 if (sk->sk_net != &init_net) 2168 if (sock_net(sk) != &init_net)
2169 return -EPROTONOSUPPORT; 2169 return -EPROTONOSUPPORT;
2170 2170
2171 rtnl_lock(); 2171 rtnl_lock();
@@ -2252,7 +2252,7 @@ void ip_mc_drop_socket(struct sock *sk)
2252 if (inet->mc_list == NULL) 2252 if (inet->mc_list == NULL)
2253 return; 2253 return;
2254 2254
2255 if (sk->sk_net != &init_net) 2255 if (sock_net(sk) != &init_net)
2256 return; 2256 return;
2257 2257
2258 rtnl_lock(); 2258 rtnl_lock();
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index d13c5f12bb32..a7fcaf205644 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -85,7 +85,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
85 struct hlist_node *node; 85 struct hlist_node *node;
86 struct inet_bind_bucket *tb; 86 struct inet_bind_bucket *tb;
87 int ret; 87 int ret;
88 struct net *net = sk->sk_net; 88 struct net *net = sock_net(sk);
89 89
90 local_bh_disable(); 90 local_bh_disable();
91 if (!snum) { 91 if (!snum) {
@@ -333,7 +333,7 @@ struct dst_entry* inet_csk_route_req(struct sock *sk,
333 .dport = ireq->rmt_port } } }; 333 .dport = ireq->rmt_port } } };
334 334
335 security_req_classify_flow(req, &fl); 335 security_req_classify_flow(req, &fl);
336 if (ip_route_output_flow(sk->sk_net, &rt, &fl, sk, 0)) { 336 if (ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 0)) {
337 IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES); 337 IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
338 return NULL; 338 return NULL;
339 } 339 }
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 8cd1ad9b9111..1064111e5b96 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -139,7 +139,7 @@ static struct sock *inet_lookup_listener_slow(struct net *net,
139 sk_for_each(sk, node, head) { 139 sk_for_each(sk, node, head) {
140 const struct inet_sock *inet = inet_sk(sk); 140 const struct inet_sock *inet = inet_sk(sk);
141 141
142 if (sk->sk_net == net && inet->num == hnum && 142 if (sock_net(sk) == net && inet->num == hnum &&
143 !ipv6_only_sock(sk)) { 143 !ipv6_only_sock(sk)) {
144 const __be32 rcv_saddr = inet->rcv_saddr; 144 const __be32 rcv_saddr = inet->rcv_saddr;
145 int score = sk->sk_family == PF_INET ? 1 : 0; 145 int score = sk->sk_family == PF_INET ? 1 : 0;
@@ -182,7 +182,7 @@ struct sock *__inet_lookup_listener(struct net *net,
182 if (inet->num == hnum && !sk->sk_node.next && 182 if (inet->num == hnum && !sk->sk_node.next &&
183 (!inet->rcv_saddr || inet->rcv_saddr == daddr) && 183 (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
184 (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) && 184 (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
185 !sk->sk_bound_dev_if && sk->sk_net == net) 185 !sk->sk_bound_dev_if && sock_net(sk) == net)
186 goto sherry_cache; 186 goto sherry_cache;
187 sk = inet_lookup_listener_slow(net, head, daddr, hnum, dif); 187 sk = inet_lookup_listener_slow(net, head, daddr, hnum, dif);
188 } 188 }
@@ -254,7 +254,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
254 struct sock *sk2; 254 struct sock *sk2;
255 const struct hlist_node *node; 255 const struct hlist_node *node;
256 struct inet_timewait_sock *tw; 256 struct inet_timewait_sock *tw;
257 struct net *net = sk->sk_net; 257 struct net *net = sock_net(sk);
258 258
259 prefetch(head->chain.first); 259 prefetch(head->chain.first);
260 write_lock(lock); 260 write_lock(lock);
@@ -406,7 +406,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
406 struct inet_bind_hashbucket *head; 406 struct inet_bind_hashbucket *head;
407 struct inet_bind_bucket *tb; 407 struct inet_bind_bucket *tb;
408 int ret; 408 int ret;
409 struct net *net = sk->sk_net; 409 struct net *net = sock_net(sk);
410 410
411 if (!snum) { 411 if (!snum) {
412 int i, remaining, low, high, port; 412 int i, remaining, low, high, port;
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index 717c411a5c6b..f12bc24de46f 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
124 tw->tw_hash = sk->sk_hash; 124 tw->tw_hash = sk->sk_hash;
125 tw->tw_ipv6only = 0; 125 tw->tw_ipv6only = 0;
126 tw->tw_prot = sk->sk_prot_creator; 126 tw->tw_prot = sk->sk_prot_creator;
127 tw->tw_net = sk->sk_net; 127 twsk_net_set(tw, sock_net(sk));
128 atomic_set(&tw->tw_refcnt, 1); 128 atomic_set(&tw->tw_refcnt, 1);
129 inet_twsk_dead_node_init(tw); 129 inet_twsk_dead_node_init(tw);
130 __module_get(tw->tw_prot->owner); 130 __module_get(tw->tw_prot->owner);
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 26685c83a146..4be00959b748 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -172,7 +172,7 @@ int ip_call_ra_chain(struct sk_buff *skb)
172 if (sk && inet_sk(sk)->num == protocol && 172 if (sk && inet_sk(sk)->num == protocol &&
173 (!sk->sk_bound_dev_if || 173 (!sk->sk_bound_dev_if ||
174 sk->sk_bound_dev_if == dev->ifindex) && 174 sk->sk_bound_dev_if == dev->ifindex) &&
175 sk->sk_net == dev_net(dev)) { 175 sock_net(sk) == dev_net(dev)) {
176 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { 176 if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) {
177 if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN)) { 177 if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN)) {
178 read_unlock(&ip_ra_lock); 178 read_unlock(&ip_ra_lock);
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 913266cd9902..08349267ceb4 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -351,7 +351,7 @@ int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
351 * itself out. 351 * itself out.
352 */ 352 */
353 security_sk_classify_flow(sk, &fl); 353 security_sk_classify_flow(sk, &fl);
354 if (ip_route_output_flow(sk->sk_net, &rt, &fl, sk, 0)) 354 if (ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 0))
355 goto no_route; 355 goto no_route;
356 } 356 }
357 sk_setup_caps(sk, &rt->u.dst); 357 sk_setup_caps(sk, &rt->u.dst);
@@ -1382,7 +1382,7 @@ void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *ar
1382 .dport = tcp_hdr(skb)->source } }, 1382 .dport = tcp_hdr(skb)->source } },
1383 .proto = sk->sk_protocol }; 1383 .proto = sk->sk_protocol };
1384 security_skb_classify_flow(skb, &fl); 1384 security_skb_classify_flow(skb, &fl);
1385 if (ip_route_output_key(sk->sk_net, &rt, &fl)) 1385 if (ip_route_output_key(sock_net(sk), &rt, &fl))
1386 return; 1386 return;
1387 } 1387 }
1388 1388
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index b854431047a4..d6e76f5229cc 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -449,7 +449,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
449 struct ip_options * opt = NULL; 449 struct ip_options * opt = NULL;
450 if (optlen > 40 || optlen < 0) 450 if (optlen > 40 || optlen < 0)
451 goto e_inval; 451 goto e_inval;
452 err = ip_options_get_from_user(sk->sk_net, &opt, 452 err = ip_options_get_from_user(sock_net(sk), &opt,
453 optval, optlen); 453 optval, optlen);
454 if (err) 454 if (err)
455 break; 455 break;
@@ -590,13 +590,13 @@ static int do_ip_setsockopt(struct sock *sk, int level,
590 err = 0; 590 err = 0;
591 break; 591 break;
592 } 592 }
593 dev = ip_dev_find(sk->sk_net, mreq.imr_address.s_addr); 593 dev = ip_dev_find(sock_net(sk), mreq.imr_address.s_addr);
594 if (dev) { 594 if (dev) {
595 mreq.imr_ifindex = dev->ifindex; 595 mreq.imr_ifindex = dev->ifindex;
596 dev_put(dev); 596 dev_put(dev);
597 } 597 }
598 } else 598 } else
599 dev = __dev_get_by_index(sk->sk_net, mreq.imr_ifindex); 599 dev = __dev_get_by_index(sock_net(sk), mreq.imr_ifindex);
600 600
601 601
602 err = -EADDRNOTAVAIL; 602 err = -EADDRNOTAVAIL;
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index e54bc1364473..11700a4dcd95 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -849,7 +849,7 @@ static void mrtsock_destruct(struct sock *sk)
849{ 849{
850 rtnl_lock(); 850 rtnl_lock();
851 if (sk == mroute_socket) { 851 if (sk == mroute_socket) {
852 IPV4_DEVCONF_ALL(sk->sk_net, MC_FORWARDING)--; 852 IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)--;
853 853
854 write_lock_bh(&mrt_lock); 854 write_lock_bh(&mrt_lock);
855 mroute_socket=NULL; 855 mroute_socket=NULL;
@@ -898,7 +898,7 @@ int ip_mroute_setsockopt(struct sock *sk,int optname,char __user *optval,int opt
898 mroute_socket=sk; 898 mroute_socket=sk;
899 write_unlock_bh(&mrt_lock); 899 write_unlock_bh(&mrt_lock);
900 900
901 IPV4_DEVCONF_ALL(sk->sk_net, MC_FORWARDING)++; 901 IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)++;
902 } 902 }
903 rtnl_unlock(); 903 rtnl_unlock();
904 return ret; 904 return ret;
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 756bc0e1a7c6..1563f29b5117 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -1496,11 +1496,11 @@ static int compat_do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user,
1496 1496
1497 switch (cmd) { 1497 switch (cmd) {
1498 case ARPT_SO_SET_REPLACE: 1498 case ARPT_SO_SET_REPLACE:
1499 ret = compat_do_replace(sk->sk_net, user, len); 1499 ret = compat_do_replace(sock_net(sk), user, len);
1500 break; 1500 break;
1501 1501
1502 case ARPT_SO_SET_ADD_COUNTERS: 1502 case ARPT_SO_SET_ADD_COUNTERS:
1503 ret = do_add_counters(sk->sk_net, user, len, 1); 1503 ret = do_add_counters(sock_net(sk), user, len, 1);
1504 break; 1504 break;
1505 1505
1506 default: 1506 default:
@@ -1644,10 +1644,10 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
1644 1644
1645 switch (cmd) { 1645 switch (cmd) {
1646 case ARPT_SO_GET_INFO: 1646 case ARPT_SO_GET_INFO:
1647 ret = get_info(sk->sk_net, user, len, 1); 1647 ret = get_info(sock_net(sk), user, len, 1);
1648 break; 1648 break;
1649 case ARPT_SO_GET_ENTRIES: 1649 case ARPT_SO_GET_ENTRIES:
1650 ret = compat_get_entries(sk->sk_net, user, len); 1650 ret = compat_get_entries(sock_net(sk), user, len);
1651 break; 1651 break;
1652 default: 1652 default:
1653 ret = do_arpt_get_ctl(sk, cmd, user, len); 1653 ret = do_arpt_get_ctl(sk, cmd, user, len);
@@ -1665,11 +1665,11 @@ static int do_arpt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned
1665 1665
1666 switch (cmd) { 1666 switch (cmd) {
1667 case ARPT_SO_SET_REPLACE: 1667 case ARPT_SO_SET_REPLACE:
1668 ret = do_replace(sk->sk_net, user, len); 1668 ret = do_replace(sock_net(sk), user, len);
1669 break; 1669 break;
1670 1670
1671 case ARPT_SO_SET_ADD_COUNTERS: 1671 case ARPT_SO_SET_ADD_COUNTERS:
1672 ret = do_add_counters(sk->sk_net, user, len, 0); 1672 ret = do_add_counters(sock_net(sk), user, len, 0);
1673 break; 1673 break;
1674 1674
1675 default: 1675 default:
@@ -1689,11 +1689,11 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
1689 1689
1690 switch (cmd) { 1690 switch (cmd) {
1691 case ARPT_SO_GET_INFO: 1691 case ARPT_SO_GET_INFO:
1692 ret = get_info(sk->sk_net, user, len, 0); 1692 ret = get_info(sock_net(sk), user, len, 0);
1693 break; 1693 break;
1694 1694
1695 case ARPT_SO_GET_ENTRIES: 1695 case ARPT_SO_GET_ENTRIES:
1696 ret = get_entries(sk->sk_net, user, len); 1696 ret = get_entries(sock_net(sk), user, len);
1697 break; 1697 break;
1698 1698
1699 case ARPT_SO_GET_REVISION_TARGET: { 1699 case ARPT_SO_GET_REVISION_TARGET: {
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 85a75e186b4b..a819d191e1aa 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1852,11 +1852,11 @@ compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user,
1852 1852
1853 switch (cmd) { 1853 switch (cmd) {
1854 case IPT_SO_SET_REPLACE: 1854 case IPT_SO_SET_REPLACE:
1855 ret = compat_do_replace(sk->sk_net, user, len); 1855 ret = compat_do_replace(sock_net(sk), user, len);
1856 break; 1856 break;
1857 1857
1858 case IPT_SO_SET_ADD_COUNTERS: 1858 case IPT_SO_SET_ADD_COUNTERS:
1859 ret = do_add_counters(sk->sk_net, user, len, 1); 1859 ret = do_add_counters(sock_net(sk), user, len, 1);
1860 break; 1860 break;
1861 1861
1862 default: 1862 default:
@@ -1963,10 +1963,10 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1963 1963
1964 switch (cmd) { 1964 switch (cmd) {
1965 case IPT_SO_GET_INFO: 1965 case IPT_SO_GET_INFO:
1966 ret = get_info(sk->sk_net, user, len, 1); 1966 ret = get_info(sock_net(sk), user, len, 1);
1967 break; 1967 break;
1968 case IPT_SO_GET_ENTRIES: 1968 case IPT_SO_GET_ENTRIES:
1969 ret = compat_get_entries(sk->sk_net, user, len); 1969 ret = compat_get_entries(sock_net(sk), user, len);
1970 break; 1970 break;
1971 default: 1971 default:
1972 ret = do_ipt_get_ctl(sk, cmd, user, len); 1972 ret = do_ipt_get_ctl(sk, cmd, user, len);
@@ -1985,11 +1985,11 @@ do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
1985 1985
1986 switch (cmd) { 1986 switch (cmd) {
1987 case IPT_SO_SET_REPLACE: 1987 case IPT_SO_SET_REPLACE:
1988 ret = do_replace(sk->sk_net, user, len); 1988 ret = do_replace(sock_net(sk), user, len);
1989 break; 1989 break;
1990 1990
1991 case IPT_SO_SET_ADD_COUNTERS: 1991 case IPT_SO_SET_ADD_COUNTERS:
1992 ret = do_add_counters(sk->sk_net, user, len, 0); 1992 ret = do_add_counters(sock_net(sk), user, len, 0);
1993 break; 1993 break;
1994 1994
1995 default: 1995 default:
@@ -2010,11 +2010,11 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
2010 2010
2011 switch (cmd) { 2011 switch (cmd) {
2012 case IPT_SO_GET_INFO: 2012 case IPT_SO_GET_INFO:
2013 ret = get_info(sk->sk_net, user, len, 0); 2013 ret = get_info(sock_net(sk), user, len, 0);
2014 break; 2014 break;
2015 2015
2016 case IPT_SO_GET_ENTRIES: 2016 case IPT_SO_GET_ENTRIES:
2017 ret = get_entries(sk->sk_net, user, len); 2017 ret = get_entries(sock_net(sk), user, len);
2018 break; 2018 break;
2019 2019
2020 case IPT_SO_GET_REVISION_MATCH: 2020 case IPT_SO_GET_REVISION_MATCH:
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 8756d502a47f..be19a4048d7c 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
117 sk_for_each_from(sk, node) { 117 sk_for_each_from(sk, node) {
118 struct inet_sock *inet = inet_sk(sk); 118 struct inet_sock *inet = inet_sk(sk);
119 119
120 if (sk->sk_net == net && inet->num == num && 120 if (sock_net(sk) == net && inet->num == num &&
121 !(inet->daddr && inet->daddr != raddr) && 121 !(inet->daddr && inet->daddr != raddr) &&
122 !(inet->rcv_saddr && inet->rcv_saddr != laddr) && 122 !(inet->rcv_saddr && inet->rcv_saddr != laddr) &&
123 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)) 123 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
@@ -499,7 +499,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
499 ipc.oif = sk->sk_bound_dev_if; 499 ipc.oif = sk->sk_bound_dev_if;
500 500
501 if (msg->msg_controllen) { 501 if (msg->msg_controllen) {
502 err = ip_cmsg_send(sk->sk_net, msg, &ipc); 502 err = ip_cmsg_send(sock_net(sk), msg, &ipc);
503 if (err) 503 if (err)
504 goto out; 504 goto out;
505 if (ipc.opt) 505 if (ipc.opt)
@@ -553,7 +553,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
553 } 553 }
554 554
555 security_sk_classify_flow(sk, &fl); 555 security_sk_classify_flow(sk, &fl);
556 err = ip_route_output_flow(sk->sk_net, &rt, &fl, sk, 1); 556 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
557 } 557 }
558 if (err) 558 if (err)
559 goto done; 559 goto done;
@@ -620,7 +620,7 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
620 620
621 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in)) 621 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
622 goto out; 622 goto out;
623 chk_addr_ret = inet_addr_type(sk->sk_net, addr->sin_addr.s_addr); 623 chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
624 ret = -EADDRNOTAVAIL; 624 ret = -EADDRNOTAVAIL;
625 if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL && 625 if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
626 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) 626 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
@@ -856,7 +856,7 @@ static struct sock *raw_get_first(struct seq_file *seq)
856 struct hlist_node *node; 856 struct hlist_node *node;
857 857
858 sk_for_each(sk, node, &state->h->ht[state->bucket]) 858 sk_for_each(sk, node, &state->h->ht[state->bucket])
859 if (sk->sk_net == state->p.net) 859 if (sock_net(sk) == state->p.net)
860 goto found; 860 goto found;
861 } 861 }
862 sk = NULL; 862 sk = NULL;
@@ -872,7 +872,7 @@ static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk)
872 sk = sk_next(sk); 872 sk = sk_next(sk);
873try_again: 873try_again:
874 ; 874 ;
875 } while (sk && sk->sk_net != state->p.net); 875 } while (sk && sock_net(sk) != state->p.net);
876 876
877 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) { 877 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
878 sk = sk_head(&state->h->ht[state->bucket]); 878 sk = sk_head(&state->h->ht[state->bucket]);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 7768d718e199..194f5cca3121 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2689,7 +2689,7 @@ nla_put_failure:
2689 2689
2690static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg) 2690static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
2691{ 2691{
2692 struct net *net = in_skb->sk->sk_net; 2692 struct net *net = sock_net(in_skb->sk);
2693 struct rtmsg *rtm; 2693 struct rtmsg *rtm;
2694 struct nlattr *tb[RTA_MAX+1]; 2694 struct nlattr *tb[RTA_MAX+1];
2695 struct rtable *rt = NULL; 2695 struct rtable *rt = NULL;
@@ -2785,7 +2785,7 @@ int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb)
2785 int idx, s_idx; 2785 int idx, s_idx;
2786 struct net *net; 2786 struct net *net;
2787 2787
2788 net = skb->sk->sk_net; 2788 net = sock_net(skb->sk);
2789 2789
2790 s_h = cb->args[0]; 2790 s_h = cb->args[0];
2791 if (s_h < 0) 2791 if (s_h < 0)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 28bece6f281b..46847e600a46 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1486,7 +1486,7 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
1486 if (req) 1486 if (req)
1487 return tcp_check_req(sk, skb, req, prev); 1487 return tcp_check_req(sk, skb, req, prev);
1488 1488
1489 nsk = inet_lookup_established(sk->sk_net, &tcp_hashinfo, iph->saddr, 1489 nsk = inet_lookup_established(sock_net(sk), &tcp_hashinfo, iph->saddr,
1490 th->source, iph->daddr, th->dest, inet_iif(skb)); 1490 th->source, iph->daddr, th->dest, inet_iif(skb));
1491 1491
1492 if (nsk) { 1492 if (nsk) {
@@ -1974,7 +1974,7 @@ static void *listening_get_next(struct seq_file *seq, void *cur)
1974 while (1) { 1974 while (1) {
1975 while (req) { 1975 while (req) {
1976 if (req->rsk_ops->family == st->family && 1976 if (req->rsk_ops->family == st->family &&
1977 req->sk->sk_net == net) { 1977 sock_net(req->sk) == net) {
1978 cur = req; 1978 cur = req;
1979 goto out; 1979 goto out;
1980 } 1980 }
@@ -1998,7 +1998,7 @@ get_req:
1998 } 1998 }
1999get_sk: 1999get_sk:
2000 sk_for_each_from(sk, node) { 2000 sk_for_each_from(sk, node) {
2001 if (sk->sk_family == st->family && sk->sk_net == net) { 2001 if (sk->sk_family == st->family && sock_net(sk) == net) {
2002 cur = sk; 2002 cur = sk;
2003 goto out; 2003 goto out;
2004 } 2004 }
@@ -2049,7 +2049,7 @@ static void *established_get_first(struct seq_file *seq)
2049 read_lock_bh(lock); 2049 read_lock_bh(lock);
2050 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) { 2050 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
2051 if (sk->sk_family != st->family || 2051 if (sk->sk_family != st->family ||
2052 sk->sk_net != net) { 2052 sock_net(sk) != net) {
2053 continue; 2053 continue;
2054 } 2054 }
2055 rc = sk; 2055 rc = sk;
@@ -2059,7 +2059,7 @@ static void *established_get_first(struct seq_file *seq)
2059 inet_twsk_for_each(tw, node, 2059 inet_twsk_for_each(tw, node,
2060 &tcp_hashinfo.ehash[st->bucket].twchain) { 2060 &tcp_hashinfo.ehash[st->bucket].twchain) {
2061 if (tw->tw_family != st->family || 2061 if (tw->tw_family != st->family ||
2062 tw->tw_net != net) { 2062 twsk_net(tw) != net) {
2063 continue; 2063 continue;
2064 } 2064 }
2065 rc = tw; 2065 rc = tw;
@@ -2086,7 +2086,7 @@ static void *established_get_next(struct seq_file *seq, void *cur)
2086 tw = cur; 2086 tw = cur;
2087 tw = tw_next(tw); 2087 tw = tw_next(tw);
2088get_tw: 2088get_tw:
2089 while (tw && (tw->tw_family != st->family || tw->tw_net != net)) { 2089 while (tw && (tw->tw_family != st->family || twsk_net(tw) != net)) {
2090 tw = tw_next(tw); 2090 tw = tw_next(tw);
2091 } 2091 }
2092 if (tw) { 2092 if (tw) {
@@ -2107,7 +2107,7 @@ get_tw:
2107 sk = sk_next(sk); 2107 sk = sk_next(sk);
2108 2108
2109 sk_for_each_from(sk, node) { 2109 sk_for_each_from(sk, node) {
2110 if (sk->sk_family == st->family && sk->sk_net == net) 2110 if (sk->sk_family == st->family && sock_net(sk) == net)
2111 goto found; 2111 goto found;
2112 } 2112 }
2113 2113
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index e2cd93481359..76d52d37d6ac 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -137,7 +137,7 @@ static inline int __udp_lib_lport_inuse(struct net *net, __u16 num,
137 struct hlist_node *node; 137 struct hlist_node *node;
138 138
139 sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)]) 139 sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)])
140 if (sk->sk_net == net && sk->sk_hash == num) 140 if (sock_net(sk) == net && sk->sk_hash == num)
141 return 1; 141 return 1;
142 return 0; 142 return 0;
143} 143}
@@ -158,7 +158,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
158 struct hlist_head *head; 158 struct hlist_head *head;
159 struct sock *sk2; 159 struct sock *sk2;
160 int error = 1; 160 int error = 1;
161 struct net *net = sk->sk_net; 161 struct net *net = sock_net(sk);
162 162
163 write_lock_bh(&udp_hash_lock); 163 write_lock_bh(&udp_hash_lock);
164 164
@@ -218,7 +218,7 @@ gotit:
218 sk_for_each(sk2, node, head) 218 sk_for_each(sk2, node, head)
219 if (sk2->sk_hash == snum && 219 if (sk2->sk_hash == snum &&
220 sk2 != sk && 220 sk2 != sk &&
221 sk2->sk_net == net && 221 sock_net(sk2) == net &&
222 (!sk2->sk_reuse || !sk->sk_reuse) && 222 (!sk2->sk_reuse || !sk->sk_reuse) &&
223 (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if 223 (!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if
224 || sk2->sk_bound_dev_if == sk->sk_bound_dev_if) && 224 || sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
@@ -269,7 +269,7 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
269 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) { 269 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
270 struct inet_sock *inet = inet_sk(sk); 270 struct inet_sock *inet = inet_sk(sk);
271 271
272 if (sk->sk_net == net && sk->sk_hash == hnum && 272 if (sock_net(sk) == net && sk->sk_hash == hnum &&
273 !ipv6_only_sock(sk)) { 273 !ipv6_only_sock(sk)) {
274 int score = (sk->sk_family == PF_INET ? 1 : 0); 274 int score = (sk->sk_family == PF_INET ? 1 : 0);
275 if (inet->rcv_saddr) { 275 if (inet->rcv_saddr) {
@@ -607,7 +607,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
607 607
608 ipc.oif = sk->sk_bound_dev_if; 608 ipc.oif = sk->sk_bound_dev_if;
609 if (msg->msg_controllen) { 609 if (msg->msg_controllen) {
610 err = ip_cmsg_send(sk->sk_net, msg, &ipc); 610 err = ip_cmsg_send(sock_net(sk), msg, &ipc);
611 if (err) 611 if (err)
612 return err; 612 return err;
613 if (ipc.opt) 613 if (ipc.opt)
@@ -656,7 +656,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
656 { .sport = inet->sport, 656 { .sport = inet->sport,
657 .dport = dport } } }; 657 .dport = dport } } };
658 security_sk_classify_flow(sk, &fl); 658 security_sk_classify_flow(sk, &fl);
659 err = ip_route_output_flow(sk->sk_net, &rt, &fl, sk, 1); 659 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
660 if (err) { 660 if (err) {
661 if (err == -ENETUNREACH) 661 if (err == -ENETUNREACH)
662 IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES); 662 IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
@@ -1511,7 +1511,7 @@ static struct sock *udp_get_first(struct seq_file *seq)
1511 for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) { 1511 for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
1512 struct hlist_node *node; 1512 struct hlist_node *node;
1513 sk_for_each(sk, node, state->hashtable + state->bucket) { 1513 sk_for_each(sk, node, state->hashtable + state->bucket) {
1514 if (sk->sk_net != net) 1514 if (sock_net(sk) != net)
1515 continue; 1515 continue;
1516 if (sk->sk_family == state->family) 1516 if (sk->sk_family == state->family)
1517 goto found; 1517 goto found;
@@ -1531,7 +1531,7 @@ static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
1531 sk = sk_next(sk); 1531 sk = sk_next(sk);
1532try_again: 1532try_again:
1533 ; 1533 ;
1534 } while (sk && (sk->sk_net != net || sk->sk_family != state->family)); 1534 } while (sk && (sock_net(sk) != net || sk->sk_family != state->family));
1535 1535
1536 if (!sk && ++state->bucket < UDP_HTABLE_SIZE) { 1536 if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
1537 sk = sk_head(state->hashtable + state->bucket); 1537 sk = sk_head(state->hashtable + state->bucket);
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index d1de9ec74261..f2c90f145cbb 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3054,7 +3054,7 @@ static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = {
3054static int 3054static int
3055inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 3055inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
3056{ 3056{
3057 struct net *net = skb->sk->sk_net; 3057 struct net *net = sock_net(skb->sk);
3058 struct ifaddrmsg *ifm; 3058 struct ifaddrmsg *ifm;
3059 struct nlattr *tb[IFA_MAX+1]; 3059 struct nlattr *tb[IFA_MAX+1];
3060 struct in6_addr *pfx; 3060 struct in6_addr *pfx;
@@ -3112,7 +3112,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
3112static int 3112static int
3113inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 3113inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
3114{ 3114{
3115 struct net *net = skb->sk->sk_net; 3115 struct net *net = sock_net(skb->sk);
3116 struct ifaddrmsg *ifm; 3116 struct ifaddrmsg *ifm;
3117 struct nlattr *tb[IFA_MAX+1]; 3117 struct nlattr *tb[IFA_MAX+1];
3118 struct in6_addr *pfx; 3118 struct in6_addr *pfx;
@@ -3322,7 +3322,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
3322 struct inet6_ifaddr *ifa; 3322 struct inet6_ifaddr *ifa;
3323 struct ifmcaddr6 *ifmca; 3323 struct ifmcaddr6 *ifmca;
3324 struct ifacaddr6 *ifaca; 3324 struct ifacaddr6 *ifaca;
3325 struct net *net = skb->sk->sk_net; 3325 struct net *net = sock_net(skb->sk);
3326 3326
3327 s_idx = cb->args[0]; 3327 s_idx = cb->args[0];
3328 s_ip_idx = ip_idx = cb->args[1]; 3328 s_ip_idx = ip_idx = cb->args[1];
@@ -3418,7 +3418,7 @@ static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
3418static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh, 3418static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
3419 void *arg) 3419 void *arg)
3420{ 3420{
3421 struct net *net = in_skb->sk->sk_net; 3421 struct net *net = sock_net(in_skb->sk);
3422 struct ifaddrmsg *ifm; 3422 struct ifaddrmsg *ifm;
3423 struct nlattr *tb[IFA_MAX+1]; 3423 struct nlattr *tb[IFA_MAX+1];
3424 struct in6_addr *addr = NULL; 3424 struct in6_addr *addr = NULL;
@@ -3645,7 +3645,7 @@ nla_put_failure:
3645 3645
3646static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) 3646static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3647{ 3647{
3648 struct net *net = skb->sk->sk_net; 3648 struct net *net = sock_net(skb->sk);
3649 int idx, err; 3649 int idx, err;
3650 int s_idx = cb->args[0]; 3650 int s_idx = cb->args[0];
3651 struct net_device *dev; 3651 struct net_device *dev;
diff --git a/net/ipv6/addrlabel.c b/net/ipv6/addrlabel.c
index de371b5997fe..9bfa8846f262 100644
--- a/net/ipv6/addrlabel.c
+++ b/net/ipv6/addrlabel.c
@@ -364,7 +364,7 @@ static const struct nla_policy ifal_policy[IFAL_MAX+1] = {
364static int ip6addrlbl_newdel(struct sk_buff *skb, struct nlmsghdr *nlh, 364static int ip6addrlbl_newdel(struct sk_buff *skb, struct nlmsghdr *nlh,
365 void *arg) 365 void *arg)
366{ 366{
367 struct net *net = skb->sk->sk_net; 367 struct net *net = sock_net(skb->sk);
368 struct ifaddrlblmsg *ifal; 368 struct ifaddrlblmsg *ifal;
369 struct nlattr *tb[IFAL_MAX+1]; 369 struct nlattr *tb[IFAL_MAX+1];
370 struct in6_addr *pfx; 370 struct in6_addr *pfx;
@@ -452,7 +452,7 @@ static int ip6addrlbl_fill(struct sk_buff *skb,
452 452
453static int ip6addrlbl_dump(struct sk_buff *skb, struct netlink_callback *cb) 453static int ip6addrlbl_dump(struct sk_buff *skb, struct netlink_callback *cb)
454{ 454{
455 struct net *net = skb->sk->sk_net; 455 struct net *net = sock_net(skb->sk);
456 struct ip6addrlbl_entry *p; 456 struct ip6addrlbl_entry *p;
457 struct hlist_node *pos; 457 struct hlist_node *pos;
458 int idx = 0, s_idx = cb->args[0]; 458 int idx = 0, s_idx = cb->args[0];
@@ -490,7 +490,7 @@ static inline int ip6addrlbl_msgsize(void)
490static int ip6addrlbl_get(struct sk_buff *in_skb, struct nlmsghdr* nlh, 490static int ip6addrlbl_get(struct sk_buff *in_skb, struct nlmsghdr* nlh,
491 void *arg) 491 void *arg)
492{ 492{
493 struct net *net = in_skb->sk->sk_net; 493 struct net *net = sock_net(in_skb->sk);
494 struct ifaddrlblmsg *ifal; 494 struct ifaddrlblmsg *ifal;
495 struct nlattr *tb[IFAL_MAX+1]; 495 struct nlattr *tb[IFAL_MAX+1];
496 struct in6_addr *addr; 496 struct in6_addr *addr;
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index f52bdaed8a1b..12f04e9d3e88 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -245,7 +245,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
245 struct sock *sk = sock->sk; 245 struct sock *sk = sock->sk;
246 struct inet_sock *inet = inet_sk(sk); 246 struct inet_sock *inet = inet_sk(sk);
247 struct ipv6_pinfo *np = inet6_sk(sk); 247 struct ipv6_pinfo *np = inet6_sk(sk);
248 struct net *net = sk->sk_net; 248 struct net *net = sock_net(sk);
249 __be32 v4addr = 0; 249 __be32 v4addr = 0;
250 unsigned short snum; 250 unsigned short snum;
251 int addr_type = 0; 251 int addr_type = 0;
@@ -438,7 +438,7 @@ EXPORT_SYMBOL(inet6_getname);
438int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 438int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
439{ 439{
440 struct sock *sk = sock->sk; 440 struct sock *sk = sock->sk;
441 struct net *net = sk->sk_net; 441 struct net *net = sock_net(sk);
442 442
443 switch(cmd) 443 switch(cmd)
444 { 444 {
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index e7a7fe26cebf..cac580749ebe 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -154,7 +154,7 @@ static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
154 struct nlattr **tb) 154 struct nlattr **tb)
155{ 155{
156 int err = -EINVAL; 156 int err = -EINVAL;
157 struct net *net = skb->sk->sk_net; 157 struct net *net = sock_net(skb->sk);
158 struct fib6_rule *rule6 = (struct fib6_rule *) rule; 158 struct fib6_rule *rule6 = (struct fib6_rule *) rule;
159 159
160 if (rule->action == FR_ACT_TO_TBL) { 160 if (rule->action == FR_ACT_TO_TBL) {
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 50857662e6b7..63309d10df3a 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -163,7 +163,7 @@ static inline int icmpv6_xrlim_allow(struct sock *sk, int type,
163 struct flowi *fl) 163 struct flowi *fl)
164{ 164{
165 struct dst_entry *dst; 165 struct dst_entry *dst;
166 struct net *net = sk->sk_net; 166 struct net *net = sock_net(sk);
167 int res = 0; 167 int res = 0;
168 168
169 /* Informational messages are not limited. */ 169 /* Informational messages are not limited. */
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index c0c8d2d17682..21c467675412 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -105,7 +105,7 @@ struct sock *inet6_lookup_listener(struct net *net,
105 105
106 read_lock(&hashinfo->lhash_lock); 106 read_lock(&hashinfo->lhash_lock);
107 sk_for_each(sk, node, &hashinfo->listening_hash[inet_lhashfn(hnum)]) { 107 sk_for_each(sk, node, &hashinfo->listening_hash[inet_lhashfn(hnum)]) {
108 if (sk->sk_net == net && inet_sk(sk)->num == hnum && 108 if (sock_net(sk) == net && inet_sk(sk)->num == hnum &&
109 sk->sk_family == PF_INET6) { 109 sk->sk_family == PF_INET6) {
110 const struct ipv6_pinfo *np = inet6_sk(sk); 110 const struct ipv6_pinfo *np = inet6_sk(sk);
111 111
@@ -172,7 +172,7 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
172 struct sock *sk2; 172 struct sock *sk2;
173 const struct hlist_node *node; 173 const struct hlist_node *node;
174 struct inet_timewait_sock *tw; 174 struct inet_timewait_sock *tw;
175 struct net *net = sk->sk_net; 175 struct net *net = sock_net(sk);
176 176
177 prefetch(head->chain.first); 177 prefetch(head->chain.first);
178 write_lock(lock); 178 write_lock(lock);
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index b0814b0082e7..b3f6e03c454c 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -346,7 +346,7 @@ end:
346 346
347static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) 347static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
348{ 348{
349 struct net *net = skb->sk->sk_net; 349 struct net *net = sock_net(skb->sk);
350 unsigned int h, s_h; 350 unsigned int h, s_h;
351 unsigned int e = 0, s_e; 351 unsigned int e = 0, s_e;
352 struct rt6_rtnl_dump_arg arg; 352 struct rt6_rtnl_dump_arg arg;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 556300f0eba5..a8b4da25b0a7 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -910,7 +910,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
910 struct dst_entry **dst, struct flowi *fl) 910 struct dst_entry **dst, struct flowi *fl)
911{ 911{
912 int err; 912 int err;
913 struct net *net = sk->sk_net; 913 struct net *net = sock_net(sk);
914 914
915 if (*dst == NULL) 915 if (*dst == NULL)
916 *dst = ip6_route_output(net, sk, fl); 916 *dst = ip6_route_output(net, sk, fl);
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index dc6695cc5767..d3d93d752e10 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -107,7 +107,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
107 char __user *optval, int optlen) 107 char __user *optval, int optlen)
108{ 108{
109 struct ipv6_pinfo *np = inet6_sk(sk); 109 struct ipv6_pinfo *np = inet6_sk(sk);
110 struct net *net = sk->sk_net; 110 struct net *net = sock_net(sk);
111 int val, valbool; 111 int val, valbool;
112 int retv = -ENOPROTOOPT; 112 int retv = -ENOPROTOOPT;
113 113
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 0357de8e78c8..20a3d8e2f6c6 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -181,7 +181,7 @@ int ipv6_sock_mc_join(struct sock *sk, int ifindex, struct in6_addr *addr)
181 struct net_device *dev = NULL; 181 struct net_device *dev = NULL;
182 struct ipv6_mc_socklist *mc_lst; 182 struct ipv6_mc_socklist *mc_lst;
183 struct ipv6_pinfo *np = inet6_sk(sk); 183 struct ipv6_pinfo *np = inet6_sk(sk);
184 struct net *net = sk->sk_net; 184 struct net *net = sock_net(sk);
185 int err; 185 int err;
186 186
187 if (!ipv6_addr_is_multicast(addr)) 187 if (!ipv6_addr_is_multicast(addr))
@@ -255,7 +255,7 @@ int ipv6_sock_mc_drop(struct sock *sk, int ifindex, struct in6_addr *addr)
255{ 255{
256 struct ipv6_pinfo *np = inet6_sk(sk); 256 struct ipv6_pinfo *np = inet6_sk(sk);
257 struct ipv6_mc_socklist *mc_lst, **lnk; 257 struct ipv6_mc_socklist *mc_lst, **lnk;
258 struct net *net = sk->sk_net; 258 struct net *net = sock_net(sk);
259 259
260 write_lock_bh(&ipv6_sk_mc_lock); 260 write_lock_bh(&ipv6_sk_mc_lock);
261 for (lnk = &np->ipv6_mc_list; (mc_lst = *lnk) !=NULL ; lnk = &mc_lst->next) { 261 for (lnk = &np->ipv6_mc_list; (mc_lst = *lnk) !=NULL ; lnk = &mc_lst->next) {
@@ -327,7 +327,7 @@ void ipv6_sock_mc_close(struct sock *sk)
327{ 327{
328 struct ipv6_pinfo *np = inet6_sk(sk); 328 struct ipv6_pinfo *np = inet6_sk(sk);
329 struct ipv6_mc_socklist *mc_lst; 329 struct ipv6_mc_socklist *mc_lst;
330 struct net *net = sk->sk_net; 330 struct net *net = sock_net(sk);
331 331
332 write_lock_bh(&ipv6_sk_mc_lock); 332 write_lock_bh(&ipv6_sk_mc_lock);
333 while ((mc_lst = np->ipv6_mc_list) != NULL) { 333 while ((mc_lst = np->ipv6_mc_list) != NULL) {
@@ -365,7 +365,7 @@ int ip6_mc_source(int add, int omode, struct sock *sk,
365 struct inet6_dev *idev; 365 struct inet6_dev *idev;
366 struct ipv6_pinfo *inet6 = inet6_sk(sk); 366 struct ipv6_pinfo *inet6 = inet6_sk(sk);
367 struct ip6_sf_socklist *psl; 367 struct ip6_sf_socklist *psl;
368 struct net *net = sk->sk_net; 368 struct net *net = sock_net(sk);
369 int i, j, rv; 369 int i, j, rv;
370 int leavegroup = 0; 370 int leavegroup = 0;
371 int pmclocked = 0; 371 int pmclocked = 0;
@@ -505,7 +505,7 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf)
505 struct inet6_dev *idev; 505 struct inet6_dev *idev;
506 struct ipv6_pinfo *inet6 = inet6_sk(sk); 506 struct ipv6_pinfo *inet6 = inet6_sk(sk);
507 struct ip6_sf_socklist *newpsl, *psl; 507 struct ip6_sf_socklist *newpsl, *psl;
508 struct net *net = sk->sk_net; 508 struct net *net = sock_net(sk);
509 int leavegroup = 0; 509 int leavegroup = 0;
510 int i, err; 510 int i, err;
511 511
@@ -598,7 +598,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
598 struct net_device *dev; 598 struct net_device *dev;
599 struct ipv6_pinfo *inet6 = inet6_sk(sk); 599 struct ipv6_pinfo *inet6 = inet6_sk(sk);
600 struct ip6_sf_socklist *psl; 600 struct ip6_sf_socklist *psl;
601 struct net *net = sk->sk_net; 601 struct net *net = sock_net(sk);
602 602
603 group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; 603 group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
604 604
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index af1ec7ba757c..70ef0d276cc0 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -1879,11 +1879,11 @@ compat_do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user,
1879 1879
1880 switch (cmd) { 1880 switch (cmd) {
1881 case IP6T_SO_SET_REPLACE: 1881 case IP6T_SO_SET_REPLACE:
1882 ret = compat_do_replace(sk->sk_net, user, len); 1882 ret = compat_do_replace(sock_net(sk), user, len);
1883 break; 1883 break;
1884 1884
1885 case IP6T_SO_SET_ADD_COUNTERS: 1885 case IP6T_SO_SET_ADD_COUNTERS:
1886 ret = do_add_counters(sk->sk_net, user, len, 1); 1886 ret = do_add_counters(sock_net(sk), user, len, 1);
1887 break; 1887 break;
1888 1888
1889 default: 1889 default:
@@ -1990,10 +1990,10 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1990 1990
1991 switch (cmd) { 1991 switch (cmd) {
1992 case IP6T_SO_GET_INFO: 1992 case IP6T_SO_GET_INFO:
1993 ret = get_info(sk->sk_net, user, len, 1); 1993 ret = get_info(sock_net(sk), user, len, 1);
1994 break; 1994 break;
1995 case IP6T_SO_GET_ENTRIES: 1995 case IP6T_SO_GET_ENTRIES:
1996 ret = compat_get_entries(sk->sk_net, user, len); 1996 ret = compat_get_entries(sock_net(sk), user, len);
1997 break; 1997 break;
1998 default: 1998 default:
1999 ret = do_ip6t_get_ctl(sk, cmd, user, len); 1999 ret = do_ip6t_get_ctl(sk, cmd, user, len);
@@ -2012,11 +2012,11 @@ do_ip6t_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
2012 2012
2013 switch (cmd) { 2013 switch (cmd) {
2014 case IP6T_SO_SET_REPLACE: 2014 case IP6T_SO_SET_REPLACE:
2015 ret = do_replace(sk->sk_net, user, len); 2015 ret = do_replace(sock_net(sk), user, len);
2016 break; 2016 break;
2017 2017
2018 case IP6T_SO_SET_ADD_COUNTERS: 2018 case IP6T_SO_SET_ADD_COUNTERS:
2019 ret = do_add_counters(sk->sk_net, user, len, 0); 2019 ret = do_add_counters(sock_net(sk), user, len, 0);
2020 break; 2020 break;
2021 2021
2022 default: 2022 default:
@@ -2037,11 +2037,11 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
2037 2037
2038 switch (cmd) { 2038 switch (cmd) {
2039 case IP6T_SO_GET_INFO: 2039 case IP6T_SO_GET_INFO:
2040 ret = get_info(sk->sk_net, user, len, 0); 2040 ret = get_info(sock_net(sk), user, len, 0);
2041 break; 2041 break;
2042 2042
2043 case IP6T_SO_GET_ENTRIES: 2043 case IP6T_SO_GET_ENTRIES:
2044 ret = get_entries(sk->sk_net, user, len); 2044 ret = get_entries(sock_net(sk), user, len);
2045 break; 2045 break;
2046 2046
2047 case IP6T_SO_GET_REVISION_MATCH: 2047 case IP6T_SO_GET_REVISION_MATCH:
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index efb0047f6880..12c7a1560977 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -76,7 +76,7 @@ static struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
76 if (inet_sk(sk)->num == num) { 76 if (inet_sk(sk)->num == num) {
77 struct ipv6_pinfo *np = inet6_sk(sk); 77 struct ipv6_pinfo *np = inet6_sk(sk);
78 78
79 if (sk->sk_net != net) 79 if (sock_net(sk) != net)
80 continue; 80 continue;
81 81
82 if (!ipv6_addr_any(&np->daddr) && 82 if (!ipv6_addr_any(&np->daddr) &&
@@ -280,7 +280,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
280 if (!sk->sk_bound_dev_if) 280 if (!sk->sk_bound_dev_if)
281 goto out; 281 goto out;
282 282
283 dev = dev_get_by_index(sk->sk_net, sk->sk_bound_dev_if); 283 dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if);
284 if (!dev) { 284 if (!dev) {
285 err = -ENODEV; 285 err = -ENODEV;
286 goto out; 286 goto out;
@@ -293,7 +293,7 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
293 v4addr = LOOPBACK4_IPV6; 293 v4addr = LOOPBACK4_IPV6;
294 if (!(addr_type & IPV6_ADDR_MULTICAST)) { 294 if (!(addr_type & IPV6_ADDR_MULTICAST)) {
295 err = -EADDRNOTAVAIL; 295 err = -EADDRNOTAVAIL;
296 if (!ipv6_chk_addr(sk->sk_net, &addr->sin6_addr, 296 if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr,
297 dev, 0)) { 297 dev, 0)) {
298 if (dev) 298 if (dev)
299 dev_put(dev); 299 dev_put(dev);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 65053fba8c1a..ac4428371432 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2020,7 +2020,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
2020 2020
2021 cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid; 2021 cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid;
2022 cfg->fc_nlinfo.nlh = nlh; 2022 cfg->fc_nlinfo.nlh = nlh;
2023 cfg->fc_nlinfo.nl_net = skb->sk->sk_net; 2023 cfg->fc_nlinfo.nl_net = sock_net(skb->sk);
2024 2024
2025 if (tb[RTA_GATEWAY]) { 2025 if (tb[RTA_GATEWAY]) {
2026 nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16); 2026 nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16);
@@ -2216,7 +2216,7 @@ int rt6_dump_route(struct rt6_info *rt, void *p_arg)
2216 2216
2217static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg) 2217static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
2218{ 2218{
2219 struct net *net = in_skb->sk->sk_net; 2219 struct net *net = sock_net(in_skb->sk);
2220 struct nlattr *tb[RTA_MAX+1]; 2220 struct nlattr *tb[RTA_MAX+1];
2221 struct rt6_info *rt; 2221 struct rt6_info *rt;
2222 struct sk_buff *skb; 2222 struct sk_buff *skb;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 086deffff9c9..323c7e06ef43 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1218,7 +1218,7 @@ static struct sock *tcp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
1218 if (req) 1218 if (req)
1219 return tcp_check_req(sk, skb, req, prev); 1219 return tcp_check_req(sk, skb, req, prev);
1220 1220
1221 nsk = __inet6_lookup_established(sk->sk_net, &tcp_hashinfo, 1221 nsk = __inet6_lookup_established(sock_net(sk), &tcp_hashinfo,
1222 &ipv6_hdr(skb)->saddr, th->source, 1222 &ipv6_hdr(skb)->saddr, th->source,
1223 &ipv6_hdr(skb)->daddr, ntohs(th->dest), inet6_iif(skb)); 1223 &ipv6_hdr(skb)->daddr, ntohs(th->dest), inet6_iif(skb));
1224 1224
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 6683c04b427e..db266ff297e5 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -70,7 +70,7 @@ static struct sock *__udp6_lib_lookup(struct net *net,
70 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) { 70 sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
71 struct inet_sock *inet = inet_sk(sk); 71 struct inet_sock *inet = inet_sk(sk);
72 72
73 if (sk->sk_net == net && sk->sk_hash == hnum && 73 if (sock_net(sk) == net && sk->sk_hash == hnum &&
74 sk->sk_family == PF_INET6) { 74 sk->sk_family == PF_INET6) {
75 struct ipv6_pinfo *np = inet6_sk(sk); 75 struct ipv6_pinfo *np = inet6_sk(sk);
76 int score = 0; 76 int score = 0;
@@ -323,7 +323,7 @@ static struct sock *udp_v6_mcast_next(struct sock *sk,
323 sk_for_each_from(s, node) { 323 sk_for_each_from(s, node) {
324 struct inet_sock *inet = inet_sk(s); 324 struct inet_sock *inet = inet_sk(s);
325 325
326 if (s->sk_net != sk->sk_net) 326 if (sock_net(s) != sock_net(sk))
327 continue; 327 continue;
328 328
329 if (s->sk_hash == num && s->sk_family == PF_INET6) { 329 if (s->sk_hash == num && s->sk_family == PF_INET6) {
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index 6f21a53cb3e7..ae54b20d0470 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -837,7 +837,7 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
837 837
838 IRDA_DEBUG(2, "%s()\n", __func__); 838 IRDA_DEBUG(2, "%s()\n", __func__);
839 839
840 err = irda_create(sk->sk_net, newsock, sk->sk_protocol); 840 err = irda_create(sock_net(sk), newsock, sk->sk_protocol);
841 if (err) 841 if (err)
842 return err; 842 return err;
843 843
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index 5ebfd93ff5e7..5c6d89c6d51d 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -700,7 +700,7 @@ static struct sock *llc_create_incoming_sock(struct sock *sk,
700 struct llc_addr *saddr, 700 struct llc_addr *saddr,
701 struct llc_addr *daddr) 701 struct llc_addr *daddr)
702{ 702{
703 struct sock *newsk = llc_sk_alloc(sk->sk_net, sk->sk_family, GFP_ATOMIC, 703 struct sock *newsk = llc_sk_alloc(sock_net(sk), sk->sk_family, GFP_ATOMIC,
704 sk->sk_prot); 704 sk->sk_prot);
705 struct llc_sock *newllc, *llc = llc_sk(sk); 705 struct llc_sock *newllc, *llc = llc_sk(sk);
706 706
diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
index 3dd4b3c76d81..69d699f95f4c 100644
--- a/net/netfilter/nf_sockopt.c
+++ b/net/netfilter/nf_sockopt.c
@@ -65,7 +65,7 @@ static struct nf_sockopt_ops *nf_sockopt_find(struct sock *sk, int pf,
65{ 65{
66 struct nf_sockopt_ops *ops; 66 struct nf_sockopt_ops *ops;
67 67
68 if (sk->sk_net != &init_net) 68 if (sock_net(sk) != &init_net)
69 return ERR_PTR(-ENOPROTOOPT); 69 return ERR_PTR(-ENOPROTOOPT);
70 70
71 if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0) 71 if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 86bd8660a8f2..712a7bff8560 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -228,7 +228,7 @@ static inline struct sock *netlink_lookup(struct net *net, int protocol,
228 read_lock(&nl_table_lock); 228 read_lock(&nl_table_lock);
229 head = nl_pid_hashfn(hash, pid); 229 head = nl_pid_hashfn(hash, pid);
230 sk_for_each(sk, node, head) { 230 sk_for_each(sk, node, head) {
231 if ((sk->sk_net == net) && (nlk_sk(sk)->pid == pid)) { 231 if (sock_net(sk) == net && (nlk_sk(sk)->pid == pid)) {
232 sock_hold(sk); 232 sock_hold(sk);
233 goto found; 233 goto found;
234 } 234 }
@@ -348,7 +348,7 @@ static int netlink_insert(struct sock *sk, struct net *net, u32 pid)
348 head = nl_pid_hashfn(hash, pid); 348 head = nl_pid_hashfn(hash, pid);
349 len = 0; 349 len = 0;
350 sk_for_each(osk, node, head) { 350 sk_for_each(osk, node, head) {
351 if ((osk->sk_net == net) && (nlk_sk(osk)->pid == pid)) 351 if (sock_net(osk) == net && (nlk_sk(osk)->pid == pid))
352 break; 352 break;
353 len++; 353 len++;
354 } 354 }
@@ -486,7 +486,7 @@ static int netlink_release(struct socket *sock)
486 486
487 if (nlk->pid && !nlk->subscriptions) { 487 if (nlk->pid && !nlk->subscriptions) {
488 struct netlink_notify n = { 488 struct netlink_notify n = {
489 .net = sk->sk_net, 489 .net = sock_net(sk),
490 .protocol = sk->sk_protocol, 490 .protocol = sk->sk_protocol,
491 .pid = nlk->pid, 491 .pid = nlk->pid,
492 }; 492 };
@@ -518,7 +518,7 @@ static int netlink_release(struct socket *sock)
518static int netlink_autobind(struct socket *sock) 518static int netlink_autobind(struct socket *sock)
519{ 519{
520 struct sock *sk = sock->sk; 520 struct sock *sk = sock->sk;
521 struct net *net = sk->sk_net; 521 struct net *net = sock_net(sk);
522 struct nl_pid_hash *hash = &nl_table[sk->sk_protocol].hash; 522 struct nl_pid_hash *hash = &nl_table[sk->sk_protocol].hash;
523 struct hlist_head *head; 523 struct hlist_head *head;
524 struct sock *osk; 524 struct sock *osk;
@@ -532,7 +532,7 @@ retry:
532 netlink_table_grab(); 532 netlink_table_grab();
533 head = nl_pid_hashfn(hash, pid); 533 head = nl_pid_hashfn(hash, pid);
534 sk_for_each(osk, node, head) { 534 sk_for_each(osk, node, head) {
535 if ((osk->sk_net != net)) 535 if (sock_net(osk) != net)
536 continue; 536 continue;
537 if (nlk_sk(osk)->pid == pid) { 537 if (nlk_sk(osk)->pid == pid) {
538 /* Bind collision, search negative pid values. */ 538 /* Bind collision, search negative pid values. */
@@ -611,7 +611,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
611 int addr_len) 611 int addr_len)
612{ 612{
613 struct sock *sk = sock->sk; 613 struct sock *sk = sock->sk;
614 struct net *net = sk->sk_net; 614 struct net *net = sock_net(sk);
615 struct netlink_sock *nlk = nlk_sk(sk); 615 struct netlink_sock *nlk = nlk_sk(sk);
616 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; 616 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;
617 int err; 617 int err;
@@ -720,7 +720,7 @@ static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
720 struct sock *sock; 720 struct sock *sock;
721 struct netlink_sock *nlk; 721 struct netlink_sock *nlk;
722 722
723 sock = netlink_lookup(ssk->sk_net, ssk->sk_protocol, pid); 723 sock = netlink_lookup(sock_net(ssk), ssk->sk_protocol, pid);
724 if (!sock) 724 if (!sock)
725 return ERR_PTR(-ECONNREFUSED); 725 return ERR_PTR(-ECONNREFUSED);
726 726
@@ -962,7 +962,7 @@ static inline int do_one_broadcast(struct sock *sk,
962 !test_bit(p->group - 1, nlk->groups)) 962 !test_bit(p->group - 1, nlk->groups))
963 goto out; 963 goto out;
964 964
965 if ((sk->sk_net != p->net)) 965 if (sock_net(sk) != p->net)
966 goto out; 966 goto out;
967 967
968 if (p->failure) { 968 if (p->failure) {
@@ -1006,7 +1006,7 @@ out:
1006int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 pid, 1006int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 pid,
1007 u32 group, gfp_t allocation) 1007 u32 group, gfp_t allocation)
1008{ 1008{
1009 struct net *net = ssk->sk_net; 1009 struct net *net = sock_net(ssk);
1010 struct netlink_broadcast_data info; 1010 struct netlink_broadcast_data info;
1011 struct hlist_node *node; 1011 struct hlist_node *node;
1012 struct sock *sk; 1012 struct sock *sk;
@@ -1064,7 +1064,7 @@ static inline int do_one_set_err(struct sock *sk,
1064 if (sk == p->exclude_sk) 1064 if (sk == p->exclude_sk)
1065 goto out; 1065 goto out;
1066 1066
1067 if (sk->sk_net != p->exclude_sk->sk_net) 1067 if (sock_net(sk) != sock_net(p->exclude_sk))
1068 goto out; 1068 goto out;
1069 1069
1070 if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups || 1070 if (nlk->pid == p->pid || p->group - 1 >= nlk->ngroups ||
@@ -1601,7 +1601,7 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
1601 atomic_inc(&skb->users); 1601 atomic_inc(&skb->users);
1602 cb->skb = skb; 1602 cb->skb = skb;
1603 1603
1604 sk = netlink_lookup(ssk->sk_net, ssk->sk_protocol, NETLINK_CB(skb).pid); 1604 sk = netlink_lookup(sock_net(ssk), ssk->sk_protocol, NETLINK_CB(skb).pid);
1605 if (sk == NULL) { 1605 if (sk == NULL) {
1606 netlink_destroy_callback(cb); 1606 netlink_destroy_callback(cb);
1607 return -ECONNREFUSED; 1607 return -ECONNREFUSED;
@@ -1643,7 +1643,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
1643 if (!skb) { 1643 if (!skb) {
1644 struct sock *sk; 1644 struct sock *sk;
1645 1645
1646 sk = netlink_lookup(in_skb->sk->sk_net, 1646 sk = netlink_lookup(sock_net(in_skb->sk),
1647 in_skb->sk->sk_protocol, 1647 in_skb->sk->sk_protocol,
1648 NETLINK_CB(in_skb).pid); 1648 NETLINK_CB(in_skb).pid);
1649 if (sk) { 1649 if (sk) {
@@ -1758,7 +1758,7 @@ static struct sock *netlink_seq_socket_idx(struct seq_file *seq, loff_t pos)
1758 1758
1759 for (j = 0; j <= hash->mask; j++) { 1759 for (j = 0; j <= hash->mask; j++) {
1760 sk_for_each(s, node, &hash->table[j]) { 1760 sk_for_each(s, node, &hash->table[j]) {
1761 if (iter->p.net != s->sk_net) 1761 if (sock_net(s) != iter->p.net)
1762 continue; 1762 continue;
1763 if (off == pos) { 1763 if (off == pos) {
1764 iter->link = i; 1764 iter->link = i;
@@ -1794,7 +1794,7 @@ static void *netlink_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1794 s = v; 1794 s = v;
1795 do { 1795 do {
1796 s = sk_next(s); 1796 s = sk_next(s);
1797 } while (s && (iter->p.net != s->sk_net)); 1797 } while (s && (sock_net(s) != iter->p.net));
1798 if (s) 1798 if (s)
1799 return s; 1799 return s;
1800 1800
@@ -1806,7 +1806,7 @@ static void *netlink_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1806 1806
1807 for (; j <= hash->mask; j++) { 1807 for (; j <= hash->mask; j++) {
1808 s = sk_head(&hash->table[j]); 1808 s = sk_head(&hash->table[j]);
1809 while (s && (iter->p.net != s->sk_net)) 1809 while (s && sock_net(s) != iter->p.net)
1810 s = sk_next(s); 1810 s = sk_next(s);
1811 if (s) { 1811 if (s) {
1812 iter->link = i; 1812 iter->link = i;
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index a270ebf9f765..4bae8b998cab 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -466,7 +466,7 @@ static struct sock *nr_make_new(struct sock *osk)
466 if (osk->sk_type != SOCK_SEQPACKET) 466 if (osk->sk_type != SOCK_SEQPACKET)
467 return NULL; 467 return NULL;
468 468
469 sk = sk_alloc(osk->sk_net, PF_NETROM, GFP_ATOMIC, osk->sk_prot); 469 sk = sk_alloc(sock_net(osk), PF_NETROM, GFP_ATOMIC, osk->sk_prot);
470 if (sk == NULL) 470 if (sk == NULL)
471 return NULL; 471 return NULL;
472 472
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index baa290d3444a..25070240d4ae 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -263,7 +263,7 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, struct
263 if (skb->pkt_type == PACKET_LOOPBACK) 263 if (skb->pkt_type == PACKET_LOOPBACK)
264 goto out; 264 goto out;
265 265
266 if (dev_net(dev) != sk->sk_net) 266 if (dev_net(dev) != sock_net(sk))
267 goto out; 267 goto out;
268 268
269 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) 269 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
@@ -337,7 +337,7 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
337 */ 337 */
338 338
339 saddr->spkt_device[13] = 0; 339 saddr->spkt_device[13] = 0;
340 dev = dev_get_by_name(sk->sk_net, saddr->spkt_device); 340 dev = dev_get_by_name(sock_net(sk), saddr->spkt_device);
341 err = -ENODEV; 341 err = -ENODEV;
342 if (dev == NULL) 342 if (dev == NULL)
343 goto out_unlock; 343 goto out_unlock;
@@ -451,7 +451,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet
451 sk = pt->af_packet_priv; 451 sk = pt->af_packet_priv;
452 po = pkt_sk(sk); 452 po = pkt_sk(sk);
453 453
454 if (dev_net(dev) != sk->sk_net) 454 if (dev_net(dev) != sock_net(sk))
455 goto drop; 455 goto drop;
456 456
457 skb->dev = dev; 457 skb->dev = dev;
@@ -568,7 +568,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
568 sk = pt->af_packet_priv; 568 sk = pt->af_packet_priv;
569 po = pkt_sk(sk); 569 po = pkt_sk(sk);
570 570
571 if (dev_net(dev) != sk->sk_net) 571 if (dev_net(dev) != sock_net(sk))
572 goto drop; 572 goto drop;
573 573
574 if (dev->header_ops) { 574 if (dev->header_ops) {
@@ -728,7 +728,7 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
728 } 728 }
729 729
730 730
731 dev = dev_get_by_index(sk->sk_net, ifindex); 731 dev = dev_get_by_index(sock_net(sk), ifindex);
732 err = -ENXIO; 732 err = -ENXIO;
733 if (dev == NULL) 733 if (dev == NULL)
734 goto out_unlock; 734 goto out_unlock;
@@ -800,7 +800,7 @@ static int packet_release(struct socket *sock)
800 if (!sk) 800 if (!sk)
801 return 0; 801 return 0;
802 802
803 net = sk->sk_net; 803 net = sock_net(sk);
804 po = pkt_sk(sk); 804 po = pkt_sk(sk);
805 805
806 write_lock_bh(&net->packet.sklist_lock); 806 write_lock_bh(&net->packet.sklist_lock);
@@ -914,7 +914,7 @@ static int packet_bind_spkt(struct socket *sock, struct sockaddr *uaddr, int add
914 return -EINVAL; 914 return -EINVAL;
915 strlcpy(name,uaddr->sa_data,sizeof(name)); 915 strlcpy(name,uaddr->sa_data,sizeof(name));
916 916
917 dev = dev_get_by_name(sk->sk_net, name); 917 dev = dev_get_by_name(sock_net(sk), name);
918 if (dev) { 918 if (dev) {
919 err = packet_do_bind(sk, dev, pkt_sk(sk)->num); 919 err = packet_do_bind(sk, dev, pkt_sk(sk)->num);
920 dev_put(dev); 920 dev_put(dev);
@@ -941,7 +941,7 @@ static int packet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len
941 941
942 if (sll->sll_ifindex) { 942 if (sll->sll_ifindex) {
943 err = -ENODEV; 943 err = -ENODEV;
944 dev = dev_get_by_index(sk->sk_net, sll->sll_ifindex); 944 dev = dev_get_by_index(sock_net(sk), sll->sll_ifindex);
945 if (dev == NULL) 945 if (dev == NULL)
946 goto out; 946 goto out;
947 } 947 }
@@ -1135,7 +1135,7 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
1135 return -EOPNOTSUPP; 1135 return -EOPNOTSUPP;
1136 1136
1137 uaddr->sa_family = AF_PACKET; 1137 uaddr->sa_family = AF_PACKET;
1138 dev = dev_get_by_index(sk->sk_net, pkt_sk(sk)->ifindex); 1138 dev = dev_get_by_index(sock_net(sk), pkt_sk(sk)->ifindex);
1139 if (dev) { 1139 if (dev) {
1140 strlcpy(uaddr->sa_data, dev->name, 15); 1140 strlcpy(uaddr->sa_data, dev->name, 15);
1141 dev_put(dev); 1141 dev_put(dev);
@@ -1160,7 +1160,7 @@ static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
1160 sll->sll_family = AF_PACKET; 1160 sll->sll_family = AF_PACKET;
1161 sll->sll_ifindex = po->ifindex; 1161 sll->sll_ifindex = po->ifindex;
1162 sll->sll_protocol = po->num; 1162 sll->sll_protocol = po->num;
1163 dev = dev_get_by_index(sk->sk_net, po->ifindex); 1163 dev = dev_get_by_index(sock_net(sk), po->ifindex);
1164 if (dev) { 1164 if (dev) {
1165 sll->sll_hatype = dev->type; 1165 sll->sll_hatype = dev->type;
1166 sll->sll_halen = dev->addr_len; 1166 sll->sll_halen = dev->addr_len;
@@ -1212,7 +1212,7 @@ static int packet_mc_add(struct sock *sk, struct packet_mreq_max *mreq)
1212 rtnl_lock(); 1212 rtnl_lock();
1213 1213
1214 err = -ENODEV; 1214 err = -ENODEV;
1215 dev = __dev_get_by_index(sk->sk_net, mreq->mr_ifindex); 1215 dev = __dev_get_by_index(sock_net(sk), mreq->mr_ifindex);
1216 if (!dev) 1216 if (!dev)
1217 goto done; 1217 goto done;
1218 1218
@@ -1266,7 +1266,7 @@ static int packet_mc_drop(struct sock *sk, struct packet_mreq_max *mreq)
1266 if (--ml->count == 0) { 1266 if (--ml->count == 0) {
1267 struct net_device *dev; 1267 struct net_device *dev;
1268 *mlp = ml->next; 1268 *mlp = ml->next;
1269 dev = dev_get_by_index(sk->sk_net, ml->ifindex); 1269 dev = dev_get_by_index(sock_net(sk), ml->ifindex);
1270 if (dev) { 1270 if (dev) {
1271 packet_dev_mc(dev, ml, -1); 1271 packet_dev_mc(dev, ml, -1);
1272 dev_put(dev); 1272 dev_put(dev);
@@ -1294,7 +1294,7 @@ static void packet_flush_mclist(struct sock *sk)
1294 struct net_device *dev; 1294 struct net_device *dev;
1295 1295
1296 po->mclist = ml->next; 1296 po->mclist = ml->next;
1297 if ((dev = dev_get_by_index(sk->sk_net, ml->ifindex)) != NULL) { 1297 if ((dev = dev_get_by_index(sock_net(sk), ml->ifindex)) != NULL) {
1298 packet_dev_mc(dev, ml, -1); 1298 packet_dev_mc(dev, ml, -1);
1299 dev_put(dev); 1299 dev_put(dev);
1300 } 1300 }
@@ -1540,7 +1540,7 @@ static int packet_ioctl(struct socket *sock, unsigned int cmd,
1540 case SIOCGIFDSTADDR: 1540 case SIOCGIFDSTADDR:
1541 case SIOCSIFDSTADDR: 1541 case SIOCSIFDSTADDR:
1542 case SIOCSIFFLAGS: 1542 case SIOCSIFFLAGS:
1543 if (sk->sk_net != &init_net) 1543 if (sock_net(sk) != &init_net)
1544 return -ENOIOCTLCMD; 1544 return -ENOIOCTLCMD;
1545 return inet_dgram_ops.ioctl(sock, cmd, arg); 1545 return inet_dgram_ops.ioctl(sock, cmd, arg);
1546#endif 1546#endif
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index 1a7f143cf741..92d85c38e4d2 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -551,7 +551,7 @@ static struct sock *rose_make_new(struct sock *osk)
551 if (osk->sk_type != SOCK_SEQPACKET) 551 if (osk->sk_type != SOCK_SEQPACKET)
552 return NULL; 552 return NULL;
553 553
554 sk = sk_alloc(osk->sk_net, PF_ROSE, GFP_ATOMIC, &rose_proto); 554 sk = sk_alloc(sock_net(osk), PF_ROSE, GFP_ATOMIC, &rose_proto);
555 if (sk == NULL) 555 if (sk == NULL)
556 return NULL; 556 return NULL;
557 557
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 0b8eb235bc13..74e662cbb2c5 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -951,7 +951,7 @@ done:
951 951
952static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg) 952static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
953{ 953{
954 struct net *net = skb->sk->sk_net; 954 struct net *net = sock_net(skb->sk);
955 struct nlattr *tca[TCA_ACT_MAX + 1]; 955 struct nlattr *tca[TCA_ACT_MAX + 1];
956 u32 pid = skb ? NETLINK_CB(skb).pid : 0; 956 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
957 int ret = 0, ovr = 0; 957 int ret = 0, ovr = 0;
@@ -1029,7 +1029,7 @@ find_dump_kind(struct nlmsghdr *n)
1029static int 1029static int
1030tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) 1030tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1031{ 1031{
1032 struct net *net = skb->sk->sk_net; 1032 struct net *net = sock_net(skb->sk);
1033 struct nlmsghdr *nlh; 1033 struct nlmsghdr *nlh;
1034 unsigned char *b = skb_tail_pointer(skb); 1034 unsigned char *b = skb_tail_pointer(skb);
1035 struct nlattr *nest; 1035 struct nlattr *nest;
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 0fbedcabf111..1086df7478bc 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -118,7 +118,7 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp)
118 118
119static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg) 119static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
120{ 120{
121 struct net *net = skb->sk->sk_net; 121 struct net *net = sock_net(skb->sk);
122 struct nlattr *tca[TCA_MAX + 1]; 122 struct nlattr *tca[TCA_MAX + 1];
123 struct tcmsg *t; 123 struct tcmsg *t;
124 u32 protocol; 124 u32 protocol;
@@ -389,7 +389,7 @@ static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
389 389
390static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) 390static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
391{ 391{
392 struct net *net = skb->sk->sk_net; 392 struct net *net = sock_net(skb->sk);
393 int t; 393 int t;
394 int s_t; 394 int s_t;
395 struct net_device *dev; 395 struct net_device *dev;
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 7e3c048ba9b1..15b91a9ee8e8 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -605,7 +605,7 @@ check_loop_fn(struct Qdisc *q, unsigned long cl, struct qdisc_walker *w)
605 605
606static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) 606static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
607{ 607{
608 struct net *net = skb->sk->sk_net; 608 struct net *net = sock_net(skb->sk);
609 struct tcmsg *tcm = NLMSG_DATA(n); 609 struct tcmsg *tcm = NLMSG_DATA(n);
610 struct nlattr *tca[TCA_MAX + 1]; 610 struct nlattr *tca[TCA_MAX + 1];
611 struct net_device *dev; 611 struct net_device *dev;
@@ -674,7 +674,7 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
674 674
675static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) 675static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
676{ 676{
677 struct net *net = skb->sk->sk_net; 677 struct net *net = sock_net(skb->sk);
678 struct tcmsg *tcm; 678 struct tcmsg *tcm;
679 struct nlattr *tca[TCA_MAX + 1]; 679 struct nlattr *tca[TCA_MAX + 1];
680 struct net_device *dev; 680 struct net_device *dev;
@@ -893,7 +893,7 @@ err_out:
893 893
894static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb) 894static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
895{ 895{
896 struct net *net = skb->sk->sk_net; 896 struct net *net = sock_net(skb->sk);
897 int idx, q_idx; 897 int idx, q_idx;
898 int s_idx, s_q_idx; 898 int s_idx, s_q_idx;
899 struct net_device *dev; 899 struct net_device *dev;
@@ -945,7 +945,7 @@ done:
945 945
946static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg) 946static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
947{ 947{
948 struct net *net = skb->sk->sk_net; 948 struct net *net = sock_net(skb->sk);
949 struct tcmsg *tcm = NLMSG_DATA(n); 949 struct tcmsg *tcm = NLMSG_DATA(n);
950 struct nlattr *tca[TCA_MAX + 1]; 950 struct nlattr *tca[TCA_MAX + 1];
951 struct net_device *dev; 951 struct net_device *dev;
@@ -1139,7 +1139,7 @@ static int qdisc_class_dump(struct Qdisc *q, unsigned long cl, struct qdisc_walk
1139 1139
1140static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb) 1140static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb)
1141{ 1141{
1142 struct net *net = skb->sk->sk_net; 1142 struct net *net = sock_net(skb->sk);
1143 int t; 1143 int t;
1144 int s_t; 1144 int s_t;
1145 struct net_device *dev; 1145 struct net_device *dev;
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index dc71d0d83753..036bfcc8d15b 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -636,7 +636,7 @@ static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
636 struct ipv6_pinfo *newnp, *np = inet6_sk(sk); 636 struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
637 struct sctp6_sock *newsctp6sk; 637 struct sctp6_sock *newsctp6sk;
638 638
639 newsk = sk_alloc(sk->sk_net, PF_INET6, GFP_KERNEL, sk->sk_prot); 639 newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot);
640 if (!newsk) 640 if (!newsk)
641 goto out; 641 goto out;
642 642
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 2faa0d8839eb..5aea91137fbb 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -554,7 +554,7 @@ static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
554{ 554{
555 struct inet_sock *inet = inet_sk(sk); 555 struct inet_sock *inet = inet_sk(sk);
556 struct inet_sock *newinet; 556 struct inet_sock *newinet;
557 struct sock *newsk = sk_alloc(sk->sk_net, PF_INET, GFP_KERNEL, 557 struct sock *newsk = sk_alloc(sock_net(sk), PF_INET, GFP_KERNEL,
558 sk->sk_prot); 558 sk->sk_prot);
559 559
560 if (!newsk) 560 if (!newsk)
diff --git a/net/socket.c b/net/socket.c
index 9d3fbfbc8535..79e5382fd110 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -857,7 +857,7 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
857 857
858 sock = file->private_data; 858 sock = file->private_data;
859 sk = sock->sk; 859 sk = sock->sk;
860 net = sk->sk_net; 860 net = sock_net(sk);
861 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) { 861 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
862 err = dev_ioctl(net, cmd, argp); 862 err = dev_ioctl(net, cmd, argp);
863 } else 863 } else
@@ -1375,7 +1375,7 @@ asmlinkage long sys_listen(int fd, int backlog)
1375 1375
1376 sock = sockfd_lookup_light(fd, &err, &fput_needed); 1376 sock = sockfd_lookup_light(fd, &err, &fput_needed);
1377 if (sock) { 1377 if (sock) {
1378 somaxconn = sock->sk->sk_net->sysctl_somaxconn; 1378 somaxconn = sock_net(sock->sk)->sysctl_somaxconn;
1379 if ((unsigned)backlog > somaxconn) 1379 if ((unsigned)backlog > somaxconn)
1380 backlog = somaxconn; 1380 backlog = somaxconn;
1381 1381
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 3220d5cb5b5d..ae45df060e3a 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1375,7 +1375,7 @@ static int accept(struct socket *sock, struct socket *newsock, int flags)
1375 } 1375 }
1376 buf = skb_peek(&sock->sk->sk_receive_queue); 1376 buf = skb_peek(&sock->sk->sk_receive_queue);
1377 1377
1378 res = tipc_create(sock->sk->sk_net, newsock, 0); 1378 res = tipc_create(sock_net(sock->sk), newsock, 0);
1379 if (!res) { 1379 if (!res) {
1380 struct tipc_sock *new_tsock = tipc_sk(newsock->sk); 1380 struct tipc_sock *new_tsock = tipc_sk(newsock->sk);
1381 struct tipc_portid id; 1381 struct tipc_portid id;
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ae584356852c..cb9d0cb5f270 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -252,7 +252,7 @@ static struct sock *__unix_find_socket_byname(struct net *net,
252 sk_for_each(s, node, &unix_socket_table[hash ^ type]) { 252 sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
253 struct unix_sock *u = unix_sk(s); 253 struct unix_sock *u = unix_sk(s);
254 254
255 if (s->sk_net != net) 255 if (sock_net(s) != net)
256 continue; 256 continue;
257 257
258 if (u->addr->len == len && 258 if (u->addr->len == len &&
@@ -289,7 +289,7 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)
289 &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) { 289 &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) {
290 struct dentry *dentry = unix_sk(s)->dentry; 290 struct dentry *dentry = unix_sk(s)->dentry;
291 291
292 if (s->sk_net != net) 292 if (sock_net(s) != net)
293 continue; 293 continue;
294 294
295 if(dentry && dentry->d_inode == i) 295 if(dentry && dentry->d_inode == i)
@@ -654,7 +654,7 @@ static int unix_release(struct socket *sock)
654static int unix_autobind(struct socket *sock) 654static int unix_autobind(struct socket *sock)
655{ 655{
656 struct sock *sk = sock->sk; 656 struct sock *sk = sock->sk;
657 struct net *net = sk->sk_net; 657 struct net *net = sock_net(sk);
658 struct unix_sock *u = unix_sk(sk); 658 struct unix_sock *u = unix_sk(sk);
659 static u32 ordernum = 1; 659 static u32 ordernum = 1;
660 struct unix_address * addr; 660 struct unix_address * addr;
@@ -758,7 +758,7 @@ fail:
758static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) 758static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
759{ 759{
760 struct sock *sk = sock->sk; 760 struct sock *sk = sock->sk;
761 struct net *net = sk->sk_net; 761 struct net *net = sock_net(sk);
762 struct unix_sock *u = unix_sk(sk); 762 struct unix_sock *u = unix_sk(sk);
763 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 763 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
764 struct dentry * dentry = NULL; 764 struct dentry * dentry = NULL;
@@ -899,7 +899,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
899 int alen, int flags) 899 int alen, int flags)
900{ 900{
901 struct sock *sk = sock->sk; 901 struct sock *sk = sock->sk;
902 struct net *net = sk->sk_net; 902 struct net *net = sock_net(sk);
903 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr; 903 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr;
904 struct sock *other; 904 struct sock *other;
905 unsigned hash; 905 unsigned hash;
@@ -996,7 +996,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
996{ 996{
997 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr; 997 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
998 struct sock *sk = sock->sk; 998 struct sock *sk = sock->sk;
999 struct net *net = sk->sk_net; 999 struct net *net = sock_net(sk);
1000 struct unix_sock *u = unix_sk(sk), *newu, *otheru; 1000 struct unix_sock *u = unix_sk(sk), *newu, *otheru;
1001 struct sock *newsk = NULL; 1001 struct sock *newsk = NULL;
1002 struct sock *other = NULL; 1002 struct sock *other = NULL;
@@ -1025,7 +1025,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
1025 err = -ENOMEM; 1025 err = -ENOMEM;
1026 1026
1027 /* create new sock for complete connection */ 1027 /* create new sock for complete connection */
1028 newsk = unix_create1(sk->sk_net, NULL); 1028 newsk = unix_create1(sock_net(sk), NULL);
1029 if (newsk == NULL) 1029 if (newsk == NULL)
1030 goto out; 1030 goto out;
1031 1031
@@ -1312,7 +1312,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1312{ 1312{
1313 struct sock_iocb *siocb = kiocb_to_siocb(kiocb); 1313 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1314 struct sock *sk = sock->sk; 1314 struct sock *sk = sock->sk;
1315 struct net *net = sk->sk_net; 1315 struct net *net = sock_net(sk);
1316 struct unix_sock *u = unix_sk(sk); 1316 struct unix_sock *u = unix_sk(sk);
1317 struct sockaddr_un *sunaddr=msg->msg_name; 1317 struct sockaddr_un *sunaddr=msg->msg_name;
1318 struct sock *other = NULL; 1318 struct sock *other = NULL;
@@ -2022,7 +2022,7 @@ static struct sock *unix_seq_idx(struct unix_iter_state *iter, loff_t pos)
2022 struct sock *s; 2022 struct sock *s;
2023 2023
2024 for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) { 2024 for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
2025 if (s->sk_net != iter->p.net) 2025 if (sock_net(s) != iter->p.net)
2026 continue; 2026 continue;
2027 if (off == pos) 2027 if (off == pos)
2028 return s; 2028 return s;
@@ -2050,7 +2050,7 @@ static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2050 sk = first_unix_socket(&iter->i); 2050 sk = first_unix_socket(&iter->i);
2051 else 2051 else
2052 sk = next_unix_socket(&iter->i, sk); 2052 sk = next_unix_socket(&iter->i, sk);
2053 while (sk && (sk->sk_net != iter->p.net)) 2053 while (sk && (sock_net(sk) != iter->p.net))
2054 sk = next_unix_socket(&iter->i, sk); 2054 sk = next_unix_socket(&iter->i, sk);
2055 return sk; 2055 return sk;
2056} 2056}
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 7a46ea73fe2d..6ba67c523c16 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -549,7 +549,7 @@ static struct sock *x25_make_new(struct sock *osk)
549 if (osk->sk_type != SOCK_SEQPACKET) 549 if (osk->sk_type != SOCK_SEQPACKET)
550 goto out; 550 goto out;
551 551
552 if ((sk = x25_alloc_socket(osk->sk_net)) == NULL) 552 if ((sk = x25_alloc_socket(sock_net(osk))) == NULL)
553 goto out; 553 goto out;
554 554
555 x25 = x25_sk(sk); 555 x25 = x25_sk(sk);