From 9c37a481f12a5fbbeb98dbc16763e444f0322f57 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 27 Mar 2026 15:34:24 +1100 Subject: conf: Move check for mapping port 0 to caller 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 Signed-off-by: Stefano Brivio --- conf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/conf.c b/conf.c index e5baf8e..dc9468c 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, -- cgit v1.2.3