2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// Network.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 2/15/22.
|
2024-01-14 13:34:21 +00:00
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import TunnelKitCore
|
|
|
|
|
|
|
|
public enum Network {
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public enum Choice: String, Codable {
|
|
|
|
case automatic // OpenVPN pulls from server
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case manual
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public static let defaultChoice: Choice = .automatic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol NetworkChoiceRepresentable {
|
|
|
|
var choice: Network.Choice { get set }
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol GatewaySettingsProviding {
|
|
|
|
var isDefaultIPv4: Bool { get }
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var isDefaultIPv6: Bool { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol DNSSettingsProviding {
|
2022-04-14 05:24:03 +00:00
|
|
|
var dnsProtocol: DNSProtocol? { get }
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
var dnsServers: [String]? { get }
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-03-17 21:16:04 +00:00
|
|
|
var dnsDomain: String? { get }
|
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
var dnsSearchDomains: [String]? { get }
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var dnsHTTPSURL: URL? { get }
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var dnsTLSServerName: String? { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol ProxySettingsProviding {
|
|
|
|
var proxyServer: Proxy? { get }
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
var proxyBypassDomains: [String]? { get }
|
2022-04-13 17:53:07 +00:00
|
|
|
|
|
|
|
var proxyAutoConfigurationURL: URL? { get }
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public protocol MTUSettingsProviding {
|
|
|
|
var mtuBytes: Int { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct GatewaySettings: Codable, Equatable, NetworkChoiceRepresentable, GatewaySettingsProviding {
|
|
|
|
public var choice: Network.Choice
|
|
|
|
|
|
|
|
public var isDefaultIPv4 = true
|
|
|
|
|
|
|
|
public var isDefaultIPv6 = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct DNSSettings: Codable, Equatable, NetworkChoiceRepresentable, DNSSettingsProviding {
|
2022-04-14 05:24:03 +00:00
|
|
|
public enum ConfigurationType: String, Codable {
|
|
|
|
case plain
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
case https
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
case tls
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
case disabled
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public var choice: Network.Choice
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
public var configurationType: ConfigurationType = .plain
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
public var dnsProtocol: DNSProtocol? {
|
|
|
|
DNSProtocol(rawValue: configurationType.rawValue)
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
public var dnsServers: [String]?
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2023-03-17 21:16:04 +00:00
|
|
|
public var dnsDomain: String?
|
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
public var dnsSearchDomains: [String]?
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
public var dnsHTTPSURL: URL?
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public var dnsTLSServerName: String?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct ProxySettings: Codable, Equatable, NetworkChoiceRepresentable, ProxySettingsProviding {
|
2022-04-13 17:34:43 +00:00
|
|
|
public enum ConfigurationType: String, Codable {
|
|
|
|
case manual
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-13 17:34:43 +00:00
|
|
|
case pac
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-13 17:34:43 +00:00
|
|
|
case disabled
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public var choice: Network.Choice
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-13 17:34:43 +00:00
|
|
|
public var configurationType: ConfigurationType = .manual
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
public var proxyAddress: String?
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public var proxyPort: UInt16?
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-14 05:24:03 +00:00
|
|
|
public var proxyBypassDomains: [String]?
|
2022-04-12 13:09:14 +00:00
|
|
|
|
2022-04-13 17:45:27 +00:00
|
|
|
public var proxyAutoConfigurationURL: URL?
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public var proxyServer: Proxy? {
|
|
|
|
guard let address = proxyAddress, let port = proxyPort, !address.isEmpty, port > 0 else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return Proxy(address, port)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct MTUSettings: Codable, Equatable, NetworkChoiceRepresentable, MTUSettingsProviding {
|
|
|
|
public var choice: Network.Choice
|
|
|
|
|
|
|
|
public var mtuBytes = 0
|
|
|
|
}
|
|
|
|
}
|