Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7dea71898d |
@@ -8,10 +8,7 @@ extension IPv4Address {
|
|||||||
init?(addrInfo: addrinfo) {
|
init?(addrInfo: addrinfo) {
|
||||||
guard addrInfo.ai_family == AF_INET else { return nil }
|
guard addrInfo.ai_family == AF_INET else { return nil }
|
||||||
|
|
||||||
let addressData = addrInfo.ai_addr.withMemoryRebound(
|
let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in.self, capacity: MemoryLayout<sockaddr_in>.size) { ptr -> Data in
|
||||||
to: sockaddr_in.self,
|
|
||||||
capacity: 1
|
|
||||||
) { ptr -> Data in
|
|
||||||
return Data(bytes: &ptr.pointee.sin_addr, count: MemoryLayout<in_addr>.size)
|
return Data(bytes: &ptr.pointee.sin_addr, count: MemoryLayout<in_addr>.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,10 +20,7 @@ extension IPv6Address {
|
|||||||
init?(addrInfo: addrinfo) {
|
init?(addrInfo: addrinfo) {
|
||||||
guard addrInfo.ai_family == AF_INET6 else { return nil }
|
guard addrInfo.ai_family == AF_INET6 else { return nil }
|
||||||
|
|
||||||
let addressData = addrInfo.ai_addr.withMemoryRebound(
|
let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in6.self, capacity: MemoryLayout<sockaddr_in6>.size) { ptr -> Data in
|
||||||
to: sockaddr_in6.self,
|
|
||||||
capacity: 1
|
|
||||||
) { ptr -> Data in
|
|
||||||
return Data(bytes: &ptr.pointee.sin6_addr, count: MemoryLayout<in6_addr>.size)
|
return Data(bytes: &ptr.pointee.sin6_addr, count: MemoryLayout<in6_addr>.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -253,35 +253,58 @@ public class WireGuardAdapter {
|
|||||||
self.packetTunnelProvider?.reasserting = false
|
self.packetTunnelProvider?.reasserting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let settingsGenerator: PacketTunnelSettingsGenerator
|
||||||
do {
|
do {
|
||||||
let settingsGenerator = try self.makeSettingsGenerator(with: tunnelConfiguration)
|
settingsGenerator = try self.makeSettingsGenerator(with: tunnelConfiguration)
|
||||||
try self.setNetworkSettings(settingsGenerator.generateNetworkSettings())
|
|
||||||
|
|
||||||
switch self.state {
|
|
||||||
case .started(let handle, _):
|
|
||||||
let (wgConfig, resolutionResults) = settingsGenerator.uapiConfiguration()
|
|
||||||
self.logEndpointResolutionResults(resolutionResults)
|
|
||||||
|
|
||||||
wgSetConfig(handle, wgConfig)
|
|
||||||
#if os(iOS)
|
|
||||||
wgDisableSomeRoamingForBrokenMobileSemantics(handle)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
self.state = .started(handle, settingsGenerator)
|
|
||||||
|
|
||||||
case .temporaryShutdown:
|
|
||||||
self.state = .temporaryShutdown(settingsGenerator)
|
|
||||||
|
|
||||||
case .stopped:
|
|
||||||
fatalError()
|
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(nil)
|
|
||||||
} catch let error as WireGuardAdapterError {
|
} catch let error as WireGuardAdapterError {
|
||||||
completionHandler(error)
|
completionHandler(error)
|
||||||
|
return
|
||||||
} catch {
|
} catch {
|
||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch self.state {
|
||||||
|
case .started(let handle, _):
|
||||||
|
do {
|
||||||
|
try self.setNetworkSettings(settingsGenerator.generateNetworkSettings())
|
||||||
|
} catch let error as WireGuardAdapterError {
|
||||||
|
completionHandler(error)
|
||||||
|
return
|
||||||
|
} catch {
|
||||||
|
fatalError()
|
||||||
|
}
|
||||||
|
|
||||||
|
let (wgConfig, resolutionResults) = settingsGenerator.uapiConfiguration()
|
||||||
|
self.logEndpointResolutionResults(resolutionResults)
|
||||||
|
|
||||||
|
wgSetConfig(handle, wgConfig)
|
||||||
|
#if os(iOS)
|
||||||
|
wgDisableSomeRoamingForBrokenMobileSemantics(handle)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
self.state = .started(handle, settingsGenerator)
|
||||||
|
|
||||||
|
case .temporaryShutdown:
|
||||||
|
// On iOS 15.1 or newer, updating network settings may fail when in airplane mode.
|
||||||
|
// Network path monitor will retry updating settings later when connectivity is
|
||||||
|
// back online.
|
||||||
|
do {
|
||||||
|
try self.setNetworkSettings(settingsGenerator.generateNetworkSettings())
|
||||||
|
} catch let error as WireGuardAdapterError {
|
||||||
|
if case .setNetworkSettings(let systemError) = error {
|
||||||
|
self.logHandler(.verbose, "Failed to set network settings while offline. Will retry when connectivity is back online. Error: \(systemError.localizedDescription)")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
fatalError()
|
||||||
|
}
|
||||||
|
|
||||||
|
self.state = .temporaryShutdown(settingsGenerator)
|
||||||
|
|
||||||
|
case .stopped:
|
||||||
|
fatalError()
|
||||||
|
}
|
||||||
|
|
||||||
|
completionHandler(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user