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