diff --git a/dragonfly-client-config/src/dfdaemon.rs b/dragonfly-client-config/src/dfdaemon.rs index 1ee10bc2..106e6f6f 100644 --- a/dragonfly-client-config/src/dfdaemon.rs +++ b/dragonfly-client-config/src/dfdaemon.rs @@ -388,6 +388,9 @@ pub struct Host { /// ip is the advertise ip of the host. pub ip: Option, + + /// enable_dual_stack indicates whether enable dual stack. + pub enable_dual_stack: bool, } /// Host implements Default. @@ -398,6 +401,7 @@ impl Default for Host { location: None, hostname: default_host_hostname(), ip: None, + enable_dual_stack: false, } } } @@ -1079,6 +1083,9 @@ pub struct ProxyServer { /// ip is the listen ip of the proxy server. pub ip: Option, + /// enable_dual_stack indicates whether enable dual stack. + pub enable_dual_stack: bool, + /// port is the port to the proxy server. #[serde(default = "default_proxy_server_port")] pub port: u16, @@ -1289,6 +1296,9 @@ pub struct Security { pub struct Network { /// enable_ipv6 indicates whether enable ipv6. pub enable_ipv6: bool, + + /// enable_dual_stack indicates whether enable dual stack. + pub enable_dual_stack: bool, } /// HealthServer is the health server configuration for dfdaemon. @@ -1349,6 +1359,9 @@ impl Default for MetricsServer { pub struct Metrics { /// server is the metrics server configuration for dfdaemon. pub server: MetricsServer, + + /// enable_dual_stack indicates whether enable dual stack. + pub enable_dual_stack: bool, } /// StatsServer is the stats server configuration for dfdaemon. @@ -1379,6 +1392,9 @@ impl Default for StatsServer { pub struct Stats { /// server is the stats server configuration for dfdaemon. pub server: StatsServer, + + /// enable_dual_stack indicates whether enable dual stack. + pub enable_dual_stack: bool, } /// Tracing is the tracing configuration for dfdaemon. diff --git a/dragonfly-client-util/src/net/mod.rs b/dragonfly-client-util/src/net/mod.rs index 3f143d2f..bbf8bab6 100644 --- a/dragonfly-client-util/src/net/mod.rs +++ b/dragonfly-client-util/src/net/mod.rs @@ -17,7 +17,7 @@ use bytesize::{ByteSize, MB}; use pnet::datalink::{self, NetworkInterface}; use std::cmp::min; -use std::net::IpAddr; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; #[cfg(not(target_os = "linux"))] use tracing::warn; @@ -83,3 +83,26 @@ pub fn get_interface_info(ip: IpAddr, rate_limit: ByteSize) -> Option }), } } + +/// DualStack represents a dual stack with ipv4 and ipv6. +pub struct DualStack { + pub ipv4: Option, + pub ipv6: Option, +} + +impl DualStack { + /// new creates a new DualStack. + pub fn new(ipv4: Option, ipv6: Option) -> Self { + Self { ipv4, ipv6 } + } + + // get_ip returns the ip address. + pub fn get_ip(&self) -> Option { + match (self.ipv4, self.ipv6) { + (Some(v4), Some(v6)) => Some(format!("{},{}", v4, v6)), + (Some(v4), None) => Some(v4.to_string()), + (None, Some(v6)) => Some(v6.to_string()), + (None, None) => None, + } + } +}