xref: /aosp_15_r20/external/ltp/testcases/network/tcp_cmds/tracepath/tracepath01.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2019 Petr Vorel <[email protected]>
4# Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
5# Author: Alexey Kodanev <[email protected]>
6
7TST_TESTFUNC="do_test"
8TST_SETUP="setup"
9
10setup()
11{
12	cmd="tracepath"
13
14	if [ "$TST_IPV6" ]; then
15		cmd="tracepath$TST_IPVER"
16		tst_cmd_available $cmd || cmd="tracepath -6"
17	fi
18	tst_require_cmds $(echo $cmd | cut -f 1 -d' ')
19
20	if $cmd -V >/dev/null 2>&1; then
21		tst_res TINFO "traceroute version:"
22		tst_res TINFO $($cmd -V 2>&1)
23	fi
24}
25
26do_test()
27{
28	local len=1280
29	local output
30	local rhost="$(tst_ipaddr rhost)"
31
32	tst_res TINFO "test $cmd with $rhost, pmtu is $len"
33
34	output=$($cmd $rhost -l $len | grep "pmtu $len")
35	if [ $? -ne 0 ]; then
36		tst_res TFAIL "$cmd failed: pmtu $len not found in output"
37		return
38	fi
39
40	# Usually only one hop is required to get to remote test machine
41	hops_num=$(echo "$output" | sed -nE 's/.*hops ([0-9]+).*/\1/p')
42	if [ -z "$hops_num" ]; then
43		tst_res TFAIL "failed to trace path to '$rhost'"
44		return
45	fi
46
47	if [ "$hops_num" -eq 0 ]; then
48		tst_res TFAIL "can't trace path to '$rhost' in 1+ hops"
49		return
50	fi
51
52	tst_res TPASS "traced path to '$rhost' in $hops_num hops"
53}
54
55. tst_net.sh
56tst_run
57