Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 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
REALDEVICE=${DEVICE%%:*}
66
DEVICE=$REALDEVICE
67
 
68
# Test whether IPv6 configuration is enabled for this interface, else stop
69
[ "$IPV6INIT" = "yes" ] || exit 0
70
 
71
[ -f /etc/sysconfig/network-scripts/network-functions-ipv6 ] || exit 1
72
. /etc/sysconfig/network-scripts/network-functions-ipv6
73
 
74
 
75
# IPv6 test, module loaded, exit if system is not IPv6-ready
76
ipv6_test || exit 1
77
 
78
# Test device status
79
ipv6_test_device_status $DEVICE
80
if [ $? != 0 -a $? != 11 ]; then
81
	# device doesn't exist or other problem occurs
82
	exit 1
83
fi
84
 
85
# Setup IPv6 address on specified interface
86
if [ -n "$IPV6ADDR" ]; then
87
	ipv6_add_addr_on_device $DEVICE $IPV6ADDR || exit 1
88
fi
89
 
90
# Get current global IPv6 forwarding
91
ipv6_global_forwarding_current="$(/sbin/sysctl -e -n net.ipv6.conf.all.forwarding)"
92
 
93
# Set some proc switches depending on defines
94
if [ "$IPV6FORWARDING" = "yes" ]; then
95
	# Global forwarding should be enabled
96
 
97
	# Check, if global IPv6 forwarding was already set by global script
98
	if [ $ipv6_global_forwarding_current -ne 1 ]; then
99
		net_log $"Global IPv6 forwarding is enabled in configuration, but not currently enabled in kernel"
100
		net_log $"Please restart network with '/sbin/service network restart'"
101
	fi
102
 
103
	ipv6_local_forwarding=1
104
	ipv6_local_auto=0
105
	if [ "$IPV6_ROUTER" = "no" ]; then
106
		ipv6_local_forwarding=0
107
	fi
108
	if [ "$IPV6_AUTOCONF" = "yes" ]; then
109
		ipv6_local_auto=1
110
	fi
111
else
112
	# Global forwarding should be disabled
113
 
114
	# Check, if global IPv6 forwarding was already set by global script
115
	if [ $ipv6_global_forwarding_current -ne 0 ]; then
116
		net_log $"Global IPv6 forwarding is disabled in configuration, but not currently disabled in kernel"
117
		net_log $"Please restart network with '/sbin/service network restart'"
118
	fi
119
 
120
	ipv6_local_forwarding=0
121
	ipv6_local_auto=1
122
	if [ "$IPV6_AUTOCONF" = "no" ]; then
123
		ipv6_local_auto=0
124
	fi
125
fi
126
/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.forwarding=$ipv6_local_forwarding >/dev/null 2>&1
127
/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.accept_ra=$ipv6_local_auto >/dev/null 2>&1
128
/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.accept_redirects=$ipv6_local_auto >/dev/null 2>&1
129
/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.autoconf=$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
	/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.use_tempaddr=2 >/dev/null 2>&1
146
	if [ $? -ne 0 ]; then
147
		net_log $"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 of 6to4, if configured
164
if [ "$IPV6TO4INIT" = "yes" ]; then
165
	valid6to4config="yes"
166
 
167
	# Test device status of 6to4 tunnel
168
	ipv6_test_device_status tun6to4
169
	if [ $? = 0 ]; then
170
		# device is already up
171
		net_log $"Device 'tun6to4' (from '$DEVICE') is already up, shutdown first"
172
		exit 1
173
	fi
174
 
175
	# Get IPv4 address for global 6to4 prefix calculation
176
	if [ -n "$IPV6TO4_IPV4ADDR" ]; then
177
		# Take special configured from config file (precedence 1)
178
		ipv4addr="$IPV6TO4_IPV4ADDR"
179
 
180
		# Get local IPv4 address from interface
181
		ipv4addrlocal="$(ipv6_get_ipv4addr_of_device $DEVICE)"
182
		if [ -z "$ipv4addrlocal" ]; then
183
			# Take configured from config file
184
			ipv4addrlocal="$IPADDR"
185
		fi
186
        else
187
		# Get IPv4 address from interface first (has precedence 2)
188
		ipv4addr="$(ipv6_get_ipv4addr_of_device $DEVICE)"
189
		if [ -z "$ipv4addr" ]; then
190
			# Take configured from config file (precedence 3)
191
			ipv4addr="$IPADDR"
192
		fi
193
		ipv4addrlocal="$ipv4addr"
194
        fi
195
 
196
	if [ -n "$ipv4addr" ]; then
197
		if ! ipv6_test_ipv4_addr_global_usable $ipv4addr; then
198
			net_log $"Given IPv4 address '$ipv4addr' is not globally usable" info
199
	                valid6to4config="no"
200
        	fi
201
		if [ -z "$IPV6TO4_RELAY" ]; then
202
			IPV6TO4_RELAY="192.88.99.1"
203
		fi
204
 
205
		# Check/generate relay address
