fix(tunnel): enforce negotiated TAP MTU

The MVP tunnel negotiates an effective TAP MTU and configures the Windows TAP IP
interface to that value, but the forwarding path only rejected frames that were
standard-Ethernet jumbo frames or exceeded the QUIC datagram budget. A frame
could therefore be larger than the negotiated TAP MTU while still fitting inside
the QUIC datagram budget.

Make the TAP-MTU frame limit an explicit shared protocol helper and enforce it
at every data-path boundary: Windows client send/receive, Linux gateway
send/receive, and relay forwarding. Such frames now produce TapMtuExceeded in
logs and counters instead of being forwarded until a later layer drops or
accepts them implicitly.

This keeps the no-fragmentation contract honest: one Ethernet frame still maps
to one QUIC datagram, but only if that frame also fits the room's negotiated TAP
MTU.

Test Plan:
- cargo fmt --check
- cargo test -p lanparty-proto tap_mtu
- cargo test -p lanparty-client-core connects_to_relay_control_stream_as_client
- cargo test -p lanparty-gateway connects_to_relay_control_stream_as_gateway
- cargo test -p lanparty-relay drops_frames_above_effective_tap_mtu
- cargo test -p lanparty-relay rate_limits_client_total_bandwidth_after_burst
- cargo test --workspace
- cargo clippy --workspace --all-targets -- -D warnings
- cargo build --release -p lanparty-relay -p lanparty-gateway
- git diff --check
- git diff --cached --check

Refs: MVP no-fragmentation tunnel MTU contract
This commit is contained in:
2026-05-22 07:15:11 +02:00
parent f229445c3d
commit bd22a68a6f
8 changed files with 131 additions and 23 deletions
+2 -1
View File
@@ -17,7 +17,8 @@ pub use ethernet::{
pub use mac::{MacAddr, MacParseError};
pub use mtu::{
DEFAULT_DATAGRAM_SAFETY_MARGIN, DEFAULT_TAP_MTU, MIN_USEFUL_TAP_MTU, MtuError,
max_tap_mtu_for_datagram, recommended_tap_mtu,
ethernet_frame_exceeds_tap_mtu, max_ethernet_frame_len_for_tap_mtu, max_tap_mtu_for_datagram,
recommended_tap_mtu,
};
pub use overlay::{
FrameType, OVERLAY_FLAGS_NONE, OVERLAY_HEADER_LEN, OVERLAY_MAGIC, OVERLAY_VERSION,
+25 -1
View File
@@ -1,6 +1,6 @@
use thiserror::Error;
use crate::{ETHERNET_HEADER_LEN, OVERLAY_HEADER_LEN};
use crate::{ETHERNET_HEADER_LEN, EthernetFrame, OVERLAY_HEADER_LEN};
pub const DEFAULT_TAP_MTU: usize = 1200;
pub const MIN_USEFUL_TAP_MTU: usize = 576;
@@ -40,6 +40,16 @@ pub fn recommended_tap_mtu(quic_max_datagram_size: usize) -> Result<usize, MtuEr
Ok(max.min(DEFAULT_TAP_MTU))
}
#[must_use]
pub const fn max_ethernet_frame_len_for_tap_mtu(tap_mtu: usize) -> usize {
ETHERNET_HEADER_LEN + tap_mtu
}
#[must_use]
pub const fn ethernet_frame_exceeds_tap_mtu(frame: EthernetFrame<'_>, tap_mtu: usize) -> bool {
frame.len() > max_ethernet_frame_len_for_tap_mtu(tap_mtu)
}
#[cfg(test)]
mod tests {
use super::*;
@@ -57,6 +67,20 @@ mod tests {
);
}
#[test]
fn checks_ethernet_frame_len_against_tap_mtu() {
let frame = vec![0; ETHERNET_HEADER_LEN + 1200];
let frame = EthernetFrame::parse(&frame).unwrap();
assert_eq!(max_ethernet_frame_len_for_tap_mtu(1200), 1214);
assert!(!ethernet_frame_exceeds_tap_mtu(frame, 1200));
let oversized = vec![0; ETHERNET_HEADER_LEN + 1201];
let oversized = EthernetFrame::parse(&oversized).unwrap();
assert!(ethernet_frame_exceeds_tap_mtu(oversized, 1200));
}
#[test]
fn rejects_too_small_datagram_budget() {
let error = recommended_tap_mtu(128).unwrap_err();