obmp-docker/scripts/wsl-portproxy.ps1
Sam b480615ca2 BMP port 1790 everywhere: parameterize the published collector port (finding 12)
Decision landed: routers target 1790 (IANA BMP port); the collector keeps
listening on 5000 in-container. One .env variable now drives every hop:

- compose publishes ${ROUTER_FACING_PORT:-1790}:5000 (was hardcoded 5000:5000)
- gobgpd.conf.tmpl (+ evpn) gains __BMP_PORT__; setup.sh renders it from
  ROUTER_FACING_PORT -- gobgp is host-networked, so it must chase the
  published port or the full-table feeder silently breaks
- deploy.sh + scripts/wsl-portproxy.ps1: the WSL side now publishes the
  router-facing port itself, so the portproxy forwards the same port
  end-to-end instead of down-mapping to 5000
- cml/proxmox_bmp_config.py reads ROUTER_FACING_IP/PORT from .env (HOST_IP
  fallback for pre-key .envs); xrd-node-definition.yaml baked port -> 1790
- .env.example documents ROUTER_FACING_IP/PORT; docs updated, finding 12
  closed on the repo side (routers still on 5000 need a config re-apply)

Verified live: collector republished 0.0.0.0:1790->5000, gobgp BMP session
Up to HOST_IP:1790 with the RIB dump flowing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 16:33:52 -07:00

69 lines
2.7 KiB
PowerShell

<#
.SYNOPSIS
Forward router-facing OpenBMP ports from the Windows host into WSL.
.DESCRIPTION
Physical routers cannot reach the WSL VM's NAT address, and that address
changes on every 'wsl --shutdown' (portability finding 4). This script
(re)creates the netsh portproxy rules that forward the router-facing BMP
port and Kafka from the Windows LAN IP into the current WSL address, plus
the matching inbound firewall rules. Idempotent: existing rules for the
same listen ports are replaced, so RE-RUN IT AFTER EVERY WSL RESTART.
Must run in an ELEVATED PowerShell.
.PARAMETER RouterPort
Router-facing BMP port (default 1790, the IANA BMP port). Compose publishes
the same port on the WSL side (ROUTER_FACING_PORT:5000), so the proxy
forwards Windows:RouterPort -> WSL:RouterPort.
.PARAMETER WslIp
WSL address to forward to. Default: auto-detected via 'wsl hostname -I'.
.EXAMPLE
powershell -ExecutionPolicy Bypass -File scripts\wsl-portproxy.ps1
powershell -ExecutionPolicy Bypass -File scripts\wsl-portproxy.ps1 -RouterPort 5000
#>
param(
[int]$RouterPort = 1790,
[int]$KafkaPort = 9092,
[string]$WslIp = ""
)
$ErrorActionPreference = "Stop"
$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
if (-not (New-Object System.Security.Principal.WindowsPrincipal($id)).IsInRole(
[System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error "Run this from an ELEVATED PowerShell (netsh portproxy needs admin)."
exit 1
}
if (-not $WslIp) {
$WslIp = (wsl hostname -I).Trim().Split(" ")[0]
if (-not $WslIp) { Write-Error "Could not auto-detect the WSL IP; pass -WslIp."; exit 1 }
}
Write-Host "WSL address: $WslIp"
# listenport => connectport (same port both sides; compose maps RouterPort
# down to the collector's in-container 5000 on the WSL side)
$maps = @{ $RouterPort = $RouterPort; $KafkaPort = $KafkaPort }
foreach ($listen in $maps.Keys) {
netsh interface portproxy delete v4tov4 listenport=$listen listenaddress=0.0.0.0 2>$null | Out-Null
netsh interface portproxy add v4tov4 listenport=$listen listenaddress=0.0.0.0 `
connectport=$($maps[$listen]) connectaddress=$WslIp | Out-Null
Write-Host "portproxy 0.0.0.0:$listen -> ${WslIp}:$($maps[$listen])"
$ruleName = "OpenBMP $listen"
if (-not (Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue)) {
New-NetFirewallRule -DisplayName $ruleName -Direction Inbound `
-LocalPort $listen -Protocol TCP -Action Allow | Out-Null
Write-Host "firewall rule added: $ruleName"
}
}
Write-Host ""
Write-Host "Active portproxy rules:"
netsh interface portproxy show v4tov4
Write-Host "Routers target the Windows LAN IP on port $RouterPort (see docs/router-bmp-config.md)."