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.133.124]) by passt.top (Postfix) with ESMTPS id 70ACA5A0269 for ; Tue, 24 Nov 2026 05:14:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795493647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YWF7EVEfV94j3AsZjWHFg9ke6+XVR3llsuyWi7eqX7U=; b=WNawt2a547Xp2bLlJmhnZ0zh4h+GVppw2EUxFXncPylimz47x0qqzodrJkJqYE6gt4VCWV SlQ9bbcCYcns/dpIGx5Nl+DV8WdjCH/Xr7H9OEW2JIgShX1DSSK5NbTJtnul9BkyZRExD0 OggI2hDYlkSttMh3WwWDRuT/aVBhLto= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-t67HAf-JMj658WkXJv56eg-1; Tue, 24 Nov 2026 04:13:55 +0000 X-MC-Unique: t67HAf-JMj658WkXJv56eg-1 X-Mimecast-MFC-AGG-ID: t67HAf-JMj658WkXJv56eg_1795493633 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EE1F21955DD5; Tue, 24 Nov 2026 04:13:52 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 893371956087; Tue, 24 Nov 2026 04:13:51 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, david@gibson.dropbear.id.au, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH v2] netlink: Set default route as on-link Date: Mon, 23 Nov 2026 23:13:50 -0500 Message-ID: <20261124041350.3347277-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: WxVE4RKU4WJiiTi2uSt1oZYsqcCxpnIo3UGxj28eLe4_1795493633 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: XIHYTIKY3TT5NPX4UGQBJLTX2UAQBTA5 X-Message-ID-Hash: XIHYTIKY3TT5NPX4UGQBJLTX2UAQBTA5 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 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: 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 --- 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