1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use rama_core::extensions::Extension;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash, Extension)]
#[extension(tags(net))]
/// Enum representing the IP modes that can be used by the DNS resolver.
pub enum DnsResolveIpMode {
#[default]
Dual,
SingleIpV4,
SingleIpV6,
DualPreferIpV4,
}
impl DnsResolveIpMode {
/// checks if IPv4 is supported in current mode
#[must_use]
pub fn ipv4_supported(&self) -> bool {
matches!(self, Self::Dual | Self::SingleIpV4 | Self::DualPreferIpV4)
}
/// checks if IPv6 is supported in current mode
#[must_use]
pub fn ipv6_supported(&self) -> bool {
matches!(self, Self::Dual | Self::SingleIpV6 | Self::DualPreferIpV4)
}
}
/// Mode for establishing a connection.
///
/// Classification is by wire family: an IPv4-mapped IPv6 address
/// (`::ffff:a.b.c.d`, [RFC 4291, Section 2.5.5.2]) counts as IPv4,
/// so [`Self::Ipv6`] rejects it and [`Self::Ipv4`] accepts it.
///
/// [RFC 4291, Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash, Extension)]
#[extension(tags(net))]
pub enum ConnectIpMode {
#[default]
Dual,
Ipv4,
Ipv6,
}