TunnelProvider: store the entire NWPath

Otherwise [utun0, en0] == [en0, utun0] before WiFi has connected, and we
wind up not rebinding after WiFi does successfully connect, which means
people have trouble when resuming from sleep.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2019-06-08 22:35:09 +02:00
parent a66f13eb01
commit c7b7b1247b
1 changed files with 3 additions and 6 deletions

View File

@ -11,7 +11,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
private var handle: Int32? private var handle: Int32?
private var networkMonitor: NWPathMonitor? private var networkMonitor: NWPathMonitor?
private var ifname: String? private var ifname: String?
private var lastSeenInterfaces: [String] = [] private var lastPath: Network.NWPath?
private var packetTunnelSettingsGenerator: PacketTunnelSettingsGenerator? private var packetTunnelSettingsGenerator: PacketTunnelSettingsGenerator?
deinit { deinit {
@ -143,18 +143,15 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
private func pathUpdate(path: Network.NWPath) { private func pathUpdate(path: Network.NWPath) {
guard let handle = handle else { return } guard let handle = handle else { return }
guard let ifname = ifname else { return }
wg_log(.debug, message: "Network change detected with \(path.status) route and interface order \(path.availableInterfaces)") wg_log(.debug, message: "Network change detected with \(path.status) route and interface order \(path.availableInterfaces)")
guard path.status == .satisfied else { return }
#if os(iOS) #if os(iOS)
if let packetTunnelSettingsGenerator = packetTunnelSettingsGenerator { if let packetTunnelSettingsGenerator = packetTunnelSettingsGenerator {
_ = packetTunnelSettingsGenerator.endpointUapiConfiguration().withGoString { return wgSetConfig(handle, $0) } _ = packetTunnelSettingsGenerator.endpointUapiConfiguration().withGoString { return wgSetConfig(handle, $0) }
} }
#endif #endif
let interfaces = path.availableInterfaces.filter { $0.name != ifname }.compactMap { $0.name } if path != lastPath {
if !interfaces.elementsEqual(lastSeenInterfaces) { lastPath = path
lastSeenInterfaces = interfaces
wgBumpSockets(handle) wgBumpSockets(handle)
} }
} }