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=202408 header.b=Cq750fFY; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 4CFE45A004F for ; Thu, 29 Aug 2024 03:32:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1724895163; bh=XraInGkWVq+u3OQAjJC/PEX2LTYJWCtQRww436rDuTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cq750fFY2iqT84hsleUL93GncqLLlp329nKSjWbUfaKGtRgUdd2mG2PnXhv87KzPD x2P2p/+ZfTiEdB11JXKgA+LRdPC32AVHfEmYMmJlno/DvPWvg0yzzmj+RX0YU8D/YK RuzOpDGiVQInDqfGNTgWil/tnP/omXnSs2EcxcATjRo3UnwwWfbfBJ9K6eMPJDG6p1 EXLRvAygNvRGOJ1Y4uXJ5RlUNy4kPfLHx5yINhpKMldppDB+YnrvNAp2FNqwwoE+Hr aSTDxOyR6nd30kvTXgkau3yUtUWzzW0Lapxi9PB4DWDt+dRq/QryM0mDhWEmYj6FWP Zbcl07UoRJnrg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WvP0q4Qs4z4x7F; Thu, 29 Aug 2024 11:32:43 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 2/3] conf, fwd: Don't attempt to forward port 0 Date: Thu, 29 Aug 2024 11:32:41 +1000 Message-ID: <20240829013242.3396770-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240829013242.3396770-1-david@gibson.dropbear.id.au> References: <20240829013242.3396770-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: CH22Q2VFIKUNDDAJVUIJKOSLVMFDVWCD X-Message-ID-Hash: CH22Q2VFIKUNDDAJVUIJKOSLVMFDVWCD 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 , Laurent Vivier 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: When using -t all, -u all or exclude-only ranges, we'll attempt to forward all non-ephemeral port numbers, including port 0. However, this won't work as intended: bind() treats a zero port not as literal port 0, but as "pick a port for me". Because of the special meaning of port 0, we mostly outright exclude it in our handling. Do the same for setting up forwards, not attempting to forward for port 0. Signed-off-by: David Gibson Reviewed-by: Laurent Vivier --- conf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/conf.c b/conf.c index 6b3dafd5..3eb117ff 100644 --- a/conf.c +++ b/conf.c @@ -157,7 +157,10 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, fwd->mode = FWD_ALL; - for (i = 0; i < NUM_PORTS; i++) { + /* Skip port 0. It has special meaning for many socket APIs, so + * trying to bind it is not really safe. + */ + for (i = 1; i < NUM_PORTS; i++) { if (fwd_port_is_ephemeral(i)) continue; @@ -262,7 +265,10 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, } while ((p = next_chunk(p, ','))); if (exclude_only) { - for (i = 0; i < NUM_PORTS; i++) { + /* Skip port 0. It has special meaning for many socket APIs, so + * trying to bind it is not really safe. + */ + for (i = 1; i < NUM_PORTS; i++) { if (fwd_port_is_ephemeral(i) || bitmap_isset(exclude, i)) continue; -- 2.46.0