diff options
author | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2008-03-25 13:26:21 -0400 |
---|---|---|
committer | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2008-03-25 15:39:55 -0400 |
commit | 3b1e0a655f8eba44ab1ee2a1068d169ccfb853b9 (patch) | |
tree | 09edb35f32ebcfb1b4dad904425128a110ef16ee /include | |
parent | c346dca10840a874240c78efe3f39acf4312a1f2 (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>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/ipv6.h | 4 | ||||
-rw-r--r-- | include/net/inet_hashtables.h | 8 | ||||
-rw-r--r-- | include/net/inet_timewait_sock.h | 18 | ||||
-rw-r--r-- | include/net/route.h | 4 | ||||
-rw-r--r-- | include/net/sock.h | 24 |
5 files changed, 48 insertions, 10 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); |
208 | extern void inet_twsk_deschedule(struct inet_timewait_sock *tw, | 208 | extern void inet_twsk_deschedule(struct inet_timewait_sock *tw, |
209 | struct inet_timewait_death_row *twdr); | 209 | struct inet_timewait_death_row *twdr); |
210 | |||
211 | static inline | ||
212 | struct 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 | |||
221 | static inline | ||
222 | void 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 | ||
1350 | static inline | ||
1351 | struct 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 | |||
1360 | static inline | ||
1361 | void 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 | */ |
1354 | static inline void sk_change_net(struct sock *sk, struct net *net) | 1374 | static 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 | ||
1360 | extern void sock_enable_timestamp(struct sock *sk); | 1380 | extern void sock_enable_timestamp(struct sock *sk); |