Skip to content

Commit e1970dc

Browse files
authored
NE: Disconnect from unmatched network when on-demand policy is "Including" (#338)
It seems to work properly on iOS/macOS 26. Fixes #10
1 parent cffe282 commit e1970dc

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Sources/PartoutOS/AppleNE/Modules/OnDemandModule+NE.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extension OnDemandModule {
88
func neRules(_ ctx: PartoutLoggerContext) -> [NEOnDemandRule] {
99
var rules: [NEOnDemandRule] = []
1010

11-
// apply exceptions (unless .any)
11+
// Apply exceptions (unless .any)
1212
if policy != .any {
1313
if Self.supportsCellular, withMobileNetwork {
1414
if let rule = cellularRule() {
@@ -30,14 +30,13 @@ extension OnDemandModule {
3030
}
3131
}
3232

33-
// IMPORTANT: append fallback rule last
33+
// IMPORTANT: Append fallback rule last
3434
rules.append(globalRule())
3535

3636
pp_log(ctx, .os, .info, "On-demand rules:")
3737
rules.forEach {
3838
pp_log(ctx, .os, .info, "\($0)")
3939
}
40-
4140
return rules
4241
}
4342
}
@@ -49,10 +48,14 @@ private extension OnDemandModule {
4948
case .any, .excluding:
5049
rule = NEOnDemandRuleConnect()
5150
case .including:
52-
rule = NEOnDemandRuleIgnore()
51+
rule = NEOnDemandRuleDisconnect()
5352
@unknown default:
5453
rule = NEOnDemandRuleConnect()
5554
}
55+
// This might be the culprit, WG only matches .wiFi
56+
// IIRC, when .any is set with .including policy (i.e. fall
57+
// back to a disconnect rule), the profile could not
58+
// activate (forcibly disconnected). Maybe only on iOS?
5659
rule.interfaceTypeMatch = .any
5760
return rule
5861
}
@@ -89,7 +92,7 @@ private extension OnDemandModule {
8992

9093
func wifiRule(SSIDs: [String]) -> NEOnDemandRule {
9194
let rule = networkRule(matchingInterface: .wiFi)
92-
rule.ssidMatch = SSIDs.sorted() // for testing
95+
rule.ssidMatch = SSIDs.sorted() // Predictable, for testing
9396
return rule
9497
}
9598
}

Tests/PartoutOSTests/AppleNE/OnDemandModuleRulesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct OnDemandModuleRulesTests {
100100
wifiRule.interfaceTypeMatch = .wiFi
101101
wifiRule.ssidMatch = ["home", "nope"]
102102
rules.append(wifiRule)
103-
rules.append(NEOnDemandRuleIgnore())
103+
rules.append(NEOnDemandRuleDisconnect())
104104
return rules
105105
}()
106106
#expect(sut.neRules == computedRules)

0 commit comments

Comments
 (0)