#!/bin/sh

# Situations when there is no need to start ddns.
( [ "$INTERFACE" == "lan" ] || [ "$INTERFACE" == "lanv6" ] ) && exit 0

. /usr/lib/ddns/dynamic_dns_functions.sh

if [ "$ACTION" = "ifup" ]; then
	/etc/init.d/ddns reload
	#start_daemon_for_all_ddns_sections "$INTERFACE"
fi

if [ "$ACTION" = "ifdown" ]; then
	if [ "$INTERFACE" = "wanb" ] || [ "$INTERFACE" = "wanbv6" ]; then
		wan_state=$(ubus call network.interface.wan status | grep "\"state\"" | grep "dis")
		access_mode=$(uci get accessmode.accessmode.mode)
		if [ "$access_mode" = "ewan" ] && [ -z "$wan_state" ]; then
			exit 0
		fi
	fi
	config_clear
	SECTIONS=""
	config_cb()
	{
		SECTIONS="$SECTIONS $2"
	}
	config_load ddns
	for section in $SECTIONS
	do
		ddns stop "$section"
	done
	config_clear
fi