#!/bin/sh

. /lib/functions.sh
. /lib/functions/network.sh
. /lib/mwan3/mwan3.sh

mwan3_lock "$ACTION" "mwan3rtmon"

config_load mwan3
config_get_bool enabled globals 'enabled' '0'
[ "${enabled}" -gt 0 ] || {
	mwan3_unlock "$ACTION" "mwan3rtmon"
	exit 0
}

if [ "$ACTION" = "ifup" ]; then
	mwan3_rtmon
fi

config_get_bool enabled "$INTERFACE" 'enabled' '0'
[ "${enabled}" -eq 0 ] || {
	mwan3_flush_conntrack "$INTERFACE" "$ACTION"
}

mwan3_unlock "$ACTION" "mwan3rtmon"

exit 0
