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=GXCpGXh0; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 277175A0262 for ; Tue, 10 Mar 2026 02:31:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773106278; bh=dw+vDcFsNt/VnLPdtybe/mRe1wLUq787PFJrPTIpW4o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GXCpGXh0VQKqqcoihAIxMcQ4KbN0+AnGubRKQA60r9g4R1kZPyDGjy3FwfZzZcrIi za4VXyIFPhJHHTZUxdbpbKfS3PlrI6gNKvWfCGYq4nv8tHzLeVZZTjAlJCZHvJ9P60 Dcsak2BYH/NS7JnD1fiztCrckCuchpPotDrCXG3mr1O4er1+lZ/IeedQjRrapp/9pV 3mrF5JwD0lmQBs4F9xrMuzQrZkM+lbB71lFr9aIfk2MOhJ5JoEYUUGCScu//ZwLtoC RS+FOV7q6L7iD32FF7TdEODHTHZL/mpF4sjYLiJH27z3L8ri/B2FDYAeiJfGGUxY8p QT5rs4LwCrx7g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fVGYf2pynz4wDK; Tue, 10 Mar 2026 12:31:18 +1100 (AEDT) Date: Tue, 10 Mar 2026 12:24:00 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v4] netlink: Return prefix length for IPv6 addresses in nl_addr_get() Message-ID: References: <20260309195233.2162459-1-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="8nVaV1mvnKhWsTaz" Content-Disposition: inline In-Reply-To: <20260309195233.2162459-1-jmaloy@redhat.com> Message-ID-Hash: FMOL3HG2URSMWO5FEMCFAOGAD56E2TLP X-Message-ID-Hash: FMOL3HG2URSMWO5FEMCFAOGAD56E2TLP 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: --8nVaV1mvnKhWsTaz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 09, 2026 at 03:52:33PM -0400, 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 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson As discussed on the last call there are some good questions about exactly what semantics we want here, but I think keeping the existing ones for now is the right call. >=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. > v4: - Reverted from the IPv4 link local exclusion change > --- > netlink.c | 11 +++-------- > 1 file changed, 3 insertions(+), 8 deletions(-) >=20 > diff --git a/netlink.c b/netlink.c > index 82a2f0c..ee9a6b1 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 > @@ -788,16 +788,11 @@ 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) { > + if (ifa->ifa_prefixlen > prefix_max && > + (af =3D=3D AF_INET || ifa->ifa_scope < RT_SCOPE_LINK)) { > memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); > =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) { > - memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); > - > - prefix_max =3D ifa->ifa_prefixlen; > } > =20 > if (addr_l && > --=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 --8nVaV1mvnKhWsTaz Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmvcqsACgkQzQJF27ox 2Gc2Gg/+J2GT6ElHTqOh91tMQoxqkrVFjiDnRnFTJpNxgqwsdiVHkR1giuMu6dOu R7CIEUTeD+aTMzcvkHbOTHzikLVybkm7QZry7klhC+xE5onhfocD+U432cE+HrZr LB/kgHYKC4fZZuYysJV8ezxAtzYW6ug7tSa5H6mg/Xw12B3BEnNPKPdWRG2bOhq0 /9ei+P7s5tQ3QIWjoI4/0qJhfoY1D6g23YzRNYF+tXZUpVDppUwoh/LO1Qpo1l6n MxmNLEe5RrsWeZtHG4mMtQs5SKRZPUmi3wOo8IlbbqLBN9+MrJ3f1fzjGSmJvNnR LCgbly83CnBX8CxpnJnVXzXZHknt02BU+9gtvmo0zZywVW9NPPjXxYj3fwolCbDr 1Cst8iAN7O2BXF/NCKVGh6/iwwDDxc+p298cFZqZowNGumbgytaDSugcvTDMXP/0 71IaYb486fnQVTT8lAEk5iF6N+mHNE5bUyjMm/vtqJ/R8JDrw2pYAFxnkYOfUVfl XjAjLglR7Ps3h7ZNCaG/YXvviFiSAsf/cKcnnrc5FSKweVH2DNGllUAJVnQ80lv0 eWmk7eVUdIdHbXLl/uYe0Y5FyXgdCvgPvzqjfk+eETInW+92C36M6py3oFxj8Xpi xGsQFYC1U1/iVeofu3yIrOXuZhQvMkmCw+iDNu/96pbCdYIQhnQ= =yd7N -----END PGP SIGNATURE----- --8nVaV1mvnKhWsTaz--