diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index ef9da018fb..ecaf2712bc 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -697,17 +697,23 @@ impl MagicSock { let mut quic_packets_total = 0; for (meta, buf) in metas.iter_mut().zip(bufs.iter_mut()).take(msgs) { - let mut start = 0; let mut is_quic = false; let mut quic_packets_count = 0; + if meta.len > meta.stride { + trace!(%meta.len, %meta.stride, "GRO datagram received"); + inc!(MagicsockMetrics, recv_gro_datagrams); + } // find disco and stun packets and forward them to the actor - loop { - let end = start + meta.stride; - if end > meta.len { - break; + for packet in buf[..meta.len].chunks_mut(meta.stride) { + if packet.len() < meta.stride { + trace!( + len = %packet.len(), + %meta.stride, + "Last GRO datagram smaller than stride", + ); } - let packet = &buf[start..end]; + 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); @@ -740,9 +746,8 @@ impl MagicSock { // this makes quinn reliably and quickly ignore the packet as long as // [`quinn::EndpointConfig::grease_quic_bit`] is set to `false` // (which we always do in Endpoint::bind). - buf[start] = 0u8; + packet[0] = 0u8; } - start = end; } if is_quic { diff --git a/iroh-net/src/magicsock/metrics.rs b/iroh-net/src/magicsock/metrics.rs index 0f3b8b40f1..5c0a97148f 100644 --- a/iroh-net/src/magicsock/metrics.rs +++ b/iroh-net/src/magicsock/metrics.rs @@ -24,6 +24,8 @@ pub struct Metrics { pub recv_data_ipv6: Counter, /// Number of QUIC datagrams received. pub recv_datagrams: Counter, + /// Number of datagrams received using GRO + pub recv_gro_datagrams: Counter, // Disco packets pub send_disco_udp: Counter, @@ -90,6 +92,7 @@ impl Default for Metrics { recv_data_ipv4: Counter::new("recv_data_ipv4"), recv_data_ipv6: Counter::new("recv_data_ipv6"), recv_datagrams: Counter::new("recv_datagrams"), + recv_gro_datagrams: Counter::new("recv_gro_packets"), // Disco packets send_disco_udp: Counter::new("disco_send_udp"),