Skip to contentSkip to conversation

ipv6: use the right ifindex when replying to icmpv6 from localhost

PATCH Applied Fernando Fernandez Mancera 3 participants 5 messages Jan 21 – Jan 25

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 ipv6: use the right ifindex when replying to icmpv6 from localhost

When replying to a ICMPv6 echo request that comes from localhost address the right output ifindex is 1 (lo) and not rt6i_idev dev index. Use the skb device ifindex instead. This fixes pinging to a local address from localhost source address.

$ ping6 -I ::1 2001:1:1::2 -c 3
PING 2001:1:1::2 (2001:1:1::2) from ::1 : 56 data bytes
64 bytes from 2001:1:1::2: icmp_seq=1 ttl=64 time=0.037 ms
64 bytes from 2001:1:1::2: icmp_seq=2 ttl=64 time=0.069 ms
64 bytes from 2001:1:1::2: icmp_seq=3 ttl=64 time=0.122 ms

2001:1:1::2 ping statistics
3 packets transmitted, 3 received, 0% packet loss, time 2032ms rtt min/avg/max/mdev = 0.037/0.076/0.122/0.035 ms

Fixes 1b70d792cf67 ("ipv6: Use rt6i_idev index for echo replies to a local address")

---
v2: no changes
v3: use ipv6_addr_loopback() as it is more efficient

---
 net/ipv6/icmp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/icmp.c +3 -1
index c72270582d9c..1a25ecb92695 100644
@@ -966,7 +966,9 @@ static enum skb_drop_reason icmpv6_echo_reply(struct sk_buff *skb)
 	fl6.daddr = ipv6_hdr(skb)->saddr;
 	if (saddr)
 		fl6.saddr = *saddr;
-	fl6.flowi6_oif = icmp6_iif(skb);
+	fl6.flowi6_oif = ipv6_addr_loopback(&fl6.daddr) ?
+			 skb->dev->ifindex :
+			 icmp6_iif(skb);
 	fl6.fl6_icmp_type = type;
 	fl6.flowi6_mark = mark;
 	fl6.flowi6_uid = sock_net_uid(net, NULL);
Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 2/2 selftests: net: add ipv6 ping to local address from localhost

Test ipv6 pinging to local configured address and linklocal address from localhost with -I ::1.

---
v2: shellcheck fixes, added VRF based tests and simplified linklocal address parsing
v3: extend existing test in fcnal-test.sh instead of creating a new one, notice some shellcheck warnings but I prefer to follow the style of the existing code. It can be fixed if it is a requirement.

---
 tools/testing/selftests/net/fcnal-test.sh | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/net/fcnal-test.sh +7 -0
index 844a580ae74e..890c3f8e51bb 100755
@@ -2327,6 +2327,13 @@ ipv6_ping_novrf()
 		log_test_addr ${a} $? 2 "ping local, device bind"
 	done
 
+	for a in ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSA_DEV} ${NSA_IP6}
+	do
+		log_start
+		run_cmd ${ping6} -c1 -w1 -I ::1 ${a}
+		log_test_addr ${a} $? 0 "ping local, from localhost"
+	done
+
 	#
 	# ip rule blocks address
 	#
Signature · 1 line
2.52.0
maintainer Reviewed-by on v3 2/2
#2 lore raw

Re: [PATCH 2/2 net-next v3] selftests: net: add ipv6 ping to local address from localhost

Quoted 22 lines · Fernando Fernandez Mancera

Test ipv6 pinging to local configured address and linklocal address from localhost with -I ::1.

---
v2: shellcheck fixes, added VRF based tests and simplified linklocal address parsing
v3: extend existing test in fcnal-test.sh instead of creating a new one, notice some shellcheck warnings but I prefer to follow the style of the existing code. It can be fixed if it is a requirement.

---
 tools/testing/selftests/net/fcnal-test.sh | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/net/fcnal-test.sh +0 -0
index 844a580ae74e..890c3f8e51bb 100755
@@ -2327,6 +2327,13 @@ ipv6_ping_novrf()
 		log_test_addr ${a} $? 2 "ping local, device bind"
 	done
 

tools/testing/selftests/net/fcnal-test.sh ipv6_ping_novrf() · line 2339

Quoted 10 lines
tools/testing/selftests/net/fcnal-test.sh +7 -0
+	for a in ${NSA_LO_IP6} ${NSA_LINKIP6}%${NSA_DEV} ${NSA_IP6}
+	do
+		log_start
+		run_cmd ${ping6} -c1 -w1 -I ::1 ${a}
+		log_test_addr ${a} $? 0 "ping local, from localhost"
+	done
+
 	#
 	# ip rule blocks address
 	#
maintainer Reviewed-by on v3 1/2
#3 lore raw
In reply to Fernando Fernandez Mancera
Quoted 15 lines · Fernando Fernandez Mancera

When replying to a ICMPv6 echo request that comes from localhost address the right output ifindex is 1 (lo) and not rt6i_idev dev index. Use the skb device ifindex instead. This fixes pinging to a local address from localhost source address.

$ ping6 -I ::1 2001:1:1::2 -c 3
PING 2001:1:1::2 (2001:1:1::2) from ::1 : 56 data bytes
64 bytes from 2001:1:1::2: icmp_seq=1 ttl=64 time=0.037 ms
64 bytes from 2001:1:1::2: icmp_seq=2 ttl=64 time=0.069 ms
64 bytes from 2001:1:1::2: icmp_seq=3 ttl=64 time=0.122 ms

2001:1:1::2 ping statistics
3 packets transmitted, 3 received, 0% packet loss, time 2032ms rtt min/avg/max/mdev = 0.037/0.076/0.122/0.035 ms

Quoted 9 lines
Fixes 1b70d792cf67 ("ipv6: Use rt6i_idev index for echo replies to a local address")

---
v2: no changes
v3: use ipv6_addr_loopback() as it is more efficient

---
 net/ipv6/icmp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
#4 lore raw
In reply to Fernando Fernandez Mancera
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 5 lines · On Wed, 21 Jan 2026 20:44:08 +0100 you wrote:

When replying to a ICMPv6 echo request that comes from localhost address the right output ifindex is 1 (lo) and not rt6i_idev dev index. Use the skb device ifindex instead. This fixes pinging to a local address from localhost source address.

Quoted 7 lines
$ ping6 -I ::1 2001:1:1::2 -c 3
PING 2001:1:1::2 (2001:1:1::2) from ::1 : 56 data bytes
64 bytes from 2001:1:1::2: icmp_seq=1 ttl=64 time=0.037 ms
64 bytes from 2001:1:1::2: icmp_seq=2 ttl=64 time=0.069 ms
64 bytes from 2001:1:1::2: icmp_seq=3 ttl=64 time=0.122 ms

[...]

Here is the summary with links:
- [1/2,net-next,v3] ipv6: use the right ifindex when replying to icmpv6 from localhost

    https://git.kernel.org/netdev/net/c/03cbcdf93866
  - [2/2,net-next,v3] selftests: net: add ipv6 ping to local address from localhost
    https://git.kernel.org/netdev/net/c/1742272bd3fa

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html