tracepath01.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. TST_TESTFUNC="do_test"
  7. TST_SETUP="setup"
  8. . tst_net.sh
  9. setup()
  10. {
  11. cmd="tracepath"
  12. if [ "$TST_IPV6" ]; then
  13. cmd="tracepath$TST_IPVER"
  14. tst_cmd_available $cmd || cmd="tracepath -6"
  15. fi
  16. tst_require_cmds $(echo $cmd | cut -f 1 -d' ')
  17. if $cmd -V >/dev/null 2>&1; then
  18. tst_res TINFO "traceroute version:"
  19. tst_res TINFO $($cmd -V 2>&1)
  20. fi
  21. }
  22. do_test()
  23. {
  24. local len=1280
  25. local output
  26. local rhost="$(tst_ipaddr rhost)"
  27. tst_res TINFO "test $cmd with $rhost, pmtu is $len"
  28. output=$($cmd $rhost -l $len | grep "pmtu $len")
  29. if [ $? -ne 0 ]; then
  30. tst_res TFAIL "$cmd failed: pmtu $len not found in output"
  31. return
  32. fi
  33. # Usually only one hop is required to get to remote test machine
  34. hops_num=$(echo "$output" | sed -nE 's/.*hops ([0-9]+).*/\1/p')
  35. if [ -z "$hops_num" ]; then
  36. tst_res TFAIL "failed to trace path to '$rhost'"
  37. return
  38. fi
  39. if [ "$hops_num" -eq 0 ]; then
  40. tst_res TFAIL "can't trace path to '$rhost' in 1+ hops"
  41. return
  42. fi
  43. tst_res TPASS "traced path to '$rhost' in $hops_num hops"
  44. }
  45. tst_run