From cf83a8d544f0896e193c502a72c10804be01399f Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 12 Jun 2024 12:09:23 +0200 Subject: [PATCH 1/3] Fix interface name scanning when listening on IP unspecified for TCP/TLS/QUIC/WS --- io/zenoh-links/zenoh-link-quic/src/unicast.rs | 9 +++++++++ io/zenoh-links/zenoh-link-tcp/src/unicast.rs | 9 +++++++++ io/zenoh-links/zenoh-link-tls/src/unicast.rs | 11 +++++++++++ io/zenoh-links/zenoh-link-udp/src/unicast.rs | 4 ++++ io/zenoh-links/zenoh-link-ws/src/unicast.rs | 9 +++++++++ 5 files changed, 42 insertions(+) diff --git a/io/zenoh-links/zenoh-link-quic/src/unicast.rs b/io/zenoh-links/zenoh-link-quic/src/unicast.rs index 8d4b82c339..8dde380577 100644 --- a/io/zenoh-links/zenoh-link-quic/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-quic/src/unicast.rs @@ -387,7 +387,16 @@ async fn accept_task( } }; + // Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used + let src_addr = match quic_conn.local_ip() { + Some(ip) => SocketAddr::new(ip, src_addr.port()), + None => { + tracing::debug!("Can not accept QUIC connection: empty local IP"); + continue; + } + }; let dst_addr = quic_conn.remote_address(); + tracing::debug!("Accepted QUIC connection on {:?}: {:?}", src_addr, dst_addr); // Create the new link object let link = Arc::new(LinkUnicastQuic::new( diff --git a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs index 3ef4f235ed..c07d6f15b9 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs @@ -409,6 +409,15 @@ async fn accept_task( res = accept(&socket) => { match res { Ok((stream, dst_addr)) => { + // Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used + let src_addr = match stream.local_addr() { + Ok(sa) => sa, + Err(e) => { + tracing::debug!("Can not accept TCP connection: {}", e); + continue; + } + }; + tracing::debug!("Accepted TCP connection on {:?}: {:?}", src_addr, dst_addr); // Create the new link object let link = Arc::new(LinkUnicastTcp::new(stream, src_addr, dst_addr)); diff --git a/io/zenoh-links/zenoh-link-tls/src/unicast.rs b/io/zenoh-links/zenoh-link-tls/src/unicast.rs index b12608354e..8776e0ae40 100644 --- a/io/zenoh-links/zenoh-link-tls/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tls/src/unicast.rs @@ -372,6 +372,15 @@ async fn accept_task( res = accept(&socket) => { match res { Ok((tcp_stream, dst_addr)) => { + // Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used + let src_addr = match tcp_stream.local_addr() { + Ok(sa) => sa, + Err(e) => { + tracing::debug!("Can not accept TLS connection: {}", e); + continue; + } + }; + // Accept the TLS connection let tls_stream = match acceptor.accept(tcp_stream).await { Ok(stream) => TlsStream::Server(stream), @@ -382,6 +391,8 @@ async fn accept_task( } }; + + tracing::debug!("Accepted TLS connection on {:?}: {:?}", src_addr, dst_addr); // Create the new link object let link = Arc::new(LinkUnicastTls::new(tls_stream, src_addr, dst_addr)); diff --git a/io/zenoh-links/zenoh-link-udp/src/unicast.rs b/io/zenoh-links/zenoh-link-udp/src/unicast.rs index 1fa9f9a7f4..563d93a517 100644 --- a/io/zenoh-links/zenoh-link-udp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-udp/src/unicast.rs @@ -498,6 +498,10 @@ async fn accept_read_task( tracing::trace!("Ready to accept UDP connections on: {:?}", src_addr); + if src_addr.ip().is_unspecified() { + tracing::warn!("Interceptors (e.g. Access Control, Downsampling) are not guaranteed to work on UDP when listening on 0.0.0.0 or [::]. See https://github.com/eclipse-zenoh/zenoh/issues/1093."); + } + loop { // Buffers for deserialization let mut buff = zenoh_buffers::vec::uninit(UDP_MAX_MTU as usize); diff --git a/io/zenoh-links/zenoh-link-ws/src/unicast.rs b/io/zenoh-links/zenoh-link-ws/src/unicast.rs index e94e4b6868..f1aa0088f0 100644 --- a/io/zenoh-links/zenoh-link-ws/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-ws/src/unicast.rs @@ -498,6 +498,15 @@ async fn accept_task( _ = token.cancelled() => break, }; + // Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used + let src_addr = match stream.local_addr() { + Ok(sa) => sa, + Err(e) => { + tracing::debug!("Can not accept TCP connection: {}", e); + continue; + } + }; + tracing::debug!( "Accepted TCP (WebSocket) connection on {:?}: {:?}", src_addr, From 4be0c386708e88729d685c2c0cbbca1f1c44fc1e Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 12 Jun 2024 12:12:44 +0200 Subject: [PATCH 2/3] Fix log message --- io/zenoh-links/zenoh-link-udp/src/unicast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/zenoh-links/zenoh-link-udp/src/unicast.rs b/io/zenoh-links/zenoh-link-udp/src/unicast.rs index 563d93a517..e62b07bf7d 100644 --- a/io/zenoh-links/zenoh-link-udp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-udp/src/unicast.rs @@ -499,7 +499,7 @@ async fn accept_read_task( tracing::trace!("Ready to accept UDP connections on: {:?}", src_addr); if src_addr.ip().is_unspecified() { - tracing::warn!("Interceptors (e.g. Access Control, Downsampling) are not guaranteed to work on UDP when listening on 0.0.0.0 or [::]. See https://github.com/eclipse-zenoh/zenoh/issues/1093."); + tracing::warn!("Interceptors (e.g. Access Control, Downsampling) are not guaranteed to work on UDP when listening on 0.0.0.0 or [::]. Their usage is discouraged. See https://github.com/eclipse-zenoh/zenoh/issues/1093."); } loop { From 56df4cefb285e6866cf434d3d98b6cd0c0b2e4f4 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Wed, 12 Jun 2024 15:51:16 +0200 Subject: [PATCH 3/3] Update log to refer #1126 rather than #1093 --- io/zenoh-links/zenoh-link-udp/src/unicast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/zenoh-links/zenoh-link-udp/src/unicast.rs b/io/zenoh-links/zenoh-link-udp/src/unicast.rs index e62b07bf7d..fba3e23b69 100644 --- a/io/zenoh-links/zenoh-link-udp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-udp/src/unicast.rs @@ -499,7 +499,7 @@ async fn accept_read_task( tracing::trace!("Ready to accept UDP connections on: {:?}", src_addr); if src_addr.ip().is_unspecified() { - tracing::warn!("Interceptors (e.g. Access Control, Downsampling) are not guaranteed to work on UDP when listening on 0.0.0.0 or [::]. Their usage is discouraged. See https://github.com/eclipse-zenoh/zenoh/issues/1093."); + tracing::warn!("Interceptors (e.g. Access Control, Downsampling) are not guaranteed to work on UDP when listening on 0.0.0.0 or [::]. Their usage is discouraged. See https://github.com/eclipse-zenoh/zenoh/issues/1126."); } loop {