Set a tunnel (routing) configuration. Still very rough.

This commit is contained in:
Jeroen Leenarts 2018-08-05 22:58:48 +02:00
parent ea44b6de20
commit e6d7dfb92c
1 changed files with 20 additions and 1 deletions

View File

@ -36,7 +36,26 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
//TODO tunnel settings //TODO tunnel settings
if wireGuardWrapper.turnOn(withInterfaceName: "test", settingsString: "") { if wireGuardWrapper.turnOn(withInterfaceName: "test", settingsString: "") {
// Success // Success
completionHandler(nil) // completionHandler(nil)
//TODO obtain network config from WireGuard config or remote.
// route all traffic to VPN
let defaultRoute = NEIPv4Route.default()
// defaultRoute.gatewayAddress = gateway
let ipv4Settings = NEIPv4Settings(addresses: ["149.248.160.60"], subnetMasks: ["255.255.255.255"])
ipv4Settings.includedRoutes = [defaultRoute]
ipv4Settings.excludedRoutes = []
// let dnsSettings = NEDNSSettings(servers: dnsServers)
let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "149.248.160.60")
newSettings.ipv4Settings = ipv4Settings
// newSettings.dnsSettings = dnsSettings
// newSettings.mtu = cfg.mtu
setTunnelNetworkSettings(newSettings, completionHandler: completionHandler)
} else { } else {
completionHandler(PacketTunnelProviderError.tunnelSetupFailed) completionHandler(PacketTunnelProviderError.tunnelSetupFailed)
} }