Enhances a net_device from the current namespace only assignment to
a network context.
Define nd_net macro to handle existing code references. Add macros
for generating net_ctx struct given a net_device (needed because of
the way net references are done) and for comparing a given net_ctx
struct to the context of a net_device.
Signed-off-by: David Ahern <redacted>
---
include/linux/netdevice.h | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 16251e96e6aa..55a221fec12b 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1697,9 +1697,8 @@ struct net_device {
struct netpoll_info __rcu *npinfo;
#endif
-#ifdef CONFIG_NET_NS
- struct net *nd_net;
-#endif
+ struct net_ctx net_ctx;
+#define nd_net net_ctx.net
/* mid-layer private */
union {@@ -1845,6 +1844,18 @@ void dev_net_set(struct net_device *dev, struct net *net)
#endif
}
+/* get net_ctx from device */
+#define DEV_NET_CTX(dev) { .net = dev_net((dev)) }
+
+static inline
+int dev_net_ctx_eq(const struct net_device *dev, struct net_ctx *ctx)
+{
+ if (net_eq(dev_net(dev), ctx->net))
+ return 1;
+
+ return 0;
+}
+
static inline bool netdev_uses_dsa(struct net_device *dev)
{
#if IS_ENABLED(CONFIG_NET_DSA)--
1.9.3 (Apple Git-50)