From: Florian Westphal <fw@strlen.de>
To: Phil Sutter <phil@nwl.cc>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>, netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH v2 1/3] mnl: Support simple wildcards in netdev hooks
Date: Wed, 16 Jul 2025 11:47:09 +0200 [thread overview]
Message-ID: <aHd1HbLSzO3KHI64@strlen.de> (raw)
In-Reply-To: <20250715151538.14882-2-phil@nwl.cc>
Phil Sutter <phil@nwl.cc> 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?
> + 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?
next prev parent reply other threads:[~2025-07-16 9:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 15:15 [nft PATCH v2 0/3] Support wildcard netdev hooks Phil Sutter
2025-07-15 15:15 ` [nft PATCH v2 1/3] mnl: Support simple wildcards in " Phil Sutter
2025-07-16 9:47 ` Florian Westphal [this message]
2025-07-16 10:26 ` Phil Sutter
2025-07-15 15:15 ` [nft PATCH v2 2/3] parser_bison: Accept ASTERISK_STRING in flowtable_expr_member Phil Sutter
2025-07-15 15:15 ` [nft PATCH v2 3/3] tests: shell: Test ifname-based hooks Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aHd1HbLSzO3KHI64@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.