aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-09-29 15:50:20 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-10-04 23:23:56 +0200
commitc0efa4e97f20848570552286403574bf228b6420 (patch)
treefd0bc3699dd700673ec35123703ee7c160ce093d
parent6471c7d01b0aad9d144448290557fcd783562228 (diff)
downloadpasst-c0efa4e97f20848570552286403574bf228b6420.tar
passt-c0efa4e97f20848570552286403574bf228b6420.tar.gz
passt-c0efa4e97f20848570552286403574bf228b6420.tar.bz2
passt-c0efa4e97f20848570552286403574bf228b6420.tar.lz
passt-c0efa4e97f20848570552286403574bf228b6420.tar.xz
passt-c0efa4e97f20848570552286403574bf228b6420.tar.zst
passt-c0efa4e97f20848570552286403574bf228b6420.zip
conf: Remove overly cryptic selection of forward table
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 <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--conf.c20
1 files 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)