Blame | Last modification | View Log | RSS feed
#!/bin/sh## ifup-ipv6### Taken from:# (P) & (C) 2000-2006 by Peter Bieringer <pb@bieringer.de>## You will find more information on the initscripts-ipv6 homepage at# http://www.deepspace6.net/projects/initscripts-ipv6.html## RHL integration assistance by Pekka Savola <pekkas@netcore.fi>## Version: 2006-07-20## Note: if called (like normally) by /etc/sysconfig/network-scripts/ifup# exit codes aren't handled by "ifup"## Uses following information from "/etc/sysconfig/network":# IPV6_DEFAULTDEV=<device>: controls default route (optional)# IPV6_DEFAULTGW=<address>: controls default route (optional)## Uses following information from "/etc/sysconfig/network-scripts/ifcfg-$1":# IPV6INIT=yes|no: controls IPv6 configuration for this interface# IPV6ADDR=<IPv6 address>[/<prefix length>]: specify primary static IPv6 address# IPV6ADDR_SECONDARIES="<IPv6 address>[/<prefix length>] ..." (optional)# IPV6_ROUTER=yes|no: controls IPv6 autoconfiguration (no: multi-homed interface without routing)# IPV6_AUTOCONF=yes|no: controls IPv6 autoconfiguration# defaults:# IPV6FORWARDING=yes: IPV6_AUTOCONF=no, IPV6_ROUTER=yes# IPV6FORWARDING=no: IPV6_AUTOCONF=yes# IPV6_MTU=<MTU for IPv6>: controls IPv6 MTU for this link (optional)# IPV6_PRIVACY="rfc3041": control IPv6 privacy (optional)# This script only supports "rfc3041" (if kernel supports it)## Optional for 6to4 tunneling (hardwired name of tunnel device is "tun6to4"):# IPV6TO4INIT=yes|no: controls 6to4 tunneling setup# IPV6TO4_RELAY=<IPv4 address>: IPv4 address of the remote 6to4 relay (default: 192.88.99.1)# IPV6TO4_MTU=<MTU for IPv6>: controls IPv6 MTU for the 6to4 link (optional, default is MTU of interface - 20)# IPV6TO4_IPV4ADDR=<IPv4 address>: overwrite local IPv4 address (optional)# IPV6TO4_ROUTING="<device>-<suffix>/<prefix length> ...": information to setup additional interfaces# Example: IPV6TO4_ROUTING="eth0-:f101::1/64 eth1-:f102::1/64"## Optional for 6to4 tunneling to trigger radvd:# IPV6_CONTROL_RADVD=yes|no: controls radvd triggering (optional)# IPV6_RADVD_PIDFILE=<file>: PID file of radvd for sending signals, default is "/var/run/radvd/radvd.pid" (optional)# IPV6_RADVD_TRIGGER_ACTION=startstop|reload|restart|SIGHUP: how to trigger radvd (optional, default is SIGHUP)## Required version of radvd to use 6to4 prefix recalculation# 0.6.2p3 or newer supporting option "Base6to4Interface"# Required version of radvd to use dynamic ppp links# 0.7.0 + fixes or newer#. /etc/sysconfig/networkcd /etc/sysconfig/network-scripts. ./network-functionsCONFIG=$1[ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIGsource_configREALDEVICE=${DEVICE%%:*}DEVICE=$REALDEVICE# Test whether IPv6 configuration is enabled for this interface, else stop[ "$IPV6INIT" = "yes" ] || exit 0[ -f /etc/sysconfig/network-scripts/network-functions-ipv6 ] || exit 1. /etc/sysconfig/network-scripts/network-functions-ipv6# IPv6 test, module loaded, exit if system is not IPv6-readyipv6_test || exit 1# Test device statusipv6_test_device_status $DEVICEif [ $? != 0 -a $? != 11 ]; then# device doesn't exist or other problem occursexit 1fi# Setup IPv6 address on specified interfaceif [ -n "$IPV6ADDR" ]; thenipv6_add_addr_on_device $DEVICE $IPV6ADDR || exit 1fi# Get current global IPv6 forwardingipv6_global_forwarding_current="$(/sbin/sysctl -e -n net.ipv6.conf.all.forwarding)"# Set some proc switches depending on definesif [ "$IPV6FORWARDING" = "yes" ]; then# Global forwarding should be enabled# Check, if global IPv6 forwarding was already set by global scriptif [ $ipv6_global_forwarding_current -ne 1 ]; thennet_log $"Global IPv6 forwarding is enabled in configuration, but not currently enabled in kernel"net_log $"Please restart network with '/sbin/service network restart'"fiipv6_local_forwarding=1ipv6_local_auto=0if [ "$IPV6_ROUTER" = "no" ]; thenipv6_local_forwarding=0fiif [ "$IPV6_AUTOCONF" = "yes" ]; thenipv6_local_auto=1fielse# Global forwarding should be disabled# Check, if global IPv6 forwarding was already set by global scriptif [ $ipv6_global_forwarding_current -ne 0 ]; thennet_log $"Global IPv6 forwarding is disabled in configuration, but not currently disabled in kernel"net_log $"Please restart network with '/sbin/service network restart'"fiipv6_local_forwarding=0ipv6_local_auto=1if [ "$IPV6_AUTOCONF" = "no" ]; thenipv6_local_auto=0fifi/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.forwarding=$ipv6_local_forwarding >/dev/null 2>&1/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.accept_ra=$ipv6_local_auto >/dev/null 2>&1/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.accept_redirects=$ipv6_local_auto >/dev/null 2>&1/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.autoconf=$ipv6_local_auto >/dev/null 2>&1# Set IPv6 MTU, if givenif [ -n "$IPV6_MTU" ]; thenipv6_set_mtu $DEVICE $IPV6_MTUfi# Setup additional IPv6 addresses from list, if givenif [ -n "$IPV6ADDR_SECONDARIES" ]; thenfor ipv6addr in $IPV6ADDR_SECONDARIES; doipv6_add_addr_on_device $DEVICE $ipv6addrdonefi# Enable IPv6 RFC3041 privacy extensions if desiredif [ "$IPV6_PRIVACY" = "rfc3041" ]; then/sbin/sysctl -e -w net.ipv6.conf.$SYSCTLDEVICE.use_tempaddr=2 >/dev/null 2>&1if [ $? -ne 0 ]; thennet_log $"Cannot enable IPv6 privacy method '$IPV6_PRIVACY', not supported by kernel"fifi# Setup default IPv6 route, check are done by functionif [ -n "$IPV6_DEFAULTDEV" -o -n "$IPV6_DEFAULTGW" ]; thenipv6_set_default_route "$IPV6_DEFAULTGW" "$IPV6_DEFAULTDEV" "$DEVICE"fi# Setup additional static IPv6 routes on specified interface, if givenif [ -f /etc/sysconfig/static-routes-ipv6 ]; thenLC_ALL=C grep -w "^$DEVICE" /etc/sysconfig/static-routes-ipv6 | while read device args; doipv6_add_route $args $DEVICEdonefi# Setup of 6to4, if configuredif [ "$IPV6TO4INIT" = "yes" ]; thenvalid6to4config="yes"# Test device status of 6to4 tunnelipv6_test_device_status tun6to4if [ $? = 0 ]; then# device is already upnet_log $"Device 'tun6to4' (from '$DEVICE') is already up, shutdown first"exit 1fi# Get IPv4 address for global 6to4 prefix calculationif [ -n "$IPV6TO4_IPV4ADDR" ]; then# Take special configured from config file (precedence 1)ipv4addr="$IPV6TO4_IPV4ADDR"# Get local IPv4 address from interfaceipv4addrlocal="$(ipv6_get_ipv4addr_of_device $DEVICE)"if [ -z "$ipv4addrlocal" ]; then# Take configured from config fileipv4addrlocal="$IPADDR"fielse# Get IPv4 address from interface first (has precedence 2)ipv4addr="$(ipv6_get_ipv4addr_of_device $DEVICE)"if [ -z "$ipv4addr" ]; then# Take configured from config file (precedence 3)ipv4addr="$IPADDR"fiipv4addrlocal="$ipv4addr"fiif [ -n "$ipv4addr" ]; thenif ! ipv6_test_ipv4_addr_global_usable $ipv4addr; thennet_log $"Given IPv4 address '$ipv4addr' is not globally usable" infovalid6to4config="no"fiif [ -z "$IPV6TO4_RELAY" ]; thenIPV6TO4_RELAY="192.88.99.1"fi# Check/generate relay addressipv6to4_relay="$(ipv6_create_6to4_relay_address $IPV6TO4_RELAY)"if [ $? -ne 0 ]; thenvalid6to4config="no"fielsenet_log $"IPv6to4 configuration needs an IPv4 address on related interface or otherwise specified" infovalid6to4config="no"fi# Setup 6to4 tunnel (hardwired name is "tun6to4"), if config is validif [ "$valid6to4config" = "yes" ]; then# Get MTU of master deviceipv4mtu="$(/sbin/ip link show dev $DEVICE | grep -w "mtu" | awk '{ print $5 }')"if [ -n "$ipv4mtu" ]; then# IPv6 tunnel MTU is IPv4 MTU minus 20 for IPv4 headertunnelmtu=$(($ipv4mtu-20))fiif [ -n "$IPV6TO4_MTU" ]; thenif [ $IPV6TO4_MTU -gt $tunnelmtu ]; thennet_log $"Warning: configured MTU '$IPV6TO4_MTU' for 6to4 exceeds maximum limit of '$tunnelmtu', ignored" warningelsetunnelmtu=$IPV6TO4_MTUfifiipv6_add_6to4_tunnel tun6to4 $ipv4addr "" $tunnelmtu $ipv4addrlocal || exit 1# Add route to for compatible addresses (removed later again)ipv6_add_route "::/96" "::" tun6to4# Add default route, if device matchesif [ "$IPV6_DEFAULTDEV" = "tun6to4" ]; thenif [ -n "$IPV6_DEFAULTGW" ]; thennet_log $"Warning: interface 'tun6to4' does not support 'IPV6_DEFAULTGW', ignored" warningfiipv6_set_default_route $ipv6to4_relay tun6to4fi# Add static routesif [ -f /etc/sysconfig/static-routes-ipv6 ]; thenLC_ALL=C grep -w "^tun6to4" /etc/sysconfig/static-routes-ipv6 | while read device network gateway; doif [ -z "$network" ]; thencontinuefiif [ -z "$gateway" ]; thengateway="$ipv6to4_relay"fiipv6_add_route $network $gateway tun6to4donefi# Setup additional static IPv6 routes (newer config style)if [ -f "/etc/sysconfig/network-scripts/route6-tun6to4" ]; thencat "/etc/sysconfig/network-scripts/route6-tun6to4" | sed 's/#.*//g' | LC_ALL=C grep -v '^[[:space:]]*$' | while read line; doif echo "$line" | LC_ALL=C grep -vq 'via'; then# Add gateway if missingline="$line via $ipv6to4_relay"fi/sbin/ip -6 route add $linedonefi# Cleanup autmatically generated autotunnel (not needed for 6to4)/sbin/ip -6 route del ::/96 dev tun6to4/sbin/ip -6 addr del "::$ipv4addrlocal/128" dev tun6to4if [ "$IPV6_CONTROL_RADVD" = "yes" ]; then# RADVD is in use, so forwarding of IPv6 packets should be enabled, display warningif [ $ipv6_global_forwarding_current -ne 1 ]; thennet_log $"Using 6to4 and RADVD IPv6 forwarding usually should be enabled, but it isn't" warningfiif [ -n "$IPV6TO4_ROUTING" ]; thenipv6to4prefix="$(ipv6_create_6to4_prefix $ipv4addr)"if [ -n "$ipv6to4prefix" ]; then# Add route to local networksfor devsuf in $IPV6TO4_ROUTING; dodev="$(echo $devsuf | awk -F- '{ print $1 }')"suf="$(echo $devsuf | awk -F- '{ print $2 }')"ipv6_add_addr_on_device ${dev} ${ipv6to4prefix}${suf}doneelsenet_log $"Error occurred while calculating the IPv6to4 prefix"fielsenet_log $"radvd control enabled, but config is not complete"fi# Control running radvdipv6_trigger_radvd up "$IPV6_RADVD_TRIGGER_ACTION" $IPV6_RADVD_PIDFILEfielsenet_log $"6to4 configuration is not valid"exit 1fifi