Set UDP socket buffer sizes to prevent receive overflow

Under high-throughput forwarding, the kernel default 212KB receive
buffer overflows, silently dropping ~11% of UDP datagrams at transit
nodes. Add configurable recv_buf_size and send_buf_size to UdpConfig
(default 2MB each) using socket2 for pre-bind buffer configuration.
Startup log now reports actual buffer sizes granted by the kernel.

Requires net.core.rmem_max >= 2097152 on the host for the full 2MB
to take effect; otherwise the kernel silently clamps.
This commit is contained in:
Johnathan Corgan
2026-02-19 05:51:36 +00:00
parent 8cc9532bad
commit ac82e61c77
7 changed files with 83 additions and 4 deletions
+3
View File
@@ -20,6 +20,7 @@ async fn test_two_node_handshake_udp() {
let udp_config = UdpConfig {
bind_addr: Some("127.0.0.1:0".to_string()),
mtu: Some(1280),
..Default::default()
};
let (packet_tx_a, mut packet_rx_a) = packet_channel(64);
@@ -255,6 +256,7 @@ async fn test_run_rx_loop_handshake() {
let udp_config = UdpConfig {
bind_addr: Some("127.0.0.1:0".to_string()),
mtu: Some(1280),
..Default::default()
};
let (packet_tx_a, packet_rx_a) = packet_channel(64);
@@ -445,6 +447,7 @@ async fn test_cross_connection_both_initiate() {
let udp_config = UdpConfig {
bind_addr: Some("127.0.0.1:0".to_string()),
mtu: Some(1280),
..Default::default()
};
let (packet_tx_a, mut packet_rx_a) = packet_channel(64);
+1
View File
@@ -25,6 +25,7 @@ pub(super) async fn make_test_node() -> TestNode {
let udp_config = UdpConfig {
bind_addr: Some("127.0.0.1:0".to_string()),
mtu: Some(1280),
..Default::default()
};
let (packet_tx, packet_rx) = packet_channel(256);