Commit 8f424b5f32d78b4f353b3cddca9804808ef063eb

Authored by Eric Dumazet
Committed by David S. Miller
1 parent 9eca0a47de

net: Introduce read_pnet() and write_pnet() helpers

This patch introduces two helpers that deal with reading and writing
struct net pointers in various network structures.

Their implementation depends on CONFIG_NET_NS

For symmetry, both functions work with "struct net **pnet".

Their usage should reduce the number of #ifdef CONFIG_NET_NS,
without adding many helpers for each network structure
that hold a "struct net *pointer"

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 18 additions and 0 deletions Side-by-side Diff

include/net/net_namespace.h
... ... @@ -192,6 +192,24 @@
192 192 }
193 193 #endif
194 194  
  195 +#ifdef CONFIG_NET_NS
  196 +
  197 +static inline void write_pnet(struct net **pnet, struct net *net)
  198 +{
  199 + *pnet = net;
  200 +}
  201 +
  202 +static inline struct net *read_pnet(struct net * const *pnet)
  203 +{
  204 + return *pnet;
  205 +}
  206 +
  207 +#else
  208 +
  209 +#define write_pnet(pnet, net) do { (void)(net);} while (0)
  210 +#define read_pnet(pnet) (&init_net)
  211 +
  212 +#endif
195 213  
196 214 #define for_each_net(VAR) \
197 215 list_for_each_entry(VAR, &net_namespace_list, list)