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: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
efd7ef1c19
commit
0c5c9fb551
16 changed files with 43 additions and 73 deletions
|
@ -1721,9 +1721,7 @@ struct net_device {
|
||||||
struct netpoll_info __rcu *npinfo;
|
struct netpoll_info __rcu *npinfo;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t nd_net;
|
||||||
struct net *nd_net;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* mid-layer private */
|
/* mid-layer private */
|
||||||
union {
|
union {
|
||||||
|
@ -1863,9 +1861,7 @@ struct net *dev_net(const struct net_device *dev)
|
||||||
static inline
|
static inline
|
||||||
void dev_net_set(struct net_device *dev, struct net *net)
|
void dev_net_set(struct net_device *dev, struct net *net)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_NS
|
write_pnet(&dev->nd_net, net);
|
||||||
dev->nd_net = net;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool netdev_uses_dsa(struct net_device *dev)
|
static inline bool netdev_uses_dsa(struct net_device *dev)
|
||||||
|
|
|
@ -3183,10 +3183,8 @@ struct wiphy {
|
||||||
const struct ieee80211_ht_cap *ht_capa_mod_mask;
|
const struct ieee80211_ht_cap *ht_capa_mod_mask;
|
||||||
const struct ieee80211_vht_cap *vht_capa_mod_mask;
|
const struct ieee80211_vht_cap *vht_capa_mod_mask;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_NS
|
|
||||||
/* the network namespace this phy lives in currently */
|
/* the network namespace this phy lives in currently */
|
||||||
struct net *_net;
|
possible_net_t _net;
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_CFG80211_WEXT
|
#ifdef CONFIG_CFG80211_WEXT
|
||||||
const struct iw_handler_def *wext;
|
const struct iw_handler_def *wext;
|
||||||
|
|
|
@ -92,9 +92,7 @@ struct genl_info {
|
||||||
struct genlmsghdr * genlhdr;
|
struct genlmsghdr * genlhdr;
|
||||||
void * userhdr;
|
void * userhdr;
|
||||||
struct nlattr ** attrs;
|
struct nlattr ** attrs;
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t _net;
|
||||||
struct net * _net;
|
|
||||||
#endif
|
|
||||||
void * user_ptr[2];
|
void * user_ptr[2];
|
||||||
struct sock * dst_sk;
|
struct sock * dst_sk;
|
||||||
};
|
};
|
||||||
|
|
|
@ -76,9 +76,7 @@ struct inet_ehash_bucket {
|
||||||
* ports are created in O(1) time? I thought so. ;-) -DaveM
|
* ports are created in O(1) time? I thought so. ;-) -DaveM
|
||||||
*/
|
*/
|
||||||
struct inet_bind_bucket {
|
struct inet_bind_bucket {
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t ib_net;
|
||||||
struct net *ib_net;
|
|
||||||
#endif
|
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
signed char fastreuse;
|
signed char fastreuse;
|
||||||
signed char fastreuseport;
|
signed char fastreuseport;
|
||||||
|
|
|
@ -47,13 +47,13 @@ static inline struct net *skb_net(const struct sk_buff *skb)
|
||||||
* Start with the most likely hit
|
* Start with the most likely hit
|
||||||
* End with BUG
|
* End with BUG
|
||||||
*/
|
*/
|
||||||
if (likely(skb->dev && skb->dev->nd_net))
|
if (likely(skb->dev && dev_net(skb->dev)))
|
||||||
return dev_net(skb->dev);
|
return dev_net(skb->dev);
|
||||||
if (skb_dst(skb) && skb_dst(skb)->dev)
|
if (skb_dst(skb) && skb_dst(skb)->dev)
|
||||||
return dev_net(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",
|
WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
if (likely(skb->sk && skb->sk->sk_net))
|
if (likely(skb->sk && sock_net(skb->sk)))
|
||||||
return 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",
|
pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
|
@ -71,11 +71,11 @@ static inline struct net *skb_sknet(const struct sk_buff *skb)
|
||||||
#ifdef CONFIG_NET_NS
|
#ifdef CONFIG_NET_NS
|
||||||
#ifdef CONFIG_IP_VS_DEBUG
|
#ifdef CONFIG_IP_VS_DEBUG
|
||||||
/* Start with the most likely hit */
|
/* 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);
|
return sock_net(skb->sk);
|
||||||
WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
|
WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
if (likely(skb->dev && skb->dev->nd_net))
|
if (likely(skb->dev && dev_net(skb->dev)))
|
||||||
return 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",
|
pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
|
|
|
@ -65,9 +65,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct neigh_parms {
|
struct neigh_parms {
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t net;
|
||||||
struct net *net;
|
|
||||||
#endif
|
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
int (*neigh_setup)(struct neighbour *);
|
int (*neigh_setup)(struct neighbour *);
|
||||||
|
@ -167,9 +165,7 @@ struct neigh_ops {
|
||||||
|
|
||||||
struct pneigh_entry {
|
struct pneigh_entry {
|
||||||
struct pneigh_entry *next;
|
struct pneigh_entry *next;
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t net;
|
||||||
struct net *net;
|
|
||||||
#endif
|
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
u8 flags;
|
u8 flags;
|
||||||
u8 key[0];
|
u8 key[0];
|
||||||
|
|
|
@ -231,24 +231,27 @@ int net_eq(const struct net *net1, const struct net *net2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
#ifdef CONFIG_NET_NS
|
#ifdef CONFIG_NET_NS
|
||||||
|
struct net *net;
|
||||||
static inline void write_pnet(struct net **pnet, struct net *net)
|
|
||||||
{
|
|
||||||
*pnet = net;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct net *read_pnet(struct net * const *pnet)
|
|
||||||
{
|
|
||||||
return *pnet;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define write_pnet(pnet, net) do { (void)(net);} while (0)
|
|
||||||
#define read_pnet(pnet) (&init_net)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
} possible_net_t;
|
||||||
|
|
||||||
|
static inline void write_pnet(possible_net_t *pnet, struct net *net)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_NET_NS
|
||||||
|
pnet->net = net;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct net *read_pnet(const possible_net_t *pnet)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_NET_NS
|
||||||
|
return pnet->net;
|
||||||
|
#else
|
||||||
|
return &init_net;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#define for_each_net(VAR) \
|
#define for_each_net(VAR) \
|
||||||
list_for_each_entry(VAR, &net_namespace_list, list)
|
list_for_each_entry(VAR, &net_namespace_list, list)
|
||||||
|
|
|
@ -95,9 +95,8 @@ struct nf_conn {
|
||||||
/* Timer function; drops refcnt when it goes off. */
|
/* Timer function; drops refcnt when it goes off. */
|
||||||
struct timer_list timeout;
|
struct timer_list timeout;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t ct_net;
|
||||||
struct net *ct_net;
|
|
||||||
#endif
|
|
||||||
/* all members below initialized via memset */
|
/* all members below initialized via memset */
|
||||||
u8 __nfct_init_offset[0];
|
u8 __nfct_init_offset[0];
|
||||||
|
|
||||||
|
|
|
@ -190,9 +190,7 @@ struct sock_common {
|
||||||
struct hlist_nulls_node skc_portaddr_node;
|
struct hlist_nulls_node skc_portaddr_node;
|
||||||
};
|
};
|
||||||
struct proto *skc_prot;
|
struct proto *skc_prot;
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t skc_net;
|
||||||
struct net *skc_net;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_IPV6)
|
#if IS_ENABLED(CONFIG_IPV6)
|
||||||
struct in6_addr skc_v6_daddr;
|
struct in6_addr skc_v6_daddr;
|
||||||
|
|
|
@ -126,9 +126,7 @@ struct xfrm_state_walk {
|
||||||
|
|
||||||
/* Full description of state of transformer. */
|
/* Full description of state of transformer. */
|
||||||
struct xfrm_state {
|
struct xfrm_state {
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t xs_net;
|
||||||
struct net *xs_net;
|
|
||||||
#endif
|
|
||||||
union {
|
union {
|
||||||
struct hlist_node gclist;
|
struct hlist_node gclist;
|
||||||
struct hlist_node bydst;
|
struct hlist_node bydst;
|
||||||
|
@ -522,9 +520,7 @@ struct xfrm_policy_queue {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xfrm_policy {
|
struct xfrm_policy {
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t xp_net;
|
||||||
struct net *xp_net;
|
|
||||||
#endif
|
|
||||||
struct hlist_node bydst;
|
struct hlist_node bydst;
|
||||||
struct hlist_node byidx;
|
struct hlist_node byidx;
|
||||||
|
|
||||||
|
|
|
@ -940,7 +940,7 @@ p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
|
||||||
sin_server.sin_family = AF_INET;
|
sin_server.sin_family = AF_INET;
|
||||||
sin_server.sin_addr.s_addr = in_aton(addr);
|
sin_server.sin_addr.s_addr = in_aton(addr);
|
||||||
sin_server.sin_port = htons(opts.port);
|
sin_server.sin_port = htons(opts.port);
|
||||||
err = __sock_create(read_pnet(¤t->nsproxy->net_ns), PF_INET,
|
err = __sock_create(current->nsproxy->net_ns, PF_INET,
|
||||||
SOCK_STREAM, IPPROTO_TCP, &csocket, 1);
|
SOCK_STREAM, IPPROTO_TCP, &csocket, 1);
|
||||||
if (err) {
|
if (err) {
|
||||||
pr_err("%s (%d): problem creating socket\n",
|
pr_err("%s (%d): problem creating socket\n",
|
||||||
|
@ -988,7 +988,7 @@ p9_fd_create_unix(struct p9_client *client, const char *addr, char *args)
|
||||||
|
|
||||||
sun_server.sun_family = PF_UNIX;
|
sun_server.sun_family = PF_UNIX;
|
||||||
strcpy(sun_server.sun_path, addr);
|
strcpy(sun_server.sun_path, addr);
|
||||||
err = __sock_create(read_pnet(¤t->nsproxy->net_ns), PF_UNIX,
|
err = __sock_create(current->nsproxy->net_ns, PF_UNIX,
|
||||||
SOCK_STREAM, 0, &csocket, 1);
|
SOCK_STREAM, 0, &csocket, 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
pr_err("%s (%d): problem creating socket\n",
|
pr_err("%s (%d): problem creating socket\n",
|
||||||
|
|
|
@ -73,9 +73,7 @@
|
||||||
|
|
||||||
struct mr_table {
|
struct mr_table {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t net;
|
||||||
struct net *net;
|
|
||||||
#endif
|
|
||||||
u32 id;
|
u32 id;
|
||||||
struct sock __rcu *mroute_sk;
|
struct sock __rcu *mroute_sk;
|
||||||
struct timer_list ipmr_expire_timer;
|
struct timer_list ipmr_expire_timer;
|
||||||
|
|
|
@ -29,9 +29,7 @@
|
||||||
* Policy Table
|
* Policy Table
|
||||||
*/
|
*/
|
||||||
struct ip6addrlbl_entry {
|
struct ip6addrlbl_entry {
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t lbl_net;
|
||||||
struct net *lbl_net;
|
|
||||||
#endif
|
|
||||||
struct in6_addr prefix;
|
struct in6_addr prefix;
|
||||||
int prefixlen;
|
int prefixlen;
|
||||||
int ifindex;
|
int ifindex;
|
||||||
|
@ -237,9 +235,7 @@ static struct ip6addrlbl_entry *ip6addrlbl_alloc(struct net *net,
|
||||||
newp->addrtype = addrtype;
|
newp->addrtype = addrtype;
|
||||||
newp->label = label;
|
newp->label = label;
|
||||||
INIT_HLIST_NODE(&newp->list);
|
INIT_HLIST_NODE(&newp->list);
|
||||||
#ifdef CONFIG_NET_NS
|
write_pnet(&newp->lbl_net, net);
|
||||||
newp->lbl_net = net;
|
|
||||||
#endif
|
|
||||||
atomic_set(&newp->refcnt, 1);
|
atomic_set(&newp->refcnt, 1);
|
||||||
return newp;
|
return newp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,9 +56,7 @@
|
||||||
|
|
||||||
struct mr6_table {
|
struct mr6_table {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t net;
|
||||||
struct net *net;
|
|
||||||
#endif
|
|
||||||
u32 id;
|
u32 id;
|
||||||
struct sock *mroute6_sk;
|
struct sock *mroute6_sk;
|
||||||
struct timer_list ipmr_expire_timer;
|
struct timer_list ipmr_expire_timer;
|
||||||
|
|
|
@ -84,10 +84,8 @@ struct datapath {
|
||||||
/* Stats. */
|
/* Stats. */
|
||||||
struct dp_stats_percpu __percpu *stats_percpu;
|
struct dp_stats_percpu __percpu *stats_percpu;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_NS
|
|
||||||
/* Network namespace ref. */
|
/* Network namespace ref. */
|
||||||
struct net *net;
|
possible_net_t net;
|
||||||
#endif
|
|
||||||
|
|
||||||
u32 user_features;
|
u32 user_features;
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,9 +74,7 @@ extern struct mutex fanout_mutex;
|
||||||
#define PACKET_FANOUT_MAX 256
|
#define PACKET_FANOUT_MAX 256
|
||||||
|
|
||||||
struct packet_fanout {
|
struct packet_fanout {
|
||||||
#ifdef CONFIG_NET_NS
|
possible_net_t net;
|
||||||
struct net *net;
|
|
||||||
#endif
|
|
||||||
unsigned int num_members;
|
unsigned int num_members;
|
||||||
u16 id;
|
u16 id;
|
||||||
u8 type;
|
u8 type;
|
||||||
|
|
Loading…
Add table
Reference in a new issue