Re: [PATCH nf-next,v2 1/3] net: pass net_device_path_ctx struct to dev_fill_forward_path()

Eric Woudstra <[email protected]>
Newsgroups gmane.comp.security.firewalls.netfilter.devel
Message-ID <[email protected]>

On 7/10/26 12:07 PM, Pablo Neira Ayuso wrote:
> Generalize dev_fill_forward_path() so it can be used by the bridge
> family to retrieve the bridge vlan filtering information from the
> bridge port when discovering the bridge flowtable path.
> 
> Signed-off-by: Pablo Neira Ayuso <[email protected]>
> ---
> v2: - move nft_dev_fill_forward_path_init() call after out: goto tag
>       to fix a crash otherwise in the existing flowtable ip family.
> 
>  include/linux/netdevice.h          |  2 +-
>  net/core/dev.c                     | 18 +++++++-----------
>  net/netfilter/nf_flow_table_path.c | 14 ++++++++++++--
>  3 files changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index 9981d637f8b5..db04b6d2e8d2 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -3420,7 +3420,7 @@ void dev_remove_offload(struct packet_offload *po);
>  
>  int dev_get_iflink(const struct net_device *dev);
>  int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb);
> -int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
> +int dev_fill_forward_path(struct net_device_path_ctx *ctx,
>  			  struct net_device_path_stack *stack);
>  struct net_device *dev_get_by_name(struct net *net, const char *name);
>  struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);

dev_fill_forward_path is also used in mtk_ppe_offload.c and airoha_ppe.c

This is the build error for mtk_ppe_offload.c:

drivers/net/ethernet/mediatek/mtk_ppe_offload.c: In function
'mtk_flow_get_wdma_info':
drivers/net/ethernet/mediatek/mtk_ppe_offload.c:105:37: error: passing
argument 1 of 'dev_fill_forward_path' from incompatible pointer type
[-Wincompatible-pointer-types]
  105 |         err = dev_fill_forward_path(dev, addr, &stack);
      |                                     ^~~
      |                                     |
      |                                     struct net_device *
In file included from ./include/net/sock.h:46,
                 from ./include/linux/tcp.h:19,
                 from ./include/linux/ipv6.h:103,
                 from drivers/net/ethernet/mediatek/mtk_ppe_offload.c:9:
./include/linux/netdevice.h:3435:55: note: expected 'struct
net_device_path_ctx *' but argument is of type 'struct net_device *'
 3435 | int dev_fill_forward_path(struct net_device_path_ctx *ctx,
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
drivers/net/ethernet/mediatek/mtk_ppe_offload.c:105:42: error: passing
argument 2 of 'dev_fill_forward_path' from incompatible pointer type
[-Wincompatible-pointer-types]
  105 |         err = dev_fill_forward_path(dev, addr, &stack);
      |                                          ^~~~
      |                                          |
      |                                          const u8 * {aka const
unsigned char *}
./include/linux/netdevice.h:3436:57: note: expected 'struct
net_device_path_stack *' but argument is of type 'const u8 *' {aka
'const unsigned char *'}
 3436 |                           struct net_device_path_stack *stack);
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
drivers/net/ethernet/mediatek/mtk_ppe_offload.c:105:15: error: too many
arguments to function 'dev_fill_forward_path'; expected 2, have 3
  105 |         err = dev_fill_forward_path(dev, addr, &stack);
      |               ^~~~~~~~~~~~~~~~~~~~~            ~~~~~~
./include/linux/netdevice.h:3435:5: note: declared here
 3435 | int dev_fill_forward_path(struct net_device_path_ctx *ctx,
      |     ^~~~~~~~~~~~~~~~~~~~~
make[6]: *** [scripts/Makefile.build:289:
drivers/net/ethernet/mediatek/mtk_ppe_offload.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/net/ethernet/mediatek]
Error 2
make[4]: *** [scripts/Makefile.build:549: drivers/net/ethernet] Error 2


> diff --git a/net/core/dev.c b/net/core/dev.c
> index 714d05283500..24c384ef9e78 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -750,41 +750,37 @@ static struct net_device_path *dev_fwd_path(struct net_device_path_stack *stack)
>  	return &stack->path[k];
>  }
>  
> -int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
> +int dev_fill_forward_path(struct net_device_path_ctx *ctx,
>  			  struct net_device_path_stack *stack)
>  {
>  	const struct net_device *last_dev;
> -	struct net_device_path_ctx ctx = {
> -		.dev	= dev,
> -	};
>  	struct net_device_path *path;
>  	int ret = 0;
>  
> -	memcpy(ctx.daddr, daddr, sizeof(ctx.daddr));
>  	stack->num_paths = 0;
> -	while (ctx.dev && ctx.dev->netdev_ops->ndo_fill_forward_path) {
> -		last_dev = ctx.dev;
> +	while (ctx->dev && ctx->dev->netdev_ops->ndo_fill_forward_path) {
> +		last_dev = ctx->dev;
>  		path = dev_fwd_path(stack);
>  		if (!path)
>  			return -1;
>  
>  		memset(path, 0, sizeof(struct net_device_path));
> -		ret = ctx.dev->netdev_ops->ndo_fill_forward_path(&ctx, path);
> +		ret = ctx->dev->netdev_ops->ndo_fill_forward_path(ctx, path);
>  		if (ret < 0)
>  			return -1;
>  
> -		if (WARN_ON_ONCE(last_dev == ctx.dev))
> +		if (WARN_ON_ONCE(last_dev == ctx->dev))
>  			return -1;
>  	}
>  
> -	if (!ctx.dev)
> +	if (!ctx->dev)
>  		return ret;
>  
>  	path = dev_fwd_path(stack);
>  	if (!path)
>  		return -1;
>  	path->type = DEV_PATH_ETHERNET;
> -	path->dev = ctx.dev;
> +	path->dev = ctx->dev;
>  
>  	return ret;
>  }
> diff --git a/net/netfilter/nf_flow_table_path.c b/net/netfilter/nf_flow_table_path.c
> index 98c03b487f52..5455149e5d9a 100644
> --- a/net/netfilter/nf_flow_table_path.c
> +++ b/net/netfilter/nf_flow_table_path.c
> @@ -42,6 +42,14 @@ static bool nft_is_valid_ether_device(const struct net_device *dev)
>  	return true;
>  }
>  
> +static void nft_dev_fill_forward_path_init(struct net_device_path_ctx *ctx,
> +					   const struct net_device *dev, const u8 *daddr)
> +{
> +	memset(ctx, 0, sizeof(*ctx));
> +	ctx->dev	= dev;
> +	memcpy(ctx->daddr, daddr, sizeof(ctx->daddr));
> +}
> +
>  static int nft_dev_fill_forward_path(const struct nf_flow_route *route,
>  				     const struct dst_entry *dst_cache,
>  				     const struct nf_conn *ct,
> @@ -50,6 +58,7 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,
>  {
>  	const void *daddr = &ct->tuplehash[!dir].tuple.src.u3;
>  	struct net_device *dev = dst_cache->dev;
> +	struct net_device_path_ctx ctx;
>  	struct neighbour *n;
>  	u8 nud_state;
>  
> @@ -70,9 +79,10 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,
>  
>  	if (!(nud_state & NUD_VALID))
>  		return -1;
> -
>  out:
> -	return dev_fill_forward_path(dev, ha, stack);
> +	nft_dev_fill_forward_path_init(&ctx, dev, ha);
> +
> +	return dev_fill_forward_path(&ctx, stack);
>  }
>  
>  struct nft_forward_info {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.