#!/bin/sh

#
# Check whether this script is running on SRM (Synology Router Manager)
# or not.
#
# @return
#       0: this is SRM
#       1: this is not SRM
#
is_SRM()
{
	local os_name=`get_key_value /etc.defaults/synoinfo.conf os_name`

	if [ "xSRM" == "x${os_name}" ]; then
		return 0
	fi

	return 1
}

is_wired_backhaul_interface()
{
	local IFNAME="$1"

	if echo "${IFNAME}" | grep -qE "^eth1.1733$"; then
		return 0
	fi

	return 1
}

is_topology_wan_interface()
{
	local IFNAME="$1"

	max_wan_index=1
	for index in $(seq 0 ${max_wan_index}); do
		if [ "$(/usr/syno/sbin/synonettool --wan --is-enabled --index ${index})" != "true" ]; then
			continue
		fi
		if [ "$(/usr/syno/sbin/synonettool --wan --ifname ${index})" = "${IFNAME}" ]; then
			return 0
		fi
	done

	return 1
}

is_6in4_interface()
{
	local IFNAME="$1"

	echo ${IFNAME} | grep -q "^6in4-"
	if [ $? -eq 0 ]; then
		return 0
	fi
	return 1
}

# return 0: found
#	else: not found
is_3glte_interface()
{
	local IFNAME="$1"

	local usbif_name=`/bin/get_key_value /tmp/usbmodem.info* USBNET_IFNAME`
	if [ "x${IFNAME}" == "x${usbif_name}" ]; then
		return 0
	fi
	echo ${IFNAME} | grep -q "^usbnet"
	if [ $? -eq 0 ]; then
		return 0
	fi
	return 1
}

# return    0: need to be filtered
#        else: irrelevant interface, or not need to be filtered
is_iptv_non_gateway_interface()
{
	local IFNAME="$1"
	local WAN1=$(get_key_value /usr/syno/etc/wan.conf WAN1)
	local WAN2=$(get_key_value /usr/syno/etc/wan.conf WAN2)

	# rt1900 does not have vlan configs, skip
	if [ "x`uname -u`" == "xsynology_northstarplus_rt1900ac" ]; then
		return 1
	fi

	if [ "${IFNAME}" = "${WAN1}" ] || [ "${IFNAME}" = "${WAN2}" ]; then
		return 1
	fi

	return 0
}

