#!/usr/bin/bash
# NetworkManager dispatcher: apply qos-profiles when an interface with
# /etc/qos-profiles/<iface>.conf comes up, clean up when it is removed.
# Both the device and its IP interface are checked (eth0 and ppp0 for PPPoE).

action=$2
ifaces=("$1")
[[ -n ${DEVICE_IP_IFACE:-} && $DEVICE_IP_IFACE != "$1" ]] && ifaces+=("$DEVICE_IP_IFACE")

for iface in "${ifaces[@]}"; do
	[[ -n $iface && -f /etc/qos-profiles/$iface.conf ]] || continue
	case $action in
		up | reapply) /usr/libexec/qos-profiles/qos-apply start "$iface" ;;
		down) [[ -e /sys/class/net/$iface ]] || /usr/libexec/qos-profiles/qos-apply stop "$iface" ;;
	esac
done
