* [PATCH v2] netlink: Set default route as on-link
@ 2026-11-24 4:13 Jon Maloy
0 siblings, 0 replies; only message in thread
From: Jon Maloy @ 2026-11-24 4:13 UTC (permalink / raw)
To: sbrivio, david, jmaloy, passt-dev
Commit da54641f140e ("conf, pasta: With --config-net, copy all routes
by default") made it possible to use a default gateway that's not on
the same subnet as any address assigned to the namespace interface,
as copying all routes from the template interface also copies the
device route for the gateway.
If pasta sets the default route itself instead, that is, with -g or
--no-copy-routes, or in local mode, there's no such device route, and
the kernel refuses a gateway that's not covered by any assigned
prefix:
$ pasta -Ix -- sh -c 'ip link set dev x up; \
ip addr add 10.0.0.2/24 dev x; \
ip route add default via 10.0.0.1 dev x; \
pasta -4 --config-net -a 192.0.2.1 -g 10.0.0.1 -- ip route'
Couldn't set IPv4 route(s) in guest: Network is unreachable
$ pasta -6 -Ix -- sh -c 'ip link set dev x up; \
ip addr add 2001:db8:1::2/64 dev x nodad; \
ip -6 route add default via 2001:db8:1::1 dev x; \
pasta -6 --config-net -a 2001:db8:2::1 -g 2001:db8:1::1 -- \
ip -6 route'
Couldn't set IPv6 route(s) in guest: No route to host
The same happens in local mode for IPv4, where the default gateway is
169.254.2.2, with -a and any address outside 169.254.0.0/16. In local
mode for IPv6, the default gateway is the link-local address fe80::1,
which is always covered by the fe80::/64 device route.
We reply to ARP requests and neighbour solicitations for any address
other than the guest's own, so the gateway is in fact always reachable
on the link. Flag the default route with RTNH_F_ONLINK, so that the
kernel doesn't require the gateway to be within an assigned prefix.
This doesn't hide anything from the user, and makes these
configurations usable. With this change:
default via 10.0.0.1 dev x onlink
192.0.2.0/24 dev x proto kernel scope link src 192.0.2.1
and:
default via 2001:db8:1::1 dev x metric 1024 onlink pref medium
Note that RTNH_F_ONLINK is supported for IPv6 routes since Linux 4.16.
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
v2: - Set RTNH_F_ONLINK for IPv6 as well, as -g with a gateway outside
the prefix given with -a fails in the same way (Stefano)
- Reworded commit message: the issue isn't specific to local mode
or to 169.254.2.2, but affects any case where we set the default
route instead of copying routes (Stefano)
- Describe this as a usability improvement, and drop the Fixes:
tag, as the previous behaviour was intended (Stefano)
- Updated code comment accordingly
---
netlink.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/netlink.c b/netlink.c
index 225b666a..a0f8783b 100644
--- a/netlink.c
+++ b/netlink.c
@@ -522,6 +522,14 @@ int nl_route_set_def(int s, unsigned int ifi, sa_family_t af, const void *gw)
req.set.r4.rta_gw.rta_len = rta_len;
}
+ /* The gateway might not be covered by any assigned prefix, e.g. with
+ * -g, or in local mode with a user-provided IPv4 address, as we don't
+ * copy the device route for it in these cases. We answer ARP requests
+ * and neighbour solicitations for any address other than the guest's,
+ * so it's reachable anyway: 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] only message in thread
only message in thread, other threads:[~2026-11-24 4:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 4:13 [PATCH v2] netlink: Set default route as on-link 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).