Skip to content

Commit

Permalink
Add other enum variants
Browse files Browse the repository at this point in the history
  • Loading branch information
t4lz committed Jan 22, 2025
1 parent 833398c commit 0953ce5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
12 changes: 11 additions & 1 deletion mirrord/agent/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 33 additions & 7 deletions mirrord/protocol/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,54 @@ impl From<GetAddrInfoRequestV2> 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<AddressFamily> for hickory_resolver::config::LookupIpStrategy {
fn from(value: AddressFamily) -> Self {
impl TryFrom<AddressFamily> for hickory_resolver::config::LookupIpStrategy {
type Error = AddressFamilyError;

fn try_from(value: AddressFamily) -> Result<Self, Self::Error> {
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`]
Expand Down

0 comments on commit 0953ce5

Please sign in to comment.