public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version
@ 2025-12-05  0:51 Stefano Brivio
  2025-12-05  3:01 ` David Gibson
  2025-12-05 11:26 ` Paul Holzinger
  0 siblings, 2 replies; 6+ messages in thread
From: Stefano Brivio @ 2025-12-05  0:51 UTC (permalink / raw)
  To: passt-dev

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version
  2025-12-05  0:51 [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version Stefano Brivio
@ 2025-12-05  3:01 ` David Gibson
  2025-12-05 11:26 ` Paul Holzinger
  1 sibling, 0 replies; 6+ messages in thread
From: David Gibson @ 2025-12-05  3:01 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev

[-- Attachment #1: Type: text/plain, Size: 4763 bytes --]

On Fri, Dec 05, 2025 at 01:51:26AM +0100, Stefano Brivio wrote:
> 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>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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
> 

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version
  2025-12-05  0:51 [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version Stefano Brivio
  2025-12-05  3:01 ` David Gibson
@ 2025-12-05 11:26 ` Paul Holzinger
  2025-12-05 11:31   ` Stefano Brivio
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Holzinger @ 2025-12-05 11:26 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev


On 05/12/2025 01:51, Stefano Brivio wrote:
> 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>
Tested-by: Paul Holzinger <pholzing@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

-- 
Paul Holzinger


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version
  2025-12-05 11:26 ` Paul Holzinger
@ 2025-12-05 11:31   ` Stefano Brivio
  2025-12-05 12:00     ` Paul Holzinger
  0 siblings, 1 reply; 6+ messages in thread
From: Stefano Brivio @ 2025-12-05 11:31 UTC (permalink / raw)
  To: Paul Holzinger; +Cc: passt-dev

On Fri, 5 Dec 2025 12:26:06 +0100
Paul Holzinger <pholzing@redhat.com> wrote:

> On 05/12/2025 01:51, Stefano Brivio wrote:
> > 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>  
>
> Tested-by: Paul Holzinger <pholzing@redhat.com>

Ah, thanks, that's quite reassuring / much needed for this one.

-- 
Stefano


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version
  2025-12-05 11:31   ` Stefano Brivio
@ 2025-12-05 12:00     ` Paul Holzinger
  2025-12-05 12:19       ` Stefano Brivio
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Holzinger @ 2025-12-05 12:00 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev


On 05/12/2025 12:31, Stefano Brivio wrote:
> On Fri, 5 Dec 2025 12:26:06 +0100
> Paul Holzinger <pholzing@redhat.com> wrote:
>
>> On 05/12/2025 01:51, Stefano Brivio wrote:
>>> 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>
>> Tested-by: Paul Holzinger <pholzing@redhat.com>
> Ah, thanks, that's quite reassuring / much needed for this one.

FWIW, this is how I tested:

unshare -rn  sh -c "ip link add test type bridge && ip link set test up 
&& ip addr add 192.168.0.0/24 dev test &&  ./pasta --config-net ip a"

unshare -rn  sh -c "ip link add test type bridge && ip link set test up 
&& ip addr add 2620::1/64 dev test &&  ./pasta --config-net ip a"

And then the variations with  adding -4/-6.

-- 
Paul Holzinger


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version
  2025-12-05 12:00     ` Paul Holzinger
@ 2025-12-05 12:19       ` Stefano Brivio
  0 siblings, 0 replies; 6+ messages in thread
From: Stefano Brivio @ 2025-12-05 12:19 UTC (permalink / raw)
  To: Paul Holzinger; +Cc: passt-dev

On Fri, 5 Dec 2025 13:00:37 +0100
Paul Holzinger <pholzing@redhat.com> wrote:

> On 05/12/2025 12:31, Stefano Brivio wrote:
> > On Fri, 5 Dec 2025 12:26:06 +0100
> > Paul Holzinger <pholzing@redhat.com> wrote:
> >  
> >> On 05/12/2025 01:51, Stefano Brivio wrote:  
> >>> 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>  
> >> Tested-by: Paul Holzinger <pholzing@redhat.com>  
> > Ah, thanks, that's quite reassuring / much needed for this one.  
> 
> FWIW, this is how I tested:
> 
> unshare -rn  sh -c "ip link add test type bridge && ip link set test up 
> && ip addr add 192.168.0.0/24 dev test &&  ./pasta --config-net ip a"
> 
> unshare -rn  sh -c "ip link add test type bridge && ip link set test up 
> && ip addr add 2620::1/64 dev test &&  ./pasta --config-net ip a"
> 
> And then the variations with  adding -4/-6.

I went another way:

  $ ./pasta --config-net -4 -- ./pasta --config-net ip a

  $ ./pasta --config-net -6 -- ./pasta --config-net ip a

...maybe we should consider to slowly start making --config-net the default.

-- 
Stefano





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-12-05 12:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-05  0:51 [PATCH] conf: Separate local mode for each IP version, don't enable disabled IP version Stefano Brivio
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

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).