From nobody Sat Feb 7 17:09:45 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B7C3243958 for ; Sun, 4 Jan 2026 03:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767497058; cv=none; b=WmsebcFIzI7VjNVL8gLDkjNKfIgb54+KvqAJT1i2EvC5IntZNkE0I46ahCBMsy1PY0S3vtXVn1Y5nbOuf4TYrl59iIB5AkmJ/tSEUEObY30RQ3CU/hoGb4h1mKIbXxhcHl1dAQgvxb9fylScwc4qgMge/xJDvnZWMLIJCLJnOg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767497058; c=relaxed/simple; bh=/lEI3/+J/BPnZOVKSfEgPgwaAZ3096zvgLIqg+pqJh8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kBlWcF6Zj5HdFBbiXHGL62Rc6w6yYK9DJq+YG5SOx9zuThU3qnUPAW+tnKnLqHca6SahpoYb8h/jgyum2NnzbmU5xvwCQCP234cjSH3ULFtC2ccp/8fWLYX6qMhC93BKqBN+nxcwThP29UIFxFS6exuLno74WSh7aH0zfJ1zEus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fUBqoj4O; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fUBqoj4O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767497054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ii8w9Sk0VGXA6EfYewOe7fg/XK65AlKb5PXLcHLgJRs=; b=fUBqoj4OL6vGjlL6jPhmHkGBQoHYnBIkM8bNfGYx8f9HbUmeLbtOr4QICPxPpyzYAS0MZq JDC+tPCy0OOLfTKpbOuTj04FHpm49PSGDo0bB+c6S3cF5jmvYqrrTDLz6pW2ndtwJOq9SQ WWezm22+UgsS4ne+W1WEzeAqb198o28= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-168-xbALdIZ0PR-HKjuLWFJAQg-1; Sat, 03 Jan 2026 22:24:11 -0500 X-MC-Unique: xbALdIZ0PR-HKjuLWFJAQg-1 X-Mimecast-MFC-AGG-ID: xbALdIZ0PR-HKjuLWFJAQg_1767497049 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D621C18002ED; Sun, 4 Jan 2026 03:24:08 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.116.49]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2BF2A19560AB; Sun, 4 Jan 2026 03:24:00 +0000 (UTC) From: Yumei Huang To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: sbrivio@redhat.com, david@gibson.dropbear.id.au, yuhuang@redhat.com, davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, justin.iurman@uliege.be, shuah@kernel.org Subject: [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses Date: Sun, 4 Jan 2026 11:23:57 +0800 Message-ID: <20260104032357.38555-1-yuhuang@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" IPv6 addresses with the same scope are returned in reverse insertion order, unlike IPv4. For example, when adding a -> b -> c, the list is reported as c -> b -> a, while IPv4 preserves the original order. This behavior causes: a. When using `ip -6 a save` and `ip -6 a restore`, addresses are restored in the opposite order from which they were saved. See example below showing addresses added as 1::1, 1::2, 1::3 but displayed and saved in reverse order. # ip -6 a a 1::1 dev x # ip -6 a a 1::2 dev x # ip -6 a a 1::3 dev x # ip -6 a s dev x 2: x: mtu 1500 qdisc noop state DOWN group default= qlen 1000 inet6 1::3/128 scope global tentative valid_lft forever preferred_lft forever inet6 1::2/128 scope global tentative valid_lft forever preferred_lft forever inet6 1::1/128 scope global tentative valid_lft forever preferred_lft forever # ip -6 a save > dump # ip -6 a d 1::1 dev x # ip -6 a d 1::2 dev x # ip -6 a d 1::3 dev x # ip a d ::1 dev lo # ip a restore < dump # ip -6 a s dev x 2: x: mtu 1500 qdisc noop state DOWN group default= qlen 1000 inet6 1::1/128 scope global tentative valid_lft forever preferred_lft forever inet6 1::2/128 scope global tentative valid_lft forever preferred_lft forever inet6 1::3/128 scope global tentative valid_lft forever preferred_lft forever # ip a showdump < dump if1: inet6 ::1/128 scope host proto kernel_lo valid_lft forever preferred_lft forever if2: inet6 1::3/128 scope global tentative valid_lft forever preferred_lft forever if2: inet6 1::2/128 scope global tentative valid_lft forever preferred_lft forever if2: inet6 1::1/128 scope global tentative valid_lft forever preferred_lft forever b. Addresses in pasta to appear in reversed order compared to host addresses. The ipv6 addresses were added in reverse order by commit e55ffac60117 ("[IPV6]: order addresses by scope"), then it was changed by commit 502a2ffd7376 ("ipv6: convert idev_list to list macros"), and restored by commit b54c9b98bbfb ("ipv6: Preserve pervious behavior in ipv6_link_dev_addr()."). However, this reverse ordering within the same scope causes inconsistency with IPv4 and the issues described above. This patch aligns IPv6 address ordering with IPv4 for consistency by changing the comparison from >=3D to > when inserting addresses into the address list. Also updates the ioam6 selftest to reflect the new address ordering behavior. Combine these two changes into one patch for bisectability. Fixes: e55ffac60117 ("[IPV6]: order addresses by scope") Link: https://bugs.passt.top/show_bug.cgi?id=3D175 Suggested-by: Stefano Brivio Signed-off-by: Yumei Huang Acked-by: Justin Iurman Reviewed-by: David Ahern --- net/ipv6/addrconf.c | 2 +- tools/testing/selftests/net/ioam6.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 40e9c336f6c5..ca998bf46863 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1013,7 +1013,7 @@ ipv6_link_dev_addr(struct inet6_dev *idev, struct ine= t6_ifaddr *ifp) list_for_each(p, &idev->addr_list) { struct inet6_ifaddr *ifa =3D list_entry(p, struct inet6_ifaddr, if_list); - if (ifp_scope >=3D ipv6_addr_src_scope(&ifa->addr)) + if (ifp_scope > ipv6_addr_src_scope(&ifa->addr)) break; } =20 diff --git a/tools/testing/selftests/net/ioam6.sh b/tools/testing/selftests= /net/ioam6.sh index 845c26dd01a9..b2b99889942f 100755 --- a/tools/testing/selftests/net/ioam6.sh +++ b/tools/testing/selftests/net/ioam6.sh @@ -273,8 +273,8 @@ setup() ip -netns $ioam_node_beta link set ioam-veth-betaR name veth1 &>/dev/null ip -netns $ioam_node_gamma link set ioam-veth-gamma name veth0 &>/dev/nu= ll =20 - ip -netns $ioam_node_alpha addr add 2001:db8:1::50/64 dev veth0 &>/dev/n= ull ip -netns $ioam_node_alpha addr add 2001:db8:1::2/64 dev veth0 &>/dev/nu= ll + ip -netns $ioam_node_alpha addr add 2001:db8:1::50/64 dev veth0 &>/dev/n= ull ip -netns $ioam_node_alpha link set veth0 up &>/dev/null ip -netns $ioam_node_alpha link set lo up &>/dev/null ip -netns $ioam_node_alpha route add 2001:db8:2::/64 \ --=20 2.52.0