Subject: Re: [PATCH net-next v2 1/3] nsim: Add support for VLAN filters

From: Sabrina Dubroca <[email-masked]>
Date: Sat, 28 Feb 2026 12:21:42 +0100

2026-02-27, 11:02:25 +0200, Cosmin Ratiu wrote:
> Add support for storing the list of VLANs in nsim devices, together with
> ops for adding/removing them and a debug file to show them.
> 
> This will be used in upcoming tests.
> 
> Signed-off-by: Cosmin Ratiu <[email-masked]>
> ---
>  drivers/net/netdevsim/netdev.c    | 59 +++++++++++++++++++++++++++++--
>  drivers/net/netdevsim/netdevsim.h |  8 +++++
>  2 files changed, 65 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
> index 6285fbefe38a..7177711cf9fc 100644
> --- a/drivers/net/netdevsim/netdev.c
> +++ b/drivers/net/netdevsim/netdev.c
> @@ -602,6 +602,36 @@ static int nsim_stop(struct net_device *dev)
>  	return 0;
>  }
>  
> +static int nsim_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
> +{
> +	struct netdevsim *ns = netdev_priv(dev);
> +
> +	if (vid >= VLAN_N_VID)
> +		return -EINVAL;
> +
> +	if (proto == htons(ETH_P_8021Q))
> +		set_bit(vid, ns->vlan.ctag);

Maybe

    DEBUG_NET_WARN_ON_ONCE(test_and_set_bit(vid, ns->vlan.ctag));

> +	else if (proto == htons(ETH_P_8021AD))
> +		set_bit(vid, ns->vlan.stag);
> +
> +	return 0;
> +}
> +
> +static int nsim_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
> +{
> +	struct netdevsim *ns = netdev_priv(dev);
> +
> +	if (vid >= VLAN_N_VID)
> +		return -EINVAL;
> +
> +	if (proto == htons(ETH_P_8021Q))
> +		clear_bit(vid, ns->vlan.ctag);

and

    DEBUG_NET_WARN_ON_ONCE(!test_and_clear_bit(vid, ns->vlan.ctag));

> +	else if (proto == htons(ETH_P_8021AD))
> +		clear_bit(vid, ns->vlan.stag);
> +
> +	return 0;
> +}

and in nsim_destroy, something like:

    for_each_set_bit(vid, ns->vlan.ctag, VLAN_N_VID)
        DEBUG_NET_WARN_ON_ONCE(1);
    for_each_set_bit(vid, ns->vlan.stag, VLAN_N_VID)
        DEBUG_NET_WARN_ON_ONCE(1);

just to make sure that we did all the accounting correctly?

This last one would catch problems like the error handling spotted by
AI (just add 3 offloaded devices + one non-offloaded, then try to
offload the last one, netdevsim accepts only 3 secys so mdo_add_secy
will fail):

# echo 1 > /sys/bus/netdevsim/new_device
# ip link add link eni1np1 type macsec port 5 offload mac
# ip link add link eni1np1 type macsec port 6 offload mac
# ip link add link eni1np1 type macsec port 7 offload mac
# ip link add macsec_H link eni1np1 type macsec offload off
# ip link add link macsec_H type  vlan id 20
# cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan
# ip link set macsec_H type  macsec offload mac
RTNETLINK answers: No space left on device
# cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan
ctag 20
# echo 1 > /sys/bus/netdevsim/del_device
<splat>

-- 
Sabrina