Hack around missing .ethernet on Catalyst

Enum seems to be mapped correctly. Make sure matching works on
real device though.

Also noticed that @available on iOS implies availability on
Catalyst as well, making it ineffective e.g. in this case, where
mobile and ethernet network matching should be only available on
iOS and macOS respectively.
This commit is contained in:
Davide De Rosa 2022-04-19 13:29:16 +02:00
parent 2af28c158d
commit a6c7305528
3 changed files with 21 additions and 13 deletions

View File

@ -26,6 +26,20 @@
import Foundation
import NetworkExtension
extension NEOnDemandRuleInterfaceType {
static var compatibleEthernet: NEOnDemandRuleInterfaceType? {
#if targetEnvironment(macCatalyst)
// FIXME: Catalyst, missing enum case, try hardcoding
// https://developer.apple.com/documentation/networkextension/neondemandruleinterfacetype/ethernet
NEOnDemandRuleInterfaceType(rawValue: 1)
#elseif os(macOS)
.ethernet
#else
nil
#endif
}
}
extension Profile.OnDemand {
func rules(withCustomRules: Bool) -> [NEOnDemandRule] {
@ -36,19 +50,20 @@ extension Profile.OnDemand {
var rules: [NEOnDemandRule] = []
if withCustomRules {
#if os(iOS)
if withMobileNetwork {
let rule = policyRule
rule.interfaceTypeMatch = .cellular
rules.append(rule)
}
#else
if withEthernetNetwork {
let rule = policyRule
rule.interfaceTypeMatch = .ethernet
rules.append(rule)
if let compatibleEthernet = NEOnDemandRuleInterfaceType.compatibleEthernet {
let rule = policyRule
rule.interfaceTypeMatch = compatibleEthernet
rules.append(rule)
} else {
pp_log.warning("Unable to add rule for NEOnDemandRuleInterfaceType.ethernet (not compatible)")
}
}
#endif
let SSIDs = Array(withSSIDs.filter { $1 }.keys)
if !SSIDs.isEmpty {
let rule = policyRule

View File

@ -36,11 +36,8 @@ extension Profile {
}
public enum OtherNetwork: String, Codable {
@available(iOS 14, *)
case mobile
@available(macOS 11, *)
case ethernet
}

View File

@ -24,12 +24,9 @@
//
import Foundation
import NetworkExtension
import PassepartoutUtils
extension Profile.OnDemand {
@available(iOS 14, *)
public var withMobileNetwork: Bool {
get {
withOtherNetworks.contains(.mobile)
@ -43,7 +40,6 @@ extension Profile.OnDemand {
}
}
@available(macOS 11, *)
public var withEthernetNetwork: Bool {
get {
withOtherNetworks.contains(.ethernet)