initialize_if 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) International Business Machines Corp., 2005 ##
  5. ## ##
  6. ## This program is free software; you can redistribute it and#or modify ##
  7. ## it under the terms of the GNU General Public License as published by ##
  8. ## the Free Software Foundation; either version 2 of the License, or ##
  9. ## (at your option) any later version. ##
  10. ## ##
  11. ## This program is distributed in the hope that it will be useful, but ##
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  13. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  14. ## for more details. ##
  15. ## ##
  16. ## You should have received a copy of the GNU General Public License ##
  17. ## along with this program; if not, write to the Free Software ##
  18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  19. ## ##
  20. ## ##
  21. ################################################################################
  22. #
  23. # File:
  24. # initialize_if
  25. #
  26. # Description:
  27. # Initialize the interface which belongs to the specified test link
  28. #
  29. # Author:
  30. # Mitsuru Chinen <mitch@jp.ibm.com>
  31. #
  32. # Arguments:
  33. # $1: Set the host type (lhost - local host | rhost - remote host)
  34. # $2: The number of the test link
  35. #
  36. # Exit Value:
  37. # 0: Exit normally
  38. # >0: Exit abnormally
  39. #
  40. # History:
  41. # Oct 19 2005 - Created (Mitsuru Chinen)
  42. #
  43. #-----------------------------------------------------------------------
  44. #Uncomment line below for debug output.
  45. $trace_logic
  46. # Make sure the value of LTPROOT
  47. LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
  48. export LTPROOT
  49. # Check the environmanet variable for the test
  50. . check_envval || exit 1
  51. # Arguments
  52. if [ $# -ne 2 ]; then
  53. echo "Usage: $0 host_type link_num" >&2
  54. exit 1
  55. fi
  56. host_type=$1
  57. link_num=$2
  58. # Check the host type
  59. if [ $host_type != lhost -a $host_type != rhost ]; then
  60. echo "$0: 1st argumet is lhost or rhost" >$2
  61. exit 1
  62. fi
  63. # Define the interface name
  64. ifname=`get_ifname $host_type $link_num` || exit 1
  65. # Initialize the specified interface
  66. command="ifconfig $ifname down mtu 1500 ; ip route flush dev $ifname ; ip addr flush dev $ifname ; ifconfig $ifname up"
  67. if [ $host_type = lhost ]; then
  68. ( ifconfig $ifname down && \
  69. ip link set mtu 1500 dev $ifname && \
  70. ip route flush dev $ifname && \
  71. ip addr flush dev $ifname && \
  72. ifconfig $ifname up ) >/dev/null 2>&1
  73. ret=$?
  74. else
  75. ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ifconfig '$ifname' down && ip link set mtu 1500 dev '$ifname' && ip route flush dev '$ifname' && ip addr flush dev '$ifname' && ifconfig '$ifname' up ) >/dev/null 2>&1 ; echo $?'`
  76. fi
  77. if [ $ret -gt 0 ]; then
  78. echo "Failed to initialize $ifname" >&2
  79. exit 1
  80. fi