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)