From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=VcEO4cj5; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 879905A0269 for ; Tue, 07 Apr 2026 05:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775531792; bh=SWy0zTTdyS1GCezenzRyYZ6UlsFN2JH43hzEAgrjLPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VcEO4cj57/gmwDD8Wc3eyaxY+jcvcNpN1zJYw34UYl+G6/hnh4LW+tem2J8bsjM8f SpH48EfoFjwrmwyJ8tALGiCL1Bxs6zyz9UQPr1FPGSu8TL7+//u3HsDcPKAh62arug J6CMytXCjgDCG6ZdERnYHSeuzKc4uhVQVce6khM7nYSljSN6VUZc0c7jxEzilVgzhw VFED7/wH1nCZzCaGnhW5NvBDJwOTft5T8gnph5UP9T5z2E+oZLFHig0DsWoaojjImG +4+ZCYQ/Sd11P7edttwByz7nuQcKwcQxU9ftfKRVmdnmPaMhd3iKileOpBTA8O59rV sWehb+7lnxFqQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fqWZ84mCXz4wK3; Tue, 07 Apr 2026 13:16:32 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 02/18] conf: Simplify handling of default forwarding mode Date: Tue, 7 Apr 2026 13:16:14 +1000 Message-ID: <20260407031630.2457081-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260407031630.2457081-1-david@gibson.dropbear.id.au> References: <20260407031630.2457081-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ZTN22OTEOQ7CJLZ7UEMQASWGYUML3FDB X-Message-ID-Hash: ZTN22OTEOQ7CJLZ7UEMQASWGYUML3FDB 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: For passt, the default forwarding mode is "none", which falls out naturally from the other handling: if we don't get any options, we get empty forwarding tables, which corresponds to "none" behaviour. However, for pasta the default is "auto". This is handled a bit oddly: in conf_ports() we set the mode variable, but don't set up the rules we need for "auto" mode. Instead we want until nearly the end of conf() and if the mode is FWD_MODE_AUTO or unset, we make conf_ports_range_except() calls to set up the "auto" rules. Simplify this a bit, by creating the rules within conf_ports() itself when we parse -[tuTU] auto. For the case of no forwarding options we call into conf_ports() itself with synthetic arguments. As well as making the code a little shorter, this makes it more obvious that giving no arguments really is equivalent to -[tuTU] auto. Signed-off-by: David Gibson --- conf.c | 54 ++++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/conf.c b/conf.c index c515480b..7d718f91 100644 --- a/conf.c +++ b/conf.c @@ -345,6 +345,10 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, die("'auto' port forwarding is only allowed for pasta"); *mode = FWD_MODE_AUTO; + + conf_ports_range_except(c, optname, optarg, fwd, NULL, NULL, + 1, NUM_PORTS - 1, NULL, 1, FWD_SCAN); + return; } @@ -1576,7 +1580,6 @@ void conf(struct ctx *c, int argc, char **argv) enum fwd_mode udp_out_mode = FWD_MODE_UNSET; enum fwd_mode tcp_in_mode = FWD_MODE_UNSET; enum fwd_mode udp_in_mode = FWD_MODE_UNSET; - enum fwd_mode fwd_default = FWD_MODE_NONE; bool v4_only = false, v6_only = false; unsigned dns4_idx = 0, dns6_idx = 0; unsigned long max_mtu = IP_MAX_MTU; @@ -1593,10 +1596,8 @@ void conf(struct ctx *c, int argc, char **argv) gid_t gid; - if (c->mode == MODE_PASTA) { + if (c->mode == MODE_PASTA) c->no_dhcp_dns = c->no_dhcp_dns_search = 1; - fwd_default = FWD_MODE_AUTO; - } if (tap_l2_max_len(c) - ETH_HLEN < max_mtu) max_mtu = tap_l2_max_len(c) - ETH_HLEN; @@ -2244,34 +2245,23 @@ void conf(struct ctx *c, int argc, char **argv) if_indextoname(c->ifi6, c->pasta_ifn); } - if (!tcp_in_mode) - tcp_in_mode = fwd_default; - if (!tcp_out_mode) - tcp_out_mode = fwd_default; - if (!udp_in_mode) - udp_in_mode = fwd_default; - if (!udp_out_mode) - udp_out_mode = fwd_default; - - if (tcp_in_mode == FWD_MODE_AUTO) { - conf_ports_range_except(c, 't', "auto", c->fwd[PIF_HOST], - NULL, NULL, 1, NUM_PORTS - 1, NULL, 1, - FWD_SCAN); - } - if (tcp_out_mode == FWD_MODE_AUTO) { - conf_ports_range_except(c, 'T', "auto", c->fwd[PIF_SPLICE], - NULL, "lo", 1, NUM_PORTS - 1, NULL, 1, - FWD_SCAN); - } - if (udp_in_mode == FWD_MODE_AUTO) { - conf_ports_range_except(c, 'u', "auto", c->fwd[PIF_HOST], - NULL, NULL, 1, NUM_PORTS - 1, NULL, 1, - FWD_SCAN); - } - if (udp_out_mode == FWD_MODE_AUTO) { - conf_ports_range_except(c, 'U', "auto", c->fwd[PIF_SPLICE], - NULL, "lo", 1, NUM_PORTS - 1, NULL, 1, - FWD_SCAN); + if (c->mode == MODE_PASTA) { + if (!tcp_in_mode) { + conf_ports(c, 't', "auto", + c->fwd[PIF_HOST], &tcp_in_mode); + } + if (!tcp_out_mode) { + conf_ports(c, 'T', "auto", + c->fwd[PIF_SPLICE], &tcp_out_mode); + } + if (!udp_in_mode) { + conf_ports(c, 'u', "auto", + c->fwd[PIF_HOST], &udp_in_mode); + } + if (!udp_out_mode) { + conf_ports(c, 'U', "auto", + c->fwd[PIF_SPLICE], &udp_out_mode); + } } if (!c->quiet) -- 2.53.0