From 0953ce5ad3996187aee7a3d84c133d28d023f372 Mon Sep 17 00:00:00 2001 From: t4lz Date: Tue, 21 Jan 2025 17:44:45 +0100 Subject: [PATCH] Add other enum variants --- mirrord/agent/src/dns.rs | 12 ++++++++++- mirrord/protocol/src/dns.rs | 40 ++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/mirrord/agent/src/dns.rs b/mirrord/agent/src/dns.rs index 45a8d2a59b0..89b2eb66800 100644 --- a/mirrord/agent/src/dns.rs +++ b/mirrord/agent/src/dns.rs @@ -123,7 +123,17 @@ impl DnsWorker { options.attempts = attempts; options.ip_strategy = if support_ipv6 { tracing::debug!("IPv6 support enabled. Respecting client IP family."); - request.family.into() + request + .family + .try_into() + .inspect_err(|e| { + tracing::error!(%e, + "Unknown address family in addrinfo request. Using IPv4 and IPv6.") + }) + // If the agent gets some new, unknown variant of family address, it's the + // client's fault, so the agent queries both IPv4 and IPv6 and if that's not + // good enough for the client, the client can error out. + .unwrap_or(hickory_resolver::config::LookupIpStrategy::Ipv4AndIpv6) } else { tracing::debug!("IPv6 support disabled. Resolving IPv4 only."); hickory_resolver::config::LookupIpStrategy::Ipv4Only diff --git a/mirrord/protocol/src/dns.rs b/mirrord/protocol/src/dns.rs index 789a6d61953..7b61a1d9662 100644 --- a/mirrord/protocol/src/dns.rs +++ b/mirrord/protocol/src/dns.rs @@ -86,28 +86,54 @@ impl From for GetAddrInfoRequest { } } -#[derive(Encode, Decode, Debug, PartialEq, Eq, Copy, Clone)] +#[derive( + serde::Serialize, serde::Deserialize, Encode, Decode, Debug, PartialEq, Eq, Copy, Clone, +)] pub enum AddressFamily { Ipv4Only, Ipv6Only, Both, + Any, + /// If we add a variant and a new client sends an old agent the new variant, the agent will see + /// this variant. + #[serde(other, skip_serializing)] + UnknownAddressFamilyFromNewerClient, +} + +#[derive(thiserror::Error, Debug)] +pub enum AddressFamilyError { + #[error( + "The agent received a GetAddrInfoRequestV2 with an address family that is not yet known \ + to this version of the agent." + )] + UnsupportedFamily, } -impl From for hickory_resolver::config::LookupIpStrategy { - fn from(value: AddressFamily) -> Self { +impl TryFrom for hickory_resolver::config::LookupIpStrategy { + type Error = AddressFamilyError; + + fn try_from(value: AddressFamily) -> Result { match value { - AddressFamily::Ipv4Only => Self::Ipv4Only, - AddressFamily::Ipv6Only => Self::Ipv6Only, - AddressFamily::Both => Self::Ipv4AndIpv6, + AddressFamily::Ipv4Only => Ok(Self::Ipv4Only), + AddressFamily::Ipv6Only => Ok(Self::Ipv6Only), + AddressFamily::Both => Ok(Self::Ipv4AndIpv6), + AddressFamily::Any => Ok(Self::Ipv4thenIpv6), + AddressFamily::UnknownAddressFamilyFromNewerClient => { + Err(AddressFamilyError::UnsupportedFamily) + } } } } -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)] +#[derive(serde::Serialize, serde::Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)] pub enum SockType { Stream, Dgram, Any, + /// If we add a variant and a new client sends an old agent the new variant, the agent will see + /// this variant. + #[serde(other, skip_serializing)] + UnknownSockTypeFromNewerClient, } /// Newer, advanced version of [`GetAddrInfoRequest`]