mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-12 04:37:23 +08:00
fix: avoid add ipv6 listener automatically for specified ipv4 listener (#782)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use std::{fmt::Debug, sync::Arc};
|
use std::{fmt::Debug, net::IpAddr, str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use async_trait::async_trait;
|
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(':'))
|
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]
|
#[async_trait]
|
||||||
pub trait TunnelHandlerForListener {
|
pub trait TunnelHandlerForListener {
|
||||||
async fn handle_tunnel(&self, tunnel: Box<dyn Tunnel>) -> Result<(), Error>;
|
async fn handle_tunnel(&self, tunnel: Box<dyn Tunnel>) -> Result<(), Error>;
|
||||||
@@ -126,7 +134,10 @@ impl<H: TunnelHandlerForListener + Send + Sync + 'static + Debug> ListenerManage
|
|||||||
)
|
)
|
||||||
.await?;
|
.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();
|
let mut ipv6_listener = l.clone();
|
||||||
ipv6_listener
|
ipv6_listener
|
||||||
.set_host(Some("[::]".to_string().as_str()))
|
.set_host(Some("[::]".to_string().as_str()))
|
||||||
|
|||||||
Reference in New Issue
Block a user