Subject: Re: [PATCH net-next 02/13] ipv4: Move IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN to helper

From: Ido Schimmel <[email-masked]>
Date: Wed, 27 Mar 2019 07:44:43 +0000

On Tue, Mar 26, 2019 at 08:29:31PM -0700, David Ahern wrote:
> From: David Ahern <[email-masked]>
> 
> in_dev lookup followed by IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN check
> is called in several places, some with the rcu lock and others with the
> rtnl held.
> 
> Move the check to a helper similar to what IPv6 has. Since the helper
> can be invoked from either context use rcu_dereference_rtnl to
> dereference ip_ptr.
> 
> Signed-off-by: David Ahern <[email-masked]>

Reviewed-by: Ido Schimmel <[email-masked]>

See one nit below.

> ---
>  include/linux/inetdevice.h | 14 ++++++++++++++
>  net/ipv4/fib_semantics.c   | 31 +++++++------------------------
>  net/ipv4/fib_trie.c        |  4 +---
>  3 files changed, 22 insertions(+), 27 deletions(-)
> 
> diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
> index a64f21a97369..35e0390fd7b8 100644
> --- a/include/linux/inetdevice.h
> +++ b/include/linux/inetdevice.h
> @@ -237,6 +237,20 @@ static inline struct in_device *__in_dev_get_rtnl(const struct net_device *dev)
>  	return rtnl_dereference(dev->ip_ptr);
>  }
>  
> +/* called with rc_read_lock or rtnl held */

s/rc_read_lock/rcu_read_lock/

> +static inline bool ip_ignore_linkdown(const struct net_device *dev)
> +{
> +	struct in_device *in_dev;
> +	bool rc = false;
> +
> +	in_dev = rcu_dereference_rtnl(dev->ip_ptr);
> +	if (in_dev &&
> +	    IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
> +		rc = true;
> +
> +	return rc;
> +}