Subject: Re: [PATCH v5 1/2] net: arp: introduce arp_evict_nocarrier sysctl parameter

From: David Ahern <[email-masked]>
Date: Thu, 21 Oct 2021 08:08:05 -0600

On 10/20/21 6:32 PM, James Prestwood wrote:
> diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
> index 922dd73e5740..4d3b8d1463b7 100644
> --- a/net/ipv4/arp.c
> +++ b/net/ipv4/arp.c
> @@ -1257,7 +1259,16 @@ static int arp_netdev_event(struct notifier_block *this, unsigned long event,
>  		change_info = ptr;
>  		if (change_info->flags_changed & IFF_NOARP)
>  			neigh_changeaddr(&arp_tbl, dev);
> -		if (!netif_carrier_ok(dev))
> +
> +		rcu_read_lock();
> +		in_dev = __in_dev_get_rcu(dev);
> +		if (!in_dev)
> +			evict_nocarrier = true;
> +		else
> +			evict_nocarrier = IN_DEV_ARP_EVICT_NOCARRIER(in_dev);
> +		rcu_read_unlock();

I believe the rtnl lock is held, so you can use __in_dev_get_rtnl and
avoid the rcu_read_{,un}lock.

> +
> +		if (evict_nocarrier && !netif_carrier_ok(dev))
>  			neigh_carrier_down(&arp_tbl, dev);
>  		break;
>  	default: