3 # openwrt.sh,v 1.1.4.1 2007/01/12 19:16:12 dgregoire Exp
5 # This source code copyright (c) Hexago Inc. 2002-2007.
7 # LICENSE NOTICE: You may use and modify this source code only if you
8 # have executed a valid license agreement with Hexago Inc. granting
9 # you the right to do so, the said license agreement governing such
10 # use and modifications. Copyright or other intellectual property
11 # notices are not to be removed from the source code.
13 # Note: IPV6 support and tun Support must be enabled before calling this script.
19 if [ -z $TSP_VERBOSE ]; then
25 if [ ! -z $TSP_VERBOSE ]; then
26 if [ $TSP_VERBOSE -ge 2 ]; then
30 PID=`ps axww | grep $1 | grep -v grep | awk '{ print $1;}'`
32 if [ ! -z $PID ]; then
39 if [ -z $TSP_VERBOSE ]; then
42 if [ $TSP_VERBOSE -lt $1 ]; then
51 if [ ! -z $TSP_VERBOSE ]; then
52 if [ $TSP_VERBOSE -ge 2 ]; then
58 echo "Error while executing $1"
66 if [ ! -z $TSP_VERBOSE ]; then
67 if [ $TSP_VERBOSE -ge 2 ]; then
74 # Program localization
76 Display 1 "--- Start of configuration script. ---"
77 Display 1 "Script: " `basename $0`
79 ifconfig=/sbin/ifconfig
82 rtadvd=/usr/sbin/radvd
83 rtadvd_pid=/var/run/radvd.pid
85 rtadvdconfigfilename=gw6c-radvd.conf
86 rtadvdconfigfile=/tmp/$rtadvdconfigfilename
88 if [ -z $TSP_HOME_DIR ]; then
89 echo "TSP_HOME_DIR variable not specified!;"
93 if [ ! -d $TSP_HOME_DIR ]; then
94 echo "Error : directory $TSP_HOME_DIR does not exist"
99 if [ -z $TSP_HOST_TYPE ]; then
100 echo Error: TSP_HOST_TYPE not defined.
104 if [ X"${TSP_HOST_TYPE}" = X"host" ] || [ X"${TSP_HOST_TYPE}" = X"router" ]; then
106 # Configured tunnel config (IPv6)
107 Display 1 "$TSP_TUNNEL_INTERFACE setup"
108 if [ X"${TSP_TUNNEL_MODE}" = X"v6v4" ]; then
109 Display 1 "Setting up link to $TSP_SERVER_ADDRESS_IPV4"
110 ExecNoCheck $ipconfig tunnel del $TSP_TUNNEL_INTERFACE
112 Exec $ipconfig tunnel add $TSP_TUNNEL_INTERFACE mode sit ttl 64 remote $TSP_SERVER_ADDRESS_IPV4
115 Exec $ifconfig $TSP_TUNNEL_INTERFACE up
117 PREF=`echo $TSP_CLIENT_ADDRESS_IPV6 | sed "s/:0*/:/g" |cut -d : -f1-2`
118 OLDADDR=`$ifconfig $TSP_TUNNEL_INTERFACE | grep "inet6.* $PREF" | sed -e "s/^.*inet6 addr: //" -e "s/ Scope.*\$//"`
119 if [ ! -z $OLDADDR ]; then
120 Display 1 "Removing old IPv6 address $OLDADDR"
121 Exec $ifconfig $TSP_TUNNEL_INTERFACE inet6 del $OLDADDR
123 Display 1 "This host is: $TSP_CLIENT_ADDRESS_IPV6/$TSP_TUNNEL_PREFIXLEN"
124 Exec $ifconfig $TSP_TUNNEL_INTERFACE add $TSP_CLIENT_ADDRESS_IPV6/$TSP_TUNNEL_PREFIXLEN
125 Exec $ifconfig $TSP_TUNNEL_INTERFACE mtu 1280
128 Display 1 "Adding default route"
129 ExecNoCheck $route -A inet6 del ::/0 2>/dev/null # delete old default route
130 ExecNoCheck $route -A inet6 del 2000::/3 2>/dev/null # delete old gw route
131 Exec $route -A inet6 add ::/0 dev $TSP_TUNNEL_INTERFACE
132 Exec $route -A inet6 add 2000::/3 dev $TSP_TUNNEL_INTERFACE
135 # Router configuration if required
136 if [ X"${TSP_HOST_TYPE}" = X"router" ]; then
137 Display 1 "Router configuration"
138 Display 1 "Kernel setup"
139 if [ X"${TSP_PREFIXLEN}" != X"64" ]; then
140 #Better way on linux to avoid loop with the remaining /48?
141 $route -A inet6 add $TSP_PREFIX::/$TSP_PREFIXLEN dev $TSP_HOME_INTERFACE 2>/dev/null
143 Display 1 "Adding prefix to $TSP_HOME_INTERFACE"
144 OLDADDR=`$ifconfig $TSP_HOME_INTERFACE | grep "inet6.* $PREF" | sed -e "s/^.*inet6 addr: //" -e "s/ Scope.*\$//"`
145 if [ ! -z $OLDADDR ]; then
146 Display 1 "Removing old IPv6 address $OLDADDR"
147 Exec $ifconfig $TSP_HOME_INTERFACE del $OLDADDR
149 Exec $ifconfig $TSP_HOME_INTERFACE add $TSP_PREFIX::1/64
150 # Router advertisement configuration
151 Display 1 "Create new $rtadvdconfigfile"
152 echo "##### rtadvd.conf made by Gateway6 Client ####" > "$rtadvdconfigfile"
153 echo "interface $TSP_HOME_INTERFACE" >> "$rtadvdconfigfile"
154 echo "{" >> "$rtadvdconfigfile"
155 echo " AdvSendAdvert on;" >> "$rtadvdconfigfile"
156 echo " prefix $TSP_PREFIX::/64" >> "$rtadvdconfigfile"
157 echo " {" >> "$rtadvdconfigfile"
158 echo " AdvOnLink on;" >> "$rtadvdconfigfile"
159 echo " AdvAutonomous on;" >> "$rtadvdconfigfile"
160 echo " };" >> "$rtadvdconfigfile"
161 echo "};" >> "$rtadvdconfigfile"
162 echo "" >> "$rtadvdconfigfile"
163 /etc/init.d/radvd stop
164 # Then enable forwarding. Killing
165 # radvd disables forwarding and radvd
166 # does NOT start without forwarding enabled
167 Exec $sysctl -w net.ipv6.conf.all.forwarding=1 # ipv6_forwarding enabled
168 if [ -f $rtadvdconfigfile ]; then
169 Exec $rtadvd -p $rtadvd_pid -C $rtadvdconfigfile
170 Display 1 "Starting radvd: $rtadvd -p $rtadvd_pid -C $rtadvdconfigfile"
172 echo "Error : file $rtadvdconfigfile not found"
177 Display 1 "--- End of configuration script. ---"
181 #---------------------------------------------------------------------