#!/bin/sh
#
# ifdown-sit
#
#@-INF@# RedHat 6.2 + 7.0
#@-INF@#
#@-INF@# directory: /etc/sysconfig/network-scripts
#@-INF@#
#@-INF@# permissions: 755
#@-INF@#
#@-INF@# description: Brings down IPv6 for tunnel interface (sitx)
#
#@+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@#  20000704: initial for a new layout
#@-INF@#  20000722: add test for static route file
#@-INF@#  20000723: handle additional static routes for tunnel device in a right way
#@-INF@#  20000731: fix misnamed function 'forwarding-ipv6-route' -> 'forwarding-ipv6'
#@-INF@#  20000816: fix because "network-functions-ipv6" function names are changed
#@-INF@#  20001004: forget one to fix...
#@-INF@#  20001125: explicitly GPL'ed
#@-INF@#  20001130: remove not needed copyright reference to RedHat
#@-INF@#  20010201: add support for sit0 (automatic tunneling only) support
#@-INF@#             you have to use functions-ipv6 from version 20010201 or newer
#@-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@#            Move forward switching to "ifdown_ipv6_autotunnel"
#@-INF@#  20010203: IPV6TUNNELROUTE is no longer used, all routes are now taken from
#@-INF@#             /etc/sysconfig/static-routes-ipv6
#@-INF@#  20010206: Add support for numbered tunnels
#@-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 for this interface
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 IPv6-in-IPv4 tunnel(s)
	if [ "$DEVICE" = "sit0" ]; then
		# Ok, bring down automatic tunneling									#@-RH7@# 
		ifdown_ipv6_autotunnel
		# Noting more to do...													#@-RH7@#
	elif [ ! -z "$IPV6TUNNELIPV4" ]; then
		# Delete static IPv6 tunnel routes on specified virtual interface
		if [ -f /etc/sysconfig/static-routes-ipv6 ]; then
			grep "^$DEVICE" /etc/sysconfig/static-routes-ipv6 | while read device ipv6route args; do
				if [ "$device" = "$DEVICE" ]; then
					ifdown_ipv6_tunnel $DEVICE $IPV6TUNNELIPV4 $ipv6route
				fi
			done
		fi

        if [ ! -z "$IPV6ADDR" ]; then
            # Numbered tunnel
            ifdown_ipv6_real sit0 $IPV6ADDR
        fi
	fi
fi 