206
		ipv6to4_relay="$(ipv6_create_6to4_relay_address $IPV6TO4_RELAY)"
207
		if [ $? -ne 0 ]; then
208
			valid6to4config="no"
209
		fi
210
	else
211
        	net_log $"IPv6to4 configuration needs an IPv4 address on related interface or otherwise specified" info
212
		valid6to4config="no"
213
	fi
214
 
215
	# Setup 6to4 tunnel (hardwired name is "tun6to4"), if config is valid
216
        if [ "$valid6to4config" = "yes" ]; then
217
		# Get MTU of master device
218
		ipv4mtu="$(/sbin/ip link show dev $DEVICE | grep -w "mtu" | awk '{ print $5 }')"
219
		if [ -n "$ipv4mtu" ]; then
220
			# IPv6 tunnel MTU is IPv4 MTU minus 20 for IPv4 header
221
			tunnelmtu=$(($ipv4mtu-20))
222
		fi
223
 
224
		if [ -n "$IPV6TO4_MTU" ]; then
225
			if [ $IPV6TO4_MTU -gt $tunnelmtu ]; then
226
				net_log $"Warning: configured MTU '$IPV6TO4_MTU' for 6to4 exceeds maximum limit of '$tunnelmtu', ignored" warning
227
			else
228
				tunnelmtu=$IPV6TO4_MTU
229
			fi
230
		fi
231
 
232
		ipv6_add_6to4_tunnel tun6to4 $ipv4addr "" $tunnelmtu $ipv4addrlocal || exit 1
233
 
234
		# Add route to for compatible addresses (removed later again)
235
		ipv6_add_route "::/96" "::" tun6to4
236
 
237
		# Add default route, if device matches
238
		if [ "$IPV6_DEFAULTDEV" = "tun6to4" ]; then
239
			if [ -n "$IPV6_DEFAULTGW" ]; then
240
				net_log $"Warning: interface 'tun6to4' does not support 'IPV6_DEFAULTGW', ignored" warning
241
			fi
242
			ipv6_set_default_route $ipv6to4_relay tun6to4
243
		fi
244
 
245
		# Add static routes
246
		if [ -f /etc/sysconfig/static-routes-ipv6 ]; then
247
			LC_ALL=C grep -w "^tun6to4" /etc/sysconfig/static-routes-ipv6 | while read device network gateway; do
248
				if [ -z "$network" ]; then
249
					continue
250
				fi
251
				if [ -z "$gateway" ]; then
252
					gateway="$ipv6to4_relay"
253
				fi
254
				ipv6_add_route $network $gateway tun6to4
255
			done
256
		fi
257
 
258
		# Setup additional static IPv6 routes (newer config style)
259
		if [ -f "/etc/sysconfig/network-scripts/route6-tun6to4" ]; then
260
			cat "/etc/sysconfig/network-scripts/route6-tun6to4" | sed 's/#.*//g' | LC_ALL=C grep -v '^[[:space:]]*$' | while read line; do
261
				if echo "$line" | LC_ALL=C grep -vq 'via'; then
262
					# Add gateway if missing
263
					line="$line via $ipv6to4_relay"
264
				fi
265
				/sbin/ip -6 route add $line
266
			done
267
		fi
268
 
269
		# Cleanup autmatically generated autotunnel (not needed for 6to4)
270
		/sbin/ip -6 route del ::/96 dev tun6to4
271
		/sbin/ip -6 addr del "::$ipv4addrlocal/128" dev tun6to4
272
 
273
	        if [ "$IPV6_CONTROL_RADVD" = "yes" ]; then
274
			# RADVD is in use, so forwarding of IPv6 packets should be enabled, display warning
275
			if [ $ipv6_global_forwarding_current -ne 1 ]; then
276
				net_log $"Using 6to4 and RADVD IPv6 forwarding usually should be enabled, but it isn't" warning
277
			fi
278
 
279
		        if [ -n "$IPV6TO4_ROUTING" ]; then
280
				ipv6to4prefix="$(ipv6_create_6to4_prefix $ipv4addr)"
281
				if [ -n "$ipv6to4prefix" ]; then
282
					# Add route to local networks
283
					for devsuf in $IPV6TO4_ROUTING; do
284
						dev="$(echo $devsuf | awk -F- '{ print $1 }')"
285
						suf="$(echo $devsuf | awk -F- '{ print $2 }')"
286
						ipv6_add_addr_on_device ${dev} ${ipv6to4prefix}${suf}
287
					done
288
				else
289
					net_log $"Error occurred while calculating the IPv6to4 prefix"
290
				fi
291
			else
292
				net_log $"radvd control enabled, but config is not complete"
293
			fi
294
 
295
			# Control running radvd
296
			ipv6_trigger_radvd up "$IPV6_RADVD_TRIGGER_ACTION" $IPV6_RADVD_PIDFILE
297
		fi
298
	else
299
		net_log $"6to4 configuration is not valid"
300
		exit 1
301
        fi
302
fi
303