aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/Tunnel
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-22 18:59:23 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:26 +0530
commit09d7a5229ae026f004eb38295679bb9c044d2da7 (patch)
tree4d6c1fdbbab8021fb68a8ae82773c9055e6753be /WireGuard/WireGuard/Tunnel
parentwireguard-go-bridge: Make CFLAGS_PREFIX work for macOS as well (diff)
downloadwireguard-apple-09d7a5229ae026f004eb38295679bb9c044d2da7.tar.xz
wireguard-apple-09d7a5229ae026f004eb38295679bb9c044d2da7.zip
On-Demand: Add support for macOS-specific values
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/Tunnel')
-rw-r--r--WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift38
1 files changed, 33 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift b/WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift
index ffc06248..c89cce37 100644
--- a/WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift
+++ b/WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift
@@ -10,9 +10,14 @@ struct ActivateOnDemandSetting {
enum ActivateOnDemandOption {
case none // Valid only when isActivateOnDemandEnabled is false
- case useOnDemandOverWiFiOrCellular
case useOnDemandOverWiFiOnly
+ #if os(iOS)
+ case useOnDemandOverWiFiOrCellular
case useOnDemandOverCellularOnly
+ #elseif os(OSX)
+ case useOnDemandOverWiFiOrEthernet
+ case useOnDemandOverEthernetOnly
+ #endif
}
extension ActivateOnDemandSetting {
@@ -24,6 +29,7 @@ extension ActivateOnDemandSetting {
switch activateOnDemandOption {
case .none:
rules = nil
+ #if os(iOS)
case .useOnDemandOverWiFiOrCellular:
rules = [connectRule]
case .useOnDemandOverWiFiOnly:
@@ -34,12 +40,33 @@ extension ActivateOnDemandSetting {
connectRule.interfaceTypeMatch = .cellular
disconnectRule.interfaceTypeMatch = .wiFi
rules = [connectRule, disconnectRule]
+ #elseif os(OSX)
+ case .useOnDemandOverWiFiOrEthernet:
+ rules = [connectRule]
+ case .useOnDemandOverWiFiOnly:
+ connectRule.interfaceTypeMatch = .wiFi
+ disconnectRule.interfaceTypeMatch = .ethernet
+ rules = [connectRule, disconnectRule]
+ case .useOnDemandOverEthernetOnly:
+ connectRule.interfaceTypeMatch = .ethernet
+ disconnectRule.interfaceTypeMatch = .wiFi
+ rules = [connectRule, disconnectRule]
+ #endif
}
tunnelProviderManager.onDemandRules = rules
}
init(from tunnelProviderManager: NETunnelProviderManager) {
let rules = tunnelProviderManager.onDemandRules ?? []
+ #if os(iOS)
+ let otherInterfaceType: NEOnDemandRuleInterfaceType = .cellular
+ let useWiFiOrOtherOption: ActivateOnDemandOption = .useOnDemandOverWiFiOrCellular
+ let useOtherOnlyOption: ActivateOnDemandOption = .useOnDemandOverCellularOnly
+ #elseif os(OSX)
+ let otherInterfaceType: NEOnDemandRuleInterfaceType = .ethernet
+ let useWiFiOrOtherOption: ActivateOnDemandOption = .useOnDemandOverWiFiOrEthernet
+ let useOtherOnlyOption: ActivateOnDemandOption = .useOnDemandOverEthernetOnly
+ #endif
let activateOnDemandOption: ActivateOnDemandOption
switch rules.count {
case 0:
@@ -47,20 +74,21 @@ extension ActivateOnDemandSetting {
case 1:
let rule = rules[0]
precondition(rule.action == .connect)
- activateOnDemandOption = .useOnDemandOverWiFiOrCellular
+ activateOnDemandOption = useWiFiOrOtherOption
case 2:
let connectRule = rules.first(where: { $0.action == .connect })!
let disconnectRule = rules.first(where: { $0.action == .disconnect })!
- if connectRule.interfaceTypeMatch == .wiFi && disconnectRule.interfaceTypeMatch == .cellular {
+ if connectRule.interfaceTypeMatch == .wiFi && disconnectRule.interfaceTypeMatch == otherInterfaceType {
activateOnDemandOption = .useOnDemandOverWiFiOnly
- } else if connectRule.interfaceTypeMatch == .cellular && disconnectRule.interfaceTypeMatch == .wiFi {
- activateOnDemandOption = .useOnDemandOverCellularOnly
+ } else if connectRule.interfaceTypeMatch == otherInterfaceType && disconnectRule.interfaceTypeMatch == .wiFi {
+ activateOnDemandOption = useOtherOnlyOption
} else {
fatalError("Unexpected onDemandRules set on tunnel provider manager")
}
default:
fatalError("Unexpected number of onDemandRules set on tunnel provider manager")
}
+
self.activateOnDemandOption = activateOnDemandOption
if activateOnDemandOption == .none {
isActivateOnDemandEnabled = false