mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-02-21 23:32:03 +00:00
Model: Use DNSServer in the Configuration model
This commit is contained in:
parent
bebbaeaa93
commit
e0ee01db78
@ -24,7 +24,7 @@ struct InterfaceConfiguration: Codable {
|
|||||||
var addresses: [IPAddressRange] = []
|
var addresses: [IPAddressRange] = []
|
||||||
var listenPort: UInt16? = nil
|
var listenPort: UInt16? = nil
|
||||||
var mtu: UInt64? = nil
|
var mtu: UInt64? = nil
|
||||||
var dns: String? = nil
|
var dns: [DNSServer] = []
|
||||||
|
|
||||||
init(name: String, privateKey: Data) {
|
init(name: String, privateKey: Data) {
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -74,8 +74,8 @@ class TunnelViewModel {
|
|||||||
if let mtu = config.mtu {
|
if let mtu = config.mtu {
|
||||||
scratchpad[.mtu] = String(mtu)
|
scratchpad[.mtu] = String(mtu)
|
||||||
}
|
}
|
||||||
if let dns = config.dns {
|
if (!config.dns.isEmpty) {
|
||||||
scratchpad[.dns] = String(dns)
|
scratchpad[.dns] = config.dns.map { $0.stringRepresentation() }.joined(separator: ", ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,9 +124,18 @@ class TunnelViewModel {
|
|||||||
errorMessages.append("Interface's MTU should be a number")
|
errorMessages.append("Interface's MTU should be a number")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Validate DNS
|
|
||||||
if let dnsString = scratchpad[.dns] {
|
if let dnsString = scratchpad[.dns] {
|
||||||
config.dns = dnsString
|
var dnsServers: [DNSServer] = []
|
||||||
|
for dnsServerString in dnsString.split(separator: ",") {
|
||||||
|
let trimmedString = dnsServerString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
||||||
|
if let dnsServer = DNSServer(from: trimmedString) {
|
||||||
|
dnsServers.append(dnsServer)
|
||||||
|
} else {
|
||||||
|
fieldsWithError.insert(.dns)
|
||||||
|
errorMessages.append("Interface's DNS should be a list of comma-separated IP addresses")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.dns = dnsServers
|
||||||
}
|
}
|
||||||
|
|
||||||
guard (errorMessages.isEmpty) else {
|
guard (errorMessages.isEmpty) else {
|
||||||
|
Loading…
Reference in New Issue
Block a user