Skip to content

Commit 2e64281

Browse files
idoschPaolo Abeni
authored andcommitted
selftests: traceroute: Test traceroute with different source IPs
When generating ICMP error messages, the kernel will prefer a source IP that is on the same subnet as the destination IP (see inet_select_addr()). Test this behavior by invoking traceroute with different source IPs and checking that the ICMP error message is generated with a source IP in the same subnet. Reviewed-by: Petr Machata <petrm@nvidia.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20250908073238.119240-8-idosch@nvidia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 5c9c782 commit 2e64281

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tools/testing/selftests/net/traceroute.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ run_traceroute6()
196196
################################################################################
197197
# traceroute test
198198
#
199-
# Verify that traceroute from H1 to H2 shows 1.0.1.1 in this scenario
199+
# Verify that traceroute from H1 to H2 shows 1.0.3.1 and 1.0.1.1 when
200+
# traceroute uses 1.0.3.3 and 1.0.1.3 as the source IP, respectively.
200201
#
201-
# 1.0.3.1/24
202+
# 1.0.3.3/24 1.0.3.1/24
202203
# ---- 1.0.1.3/24 1.0.1.1/24 ---- 1.0.2.1/24 1.0.2.4/24 ----
203204
# |H1|--------------------------|R1|--------------------------|H2|
204205
# ---- N1 ---- N2 ----
@@ -226,6 +227,7 @@ setup_traceroute()
226227

227228
connect_ns $h1 eth0 1.0.1.3/24 - \
228229
$router eth1 1.0.3.1/24 -
230+
ip -n "$h1" addr add 1.0.3.3/24 dev eth0
229231
ip netns exec $h1 ip route add default via 1.0.1.1
230232

231233
ip netns exec $router ip addr add 1.0.1.1/24 dev eth1
@@ -248,9 +250,12 @@ run_traceroute()
248250

249251
RET=0
250252

251-
# traceroute host-2 from host-1 (expects 1.0.1.1). Takes a while.
252-
run_cmd $h1 "traceroute 1.0.2.4 | grep -q 1.0.1.1"
253+
# traceroute host-2 from host-1. Expect a source IP that is on the same
254+
# subnet as destination IP of the ICMP error message.
255+
run_cmd "$h1" "traceroute -s 1.0.1.3 1.0.2.4 | grep -q 1.0.1.1"
253256
check_err $? "traceroute did not return 1.0.1.1"
257+
run_cmd "$h1" "traceroute -s 1.0.3.3 1.0.2.4 | grep -q 1.0.3.1"
258+
check_err $? "traceroute did not return 1.0.3.1"
254259
log_test "IPv4 traceroute"
255260

256261
cleanup_traceroute

0 commit comments

Comments
 (0)