Message ID | 20250319230743.65267-8-kuniyu@amazon.com (mailing list archive) |
---|---|
State | New |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | nexthop: Convert RTM_{NEW,DEL}NEXTHOP to per-netns RTNL. | expand |
On Thu, Mar 20, 2025 at 12:11 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote: > > In rtm_del_nexthop(), only nexthop_find_by_id() and remove_nexthop() > require RTNL as they touch net->nexthop.rb_root. > > Let's move RTNL down as rtnl_net_lock() before nexthop_find_by_id(). > > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com>
On 3/19/25 5:06 PM, Kuniyuki Iwashima wrote: > In rtm_del_nexthop(), only nexthop_find_by_id() and remove_nexthop() > require RTNL as they touch net->nexthop.rb_root. > > Let's move RTNL down as rtnl_net_lock() before nexthop_find_by_id(). > > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> > --- > net/ipv4/nexthop.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > Reviewed-by: David Ahern <dsahern@kernel.org>
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 06d5467eadc1..467151517023 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3314,13 +3314,17 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err) return err; + rtnl_net_lock(net); + nh = nexthop_find_by_id(net, id); - if (!nh) - return -ENOENT; + if (nh) + remove_nexthop(net, nh, &nlinfo); + else + err = -ENOENT; - remove_nexthop(net, nh, &nlinfo); + rtnl_net_unlock(net); - return 0; + return err; } /* rtnl */ @@ -4074,7 +4078,8 @@ static struct pernet_operations nexthop_net_ops = { static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] __initconst = { {.msgtype = RTM_NEWNEXTHOP, .doit = rtm_new_nexthop, .flags = RTNL_FLAG_DOIT_PERNET}, - {.msgtype = RTM_DELNEXTHOP, .doit = rtm_del_nexthop}, + {.msgtype = RTM_DELNEXTHOP, .doit = rtm_del_nexthop, + .flags = RTNL_FLAG_DOIT_PERNET}, {.msgtype = RTM_GETNEXTHOP, .doit = rtm_get_nexthop, .dumpit = rtm_dump_nexthop}, {.msgtype = RTM_GETNEXTHOPBUCKET, .doit = rtm_get_nexthop_bucket,
In rtm_del_nexthop(), only nexthop_find_by_id() and remove_nexthop() require RTNL as they touch net->nexthop.rb_root. Let's move RTNL down as rtnl_net_lock() before nexthop_find_by_id(). Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> --- net/ipv4/nexthop.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)