mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-08-01 22:43:11 +00:00
49 lines
1.4 KiB
Bash
49 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
source "$(dirname "$0")/router-common.sh"
|
|
|
|
# miniupnpd serves PCP/NAT-PMP (UDP 5351) on the lan face, so find it by its IP
|
|
# like router-common.sh finds the wan one.
|
|
lanif=$(ip -o -4 addr show | awk -v ip="$ROUTER_LAN_IP" '$0 ~ ip {print $2; exit}')
|
|
|
|
# Reuse miniupnpd's chains (as nft_init.sh sets them up) without its forward drop
|
|
# policy.
|
|
nft -f - <<'EOF'
|
|
table inet filter {
|
|
chain prerouting_miniupnpd {}
|
|
chain postrouting_miniupnpd {}
|
|
chain miniupnpd {}
|
|
chain prerouting {
|
|
type nat hook prerouting priority -100; policy accept;
|
|
jump prerouting_miniupnpd
|
|
}
|
|
chain postrouting {
|
|
type nat hook postrouting priority 100; policy accept;
|
|
jump postrouting_miniupnpd
|
|
}
|
|
}
|
|
EOF
|
|
|
|
conf=/tmp/miniupnpd.conf
|
|
cat > "$conf" <<EOF
|
|
ext_ifname=$wanif
|
|
listening_ip=$lanif
|
|
# Enable PCP/NAT-PMP: libplum tries PCP first, so it picks it here.
|
|
enable_pcp_pmp=yes
|
|
# port=0: pick a random HTTP port, no conflict with the storage API.
|
|
port=0
|
|
# Without an allow rule miniupnpd denies every mapping request by default.
|
|
allow 1024-65535 0.0.0.0/0 1024-65535
|
|
EOF
|
|
|
|
# -d: stay in the foreground; background it so the SIGTERM trap below still fires.
|
|
miniupnpd-nft -d -f "$conf" &
|
|
upnpd_pid=$!
|
|
sleep 1
|
|
kill -0 "$upnpd_pid" 2>/dev/null \
|
|
|| { echo "ERROR: miniupnpd failed to start" >&2; exit 1; }
|
|
|
|
echo "router ready (wan iface $wanif, miniupnpd on $lanif)"
|
|
|
|
hold_until_stopped
|