Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b1e0a65 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki
Browse files

[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: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
parent c346dca1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -481,7 +481,7 @@ static inline struct raw6_sock *raw6_sk(const struct sock *sk)
#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */

#define INET6_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif)\
	(((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net))	&& \
	(((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net)	&& \
	 ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports))  	&& \
	 ((__sk)->sk_family		== AF_INET6)		&& \
	 ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr))	&& \
@@ -489,7 +489,7 @@ static inline struct raw6_sock *raw6_sk(const struct sock *sk)
	 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))

#define INET6_TW_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif) \
	(((__sk)->sk_hash == (__hash)) && ((__sk)->sk_net == (__net))	&& \
	(((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net)	&& \
	 (*((__portpair *)&(inet_twsk(__sk)->tw_dport)) == (__ports))	&& \
	 ((__sk)->sk_family	       == PF_INET6)			&& \
	 (ipv6_addr_equal(&inet6_twsk(__sk)->tw_v6_daddr, (__saddr)))	&& \
+4 −4
Original line number Diff line number Diff line
@@ -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)) &&	\
+18 −0
Original line number Diff line number Diff line
@@ -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_ */
+2 −2
Original line number Diff line number Diff line
@@ -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;
}
+22 −2
Original line number Diff line number Diff line
@@ -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);
Loading