diff --git a/Cargo.lock b/Cargo.lock index 0fd5080..0fd01cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -470,6 +470,7 @@ dependencies = [ "anyhow", "clap", "lanparty-client-core", + "lanparty-client-route", "lanparty-client-tap", "lanparty-ctrl", "lanparty-proto", diff --git a/README.md b/README.md index 89541f2..74f9536 100644 --- a/README.md +++ b/README.md @@ -130,8 +130,9 @@ cargo run -p lanparty-client-win -- \ The Windows client binary currently connects to the relay as `role = client` with a generated locally administered virtual MAC persisted in `lanparty-client-identity.json`, completes the control-stream hello/welcome -handshake, and then bridges Ethernet frames between the relay and the first -TAP-Windows6 adapter until shutdown. `--virtual-mac` can still override the -stored identity for manual testing. On Windows it marks the TAP media -connected and reports the driver MAC/MTU before forwarding frames. Route -pinning and automatic TAP MAC/MTU configuration are not wired yet. +handshake, snapshots the current relay route, and then bridges Ethernet frames +between the relay and the first TAP-Windows6 adapter until shutdown. +`--virtual-mac` can still override the stored identity for manual testing. On +Windows it marks the TAP media connected and reports the driver MAC/MTU before +forwarding frames. Route pinning and automatic TAP MAC/MTU configuration are +not wired yet. diff --git a/crates/lanparty-client-win/Cargo.toml b/crates/lanparty-client-win/Cargo.toml index 3060cc8..d26509f 100644 --- a/crates/lanparty-client-win/Cargo.toml +++ b/crates/lanparty-client-win/Cargo.toml @@ -12,4 +12,5 @@ lanparty-proto = { path = "../lanparty-proto" } tokio.workspace = true [target.'cfg(windows)'.dependencies] +lanparty-client-route = { path = "../lanparty-client-route" } lanparty-client-tap = { path = "../lanparty-client-tap" } diff --git a/crates/lanparty-client-win/src/main.rs b/crates/lanparty-client-win/src/main.rs index a8b389a..f34b76c 100644 --- a/crates/lanparty-client-win/src/main.rs +++ b/crates/lanparty-client-win/src/main.rs @@ -13,6 +13,8 @@ use lanparty_client_core::{ ClientIdentity, ClientIdentityStore, ClientSession, ClientSessionConfig, connect_client, }; #[cfg(windows)] +use lanparty_client_route::RouteSnapshot; +#[cfg(windows)] use lanparty_client_tap::TapAdapter; use lanparty_ctrl::RoomCode; use lanparty_proto::MacAddr; @@ -106,6 +108,7 @@ async fn main() -> Result<()> { #[cfg(windows)] async fn run_client(session: &ClientSession) -> Result<()> { + log_relay_route_before_tap(session.config().relay_addr().ip()); let tap = open_tap_adapter(session)?; println!("bridging TAP frames; route pinning is not wired yet; press Ctrl-C to stop"); @@ -125,6 +128,33 @@ async fn run_client(session: &ClientSession) -> Result<()> { .context("failed to wait for Ctrl-C") } +#[cfg(windows)] +fn log_relay_route_before_tap(destination: std::net::IpAddr) { + match lanparty_client_route::best_route_to(destination) { + Ok(route) => print_relay_route(&route), + Err(error) => eprintln!( + "failed to inspect relay route before TAP activation; route pinning is not wired yet: {error:#}" + ), + } +} + +#[cfg(windows)] +fn print_relay_route(route: &RouteSnapshot) { + println!( + "relay route before TAP: destination {} source {} next hop {} interface index {} LUID {} prefix {}/{} metric {}", + route.destination(), + route.source(), + route + .next_hop() + .map_or_else(|| "on-link".to_string(), |next_hop| next_hop.to_string()), + route.interface_index(), + route.interface_luid(), + route.route_prefix(), + route.route_prefix_len(), + route.metric() + ); +} + #[cfg(windows)] fn open_tap_adapter(session: &ClientSession) -> Result { let tap = lanparty_client_tap::open_first_adapter()?;