From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
"Daniel Borkmann" <daniel@iogearbox.net>,
Nikolay Aleksandrov <razor@blackwall.org>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v1 net-next 2/8] rtnetlink: Factorise rtnl_link_get_net_tb().
Date: Mon, 4 Nov 2024 18:05:08 -0800 [thread overview]
Message-ID: <20241105020514.41963-3-kuniyu@amazon.com> (raw)
In-Reply-To: <20241105020514.41963-1-kuniyu@amazon.com>
In ops->newlink(), veth, vxcan, and netkit call rtnl_link_get_net() with
a net pointer, which is the first argument of ->newlink().
rtnl_link_get_net() could return another netns based on IFLA_NET_NS_PID
and IFLA_NET_NS_FD in the peer device's attributes.
We want to get it and fill rtnl_nets->nets[] in advance.
Let's factorise the peer netns part from rtnl_link_get_net().
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
include/net/rtnetlink.h | 1 +
net/core/rtnetlink.c | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index 814364367dd7..b9ed44b2d056 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -221,6 +221,7 @@ struct rtnl_af_ops {
int rtnl_af_register(struct rtnl_af_ops *ops);
void rtnl_af_unregister(struct rtnl_af_ops *ops);
+struct net *rtnl_link_get_net_tb(struct nlattr *tb[]);
struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
struct net_device *rtnl_create_link(struct net *net, const char *ifname,
unsigned char name_assign_type,
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index f98706ad390a..1bc8afcefc1e 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2511,9 +2511,10 @@ int rtnl_nla_parse_ifinfomsg(struct nlattr **tb, const struct nlattr *nla_peer,
}
EXPORT_SYMBOL(rtnl_nla_parse_ifinfomsg);
-struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
+struct net *rtnl_link_get_net_tb(struct nlattr *tb[])
{
- struct net *net;
+ struct net *net = NULL;
+
/* Examine the link attributes and figure out which
* network namespace we are talking about.
*/
@@ -2521,8 +2522,18 @@ struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
else if (tb[IFLA_NET_NS_FD])
net = get_net_ns_by_fd(nla_get_u32(tb[IFLA_NET_NS_FD]));
- else
+
+ return net;
+}
+EXPORT_SYMBOL(rtnl_link_get_net_tb);
+
+struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
+{
+ struct net *net = rtnl_link_get_net_tb(tb);
+
+ if (!net)
net = get_net(src_net);
+
return net;
}
EXPORT_SYMBOL(rtnl_link_get_net);
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2024-11-05 2:06 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 2:05 [PATCH v1 net-next 0/8] rtnetlink: Convert rtnl_newlink() to per-netns RTNL Kuniyuki Iwashima
2024-11-05 2:05 ` [PATCH v1 net-next 1/8] rtnetlink: Introduce struct rtnl_nets and helpers Kuniyuki Iwashima
2024-11-05 10:16 ` Eric Dumazet
2024-11-06 0:35 ` Jakub Kicinski
2024-11-06 0:41 ` Kuniyuki Iwashima
2024-11-05 2:05 ` Kuniyuki Iwashima [this message]
2024-11-05 10:18 ` [PATCH v1 net-next 2/8] rtnetlink: Factorise rtnl_link_get_net_tb() Eric Dumazet
2024-11-06 0:37 ` Jakub Kicinski
2024-11-06 0:44 ` Kuniyuki Iwashima
2024-11-05 2:05 ` [PATCH v1 net-next 3/8] rtnetlink: Add peer_type in struct rtnl_link_ops Kuniyuki Iwashima
2024-11-05 10:23 ` Eric Dumazet
2024-11-06 0:39 ` Jakub Kicinski
2024-11-06 0:39 ` Jakub Kicinski
2024-11-06 0:52 ` Kuniyuki Iwashima
2024-11-06 0:58 ` Kuniyuki Iwashima
2024-11-06 1:04 ` Jakub Kicinski
2024-11-06 1:22 ` Kuniyuki Iwashima
2024-11-05 2:05 ` [PATCH v1 net-next 4/8] veth: Set VETH_INFO_PEER to veth_link_ops.peer_type Kuniyuki Iwashima
2024-11-05 10:24 ` Eric Dumazet
2024-11-05 2:05 ` [PATCH v1 net-next 5/8] vxcan: Set VXCAN_INFO_PEER to vxcan_link_ops.peer_type Kuniyuki Iwashima
2024-11-05 10:37 ` Eric Dumazet
2024-11-05 2:05 ` [PATCH v1 net-next 6/8] netkit: Set IFLA_NETKIT_PEER_INFO to netkit_link_ops.peer_type Kuniyuki Iwashima
2024-11-05 10:39 ` Eric Dumazet
2024-11-05 2:05 ` [PATCH v1 net-next 7/8] rtnetlink: Convert RTM_NEWLINK to per-netns RTNL Kuniyuki Iwashima
2024-11-05 10:40 ` Eric Dumazet
2024-11-05 16:22 ` Paolo Abeni
2024-11-05 17:11 ` Kuniyuki Iwashima
2024-11-05 2:05 ` [PATCH v1 net-next 8/8] rtnetlink: Register rtnl_dellink() and rtnl_setlink() with RTNL_FLAG_DOIT_PERNET_WIP Kuniyuki Iwashima
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=20241105020514.41963-3-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=andrew+netdev@lunn.ch \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
/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).