From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QAj93wtN; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id EF0905A0265 for ; Wed, 01 Jul 2026 02:07:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782864462; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ji+oBnQKl5EgGxB8I9UYvrK7RnZX1uUSb0M/PpRAgaU=; b=QAj93wtNI0i1xJ1LTwXUhm4OjQ+XmwBvYff+HNPhGaKLVH5qA8HEmhIGGfz62eSgldYk2p 9m5aF5iX3dQFCpR0JOwQ5rGqn8G1uOUR54sPxAs/G+FTr8m0qEmyZQiPitTXR26sL+qqvk o1WVuV4zPPZjFRR9uubgRP/zHVCvpVo= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-671-ifqCzUzPMKCm89lwSM8gFw-1; Tue, 30 Jun 2026 20:07:41 -0400 X-MC-Unique: ifqCzUzPMKCm89lwSM8gFw-1 X-Mimecast-MFC-AGG-ID: ifqCzUzPMKCm89lwSM8gFw_1782864460 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4926fa2cb17so454555e9.1 for ; Tue, 30 Jun 2026 17:07:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782864460; x=1783469260; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ji+oBnQKl5EgGxB8I9UYvrK7RnZX1uUSb0M/PpRAgaU=; b=DjOBXWeVOsQ5CuNU2w+cvd5GoscMP17zwGuEwUUY9XsTzvBBGTb70JF7rrBZ2PblPT c18nKb/FkhJyTDniNCtHtqpIDdNcPXyh2ypvoyBseABew/3XfSfN9KuhFr0TJu7PFv0f NpYO2YdaKbqLYqywxE+TXUh0l9/LiwyVG/zJPhBSOqTJQ2xxgHwbX83NUkAkgsZttAzZ dUK2hsXY2ASd0KIbn3mbuNzZsr2CZrn5dXDkwPlgUl+Yafy0NR+Gi/c7MxFrdkggqo/q mfHTJzB5XrXwYWJamM6S3/8AUSfKZFgw/WXfLIRgJ3aBBQtKHB5/COkfwDHtXCvNfPrq 58SQ== X-Gm-Message-State: AOJu0YwxXYhW0JRHKG8l8xmI2c2IhFT3nKNYq8csgpiQTGAuYNFNYYyT V8q5n6lfa2SaXQz4KtN6UrNIi9BzBj3+5khrbDiktkAkZBGaLE7DZZUJq8tXAlgtTCyGzc8kZqo 1+PqPw2TmgS4gf/Mnt1/aiGORDu5ftllDfYuuj3Y++12UGy0bFCDYoA== X-Gm-Gg: AfdE7cmmyPMbHnHwFyqexxU3y76Hc/lP1aQt0KwIKiplTBZ0RrkRJ2hiynuXEFNsy/w ieX0mPL9XbN5SogfJGlckVPlZ534bCI1Xfb0m+rzNZl+L+JvhkgtIGa+tZyF2my8Z+xKW3WTK5P lXe+K7CxFxKftTG413gWESkL6kjgwEUmemz+EdXKBq3EmM+s2U8roDsPDCLad1xclLRfI5VkrE3 OM8VtIwXtJM1wrhCBNC48+1BqHncI80+PB35TnZ1+Fzfn8gU2NOwggE6jJf+a3HiZqCl2gO7lxN nC9sZPKlNL142868L0u6RqUBTtcF+4kHDGmrt+oCDWv+G8enZBln8jlZBPOk8MbUOFNJT4JuH9D NdVqFCfx1XhynWG+VZA3BqaOkgwkUVbFhYybj+1c= X-Received: by 2002:a05:600c:3e8f:b0:492:6f5c:fd8c with SMTP id 5b1f17b1804b1-493bc74b8f3mr48557225e9.15.1782864460017; Tue, 30 Jun 2026 17:07:40 -0700 (PDT) X-Received: by 2002:a05:600c:3e8f:b0:492:6f5c:fd8c with SMTP id 5b1f17b1804b1-493bc74b8f3mr48556925e9.15.1782864459558; Tue, 30 Jun 2026 17:07:39 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493be493c24sm20927495e9.0.2026.06.30.17.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 17:07:38 -0700 (PDT) From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 09/12] conf: Move address configuration into helper function Message-ID: <20260701020735.73596cda@elisabeth> In-Reply-To: <20260626071003.3472194-10-david@gibson.dropbear.id.au> References: <20260626071003.3472194-1-david@gibson.dropbear.id.au> <20260626071003.3472194-10-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Wed, 01 Jul 2026 02:07:38 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -lEGXjaVDcCtV8b3vPvmAKSs5L0Gb5nLcaC-HsoyIzk_1782864460 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: SUNHVH6KG33UDMAR4JCY3BOXJYK4CQAK X-Message-ID-Hash: SUNHVH6KG33UDMAR4JCY3BOXJYK4CQAK X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top, Jon Maloy 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: On Fri, 26 Jun 2026 17:10:00 +1000 David Gibson wrote: > The handling of the -a option is getting complex enough that it's pretty > bulky inside it's switch label. Move it into a new conf_addr() function. Nit if you respin: 'its'. > We also rename the bulky addr_has_prefix_len and prefix_len_from_opt > variables to the terser 'opt_a_is_prefix' and 'opt_n', since they are > specifically about those command line options. > > Cc: Jon Maloy > > Signed-off-by: David Gibson > --- > conf.c | 96 ++++++++++++++++++++++++++++++++-------------------------- > 1 file changed, 53 insertions(+), 43 deletions(-) > > diff --git a/conf.c b/conf.c > index 2d1895d4..3614776c 100644 > --- a/conf.c > +++ b/conf.c > @@ -1168,6 +1168,53 @@ int conf_tap_fd(const char *arg) > return val; > } > > +/** > + * conf_addr() - Configure guest address with -a option > + * @c: Execution context > + * @arg: -a command line argument > + * @opt_n: Value from -n option, if any > + */ > +static bool conf_addr(struct ctx *c, char *arg, uint8_t opt_n) > +{ > + union inany_addr addr; > + const char *p = arg; > + uint8_t prefix_len; > + bool is_prefix; > + > + is_prefix = inany_prefix_pton(arg, &addr, &prefix_len); > + > + if (is_prefix && opt_n) > + die("Redundant prefix length specification"); > + > + if (!is_prefix && > + !(parse_inany(&p, &addr) && parse_eoi(p))) > + die("Invalid address: %s", arg); > + > + if (opt_n && inany_v4(&addr)) > + prefix_len = opt_n; > + else if (!is_prefix) > + prefix_len = inany_default_prefix_len(&addr); > + > + if (inany_is_unspecified(&addr) || inany_is_multicast(&addr) || > + inany_is_loopback(&addr) || IN6_IS_ADDR_V4COMPAT(&addr.a6)) > + die("Invalid address: %s", arg); > + > + if (inany_v4(&addr)) { > + c->ip4.addr = *inany_v4(&addr); > + c->ip4.prefix_len = prefix_len - 96; > + c->ip4.addr_fixed = true; > + if (c->mode == MODE_PASTA) > + c->ip4.no_copy_addrs = true; > + } else { > + c->ip6.addr = addr.a6; > + c->ip6.addr_fixed = true; > + if (c->mode == MODE_PASTA) > + c->ip6.no_copy_addrs = true; > + } > + > + return is_prefix; > +} > + > /** > * conf() - Process command-line arguments and set configuration > * @c: Execution context > @@ -1262,12 +1309,12 @@ void conf(struct ctx *c, int argc, char **argv) > unsigned dns4_idx = 0, dns6_idx = 0; > unsigned long max_mtu = IP_MAX_MTU; > struct fqdn *dnss = c->dns_search; > - bool addr_has_prefix_len = false; > - uint8_t prefix_len_from_opt = 0; > unsigned int ifi4 = 0, ifi6 = 0; > + bool opt_a_is_prefix = false; > const char *logfile = NULL; > char *runas = NULL; > size_t logsize = 0; > + uint8_t opt_n = 0; > int name, ret; > uid_t uid; > gid_t gid; > @@ -1567,52 +1614,15 @@ void conf(struct ctx *c, int argc, char **argv) > c->mtu = mtu; > break; > } > - case 'a': { > - union inany_addr addr; > - uint8_t prefix_len; > - > - addr_has_prefix_len = inany_prefix_pton(optarg, &addr, > - &prefix_len); > - > - if (addr_has_prefix_len && prefix_len_from_opt) > - die("Redundant prefix length specification"); > - > - p = optarg; > - if (!addr_has_prefix_len && > - !(parse_inany(&p, &addr) && parse_eoi(p))) > - die("Invalid address: %s", optarg); > - > - if (prefix_len_from_opt && inany_v4(&addr)) > - prefix_len = prefix_len_from_opt; > - else if (!addr_has_prefix_len) > - prefix_len = inany_default_prefix_len(&addr); > - > - if (inany_is_unspecified(&addr) || > - inany_is_multicast(&addr) || > - inany_is_loopback(&addr) || > - IN6_IS_ADDR_V4COMPAT(&addr.a6)) > - die("Invalid address: %s", optarg); > - > - if (inany_v4(&addr)) { > - c->ip4.addr = *inany_v4(&addr); > - c->ip4.prefix_len = prefix_len - 96; > - c->ip4.addr_fixed = true; > - if (c->mode == MODE_PASTA) > - c->ip4.no_copy_addrs = true; > - } else { > - c->ip6.addr = addr.a6; > - c->ip6.addr_fixed = true; > - if (c->mode == MODE_PASTA) > - c->ip6.no_copy_addrs = true; > - } > + case 'a': > + opt_a_is_prefix = conf_addr(c, optarg, opt_n); > break; > - } > case 'n': > - if (addr_has_prefix_len) > + if (opt_a_is_prefix) > die("Redundant prefix length specification"); > > c->ip4.prefix_len = conf_ip4_prefix(optarg); > - prefix_len_from_opt = c->ip4.prefix_len + 96; > + opt_n = c->ip4.prefix_len + 96; > break; > case 'M': > parse_mac(c->our_tap_mac, optarg); -- Stefano