* [PATCH] netlink: Set default IPv4 route as on-link
@ 2026-11-19 23:21 Jon Maloy
2026-11-22 22:15 ` Stefano Brivio
0 siblings, 1 reply; 2+ messages in thread
From: Jon Maloy @ 2026-11-19 23:21 UTC (permalink / raw)
To: sbrivio, david, jmaloy, passt-dev
In local mode, the default IPv4 gateway is 169.254.2.2. If the user
assigns an address outside 169.254.0.0/16 with -a, the gateway isn't
covered by any prefix on the namespace interface, and if pasta is run
with --config-net, setting the default route fails.
This can be reproduced from a namespace without routes, e.g. one
created by pasta without --config-net:
$ pasta
# pasta --config-net -a 10.0.0.1/24 -- ip route
...
Couldn't set IPv4 route(s) in guest: Network is unreachable
We reply to ARP requests for any address other than the guest's own,
so the gateway is always reachable on the link. Therefore, flag the
default route with RTNH_F_ONLINK, so that the kernel doesn't require
the gateway to be within an assigned prefix.
Fixes: 14b84a7f077e ("treewide: Introduce 'local mode' for disconnected setups")
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
netlink.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/netlink.c b/netlink.c
index 225b666a..8d7f2e7b 100644
--- a/netlink.c
+++ b/netlink.c
@@ -520,6 +520,13 @@ int nl_route_set_def(int s, unsigned int ifi, sa_family_t af, const void *gw)
memcpy(&req.set.r4.a, gw, sizeof(req.set.r4.a));
req.set.r4.rta_gw.rta_type = RTA_GATEWAY;
req.set.r4.rta_gw.rta_len = rta_len;
+
+ /* The gateway might not be covered by any assigned prefix,
+ * e.g. the 169.254.2.2 default of local mode with a
+ * user-provided address. Since we answer ARP requests for
+ * any address other than the guest's, treat it as on-link
+ */
+ req.rtm.rtm_flags = RTNH_F_ONLINK;
}
return nl_do(s, &req, RTM_NEWROUTE, NLM_F_CREATE | NLM_F_EXCL, len);
--
2.56.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] netlink: Set default IPv4 route as on-link
2026-11-19 23:21 [PATCH] netlink: Set default IPv4 route as on-link Jon Maloy
@ 2026-11-22 22:15 ` Stefano Brivio
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Brivio @ 2026-11-22 22:15 UTC (permalink / raw)
To: Jon Maloy; +Cc: david, passt-dev
On Thu, 19 Nov 2026 18:21:31 -0500
Jon Maloy <jmaloy@redhat.com> wrote:
> In local mode, the default IPv4 gateway is 169.254.2.2. If the user
> assigns an address outside 169.254.0.0/16 with -a, the gateway isn't
> covered by any prefix on the namespace interface, and if pasta is run
> with --config-net, setting the default route fails.
This shouldn't depend on a particular choice of the gateway address
(but it seems to do, see below).
It should be rather related to the fact that if routes aren't copied
(which also happens in local mode), then you don't have a device route
for the default gateway, that is:
$ pasta -Ix -- sh -c '{ ip link set dev x up; ip addr add 10.0.0.2/24 dev x; ip ro add default via 10.0.0.1 dev x; pasta -4 --config-net -a 192.0.2.1 -- ip r; }'
default via 10.0.0.1 dev x
10.0.0.0/24 dev x proto kernel scope link
192.0.2.0/24 dev x proto kernel scope link src 192.0.2.1
we copy the device route for 10.0.0.1 so it's reachable.
Here, instead:
$ pasta -Ix -- sh -c '{ ip link set dev x up; ip addr add 169.254.2.2/16 dev x; pasta -4 --config-net -a 192.0.2.1 -- ip r; }'
No interfaces with usable IPv4 routes
IPv4: no external interface as template, use local mode
Couldn't set IPv4 route(s) in guest: Network is unreachable
we don't have a device route, so it's unreachable and we can't set it
as default gateway, as expected. However:
$ pasta -Ix -- sh -c '{ ip link set dev x up; ip addr add 168.254.2.2/16 dev x; pasta -4 --config-net -a 192.0.2.1 -- ip r; }'
168.254.0.0/16 dev x proto kernel scope link
192.0.2.0/24 dev x proto kernel scope link src 192.0.2.1
...this shouldn't work either. But it does. I think we should find
out why and make it consistent if it's not.
> This can be reproduced from a namespace without routes, e.g. one
> created by pasta without --config-net:
>
> $ pasta
> # pasta --config-net -a 10.0.0.1/24 -- ip route
> ...
> Couldn't set IPv4 route(s) in guest: Network is unreachable
>
> We reply to ARP requests for any address other than the guest's own,
> so the gateway is always reachable on the link. Therefore, flag the
> default route with RTNH_F_ONLINK, so that the kernel doesn't require
> the gateway to be within an assigned prefix.
Regardless of that, RTNH_F_ONLINK *might* be a good idea, except that:
>
> Fixes: 14b84a7f077e ("treewide: Introduce 'local mode' for disconnected setups")
...I really intended it to work that way: if you override things so
that the default gateway is unreachable, it should be unreachable.
On the other hand, there's probably no harm in setting RTNH_F_ONLINK.
It's a bit unexpected for me that things would work that way, but if
they do, I don't think we're going to hide any dangerous detail from
the user, and as you noted it all works ARP-wise, so it should simply
improve usability.
> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
> ---
> netlink.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/netlink.c b/netlink.c
> index 225b666a..8d7f2e7b 100644
> --- a/netlink.c
> +++ b/netlink.c
> @@ -520,6 +520,13 @@ int nl_route_set_def(int s, unsigned int ifi, sa_family_t af, const void *gw)
> memcpy(&req.set.r4.a, gw, sizeof(req.set.r4.a));
> req.set.r4.rta_gw.rta_type = RTA_GATEWAY;
> req.set.r4.rta_gw.rta_len = rta_len;
> +
> + /* The gateway might not be covered by any assigned prefix,
> + * e.g. the 169.254.2.2 default of local mode with a
> + * user-provided address. Since we answer ARP requests for
> + * any address other than the guest's, treat it as on-link
> + */
> + req.rtm.rtm_flags = RTNH_F_ONLINK;
> }
>
> return nl_do(s, &req, RTM_NEWROUTE, NLM_F_CREATE | NLM_F_EXCL, len);
By the way, did you happen to find out why it works with IPv6 instead?
It looks like the choice of the interface name is also inconsistent.
This is without your patch:
$ pasta -6 -Ix -- pasta --config-net -a 2001:db8::1 -- ip -6 r
Couldn't get any nameserver address
No interfaces with usable IPv4 routes
No interfaces with usable IPv6 routes
IPv4: no external interface as template, use local mode
IPv6: no external interface as template, use local mode
2001:db8::/64 dev tap0 proto kernel metric 256 pref medium
fe80::/64 dev tap0 proto kernel metric 256 pref medium
default via fe80::1 dev tap0 metric 1024 pref medium
--
Stefano
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-22 22:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 23:21 [PATCH] netlink: Set default IPv4 route as on-link Jon Maloy
2026-11-22 22:15 ` 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).