From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=quarantine dis=none) header.from=redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 8BB145A0269 for ; Tue, 24 Nov 2026 05:08:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795493293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5SD8XNj7tEI0a+59qTssHXZl//2Z1o23VV6HYRBlpO8=; b=G44pcJDpzWRQ5xkTieOKfwuHH2I+Ui5G19Gqg+Ntdr2e9wByoENIU8lEzg4jueC0de/M5S ahvUX9szUACOGu2QnG4kLeNSCjVNelQ8U1cHBe0IrlMuWDpjy6tEleBWQMx4QGyVTxBgeG jjTKd3hJdnXZ48++qZZgGjc15QRU9xw= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-jyn0CsFWPVakdWCv8hpiow-1; Tue, 24 Nov 2026 04:08:11 +0000 X-MC-Unique: jyn0CsFWPVakdWCv8hpiow-1 X-Mimecast-MFC-AGG-ID: jyn0CsFWPVakdWCv8hpiow_1795493291 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-91256a7b7b3so61499136d6.2 for ; Mon, 23 Nov 2026 20:08:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795493290; x=1796098090; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5SD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cvWT+x5FsJpc2 lD9Abr9kmY/rsIP62g07CQ8mY2OsX1pF1K57VxdTGv+4WMAGonLv78wPm2HSpfuSlUpeTSsxjeS yrkjgW71y+DrkOXUpZpo4KqzdgA8ag5+4r151+ER4O X-Received: by 2002:a05:622a:53c4:b0:536:918a:2e7d with SMTP id d75a77b69052e-55d76a26b42mr246699571cf.15.1795493290368; Mon, 23 Nov 2026 20:08:10 -0800 (PST) X-Received: by 2002:a05:622a:53c4:b0:536:918a:2e7d with SMTP id d75a77b69052e-55d76a26b42mr246699331cf.15.1795493289855; Mon, 23 Nov 2026 20:08:09 -0800 (PST) Received: from [192.168.2.15] (lnsm6-montreal02-142-122-43-105.internet.virginmobile.ca. [142.122.43.105]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-92134a0f5d7sm125044166d6.37.2026.11.23.20.08.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Nov 2026 20:08:09 -0800 (PST) Message-ID: Date: Mon, 23 Nov 2026 23:08:08 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] netlink: Set default IPv4 route as on-link To: Stefano Brivio References: <20261119232131.1409908-1-jmaloy@redhat.com> <20261122231505.276d47b3@elisabeth> From: Jon Maloy In-Reply-To: <20261122231505.276d47b3@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: qx7dDuhOD53PrggB_4o9F6f0A86zkAzNE9lXUdYZ8hA_1795493291 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: J6Z6KB34LVLRZIZ6EACZ75TXHD353ZRW X-Message-ID-Hash: J6Z6KB34LVLRZIZ6EACZ75TXHD353ZRW X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: david@gibson.dropbear.id.au, passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 2026-11-22 17:15, Stefano Brivio wrote: > On Thu, 19 Nov 2026 18:21:31 -0500 > Jon Maloy 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). That is right, it doesn't. Local mode and 169.254.2.2 were just the case where I happened to hit it. > > 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. > Right, and that's the key: when we don't copy routes, there's no device route for the gateway. Besides local mode, that's also the case with -g, which implies --no-copy-routes. Your example with -g added: $ 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 and with my patch: 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 > 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. Actually it doesn't. There is just nothing to reject, because we never try to set a default route. Since 168.254.0.0/16 (contrary to 169.254.0.0/16) isn't a link-local prefix, nl_get_ext_if() accepts x as template interface, and we don't go to local mode. However, x has no default route, so we don't get a gateway from it, and there's no default route to copy either. We only copy the device route for 168.254.0.0/16. > >> 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. > Ok. I'll drop the "Fixes:" line and describe it as a usability improvement rather than a fix. > 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 >> --- >> 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? As I understand it, in local mode the IPv6 default gateway is the link-local address fe80::1, which is always reachable whatever the user assigns with -a, because the kernel adds a fe80::/64 device route to every IPv6 interface. This is in contrast to IPv4, where the local-mode gateway 169.254.2.2 is only covered if the assigned address happens to be in 169.254.0.0/16. I actually found it fails just like IPv4 with -g and a global gateway outside the -a prefix, though: $ 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 Since we also answer neighbour solicitations for any address, I realize I must set RTNH_F_ONLINK for IPv6 too. > 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 > That's intentional, but maybe not obvious. The inner pasta copies the name of the template interface, if any, and falls back to "tap0" (pasta_default_ifn) otherwise. In your IPv6 example, x is down and has no routes, so there's no template for either family and we end up with tap0. In the 168.254.0.0/16 example, x is the template, so the name is x as well. Note that -Ix only applies to the outer pasta. I will post a v2 shortly with improved comments and the IPv6 fix. ///jon