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=jCgza53d; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id D970A5A0276 for ; Wed, 19 Nov 2025 05:26:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202510; t=1763526396; bh=/GZTzRb9EKZIgKhbU98Jk39tzL9rMUhFvIBNxc2YbHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jCgza53dgMe8GwuR35gLNxSMxMrXviLTaV/H/B/tByrjT01uLsQYlOL2GadGXeC2V U8hF4dImBl5Uk1AvoWN6xU5LVd47DzbdLgvBLwMf9H4rCIVk96yIzcis25/mzctPnt ZJZT51guPJ/FvdUzjBHLPh5MrdFMdQI8N8w19hSShNrvm0IXPjNa1wv82A+3h0zGnR C9wdv3yHwWrhap7JHR36LXYFB+lyDpskYbU1OhFFnBhLdu7dZCW8HiEDiBUDi/KFzV nFlZDebVfAVNQgJLtMz/YLdLiuRBHwJDbV5tn5T8N+Zl60xaPC6r6Cw3YqKxexeXDL YQbj8jDG19EiA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dB7j85ztJz4wGV; Wed, 19 Nov 2025 15:26:36 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 1/3] Revert "fwd: Update all port maps before applying exclusions" Date: Wed, 19 Nov 2025 15:26:32 +1100 Message-ID: <20251119042634.2978171-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251119042634.2978171-1-david@gibson.dropbear.id.au> References: <20251119042634.2978171-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 4TT3HBMDI3FYFBCSRDN3QS3XSMRIOE7N X-Message-ID-Hash: 4TT3HBMDI3FYFBCSRDN3QS3XSMRIOE7N 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: This reverts commit 81942a2417357ff10b02ccc8275cde2d4d6fbfbe. That commit was based on the premise of trying to make all the exclusions use the "latest" scan data. That was a fundamentally wrong approach: what we need to exclude is listening ports that pasta itself has created. That is, we need to exclude ports that we were _already_ listening on, not ones that we intend to listen once we rebind - we *want* the old data. Reverting this reduces the cases in which bug 176 occurs, but it's not a complete fix. Link: https://bugs.passt.top/show_bug.cgi?id=176 Signed-off-by: David Gibson --- fwd.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/fwd.c b/fwd.c index 68bb1166..7b6c40fb 100644 --- a/fwd.c +++ b/fwd.c @@ -358,8 +358,10 @@ static void procfs_scan_listen(int fd, unsigned int lstate, uint8_t *map) /** * fwd_scan_ports_tcp() - Scan /proc to update TCP forwarding map * @fwd: Forwarding information to update + * @rev: Forwarding information for the reverse direction */ -static void fwd_scan_ports_tcp(struct fwd_ports *fwd) +static void fwd_scan_ports_tcp(struct fwd_ports *fwd, + const struct fwd_ports *rev) { if (fwd->mode != FWD_AUTO) return; @@ -367,15 +369,20 @@ static void fwd_scan_ports_tcp(struct fwd_ports *fwd) 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); + bitmap_and_not(fwd->map, PORT_BITMAP_SIZE, fwd->map, rev->map); } /** * fwd_scan_ports_udp() - Scan /proc to update UDP forwarding map * @fwd: Forwarding information to update + * @rev: Forwarding information for the reverse direction * @tcp_fwd: Corresponding TCP forwarding information + * @tcp_rev: TCP forwarding information for the reverse direction */ static void fwd_scan_ports_udp(struct fwd_ports *fwd, - const struct fwd_ports *tcp_fwd) + const struct fwd_ports *rev, + const struct fwd_ports *tcp_fwd, + const struct fwd_ports *tcp_rev) { if (fwd->mode != FWD_AUTO) return; @@ -391,6 +398,14 @@ static void fwd_scan_ports_udp(struct fwd_ports *fwd, */ procfs_scan_listen(tcp_fwd->scan4, TCP_LISTEN, fwd->map); procfs_scan_listen(tcp_fwd->scan6, TCP_LISTEN, fwd->map); + + /* This means we need to skip numbers of TCP ports bound on the other + * side, too. Otherwise, we would detect corresponding UDP ports as + * bound and try to forward them from the opposite side, but it's + * already us handling them. + */ + bitmap_and_not(fwd->map, PORT_BITMAP_SIZE, fwd->map, rev->map); + bitmap_and_not(fwd->map, PORT_BITMAP_SIZE, fwd->map, tcp_rev->map); } /** @@ -399,28 +414,12 @@ static void fwd_scan_ports_udp(struct fwd_ports *fwd, */ static void fwd_scan_ports(struct ctx *c) { - fwd_scan_ports_tcp(&c->tcp.fwd_out); - fwd_scan_ports_tcp(&c->tcp.fwd_in); - fwd_scan_ports_udp(&c->udp.fwd_out, &c->tcp.fwd_out); - fwd_scan_ports_udp(&c->udp.fwd_in, &c->tcp.fwd_in); - - if (c->tcp.fwd_out.mode == FWD_AUTO) { - bitmap_and_not(c->tcp.fwd_out.map, PORT_BITMAP_SIZE, - c->tcp.fwd_out.map, c->tcp.fwd_in.map); - } - if (c->tcp.fwd_in.mode == FWD_AUTO) { - bitmap_and_not(c->tcp.fwd_in.map, PORT_BITMAP_SIZE, - c->tcp.fwd_in.map, c->tcp.fwd_out.map); - } - - if (c->udp.fwd_out.mode == FWD_AUTO) { - bitmap_and_not(c->udp.fwd_out.map, PORT_BITMAP_SIZE, - c->udp.fwd_out.map, c->udp.fwd_in.map); - } - if (c->udp.fwd_in.mode == FWD_AUTO) { - bitmap_and_not(c->udp.fwd_in.map, PORT_BITMAP_SIZE, - c->udp.fwd_in.map, c->udp.fwd_out.map); - } + 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.1