* [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses
@ 2026-01-04 3:23 Yumei Huang
2026-01-05 21:56 ` Justin Iurman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yumei Huang @ 2026-01-04 3:23 UTC (permalink / raw)
To: netdev, linux-kernel, linux-kselftest
Cc: sbrivio, david, yuhuang, davem, dsahern, edumazet, kuba, pabeni,
horms, justin.iurman, shuah
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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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 >= 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=175
Suggested-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Yumei Huang <yuhuang@redhat.com>
---
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 inet6_ifaddr *ifp)
list_for_each(p, &idev->addr_list) {
struct inet6_ifaddr *ifa
= list_entry(p, struct inet6_ifaddr, if_list);
- if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr))
+ if (ifp_scope > ipv6_addr_src_scope(&ifa->addr))
break;
}
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/null
- ip -netns $ioam_node_alpha addr add 2001:db8:1::50/64 dev veth0 &>/dev/null
ip -netns $ioam_node_alpha addr add 2001:db8:1::2/64 dev veth0 &>/dev/null
+ ip -netns $ioam_node_alpha addr add 2001:db8:1::50/64 dev veth0 &>/dev/null
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 \
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses
2026-01-04 3:23 [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses Yumei Huang
@ 2026-01-05 21:56 ` Justin Iurman
2026-01-06 17:37 ` David Ahern
2026-01-07 1:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Justin Iurman @ 2026-01-05 21:56 UTC (permalink / raw)
To: Yumei Huang, netdev, linux-kernel, linux-kselftest
Cc: sbrivio, david, davem, dsahern, edumazet, kuba, pabeni, horms,
shuah
On 1/4/26 04:23, Yumei Huang wrote:
> 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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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 >= 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=175
> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> Signed-off-by: Yumei Huang <yuhuang@redhat.com>
> ---
> 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 inet6_ifaddr *ifp)
> list_for_each(p, &idev->addr_list) {
> struct inet6_ifaddr *ifa
> = list_entry(p, struct inet6_ifaddr, if_list);
> - if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr))
> + if (ifp_scope > ipv6_addr_src_scope(&ifa->addr))
> break;
> }
>
> 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/null
>
> - ip -netns $ioam_node_alpha addr add 2001:db8:1::50/64 dev veth0 &>/dev/null
> ip -netns $ioam_node_alpha addr add 2001:db8:1::2/64 dev veth0 &>/dev/null
> + ip -netns $ioam_node_alpha addr add 2001:db8:1::50/64 dev veth0 &>/dev/null
> 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 \
For tools/testing/selftests/net/ioam6.sh:
Acked-by: Justin Iurman <justin.iurman@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses
2026-01-04 3:23 [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses Yumei Huang
2026-01-05 21:56 ` Justin Iurman
@ 2026-01-06 17:37 ` David Ahern
2026-01-07 1:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2026-01-06 17:37 UTC (permalink / raw)
To: Yumei Huang, netdev, linux-kernel, linux-kselftest
Cc: sbrivio, david, davem, edumazet, kuba, pabeni, horms,
justin.iurman, shuah
On 1/3/26 8:23 PM, Yumei Huang wrote:
> 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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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 >= 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=175
> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> Signed-off-by: Yumei Huang <yuhuang@redhat.com>
> ---
> net/ipv6/addrconf.c | 2 +-
> tools/testing/selftests/net/ioam6.sh | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
>
I am ok with the change, but I will not be surprised if someone
complains about a change in behavior.
Reviewed-by: David Ahern <dsahern@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses
2026-01-04 3:23 [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses Yumei Huang
2026-01-05 21:56 ` Justin Iurman
2026-01-06 17:37 ` David Ahern
@ 2026-01-07 1:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-07 1:00 UTC (permalink / raw)
To: Yumei Huang
Cc: netdev, linux-kernel, linux-kselftest, sbrivio, david, davem,
dsahern, edumazet, kuba, pabeni, horms, justin.iurman, shuah
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 4 Jan 2026 11:23:57 +0800 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [net-next,v2] ipv6: preserve insertion order for same-scope addresses
https://git.kernel.org/netdev/net-next/c/cb3de96eea66
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-07 1:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-04 3:23 [PATCH net-next v2] ipv6: preserve insertion order for same-scope addresses Yumei Huang
2026-01-05 21:56 ` Justin Iurman
2026-01-06 17:37 ` David Ahern
2026-01-07 1:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox