#!/bin/sh
#
# Stop the daemon, mark interfaces down, kill routes and then unload
# the modules

DEVICE=/dev/dp0
. /etc/dp.conf

#
# Kill the daemon
#
kill -TERM `cat $DPPID_DIR/dpd`

#
# ifconfig 'down' interfaces
#
if [ -f $DPCONF_DIR/dp-if ]; then
	cat $DPCONF_DIR/dp-if | (
		while read IFNAME LOCAL REMOTE
		do
			ifconfig $IFNAME down
		done
	)
fi

#
# kill routes from netstat output
#

netstat -n -r | (
	read line1
	read line2
	while read DEST GATE FLAGS REFCNT USE INTERFACE
	do
		if [ "`echo $INTERFACE | cut -c1,2`"X = "dp"X ]; then
			route delete $DEST $GATE
		fi
	done
	)

#
# let it quiet down a bit ...
#
sleep 2

# OK - exit true
exit 0
