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=DrlnT0/G; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 3AB455A0272 for ; Fri, 27 Mar 2026 05:34:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774586072; bh=2laAEZ3fAUpYcU5hgfAweTHC5+Gc4ReYEzLyWFGncGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DrlnT0/GNYWVqrRnat4sQaIlmVPqu3H4ooO9g8h35EMvIYxbTeIGjmIk7NGOQ2HBb aXF4wBF3xCzWk7u/qbR0m8aLjwZlHaDCqvacvWwP1Lx8u971AY7NntR+lO41IU5gpM lvOcKW8ulLyc27TGDs/ufNmqtmKC/wMn1VzvkKITs7/DvhvPkB4czPOsXcYbNwmpFV CJ2IwZYaa9DJW3meGFItOmldK/V9nX8v2bNnBculyx2QSBR/xWbF4ecqYu0gW1XQQq 3A4+3u4u2eWBd6LY2XFptll45frqhFIabO04HjrApUmFgvLmLCkE6IAzo/SLMm5Hpx C9wg9hULR9X2A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fhnqD5prcz4wT8; Fri, 27 Mar 2026 15:34:32 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 12/18] conf: Move check for mapping port 0 to caller Date: Fri, 27 Mar 2026 15:34:24 +1100 Message-ID: <20260327043430.1785787-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327043430.1785787-1-david@gibson.dropbear.id.au> References: <20260327043430.1785787-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: KEITY2TIDJTRFALRHIM3EZLJ4ILECY4S X-Message-ID-Hash: KEITY2TIDJTRFALRHIM3EZLJ4ILECY4S 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: conf_ports_range_except() checks that it hasn't been asked to map port 0, which generally won't work. However, there's only one callsite that doesn't statically pass a non-zero value here. Change the check to an assert() and move the actual error message to that callsite. This will allow further cleanups later. Signed-off-by: David Gibson --- conf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/conf.c b/conf.c index e5baf8ee..dc9468c2 100644 --- a/conf.c +++ b/conf.c @@ -151,10 +151,7 @@ static void conf_ports_range_except(const struct ctx *c, char optname, unsigned base, i; uint8_t proto; - if (first == 0) { - die("Can't forward port 0 for option '-%c %s'", - optname, optarg); - } + assert(first != 0); if (optname == 't' || optname == 'T') proto = IPPROTO_TCP; @@ -404,6 +401,11 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, if ((*p != '\0') && (*p != ',')) /* Garbage after the ranges */ goto bad; + if (orig_range.first == 0) { + die("Can't forward port 0 for option '-%c %s'", + optname, optarg); + } + conf_ports_range_except(c, optname, optarg, fwd, addr, ifname, orig_range.first, orig_range.last, -- 2.53.0