Re: [PATCH batadv] batman-adv: gw: don't deselect gateway with active hardif

Nora Schiffer <[email protected]> Wed, 10 Jun 2026 19:50:12 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
On 07/06/2026 14:57, Sven Eckelmann wrote:
> The batadv_hardif_cnt() was previously checking if there is an
> batadv_hard_iface->mesh_iface which is has the same mesh_iface. And since
> batadv_hardif_disable_interface() was resetting the
> batadv_hard_iface->mesh_iface after this check, it had to verify whether
> *1* interface was still part of the mesh_iface before it started the
> gateway deselection.
> 
> But after batadv_hardif_cnt() is now checking the lower interfaces of
> mesh_iface and batadv_hardif_disable_interface() already removed the
> interface via netdev_upper_dev_unlink() earlier in this function, the check
> must now make sure that *0* interfaces can be found by batadv_hardif_cnt()
> before selected gateway must be deselected. Otherwise the deselection would
> already happen one batadv_hard_iface too early.
> 
> Fixes: 702c52a87eab ("batman-adv: store hard_iface as iflink private data")
> Cc: Nora Schiffer <[email protected]>
> Signed-off-by: Sven Eckelmann <[email protected]>
> ---
>   net/batman-adv/hard-interface.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
> index 60cee2c2..ae19f144 100644
> --- a/net/batman-adv/hard-interface.c
> +++ b/net/batman-adv/hard-interface.c
> @@ -879,7 +879,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
>   	batadv_hardif_recalc_extra_skbroom(hard_iface->mesh_iface);
>   
>   	/* nobody uses this interface anymore */
> -	if (batadv_hardif_cnt(hard_iface->mesh_iface) <= 1)
> +	if (batadv_hardif_cnt(hard_iface->mesh_iface) == 0)
>   		batadv_gw_check_client_stop(bat_priv);

The change looks correct, but this is the only remaining user of 
batadv_hardif_cnt(), and it's only checking if there aren't any hardifs, so 
this could avoid counting altogether and just use

	if (list_empty(&hard_iface->mesh_iface->adj_list.lower))

and drop batadv_hardif_cnt().

We are holding RTNL here, right?

Best,
Nora


>   
>   	hard_iface->mesh_iface = NULL;
> 
> ---
> base-commit: 385b248dd4e46c4ce022adeb1b13e547d1954901
> change-id: 20260607-gw-disable-check-f3393c3a4989
> 
> Best regards,
> --
> Sven Eckelmann <[email protected]>
>