From 739b4ee106105fb102eac7d5960eeeb660e97f47 Mon Sep 17 00:00:00 2001 From: L-Trump <37738631+L-Trump@users.noreply.github.com> Date: Wed, 16 Apr 2025 21:58:39 +0800 Subject: [PATCH] fix: avoid add ipv6 listener automatically for specified ipv4 listener (#782) --- easytier/src/instance/listeners.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/easytier/src/instance/listeners.rs b/easytier/src/instance/listeners.rs index 65350f9..26a2d97 100644 --- a/easytier/src/instance/listeners.rs +++ b/easytier/src/instance/listeners.rs @@ -1,4 +1,4 @@ -use std::{fmt::Debug, sync::Arc}; +use std::{fmt::Debug, net::IpAddr, str::FromStr, sync::Arc}; use anyhow::Context; use async_trait::async_trait; @@ -54,6 +54,14 @@ pub fn is_url_host_ipv6(l: &url::Url) -> bool { l.host_str().map_or(false, |h| h.contains(':')) } +pub fn is_url_host_unspecified(l: &url::Url) -> bool { + if let Ok(ip) = IpAddr::from_str(l.host_str().unwrap_or_default()) { + ip.is_unspecified() + } else { + false + } +} + #[async_trait] pub trait TunnelHandlerForListener { async fn handle_tunnel(&self, tunnel: Box) -> Result<(), Error>; @@ -126,7 +134,10 @@ impl ListenerManage ) .await?; - if self.global_ctx.config.get_flags().enable_ipv6 && !is_url_host_ipv6(&l) { + if self.global_ctx.config.get_flags().enable_ipv6 + && !is_url_host_ipv6(&l) + && is_url_host_unspecified(&l) + { let mut ipv6_listener = l.clone(); ipv6_listener .set_host(Some("[::]".to_string().as_str()))