Re: [nft PATCH v2 1/3] mnl: Support simple wildcards in netdev hooks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 16, 2025 at 11:47:09AM +0200, Florian Westphal wrote:
> Phil Sutter <phil@xxxxxx> wrote:
> > +		len = strlen(dev_array[0].ifname) + 1;
> > +		if (dev_array[0].ifname[len - 2] == '*')
> > +			len -= 2;
> 
> Not obvious to me, is there a guarantee that 'len' is 2?
> And, what if len yields 0 here?

Oh, right. Same goes for the introduced libnftnl helpers.

> > +			if (dev_array[i].ifname[len - 2] == '*')
> > +				len -= 2;
> > +			mnl_attr_put(nlh, NFTA_DEVICE_NAME, len, dev_array[i].ifname);
> >  			mnl_attr_nest_end(nlh, nest_dev);
> >  		}
> >  	}
> > @@ -2084,14 +2090,17 @@ static void mnl_nft_ft_devs_build(struct nlmsghdr *nlh, struct cmd *cmd)
> >  {
> >  	const struct expr *dev_expr = cmd->flowtable->dev_expr;
> >  	const struct nft_dev *dev_array;
> > +	int i, len, num_devs = 0;
> >  	struct nlattr *nest_dev;
> > -	int i, num_devs= 0;
> >  
> >  	dev_array = nft_dev_array(dev_expr, &num_devs);
> >  	nest_dev = mnl_attr_nest_start(nlh, NFTA_FLOWTABLE_HOOK_DEVS);
> >  	for (i = 0; i < num_devs; i++) {
> >  		cmd_add_loc(cmd, nlh, dev_array[i].location);
> > -		mnl_attr_put_strz(nlh, NFTA_DEVICE_NAME, dev_array[i].ifname);
> > +		len = strlen(dev_array[i].ifname) + 1;
> > +		if (dev_array[i].ifname[len - 2] == '*')
> > +			len -= 2;
> > +		mnl_attr_put(nlh, NFTA_DEVICE_NAME, len, dev_array[i].ifname);
> 
> This (test, subtract, put) is a repeating pattern, perhaps this warrants a helper?

It's even there already, (still) named 'mnl_attr_put_ifname' in my
libnftnl patch. I'll export it (with correct prefix) for use in
nftables.

Thanks, Phil




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux