#!/bin/sh

[ "$LINK" = "up" -a -n "$PORT" ] || exit 0

compare_mcast_snooping_interface() {
	local interface dev running

	config_get interface "$1" interface

	for dev in $interface; do
		if [ "$PORT" = "$dev" ]; then
			running=$(ubus call service list '{"name": "mcast"}' | jsonfilter -e '@.mcast.instances')
			if [ -z "${running}" ]; then
				/etc/init.d/mcast start
			else
				ubus call uci commit '{"config":"mcast"}'
			fi
			exit
		fi
	done
}

config_load mcast
config_foreach compare_mcast_snooping_interface "snooping"
