[ "$ACTION" = "ifup" ] || exit 0

DEFAULT_L3_IFACE=$(ip route show default 0.0.0.0/0 | awk '{print $5}' | head -n1)
[ -n "$DEFAULT_L3_IFACE" ] || exit 0

UCI_INTERFACE=""
for name in $(ubus list 'network.interface.*' | cut -d. -f3); do
	L3=$(ubus call network.interface.$name status | jsonfilter -e '@.l3_device')
	if [ "$L3" = "$DEFAULT_L3_IFACE" ]; then
		UCI_INTERFACE="$name"
		break
	fi
done

if [ "$INTERFACE" = "$UCI_INTERFACE" ] || [ "$INTERFACE" = "$DEFAULT_L3_IFACE" ]; then
	kill -HUP $(pidof dns-failsafe-proxy 2>/dev/null)
fi
