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=aDVEq7Ts; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 0EEC95A0262 for ; Mon, 09 Mar 2026 18:58:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773079128; 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=4qPfzYmnHzqfUL5A8l4JWMsleAHZBmCkHK/8UKgvWwE=; b=aDVEq7TsfMXtFkOVerkLrLRrjtTRYef5apXcDmuSbeU3v6C3nfAeT94Zoepe6s+xgY13kk QJspCA7mE49ELIw/CZqVe/fI3XTc/XKchK6tq9quG57IuiPZd9FYfPGGUSbPTOxzb/SDaf YmTWTCd/vqpM3KeZqVT/mraLCBmocTQ= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-281-3g5rbIXZMlSyoYQh4UKOTw-1; Mon, 09 Mar 2026 13:58:46 -0400 X-MC-Unique: 3g5rbIXZMlSyoYQh4UKOTw-1 X-Mimecast-MFC-AGG-ID: 3g5rbIXZMlSyoYQh4UKOTw_1773079126 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cd767c51efso277619085a.2 for ; Mon, 09 Mar 2026 10:58:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773079126; x=1773683926; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4qPfzYmnHzqfUL5A8l4JWMsleAHZBmCkHK/8UKgvWwE=; b=wXGrU5aQDFsFLdLRQYJryqu7Jv63b5w2ty8/0VagJo08M7pte0wRH12+QU40zvJpco H2CAFfuQM1ayB/yQq/BnRSMLxNhvs7RczLtOe+JMsr7ZWxnTaYVogpVdM2UM06/h/5Cl 7kqznrnVVcdWyeKB40hjMgtr3NclQHSa2p9PgS+8szMd0I74mzuXwtqtbtGOpZutMkfh UdzOB4Brzv5TuC83IzUaPpgkC+Ne41A+cVzlP5xe+3vNrwf9F1+3h8adG1ArvBbTgyiv g2KaQL6FtIHlanSUDrzq+yLIaAhIzJKW8CHOiJHiBJ5yK8Srya9VICsKsauKKfUJazfc QY9Q== X-Forwarded-Encrypted: i=1; AJvYcCXjP18nYQx+h7HSgAWIjcIfj3R7T6pkR7f1pv9i+pGrR/FrrqKQbrup+NRDmPEolLjcVTMJrWBiHVI=@passt.top X-Gm-Message-State: AOJu0YxnS4jaadg7EObEV7zsQEXBoGU7VRJu1V/uvjtqFpelhrK1zMT0 bn6KpQPswxOWLlNJY/IKMKu6od5tU4ptDT2ZZs7l58JJJGwVz0M//dAlQruDiOnEyxZTMLpGg03 wwMs/iEVwQba31JAiFswn4K0zWxCtV2A80edhUTgshJx66qCJWoQSAw== X-Gm-Gg: ATEYQzzOXxf9GPsBmlRfDyZC/9drHCPA/dgE7hc+giqkxo+wIwhCjn0RR2se3UOT3vA zrhbPuWddPKxcDsd56nXhYvagtZhid2VdkuT95voKfVvLmIq0ZSO1FOoEFn6QvGrd8KqCybl4Db K/DyAlWyV0S4OM2xtiC91LBVPk3QvdObUIruT4JFg4ufFVtljmSmgOAX3wn/jqFvcuNwuAJ389T yZzsHfU44/FupXGomgsxtGEFUMZZlBM0VX5tF2DFU7YK+FbECKHLKLOK0VPnphHzy7skx5qg+2a l4LP2/3GmBxiLyjQMxfPUQaMIjykit3uoWOpjRfFIPSZDH9zKKe939g7e7HWJw25ifnkzYNguyi wZ98iUeSCnjmG050GptpFD9D4NyzL+s3Zv82lSQt2FNWRKjvSbQGwxefkQsTJbbKrsUtlwRNdq+ LBuSdbOw1577pgEA== X-Received: by 2002:a05:620a:3703:b0:8cb:4fa5:d460 with SMTP id af79cd13be357-8cd6d48d4c4mr1598529585a.74.1773079125656; Mon, 09 Mar 2026 10:58:45 -0700 (PDT) X-Received: by 2002:a05:620a:3703:b0:8cb:4fa5:d460 with SMTP id af79cd13be357-8cd6d48d4c4mr1598526785a.74.1773079125089; Mon, 09 Mar 2026 10:58:45 -0700 (PDT) Received: from [192.168.2.15] (lnsm1-montreal01-69-158-139-121.internet.virginmobile.ca. [69.158.139.121]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cd7e3d00dasm431538185a.45.2026.03.09.10.58.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Mar 2026 10:58:44 -0700 (PDT) Message-ID: <94fdb9a0-48ce-4a92-ac01-2af045432227@redhat.com> Date: Mon, 9 Mar 2026 13:58:42 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] netlink: Return prefix length for IPv6 addresses in nl_addr_get() To: David Gibson References: <20260307184157.1675234-1-jmaloy@redhat.com> From: Jon Maloy In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -cXLyshDjCw2rVaFyjjDVXx497zY_tqm1s4TzHisKp0_1773079126 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: 2CYLCO3UUC735X6AB2MCRY5P6XF5DGTF X-Message-ID-Hash: 2CYLCO3UUC735X6AB2MCRY5P6XF5DGTF 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 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: On 2026-03-09 05:47, David Gibson wrote: > 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). >> >> Fix by assigning *prefix_len even in the IPv6 case. >> >> 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. >> >> Signed-off-by: Jon Maloy >> >> --- >> 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(-) >> >> 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 = (struct ifaddrmsg *)NLMSG_DATA(nh); >> struct rtattr *rta; >> + bool link_local; >> size_t na; >> >> if (ifa->ifa_index != 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 == AF_INET6 && rta->rta_type != IFA_ADDRESS)) >> continue; >> >> - if (af == AF_INET && ifa->ifa_prefixlen > prefix_max) { >> - memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); >> + link_local = (af == AF_INET6) ? >> + ifa->ifa_scope >= RT_SCOPE_LINK : >> + IN4_IS_ADDR_LINKLOCAL(RTA_DATA(rta)); > > > Is ifa->ifa_scope not populatedcorrectly for IPv4 link local addresses? It isn't populated by the kernel, and my conclusion was we cannot trust it is set correctly. Also see my response to Stefano about this. /jon >> >> - prefix_max = *prefix_len = ifa->ifa_prefixlen; >> - } else if (af == 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 = ifa->ifa_prefixlen; >> + prefix_max = *prefix_len = ifa->ifa_prefixlen; >> } >> - >> if (addr_l && >> af == AF_INET6 && ifa->ifa_scope == RT_SCOPE_LINK && >> ifa->ifa_prefixlen > prefix_max_ll) { >> -- >> 2.52.0 >> >