ipv6: use the right ifindex when replying to icmpv6 from localhost
Subsystems (4)
PATCH 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
--- net/ipv6/icmp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/icmp.c +3 -1
@@ -965,7 +965,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_type (&fl6.daddr) &IPV6_ADDR_LOOPBACK ? + 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.51.1
PATCH 2/2 selftests: ipv6_icmp: add tests for ICMPv6 handling
Test ICMPv6 to link local address and local address. In addition, this test set could be extended to cover more situations in the future.
ICMPv6 to local addresses
TEST: Ping to link local address [OK]
TEST: Ping to link local address from ::1 [OK]
TEST: Ping to local address [OK]
TEST: Ping to local address from ::1 [OK]Tests passed: 4 Tests failed: 0
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/ipv6_icmp.sh | 204 +++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100755 tools/testing/selftests/net/ipv6_icmp.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -47,6 +47,7 @@ TEST_PROGS := \ ip_local_port_range.sh \ ipv6_flowlabel.sh \ ipv6_force_forwarding.sh \ + ipv6_icmp.sh \ ipv6_route_update_soft_lockup.sh \ l2_tos_ttl_inherit.sh \ l2tp.sh \
tools/testing/selftests/net/ipv6_icmp.sh new file +204 -0
204 lines not on this page · raw message
Signature · 1 line
2.51.1
David Ahern
maintainerRe: [PATCH 2/2 net-next] selftests: ipv6_icmp: add tests for ICMPv6 handling
Quoted 9 lines · Fernando Fernandez Mancera
Test ICMPv6 to link local address and local address. In addition, this test set could be extended to cover more situations in the future.
ICMPv6 to local addresses
TEST: Ping to link local address [OK] TEST: Ping to link local address from ::1 [OK] TEST: Ping to local address [OK] TEST: Ping to local address from ::1 [OK]
VRF based tests are needed as well to ensure this change works properly with VRFs.
Re: [PATCH 2/2 net-next] selftests: ipv6_icmp: add tests for ICMPv6 handling
Quoted 11 lines · David Ahern
Quoted 9 lines · Fernando Fernandez Mancera
Test ICMPv6 to link local address and local address. In addition, this test set could be extended to cover more situations in the future.
ICMPv6 to local addresses
TEST: Ping to link local address [OK] TEST: Ping to link local address from ::1 [OK] TEST: Ping to local address [OK] TEST: Ping to local address from ::1 [OK]
Quoted 3 lines
VRF based tests are needed as well to ensure this change works properly with VRFs.
Thank you David. I am reposting it with VRF based tests once net-next tree is open again.
Paolo Abeni
maintainerRe: [PATCH 2/2 net-next] selftests: ipv6_icmp: add tests for ICMPv6 handling
Quoted 12 lines · Fernando Fernandez Mancera
Quoted 11 lines · David Ahern
Quoted 9 lines · Fernando Fernandez Mancera
Test ICMPv6 to link local address and local address. In addition, this test set could be extended to cover more situations in the future.
ICMPv6 to local addresses
TEST: Ping to link local address [OK] TEST: Ping to link local address from ::1 [OK] TEST: Ping to local address [OK] TEST: Ping to local address from ::1 [OK]
Quoted 5 lines
Quoted 2 lines
VRF based tests are needed as well to ensure this change works properly with VRFs.
Thank you David. I am reposting it with VRF based tests once net-next tree is open again.
While at it, please have a look at the shellcheck reported issues:
https://netdev-ctrl.bots.linux.dev/logs/build/1028021/14331024/shellcheck/stderr
Also, not a big deal but you could possibly simplify a bit the ip addr parse code using json formatting:
ip -j -6 addr show dev ${dev} | jq -r '.[].addr_info[].local'
Cheers,
Paolo