diff --git a/src/bin/fips.rs b/src/bin/fips.rs index 1e95f9a..e4443fd 100644 --- a/src/bin/fips.rs +++ b/src/bin/fips.rs @@ -3,7 +3,7 @@ //! Loads configuration and creates the top-level node instance. use clap::Parser; -use fips::{Config, Node, TunState}; +use fips::{Config, Node}; use std::path::PathBuf; use tracing::{error, info, warn, Level}; use tracing_subscriber::{fmt, EnvFilter}; @@ -101,29 +101,6 @@ async fn main() { std::process::exit(1); } - // Show TUN interface details if active - if node.tun_state() == TunState::Active { - if let Some(tun_name) = node.config().tun.name.as_deref() { - let output = std::process::Command::new("ip") - .args(["link", "show", tun_name]) - .output(); - match output { - Ok(out) => { - if out.status.success() { - info!( - "ip link show {}:\n{}", - tun_name, - String::from_utf8_lossy(&out.stdout) - ); - } - } - Err(e) => { - warn!("Failed to run ip link: {}", e); - } - } - } - } - info!("FIPS running, press Ctrl+C to exit"); match tokio::signal::ctrl_c().await { diff --git a/src/node.rs b/src/node.rs index 3d480d3..02097cd 100644 --- a/src/node.rs +++ b/src/node.rs @@ -984,7 +984,11 @@ impl Node { info!(count = self.transports.len(), "Transports initialized"); } - // Initialize TUN interface if configured + // Connect to static peers before TUN is active + // This allows handshake messages to be sent before we start accepting packets + self.initiate_peer_connections().await; + + // Initialize TUN interface last, after transports and peers are ready if self.config.tun.enabled { let address = *self.identity.address(); match TunDevice::create(&self.config.tun, address).await { @@ -993,18 +997,14 @@ impl Node { let name = device.name().to_string(); let our_addr = *device.address(); - info!( - name = %name, - mtu, - address = %device.address(), - "TUN device active" - ); + info!("TUN device active:"); + info!(" name: {}", name); + info!(" address: {}", device.address()); + info!(" mtu: {}", mtu); // Create writer (dups the fd for independent write access) let (writer, tun_tx) = device.create_writer()?; - info!(mtu, name = %name, "Starting TUN reader and writer"); - // Spawn writer thread let writer_handle = thread::spawn(move || { writer.run(); @@ -1031,9 +1031,6 @@ impl Node { } } - // Connect to static peers (step 5 per architecture doc) - self.initiate_peer_connections().await; - self.state = NodeState::Running; info!( state = %self.state, diff --git a/src/tun.rs b/src/tun.rs index 83dd98f..e577155 100644 --- a/src/tun.rs +++ b/src/tun.rs @@ -317,16 +317,11 @@ pub fn log_ipv6_packet(packet: &[u8]) { _ => "other", }; - debug!( - %src, - %dst, - protocol, - next_header, - payload_len, - hop_limit, - total_len = packet.len(), - "TUN packet received" - ); + debug!("TUN packet received:"); + debug!(" src: {}", src); + debug!(" dst: {}", dst); + debug!(" protocol: {} ({})", protocol, next_header); + debug!(" payload: {} bytes, hop_limit: {}", payload_len, hop_limit); } /// Shutdown and delete a TUN interface by name.