homek8s/infrastructure/networking/rosenpass/rosenpass-upnp.sh

25 lines
1 KiB
Shell
Raw Normal View History

#!/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
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
logger -t rosenpass-upnp "mapping missing after re-assert: ${out}"
exit 1
fi