#!/bin/sh

[ "$DEVICE" == "lo" ] && exit 0

get_inface_name()
{
	config_get interface $1 interface
	append interfaces $interface
}

check_inface_reset_static_route()
{
	local interfaces 

	config_load static_route

	config_foreach get_inface_name route

	[ -n "$interfaces" ] || return 

	for inface in $interfaces;do
		if [ "$inface" == $INTERFACE_ZONE ] || [ "$inface" == "NA" ];then
			/etc/init.d/static_route restart 
			return
		fi
	done	
}

. /lib/zone/zone_api.sh

INTERFACE_ZONE=`zone_get_zone_byif $INTERFACE`

case "$ACTION" in
        ifup)		
			[ -n "$INTERFACE_ZONE" ] && check_inface_reset_static_route

			if [ $INTERFACE_ZONE == "LAN" ]; then
				/etc/init.d/static_route restart 
			fi
        ;;
        ifdown)	
			[ -n "$INTERFACE" ] || [ -n "$INTERFACE_ZONE" ] && check_inface_reset_static_route
        ;;
        ifupdate)
                # do nothing
        ;;
esac



