From: Phil Sutter <phil@nwl.cc>
To: Alexandre Knecht <knecht.alexandre@gmail.com>
Cc: netfilter-devel@vger.kernel.org, fw@strlen.de
Subject: Re: [PATCH v5 1/3] parser_json: support handle for rule positioning in explicit JSON format
Date: Tue, 20 Jan 2026 15:08:35 +0100 [thread overview]
Message-ID: <aW-MY7iZLC-iVuht@orbyte.nwl.cc> (raw)
In-Reply-To: <20260119140813.536515-2-knecht.alexandre@gmail.com>
Hi Alexandre,
On Mon, Jan 19, 2026 at 03:08:11PM +0100, Alexandre Knecht wrote:
> Implementation details:
> - CTX_F_IMPLICIT flag (bit 10) marks implicit add commands
> - CTX_F_EXPR_MASK uses inverse mask for future-proof expression flag filtering
> - Handle-to-position conversion in json_parse_cmd_add_rule()
> - Variables declared at function start per project style
Thanks for your follow-up, just two nits:
[...]
> diff --git a/src/parser_json.c b/src/parser_json.c
> index 7b4f3384..87266de6 100644
> --- a/src/parser_json.c
> +++ b/src/parser_json.c
[...]
> @@ -3201,6 +3209,18 @@ static struct cmd *json_parse_cmd_add_rule(struct json_ctx *ctx, json_t *root,
> h.index.id++;
> }
>
> + /* For explicit add/insert/create commands, handle is used for positioning.
> + * Convert handle to position for proper rule placement.
> + * Skip this for implicit adds (export/import format).
> + */
> + if (!(ctx->flags & CTX_F_IMPLICIT) &&
> + !json_unpack(root, "{s:I}", "handle", &h.handle.id)) {
> + if (op == CMD_INSERT || op == CMD_ADD || op == CMD_CREATE) {
> + h.position.id = h.handle.id;
> + h.handle.id = 0;
> + }
> + }
Please merge the nested if-conditionals. I suggest sorting expressions
from cheap to expensive:
| if (!(ctx->flags & CTX_F_IMPLICIT) &&
| (op == CMD_INSERT || op == CMD_ADD || op == CMD_CREATE) &&
| !json_unpack(root, "{s:I}", "handle", &h.handle.id)) {
[...]
> @@ -4344,6 +4364,8 @@ static struct cmd *json_parse_cmd(struct json_ctx *ctx, json_t *root)
> };
> unsigned int i;
> json_t *tmp;
> + uint32_t old_flags;
> + struct cmd *cmd;
Please use Reverse Christmas Tree notation, i.e. reverse-sort variable
definitions by line length.
Thanks, Phil
next prev parent reply other threads:[~2026-01-20 14:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 14:08 [PATCH v5 0/3] parser_json: support handle for rule positioning Alexandre Knecht
2026-01-19 14:08 ` [PATCH v5 1/3] parser_json: support handle for rule positioning in explicit JSON format Alexandre Knecht
2026-01-20 14:08 ` Phil Sutter [this message]
2026-01-20 14:27 ` Alexandre Knecht
2026-01-20 14:56 ` Phil Sutter
2026-01-19 14:08 ` [PATCH v5 2/3] tests: shell: add JSON test for all object types Alexandre Knecht
2026-01-20 14:39 ` Phil Sutter
2026-01-19 14:08 ` [PATCH v5 3/3] tests: shell: add JSON test for handle-based rule positioning Alexandre Knecht
2026-01-20 14:46 ` 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=aW-MY7iZLC-iVuht@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--cc=knecht.alexandre@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox