[ "$ACTION" = "ifup" ] && route -n 2>&- | grep '^0.0.0.0' 2>&- >&- && {
	lock -u /var/run/startup.lock
}

[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
	outdev="$(nvram get wan_ifname)"
	DNET=$(route -n | grep "$outdev" | awk '($2 == "0.0.0.0") { print $1 "/" $3 }' | head -n1)
	
	iptables -L -n 2>&- | grep WAN_HOOK >&- 2>&- || {
		sleep 10
		iptables -L -n 2>&- | grep WAN_HOOK >&- 2>&- || iptables -N WAN_HOOK 2>&- >&- # to avoid race conditions
	}
	iptables -F WAN_HOOK
	[ -z "$DNET" ] || iptables -I WAN_HOOK -o "$outdev" -d "$DNET" -j DROP

	# For IP conflict detection
	. /etc/functions.sh
	wan_ip=$(nvram get ${INTERFACE}_ipaddr)
	wan_ip=${lan_ip:-$(ifconfig $(nvram get ${INTERFACE}_ifname) | grep "inet addr:" | awk '{ print $2}' | cut -d: -f2)}
	new_ip=$(echo $wan_ip | cut -d. -f1).$(echo $wan_ip | cut -d. -f2).$(($(echo $wan_ip | cut -d. -f 3)+1)).$(echo $wan_ip | cut -d. -f4)
	ip_conflict "lan" "$new_ip"
	ifdown lan
	ifup lan
}
