aboutsummaryrefslogtreecommitdiff
path: root/include/net
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-03-26 02:26:21 +0900
committerYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2008-03-26 04:39:55 +0900
commit3b1e0a655f8eba44ab1ee2a1068d169ccfb853b9 (patch)
tree09edb35f32ebcfb1b4dad904425128a110ef16ee /include/net
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>
Diffstat (limited to 'include/net')
-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
4 files changed, 46 insertions, 8 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index d99c1ba2ece..5525227c5e9 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -314,25 +314,25 @@ typedef __u64 __bitwise __addrpair;
((__force __u64)(__be32)(__saddr)));
#endif /* __BIG_ENDIAN */
#define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
- (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \
+ (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
((*((__addrpair *)&(inet_sk(__sk)->daddr))) == (__cookie)) && \
((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
#define INET_TW_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
- (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \
+ (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
((*((__addrpair *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \
((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
#else /* 32-bit arch */
#define INET_ADDR_COOKIE(__name, __saddr, __daddr)
#define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif) \
- (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \
+ (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
(inet_sk(__sk)->daddr == (__saddr)) && \
(inet_sk(__sk)->rcv_saddr == (__daddr)) && \
((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
#define INET_TW_MATCH(__sk, __net, __hash,__cookie, __saddr, __daddr, __ports, __dif) \
- (((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net)) && \
+ (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
(inet_twsk(__sk)->tw_daddr == (__saddr)) && \
(inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \
((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
diff --git a/include/net/inet_timewait_sock.h b/include/net/inet_timewait_sock.h
index 296547bfb0b..07fe0d1a4f0 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,
const int timeo, const int timewait_len);
extern void inet_twsk_deschedule(struct inet_timewait_sock *tw,
struct inet_timewait_death_row *twdr);
+
+static inline
+struct net *twsk_net(const struct inet_timewait_sock *twsk)
+{
+#ifdef CONFIG_NET_NS
+ return twsk->tw_net;
+#else
+ return &init_net;
+#endif
+}
+
+static inline
+void twsk_net_set(struct inet_timewait_sock *twsk, const struct net *net)
+{
+#ifdef CONFIG_NET_NS
+ twsk->tw_net = net;
+#endif
+}
#endif /* _INET_TIMEWAIT_SOCK_ */
diff --git a/include/net/route.h b/include/net/route.h
index 28dba925663..c6338802e8f 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,
.dport = dport } } };
int err;
- struct net *net = sk->sk_net;
+ struct net *net = sock_net(sk);
if (!dst || !src) {
err = __ip_route_output_key(net, rp, &fl);
if (err)
@@ -188,7 +188,7 @@ static inline int ip_route_newports(struct rtable **rp, u8 protocol,
ip_rt_put(*rp);
*rp = NULL;
security_sk_classify_flow(sk, &fl);
- return ip_route_output_flow(sk->sk_net, rp, &fl, sk, 0);
+ return ip_route_output_flow(sock_net(sk), rp, &fl, sk, 0);
}
return 0;
}
diff --git a/include/net/sock.h b/include/net/sock.h
index b433b1ed203..7e0d4a0c4d1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -126,7 +126,9 @@ struct sock_common {
atomic_t skc_refcnt;
unsigned int skc_hash;
struct proto *skc_prot;
+#ifdef CONFIG_NET_NS
struct net *skc_net;
+#endif
};
/**
@@ -1345,6 +1347,24 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_e
}
#endif
+static inline
+struct net *sock_net(const struct sock *sk)
+{
+#ifdef CONFIG_NET_NS
+ return sk->sk_net;
+#else
+ return &init_net;
+#endif
+}
+
+static inline
+void sock_net_set(struct sock *sk, const struct net *net)
+{
+#ifdef CONFIG_NET_NS
+ sk->sk_net = net;
+#endif
+}
+
/*
* Kernel sockets, f.e. rtnl or icmp_socket, are a part of a namespace.
* 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
*/
static inline void sk_change_net(struct sock *sk, struct net *net)
{
- put_net(sk->sk_net);
- sk->sk_net = net;
+ put_net(sock_net(sk));
+ sock_net_set(sk, net);
}
extern void sock_enable_timestamp(struct sock *sk);