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