#!/bin/bash
# Re-assert EUI-64 IPv6 addressing on the uplink whenever it comes up.
#
# NetworkManager re-creates the WAN profile on every boot (auto-generated,
# often volatile under /run), and a re-created profile is back on "default",
# which resolves to stable-privacy. Without this hook the interface id would
# change again after the next reboot or prefix change, and every IPv6 opening
# in the customer's router would point at an address that no longer exists.
# Background and the measurements behind it:
# /usr/share/trutz-network/ensure-ipv6-eui64.sh

IFACE="$1"
ACTION="$2"

case "$ACTION" in
    up|dhcp6-change) : ;;
    *) exit 0 ;;
esac

# Only the uplink can carry an opening. The bridge, wifi and tunnels never do,
# and skipping them saves a pointless run on every LAN port that comes up.
case "$IFACE" in
    lo|br0|wl*|p2p-dev*|tun*|veth*) exit 0 ;;
esac

[ -x /usr/share/trutz-network/ensure-ipv6-eui64.sh ] || exit 0

# Decoupled: the script calls `nmcli device reapply`, and a dispatcher script
# must not keep NetworkManager waiting while it itself waits for NetworkManager.
setsid /usr/share/trutz-network/ensure-ipv6-eui64.sh </dev/null >/dev/null 2>&1 &
exit 0
