#!/bin/sh
# Script:       S25ipv6
#
# Description:  Temporary support for IP V6
#
# Platform:     All
#
# Author:       P.Griffiths-Todd
#
#
# IPV6 configuration file lives in /opt/HAC/RSF-1/etc/ipv6.tab on BOTH
# machines. Its format is (field separator is '@'):
#
#   SERVICE@INTERFACE@IPV6_ADDRESS
#
# For example:
#
#   vol01@e1000g0@testv6
#   vol01@e1000g0@testingv6
#
# Where vol01 is the service, e1000g is the device to plumb in on and
# 'testv6' and 'testingv6' are both IPV6 addresses to bring online/offline.
#
# Place a copy of this script in /opt/HAC/RSF-1/etc/rc.appliance.c/S25ipv6 and a
# symbolic link from K75ipv6 to S25ipv6.

. /opt/HAC/bin/rsf.sh

service=${RSF_SERVICE:-"service_name"}
script="`basename $0`"
state=$1
attempt=${2:-'1'}
config="/opt/HAC/RSF-1/etc/ipv6.tab"
ipv6log="/var/log/rsfipv6.log"

function plumb_interfaces {
    action=$1

    dated_echo "IPV6 config before actions: "
    ifconfig -a6

    while read line
    do
        svc=`echo $line|awk -F@ '{print $1}'`
        dev=`echo $line|awk -F@ '{print $2}'`
        add=`echo $line|awk -F@ '{print $3}'`
        if [ "${svc}" = "${service}" ] ; then
            if [ "${action}" = "up" ] ; then
                ifconfig ${dev} inet6 plumb up >>${ipv6log} 2>&1
                ifconfig ${dev} inet6 addif ${add} up >>${ipv6log} 2>&1
            else
                ifconfig ${dev} inet6 removeif ${add} >>${ipv6log} 2>&1
            fi
        fi
    done < ${config}

    dated_echo "IPV6 config after actions: "
    ifconfig -a6
}

case "${state}" in

'start')
        dated_echo "Starting IPV6 for service:${RSF_SERVICE}."
        plumb_interfaces up
        exit ${RSF_OK}
        ;;

'stop')
        dated_echo "Stopping IPV6 for service:${RSF_SERVICE}."
        plumb_interfaces down
        exit ${RSF_OK}
        ;;

*)      echo "usage: $0 <start|stop>"
        exit ${RSF_WARN}
        ;;

esac
