diff --git a/TunnelKit/Sources/Core/SocketType.swift b/TunnelKit/Sources/Core/SocketType.swift index 2bf5209..bd0ddff 100644 --- a/TunnelKit/Sources/Core/SocketType.swift +++ b/TunnelKit/Sources/Core/SocketType.swift @@ -33,4 +33,16 @@ public enum SocketType: String { /// TCP socket type. case tcp = "TCP" + + /// UDP socket type (IPv4). + case udp4 = "UDP4" + + /// TCP socket type (IPv4). + case tcp4 = "TCP4" + + /// UDP socket type (IPv6). + case udp6 = "UDP6" + + /// TCP socket type (IPv6). + case tcp6 = "TCP6" } diff --git a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/ConnectionStrategy.swift b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/ConnectionStrategy.swift index 0b4b78d..e00b4cb 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/ConnectionStrategy.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/ConnectionStrategy.swift @@ -156,11 +156,11 @@ private extension NEProvider { func createSocket(to address: String, protocol endpointProtocol: EndpointProtocol) -> GenericSocket { let endpoint = NWHostEndpoint(hostname: address, port: "\(endpointProtocol.port)") switch endpointProtocol.socketType { - case .udp: + case .udp, .udp4, .udp6: let impl = createUDPSession(to: endpoint, from: nil) return NEUDPSocket(impl: impl) - case .tcp: + case .tcp, .tcp4, .tcp6: let impl = createTCPConnection(to: endpoint, enableTLS: false, tlsParameters: nil, delegate: nil) return NETCPSocket(impl: impl) } diff --git a/TunnelKit/Sources/Protocols/OpenVPN/ConfigurationParser.swift b/TunnelKit/Sources/Protocols/OpenVPN/ConfigurationParser.swift index 49d4dba..a03fa89 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/ConfigurationParser.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/ConfigurationParser.swift @@ -62,11 +62,11 @@ extension OpenVPN { // MARK: Client - static let proto = NSRegularExpression("^proto +(udp6?|tcp6?)") + static let proto = NSRegularExpression("^proto +(udp[46]?|tcp[46]?)") static let port = NSRegularExpression("^port +\\d+") - static let remote = NSRegularExpression("^remote +[^ ]+( +\\d+)?( +(udp6?|tcp6?))?") + static let remote = NSRegularExpression("^remote +[^ ]+( +\\d+)?( +(udp[46]?|tcp[46]?))?") static let eku = NSRegularExpression("^remote-cert-tls +server") @@ -817,10 +817,6 @@ private extension String { private extension SocketType { init?(protoString: String) { - var str = protoString - if str.hasSuffix("6") { - str.removeLast() - } - self.init(rawValue: str.uppercased()) + self.init(rawValue: protoString.uppercased()) } }