From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 5CEB25A026F for ; Fri, 29 Sep 2023 07:50:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1695966626; bh=SojN8wtYcLR+DBI1yoYOrjQ4oi+Va17WhwFTPUqvlfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MzGkEUlBCFJ3yjr8+F3vrXYU6ZxU7v4xNKy0rVHrhxdbjCQ6IQPJBNNaqiZFtco3K JAJRiNYfkSRFtHKzBa7cmSLWCs6GagPuwDBfWfOVAAhwOAuPUFUMFmQp9nvoP8q5fY va4kOqS3iRspE+J3JDOs3iIvFHsXLrrzHZ7LkFOg= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RxfZp5n8jz4x80; Fri, 29 Sep 2023 15:50:26 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/4] conf: Remove overly cryptic selection of forward table Date: Fri, 29 Sep 2023 15:50:20 +1000 Message-ID: <20230929055022.48624-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230929055022.48624-1-david@gibson.dropbear.id.au> References: <20230929055022.48624-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: UH7WN24W5LRO3KKKCEIFFSVKLL7X2BZG X-Message-ID-Hash: UH7WN24W5LRO3KKKCEIFFSVKLL7X2BZG X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In a couple of places in conf(), we use a local 'fwd' variable to reference one of our forwarding tables. The value depends on which command line option we're currently looking at, and is initialized rather cryptically from an assignment side-effect within the if condition checking that option. Newer versions of cppcheck complain about this assignment being an always true condition, but in any case it's both clearer and slightly shorter to use separate if branches for the two cases and set the forwarding parameter more directly. Signed-off-by: David Gibson --- conf.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/conf.c b/conf.c index 551a9da..a235b31 100644 --- a/conf.c +++ b/conf.c @@ -1742,14 +1742,12 @@ void conf(struct ctx *c, int argc, char **argv) /* Inbound port options can be parsed now (after IPv4/IPv6 settings) */ optind = 1; do { - struct port_fwd *fwd; - name = getopt_long(argc, argv, optstring, options, NULL); - if ((name == 't' && (fwd = &c->tcp.fwd_in)) || - (name == 'u' && (fwd = &c->udp.fwd_in.f))) { - conf_ports(c, name, optarg, fwd); - } + if (name == 't') + conf_ports(c, name, optarg, &c->tcp.fwd_in); + else if (name == 'u') + conf_ports(c, name, optarg, &c->udp.fwd_in.f); } while (name != -1); if (c->mode == MODE_PASTA) @@ -1777,14 +1775,12 @@ void conf(struct ctx *c, int argc, char **argv) /* ...and outbound port options now that namespaces are set up. */ optind = 1; do { - struct port_fwd *fwd; - name = getopt_long(argc, argv, optstring, options, NULL); - if ((name == 'T' && (fwd = &c->tcp.fwd_out)) || - (name == 'U' && (fwd = &c->udp.fwd_out.f))) { - conf_ports(c, name, optarg, fwd); - } + if (name == 'T') + conf_ports(c, name, optarg, &c->tcp.fwd_out); + else if (name == 'U') + conf_ports(c, name, optarg, &c->udp.fwd_out.f); } while (name != -1); if (!c->ifi4) -- 2.41.0