Skip to content

Commit ed6c636

Browse files
MalletsJEnoch
andauthored
Fix interface name scanning when listening on IP unspecified for TCP/TLS/QUIC/WS (#1123)
Co-authored-by: Julien Enoch <julien.e@zettascale.tech>
1 parent 9d09742 commit ed6c636

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

io/zenoh-links/zenoh-link-quic/src/unicast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,16 @@ async fn accept_task(
387387
}
388388
};
389389

390+
// Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used
391+
let src_addr = match quic_conn.local_ip() {
392+
Some(ip) => SocketAddr::new(ip, src_addr.port()),
393+
None => {
394+
tracing::debug!("Can not accept QUIC connection: empty local IP");
395+
continue;
396+
}
397+
};
390398
let dst_addr = quic_conn.remote_address();
399+
391400
tracing::debug!("Accepted QUIC connection on {:?}: {:?}", src_addr, dst_addr);
392401
// Create the new link object
393402
let link = Arc::new(LinkUnicastQuic::new(

io/zenoh-links/zenoh-link-tcp/src/unicast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,15 @@ async fn accept_task(
409409
res = accept(&socket) => {
410410
match res {
411411
Ok((stream, dst_addr)) => {
412+
// Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used
413+
let src_addr = match stream.local_addr() {
414+
Ok(sa) => sa,
415+
Err(e) => {
416+
tracing::debug!("Can not accept TCP connection: {}", e);
417+
continue;
418+
}
419+
};
420+
412421
tracing::debug!("Accepted TCP connection on {:?}: {:?}", src_addr, dst_addr);
413422
// Create the new link object
414423
let link = Arc::new(LinkUnicastTcp::new(stream, src_addr, dst_addr));

io/zenoh-links/zenoh-link-tls/src/unicast.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,15 @@ async fn accept_task(
372372
res = accept(&socket) => {
373373
match res {
374374
Ok((tcp_stream, dst_addr)) => {
375+
// Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used
376+
let src_addr = match tcp_stream.local_addr() {
377+
Ok(sa) => sa,
378+
Err(e) => {
379+
tracing::debug!("Can not accept TLS connection: {}", e);
380+
continue;
381+
}
382+
};
383+
375384
// Accept the TLS connection
376385
let tls_stream = match acceptor.accept(tcp_stream).await {
377386
Ok(stream) => TlsStream::Server(stream),
@@ -382,6 +391,8 @@ async fn accept_task(
382391
}
383392
};
384393

394+
395+
385396
tracing::debug!("Accepted TLS connection on {:?}: {:?}", src_addr, dst_addr);
386397
// Create the new link object
387398
let link = Arc::new(LinkUnicastTls::new(tls_stream, src_addr, dst_addr));

io/zenoh-links/zenoh-link-udp/src/unicast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ async fn accept_read_task(
498498

499499
tracing::trace!("Ready to accept UDP connections on: {:?}", src_addr);
500500

501+
if src_addr.ip().is_unspecified() {
502+
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.");
503+
}
504+
501505
loop {
502506
// Buffers for deserialization
503507
let mut buff = zenoh_buffers::vec::uninit(UDP_MAX_MTU as usize);

io/zenoh-links/zenoh-link-ws/src/unicast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,15 @@ async fn accept_task(
498498
_ = token.cancelled() => break,
499499
};
500500

501+
// Get the right source address in case an unsepecified IP (i.e. 0.0.0.0 or [::]) is used
502+
let src_addr = match stream.local_addr() {
503+
Ok(sa) => sa,
504+
Err(e) => {
505+
tracing::debug!("Can not accept TCP connection: {}", e);
506+
continue;
507+
}
508+
};
509+
501510
tracing::debug!(
502511
"Accepted TCP (WebSocket) connection on {:?}: {:?}",
503512
src_addr,

0 commit comments

Comments
 (0)