1 | #!/bin/sh |
---|
2 | # |
---|
3 | # ifup-ipv6 |
---|
4 | # |
---|
5 | # |
---|
6 | # Taken from: |
---|
7 | # (P) & (C) 2000-2006 by Peter Bieringer <pb@bieringer.de> |
---|
8 | # |
---|
9 | # You will find more information on the initscripts-ipv6 homepage at |
---|
10 | # http://www.deepspace6.net/projects/initscripts-ipv6.html |
---|
11 | # |
---|
12 | # RHL integration assistance by Pekka Savola <pekkas@netcore.fi> |
---|
13 | # |
---|
14 | # Version: 2006-07-20 |
---|
15 | # |
---|
16 | # Note: if called (like normally) by /etc/sysconfig/network-scripts/ifup |
---|
17 | # exit codes aren't handled by "ifup" |
---|
18 | # |
---|
19 | # Uses following information from "/etc/sysconfig/network": |
---|
20 | # IPV6_DEFAULTDEV=<device>: controls default route (optional) |
---|
21 | # IPV6_DEFAULTGW=<address>: controls default route (optional) |
---|
22 | # |
---|
23 | # Uses following information from "/etc/sysconfig/network-scripts/ifcfg-$1": |
---|
24 | # IPV6INIT=yes|no: controls IPv6 configuration for this interface |
---|
25 | # IPV6ADDR=<IPv6 address>[/<prefix length>]: specify primary static IPv6 address |
---|
26 | # IPV6ADDR_SECONDARIES="<IPv6 address>[/<prefix length>] ..." (optional) |
---|
27 | # IPV6_ROUTER=yes|no: controls IPv6 autoconfiguration (no: multi-homed interface without routing) |
---|
28 | # IPV6_AUTOCONF=yes|no: controls IPv6 autoconfiguration |
---|
29 | # defaults: |
---|
30 | # IPV6FORWARDING=yes: IPV6_AUTOCONF=no, IPV6_ROUTER=yes |
---|
31 | # IPV6FORWARDING=no: IPV6_AUTOCONF=yes |
---|
32 | # IPV6_MTU=<MTU for IPv6>: controls IPv6 MTU for this link (optional) |
---|
33 | # IPV6_PRIVACY="rfc3041": control IPv6 privacy (optional) |
---|
34 | # This script only supports "rfc3041" (if kernel supports it) |
---|
35 | # |
---|
36 | # Optional for 6to4 tunneling (hardwired name of tunnel device is "tun6to4"): |
---|
37 | # IPV6TO4INIT=yes|no: controls 6to4 tunneling setup |
---|
38 | # IPV6TO4_RELAY=<IPv4 address>: IPv4 address of the remote 6to4 relay (default: 192.88.99.1) |
---|
39 | # IPV6TO4_MTU=<MTU for IPv6>: controls IPv6 MTU for the 6to4 link (optional, default is MTU of interface - 20) |
---|
40 | # IPV6TO4_IPV4ADDR=<IPv4 address>: overwrite local IPv4 address (optional) |
---|
41 | # IPV6TO4_ROUTING="<device>-<suffix>/<prefix length> ...": information to setup additional interfaces |
---|
42 | # Example: IPV6TO4_ROUTING="eth0-:f101::1/64 eth1-:f102::1/64" |
---|
43 | # |
---|
44 | # Optional for 6to4 tunneling to trigger radvd: |
---|
45 | # IPV6_CONTROL_RADVD=yes|no: controls radvd triggering (optional) |
---|
46 | # IPV6_RADVD_PIDFILE=<file>: PID file of radvd for sending signals, default is "/var/run/radvd/radvd.pid" (optional) |
---|
47 | # IPV6_RADVD_TRIGGER_ACTION=startstop|reload|restart|SIGHUP: how to trigger radvd (optional, default is SIGHUP) |
---|
48 | # |
---|
49 | # Required version of radvd to use 6to4 prefix recalculation |
---|
50 | # 0.6.2p3 or newer supporting option "Base6to4Interface" |
---|
51 | # Required version of radvd to use dynamic ppp links |
---|
52 | # 0.7.0 + fixes or newer |
---|
53 | # |
---|
54 | |
---|
55 | |
---|
56 | . /etc/sysconfig/network |
---|
57 | |
---|
58 | cd /etc/sysconfig/network-scripts |
---|
59 | . ./network-functions |
---|
60 | |
---|
61 | CONFIG=$1 |
---|
62 | [ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIG |
---|
63 | source_config |
---|
64 | |
---|
65 | # IPv6 don't need aliases anymore, config is skipped |
---|
66 | REALDEVICE=`echo ${DEVICE} | sed 's/:.*//g'` |
---|
67 | [ "$DEVICE" != "$REALDEVICE" ] && exit 0 |
---|
68 | |
---|
69 | # Test whether IPv6 configuration is enabled for this interface, else stop |
---|
70 | [ "$IPV6INIT" = "yes" ] || exit 0 |
---|
71 | |
---|
72 | [ -f /etc/sysconfig/network-scripts/network-functions-ipv6 ] || exit 1 |
---|
73 | . /etc/sysconfig/network-scripts/network-functions-ipv6 |
---|
74 | |
---|
75 | |
---|
76 | # IPv6 test, module loaded, exit if system is not IPv6-ready |
---|
77 | ipv6_test || exit 1 |
---|
78 | |
---|
79 | # Test device status |
---|
80 | ipv6_test_device_status $DEVICE |
---|
81 | if [ $? != 0 -a $? != 11 ]; then |
---|
82 | # device doesn't exist or other problem occurs |
---|
83 | exit 1 |
---|
84 | fi |
---|
85 | |
---|
86 | # Setup IPv6 address on specified interface |
---|
87 | if [ -n "$IPV6ADDR" ]; then |
---|
88 | ipv6_add_addr_on_device $DEVICE $IPV6ADDR || exit 1 |
---|
89 | fi |
---|
90 | |
---|
91 | # Get current global IPv6 forwarding |
---|
92 | ipv6_global_forwarding_current="`ipv6_exec_sysctl -n net.ipv6.conf.all.forwarding`" |
---|
93 | |
---|
94 | # Set some proc switches depending on defines |
---|
95 | if [ "$IPV6FORWARDING" = "yes" ]; then |
---|
96 | # Global forwarding should be enabled |
---|
97 | |
---|
98 | # Check, if global IPv6 forwarding was already set by global script |
---|
99 | if [ $ipv6_global_forwarding_current -ne 1 ]; then |
---|
100 | echo $"Global IPv6 forwarding is enabled in configuration, but not currently enabled in kernel" |
---|
101 | echo $"Please restart network with '/sbin/service network restart'" |
---|
102 | fi |
---|
103 | |
---|
104 | ipv6_local_forwarding=1 |
---|
105 | ipv6_local_auto=0 |
---|
106 | if [ "$IPV6_ROUTER" = "no" ]; then |
---|
107 | ipv6_local_forwarding=0 |
---|
108 | fi |
---|
109 | if [ "$IPV6_AUTOCONF" = "yes" ]; then |
---|
110 | ipv6_local_auto=1 |
---|
111 | fi |
---|
112 | else |
---|
113 | # Global forwarding should be disabled |
---|
114 | |
---|
115 | # Check, if global IPv6 forwarding was already set by global script |
---|
116 | if [ $ipv6_global_forwarding_current -ne 0 ]; then |
---|
117 | echo $"Global IPv6 forwarding is disabled in configuration, but not currently disabled in kernel" |
---|
118 | echo $"Please restart network with '/sbin/service network restart'" |
---|
119 | fi |
---|
120 | |
---|
121 | ipv6_local_forwarding=0 |
---|
122 | ipv6_local_auto=1 |
---|
123 | if [ "$IPV6_AUTOCONF" = "no" ]; then |
---|
124 | ipv6_local_auto=0 |
---|
125 | fi |
---|
126 | fi |
---|
127 | ipv6_exec_sysctl -w net.ipv6.conf.$DEVICE.forwarding=$ipv6_local_forwarding >/dev/null 2>&1 |
---|
128 | ipv6_exec_sysctl -w net.ipv6.conf.$DEVICE.accept_ra=$ipv6_local_auto >/dev/null 2>&1 |
---|
129 | ipv6_exec_sysctl -w net.ipv6.conf.$DEVICE.accept_redirects=$ipv6_local_auto >/dev/null 2>&1 |
---|
130 | |
---|
131 | # Set IPv6 MTU, if given |
---|
132 | if [ -n "$IPV6_MTU" ]; then |
---|
133 | ipv6_set_mtu $DEVICE $IPV6_MTU |
---|
134 | fi |
---|
135 | |
---|
136 | # Setup additional IPv6 addresses from list, if given |
---|
137 | if [ -n "$IPV6ADDR_SECONDARIES" ]; then |
---|
138 | for ipv6addr in $IPV6ADDR_SECONDARIES; do |
---|
139 | ipv6_add_addr_on_device $DEVICE $ipv6addr |
---|
140 | done |
---|
141 | fi |
---|
142 | |
---|
143 | # Enable IPv6 RFC3041 privacy extensions if desired |
---|
144 | if [ "$IPV6_PRIVACY" = "rfc3041" ]; then |
---|
145 | ipv6_exec_sysctl -w net.ipv6.conf.$DEVICE.use_tempaddr=2 >/dev/null 2>&1 |
---|
146 | if [ $? -ne 0 ]; then |
---|
147 | echo $"Cannot enable IPv6 privacy method '$IPV6_PRIVACY', not supported by kernel" |
---|
148 | fi |
---|
149 | fi |
---|
150 | |
---|
151 | # Setup default IPv6 route, check are done by function |
---|
152 | if [ -n "$IPV6_DEFAULTDEV" -o -n "$IPV6_DEFAULTGW" ]; then |
---|
153 | ipv6_set_default_route "$IPV6_DEFAULTGW" "$IPV6_DEFAULTDEV" "$DEVICE" |
---|
154 | fi |
---|
155 | |
---|
156 | # Setup additional static IPv6 routes on specified interface, if given |
---|
157 | if [ -f /etc/sysconfig/static-routes-ipv6 ]; then |
---|
158 | LC_ALL=C grep -w "^$DEVICE" /etc/sysconfig/static-routes-ipv6 | while read device args; do |
---|
159 | ipv6_add_route $args $DEVICE |
---|
160 | done |
---|
161 | fi |
---|
162 | |
---|
163 | # Setup additional static IPv6 routes (newer config style) |
---|
164 | if [ -f "/etc/sysconfig/network-scripts/route6-$DEVICE" ]; then |
---|
165 | cat "/etc/sysconfig/network-scripts/route6-$DEVICE" | sed 's/#.*//g' | grep -v '^[[:space:]]*$' | while read line; do |
---|
166 | ipv6_exec_ip -6 route add $line |
---|
167 | done |
---|
168 | fi |
---|
169 | |
---|
170 | # Setup of 6to4, if configured |
---|
171 | if [ "$IPV6TO4INIT" = "yes" ]; then |
---|
172 | valid6to4config="yes" |
---|
173 | |
---|
174 | # Test device status of 6to4 tunnel |
---|
175 | ipv6_test_device_status tun6to4 |
---|
176 | if [ $? = 0 ]; then |
---|
177 | # device is already up |
---|
178 | echo $"Device 'tun6to4' (from '$DEVICE') is already up, shutdown first" |
---|
179 | exit 1 |
---|
180 | fi |
---|
181 | |
---|
182 | # Get IPv4 address for global 6to4 prefix calculation |
---|
183 | if [ -n "$IPV6TO4_IPV4ADDR" ]; then |
---|
184 | # Take special configured from config file (precedence 1) |
---|
185 | ipv4addr="$IPV6TO4_IPV4ADDR" |
---|
186 | |
---|
187 | # Get local IPv4 address from interface |
---|
188 | ipv4addrlocal="`ipv6_get_ipv4addr_of_device $DEVICE`" |
---|
189 | if [ -z "$ipv4addrlocal" ]; then |
---|
190 | # Take configured from config file |
---|
191 | ipv4addrlocal="$IPADDR" |
---|
192 | fi |
---|
193 | else |
---|
194 | # Get IPv4 address from interface first (has precedence 2) |
---|
195 | ipv4addr="`ipv6_get_ipv4addr_of_device $DEVICE`" |
---|
196 | if [ -z "$ipv4addr" ]; then |
---|
197 | # Take configured from config file (precedence 3) |
---|
198 | ipv4addr="$IPADDR" |
---|
199 | fi |
---|
200 | ipv4addrlocal="$ipv4addr" |
---|
201 | fi |
---|
202 | |
---|
203 | if [ -n "$ipv4addr" ]; then |
---|
204 | if ! ipv6_test_ipv4_addr_global_usable $ipv4addr; then |
---|
205 | echo $"Given IPv4 address '$ipv4addr' is not globally usable" |
---|
206 | valid6to4config="no" |
---|
207 | fi |
---|
208 | if [ -z "$IPV6TO4_RELAY" ]; then |
---|
209 | IPV6TO4_RELAY="192.88.99.1" |
---|
210 | fi |
---|
211 | |
---|
212 | # Check/generate relay address |
---|
213 | ipv6to4_relay="`ipv6_create_6to4_relay_address $IPV6TO4_RELAY`" |
---|
214 | if [ $? -ne 0 ]; then |
---|
215 | valid6to4config="no" |
---|
216 | fi |
---|
217 | else |
---|
218 | echo $"IPv6to4 configuration needs an IPv4 address on related interface or otherwise specified" |
---|
219 | valid6to4config="no" |
---|
220 | fi |
---|
221 | |
---|
222 | # Setup 6to4 tunnel (hardwired name is "tun6to4"), if config is valid |
---|
223 | if [ "$valid6to4config" = "yes" ]; then |
---|
224 | # Get MTU of master device |
---|
225 | ipv4mtu="`ipv6_exec_ip link show dev $DEVICE | grep -w "mtu" | awk '{ print $5 }'`" |
---|
226 | if [ -n "$ipv4mtu" ]; then |
---|
227 | # IPv6 tunnel MTU is IPv4 MTU minus 20 for IPv4 header |
---|
228 | tunnelmtu=$[ $ipv4mtu - 20 ] |
---|
229 | fi |
---|
230 | |
---|
231 | if [ -n "$IPV6TO4_MTU" ]; then |
---|
232 | if [ $IPV6TO4_MTU -gt $tunnelmtu ]; then |
---|
233 | echo $"Warning: configured MTU '$IPV6TO4_MTU' for 6to4 exceeds maximum limit of '$tunnelmtu', ignored" |
---|
234 | else |
---|
235 | tunnelmtu=$IPV6TO4_MTU |
---|
236 | fi |
---|
237 | fi |
---|
238 | |
---|
239 | ipv6_add_6to4_tunnel tun6to4 $ipv4addr "" $tunnelmtu $ipv4addrlocal || exit 1 |
---|
240 | |
---|
241 | # Add route to for compatible addresses (removed later again) |
---|
242 | ipv6_add_route "::/96" "::" tun6to4 |
---|
243 | |
---|
244 | # Add default route, if device matches |
---|
245 | if [ "$IPV6_DEFAULTDEV" = "tun6to4" ]; then |
---|
246 | if [ -n "$IPV6_DEFAULTGW" ]; then |
---|
247 | echo $"Warning: interface 'tun6to4' does not support 'IPV6_DEFAULTGW', ignored" |
---|
248 | fi |
---|
249 | ipv6_set_default_route $ipv6to4_relay tun6to4 |
---|
250 | fi |
---|
251 | |
---|
252 | # Add static routes |
---|
253 | if [ -f /etc/sysconfig/static-routes-ipv6 ]; then |
---|
254 | LC_ALL=C grep -w "^tun6to4" /etc/sysconfig/static-routes-ipv6 | while read device network gateway; do |
---|
255 | if [ -z "$network" ]; then |
---|
256 | continue |
---|
257 | fi |
---|
258 | if [ -z "$gateway" ]; then |
---|
259 | gateway="$ipv6to4_relay" |
---|
260 | fi |
---|
261 | ipv6_add_route $network $gateway tun6to4 |
---|
262 | done |
---|
263 | fi |
---|
264 | |
---|
265 | # Setup additional static IPv6 routes (newer config style) |
---|
266 | if [ -f "/etc/sysconfig/network-scripts/route6-tun6to4" ]; then |
---|
267 | cat "/etc/sysconfig/network-scripts/route6-tun6to4" | sed 's/#.*//g' | LC_ALL=C grep -v '^[[:space:]]*$' | while read line; do |
---|
268 | if echo "$line" | LC_ALL=C grep -vq 'via'; then |
---|
269 | # Add gateway if missing |
---|
270 | line="$line via $ipv6to4_relay" |
---|
271 | fi |
---|
272 | ipv6_exec_ip -6 route add $line |
---|
273 | done |
---|
274 | fi |
---|
275 | |
---|
276 | # Cleanup autmatically generated autotunnel (not needed for 6to4) |
---|
277 | ipv6_del_route "::/96" "::" tun6to4 |
---|
278 | ipv6_del_addr_on_device tun6to4 "::$ipv4addrlocal/128" |
---|
279 | |
---|
280 | if [ "$IPV6_CONTROL_RADVD" = "yes" ]; then |
---|
281 | # RADVD is in use, so forwarding of IPv6 packets should be enabled, display warning |
---|
282 | if [ $ipv6_global_forwarding_current -ne 1 ]; then |
---|
283 | echo $"Using 6to4 and RADVD IPv6 forwarding usually should be enabled, but it isn't" |
---|
284 | fi |
---|
285 | |
---|
286 | if [ -n "$IPV6TO4_ROUTING" ]; then |
---|
287 | ipv6to4prefix="`ipv6_create_6to4_prefix $ipv4addr`" |
---|
288 | if [ -n "$ipv6to4prefix" ]; then |
---|
289 | # Add route to local networks |
---|
290 | for devsuf in $IPV6TO4_ROUTING; do |
---|
291 | dev="`echo $devsuf | awk -F- '{ print $1 }'`" |
---|
292 | suf="`echo $devsuf | awk -F- '{ print $2 }'`" |
---|
293 | ipv6_add_addr_on_device ${dev} ${ipv6to4prefix}${suf} |
---|
294 | done |
---|
295 | else |
---|
296 | echo $"Error occurred while calculating the IPv6to4 prefix" |
---|
297 | fi |
---|
298 | else |
---|
299 | echo $"radvd control enabled, but config is not complete" |
---|
300 | fi |
---|
301 | |
---|
302 | # Control running radvd |
---|
303 | ipv6_trigger_radvd up "$IPV6_RADVD_TRIGGER_ACTION" $IPV6_RADVD_PIDFILE |
---|
304 | fi |
---|
305 | else |
---|
306 | echo $"6to4 configuration is not valid" |
---|
307 | exit 1 |
---|
308 | fi |
---|
309 | fi |
---|
310 | |
---|