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=murB2Amx; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 09FAF5A0275 for ; Tue, 07 Apr 2026 05:16:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775531792; bh=ldix9mlsRWscno+T0B1EakC6qpmwG3eqSN4gt2/KSAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=murB2AmxjY8dKRav5LfIgCmf5JWmqwvXdIW4HXypYq5hsynUsfGTf/wgd11rZyUxv zGr8KTx/g3lz6ovUT0KSjDxjkGZ1gaFWE9SLzOVROl1TMzhYQHwcVQp5zCgRj5QpTB U/dkcx4M1Bwb2qrBUoMT9PCMq8viBcRvBuvBjM4mEPrRtJzeJPpjO7FaRBd4GL7w9X NDIyw+2AWNzBCJwvrAj+24DYy59SFxBYNQJNbKPPTuVrIclghQJasOtUU8GCtKG8XJ bpkAmjR3ZcvpujF5Gu9eT0bp/bN9j4G4qjAFTjV6k05uY7ckkVI18hTzBySsWKinY7 ZSuzDWrFHZSug== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fqWZ86mpYz4wLM; Tue, 07 Apr 2026 13:16:32 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 17/18] conf: Move SO_BINDTODEVICE workaround to conf_ports() Date: Tue, 7 Apr 2026 13:16:29 +1000 Message-ID: <20260407031630.2457081-18-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: QKHA5WBHH3E45UBLIQ6O53FJOM43SNB3 X-Message-ID-Hash: QKHA5WBHH3E45UBLIQ6O53FJOM43SNB3 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 historical reasons we apply our workaround for -[TU] handling when SO_BINDTODEVICE is unavailable inside conf_ports_range_except(). We've now removed the reasons it had to be there, so it can move to conf_ports(), the caller's caller. Signed-off-by: David Gibson --- conf.c | 77 ++++++++++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/conf.c b/conf.c index 86c30c7f..de262ef5 100644 --- a/conf.c +++ b/conf.c @@ -138,9 +138,6 @@ static int parse_keyword(const char *s, const char **endptr, const char *kw) /** * conf_ports_range_except() - Set up forwarding for a range of ports minus a * bitmap of exclusions - * @c: Execution context - * @optname: Short option name, t, T, u, or U - * @optarg: Option argument (port specification) * @fwd: Forwarding table to be updated * @proto: Protocol to forward * @addr: Listening address @@ -151,9 +148,8 @@ static int parse_keyword(const char *s, const char **endptr, const char *kw) * @to: Port to translate @first to when forwarding * @flags: Flags for forwarding entries */ -static void conf_ports_range_except(const struct ctx *c, char optname, - const char *optarg, struct fwd_table *fwd, - uint8_t proto, const union inany_addr *addr, +static void conf_ports_range_except(struct fwd_table *fwd, uint8_t proto, + const union inany_addr *addr, const char *ifname, uint16_t first, uint16_t last, const uint8_t *exclude, uint16_t to, @@ -195,42 +191,10 @@ static void conf_ports_range_except(const struct ctx *c, char optname, rule.last = i - 1; rule.to = base + delta; - if ((optname == 'T' || optname == 'U') && c->no_bindtodevice) { - /* FIXME: Once the fwd bitmaps are removed, move this - * workaround to the caller - */ - struct fwd_rule rulev = { - .ifname = { 0 }, - .flags = flags, - .first = base, - .last = i - 1, - .to = base + delta, - }; - - assert(!addr && ifname && !strcmp(ifname, "lo")); - warn( -"SO_BINDTODEVICE unavailable, forwarding only 127.0.0.1 and ::1 for '-%c %s'", - optname, optarg); + fwd_rule_conflict_check(&rule, fwd->rules, fwd->count); + if (fwd_rule_add(fwd, &rule) < 0) + goto fail; - if (c->ifi4) { - rulev.addr = inany_loopback4; - fwd_rule_conflict_check(&rulev, - fwd->rules, fwd->count); - if (fwd_rule_add(fwd, &rulev) < 0) - goto fail; - } - if (c->ifi6) { - rulev.addr = inany_loopback6; - fwd_rule_conflict_check(&rulev, - fwd->rules, fwd->count); - if (fwd_rule_add(fwd, &rulev) < 0) - goto fail; - } - } else { - fwd_rule_conflict_check(&rule, fwd->rules, fwd->count); - if (fwd_rule_add(fwd, &rule) < 0) - goto fail; - } base = i - 1; } return; @@ -321,8 +285,7 @@ static void conf_ports_spec(const struct ctx *c, /* Exclude ephemeral ports */ fwd_port_map_ephemeral(exclude); - conf_ports_range_except(c, optname, optarg, fwd, - proto, addr, ifname, + conf_ports_range_except(fwd, proto, addr, ifname, 1, NUM_PORTS - 1, exclude, 1, flags | FWD_WEAK); return; @@ -357,8 +320,7 @@ static void conf_ports_spec(const struct ctx *c, optname, optarg); } - conf_ports_range_except(c, optname, optarg, fwd, - proto, addr, ifname, + conf_ports_range_except(fwd, proto, addr, ifname, orig_range.first, orig_range.last, exclude, mapped_range.first, flags); @@ -461,14 +423,33 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, } } + if (optname == 'T' || optname == 'U') { + assert(!addr && !ifname); + + if (c->no_bindtodevice) { + warn( +"SO_BINDTODEVICE unavailable, forwarding only 127.0.0.1 and ::1 for '-%c %s'", + optname, optarg); + + if (c->ifi4) { + conf_ports_spec(c, optname, optarg, fwd, proto, + &inany_loopback4, NULL, spec); + } + if (c->ifi6) { + conf_ports_spec(c, optname, optarg, fwd, proto, + &inany_loopback6, NULL, spec); + } + return; + } + + ifname = "lo"; + } + if (ifname && c->no_bindtodevice) { die( "Device binding for '-%c %s' unsupported (requires kernel 5.7+)", optname, optarg); } - /* Outbound forwards come from guest loopback */ - if ((optname == 'T' || optname == 'U') && !ifname) - ifname = "lo"; conf_ports_spec(c, optname, optarg, fwd, proto, addr, ifname, spec); } -- 2.53.0