add_ipv6addr 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. # add_ipv6addr
  25. #
  26. # Description:
  27. # Add an IPv6 address to the interface which belongs to the specified
  28. # test link
  29. #
  30. # Author:
  31. # Mitsuru Chinen <mitch@jp.ibm.com>
  32. #
  33. # Arguments:
  34. # $1: target host to add the IPv6 address
  35. # lhost - local host / rhost - remote host
  36. # $2: number of the test link
  37. # $3: network portion of the IPv6 address
  38. # $4: host portion of the IPv6 address
  39. #
  40. # Exit Value:
  41. # 0: Exit normally
  42. # >0: Exit abnormally
  43. #
  44. # History:
  45. # Oct 19 2005 - Created (Mitsuru Chinen)
  46. #
  47. #-----------------------------------------------------------------------
  48. #Uncomment line below for debug output.
  49. #trace_logic=${trace_logic:-"set -x"}
  50. $trace_logic
  51. # Make sure the value of LTPROOT
  52. LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
  53. export LTPROOT
  54. # Check the environmanet variable for the test
  55. . check_envval || exit 1
  56. # Arguments
  57. if [ $# -ne 4 ]; then
  58. echo "Usage: $0 host_type link_number network_portion host_portion" >&2
  59. exit 1
  60. fi
  61. host_type=$1
  62. link_num=$2
  63. network_part=$3
  64. host_part=$4
  65. # Check the host type
  66. if [ $host_type != lhost -a $host_type != rhost ]; then
  67. echo "$0: 1st argumet is lhost or rhost" >&2
  68. exit 1
  69. fi
  70. # Define IPv6 address and netmask
  71. addr="${network_part}:${host_part}"
  72. netmask=64
  73. # Assign IPv6 address to the interface belongs the nth Test Link
  74. ifname=`get_ifname $host_type $link_num` || exit 1
  75. if [ $host_type = lhost ]; then
  76. ifconfig ${ifname} up ; ifconfig ${ifname} add ${addr}/${netmask}
  77. ret=$?
  78. else
  79. ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ifconfig '${ifname}' up && ifconfig '${ifname}' add '${addr}/${netmask}' ) >/dev/null 2>&1; echo $?'`
  80. fi
  81. if [ $ret -ne 0 ]; then
  82. echo "Cannot assign $addr to $ifname" >&2
  83. exit 1
  84. fi