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:
@@ -14,8 +14,8 @@ use lanparty_ctrl::{
|
||||
};
|
||||
use lanparty_obs::{DropReason, FrameAction};
|
||||
use lanparty_proto::{
|
||||
EthernetFrame, MacAddr, gateway_lan_safety_drop_reason, recommended_tap_mtu,
|
||||
remote_client_safety_drop_reason,
|
||||
EthernetFrame, MacAddr, ethernet_frame_exceeds_tap_mtu, gateway_lan_safety_drop_reason,
|
||||
recommended_tap_mtu, remote_client_safety_drop_reason,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -31,8 +31,6 @@ const CLIENT_UNKNOWN_UNICAST_REFILL_FRAMES_PER_SECOND: u32 = 32;
|
||||
const CLIENT_TOTAL_BANDWIDTH_BURST_BYTES: u64 = 4 * MEBIBYTE;
|
||||
const CLIENT_TOTAL_BANDWIDTH_REFILL_BYTES_PER_SECOND: u64 = 2 * MEBIBYTE;
|
||||
#[cfg(test)]
|
||||
use lanparty_proto::ETHERNET_HEADER_LEN;
|
||||
#[cfg(test)]
|
||||
const ETHERTYPE_IPV4: u16 = 0x0800;
|
||||
#[cfg(test)]
|
||||
const ETHERTYPE_LLDP: u16 = 0x88cc;
|
||||
@@ -561,6 +559,11 @@ impl Room {
|
||||
if let Some(drop_reason) = safety_drop_reason {
|
||||
return Ok(ForwardingDecision::filtered(DropReason::from(drop_reason)));
|
||||
}
|
||||
if let Some(effective_tap_mtu) = self.effective_tap_mtu
|
||||
&& ethernet_frame_exceeds_tap_mtu(frame, usize::from(effective_tap_mtu))
|
||||
{
|
||||
return Ok(ForwardingDecision::dropped(DropReason::TapMtuExceeded));
|
||||
}
|
||||
|
||||
if ingress_role == Role::Client
|
||||
&& !self.allow_client_total_bandwidth(ingress_peer_id, frame.len() as u64, now)
|
||||
@@ -1263,7 +1266,7 @@ mod tests {
|
||||
let mut registry = RoomRegistry::default();
|
||||
let client_one = registry.join(client_hello(1)).unwrap();
|
||||
let client_two = registry.join(client_hello(2)).unwrap();
|
||||
let payload = vec![0; MAX_STANDARD_ETHERNET_FRAME_LEN - ETHERNET_HEADER_LEN];
|
||||
let payload = vec![0; usize::from(client_one.welcome().effective_tap_mtu())];
|
||||
let frame = ethernet_with_payload(mac(2), mac(1), ETHERTYPE_IPV4, &payload);
|
||||
let frame_len = frame.len() as u64;
|
||||
let burst_frames = CLIENT_TOTAL_BANDWIDTH_BURST_BYTES / frame_len;
|
||||
@@ -1353,6 +1356,32 @@ mod tests {
|
||||
assert_filtered(&decision, DropReason::JumboFrame);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drops_frames_above_effective_tap_mtu() {
|
||||
let mut registry = RoomRegistry::default();
|
||||
let gateway = registry.join(gateway_hello()).unwrap();
|
||||
let client = registry.join(client_hello(1)).unwrap();
|
||||
let oversized_payload = vec![0; usize::from(client.welcome().effective_tap_mtu()) + 1];
|
||||
let client_frame = ethernet_with_payload(
|
||||
MacAddr::BROADCAST,
|
||||
mac(1),
|
||||
ETHERTYPE_IPV4,
|
||||
&oversized_payload,
|
||||
);
|
||||
let gateway_frame =
|
||||
ethernet_with_payload(mac(1), physical_mac(), ETHERTYPE_IPV4, &oversized_payload);
|
||||
|
||||
let client_decision = registry
|
||||
.forward_ethernet(&room(), client.peer().peer_id(), &client_frame)
|
||||
.unwrap();
|
||||
let gateway_decision = registry
|
||||
.forward_ethernet(&room(), gateway.peer().peer_id(), &gateway_frame)
|
||||
.unwrap();
|
||||
|
||||
assert_dropped(&client_decision, DropReason::TapMtuExceeded);
|
||||
assert_dropped(&gateway_decision, DropReason::TapMtuExceeded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filters_l2_control_plane_frames_from_clients_and_gateway() {
|
||||
let mut registry = RoomRegistry::default();
|
||||
|
||||
Reference in New Issue
Block a user