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

Commit 0c5c9fb5 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller
Browse files

net: Introduce possible_net_t



Having to say
> #ifdef CONFIG_NET_NS
> 	struct net *net;
> #endif

in structures is a little bit wordy and a little bit error prone.

Instead it is possible to say:
> typedef struct {
> #ifdef CONFIG_NET_NS
>       struct net *net;
> #endif
> } possible_net_t;

And then in a header say:

> 	possible_net_t net;

Which is cleaner and easier to use and easier to test, as the
possible_net_t is always there no matter what the compile options.

Further this allows read_pnet and write_pnet to be functions in all
cases which is better at catching typos.

This change adds possible_net_t, updates the definitions of read_pnet
and write_pnet, updates optional struct net * variables that
write_pnet uses on to have the type possible_net_t, and finally fixes
up the b0rked users of read_pnet and write_pnet.

Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent efd7ef1c
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -1721,9 +1721,7 @@ struct net_device {
	struct netpoll_info __rcu	*npinfo;
#endif

#ifdef CONFIG_NET_NS
	struct net		*nd_net;
#endif
	possible_net_t			nd_net;

	/* mid-layer private */
	union {
@@ -1863,9 +1861,7 @@ struct net *dev_net(const struct net_device *dev)
static inline
void dev_net_set(struct net_device *dev, struct net *net)
{
#ifdef CONFIG_NET_NS
	dev->nd_net = net;
#endif
	write_pnet(&dev->nd_net, net);
}

static inline bool netdev_uses_dsa(struct net_device *dev)
+1 −3
Original line number Diff line number Diff line
@@ -3183,10 +3183,8 @@ struct wiphy {
	const struct ieee80211_ht_cap *ht_capa_mod_mask;
	const struct ieee80211_vht_cap *vht_capa_mod_mask;

#ifdef CONFIG_NET_NS
	/* the network namespace this phy lives in currently */
	struct net *_net;
#endif
	possible_net_t _net;

#ifdef CONFIG_CFG80211_WEXT
	const struct iw_handler_def *wext;
+1 −3
Original line number Diff line number Diff line
@@ -92,9 +92,7 @@ struct genl_info {
	struct genlmsghdr *	genlhdr;
	void *			userhdr;
	struct nlattr **	attrs;
#ifdef CONFIG_NET_NS
	struct net *		_net;
#endif
	possible_net_t		_net;
	void *			user_ptr[2];
	struct sock *		dst_sk;
};
+1 −3
Original line number Diff line number Diff line
@@ -76,9 +76,7 @@ struct inet_ehash_bucket {
 * ports are created in O(1) time?  I thought so. ;-)	-DaveM
 */
struct inet_bind_bucket {
#ifdef CONFIG_NET_NS
	struct net		*ib_net;
#endif
	possible_net_t		ib_net;
	unsigned short		port;
	signed char		fastreuse;
	signed char		fastreuseport;
+4 −4
Original line number Diff line number Diff line
@@ -47,13 +47,13 @@ static inline struct net *skb_net(const struct sk_buff *skb)
	 * Start with the most likely hit
	 * End with BUG
	 */
	if (likely(skb->dev && skb->dev->nd_net))
	if (likely(skb->dev && dev_net(skb->dev)))
		return dev_net(skb->dev);
	if (skb_dst(skb) && skb_dst(skb)->dev)
		return dev_net(skb_dst(skb)->dev);
	WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
		      __func__, __LINE__);
	if (likely(skb->sk && skb->sk->sk_net))
	if (likely(skb->sk && sock_net(skb->sk)))
		return sock_net(skb->sk);
	pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
		__func__, __LINE__);
@@ -71,11 +71,11 @@ static inline struct net *skb_sknet(const struct sk_buff *skb)
#ifdef CONFIG_NET_NS
#ifdef CONFIG_IP_VS_DEBUG
	/* Start with the most likely hit */
	if (likely(skb->sk && skb->sk->sk_net))
	if (likely(skb->sk && sock_net(skb->sk)))
		return sock_net(skb->sk);
	WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
		       __func__, __LINE__);
	if (likely(skb->dev && skb->dev->nd_net))
	if (likely(skb->dev && dev_net(skb->dev)))
		return dev_net(skb->dev);
	pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
		__func__, __LINE__);
Loading