xref: /aosp_15_r20/external/ltp/testcases/network/traceroute/traceroute01.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/sh
2*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later
3*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2019 Petr Vorel <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
5*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) International Business Machines  Corp., 2001
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard WorkerTST_CNT=2
8*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_CMDS="traceroute"
9*49cdfc7eSAndroid Build Coastguard WorkerTST_SETUP="setup"
10*49cdfc7eSAndroid Build Coastguard WorkerTST_TESTFUNC="test"
11*49cdfc7eSAndroid Build Coastguard WorkerTST_NEEDS_TMPDIR=1
12*49cdfc7eSAndroid Build Coastguard Worker
13*49cdfc7eSAndroid Build Coastguard Workersetup()
14*49cdfc7eSAndroid Build Coastguard Worker{
15*49cdfc7eSAndroid Build Coastguard Worker
16*49cdfc7eSAndroid Build Coastguard Worker	TRACEROUTE=traceroute${TST_IPV6}
17*49cdfc7eSAndroid Build Coastguard Worker	tst_require_cmds $TRACEROUTE
18*49cdfc7eSAndroid Build Coastguard Worker
19*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "$TRACEROUTE version:"
20*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO $($TRACEROUTE -V 2>&1)
21*49cdfc7eSAndroid Build Coastguard Worker}
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Workerrun_trace()
24*49cdfc7eSAndroid Build Coastguard Worker{
25*49cdfc7eSAndroid Build Coastguard Worker	local opts="$@"
26*49cdfc7eSAndroid Build Coastguard Worker	local ip=$(tst_ipaddr rhost)
27*49cdfc7eSAndroid Build Coastguard Worker	local pattern="^[ ]+1[ ]+$ip([ ]+[0-9]+[.][0-9]+ ms){3}"
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Worker	if $TRACEROUTE $opts 2>&1 | grep -q "invalid option"; then
30*49cdfc7eSAndroid Build Coastguard Worker		tst_res TCONF "$opts flag not supported"
31*49cdfc7eSAndroid Build Coastguard Worker		return
32*49cdfc7eSAndroid Build Coastguard Worker	fi
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker	# According to man pages, default sizes:
35*49cdfc7eSAndroid Build Coastguard Worker	local bytes=60
36*49cdfc7eSAndroid Build Coastguard Worker	[ "$TST_IPV6" ] && bytes=80
37*49cdfc7eSAndroid Build Coastguard Worker
38*49cdfc7eSAndroid Build Coastguard Worker	EXPECT_PASS $TRACEROUTE $ip $bytes -n -m 2 $opts \>out.log
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker	grep -q "$bytes byte" out.log
41*49cdfc7eSAndroid Build Coastguard Worker	if [ $? -ne 0 ]; then
42*49cdfc7eSAndroid Build Coastguard Worker		cat out.log
43*49cdfc7eSAndroid Build Coastguard Worker		tst_res TFAIL "'$bytes byte' not found"
44*49cdfc7eSAndroid Build Coastguard Worker	else
45*49cdfc7eSAndroid Build Coastguard Worker		tst_res TPASS "$TRACEROUTE use $bytes bytes"
46*49cdfc7eSAndroid Build Coastguard Worker	fi
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker	tail -1 out.log | grep -qE "$pattern"
49*49cdfc7eSAndroid Build Coastguard Worker	if [ $? -ne 0 ]; then
50*49cdfc7eSAndroid Build Coastguard Worker		cat out.log
51*49cdfc7eSAndroid Build Coastguard Worker		tst_res TFAIL "pattern '$pattern' not found in log"
52*49cdfc7eSAndroid Build Coastguard Worker	else
53*49cdfc7eSAndroid Build Coastguard Worker		tst_res TPASS "$TRACEROUTE test completed with 1 hop"
54*49cdfc7eSAndroid Build Coastguard Worker	fi
55*49cdfc7eSAndroid Build Coastguard Worker}
56*49cdfc7eSAndroid Build Coastguard Worker
57*49cdfc7eSAndroid Build Coastguard Workertest1()
58*49cdfc7eSAndroid Build Coastguard Worker{
59*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "run $TRACEROUTE with ICMP ECHO"
60*49cdfc7eSAndroid Build Coastguard Worker	run_trace -I
61*49cdfc7eSAndroid Build Coastguard Worker}
62*49cdfc7eSAndroid Build Coastguard Worker
63*49cdfc7eSAndroid Build Coastguard Workertest2()
64*49cdfc7eSAndroid Build Coastguard Worker{
65*49cdfc7eSAndroid Build Coastguard Worker	tst_res TINFO "run $TRACEROUTE with TCP SYN"
66*49cdfc7eSAndroid Build Coastguard Worker	run_trace -T
67*49cdfc7eSAndroid Build Coastguard Worker}
68*49cdfc7eSAndroid Build Coastguard Worker
69*49cdfc7eSAndroid Build Coastguard Worker. tst_net.sh
70*49cdfc7eSAndroid Build Coastguard Workertst_run
71