Message ID | 20241105020514.41963-3-kuniyu@amazon.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | rtnetlink: Convert rtnl_newlink() to per-netns RTNL. | expand |
On Tue, Nov 5, 2024 at 3:06 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote: > > 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> Reviewed-by: Eric Dumazet <edumazet@google.com>
On Mon, 4 Nov 2024 18:05:08 -0800 Kuniyuki Iwashima wrote:
> +struct net *rtnl_link_get_net_tb(struct nlattr *tb[])
"tb" stands for "table", AFAIU, it's not a very meaningful suffix.
I'd suggestrtnl_link_get_net_ifla or rtnl_get_net_ifla
ifla == if_link attribute
From: Jakub Kicinski <kuba@kernel.org> Date: Tue, 5 Nov 2024 16:37:07 -0800 > On Mon, 4 Nov 2024 18:05:08 -0800 Kuniyuki Iwashima wrote: > > +struct net *rtnl_link_get_net_tb(struct nlattr *tb[]) > > "tb" stands for "table", AFAIU, it's not a very meaningful suffix. > I'd suggestrtnl_link_get_net_ifla or rtnl_get_net_ifla > ifla == if_link attribute Will use rtnl_get_net_ifla().
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);
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(-)