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