source: projects/initscripts/tags/initscripts-8.91.3/ppp/ip-up.ipv6to4 @ 1108

Revision 1108, 6.3 KB checked in by daisuke, 14 years ago (diff)

import initscripts-8.90.6 from internal cvs repository

Line 
1#!/bin/sh
2#
3# ip-up.ipv6to4
4#
5#
6# Taken from:
7# (P) & (C) 2000-2005 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# Version: 2005-09-22
13#
14# Calling parameters:
15#  $1: interface name
16#
17# Called (mostly) by /etc/ppp/ip-up.local
18#  like: /etc/ppp/ip-up.ipv6to4 $1 >>/var/log/ppp-ipv6to4.log 2>&1
19#
20# Note: this script will *kill* older still existing 6to4 tunnels regardless
21#        whether they were set before by another device
22#
23# Uses following information from /etc/sysconfig/network-scripts/ifcfg-$1:
24#  IPV6TO4INIT=yes|no: controls configuration
25#  IPV6TO4_IPV4ADDR=<IPv4 address>: special local address for 6to4 tunneling (only needed behind a NAT gateway)
26#  IPV6TO4_RELAY=<IPv4 address>: remote 6to4 relay router address (default: 192.88.99.1)
27#  IPV6TO4_MTU=<MTU for IPv6>: controls IPv6 MTU for the 6to4 link (optional, default is MTU of interface - 20)
28#  IPV6TO4_ROUTING="<device>-<suffix>/<prefix length> ...": information to setup additional interfaces
29#    Example: IPV6TO4_ROUTING="eth0-:f101::1/64 eth1-:f102::1/64"
30#
31#  IPV6_CONTROL_RADVD=yes|no: controls radvd triggering
32#  IPV6_RADVD_PIDFILE=<file>: PID file of radvd for sending signals, default is "/var/run/radvd/radvd.pid"
33#  IPV6_RADVD_TRIGGER_ACTION=startstop|reload|restart|SIGHUP: how to trigger radvd (optional, default is SIGHUP)
34#
35# Requirements
36#  radvd-0.6.2p3 or newer supporting option "Base6to4Interface"
37#
38
39
40if [ -z "$1" ]; then
41        echo $"Argument 1 is empty but should contain interface name - skip IPv6to4 initialization"
42        exit 1
43fi
44
45# Get global network configuration
46. /etc/sysconfig/network
47
48# Source IPv4 helper functions
49cd /etc/sysconfig/network-scripts
50. ./network-functions
51
52CONFIG=$1
53[ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIG
54source_config
55
56# IPv6 don't need aliases anymore, config is skipped
57REALDEVICE=`echo ${DEVICE} | sed 's/:.*//g'`
58[ "$DEVICE" != "$REALDEVICE" ] && exit 0
59
60if [ ! -f /etc/sysconfig/network-scripts/network-functions-ipv6 ]; then
61        exit 1
62fi
63
64. /etc/sysconfig/network-scripts/network-functions-ipv6
65
66
67# Run basic IPv6 test (and make sure the ipv6 module will be loaded), if not ok, skip IPv6 initialization
68ipv6_test || exit 1
69
70# Setup of 6to4, if configured
71valid6to4config="yes"
72if [ "$IPV6TO4INIT" = "yes" ]; then
73        if [ -n "$IPV6TO4_IPV4ADDR" ]; then
74                # Take 6to4-dedicated configured IPv4 address from config file (precedence 1)
75                ipv4addr="$IPV6TO4_IPV4ADDR"
76        else
77                # Get IPv4 address from interface (precedence 2)
78                ipv4addr="`ipv6_get_ipv4addr_of_device $DEVICE`"
79                if [ -z "$ipv4addr" ]; then
80                        # Take configured IPv4 address of interface from config file (precedence 3)
81                        ipv4addr="$IPADDR"
82                fi
83        fi
84        if [ -n "$ipv4addr" ]; then
85                # Test for non-global IPv4 address
86                if ! ipv6_test_ipv4_addr_global_usable $ipv4addr; then
87                        echo $"Given IPv4 address '$ipv4addr' is not globally usable"
88                        valid6to4config="no"
89                fi
90        else
91                echo $"IPv6to4 configuration needs an IPv4 address on related interface or otherwise specified"
92                valid6to4config="no"
93        fi
94        if [ -z "$IPV6TO4_RELAY" ]; then
95                IPV6TO4_RELAY="192.88.99.1"
96        fi
97
98        # Check/generate relay address
99        ipv6to4_relay="`ipv6_create_6to4_relay_address $IPV6TO4_RELAY`"
100        if [ $? -ne 0 ]; then
101                valid6to4config="no"
102        fi
103
104        if [ "$valid6to4config" = "yes" ]; then
105                # Delete routes to local networks
106                for devsuf in $IPV6TO4_ROUTING; do
107                        dev="`echo $devsuf | awk -F- '{ print $1 }'`"
108                        ipv6_cleanup_6to4_device $dev
109                done
110
111                # Cleanup all old data (needed, if "ip-down.ipv6to4" wasn't executed), delete all configured 6to4 address
112                ipv6_cleanup_6to4_tunnels tun6to4
113
114                # Get MTU of master device
115                ipv4mtu="`ipv6_exec_ip link show dev $DEVICE | grep -w "mtu" | awk '{ print $5 }'`"
116                if [ -n "$ipv4mtu" ]; then
117                        # IPv6 tunnel MTU is IPv4 MTU minus 20 for IPv4 header
118                        tunnelmtu=$[ $ipv4mtu - 20 ]
119                fi
120
121                if [ -n "$IPV6TO4_MTU" ]; then
122                        if [ $IPV6TO4_MTU -gt $tunnelmtu ]; then
123                                echo $"Warning: configured MTU '$IPV6TO4_MTU' for 6to4 exceeds maximum limit of '$tunnelmtu', ignored"
124                        else
125                                tunnelmtu=$IPV6TO4_MTU
126                        fi
127                fi
128
129                # Setup new data
130                ipv6_add_6to4_tunnel tun6to4 $ipv4addr "" $tunnelmtu || exit 1
131
132                # Add route to for compatible addresses (removed later again)
133                ipv6_add_route "::/96" "::" tun6to4
134
135                # Add default route, if device matches
136                if [ "$IPV6_DEFAULTDEV" = "tun6to4" ]; then
137                        if [ -n "$IPV6_DEFAULTGW" ]; then
138                                echo $"Warning: interface 'tun6to4' does not support 'IPV6_DEFAULTGW', ignored"
139                        fi
140                        ipv6_set_default_route $ipv6to4_relay tun6to4
141                fi
142
143                # Add static routes
144                if [ -f /etc/sysconfig/static-routes-ipv6 ]; then
145                        LC_ALL=C grep -w "^tun6to4" /etc/sysconfig/static-routes-ipv6 | while read device network gateway; do
146                                if [ -z "$network" ]; then
147                                        continue
148                                fi
149                                if [ -z "$gateway" ]; then
150                                        gateway="$ipv6to4_relay"
151                                fi
152                                ipv6_add_route $network $gateway tun6to4
153                        done
154                fi
155
156                # Setup additional static IPv6 routes (newer config style)
157                if [ -f "/etc/sysconfig/network-scripts/route6-tun6to4" ]; then
158                        cat "/etc/sysconfig/network-scripts/route6-tun6to4" | sed 's/#.*//g' | grep -v '^[[:space:]]*$' | while read line; do
159                                if echo "$line" | grep -vq 'via'; then
160                                        # Add gateway if missing
161                                        line="$line via $ipv6to4_relay"
162                                fi
163                                ipv6_exec_ip -6 route add $line
164                        done
165                fi
166
167                # Cleanup autmatically generated autotunnel (not needed for 6to4)
168                ipv6_del_route "::/96" "::" tun6to4
169                ipv6_del_addr_on_device tun6to4 "::$ipv4addr/128"
170
171                if [ "$IPV6_CONTROL_RADVD" = "yes" ]; then
172                        # Control running radvd
173                        ipv6_trigger_radvd up "$IPV6_RADVD_TRIGGER_ACTION" $IPV6_RADVD_PIDFILE
174
175                        if [ -n "$IPV6TO4_ROUTING" ]; then
176                                # Generate 6to4 address
177                                ipv6to4prefix="`ipv6_create_6to4_prefix $ipv4addr`"
178                                if [ -n "$ipv6to4prefix" ]; then
179                                        # Add IPv6 address to interface (required interface route will be set automatically)
180                                        for devsuf in $IPV6TO4_ROUTING; do
181                                                dev="`echo $devsuf | awk -F- '{ print $1 }'`"
182                                                suf="`echo $devsuf | awk -F- '{ print $2 }'`"
183                                                ipv6_add_addr_on_device ${dev} ${ipv6to4prefix}${suf}
184                                        done
185                                else
186                                        echo $"Error occured while calculating the IPv6to4 prefix"
187                                fi
188                        else
189                                echo $"radvd control enabled, but config is not complete"
190                        fi
191                fi
192        fi
193fi
Note: See TracBrowser for help on using the repository browser.