public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] netlink: Ignore routes via gateways from another address family
@ 2026-12-02 22:51 Jon Maloy
  2026-12-02 23:04 ` Stefano Brivio
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Maloy @ 2026-12-02 22:51 UTC (permalink / raw)
  To: sbrivio, jmaloy, passt-dev

With NetworkManager's CLAT implementation, the IPv4 default route has
an IPv6 gateway, given in a RTA_VIA attribute instead of RTA_GATEWAY:

  default via inet6 fe80::1 dev wlp170s0f0 proto static src 192.0.0.5

nl_get_ext_if() picks the interface of that route as template for
IPv4, but nl_route_get_def() finds no IPv4 gateway, so we disable DHCP
altogether, and the guest silently ends up without IPv4 connectivity,
even if the host has it.

We can't pass a gateway of a different address family on to the guest,
so don't consider such routes in nl_get_ext_if(). If no other IPv4
routes are available, as in the case above, we fall back to local
mode, which gives the guest a working IPv4 configuration: traffic
still reaches the host via our sockets, and the host translates it.
The address we would otherwise copy, from 192.0.0.0/29 (RFC 7335), is
just a placeholder in CLAT setups anyway.

Link: https://bugs.passt.top/show_bug.cgi?id=231
Suggested-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
 netlink.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/netlink.c b/netlink.c
index a0f8783b..99aeec2b 100644
--- a/netlink.c
+++ b/netlink.c
@@ -287,6 +287,7 @@ unsigned int nl_get_ext_if(int s, sa_family_t af)
 		struct rtmsg *rtm = (struct rtmsg *)NLMSG_DATA(nh);
 		const void *dst = NULL;
 		unsigned thisifi = 0;
+		bool via = false;
 
 		if (rtm->rtm_family != af)
 			continue;
@@ -302,12 +303,22 @@ unsigned int nl_get_ext_if(int s, sa_family_t af)
 				thisifi = rtnh->rtnh_ifindex;
 			} else if (rta->rta_type == RTA_DST) {
 				dst = RTA_DATA(rta);
+			} else if (rta->rta_type == RTA_VIA) {
+				const struct rtvia *v = RTA_DATA(rta);
+
+				via = v->rtvia_family != af;
 			}
 		}
 
 		if (!thisifi)
 			continue; /* No interface for this route */
 
+		/* Skip routes with a gateway from another address family, such
+		 * as IPv4 routes via IPv6 gateways in CLAT setups.
+		 */
+		if (via)
+			continue;
+
 		/* Skip 'lo': we should test IFF_LOOPBACK, but keep it simple */
 		if (thisifi == 1)
 			continue;
-- 
2.56.1


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

* Re: [PATCH] netlink: Ignore routes via gateways from another address family
  2026-12-02 22:51 [PATCH] netlink: Ignore routes via gateways from another address family Jon Maloy
@ 2026-12-02 23:04 ` Stefano Brivio
  2026-12-03 15:11   ` Jon Maloy
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Brivio @ 2026-12-02 23:04 UTC (permalink / raw)
  To: Jon Maloy; +Cc: passt-dev

On Wed,  2 Dec 2026 17:51:47 -0500
Jon Maloy <jmaloy@redhat.com> wrote:

> With NetworkManager's CLAT implementation, the IPv4 default route has
> an IPv6 gateway, given in a RTA_VIA attribute instead of RTA_GATEWAY:
> 
>   default via inet6 fe80::1 dev wlp170s0f0 proto static src 192.0.0.5
> 
> nl_get_ext_if() picks the interface of that route as template for
> IPv4, but nl_route_get_def() finds no IPv4 gateway, so we disable DHCP
> altogether, and the guest silently ends up without IPv4 connectivity,
> even if the host has it.
> 
> We can't pass a gateway of a different address family on to the guest,
> so don't consider such routes in nl_get_ext_if(). If no other IPv4
> routes are available, as in the case above, we fall back to local
> mode, which gives the guest a working IPv4 configuration: traffic
> still reaches the host via our sockets, and the host translates it.
> The address we would otherwise copy, from 192.0.0.0/29 (RFC 7335), is
> just a placeholder in CLAT setups anyway.
> 
> Link: https://bugs.passt.top/show_bug.cgi?id=231
> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> Signed-off-by: Jon Maloy <jmaloy@redhat.com>

Thanks for the patch, could you perhaps resend as it is with the correct
Reported-by: tag and Cc'ing the reporter?

By the way, at a quick glance, it might be nice to implement a fallback
for kernel version headers without 'rtvia_family' (before 4.1), but I'm
not sure how involved that is.  On the other hand 4.1 is pretty old so
I don't think it's strictly necessary.

-- 
Stefano

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

* Re: [PATCH] netlink: Ignore routes via gateways from another address family
  2026-12-02 23:04 ` Stefano Brivio
@ 2026-12-03 15:11   ` Jon Maloy
  0 siblings, 0 replies; 3+ messages in thread
From: Jon Maloy @ 2026-12-03 15:11 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev



On 2026-12-02 18:04, Stefano Brivio wrote:
> On Wed,  2 Dec 2026 17:51:47 -0500
> Jon Maloy <jmaloy@redhat.com> wrote:
> 
>> With NetworkManager's CLAT implementation, the IPv4 default route has
>> an IPv6 gateway, given in a RTA_VIA attribute instead of RTA_GATEWAY:
>>
>>    default via inet6 fe80::1 dev wlp170s0f0 proto static src 192.0.0.5
>>
>> nl_get_ext_if() picks the interface of that route as template for
>> IPv4, but nl_route_get_def() finds no IPv4 gateway, so we disable DHCP
>> altogether, and the guest silently ends up without IPv4 connectivity,
>> even if the host has it.
>>
>> We can't pass a gateway of a different address family on to the guest,
>> so don't consider such routes in nl_get_ext_if(). If no other IPv4
>> routes are available, as in the case above, we fall back to local
>> mode, which gives the guest a working IPv4 configuration: traffic
>> still reaches the host via our sockets, and the host translates it.
>> The address we would otherwise copy, from 192.0.0.0/29 (RFC 7335), is
>> just a placeholder in CLAT setups anyway.
>>
>> Link: https://bugs.passt.top/show_bug.cgi?id=231
>> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
>> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
> 
> Thanks for the patch, could you perhaps resend as it is with the correct
> Reported-by: tag and Cc'ing the reporter?
> 
> By the way, at a quick glance, it might be nice to implement a fallback
> for kernel version headers without 'rtvia_family' (before 4.1), but I'm
> not sure how involved that is.  On the other hand 4.1 is pretty old so
> I don't think it's strictly necessary.
> 
Reposted as v2.
Regarding the kernel headers, Linux 4.1 is from 2015, so I think the 
risk is extremely low. I feel we can afford to wait until there is
an actual bug report on this.

///jon

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

end of thread, other threads:[~2026-12-03 15:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 22:51 [PATCH] netlink: Ignore routes via gateways from another address family Jon Maloy
2026-12-02 23:04 ` Stefano Brivio
2026-12-03 15:11   ` Jon Maloy

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