Retain legacy MTU across iOS update

Enforce 1200 (formerly 1250). If and only if unset.

Defaulting to standard MTU (1500) without notice, may break
connectivity for some existing users.
This commit is contained in:
Davide De Rosa 2021-01-04 23:40:49 +01:00
parent 04fc806e5a
commit 7b87f4247c
1 changed files with 31 additions and 0 deletions

View File

@ -44,6 +44,8 @@ public class TransientStore {
static let didMigrateHostsToUUID = "DidMigrateHostsToUUID"
static let didMigrateKeychainContext = "didMigrateKeychainContext"
static let didMigrateRetainLowMTU = "didMigrateRetainLowMTU"
}
public static let shared = TransientStore()
@ -81,6 +83,15 @@ public class TransientStore {
}
}
public static var didMigrateRetainLowMTU: Bool {
get {
return UserDefaults.standard.bool(forKey: Keys.didMigrateRetainLowMTU)
}
set {
UserDefaults.standard.set(newValue, forKey: Keys.didMigrateRetainLowMTU)
}
}
public static var baseVPNConfiguration: OpenVPNTunnelProvider.ConfigurationBuilder {
let sessionBuilder = OpenVPN.ConfigurationBuilder()
var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
@ -127,6 +138,26 @@ public class TransientStore {
service.migrateKeychainContext()
TransientStore.didMigrateKeychainContext = true
}
if !TransientStore.didMigrateRetainLowMTU {
for key in service.allProfileKeys() {
guard let profile = service.profile(withKey: key) else {
continue
}
if profile.networkChoices == nil {
profile.networkChoices = ProfileNetworkChoices(
choice: (key.context == .provider) ? .server : .client
)
}
if profile.manualNetworkSettings == nil {
profile.manualNetworkSettings = ProfileNetworkSettings()
}
if profile.manualNetworkSettings?.mtuBytes == nil {
profile.networkChoices?.mtu = .manual
profile.manualNetworkSettings?.mtuBytes = 1200
}
}
TransientStore.didMigrateRetainLowMTU = true
}
#endif
} catch let e {
log.error("Could not decode service: \(e)")