Skip to content

Commit

Permalink
fix(net): correct packet math for poll_recv (#1698)
Browse files Browse the repository at this point in the history
## Description

- `meta.len` is the length of the actually received data (not
`buf.len()`)
- `meta.stride` is the length of an individual packet (not `meta.len`)

This was triggering #1696
because for STUN packets the additional (empty) buffer was considered to
be QUIC packets, resulting in the warning.
  • Loading branch information
dignifiedquire authored Oct 21, 2023
1 parent d0c7cac commit c603a9e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,26 +528,28 @@ impl Inner {
// find disco and stun packets and forward them to the actor
loop {
let end = start + meta.stride;
if end > buf.len() {
if end > meta.len {
break;
}
let packet = &buf[start..end];
let mut packet_is_quic = true;
if stun::is(packet) {
trace!(src = %meta.addr, len = %meta.len, "UDP recv: stun packet");
let packet_is_quic = if stun::is(packet) {
trace!(src = %meta.addr, len = %meta.stride, "UDP recv: stun packet");
let packet2 = Bytes::copy_from_slice(packet);
self.net_checker.receive_stun_packet(packet2, meta.addr);
packet_is_quic = false;
false
} else if let Some((sender, sealed_box)) = disco::source_and_box(packet) {
// Disco?
trace!(src = %meta.addr, len = %meta.len, "UDP recv: disco packet");
trace!(src = %meta.addr, len = %meta.stride, "UDP recv: disco packet");
self.handle_disco_message(
sender,
sealed_box,
DiscoMessageSource::Udp(meta.addr),
);
packet_is_quic = false;
}
false
} else {
trace!(src = %meta.addr, len = %meta.stride, "UDP recv: quic packet");
true
};

if packet_is_quic {
quic_packets_count += 1;
Expand Down

0 comments on commit c603a9e

Please sign in to comment.