1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
4# Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
5# Copyright (c) International Business Machines  Corp., 2001
6
7TST_CNT=2
8TST_NEEDS_CMDS="traceroute"
9TST_SETUP="setup"
10TST_TESTFUNC="test"
11TST_NEEDS_TMPDIR=1
12. tst_net.sh
13
14setup()
15{
16	tst_res TINFO "traceroute version:"
17	tst_res TINFO $(traceroute --version 2>&1)
18	[ "$TST_IPV6" ] && tst_res TINFO "NOTE: tracepath6 from iputils is not supported"
19}
20
21run_trace()
22{
23	local opts="$@"
24	local ip=$(tst_ipaddr rhost)
25	local pattern="^[ ]+1[ ]+$ip([ ]+[0-9]+[.][0-9]+ ms){3}"
26
27	# According to man pages, default sizes:
28	local bytes=60
29	[ "$TST_IPV6" ] && bytes=80
30
31	EXPECT_PASS traceroute $ip $bytes -n -m 2 $opts \>out.log 2>&1
32
33	grep -q "$bytes byte" out.log
34	if [ $? -ne 0 ]; then
35		cat out.log
36		tst_res TFAIL "'$bytes byte' not found"
37	else
38		tst_res TPASS "traceroute use $bytes bytes"
39	fi
40
41	tail -1 out.log | grep -qE "$pattern"
42	if [ $? -ne 0 ]; then
43		cat out.log
44		tst_res TFAIL "pattern '$pattern' not found in log"
45	else
46		tst_res TPASS "traceroute test completed with 1 hop"
47	fi
48}
49
50test1()
51{
52	tst_res TINFO "run traceroute with ICMP ECHO"
53	run_trace -I
54}
55
56test2()
57{
58	tst_res TINFO "run traceroute with TCP SYN"
59	run_trace -T
60}
61
62tst_run
63