public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v2 8/9] conf: Don't defer handling of --dns option
Date: Wed, 11 Mar 2026 23:03:13 +1100	[thread overview]
Message-ID: <20260311120314.933546-9-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260311120314.933546-1-david@gibson.dropbear.id.au>

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 <david@gibson.dropbear.id.au>
---
 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


  parent reply	other threads:[~2026-03-11 12:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 12:03 [PATCH v2 0/9] Unify TCP and UDP forwarding tables David Gibson
2026-03-11 12:03 ` [PATCH v2 1/9] conf, fwd: Make overall forwarding mode local to conf path David Gibson
2026-03-11 12:03 ` [PATCH v2 2/9] tcp: Remove stale description of port_to_tap field David Gibson
2026-03-11 12:03 ` [PATCH v2 3/9] fwd: Don't initialise unused port bitmaps David Gibson
2026-03-11 12:03 ` [PATCH v2 4/9] Fix misnamed field in struct ctx comments David Gibson
2026-03-11 12:03 ` [PATCH v2 5/9] fwd: Split forwarding table from port scanning state David Gibson
2026-03-11 12:03 ` [PATCH v2 6/9] fwd: Unify TCP and UDP forwarding tables David Gibson
2026-03-11 12:03 ` [PATCH v2 7/9] fwd: Always open /proc/net{tcp,tcp6,udp,udp6} in pasta mode David Gibson
2026-03-11 12:03 ` David Gibson [this message]
2026-03-11 12:03 ` [PATCH v2 9/9] conf: Parse all forwarding options at the same time David Gibson
2026-03-11 21:12 ` [PATCH v2 0/9] Unify TCP and UDP forwarding tables Stefano Brivio
2026-03-11 23:33   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260311120314.933546-9-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).