#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin

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

IP=/sbin/ip

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

if [ -z "$TUNLOCAL" ]; then
  echo "missing TUNLOCAL"; 
	exit 1
fi

[ -x "$IP" ] || {
  echo "$IP does not exist or is not executable"
  echo "ifdown-tun for $DEVICE exiting"
  logger -p daemon.info -t ifdown-iptun \
    "$IP does not exist or is not executable for $DEVICE"
  exit 1
}

$IP link set dev $DEVICE down
$IP address del $TUNLOCAL dev $DEVICE
$IP tunnel del $DEVICE
exec /etc/sysconfig/network-scripts/ifdown-post "ifcfg-$DEVICE" "$2"
