From: Xiao Liang <shaw.leon@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH net-next 5/5] net: ip_gre: Add netns_atomic module parameter
Date: Wed, 23 Oct 2024 10:31:46 +0800 [thread overview]
Message-ID: <20241023023146.372653-6-shaw.leon@gmail.com> (raw)
In-Reply-To: <20241023023146.372653-1-shaw.leon@gmail.com>
If set to true, create device in target netns (when different from
link-netns) without netns change, and use current netns as link-netns
if not specified explicitly.
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
net/ipv4/ip_gre.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index f1f31ebfc793..6ef7e98e4620 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -107,6 +107,11 @@ static bool log_ecn_error = true;
module_param(log_ecn_error, bool, 0644);
MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
+static bool netns_atomic;
+module_param(netns_atomic, bool, 0444);
+MODULE_PARM_DESC(netns_atomic,
+ "Create tunnel in target net namespace directly and use current net namespace as link-netns by default");
+
static struct rtnl_link_ops ipgre_link_ops __read_mostly;
static const struct header_ops ipgre_header_ops;
@@ -1393,6 +1398,7 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack)
{
+ struct net *link_net = netns_atomic ? src_net : dev_net(dev);
struct ip_tunnel_parm_kern p;
__u32 fwmark = 0;
int err;
@@ -1404,13 +1410,14 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev,
err = ipgre_netlink_parms(dev, data, tb, &p, &fwmark);
if (err < 0)
return err;
- return ip_tunnel_newlink(dev, tb, &p, fwmark);
+ return ip_tunnel_newlink_net(link_net, dev, tb, &p, fwmark);
}
static int erspan_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack)
{
+ struct net *link_net = netns_atomic ? src_net : dev_net(dev);
struct ip_tunnel_parm_kern p;
__u32 fwmark = 0;
int err;
@@ -1422,7 +1429,7 @@ static int erspan_newlink(struct net *src_net, struct net_device *dev,
err = erspan_netlink_parms(dev, data, tb, &p, &fwmark);
if (err)
return err;
- return ip_tunnel_newlink(dev, tb, &p, fwmark);
+ return ip_tunnel_newlink_net(link_net, dev, tb, &p, fwmark);
}
static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[],
@@ -1777,6 +1784,10 @@ static int __init ipgre_init(void)
pr_info("GRE over IPv4 tunneling driver\n");
+ ipgre_link_ops.netns_atomic = netns_atomic;
+ ipgre_tap_ops.netns_atomic = netns_atomic;
+ erspan_link_ops.netns_atomic = netns_atomic;
+
err = register_pernet_device(&ipgre_net_ops);
if (err < 0)
return err;
--
2.47.0
next prev parent reply other threads:[~2024-10-23 2:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 2:31 [PATCH net-next 0/5] net: Improve netns handling in RTNL and ip_tunnel Xiao Liang
2024-10-23 2:31 ` [PATCH net-next 1/5] rtnetlink: Lookup device in target netns when creating link Xiao Liang
2024-10-23 3:49 ` Kuniyuki Iwashima
2024-10-23 4:19 ` Xiao Liang
2024-10-23 2:31 ` [PATCH net-next 2/5] rtnetlink: Add netns_atomic flag in rtnl_link_ops Xiao Liang
2024-10-23 4:03 ` Kuniyuki Iwashima
2024-10-23 4:36 ` Xiao Liang
2024-10-23 2:31 ` [PATCH net-next 3/5] net: ip_tunnel: Build flow in underlay net namespace Xiao Liang
2024-10-23 2:31 ` [PATCH net-next 4/5] net: ip_tunnel: Add source netns support for newlink Xiao Liang
2024-10-23 2:31 ` Xiao Liang [this message]
2024-10-29 23:17 ` [PATCH net-next 0/5] net: Improve netns handling in RTNL and ip_tunnel Jakub Kicinski
2024-10-30 2:10 ` Xiao Liang
2024-10-30 23:35 ` Jakub Kicinski
2024-10-31 3:08 ` Xiao Liang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241023023146.372653-6-shaw.leon@gmail.com \
--to=shaw.leon@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).