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=202510 header.b=jPmAANNI; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 29D485A061E for ; Sat, 11 Oct 2025 06:49:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202510; t=1760158165; bh=ASajkkB0lMZdYZ6rMD49UKW/dzhRYaHvF56ljPZh8Mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jPmAANNIalKSttXGL5iXayzEiSDVsGRsfHhJ3dkrz798cFv8RiSE3JFN6UBoGBNrI ugClMbeOebe5QcCsoDYbyRSplhXEzGwE67IRs3671aR2d9YcYCDNjZ51IYjZZ1QNOr h2t7AXGPxddcDtHsTSsoOdxAbxz6nMLzFt5Y7n3SdhJ3uIgh7erEfdviugK7tq4fkw umon8lXoodCb+bpgnb2g6y7OlJT0xXE4VlvflkwVLsUJ5xFulB73jNj2fnx5en25kj I5Erz356gSLwXHy/GDbMFYwJv1L5LuC/Swr/t1QIvlOIsndLFuVmeSzwphVeWnK5Iu TjkBK4QZ12I+Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ckB3T5b61z4wD7; Sat, 11 Oct 2025 15:49:25 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 6/8] fwd: Check forwarding mode in fwd_scan_ports_*() rather than caller Date: Sat, 11 Oct 2025 15:48:25 +1100 Message-ID: <20251011044827.862757-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251011044827.862757-1-david@gibson.dropbear.id.au> References: <20251011044827.862757-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: LZCMJSQMZZTDOQ6S7DU3Z6GGROWB5B3O X-Message-ID-Hash: LZCMJSQMZZTDOQ6S7DU3Z6GGROWB5B3O 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: fwd_scan_ports() needs to check for FWD_AUTO mode before calling each scan function - otherwise it would clobber the forwarding bitmap which should retain the user's fixed configuration. Make this slightly cleaner and safer by moving the mode check into fwd_scan_ports_{tcp,udp}(). Signed-off-by: David Gibson --- fwd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fwd.c b/fwd.c index 6f89acf5..57941759 100644 --- a/fwd.c +++ b/fwd.c @@ -151,6 +151,9 @@ static void procfs_scan_listen(int fd, unsigned int lstate, uint8_t *map) static void fwd_scan_ports_tcp(struct fwd_ports *fwd, const struct fwd_ports *rev) { + if (fwd->mode != FWD_AUTO) + return; + memset(fwd->map, 0, PORT_BITMAP_SIZE); procfs_scan_listen(fwd->scan4, TCP_LISTEN, fwd->map); procfs_scan_listen(fwd->scan6, TCP_LISTEN, fwd->map); @@ -169,6 +172,9 @@ static void fwd_scan_ports_udp(struct fwd_ports *fwd, const struct fwd_ports *tcp_fwd, const struct fwd_ports *tcp_rev) { + if (fwd->mode != FWD_AUTO) + return; + memset(fwd->map, 0, PORT_BITMAP_SIZE); procfs_scan_listen(fwd->scan4, UDP_LISTEN, fwd->map); procfs_scan_listen(fwd->scan6, UDP_LISTEN, fwd->map); @@ -197,18 +203,12 @@ static void fwd_scan_ports_udp(struct fwd_ports *fwd, */ static void fwd_scan_ports(struct ctx *c) { - if (c->tcp.fwd_out.mode == FWD_AUTO) - fwd_scan_ports_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in); - if (c->tcp.fwd_in.mode == FWD_AUTO) - fwd_scan_ports_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out); - if (c->udp.fwd_out.mode == FWD_AUTO) { - fwd_scan_ports_udp(&c->udp.fwd_out, &c->udp.fwd_in, - &c->tcp.fwd_out, &c->tcp.fwd_in); - } - if (c->udp.fwd_in.mode == FWD_AUTO) { - fwd_scan_ports_udp(&c->udp.fwd_in, &c->udp.fwd_out, - &c->tcp.fwd_in, &c->tcp.fwd_out); - } + fwd_scan_ports_tcp(&c->tcp.fwd_out, &c->tcp.fwd_in); + fwd_scan_ports_tcp(&c->tcp.fwd_in, &c->tcp.fwd_out); + fwd_scan_ports_udp(&c->udp.fwd_out, &c->udp.fwd_in, + &c->tcp.fwd_out, &c->tcp.fwd_in); + fwd_scan_ports_udp(&c->udp.fwd_in, &c->udp.fwd_out, + &c->tcp.fwd_in, &c->tcp.fwd_out); } /** -- 2.51.0