#!/bin/sh
#
# ifup-ipv6
#
#@-INF@# RedHat 6.2 + 7.0
#@-INF@#
#@-INF@# directory: /etc/sysconfig/network-scripts
#@-INF@#
#@-INF@# permissions: 755
#@-INF@#
#@-INF@# description: Brings up IPv6 for an interface
#
#@+RH7@# Taken from:
# (P) & (C) 2000-2001 by Peter Bieringer <pb@bieringer.de>
#
# Version 2001-02-08
#
#@-INF@#  This script is now explicitly GPL'ed (20001125, Peter Bieringer)
#@-INF@#   http://www.gnu.org/copyleft/gpl.html
#@-INF@#
#@-INF@#  Suggestions, comments and improvements are welcome!
#@-INF@#
#@-INF@#  You will find more information in the IPv6-HowTo for Linux at
#@-INF@#   http://www.bieringer.de/linux/IPv6/
#@-INF@#
#@-INF@# Changes to:
#@-INF@#  20000703: initial for a new layout
#@-INF@#  20000704: review
#@-INF@#  20000722: test for static route file
#@-INF@#  20000723: fix bug in static route selection
#@-INF@#  20000724: add missing forwarding for "all", enabled only if "all" & "perdevice"
#@-INF@#  20000731: fix misnamed function 'forwarding-ipv6-route' -> 'forwarding-ipv6'
#@-INF@#  20000816: fix because "network-functions-ipv6" function names are changed
#@-INF@#  20001125: explicitly GPL'ed
#@-INF@#  20001130: remove not needed copyright reference to RedHat
#@-INF@#  20010202: Backpatch changes done in Rawhide/initscripts-5.60-1.src.rpm by others
#@-INF@#            Tag several lines for easier stripping of unnecessary lines  
#@-INF@#            Enable support for IPV6ADDR_SECONDARIES (a list of IPv6 addresses)
#@-INF@#             remove IPV6ADDR_0 + IPV6ADDR_1 support
#@-INF@#             prefixlength can be directly specified on IPv6 address
#@-INF@#  20010203: Remove obsolete tunnel configuration
#@-INF@#  20010208: Remove backward compatibility for extra prefix length

# Filter tags (for stripping, empty lines following if all is stripped)
#  #@-DEB@#  : Additional debug code
#  #@-INF@#  : Additional information
#  #@-RH7@#  : Not necessary for RedHat 7 rawhide
#  #@+RH7@#  : Necessary for RedHat 7 rawhide 

. /etc/sysconfig/network 

cd /etc/sysconfig/network-scripts
. network-functions 

CONFIG=$1
[ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIG
source_config  

# Test if IPv6 configuration is enabled
if [ ! "$IPV6INIT" = "yes" ]; then
	# not enabled, stop here
	exit 0
fi                                                  

# Test if IPv6 is up
if [ "${NETWORKING_IPV6}" = "yes" ]; then
	if [ ! -f /etc/sysconfig/network-scripts/network-functions-ipv6 ]; then		 #@-RH7@#
		echo " You have enabled IPv6 in '/etc/sysconfig/network'"				 #@-RH7@#
		echo "  by setting 'NETWORKING_IPV6' to 'yes', but"						 #@-RH7@#
		echo "  file '/etc/sysconfig/network-scripts/network-functions-ipv6"	 #@-RH7@#
		echo "  is missing -> disabling it!"									 #@-RH7@#
        NETWORKING_IPV6=no														 #@-RH7@#
		exit 1																	 #@-RH7@#
	fi																			 #@-RH7@#

	. /etc/sysconfig/network-scripts/network-functions-ipv6
		
	# Setup IPv6 address on specified interface
	if ! [ -z "$IPV6ADDR" ]; then
		ifup_ipv6_real $DEVICE $IPV6ADDR
	fi
	
	# Switch forwarding per device like defined
	#  Packets received on selected interface are forwarded
	if ! [ -z "$IPV6FORWARDING" ]; then
		if [ "$IPV6FORWARDING" = "yes" ]; then
			forwarding_ipv6 yes $DEVICE
			# also for all (otherwise, nothing is forwarded)
			forwarding_ipv6 yes
		else
			forwarding_ipv6 no $DEVICE
		fi
	fi
		
	# Setup additional IPv6 addresses from list
	if [ ! -z "$IPV6ADDR_SECONDARIES" ]; then
		for ipv6addr in $IPV6ADDR_SECONDARIES; do
			ifup_ipv6_real $DEVICE $ipv6addr
		done
	fi

	# Setup additional static IPv6 routes on specified interface
	if [ -f /etc/sysconfig/static-routes-ipv6 ]; then
		grep "^$DEVICE" /etc/sysconfig/static-routes-ipv6 | while read device args; do
			if [ "$device" = "$DEVICE" ]; then
				ifup_ipv6_route $args $DEVICE
			fi
		done
	fi
fi 
