global: support DNS search domains
This has been supported by Windows and Linux for quite some time. Add support here for iOS and macOS. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -74,6 +74,7 @@ extension TunnelConfiguration {
|
||||
|
||||
interfaceConfiguration?.addresses = base?.interface.addresses ?? []
|
||||
interfaceConfiguration?.dns = base?.interface.dns ?? []
|
||||
interfaceConfiguration?.dnsSearch = base?.interface.dnsSearch ?? []
|
||||
interfaceConfiguration?.mtu = base?.interface.mtu
|
||||
|
||||
if let interfaceConfiguration = interfaceConfiguration {
|
||||
|
||||
@@ -139,8 +139,10 @@ class TunnelViewModel {
|
||||
if let mtu = config.mtu {
|
||||
scratchpad[.mtu] = String(mtu)
|
||||
}
|
||||
if !config.dns.isEmpty {
|
||||
scratchpad[.dns] = config.dns.map { $0.stringRepresentation }.joined(separator: ", ")
|
||||
if !config.dns.isEmpty || !config.dnsSearch.isEmpty {
|
||||
var dns = config.dns.map { $0.stringRepresentation }
|
||||
dns.append(contentsOf: config.dnsSearch)
|
||||
scratchpad[.dns] = dns.joined(separator: ", ")
|
||||
}
|
||||
return scratchpad
|
||||
}
|
||||
@@ -194,15 +196,16 @@ class TunnelViewModel {
|
||||
}
|
||||
if let dnsString = scratchpad[.dns] {
|
||||
var dnsServers = [DNSServer]()
|
||||
var dnsSearch = [String]()
|
||||
for dnsServerString in dnsString.splitToArray(trimmingCharacters: .whitespacesAndNewlines) {
|
||||
if let dnsServer = DNSServer(from: dnsServerString) {
|
||||
dnsServers.append(dnsServer)
|
||||
} else {
|
||||
fieldsWithError.insert(.dns)
|
||||
errorMessages.append(tr("alertInvalidInterfaceMessageDNSInvalid"))
|
||||
dnsSearch.append(dnsServerString)
|
||||
}
|
||||
}
|
||||
config.dns = dnsServers
|
||||
config.dnsSearch = dnsSearch
|
||||
}
|
||||
|
||||
guard errorMessages.isEmpty else { return .error(errorMessages.first!) }
|
||||
|
||||
@@ -337,11 +337,6 @@ static bool is_valid_network(string_span_t s)
|
||||
return is_valid_ipv4(s) || is_valid_ipv6(s);
|
||||
}
|
||||
|
||||
static bool is_valid_dns(string_span_t s)
|
||||
{
|
||||
return is_valid_ipv4(s) || is_valid_ipv6(s);
|
||||
}
|
||||
|
||||
enum field {
|
||||
InterfaceSection,
|
||||
PrivateKey,
|
||||
@@ -451,7 +446,12 @@ static void highlight_multivalue_value(struct highlight_span_array *ret, const s
|
||||
{
|
||||
switch (section) {
|
||||
case DNS:
|
||||
append_highlight_span(ret, parent.s, s, is_valid_dns(s) ? HighlightIP : HighlightError);
|
||||
if (is_valid_ipv4(s) || is_valid_ipv6(s))
|
||||
append_highlight_span(ret, parent.s, s, HighlightIP);
|
||||
else if (is_valid_hostname(s))
|
||||
append_highlight_span(ret, parent.s, s, HighlightHost);
|
||||
else
|
||||
append_highlight_span(ret, parent.s, s, HighlightError);
|
||||
break;
|
||||
case Address:
|
||||
case AllowedIPs: {
|
||||
|
||||
Reference in New Issue
Block a user