#!/bin/sh

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

get_gateways()
{
	config_get gateway $1 gateway
	append gateways $gateway
}

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 ];then
			/etc/init.d/static_route restart
			return
		fi
	done

	config_foreach get_gateways route

	for gateway in $gateways; do
		if [ "$gateway" == "$IPREMOTE" ]; then
			/etc/init.d/static_route restart
			return
		fi
	done
}

. /lib/zone/zone_api.sh
. /lib/route/route_api.sh

if [[ -z $INTERFACE ]]; then
    [ -z $DEVICE ] && exit 0
    INTERFACE=$(zone_get_iface_bydev $DEVICE)
fi
[ -z $INTERFACE ] && exit 0

case "$ACTION" in
        ifup)			
			check_inface_reset_static_route
        ;;
        ifdown)		
			check_inface_reset_static_route
        ;;
        ifupdate)
                # do nothing
        ;;
esac



