summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorXiao Liang <shaw.leon@gmail.com>2025-02-19 15:50:29 +0300
committerJakub Kicinski <kuba@kernel.org>2025-02-22 02:28:02 +0300
commitcf517ac16ad96f3953d65ea198c0b310a1ffa14f (patch)
treed8243f30ed1f38dda34dae12a11885eeff4c3de5 /include
parent69c7be1b903fca2835e80ec506bd1d75ce84fb4d (diff)
downloadlinux-cf517ac16ad96f3953d65ea198c0b310a1ffa14f.tar.xz
net: Use link/peer netns in newlink() of rtnl_link_ops
Add two helper functions - rtnl_newlink_link_net() and rtnl_newlink_peer_net() for netns fallback logic. Peer netns falls back to link netns, and link netns falls back to source netns. Convert the use of params->net in netdevice drivers to one of the helper functions for clarity. Signed-off-by: Xiao Liang <shaw.leon@gmail.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250219125039.18024-4-shaw.leon@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/net/rtnetlink.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index 563a6a27436c..b22a106621fb 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -88,6 +88,23 @@ struct rtnl_newlink_params {
struct nlattr **data;
};
+/* Get effective link netns from newlink params. Generally, this is link_net
+ * and falls back to src_net. But for compatibility, a driver may * choose to
+ * use dev_net(dev) instead.
+ */
+static inline struct net *rtnl_newlink_link_net(struct rtnl_newlink_params *p)
+{
+ return p->link_net ? : p->src_net;
+}
+
+/* Get peer netns from newlink params. Fallback to link netns if peer netns is
+ * not specified explicitly.
+ */
+static inline struct net *rtnl_newlink_peer_net(struct rtnl_newlink_params *p)
+{
+ return p->peer_net ? : rtnl_newlink_link_net(p);
+}
+
/**
* struct rtnl_link_ops - rtnetlink link operations
*