Add gw6c and make it link against uclibcxx (#2125)
[openwrt/svn-archive/archive.git] / ipv6 / gw6c / files / openwrt.sh
1 #!/bin/sh
2 #
3 # openwrt.sh,v 1.1.4.1 2007/01/12 19:16:12 dgregoire Exp
4 #
5 # This source code copyright (c) Hexago Inc. 2002-2007.
6 #
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.
12 #
13 # Note: IPV6 support and tun Support must be enabled before calling this script.
14 #
15
16
17 LANGUAGE=C
18
19 if [ -z $TSP_VERBOSE ]; then
20 TSP_VERBOSE=0
21 fi
22
23 KillProcess()
24 {
25 if [ ! -z $TSP_VERBOSE ]; then
26 if [ $TSP_VERBOSE -ge 2 ]; then
27 echo killing $*
28 fi
29 fi
30 PID=`ps axww | grep $1 | grep -v grep | awk '{ print $1;}'`
31 echo $PID
32 if [ ! -z $PID ]; then
33 kill $PID
34 fi
35 }
36
37 Display()
38 {
39 if [ -z $TSP_VERBOSE ]; then
40 return;
41 fi
42 if [ $TSP_VERBOSE -lt $1 ]; then
43 return;
44 fi
45 shift
46 echo "$*"
47 }
48
49 Exec()
50 {
51 if [ ! -z $TSP_VERBOSE ]; then
52 if [ $TSP_VERBOSE -ge 2 ]; then
53 echo $*
54 fi
55 fi
56 $* # Execute command
57 if [ $? -ne 0 ]; then
58 echo "Error while executing $1"
59 echo " Command: $*"
60 exit 1
61 fi
62 }
63
64 ExecNoCheck()
65 {
66 if [ ! -z $TSP_VERBOSE ]; then
67 if [ $TSP_VERBOSE -ge 2 ]; then
68 echo $*
69 fi
70 fi
71 $* # Execute command
72 }
73
74 # Program localization
75
76 Display 1 "--- Start of configuration script. ---"
77 Display 1 "Script: " `basename $0`
78
79 ifconfig=/sbin/ifconfig
80 route=/sbin/route
81 ipconfig=/usr/sbin/ip
82 rtadvd=/usr/sbin/radvd
83 rtadvd_pid=/var/run/radvd.pid
84 sysctl=/sbin/sysctl
85 rtadvdconfigfilename=gw6c-radvd.conf
86 rtadvdconfigfile=/tmp/$rtadvdconfigfilename
87
88 if [ -z $TSP_HOME_DIR ]; then
89 echo "TSP_HOME_DIR variable not specified!;"
90 exit 1
91 fi
92
93 if [ ! -d $TSP_HOME_DIR ]; then
94 echo "Error : directory $TSP_HOME_DIR does not exist"
95 exit 1
96 fi
97 #
98
99 if [ -z $TSP_HOST_TYPE ]; then
100 echo Error: TSP_HOST_TYPE not defined.
101 exit 1
102 fi
103
104 if [ X"${TSP_HOST_TYPE}" = X"host" ] || [ X"${TSP_HOST_TYPE}" = X"router" ]; then
105 #
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
111 ExecNoCheck sleep 1
112 Exec $ipconfig tunnel add $TSP_TUNNEL_INTERFACE mode sit ttl 64 remote $TSP_SERVER_ADDRESS_IPV4
113 fi
114
115 Exec $ifconfig $TSP_TUNNEL_INTERFACE up
116
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
122 fi
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
126 #
127 # Default route
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
133 fi
134
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
142 fi
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
148 fi
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"
171 else
172 echo "Error : file $rtadvdconfigfile not found"
173 exit 1
174 fi
175 fi
176
177 Display 1 "--- End of configuration script. ---"
178
179 exit 0
180
181 #---------------------------------------------------------------------