From: Phil Sutter <phil@nwl.cc>
To: Jeremy Sowden <jeremy@azazel.net>
Cc: Netfilter Devel <netfilter-devel@vger.kernel.org>,
Pablo Neira Ayuso <pablo@netfilter.org>
Subject: Re: [PATCH nft] libnftables: got rid of repeated initialization of netlink_ctx variable in loop.
Date: Fri, 19 Jul 2019 12:32:05 +0200 [thread overview]
Message-ID: <20190719103205.GM1628@orbyte.nwl.cc> (raw)
In-Reply-To: <20190718210552.16890-1-jeremy@azazel.net>
Hi,
On Thu, Jul 18, 2019 at 10:05:52PM +0100, Jeremy Sowden wrote:
> Most members in the context doesn't change, so there is no need to
> memset it and reassign most of its members on every iteration. Moved
> that code out of the loop.
>
> Fixes: 49900d448ac9 ("libnftables: Move library stuff out of main.c")
This commit merely moved the code from src/main.c into the current
location. I would rather point at a72315d2bad47 ("src: add rule batching
support"), which introduced the loop (and already contains some of the
pointless assignments). Note that commit is from 2013. :)
> Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
> Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
> ---
> src/libnftables.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/src/libnftables.c b/src/libnftables.c
> index 2f77a7709e2c..834ea661a146 100644
> --- a/src/libnftables.c
> +++ b/src/libnftables.c
> @@ -23,7 +23,7 @@ static int nft_netlink(struct nft_ctx *nft,
> {
> uint32_t batch_seqnum, seqnum = 0, num_cmds = 0;
> struct nftnl_batch *batch;
> - struct netlink_ctx ctx;
> + struct netlink_ctx ctx = { .msgs = msgs, .nft = nft };
Use '.list = LIST_HEAD_INIT(ctx.list),' here. Refer to cache_update() in
src/rule.c for inspiration. :)
> struct cmd *cmd;
> struct mnl_err *err, *tmp;
> LIST_HEAD(err_list);
> @@ -32,16 +32,13 @@ static int nft_netlink(struct nft_ctx *nft,
> if (list_empty(cmds))
> return 0;
>
> - batch = mnl_batch_init();
> + init_list_head(&ctx.list);
Drop this.
> +
> + ctx.batch = batch = mnl_batch_init();
Move ctx.batch init into declaration as well. Drop dedicated 'batch'
variable and replace by 'ctx.batch'.
Thanks, Phil
next prev parent reply other threads:[~2019-07-19 10:32 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
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 [this message]
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=20190719103205.GM1628@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=jeremy@azazel.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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;
as well as URLs for NNTP newsgroup(s).