#!/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
wanMode=`/bin/nvram_get 2860 wanConnectionMode`
pppoeMode=`nvram_get 2860 wan_pppoe_mode`
l2tpMode=`nvram_get 2860 wan_l2tp_mode`
pptpMode=`nvram_get 2860 wan_pptp_mode`
gw=`nvram_get 2860 wan_gateway`
lan_ip=`nvram_get 2860 lan_ipaddr`
lan_nm=`nvram_get 2860 lan_netmask`
if [ "$wanMode" = "PPPOE" -o "$wanMode" = "L2TP" -o "$wanMode" = "PPTP" ]; 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" ]; 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
#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
wanmode=`nvram_get 2860 wanConnectionMode`
useDefaultMtu=`nvram_get 2860 wan_use_default_mtu`
#wanMtu=`nvram_get 2860 wan_mtu`
if [ "$wanmode" = "PPPOE" ]; then
	iptables -F tcp_mss_fix
fi