Skip to content

Commit

Permalink
Fix interface name scanning when listening on IP unspecified for TCP/…
Browse files Browse the repository at this point in the history
…TLS/QUIC/WS (#1123)

Co-authored-by: Julien Enoch <[email protected]>
  • Loading branch information
Mallets and JEnoch authored Jun 12, 2024
1 parent 9d09742 commit ed6c636
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions io/zenoh-links/zenoh-link-quic/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions io/zenoh-links/zenoh-link-tcp/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
11 changes: 11 additions & 0 deletions io/zenoh-links/zenoh-link-tls/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions io/zenoh-links/zenoh-link-udp/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [::]. Their usage is discouraged. See https://github.com/eclipse-zenoh/zenoh/issues/1126.");
}

loop {
// Buffers for deserialization
let mut buff = zenoh_buffers::vec::uninit(UDP_MAX_MTU as usize);
Expand Down
9 changes: 9 additions & 0 deletions io/zenoh-links/zenoh-link-ws/src/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ed6c636

Please sign in to comment.