#!/bin/bash # rosenpass-upnp.sh - re-assert the permanent UPnP mapping that gives the # Linode a way back to Rosenpass on the Pi (UDP 9999 -> 192.168.1.125:9999). # # The home router's admin panel is inaccessible, so this mapping is the ONLY # inbound path for the Rosenpass exchange on Link B (rpi wg-remote <-> # linode wg0). It is runtime state: a router reboot, a factory reset or a UPnP # daemon hiccup drops it, and the failure is silent - the link keeps its last # PSK and simply stops being post-quantum. Hence this timer. # # Idempotent: re-adding an identical permanent-lease mapping is a no-op, so it # is safe to run on a schedule. Never prints key material (it handles none). set -uo pipefail LAN_IP=192.168.1.125 PORT=9999 DESC=rosenpass-pq # Result of this run, read by rosenpass-metrics.sh (60 s textfile collector) so # the mapping is observable without polling the IGD from that timer. /run is # tmpfs: on a reboot the file is gone and the metric is absent until this unit # runs again (OnBootSec=2min), which the alert treats as "unknown", not "lost". STATE=/run/rosenpass-upnp.present set_present() { printf '%s\n' "$1" > "$STATE.tmp" && mv "$STATE.tmp" "$STATE" } out=$(upnpc -e "$DESC" -a "$LAN_IP" "$PORT" "$PORT" UDP 0 2>&1) || true # upnpc prints the mapping as " 0 UDP 9999->192.168.1.125:9999 'rosenpass-pq'" if ! upnpc -l 2>/dev/null | grep -q "${PORT}->${LAN_IP}:${PORT}"; then set_present 0 logger -t rosenpass-upnp "mapping missing after re-assert: ${out}" exit 1 fi set_present 1