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=YVKhe2d1; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id BF46C5A0272 for ; Thu, 19 Mar 2026 07:12:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773900722; bh=apZWI4ivzj5a9alE2daQkJc5yZPpO71IwQS/IGv6ncA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YVKhe2d1pDoMF8E8PytiOrZ3r/EkkGYfmDGdZzgGggV5UqOvU1/1O92BDGnrr+HhX ECrdR4rSNjDB8XG0Akjc8v4XzzhCdaCFqaQy01/myShat+wEvROfvotVI9jHm+lKS/ y6Mh1SnqvSE2ViGYrzS5y6C8JY/Hu+UE3UqhIYuj57rIWrOGINWrsan6DF+bC6y1NH gjxdbOv0e7TjoLhDgPzEygy1iqGdwKoFbYx4R28dsX7YXgockorAZq1IPhM3j3FSaM eWRDKjZa27T2vqGNMusvYVi3VdOHaiLBGdxkEsCwjhBBzZd2soQCJV9QRR7XjzxrQM WTLFnA9egpQvQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fbwMQ04nQz4wSp; Thu, 19 Mar 2026 17:12:02 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 04/15] fwd: Move selecting correct scan bitmap into fwd_sync_one() Date: Thu, 19 Mar 2026 17:11:46 +1100 Message-ID: <20260319061157.1983818-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260319061157.1983818-1-david@gibson.dropbear.id.au> References: <20260319061157.1983818-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: PBCPB3GSJPPUM7A7RM2ESZDHQT3DMH7C X-Message-ID-Hash: PBCPB3GSJPPUM7A7RM2ESZDHQT3DMH7C 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: Currently fwd_listen_sync_() determines which of the two port scanned bitmaps is the correct one for a rule before passing it into fwd_sync_one(). However, fwd_sync_one() is already looking at the rule internals so is better placed to do this. Signed-off-by: David Gibson --- fwd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/fwd.c b/fwd.c index f3b4bf2a..a306b409 100644 --- a/fwd.c +++ b/fwd.c @@ -508,16 +508,18 @@ void fwd_rules_print(const struct fwd_table *fwd) * @fwd: Forwarding table * @rule: Forwarding rule * @pif: Interface to create listening sockets for - * @scanmap: Bitmap of ports to listen for on FWD_SCAN entries + * @tcp: Bitmap of TCP ports to listen for on FWD_SCAN entries + * @udp: Bitmap of UDP ports to listen for on FWD_SCAN entries * * Return: 0 on success, -1 on failure */ static int fwd_sync_one(const struct ctx *c, const struct fwd_table *fwd, const struct fwd_rule *rule, uint8_t pif, - const uint8_t *scanmap) + const uint8_t *tcp, const uint8_t *udp) { const union inany_addr *addr = fwd_rule_addr(rule); const char *ifname = rule->ifname; + const uint8_t *map = NULL; bool bound_one = false; unsigned port, idx; @@ -528,12 +530,19 @@ static int fwd_sync_one(const struct ctx *c, const struct fwd_table *fwd, idx = rule - fwd->rules; assert(idx < MAX_FWD_RULES); - assert(!(rule->flags & FWD_SCAN && !scanmap)); - + + if (rule->flags & FWD_SCAN) { + if (rule->proto == IPPROTO_TCP) + map = tcp; + else if (rule->proto == IPPROTO_UDP) + map = udp; + assert(map); + } + for (port = rule->first; port <= rule->last; port++) { int fd = rule->socks[port - rule->first]; - if ((rule->flags & FWD_SCAN) && !bitmap_isset(scanmap, port)) { + if (map && !bitmap_isset(map, port)) { /* We don't want to listen on this port */ if (fd >= 0) { /* We already are, so stop */ @@ -619,15 +628,8 @@ static int fwd_listen_sync_(void *arg) ns_enter(a->c); for (i = 0; i < a->fwd->count; i++) { - const uint8_t *scanmap = NULL; - - if (a->fwd->rules[i].proto == IPPROTO_TCP) - scanmap = a->tcpmap; - else if (a->fwd->rules[i].proto == IPPROTO_UDP) - scanmap = a->udpmap; - a->ret = fwd_sync_one(a->c, a->fwd, &a->fwd->rules[i], - a->pif, scanmap); + a->pif, a->tcpmap, a->udpmap); if (a->ret < 0) break; } -- 2.53.0