From fa9265ff5162adc962402836bb28132ef3a09936 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Fri, 22 May 2026 07:40:24 +0200 Subject: [PATCH] test(client): cover accepted LAN destinations The Windows TAP receive path depends on accepting relay frames that are addressed to the client virtual MAC as well as broadcast and multicast LAN traffic. That is what carries DHCP, ARP, and LAN discovery back into the TAP adapter. Add a focused client-core test for the destination classifier so unrelated unicast stays dropped while directed, broadcast, and multicast LAN frames continue to be accepted. Test Plan: - cargo fmt --check - cargo test -p lanparty-client-core accepts_lan_destinations_for_client_tap - cargo test -p lanparty-client-core - cargo clippy -p lanparty-client-core --all-targets -- -D warnings - git diff --check - git diff --cached --check Refs: MVP TAP receive validation --- crates/lanparty-client-core/src/lib.rs | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/lanparty-client-core/src/lib.rs b/crates/lanparty-client-core/src/lib.rs index c514f71..9b4a0a2 100644 --- a/crates/lanparty-client-core/src/lib.rs +++ b/crates/lanparty-client-core/src/lib.rs @@ -1066,6 +1066,37 @@ mod tests { assert_eq!(snapshot.malformed_frames(), 1); } + #[test] + fn accepts_lan_destinations_for_client_tap() { + let virtual_mac = MacAddr::new([0x02, 0, 0, 0, 0, 1]); + let lan_source = MacAddr::new([0x0a, 0, 0, 0, 0, 2]); + + assert!(accepted_relay_destination( + virtual_mac, + lan_source, + virtual_mac, + b"directed", + )); + assert!(accepted_relay_destination( + MacAddr::BROADCAST, + lan_source, + virtual_mac, + b"broadcast", + )); + assert!(accepted_relay_destination( + MacAddr::new([0x01, 0x00, 0x5e, 0, 0, 1]), + lan_source, + virtual_mac, + b"multicast", + )); + assert!(!accepted_relay_destination( + MacAddr::new([0x02, 0, 0, 0, 0, 9]), + lan_source, + virtual_mac, + b"wrong client", + )); + } + #[test] fn converts_relay_rtt_to_milliseconds() { assert_eq!(duration_millis_saturating(Duration::from_micros(999)), 0); @@ -1168,6 +1199,23 @@ mod tests { frame } + fn accepted_relay_destination( + destination: MacAddr, + source: MacAddr, + virtual_mac: MacAddr, + payload: &[u8], + ) -> bool { + let bytes = ethernet_frame_with_headers( + destination, + source, + lanparty_proto::ETHERTYPE_IPV4, + payload, + ); + let frame = EthernetFrame::parse(&bytes).unwrap(); + + is_accepted_relay_destination(frame, virtual_mac) + } + fn unique_temp_identity_path() -> std::path::PathBuf { let nanos = SystemTime::now() .duration_since(UNIX_EPOCH)