traceroute01.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. TST_CNT=2
  7. TST_NEEDS_CMDS="traceroute"
  8. TST_SETUP="setup"
  9. TST_TESTFUNC="test"
  10. TST_NEEDS_TMPDIR=1
  11. . tst_net.sh
  12. setup()
  13. {
  14. tst_res TINFO "traceroute version:"
  15. tst_res TINFO $(traceroute --version 2>&1)
  16. [ "$TST_IPV6" ] && tst_res TINFO "NOTE: tracepath6 from iputils is not supported"
  17. }
  18. run_trace()
  19. {
  20. local opts="$@"
  21. local ip=$(tst_ipaddr rhost)
  22. local pattern="^[ ]+1[ ]+$ip([ ]+[0-9]+[.][0-9]+ ms){3}"
  23. # According to man pages, default sizes:
  24. local bytes=60
  25. [ "$TST_IPV6" ] && bytes=80
  26. EXPECT_PASS traceroute $ip $bytes -n -m 2 $opts \>out.log 2>&1
  27. grep -q "$bytes byte" out.log
  28. if [ $? -ne 0 ]; then
  29. cat out.log
  30. tst_res TFAIL "'$bytes byte' not found"
  31. else
  32. tst_res TPASS "traceroute use $bytes bytes"
  33. fi
  34. tail -1 out.log | grep -qE "$pattern"
  35. if [ $? -ne 0 ]; then
  36. cat out.log
  37. tst_res TFAIL "pattern '$pattern' not found in log"
  38. else
  39. tst_res TPASS "traceroute test completed with 1 hop"
  40. fi
  41. }
  42. test1()
  43. {
  44. tst_res TINFO "run traceroute with ICMP ECHO"
  45. run_trace -I
  46. }
  47. test2()
  48. {
  49. tst_res TINFO "run traceroute with TCP SYN"
  50. run_trace -T
  51. }
  52. tst_run