Net core: re-create WireGuard tunnels after a network change (rebind)
mihomo's WireGuard outbounds keep their UDP socket bound to the address they started on: after moving from Planet9 to Saga the Amnezia sockets were still sending from 192.168.68.x, so every Amnezia (and client) tunnel looked dead while the AmneziaVPN app, connecting afresh, worked. Client tunnels now live in a file provider (keys/clients.yaml, groups select them by filter) like the Amnezia keys; netctl rebind touches both files and reloads the providers, which re-creates the tunnels on the current address without touching other connections. BroV calls it on every network change before re-testing. Tested on a scratch core: groups, selection across a rebind, health check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -300,9 +300,10 @@ final class NetCore: ObservableObject {
|
||||
// MARK: Network changes
|
||||
//
|
||||
// Moving between home / Saga / Planet9 Wi-Fi, waking from sleep or AmneziaVPN going on
|
||||
// and off leaves the WireGuard tunnels talking from an address that no longer exists.
|
||||
// Re-test everything a few seconds after the change so "auto" and "exit" re-pick at
|
||||
// once instead of at the next scheduled check.
|
||||
// and off leaves the WireGuard tunnels talking from an address that no longer exists
|
||||
// (seen: Amnezia sockets still on 192.168.68.x after moving to Saga). A few seconds after
|
||||
// the change the tunnels are re-created (netctl rebind), then everything is re-tested so
|
||||
// "auto" and "exit" re-pick at once.
|
||||
|
||||
private var pathMonitor: NWPathMonitor?
|
||||
private var recheckTask: Task<Void, Never>?
|
||||
@@ -322,6 +323,10 @@ final class NetCore: ObservableObject {
|
||||
recheckTask = Task {
|
||||
try? await Task.sleep(for: .seconds(4))
|
||||
guard !Task.isCancelled else { return }
|
||||
// WireGuard tunnels (Amnezia, clients) stay bound to the old network's address:
|
||||
// re-create them first, then re-test.
|
||||
_ = await call(["cmd": "rebind"], timeout: 20)
|
||||
try? await Task.sleep(for: .seconds(2))
|
||||
_ = await call(["cmd": "delay", "group": "auto"], timeout: 15)
|
||||
_ = await call(["cmd": "delay", "group": "amnezia"], timeout: 15)
|
||||
_ = await call(["cmd": "delay", "group": "exit"], timeout: 15)
|
||||
|
||||
Reference in New Issue
Block a user