#!/bin/sh
# Starchaser firewall: a network came or went, so the zones (which interface is Trusted / Public / VPN /
# Tailscale) change. NetworkManager runs this as root with: $1 = interface, $2 = action.
# Also linked from pre-up.d: NetworkManager waits for pre-up scripts, so a network that connects is in its zone
# before it is reported connected. Without that, a device's first try in the moment between the address arriving
# and "up" came in on an interface in no zone, and was asked about as "a connection that isn't one of your
# networks" (decided 2026-10-09: his own home Wi-Fi, a moment after it reconnected).
# Identity (policy v3): at pre-up a cable has no router address yet, so its zone is the connection id's for now;
# up / dhcp4-change re-zone it once the router is known (its hardware address + range must be the saved ones, else
# Public). A Wi-Fi network is matched at pre-up already, from its saved name, security and password fingerprint.
case "$2" in
    pre-up|up|down|vpn-up|vpn-down|dhcp4-change|dhcp6-change|connectivity-change)
        [ -f /etc/starchaser/policy.json ] && exec /usr/local/lib/starchaser/starchaser-admin firewall-zones-refresh ;;
esac
exit 0
