#!/bin/sh
echo "The PPP interface going DOWN" > /dev/console
#When wan is set to PPPOE or L2TP or PPTP, we only allow the PPP0 to communicate with outside
#so I deny all inbound packets from eth2.2 after ppp0 is up, 
#but after ppp0 become to down, we need allow all inbound packets from eth2.2 again for general operation

pppoeMode=`nvram_get 2860 wan_pppoe_mode`
l2tpMode=`nvram_get 2860 wan_l2tp_mode`
pptpMode=`nvram_get 2860 wan_pptp_mode`
lan_ip=`nvram_get 2860 lan_ipaddr`
lan_nm=`nvram_get 2860 lan_netmask`
wan_ip=`nvram_get 2860 wan_ipaddr`
wan_nm=`nvram_get 2860 wan_netmask`
wanMode=`/bin/nvram_get 2860 wanConnectionMode`
gw=`nvram_get 2860 wan_gateway`
wan_1="eth2.2"
wan_2="ppp0"

if [ "$wanMode" = "PPPOE" -o "$wanMode" = "L2TP" -o "$wanMode" = "PPTP" -o "$wanMode" = "3G" ]; then
        iptables -D PREROUTING -t nat -i eth2.2 -s 0.0.0.0/0 -d ${lan_ip}/${lan_nm} -j DROP
        iptables -D PREROUTING -t nat -i eth2.2 -p udp --sport 53 -s 0.0.0.0/0 -d ${lan_ip}/${lan_nm} -j ACCEPT
fi
#Add for recove the default after PPP disconnec - U-Media Ricky Cao on May 8 2008
if [ "$wanMode" = "RussiaPPTP" -a "$pptpMode" = "0" ]; then
        route add default gw $gw
elif [ "$wanMode" = "RussiaPPTP" -a "$pptpMode" = "1" ]; then
        #This file is generate when get IP information from DHCP before PPP session active
        var/addDefaultRoute
elif [ "$wanMode" = "L2TP" -o "$wanMode" = "RussiaL2TP" ]; then
        #L2TP will bring up another pppd daemon when ppp interface going UP.
        #So I need kill all pppd after ppp0 going DOWN otherwise system will appear duplicate pppd daemon
        #Ricky Cao on Oct. 30 2008
        killall -9 pppd
else
        :
fi

#2009.10.30 Recover Rick Cao before setting ,for delete iptable rule when Wan mode is PPP.
if [ "$wanMode" = "L2TP" -o "$wanMode" = "PPTP" ]; then
#2010.01.07 Joan.Huang End
        iptables -D PREROUTING -t nat -i eth2.2 -p udp --sport 53 -s 0.0.0.0/0 -d ${lan_ip}/${lan_nm} -j ACCEPT
fi

cat /etc/wan_resolv.conf > /etc/resolv.conf

#U-Media Ricky Cao on May 8 2008
#Remove the rule of set MSS to 1452 bytes - U-Media Ricky Cao on May 16 2008
if [ "$wanMode" = "PPPOE" ]; then
        iptables -F tcp_mss_fix
fi

#Tom.Hung 2009-11-19, add for GUI verify ppp is on or down
echo 0 > /var/ppp_status
