From 1b32bfe181c7a22d22fbc9ba90b94c8234e15adc Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 11 Mar 2026 23:03:14 +1100 Subject: conf: Parse all forwarding options at the same time We don't handle the -t and -u options in the main option parsing loop, because they rely on some IP parameters already being finalised (specifically, conf_ports() uses use ifi4 and ifi6 to determine if IP versions are enabled). So, we parse them in a second pass through the command line. The -T and -U options are parsed in a third pass through the command line, because they relied on setup of the guest namespace. However, since we reworked their handling to use the forward table structure, that's no longer the case. So, move their handling into the same loop as the -t and -u options. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- conf.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/conf.c b/conf.c index ffbd403..dafac46 100644 --- a/conf.c +++ b/conf.c @@ -2152,7 +2152,7 @@ void conf(struct ctx *c, int argc, char **argv) if (c->ifi4 && IN4_IS_ADDR_UNSPECIFIED(&c->ip4.guest_gw)) c->no_dhcp = 1; - /* Inbound port options can be parsed now, after IPv4/IPv6 settings */ + /* Forwarding options can be parsed now, after IPv4/IPv6 settings */ fwd_probe_ephemeral(); optind = 0; do { @@ -2162,6 +2162,10 @@ void conf(struct ctx *c, int argc, char **argv) conf_ports(c, name, optarg, &c->fwd_in, &tcp_in_mode); else if (name == 'u') conf_ports(c, name, optarg, &c->fwd_in, &udp_in_mode); + else if (name == 'T') + conf_ports(c, name, optarg, &c->fwd_out, &tcp_out_mode); + else if (name == 'U') + conf_ports(c, name, optarg, &c->fwd_out, &udp_out_mode); } while (name != -1); if (c->mode == MODE_PASTA) @@ -2191,17 +2195,6 @@ void conf(struct ctx *c, int argc, char **argv) if (c->mode == MODE_PASTA) nl_sock_init(c, true); - /* ...and outbound port options now that namespaces are set up. */ - optind = 0; - do { - name = getopt_long(argc, argv, optstring, options, NULL); - - if (name == 'T') - conf_ports(c, name, optarg, &c->fwd_out, &tcp_out_mode); - else if (name == 'U') - conf_ports(c, name, optarg, &c->fwd_out, &udp_out_mode); - } while (name != -1); - if (!c->ifi4) c->no_dhcp = 1; -- cgit v1.2.3