#!/bin/sh
#
# ifdown-ipv6
#
#@-INF@# RedHat 6.2 + 7.0
#@-INF@#
#@-INF@# directory: /etc/sysconfig/network-scripts
#@-INF@#
#@-INF@# permissions: 755
#@-INF@#
#@-INF@# description: Brings down 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: add test for static route file
#@-INF@#  20000723: fix bug in static route selection
#@-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 entries, add cleanup call at the end
#@-INF@#  20010208: Remove backward compatibility for extra prefix length

. /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

	# Delete 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
				ifdown_ipv6_route $args $DEVICE 
			fi
		done
	fi

	# Switch off forwarding per device (packets received on this
	#  interface aren't forwarded
	forwarding_ipv6 no $DEVICE

	# Delete additional IPv6 addresses from list
	if [ ! -z "$IPV6ADDR_SECONDARIES" ]; then
		for ipv6addr in $IPV6ADDR_SECONDARIES; do
			ifdown_ipv6_real $DEVICE $ipv6addr
		done
	fi
          
	# Shutdown basic configured IPv6 address on specified interface
	if ! [ -z "$IPV6ADDR" ]; then
		ifdown_ipv6_real $DEVICE $IPV6ADDR
	fi

	# Cleanup all IPv6 configuration on specified interface (prevents from kernel crashing)
	ifdown_ipv6_real_all $DEVICE
fi 
