Files
magpie/docs
yetone cff530079f wsl: a bridged distro reaches Windows on the bridge's adapter, not the LAN router
ecalpal_ on Discord (magpie 0.1.2689, Windows 11, WSL 3.0.3.0, Ubuntu
22.04.5; .wslconfig vmSwitch=WSL_Bridge_Switch, networkingMode=Bridged,
dhcp=false). In bridged networking the distro is a peer on the LAN and its
default route is the router, 192.168.9.1. magpie took that next hop for
Windows: wsl.json got {"net":"bridged","gateway":"192.168.9.1"} and Pi's
models.json a baseUrl on 192.168.9.1:3425, where nothing listens, with the
gateway token rather than the WSL key. serveWSL already listened on
192.168.9.147, Windows' address on vEthernet (WSL_Bridge_Switch).

wslrun.HostAt now picks the address: "" where the distro's 127.0.0.1 is
Windows' (mirrored, consomme, virtioproxy, as before); the next hop as it
is when it is Windows' own address on a WSL adapter (NAT, unchanged);
otherwise Windows' address on the one WSL adapter whose network holds
that next hop (bridged: 192.168.9.1 in 192.168.9.147/24 -> .147). A next
hop on no WSL network is kept as it was. The adapter list moved from
gateway.wslNets to wslrun.Nets (gateway.WSLNets still wraps it), so both
probes use it: agent's parseProbe (distro.Gateway, what place writes into
agents) and wslrun's (Tool.Host, a 127.0.0.1 proxy handed to a WSL CLI),
which had the same bug.

The key follows the address: keyAt(http://192.168.9.147:3425) is on a WSL
net (OnWSLNet), so agents there get the WSL key.

Existing users: on the next start, the first probe of the running distro
writes the new gateway into wsl.json and keeps 192.168.9.1 in Was. The
startup SyncCatalog then rewrites Pi's provider block (baseUrl and apiKey)
at the new address; keptaway treats the old router address as magpie's
because it is in Was. A distro that isn't running at start is fixed at its
first probe after it runs, and its agents' files at the next sync after
that. Codex in WSL, which keeps its own base_url, gets the existing
"unreachable" drift with "Use 192.168.9.147:3425" (wslMovedFrom), not an
automatic rewrite.

Tests (fixtures are the reporter's values):
- wslrun TestHostAt: bridged/nat/mirrored/consomme each with its own route
  and adapters; TestParseProbeBridged (Tool.Host and proxy).
- agent TestWSLBridgedReachesWindowsOnTheBridge (bridged .147, nat
  172.20.0.1 unchanged, mirrored 127.0.0.1) and
  TestWSLBridgedOldRouterWrittenOver: wsl.json and Pi's models.json as
  0.1.2689 wrote them, then a probe and a sync: baseUrl .147, apiKey the
  WSL key, wsl.json rewritten.

Run:
- Broken by hand: probe code put back to HostLoopback only. Both new agent
  tests and TestParseProbeBridged FAIL (Gateway/Host 192.168.9.1).
- mote: gofmt -l empty; go vet, GOOS=windows go vet, GOOS=linux go vet
  -tags nogui for wslrun, gateway, agent; GOOS=windows go build: ok.
- mote: go test -timeout 45m ./internal/wslrun ./internal/agent
  ./internal/gateway: ok (wslrun 1.3s, agent 231s, gateway 855s)
- xiaomi-gpu (win-run): go test ./internal/wslrun ./internal/gateway
  -run 'HostAt|ParseProbe|WSL' ok; ./internal/agent -run
  'WSL|ParseProbe|Omp' ok. A first try with a fallback (bridged + one WSL
  adapter -> that adapter) went red there on TestParseProbe and
  TestWSLNetworkingFromWslinfo, because the box's real NAT adapter
  (vEthernet (WSL (Hyper-V firewall)) 172.17.32.1/20) was taken for the
  bridge; the fallback was dropped.
- xiaomi-gpu, real adapters: HostAt("nat", "172.17.32.1", Nets()) =
  172.17.32.1; magpie-desktop is NAT (wslinfo nat, default via
  172.17.32.1), so its value is unchanged.

Not tried: a real bridged WSL (none on the LAN; magpie-desktop's
networking was not changed), a real magpie start against an existing
wrong config, and the full go test ./... before the push (run after).
2026-11-06 10:49:35 +08:00
..