connlib: update upstream dns format configuration (#2543)

fixes #2297
This commit is contained in:
Gabi
2023-11-03 02:16:03 -03:00
committed by GitHub
parent b404f10d87
commit 953ddeace6
2 changed files with 27 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
use async_compression::tokio::bufread::GzipEncoder;
use std::net::{IpAddr, SocketAddr};
use connlib_shared::messages::{DnsServer, IpDnsServer};
use std::path::PathBuf;
use std::{io, sync::Arc};
@@ -37,7 +37,7 @@ pub struct ControlPlane<CB: Callbacks> {
}
fn create_resolver(
upstream_dns: Vec<IpAddr>,
upstream_dns: Vec<DnsServer>,
callbacks: &impl Callbacks,
) -> Option<TokioAsyncResolver> {
let dns_servers = if upstream_dns.is_empty() {
@@ -48,13 +48,23 @@ fn create_resolver(
return None;
}
dns_servers
.into_iter()
.map(|ip| {
DnsServer::IpPort(IpDnsServer {
address: (ip, DNS_PORT).into(),
})
})
.collect()
} else {
upstream_dns
};
let mut resolver_config = ResolverConfig::new();
for ip in dns_servers.iter() {
let name_server = NameServerConfig::new(SocketAddr::new(*ip, DNS_PORT), Protocol::Udp);
for srv in dns_servers.iter() {
let name_server = match srv {
DnsServer::IpPort(srv) => NameServerConfig::new(srv.address, Protocol::Udp),
};
resolver_config.add_name_server(name_server);
}

View File

@@ -1,5 +1,5 @@
//! Message types that are used by both the gateway and client.
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use chrono::{serde::ts_seconds, DateTime, Utc};
use ip_network::IpNetwork;
@@ -203,6 +203,17 @@ pub struct ResourceDescriptionCidr {
pub name: String,
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(tag = "protocol", rename_all = "snake_case")]
pub enum DnsServer {
IpPort(IpDnsServer),
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct IpDnsServer {
pub address: SocketAddr,
}
/// Represents a wireguard interface configuration.
///
/// Note that the ips are /32 for ipv4 and /128 for ipv6.
@@ -216,7 +227,7 @@ pub struct Interface {
/// DNS that will be used to query for DNS that aren't within our resource list.
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub upstream_dns: Vec<IpAddr>,
pub upstream_dns: Vec<DnsServer>,
}
/// A single relay