#!/bin/sh

source /etc/pmnetconfig/funcs

${LOG} "${CMROUTES}"
##TBL="table ${TABLE}"
TBL=""
NetCfgCalcPrio $CMINTERFACE
ISPPP=`expr $CMINTERFACE : ppp[0-9]`
ISRMNET=`expr $CMINTERFACE : rmnet[0-9]`
ISCSCOTUNVPN=`expr $CMINTERFACE : cscotun[0-9]`
ISTUN=`expr $CMINTERFACE : tun[0-9]`

if [ "$ISPPP" -ne 4 ] && [ "$ISRMNET" -ne 6 ] && [ "$ISTUN" -ne 4 ] && [ "$ISCSCOTUNVPN" -ne 8 ]; then
	NetCfgDelAddr $CMIPADDR $CMPREFIXLEN $CMINTERFACE
fi
NetCfgDelDns

# We need to delete the rule that directs all traffic
# whose source IP address matches this interface's 
# IP address to the interface-specific routing table.
NetCfgCalcTblNum $CMINTERFACE
TBL="table $CMTBLNUM"
NetCfgDelSrcRule $CMIPADDR $CMTBLNUM
NetCfgDelDnsRules $CMDNSSERVERS
NetCfgDelRoute

# Remove this interface's DNS servers from
# dnsmasq.server.conf.
NetCfgDelDnsServersForDomains

# Disable NAT and IP forwarding if BT-PAN goes down.
if [ ${CMINTERFACE} = ${CMBTINTERFACENAME} ] || [ ${CMINTERFACE} = ${CMBRINTERFACENAME} ]; then
    ${LOG} "${IPTABLES} -t nat -D POSTROUTING -s  $CMNETADDR/$CMPREFIXLEN -j MASQUERADE"
    ${IPTABLES} -t nat -D POSTROUTING -s $CMNETADDR/$CMPREFIXLEN -j MASQUERADE
    ${LOG} "${ECHO} 0 >/proc/sys/net/ipv4/ip_forward"
    ${ECHO} 0 >/proc/sys/net/ipv4/ip_forward
fi

NetCfgCommit
