From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 891CD5A0051 for ; Wed, 19 Jun 2024 03:56:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1718762199; bh=nHsGLW8GfPy3o0jGPVPfIiefV/CNyKl3AuOnq1B+icY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FgxBKvM263fczVR66VWLB41zsHGm5oJGNBWsm5LwbXhq9lghY5SrOk3J0XB4BDW3g 3FfLU0bxhmCKN/Xh0OK6glj8mlGiy5luxRvE6UPpMPg7Ia/hV8/jExEtFtQcS6WXRM sgWF2S+PnxzNrBxWQx99466vcJv7DjV9fdRSkIvbcsWfRkYHckvoVxGdxqIisKBHcT HHW1npTFv9sM7Jmenuug5Gz5C1wI8mbHWlrgJfRJfcmrv59C7lWy+XDt4CeEX/VKFv b0Gr+xihw8Vn3Ey7zfwFAAvLNIW+61gjYcpmmyPyA+6Aop42RJHXfRtzfXiBHU8dQ2 6uD7Cb025vnLA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W3mvC1f9Mz4wcp; Wed, 19 Jun 2024 11:56:39 +1000 (AEST) Date: Wed, 19 Jun 2024 11:53:33 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] netlink: With no default route, pick the first interface with a route Message-ID: References: <20240618171803.1924322-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1EiSkWyK3XTJEZsW" Content-Disposition: inline In-Reply-To: <20240618171803.1924322-1-sbrivio@redhat.com> Message-ID-Hash: 5THGJDS573ZX7QP7RIR4V5KBN3FXGXV6 X-Message-ID-Hash: 5THGJDS573ZX7QP7RIR4V5KBN3FXGXV6 X-MailFrom: dgibson@gandalf.ozlabs.org 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: passt-dev@passt.top, Jelle van der Waa , Martin Pitt 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: --1EiSkWyK3XTJEZsW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 18, 2024 at 07:18:03PM +0200, Stefano Brivio wrote: > While commit f919dc7a4b1c ("conf, netlink: Don't require a default > route to start") sounded reasonable in the assumption that, if we > don't find default routes for a given address family, we can still > proceed by selecting an interface with any route *iff it's the only > one for that protocol family*, Jelle reported a further issue in a > similar setup. >=20 > There, multiple interfaces are present, and while remote container > connectivity doesn't matter for the container, local connectivity is > desired. There are no default routes, but those multiple interfaces > all have non-default routes, so we should just pick one and start. >=20 > Pick the first interface reported by the kernel with any route, if > there are no default routes. There should be no harm in doing so. >=20 > Reported-by: Jelle van der Waa > Reported-by: Martin Pitt > Link: https://bugzilla.redhat.com/show_bug.cgi?id=3D2277954 > Signed-off-by: Stefano Brivio Seems reasonable until we can tackle this better. Reviewed-by: David Gibson > --- > netlink.c | 16 ++++++++-------- > passt.1 | 4 ++-- > 2 files changed, 10 insertions(+), 10 deletions(-) >=20 > diff --git a/netlink.c b/netlink.c > index 0be4ea3..3aed7e5 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -269,8 +269,7 @@ unsigned int nl_get_ext_if(int s, sa_family_t af) > size_t na; > =20 > /* Look for an interface with a default route first, failing that, look > - * for any interface with a route, and pick it only if it's the only > - * interface with a route. > + * for any interface with a route, and pick the first one, if any. > */ > seq =3D nl_send(s, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req)); > nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWROUTE) { > @@ -324,18 +323,19 @@ unsigned int nl_get_ext_if(int s, sa_family_t af) > warn("netlink: RTM_GETROUTE failed: %s", strerror(-status)); > =20 > if (defifi) { > - if (ndef > 1) > + if (ndef > 1) { > info("Multiple default %s routes, picked first", > af_name(af)); > + } > return defifi; > } > =20 > if (anyifi) { > - if (nany =3D=3D 1) > - return anyifi; > - > - info("Multiple interfaces with %s routes, use -i to select one", > - af_name(af)); > + if (nany > 1) { > + info("Multiple interfaces with %s routes, picked first", > + af_name(af)); > + } > + return anyifi; > } > =20 > if (!nany) > diff --git a/passt.1 b/passt.1 > index 6dfa670..6ee1e2e 100644 > --- a/passt.1 > +++ b/passt.1 > @@ -152,8 +152,8 @@ This option can be specified zero (for defaults) to t= wo times (once for IPv4, > once for IPv6). > By default, assigned IPv4 and IPv6 addresses are taken from the host int= erfaces > with the first default route, if any, for the corresponding IP version. = If no > -default routes are available and there is just one interface with any ro= ute, > -that interface will be chosen instead. > +default routes are available and there is any interface with any route f= or a > +given IP version, the first of these interfaces will be chosen instead. > =20 > .TP > .BR \-n ", " \-\-netmask " " \fImask --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --1EiSkWyK3XTJEZsW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZyOhwACgkQzQJF27ox 2GfERA//RtGiWIm+pZgbJ3FJr7AxH+xTixRh65m7jRkRhmtR3d6t0OHzuYP/ECKo AQ56OGC1VQA/BG4VEEEoW3wz+OfPubkO5BkBf3O/rrCVGNoN750feJiYOUYGgphg aVl1+EK0FNtp6FLTh2gaXHb/gdPkHBLPYSfo7wvFj+SVHuCKXqjueq2toRCIaLPG mcpxlvMk9mD0Qgv5/KP61V/+vGpCtObO+Fve75cuh/3i1Xn808sHgOJI1rxZ1CuM SMSbx99SuiZWexb1Fo4G5H6/HlM2ex1RmPJdsH3N1GujqyKXvSOHXEBrYJ3gnkBm dYColFgeV2TxYA+oUpotnbEewflSgn+g43DaSrg66pZmNgXsDwa66jmkpOOLV/I1 rUmid5FHF22HSMJ5JoFqYcquerGW4UBUf25kZMnzNDfbDsBjdzrP0HQAszdTjz82 Qefm3vRnQhBgLXhalOseZ/N/kpIm32zTAEAPUk+RB34JK2qNgolOrh8x8rNztuxc ehdBHRELre/YbJ55V85USqw/T0fZnwvqp08UJqZIKs2gd4Kr4YGTspeE0I+mrY1L ZjRaEPnqM7HT5O+yTsje1ePhTu5woAR08FzfcilcsfX0RMYxPtNqNhezUnrddOe2 b5qSXv/JXMbYrK2YO/kM1Yrx2t1CdL3/oVLsrKcPbWUnvJ/sLTE= =UVdF -----END PGP SIGNATURE----- --1EiSkWyK3XTJEZsW--