From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O29taXDp; dkim-atps=neutral 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 587755A0262 for ; Wed, 04 Mar 2026 19:46:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772650007; 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=Uc4HoFs5pc9tSmZPED8quz4S7sAKBj8SPrAwZIBKmVU=; b=O29taXDp63+EyVmxRZRquY/ajmhJ98S3acHO+PVRmriAYrDhl7JzUPP3BUkXzLe5m/k5Up U1YS/t6irMFPr4gURg8l1jedt3GKSKTsld1InDs1q8kShm9jZFG6Td63dcQ44a1j7VZnBq du5v/oCkM0Kqa1dgQdsblwLOmSHxtuQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-eUjEnAGzOzqrxCQjiJp3Wg-1; Wed, 04 Mar 2026 13:46:46 -0500 X-MC-Unique: eUjEnAGzOzqrxCQjiJp3Wg-1 X-Mimecast-MFC-AGG-ID: eUjEnAGzOzqrxCQjiJp3Wg_1772650005 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4836ff58111so73613255e9.1 for ; Wed, 04 Mar 2026 10:46:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772650005; x=1773254805; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Uc4HoFs5pc9tSmZPED8quz4S7sAKBj8SPrAwZIBKmVU=; b=ghfvQqi0Wzf/Q7yq/Tw2bgM/l6XFv51X78VcJ14Mo95xoJPZh+gJYfFhmzhF3SSON/ j2RFcMvOa6et7vfw1+5nt21M0fpASeInZ0jdijTUx2PHkI3AJDiqzW2K2zr3tPdFDnms oKGRJEUO0KvsnnTLJrtP3o9E1SATxp4/8i4bBNYjhgVEfyDIqjrS8zcHnjs4SBP2uphT VxwO/6P3fQOiWZvj6I69QXXBeSCvzwA2FekrhuHQcnuYqF0rbvAjoWIurrY6ZYmfN+DH iFjB/+ViI/1mXz9PviMWt7TsLuSOP54y/llMqFs0Ge//k4aRpNW/I46Cs+uCQ258Zqkz KAjw== X-Forwarded-Encrypted: i=1; AJvYcCWmqbRbYYuIEIUw/d68iSaLjxyt+m6bJqSSnJkhRv1+ph3his5QJTC+l0uuVri2cgHdJvWhL7BVQUU=@passt.top X-Gm-Message-State: AOJu0Ywgvz6zcoPdV8MaTftNW84ttpKMZbeT+iDGCNjH7bu2PkeHL5Dl htRF/+PXS9b67YnVk6NrCHFF3G/nr8kZaM5lphzX2MPL8Id3PI0Zr7YzgN5b94kEHIJtNx6nKML KKeHINz2uToq7fDdkiMMLc4pvj4GJBRrkI6bJXKksO48fD73pQTQmiQ== X-Gm-Gg: ATEYQzw9y/r1lPOK2UiZHXSOkmdSfp+tsoCRR9xQVom344pfEs3JibVmQs/AQBdYRJ9 oL0J9onHhqvs+ZdUvn3drjaBG2ha1jAzY9OLiOf9pen5MSmU+NzUYtalrJXOu4Kt+qprV7+3qNM 5jKTol432iSqk2VYr6KEw520caTYYujhqDJI3LM3QDpMVbCAW22En+6XBwevMUIDViQ8JZvXoZ0 iAh3EbZeV18IQPOj3LrVWzBEwNlRgubFTaUezebdjB3oVLwC/DWHXAzDY/vmyN8l/cxfEvahUc6 As835ROLCr5ytrkBZpTsyijstBrt4LdtHAQns+02dGTbTWUGY4ZRu4dBKxp1nKzl65bEZYr9Bqm 2X7cVAQuDhVtIfZN5OwxSTyY547wAdGcI X-Received: by 2002:a05:600c:621b:b0:476:4efc:8ed4 with SMTP id 5b1f17b1804b1-48519854b2emr52469055e9.11.1772650004687; Wed, 04 Mar 2026 10:46:44 -0800 (PST) X-Received: by 2002:a05:600c:621b:b0:476:4efc:8ed4 with SMTP id 5b1f17b1804b1-48519854b2emr52468535e9.11.1772650004222; Wed, 04 Mar 2026 10:46:44 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4851887fd5asm71223285e9.11.2026.03.04.10.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 10:46:43 -0800 (PST) From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH] netlink: Return prefix length for IPv6 addresses in nl_addr_get() Message-ID: <20260304194642.4de751f3@elisabeth> In-Reply-To: <20260303191641.768523-1-jmaloy@redhat.com> References: <20260303191641.768523-1-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Wed, 04 Mar 2026 19:46:43 +0100 (CET) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Ngq-jFzFLEM1UYzrpGLXlt_p2h9rmjgduyDK1TX9PMs_1772650005 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: WA7XQ7JOGLQETB6DEU7HIVNHVWH257QR X-Message-ID-Hash: WA7XQ7JOGLQETB6DEU7HIVNHVWH257QR X-MailFrom: sbrivio@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 Tue, 3 Mar 2026 14:16:41 -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). > > Fix by assigning *prefix_len even in the IPv6 case. > > Signed-off-by: Jon Maloy > Reviewed-by: David Gibson > --- > netlink.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/netlink.c b/netlink.c > index 82a2f0c..769cb23 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 > @@ -797,7 +797,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af, > ifa->ifa_prefixlen > prefix_max) { > memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); > > - prefix_max = ifa->ifa_prefixlen; > + prefix_max = *prefix_len = ifa->ifa_prefixlen; Sorry, I spotted this just now and not in the original series, because I hadn't really looked at the context there. The main reason why there are two separate blocks for IPv4 and IPv6, here, is the *prefix_len assignment. Now that this becomes the same for IPv6, that doesn't hold anymore, so, instead of: if (af == AF_INET && ifa->ifa_prefixlen > prefix_max) { memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); prefix_max = *prefix_len = ifa->ifa_prefixlen; } else if (af == AF_INET6 && addr && ifa->ifa_scope < RT_SCOPE_LINK && ifa->ifa_prefixlen > prefix_max) { memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); prefix_max = *prefix_len = ifa->ifa_prefixlen; } you could simplify all that to: if (ifa->ifa_prefixlen > prefix_max && (af == AF_INET || ifa->ifa_scope < RT_SCOPE_LINK)) { memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); prefix_max = *prefix_len = ifa->ifa_prefixlen; } and save 5 lines out of 11. I haven't checked the possible meanings of ifa_scope for IPv4 by the way, maybe that part of the condition could go away as well. -- Stefano