From: Jeremy Sowden <jeremy@azazel.net>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Phil Sutter <phil@nwl.cc>, netfilter-devel@vger.kernel.org
Subject: Re: json_cmd_assoc and cmd
Date: Thu, 18 Jul 2019 16:07:14 +0100 [thread overview]
Message-ID: <20190718150714.GA5028@azazel.net> (raw)
In-Reply-To: <20190718145722.k5nnznt753cunnca@salvia>
[-- Attachment #1: Type: text/plain, Size: 1992 bytes --]
On 2019-07-18, at 16:57:22 +0200, Pablo Neira Ayuso wrote:
> On Thu, Jul 18, 2019 at 01:37:04PM +0100, Jeremy Sowden wrote:
> > On 2019-07-16, at 21:39:03 +0200, Pablo Neira Ayuso wrote:
> > > BTW, not directly related to this, but isn't this strange?
> > >
> > > list_for_each_entry(cmd, cmds, list) {
> > > memset(&ctx, 0, sizeof(ctx));
> > > ctx.msgs = msgs;
> > > ctx.seqnum = cmd->seqnum = mnl_seqnum_alloc(&seqnum);
> > > ctx.batch = batch;
> > > ctx.nft = nft;
> > > init_list_head(&ctx.list);
> > > ret = do_command(&ctx, cmd);
> > > ...
> > >
> > > ctx is reset over and over again. Then, recycled here:
> > >
> > > ret = mnl_batch_talk(&ctx, &err_list, num_cmds);
> > >
> > > I wonder if we can get this better.
> >
> > Something like this?
>
> Yes, something like that would get things in better shape I think,
> more comments below.
>
> > struct netlink_ctx ctx = { .msgs = msgs, .nft = nft };
> > ...
> >
> > ctx.batch = batch = mnl_batch_init();
> > batch_seqnum = mnl_batch_begin(batch, mnl_seqnum_alloc(&seqnum));
> > list_for_each_entry(cmd, cmds, list) {
> > ctx.seqnum = cmd->seqnum = mnl_seqnum_alloc(&seqnum);
> > init_list_head(&ctx.list);
>
> I think we don't need to re-initialize this list over and over again
> (from what I see when doing: git grep "ctx->list").
>
> This always does list_splice_tail_init() to attach the object list
> where they belong.
Right. Got it.
> You can probably add something like:
>
> if (!list_empty(&ctx->list))
> BUG("command list is not empty\n");
>
> I would make a patch and run tests/shell and tests/py to check if what
> I'm suggesting this fine :-)
I've compiled the changes I outlined above and run `make check`. Will
add the list changes and submit a patch once I've tested them.
> > ret = do_command(&ctx, cmd);
> > ...
J.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-07-18 15:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-16 18:31 json_cmd_assoc and cmd Pablo Neira Ayuso
2019-07-16 19:02 ` Phil Sutter
2019-07-16 19:39 ` Pablo Neira Ayuso
2019-07-18 12:37 ` Jeremy Sowden
2019-07-18 14:11 ` Phil Sutter
2019-07-18 14:57 ` Pablo Neira Ayuso
2019-07-18 15:07 ` Jeremy Sowden [this message]
2019-07-18 21:05 ` [PATCH nft] libnftables: got rid of repeated initialization of netlink_ctx variable in loop Jeremy Sowden
2019-07-19 10:32 ` Phil Sutter
2019-07-19 11:10 ` [PATCH nft v2 0/2] netlink_ctx initialization fixes Jeremy Sowden
2019-07-19 11:10 ` [PATCH nft v2 1/2] libnftables: got rid of repeated initialization of netlink_ctx variable in loop Jeremy Sowden
2019-07-19 11:17 ` Phil Sutter
2019-07-19 11:10 ` [PATCH nft v2 2/2] rule: removed duplicate member initializer Jeremy Sowden
2019-07-19 11:17 ` Phil Sutter
2019-07-22 21:29 ` [PATCH nft v2 0/2] netlink_ctx initialization fixes Pablo Neira Ayuso
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=20190718150714.GA5028@azazel.net \
--to=jeremy@azazel.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).