public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Subject: [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version
Date: Fri,  5 Dec 2025 01:51:26 +0100	[thread overview]
Message-ID: <20251205005126.2577347-1-sbrivio@redhat.com> (raw)

This fixes an issue and introduces a feature:

- in local mode, we accidentally ignored the -4 / --ipv4-only and
  -6 / --ipv6-only command line options

- if no template interface is available for a given IP version,
  instead of disabling that IP version, use local mode, separately,
  for it

Link: https://bugs.passt.top/show_bug.cgi?id=129
Link: https://bugs.passt.top/show_bug.cgi?id=128
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 conf.c  | 19 +++++++++++--------
 passt.1 | 15 ++++++++-------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/conf.c b/conf.c
index 02a4b65..fdc19e8 100644
--- a/conf.c
+++ b/conf.c
@@ -1109,7 +1109,7 @@ static void conf_print(const struct ctx *c)
 		info("Template interface: %s%s%s%s%s",
 		     c->ifi4 > 0 ? if_indextoname(c->ifi4, ifn) : "",
 		     c->ifi4 > 0 ? " (IPv4)" : "",
-		     (c->ifi4 && c->ifi6) ? ", " : "",
+		     (c->ifi4 > 0 && c->ifi6 > 0) ? ", " : "",
 		     c->ifi6 > 0 ? if_indextoname(c->ifi6, ifn) : "",
 		     c->ifi6 > 0 ? " (IPv6)" : "");
 	}
@@ -2001,20 +2001,23 @@ void conf(struct ctx *c, int argc, char **argv)
 	    (*c->ip6.ifname_out && !c->ifi6))
 		die("External interface not usable");
 
+	if (!c->ifi4 && !c->ifi6 && !*c->pasta_ifn) {
+		strncpy(c->pasta_ifn, pasta_default_ifn,
+			sizeof(c->pasta_ifn) - 1);
+	}
 
-	if (!c->ifi4 && !c->ifi6) {
-		info("No external interface as template, switch to local mode");
+	if (!c->ifi4 && !v6_only) {
+		info("IPv4: no external interface as template, use local mode");
 
 		conf_ip4_local(&c->ip4);
 		c->ifi4 = -1;
+	}
+
+	if (!c->ifi6 && !v4_only) {
+		info("IPv6: no external interface as template, use local mode");
 
 		conf_ip6_local(&c->ip6);
 		c->ifi6 = -1;
-
-		if (!*c->pasta_ifn) {
-			strncpy(c->pasta_ifn, pasta_default_ifn,
-				sizeof(c->pasta_ifn) - 1);
-		}
 	}
 
 	if (c->ifi4 && !no_map_gw &&
diff --git a/passt.1 b/passt.1
index 0c17454..db0d662 100644
--- a/passt.1
+++ b/passt.1
@@ -166,8 +166,8 @@ By default, assigned IPv4 and IPv6 addresses are taken from the host interfaces
 with the first default route, if any, for the corresponding IP version. If no
 default routes are available and there is any interface with any route for a
 given IP version, the first of these interfaces will be chosen instead. If no
-such interface exists, the link-local address 169.254.2.1 is assigned for IPv4,
-and no additional address will be assigned for IPv6.
+such interface exists for a given IP version, the link-local address 169.254.2.1
+is assigned for IPv4, and no additional address will be assigned for IPv6.
 
 .TP
 .BR \-n ", " \-\-netmask " " \fImask
@@ -194,9 +194,9 @@ first default route, if any, for the corresponding IP version. If the default
 route is a multipath one, the gateway is the first nexthop router returned by
 the kernel which has the highest weight in the set of paths. If no default
 routes are available and there is just one interface with any route, that
-interface will be chosen instead. If no such interface exists, the link-local
-address 169.254.2.2 is used for IPv4, and the link-local address fe80::1 is used
-for IPv6.
+interface will be chosen instead. If no such interface exists for a given IP
+version, the link-local address 169.254.2.2 is used for IPv4, and the link-local
+address fe80::1 is used for IPv6.
 
 Note: these addresses are also used as source address for packets directed to
 the guest or to the target namespace having a loopback or local source address,
@@ -1117,8 +1117,9 @@ throughput of TCP connections.
 .SS Local mode for disconnected setups
 
 If \fBpasst\fR and \fBpasta\fR fail to find a host interface with a configured
-address, other than loopback addresses, they will, obviously, not attempt to
-source addresses or routes from the host.
+address for a given IP version, other than loopback addresses, they will,
+obviously, not attempt to source addresses or routes from the host, for that
+IP version.
 
 In this case, unless configured otherwise, they will assign the IPv4 link-local
 address 169.254.2.1 to the guest or target namespace, and no IPv6 address. The
-- 
2.43.0


             reply	other threads:[~2025-12-05  0:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05  0:51 Stefano Brivio [this message]
2025-12-05  3:01 ` David Gibson
2025-12-05 11:26 ` Paul Holzinger
2025-12-05 11:31   ` Stefano Brivio
2025-12-05 12:00     ` Paul Holzinger
2025-12-05 12:19       ` Stefano Brivio

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=20251205005126.2577347-1-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=passt-dev@passt.top \
    /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).