. /etc/functions.sh
set_wan_ip_alias() {
	local ENABLE
	local IDX
	local WANIF
	
	config_get_bool ENABLE  $1	enable  0
	config_get ALIAS_IP $1 alias_ip "0.0.0.0"
	config_get IDX $1 idx
	[ "$ALIAS_IP" == "0.0.0.0" ] && return
	WANIF=$(uci -q -P /var/state get network.wan.ifname || echo "br-wan")
	MASK=$(uci -q -P /var/state get network.wan.netmask || echo "255.255.255.0")
	
	if [ $ENABLE -eq 1 ]; then
		logger "[WAN] ifconfig $WANIF:$IDX $ALIAS_IP netmask $MASK up"
		ifconfig "$WANIF":"$IDX" "$ALIAS_IP" netmask "$MASK" up
	else
		logger "[WAN] ifconfig $WANIF:$IDX $ALIAS_IP down"
		ifconfig "$WANIF":"$IDX" "$ALIAS_IP" down
	fi
}

[ "$INTERFACE" == "wan" ] && {
	case "$ACTION" in
		ifup)
			# Add WAN IP alias
			if [ -f /etc/config/wan_ip_alias ]; then
					config_load /etc/config/wan_ip_alias
					config_foreach set_wan_ip_alias wanip-alias
			fi
		;;
	esac
}