diff options
| author | Jon Maloy <jmaloy@redhat.com> | 2026-11-23 23:13:50 -0500 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-11-24 11:38:26 +0100 |
| commit | 2b9de43e51ac789dce5872d5cfdba05376dad00c (patch) | |
| tree | 6c3ab25225e2e97dd39a20c947e5e1732d857c2e | |
| parent | db7fb06f710e2d14b0d5b03d4edd3dfb2de1f913 (diff) | |
| download | passt-2b9de43e51ac789dce5872d5cfdba05376dad00c.tar passt-2b9de43e51ac789dce5872d5cfdba05376dad00c.tar.gz passt-2b9de43e51ac789dce5872d5cfdba05376dad00c.tar.bz2 passt-2b9de43e51ac789dce5872d5cfdba05376dad00c.tar.lz passt-2b9de43e51ac789dce5872d5cfdba05376dad00c.tar.xz passt-2b9de43e51ac789dce5872d5cfdba05376dad00c.tar.zst passt-2b9de43e51ac789dce5872d5cfdba05376dad00c.zip | |
netlink: Set default route as on-link
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>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | netlink.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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); } |
