#!/bin/sh
# Restart DHCPv6 negotiation when a NetworkManager connection changes state.

case "${2:-}" in
    up|vpn-up) action=start ;;
    down|vpn-down) action=stop ;;
    *) exit 0 ;;
esac

[ -n "${1:-}" ] && [ "$1" != lo ] || exit 0
# Externally configured connections may already have run ifupdown hooks.
[ "${CONNECTION_EXTERNAL:-0}" != 1 ] || exit 0
[ -r /etc/default/wide-dhcpv6-client ] || exit 0
[ -x /usr/sbin/dhcp6ctl ] || exit 0
pidof dhcp6c >/dev/null 2>&1 || exit 0

INTERFACES=
. /etc/default/wide-dhcpv6-client

# Interface names are literal values, not shell patterns.
set -f
for interface in $INTERFACES; do
    if [ "$interface" = "$1" ]; then
        exec /usr/sbin/dhcp6ctl "$action" interface "$1"
    fi
done

exit 0
