1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2019 Petr Vorel <[email protected]> 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 13setup() 14{ 15 16 TRACEROUTE=traceroute${TST_IPV6} 17 tst_require_cmds $TRACEROUTE 18 19 tst_res TINFO "$TRACEROUTE version:" 20 tst_res TINFO $($TRACEROUTE -V 2>&1) 21} 22 23run_trace() 24{ 25 local opts="$@" 26 local ip=$(tst_ipaddr rhost) 27 local pattern="^[ ]+1[ ]+$ip([ ]+[0-9]+[.][0-9]+ ms){3}" 28 29 if $TRACEROUTE $opts 2>&1 | grep -q "invalid option"; then 30 tst_res TCONF "$opts flag not supported" 31 return 32 fi 33 34 # According to man pages, default sizes: 35 local bytes=60 36 [ "$TST_IPV6" ] && bytes=80 37 38 EXPECT_PASS $TRACEROUTE $ip $bytes -n -m 2 $opts \>out.log 39 40 grep -q "$bytes byte" out.log 41 if [ $? -ne 0 ]; then 42 cat out.log 43 tst_res TFAIL "'$bytes byte' not found" 44 else 45 tst_res TPASS "$TRACEROUTE use $bytes bytes" 46 fi 47 48 tail -1 out.log | grep -qE "$pattern" 49 if [ $? -ne 0 ]; then 50 cat out.log 51 tst_res TFAIL "pattern '$pattern' not found in log" 52 else 53 tst_res TPASS "$TRACEROUTE test completed with 1 hop" 54 fi 55} 56 57test1() 58{ 59 tst_res TINFO "run $TRACEROUTE with ICMP ECHO" 60 run_trace -I 61} 62 63test2() 64{ 65 tst_res TINFO "run $TRACEROUTE with TCP SYN" 66 run_trace -T 67} 68 69. tst_net.sh 70tst_run 71