Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interface name scanning when listening on IP unspecified for TCP/TLS/QUIC/WS #1123

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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