All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Phil Sutter <phil@nwl.cc>,
	Alexandre Knecht <knecht.alexandre@gmail.com>,
	netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf-next v4] parser_json: support handle for rule positioning without breaking other objects
Date: Fri, 14 Nov 2025 14:36:43 +0100	[thread overview]
Message-ID: <aRcwa_ZsBrvKFEci@strlen.de> (raw)
In-Reply-To: <aRcnt9F7N5WiV-zi@orbyte.nwl.cc>

Phil Sutter <phil@nwl.cc> wrote:
> > +/* Mask for flags that affect expression parsing context */
> > +#define CTX_F_EXPR_MASK	(CTX_F_RHS | CTX_F_STMT | CTX_F_PRIMARY | CTX_F_DTYPE | \
> > +			 CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_MAP | \
> > +			 CTX_F_CONCAT)
> 
> Maybe define as 'UINT32_MAX & ~(CTX_F_COLLAPSED | CTX_F_IMPLICIT)'
> instead?

> >  struct json_ctx {
> >  	struct nft_ctx *nft;
> > @@ -1725,10 +1731,14 @@ static struct expr *json_parse_expr(struct json_ctx *ctx, json_t *root)
> >  		return NULL;
> >  
> >  	for (i = 0; i < array_size(cb_tbl); i++) {
> > +		uint32_t expr_flags;
> > +
> >  		if (strcmp(type, cb_tbl[i].name))
> >  			continue;
> >  
> > -		if ((cb_tbl[i].flags & ctx->flags) != ctx->flags) {
> > +		/* Only check expression context flags, not command-level flags */
> > +		expr_flags = ctx->flags & CTX_F_EXPR_MASK;
> > +		if ((cb_tbl[i].flags & expr_flags) != expr_flags) {

So when adding CTX_F_BLA as new expr flag, one has to rember to add it
to CTX_F_EXPR_MASK.  Given that I concur with Phil.

> >  	rule = rule_alloc(int_loc, NULL);
> >  
> >  	json_unpack(root, "{s:s}", "comment", &comment);
> > @@ -4352,8 +4374,21 @@ static struct cmd *json_parse_cmd(struct json_ctx *ctx, json_t *root)
> >  
> >  		return parse_cb_table[i].cb(ctx, tmp, parse_cb_table[i].op);
> >  	}
> > -	/* to accept 'list ruleset' output 1:1, try add command */
> > -	return json_parse_cmd_add(ctx, root, CMD_ADD);
> > +	/* to accept 'list ruleset' output 1:1, try add command
> > +	 * Mark as implicit to distinguish from explicit add commands.
> > +	 * This allows explicit {"add": {"rule": ...}} to use handle for positioning
> > +	 * while implicit {"rule": ...} (export format) ignores handles.
> > +	 */
> > +	{
> > +		uint32_t old_flags = ctx->flags;
> > +		struct cmd *cmd;
> > +
> > +		ctx->flags |= CTX_F_IMPLICIT;
> > +		cmd = json_parse_cmd_add(ctx, root, CMD_ADD);
> > +		ctx->flags = old_flags;
> > +
> > +		return cmd;
> > +	}
> 
> This use of nested blocks is uncommon in this project. I suggest to
> either introduce a wrapper function or declare the two variables at the
> start of the function's body.

Right, as json_parse_cmd() is small I would go for the latter.

> > +# Verify all objects were created
> > +$NFT list ruleset > /dev/null || { echo "Failed to list ruleset after add operations"; exit 1; }
> 
> This command does not do what the comment says. To verify object
> creation, either use a series of 'nft list table/chain/set/...' commands
> or compare against a stored ruleset dump. See
> tests/shell/testcases/cache/0010_implicit_chain_0 for a simple example.

Yes, please use stored dump and let the test wrapper validate this if
possible.  I understand this can't work when the script has to validate
intermediate states too, but the last expected state canand should be
handled via dump.  More dumps also enhance fuzzer coverage since the
dumps are used for the initial input pool.

Also run "tools/check-tree.sh" and make sure it doesn't result in new
errors with the new test case.

If you like you can also split the actual patch and the test cases in
multiple patches, but thats up to you.

  reply	other threads:[~2025-11-14 13:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 20:30 [PATCH nf-next v4] parser_json: support handle for rule positioning without breaking other objects Alexandre Knecht
2025-11-14 12:59 ` Phil Sutter
2025-11-14 13:36   ` Florian Westphal [this message]
2026-01-14 15:27     ` Phil Sutter
2026-01-15 20:23       ` Alexandre Knecht
2026-01-16 12:39         ` Phil Sutter
2026-01-19 14:18           ` Alexandre Knecht

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=aRcwa_ZsBrvKFEci@strlen.de \
    --to=fw@strlen.de \
    --cc=knecht.alexandre@gmail.com \
    --cc=netfilter-devel@vger.kernel.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.