From patchwork Thu Jul 18 21:05:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Sowden X-Patchwork-Id: 1133849 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=azazel.net Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=azazel.net header.i=@azazel.net header.b="L4JMBM4x"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45qRW90Syzz9s3Z for ; Fri, 19 Jul 2019 07:05:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728032AbfGRVF4 (ORCPT ); Thu, 18 Jul 2019 17:05:56 -0400 Received: from kadath.azazel.net ([81.187.231.250]:33838 "EHLO kadath.azazel.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727685AbfGRVF4 (ORCPT ); Thu, 18 Jul 2019 17:05:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=azazel.net; s=20190108; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=3PY7012T2qOBDorU2puIHz8w0UYPhoK3T6PtPUxhSgI=; b=L4JMBM4xBOo8Bfxl/m5DklWYHh uAbJ8fe4SFrFsgCZ/MwroeYaJ6YP+wHu+1a+6JzyhI1nrxRNO7hXvyUIwtCpZpetI0Qca0tl/hPBJ unZNgkqXUF7sP4ULmMPyXRSTER0oJGjNfdpHSSapieETDrzaJTOHTDntT6e9Vqxx5MIdJmySMgFN0 +9+3RZSjuBZ2OHPavWfwHtuHTBms5Qc/8Gb0dLAivz7l5Gy+NEnvA05rYf9QRjdgQ14GOwPNZr0ke kyqeChUroxOaktjH582tDspVH/7CgJIx+BsEBgXQAcLjETtr/LtFmKyABofzz6/76Y93UZHHyfXfc +1j8b9Aw==; Received: from [2001:8b0:fb7d:d6d7:2e4d:54ff:fe4b:a9ae] (helo=ulthar.dreamlands) by kadath.azazel.net with esmtp (Exim 4.92) (envelope-from ) id 1hoDb6-0008LM-RP; Thu, 18 Jul 2019 22:05:52 +0100 From: Jeremy Sowden To: Netfilter Devel Cc: Pablo Neira Ayuso , Phil Sutter Subject: [PATCH nft] libnftables: got rid of repeated initialization of netlink_ctx variable in loop. Date: Thu, 18 Jul 2019 22:05:52 +0100 Message-Id: <20190718210552.16890-1-jeremy@azazel.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190718145722.k5nnznt753cunnca@salvia> References: <20190718145722.k5nnznt753cunnca@salvia> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:8b0:fb7d:d6d7:2e4d:54ff:fe4b:a9ae X-SA-Exim-Mail-From: jeremy@azazel.net X-SA-Exim-Scanned: No (on kadath.azazel.net); SAEximRunCond expanded to false Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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") Reported-by: Pablo Neira Ayuso Signed-off-by: Jeremy Sowden --- 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 }; 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); + + ctx.batch = batch = mnl_batch_init(); batch_seqnum = mnl_batch_begin(batch, mnl_seqnum_alloc(&seqnum)); 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); if (ret < 0) { netlink_io_error(&ctx, &cmd->location,