From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=ePerEMkR; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 4067F5A026E for ; Mon, 09 Mar 2026 10:47:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773049675; bh=FFQp8oQO0bBeeiCABcU0Pp7AyM+EPbSU7yj8riTMUYg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ePerEMkR1JiyVWr5nxs2F9BVE0n/vIB2RnMFoOrEGeUmmRvcmzIZWny+WiZYXkwCk yAuaJgDBg7sexiCZfQd59SqC2fj+Gr6ISBQgID0v0LE+xZdKXkgKvt05D9Z9DMKp0g fDPq3GE+q+TeFRBlYnTo3TOQiRENF7GQ3pIiESAEJGWaeO4BfEAOMRBBo6T89ISaeh TRrjSH+ATNmnFefWI5nS4ak+u72vASALNf47+j4k5FjIt4I8lYlgggAFNAFb7BFFFJ Mp7alT6J7m5BEMjOrLWiqkfT+k7N6zLyN3W5m3xSw8szYU/3OPSadOWeqLDD1vDPOt rDh7qIZKq0oGw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fTsd7163Zz4wR8; Mon, 09 Mar 2026 20:47:55 +1100 (AEDT) Date: Mon, 9 Mar 2026 20:47:51 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3] netlink: Return prefix length for IPv6 addresses in nl_addr_get() Message-ID: References: <20260307184157.1675234-1-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zpfm6BVJt+/hecTD" Content-Disposition: inline In-Reply-To: <20260307184157.1675234-1-jmaloy@redhat.com> Message-ID-Hash: ROOTIORZ5EBE4DJ3SF3QRNRA7AAFANV4 X-Message-ID-Hash: ROOTIORZ5EBE4DJ3SF3QRNRA7AAFANV4 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: sbrivio@redhat.com, dgibson@redhat.com, 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: --zpfm6BVJt+/hecTD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 07, 2026 at 01:41:57PM -0500, Jon Maloy wrote: > nl_addr_get() was not setting the prefix_len output parameter for > IPv6 addresses, only for IPv4. This meant callers always got 0 for > IPv6, forcing them to use a hardcoded default (64). >=20 > Fix by assigning *prefix_len even in the IPv6 case. >=20 > We also add another functional change. We now check for if an AF_INET > address is link local, in which case we have to skip it. Although it > is conventional to set the scope of such addresses to RT_SCOPE_LINK, > this is not stated in any RFC, and we cannot trust it to have been set > correctly by the user, just as we cannot trust it to have been set > correctly for any other AF_INET address. We therefore add this check > explicitly on the address itself. >=20 > Signed-off-by: Jon Maloy >=20 > --- > v2: - Simplified according to feedback from S. Brivio > - Added test for AF_INET link local property > v3: - Corrected claim about convention for IPv4 link local address > scope in commit log. > --- > netlink.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) >=20 > diff --git a/netlink.c b/netlink.c > index 82a2f0c..f0e8fa7 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -752,7 +752,7 @@ int nl_addr_set_ll_nodad(int s, unsigned int ifi) > * @ifi: Interface index in outer network namespace > * @af: Address family > * @addr: Global address to fill > - * @prefix_len: Mask or prefix length, to fill (for IPv4) > + * @prefix_len: Mask or prefix length, to fill > * @addr_l: Link-scoped address to fill (for IPv6) > * > * Return: 0 on success, negative error code on failure > @@ -777,6 +777,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t = af, > nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWADDR) { > struct ifaddrmsg *ifa =3D (struct ifaddrmsg *)NLMSG_DATA(nh); > struct rtattr *rta; > + bool link_local; > size_t na; > =20 > if (ifa->ifa_index !=3D ifi || ifa->ifa_flags & IFA_F_DEPRECATED) > @@ -788,18 +789,14 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_= t af, > (af =3D=3D AF_INET6 && rta->rta_type !=3D IFA_ADDRESS)) > continue; > =20 > - if (af =3D=3D AF_INET && ifa->ifa_prefixlen > prefix_max) { > - memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); > + link_local =3D (af =3D=3D AF_INET6) ? > + ifa->ifa_scope >=3D RT_SCOPE_LINK : > + IN4_IS_ADDR_LINKLOCAL(RTA_DATA(rta)); Is ifa->ifa_scope not populatedcorrectly for IPv4 link local addresses? > =20 > - prefix_max =3D *prefix_len =3D ifa->ifa_prefixlen; > - } else if (af =3D=3D AF_INET6 && addr && > - ifa->ifa_scope < RT_SCOPE_LINK && > - ifa->ifa_prefixlen > prefix_max) { > + if (ifa->ifa_prefixlen > prefix_max && !link_local) { > memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); > - > - prefix_max =3D ifa->ifa_prefixlen; > + prefix_max =3D *prefix_len =3D ifa->ifa_prefixlen; > } > - > if (addr_l && > af =3D=3D AF_INET6 && ifa->ifa_scope =3D=3D RT_SCOPE_LINK && > ifa->ifa_prefixlen > prefix_max_ll) { > --=20 > 2.52.0 >=20 --=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 --zpfm6BVJt+/hecTD Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmul0YACgkQzQJF27ox 2Ge+AQ//eaY1SbOlbBD4DRlHRDMI/fx5yH7/6gMyNg4+xj+C4xsRhDHLSnOsDUWs uJrXpVAONZBcnigjL6lcuJoEz9eAS5N/eS9aqlQyPYio7tOxV4mnsCC46MOAV/j1 rI058cOzV/OCFBFAYFF2fCQf/C8iCwLiEp8iI1W86sYGfxHdgsqTrTldDyL5l/uA pOQby2A8GC4zYXT8lEaFtmFlG4YfukCIl5oUCL5dhx86p7oQDIrRF9HtHEEyYKrZ N+kZdeIWKm/ssic4wgFKe+XAfKlO8/GEYMRdv0YwSOI6dTJplYPkSR6n9VUJlsFZ X72WDsb/Wcwvud8QSPmEZFRYYRO9JbIXQQsPcxrOkAyc0UixWmC6fudofYUjDTyc uS9A64LlkelmAdCAWDu2oaR0Rn9iimMXCgE09OgdAYOnDQtD3TB1pffhpWDoSoAy P2andg/lXpx0BQ3j9BmdZZCyuAvAmcs0BKQDtyZm15fVKM0S4ocL7Y7ANZYsD2Wh lGHN+a5OR/bRWveHvOH4dSI0Vjm+b5enVlVpgsoHh2MFc/0WKfnwrN8vKoSXjCzn bLgPVHiy5CzkJnQy/BkrDvn6BB3H3mdO2jjCS/H0NCaVttJZlS/hNogtbEu3CdyB vO1d32Fmd88siVzfuMrehgMP9gZq1KjkvDUVfo2RyHhvBuJbLPo= =/XTJ -----END PGP SIGNATURE----- --zpfm6BVJt+/hecTD--