From b5902da5a95e863dfad7e1d15afaef07fc6fba0a Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 23 Oct 2024 12:26:36 +0200 Subject: [PATCH] fix(udp/bench): enforce max 64k UDP datagram limit Linux drops UDP datagrams larger than 64k, even when segmented. In other words, 64k - headers is the maximum GSO payload size. --- quinn-udp/benches/throughput.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/quinn-udp/benches/throughput.rs b/quinn-udp/benches/throughput.rs index 1ba2db1a9..46385d73a 100644 --- a/quinn-udp/benches/throughput.rs +++ b/quinn-udp/benches/throughput.rs @@ -1,4 +1,5 @@ use std::{ + cmp::min, io::{ErrorKind, IoSliceMut}, net::{Ipv4Addr, Ipv6Addr, UdpSocket}, }; @@ -51,7 +52,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { } else { 1 }; - let msg = vec![0xAB; SEGMENT_SIZE * gso_segments]; + let msg = vec![0xAB; min(MAX_DATAGRAM_SIZE, SEGMENT_SIZE * gso_segments)]; let transmit = Transmit { destination: dst_addr, ecn: None, @@ -117,3 +118,6 @@ fn new_socket() -> (UdpSocketState, tokio::net::UdpSocket) { criterion_group!(benches, criterion_benchmark); criterion_main!(benches); + +const MAX_IP_UDP_HEADER_SIZE: usize = 48; +const MAX_DATAGRAM_SIZE: usize = u16::MAX as usize - MAX_IP_UDP_HEADER_SIZE;