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=RtNfPsU1; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 7963A5A0657 for ; Wed, 11 Mar 2026 13:03:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773230596; bh=c+xAteuqupYzHATHmzuudqP0peVLQ9J5PEG/BMMlxYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RtNfPsU1w5BUjqRBBLpN/uGEpdo07nLkKpVVebaLyHYMlV8XtqEb6JCjbKBkSvwtF FdWww4gdLAb5jiwt7qPjwjolpGTbr+Eary0D53g5kWKKPu+DbciVJjkqNyPrjy4wZs /JKAIUAyphKsXAGyVD74ZfXaRS5R+jqBlETU+pui8LiXDd99z5WdG3mFAyix/AQ5Gf IDpNK/cZMVWJRPXVPdP0hWKnSUoTzzrr4egkLmG+lUScXVr0GIa0oiCZ4gjPyE+RCp zdppARdaaNCikgkQAnXh9Lx958my5MMSHprP+roihqJ9T/a5TrG1Q7E3QQJ0R+nFTR YzZoXwz/q/ujg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fW8XN2LRMz4wMQ; Wed, 11 Mar 2026 23:03:16 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 8/9] conf: Don't defer handling of --dns option Date: Wed, 11 Mar 2026 23:03:13 +1100 Message-ID: <20260311120314.933546-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311120314.933546-1-david@gibson.dropbear.id.au> References: <20260311120314.933546-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NQSWENV3K3B3FIW6MPLWOYOEWATHAC3B X-Message-ID-Hash: NQSWENV3K3B3FIW6MPLWOYOEWATHAC3B 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: For various reasons we make several passes through our command line options in conf(). First there's the main pass, then some supplemental passes for options that couldn't be handled in the initial pass. The --dns / -D option is handled in the second pass since f6d5a5239264 ("conf: Delay handling -D option until after addresses are configured"). The reason was that it called add_dns[46]() which relied on the gateway address already being configured which needed the first pass to complete. However, since 0b25cac94eca ("conf: Treat --dns addresses as guest visible addresses") that reason no longer applies - add_dns[46]() do nothing but update tables in a very simple way. So, move the --dns handling back into the main parsing pass. Signed-off-by: David Gibson --- conf.c | 80 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/conf.c b/conf.c index 96aa506d..ffbd403d 100644 --- a/conf.c +++ b/conf.c @@ -2001,9 +2001,44 @@ void conf(struct ctx *c, int argc, char **argv) break; case 't': case 'u': - case 'D': /* Handle these later, once addresses are configured */ break; + case 'D': { + struct in6_addr dns6_tmp; + struct in_addr dns4_tmp; + + if (!strcmp(optarg, "none")) { + c->no_dns = 1; + + dns4_idx = 0; + memset(c->ip4.dns, 0, sizeof(c->ip4.dns)); + c->ip4.dns[0] = (struct in_addr){ 0 }; + c->ip4.dns_match = (struct in_addr){ 0 }; + c->ip4.dns_host = (struct in_addr){ 0 }; + + dns6_idx = 0; + memset(c->ip6.dns, 0, sizeof(c->ip6.dns)); + c->ip6.dns_match = (struct in6_addr){ 0 }; + c->ip6.dns_host = (struct in6_addr){ 0 }; + + continue; + } + + c->no_dns = 0; + + if (inet_pton(AF_INET, optarg, &dns4_tmp)) { + dns4_idx += add_dns4(c, &dns4_tmp, dns4_idx); + continue; + } + + if (inet_pton(AF_INET6, optarg, &dns6_tmp)) { + dns6_idx += add_dns6(c, &dns6_tmp, dns6_idx); + continue; + } + + die("Cannot use DNS address %s", optarg); + } + break; case 'T': case 'U': if (c->mode != MODE_PASTA) @@ -2117,53 +2152,16 @@ void conf(struct ctx *c, int argc, char **argv) if (c->ifi4 && IN4_IS_ADDR_UNSPECIFIED(&c->ip4.guest_gw)) c->no_dhcp = 1; - /* Inbound port options and DNS can be parsed now, after IPv4/IPv6 - * settings - */ + /* Inbound port options can be parsed now, after IPv4/IPv6 settings */ fwd_probe_ephemeral(); optind = 0; do { name = getopt_long(argc, argv, optstring, options, NULL); - if (name == 't') { + if (name == 't') conf_ports(c, name, optarg, &c->fwd_in, &tcp_in_mode); - } else if (name == 'u') { + else if (name == 'u') conf_ports(c, name, optarg, &c->fwd_in, &udp_in_mode); - } else if (name == 'D') { - struct in6_addr dns6_tmp; - struct in_addr dns4_tmp; - - if (!strcmp(optarg, "none")) { - c->no_dns = 1; - - dns4_idx = 0; - memset(c->ip4.dns, 0, sizeof(c->ip4.dns)); - c->ip4.dns[0] = (struct in_addr){ 0 }; - c->ip4.dns_match = (struct in_addr){ 0 }; - c->ip4.dns_host = (struct in_addr){ 0 }; - - dns6_idx = 0; - memset(c->ip6.dns, 0, sizeof(c->ip6.dns)); - c->ip6.dns_match = (struct in6_addr){ 0 }; - c->ip6.dns_host = (struct in6_addr){ 0 }; - - continue; - } - - c->no_dns = 0; - - if (inet_pton(AF_INET, optarg, &dns4_tmp)) { - dns4_idx += add_dns4(c, &dns4_tmp, dns4_idx); - continue; - } - - if (inet_pton(AF_INET6, optarg, &dns6_tmp)) { - dns6_idx += add_dns6(c, &dns6_tmp, dns6_idx); - continue; - } - - die("Cannot use DNS address %s", optarg); - } } while (name != -1); if (c->mode == MODE_PASTA) -- 2.53.0