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=FxkOaxuQ; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6158E5A061D for ; Mon, 23 Mar 2026 09:32:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774254767; bh=2laAEZ3fAUpYcU5hgfAweTHC5+Gc4ReYEzLyWFGncGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxkOaxuQVhIADdCJsblIpYNyCC+sSi/4pOG13aE9RLCB0GWkwcTgNmIN2oBkKz9p5 gOoCgK6wNHdeuusLQr1S35thaprgdv207SieEk8mkGrf2iGf+eIXYLeRZNqj87V/jf tC9Ra98A3i19/lzDAwPaGFF9ieluIFoI27eaUKhlZ1kf/WWXVI6J6z9GyGjoH+2Ljf 6+ARvQh+60hOyYUrKqC12QbAiiFv5Faa3lWcnKolo0yKONTRgUqDzuuDOYQiziqbNw BBi0L1eumYpkCpxrIrYN6V8K1Dfh5ATKVY3FNeqVv5avWINra2OognDV9aMEQ319/Z 5SLyQB9xqINbg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ffRHz4mz1z4wM0; Mon, 23 Mar 2026 19:32:47 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 11/25] conf: Move check for mapping port 0 to caller Date: Mon, 23 Mar 2026 18:37:18 +1100 Message-ID: <20260323073732.3158468-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323073732.3158468-1-david@gibson.dropbear.id.au> References: <20260323073732.3158468-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 477635J3FVAJONGJUUUKA5TZXE6NI6YK X-Message-ID-Hash: 477635J3FVAJONGJUUUKA5TZXE6NI6YK 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