Skip to content

Commit

Permalink
Adds VPN metadata information to know what failed on VPN start attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Apr 25, 2024
1 parent b1501e6 commit 30f6784
Showing 1 changed file with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,39 @@ public actor NetworkProtectionTunnelFailureMonitor {
}

extension Network.NWPath {

/// Helper enum to identify known interfaces
///
public enum KnownInterface: CaseIterable {
case utun
case ipsec
case dns
case unidentified

var prefix: String {
switch self {
case .utun:
return "utun"
case .ipsec:
return "ipsec"
case .dns:
return "dns"
case .unidentified:
return "unidentified"
}
}

static func identify(_ interface: NWInterface) -> KnownInterface {
for knownInterface in allCases {
if interface.name.hasPrefix(knownInterface.prefix) {

Check failure on line 171 in Sources/NetworkProtection/Diagnostics/NetworkProtectionTunnelFailureMonitor.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

`where` clauses are preferred over a single `if` inside a `for` (for_where)
return knownInterface
}
}

return .unidentified
}
}

/// A description that's safe from a privacy standpoint.
///
/// Ref: https://app.asana.com/0/0/1206712493935053/1206712516729780/f
Expand All @@ -157,17 +190,29 @@ extension Network.NWPath {
description += "unsatisfiedReason: \(unsatisfiedReason), "
}

let tunnelCount = availableInterfaces.filter { interface in
interface.type == .other && interface.name.contains("utun")
}.count

let dnsCount = availableInterfaces.filter { interface in
interface.type == .other && interface.name.contains("dns")
}.count
var dnsCount = 0
var ipsecCount = 0
var utunCount = 0
var unidentifiedCount = 0

availableInterfaces.map(KnownInterface.identify).forEach { knownInterface in
switch knownInterface {
case .dns:
dnsCount += 1
case .ipsec:
ipsecCount += 1
case .utun:
utunCount += 1
case .unidentified:
unidentifiedCount += 1
}
}

description += "mainInterfaceType: \(String(describing: availableInterfaces.first?.type)), "
description += "tunnelInterfaceCount: \(tunnelCount), "
description += "utunInterfaceCount: \(utunCount), "
description += "ipsecInterfaceCount: \(ipsecCount), "
description += "dnsInterfaceCount: \(dnsCount)), "
description += "unidentifiedInterfaceCount: \(unidentifiedCount)), "
description += "isConstrained: \(isConstrained ? "true" : "false"), "
description += "isExpensive: \(isExpensive ? "true" : "false")"
description += ")"
Expand Down

0 comments on commit 30f6784

Please sign in to comment.