Session 48: Initialization order and logging improvements

- Defer TUN setup until after peer connections initiated
- Split TUN packet/device logs into aligned multi-line format
- Remove ip link show debug callout from fips binary
This commit is contained in:
Johnathan Corgan
2026-02-01 03:33:56 +00:00
parent 58be9e2e59
commit 8ba24c38ae
3 changed files with 15 additions and 46 deletions

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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.