Message ID | 20250214140705.2105890-1-edumazet@google.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 0784d83df3bfc977c13252a0599be924f0afa68d |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next] ndisc: ndisc_send_redirect() cleanup | expand |
On 2/14/25 7:07 AM, Eric Dumazet wrote: > ndisc_send_redirect() is always called under rcu_read_lock(). > > It can use dev_net_rcu() and avoid one redundant > rcu_read_lock()/rcu_read_unlock() pair. > > Signed-off-by: Eric Dumazet <edumazet@google.com> > --- > net/ipv6/ndisc.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > Reviewed-by: David Ahern <dsahern@kernel.org>
Hello: This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <kuba@kernel.org>: On Fri, 14 Feb 2025 14:07:05 +0000 you wrote: > ndisc_send_redirect() is always called under rcu_read_lock(). > > It can use dev_net_rcu() and avoid one redundant > rcu_read_lock()/rcu_read_unlock() pair. > > Signed-off-by: Eric Dumazet <edumazet@google.com> > > [...] Here is the summary with links: - [net-next] ndisc: ndisc_send_redirect() cleanup https://git.kernel.org/netdev/net-next/c/0784d83df3bf You are awesome, thank you!
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 8699d1a188dc4a15ac0b65229c4dd19240c9c054..ecb5c4b8518fdd72d0e89640641ec917743e9c72 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1680,7 +1680,7 @@ static void ndisc_fill_redirect_hdr_option(struct sk_buff *skb, void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) { struct net_device *dev = skb->dev; - struct net *net = dev_net(dev); + struct net *net = dev_net_rcu(dev); struct sock *sk = net->ipv6.ndisc_sk; int optlen = 0; struct inet_peer *peer; @@ -1695,8 +1695,8 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) ops_data_buf[NDISC_OPS_REDIRECT_DATA_SPACE], *ops_data = NULL; bool ret; - if (netif_is_l3_master(skb->dev)) { - dev = dev_get_by_index_rcu(dev_net(skb->dev), IPCB(skb)->iif); + if (netif_is_l3_master(dev)) { + dev = dev_get_by_index_rcu(net, IPCB(skb)->iif); if (!dev) return; } @@ -1734,10 +1734,8 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target) goto release; } - rcu_read_lock(); peer = inet_getpeer_v6(net->ipv6.peers, &ipv6_hdr(skb)->saddr); ret = inet_peer_xrlim_allow(peer, 1*HZ); - rcu_read_unlock(); if (!ret) goto release;
ndisc_send_redirect() is always called under rcu_read_lock(). It can use dev_net_rcu() and avoid one redundant rcu_read_lock()/rcu_read_unlock() pair. Signed-off-by: Eric Dumazet <edumazet@google.com> --- net/ipv6/ndisc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)