Update TunnelKit

Split IP settings and routes. Now properly handling local routes.
This commit is contained in:
Davide De Rosa 2022-10-29 11:22:06 +02:00
parent 0f04bdcce3
commit cdc05f0c10
6 changed files with 51 additions and 52 deletions

View File

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- OpenVPN: Tunnel dying prematurely. [tunnelkit#289](https://github.com/passepartoutvpn/tunnelkit/issues/289), [#237](https://github.com/passepartoutvpn/passepartout-apple/issues/237) - OpenVPN: Tunnel dying prematurely. [tunnelkit#289](https://github.com/passepartoutvpn/tunnelkit/issues/289), [#237](https://github.com/passepartoutvpn/passepartout-apple/issues/237)
- OpenVPN: Local network settings being ignored. [tunnelkit#290](https://github.com/passepartoutvpn/tunnelkit/issues/290) - OpenVPN: Local network settings being ignored. [tunnelkit#290](https://github.com/passepartoutvpn/tunnelkit/issues/290)
- OpenVPN: Routes from configuration file are ignored. [tunnelkit#278](https://github.com/passepartoutvpn/tunnelkit/issues/278)
- OpenVPN: Parse IPv6 endpoints properly. [tunnelkit#294](https://github.com/passepartoutvpn/tunnelkit/issues/294) - OpenVPN: Parse IPv6 endpoints properly. [tunnelkit#294](https://github.com/passepartoutvpn/tunnelkit/issues/294)
- Restore "Reconnect" action in profiles. [#232](https://github.com/passepartoutvpn/passepartout-apple/pull/232) - Restore "Reconnect" action in profiles. [#232](https://github.com/passepartoutvpn/passepartout-apple/pull/232)
- Systematic uninstallation of VPN profile if any IAP was refunded. [#238](https://github.com/passepartoutvpn/passepartout-apple/issues/238) - Systematic uninstallation of VPN profile if any IAP was refunded. [#238](https://github.com/passepartoutvpn/passepartout-apple/issues/238)

View File

@ -51,7 +51,7 @@
"repositoryURL": "https://github.com/passepartoutvpn/tunnelkit", "repositoryURL": "https://github.com/passepartoutvpn/tunnelkit",
"state": { "state": {
"branch": null, "branch": null,
"revision": "8ac21771e347f700ecd05e974df1a4ebf954a6df", "revision": "cae371bb400ad3de9bc59f96c18a091fb577ac44",
"version": null "version": null
} }
}, },

View File

@ -34,12 +34,12 @@ extension Endpoint: Identifiable {
extension IPv4Settings.Route: Identifiable { extension IPv4Settings.Route: Identifiable {
public var id: String { public var id: String {
"\(destination):\(mask):\(gateway)" "\(destination):\(mask):\(gateway ?? "*")"
} }
} }
extension IPv6Settings.Route: Identifiable { extension IPv6Settings.Route: Identifiable {
public var id: String { public var id: String {
"\(destination):\(prefixLength):\(gateway)" "\(destination):\(prefixLength):\(gateway ?? "*")"
} }
} }

View File

@ -40,12 +40,9 @@ extension EndpointAdvancedView {
var body: some View { var body: some View {
List { List {
let cfg = builder.build() let cfg = builder.build()
if isServerPushed {
ipv4Section ipv4Section
ipv6Section ipv6Section
} else {
pullSection(configuration: cfg) pullSection(configuration: cfg)
}
dnsSection(configuration: cfg) dnsSection(configuration: cfg)
proxySection(configuration: cfg) proxySection(configuration: cfg)
if !isReadonly { if !isReadonly {
@ -65,48 +62,57 @@ extension EndpointAdvancedView {
} }
extension EndpointAdvancedView.OpenVPNView { extension EndpointAdvancedView.OpenVPNView {
@ViewBuilder
private var ipv4Section: some View { private var ipv4Section: some View {
builder.ipv4.map { cfg in if builder.ipv4 != nil || builder.routes4 != nil {
Section { Section {
if let settings = builder.ipv4 {
themeLongContentLinkDefault( themeLongContentLinkDefault(
L10n.Global.Strings.address, L10n.Global.Strings.address,
content: .constant(builder.ipv4.localizedAddress) content: .constant(settings.localizedAddress)
) )
themeLongContentLinkDefault( themeLongContentLinkDefault(
L10n.NetworkSettings.Gateway.title, L10n.NetworkSettings.Gateway.title,
content: .constant(builder.ipv4.localizedDefaultGateway) content: .constant(settings.localizedDefaultGateway)
) )
}
ForEach(cfg.routes, id: \.self) { route in builder.routes4.map { routes in
ForEach(routes, id: \.self) { route in
themeLongContentLinkDefault( themeLongContentLinkDefault(
L10n.Endpoint.Advanced.Openvpn.Items.Route.caption, L10n.Endpoint.Advanced.Openvpn.Items.Route.caption,
content: .constant(route.localizedDescription) content: .constant(route.localizedDescription)
) )
} }
}
} header: { } header: {
Text(Unlocalized.Network.ipv4) Text(Unlocalized.Network.ipv4)
} }
} }
} }
@ViewBuilder
private var ipv6Section: some View { private var ipv6Section: some View {
builder.ipv6.map { cfg in if builder.ipv6 != nil || builder.routes6 != nil {
Section { Section {
if let settings = builder.ipv6 {
themeLongContentLinkDefault( themeLongContentLinkDefault(
L10n.Global.Strings.address, L10n.Global.Strings.address,
content: .constant(builder.ipv6.localizedAddress) content: .constant(settings.localizedAddress)
) )
themeLongContentLinkDefault( themeLongContentLinkDefault(
L10n.NetworkSettings.Gateway.title, L10n.NetworkSettings.Gateway.title,
content: .constant(builder.ipv6.localizedDefaultGateway) content: .constant(settings.localizedDefaultGateway)
) )
}
ForEach(cfg.routes, id: \.self) { route in builder.routes6.map { routes in
ForEach(routes, id: \.self) { route in
themeLongContentLinkDefault( themeLongContentLinkDefault(
L10n.Endpoint.Advanced.Openvpn.Items.Route.caption, L10n.Endpoint.Advanced.Openvpn.Items.Route.caption,
content: .constant(route.localizedDescription) content: .constant(route.localizedDescription)
) )
} }
}
} header: { } header: {
Text(Unlocalized.Network.ipv6) Text(Unlocalized.Network.ipv6)
} }

View File

@ -76,43 +76,35 @@ extension TimeInterval {
} }
} }
extension Optional where Wrapped == IPv4Settings { extension IPv4Settings {
var localizedAddress: String { var localizedAddress: String {
if let ipv4 = self { "\(address)/\(addressMask)"
return "\(ipv4.address)/\(ipv4.addressMask)"
} else {
return L10n.Global.Strings.none
}
} }
var localizedDefaultGateway: String { var localizedDefaultGateway: String {
self?.defaultGateway ?? L10n.Global.Strings.none defaultGateway
} }
} }
extension Optional where Wrapped == IPv6Settings { extension IPv6Settings {
var localizedAddress: String { var localizedAddress: String {
if let ipv6 = self { "\(address)/\(addressPrefixLength)"
return "\(ipv6.address)/\(ipv6.addressPrefixLength)"
} else {
return L10n.Global.Strings.none
}
} }
var localizedDefaultGateway: String { var localizedDefaultGateway: String {
self?.defaultGateway ?? L10n.Global.Strings.none defaultGateway
} }
} }
extension IPv4Settings.Route { extension IPv4Settings.Route {
var localizedDescription: String { var localizedDescription: String {
"\(destination)/\(mask) -> \(gateway)" "\(destination)/\(mask) -> \(gateway ?? "*")"
} }
} }
extension IPv6Settings.Route { extension IPv6Settings.Route {
var localizedDescription: String { var localizedDescription: String {
"\(destination)/\(prefixLength) -> \(gateway)" "\(destination)/\(prefixLength) -> \(gateway ?? "*")"
} }
} }

View File

@ -24,7 +24,7 @@ let package = Package(
// Dependencies declare other packages that this package depends on. // Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"), // .package(url: /* package url */, from: "1.0.0"),
// .package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", from: "5.0.0"), // .package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", from: "5.0.0"),
.package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", .revision("8ac21771e347f700ecd05e974df1a4ebf954a6df")), .package(name: "TunnelKit", url: "https://github.com/passepartoutvpn/tunnelkit", .revision("cae371bb400ad3de9bc59f96c18a091fb577ac44")),
// .package(name: "TunnelKit", path: "../../tunnelkit"), // .package(name: "TunnelKit", path: "../../tunnelkit"),
.package(url: "https://github.com/zoul/generic-json-swift", from: "2.0.0"), .package(url: "https://github.com/zoul/generic-json-swift", from: "2.0.0"),
.package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver", from: "1.9.0") .package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver", from: "1.9.0")