public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: "Jan Rodák" <jrodak@redhat.com>,
	"Paul Holzinger" <pholzing@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: [PATCH 1/2] conf: Honour --address, --gateway, --netmask in local mode as well
Date: Thu, 23 Jul 2026 01:26:38 +0200	[thread overview]
Message-ID: <20260722232639.1105561-2-sbrivio@redhat.com> (raw)
In-Reply-To: <20260722232639.1105561-1-sbrivio@redhat.com>

When I implemented local mode in 14b84a7f077e ("treewide: Introduce
'local mode' for disconnected setups"), I didn't consider the
possibility that, also in that case, the user might want to override
addresses, default gateway or netmask, even though I expressly
mentioned this in the man page:

  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.

Fix this by checking if an address, gateway, or netmask length was
explicitly set by the user, before overriding them with the default
parameters for local mode.

This might lead to invalid configurations where we won't be able to
set the default gateway passed by the user, but we print a warning
message, and we assume users know what they're doing in that case.

Link: https://bugs.passt.top/show_bug.cgi?id=217
Fixes: 14b84a7f077e ("treewide: Introduce 'local mode' for disconnected setups")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 conf.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/conf.c b/conf.c
index 0fcba5c..7908123 100644
--- a/conf.c
+++ b/conf.c
@@ -435,9 +435,16 @@ static unsigned int conf_ip4(unsigned int ifi, struct ip4_ctx *ip4)
  */
 static void conf_ip4_local(struct ip4_ctx *ip4)
 {
-	ip4->addr_seen = ip4->addr = IP4_LL_GUEST_ADDR;
-	ip4->our_tap_addr = ip4->guest_gw = IP4_LL_GUEST_GW;
-	ip4->prefix_len = IP4_LL_PREFIX_LEN;
+	if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr))
+		ip4->addr = IP4_LL_GUEST_ADDR;
+	ip4->addr_seen = ip4->addr;
+
+	if (IN4_IS_ADDR_UNSPECIFIED(&ip4->guest_gw))
+		ip4->guest_gw = IP4_LL_GUEST_GW;
+	ip4->our_tap_addr = ip4->guest_gw;
+
+	if (!ip4->prefix_len)
+		ip4->prefix_len = IP4_LL_PREFIX_LEN;
 
 	ip4->no_copy_addrs = ip4->no_copy_routes = true;
 }
@@ -497,7 +504,13 @@ static unsigned int conf_ip6(unsigned int ifi, struct ip6_ctx *ip6)
  */
 static void conf_ip6_local(struct ip6_ctx *ip6)
 {
-	ip6->our_tap_ll = ip6->guest_gw = IP6_LL_GUEST_GW;
+	if (IN6_IS_ADDR_UNSPECIFIED(&ip6->guest_gw))
+		ip6->guest_gw = IP6_LL_GUEST_GW;
+
+	if (IN6_IS_ADDR_LINKLOCAL(&ip6->guest_gw))
+		ip6->our_tap_ll = ip6->guest_gw;
+	else
+		ip6->our_tap_ll = IP6_LL_GUEST_GW;
 
 	ip6->no_copy_addrs = ip6->no_copy_routes = true;
 }
-- 
2.43.0


  reply	other threads:[~2026-07-22 23:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 23:26 [PATCH 0/2] Allow users to give source address with --gateway also for IPv6 Stefano Brivio
2026-07-22 23:26 ` Stefano Brivio [this message]
2026-07-23  3:26   ` [PATCH 1/2] conf: Honour --address, --gateway, --netmask in local mode as well David Gibson
2026-07-22 23:26 ` [PATCH 2/2] conf, fwd: Prefer same-scope address as inbound source address from host Stefano Brivio
2026-07-23  3:36   ` David Gibson
2026-07-23  9:42     ` 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=20260722232639.1105561-2-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=jrodak@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=pholzing@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).