From a51acfbe289616b68eb11a16608bece03454c04a Mon Sep 17 00:00:00 2001 From: Marco Cadetg Date: Fri, 29 Aug 2025 10:03:24 +0200 Subject: [PATCH] improve linux build warnings --- RELEASE.md | 8 ++-- src/app.rs | 4 +- src/network/parser.rs | 2 + src/network/platform/linux.rs | 23 +++++------ src/network/platform/mod.rs | 6 ++- src/ui.rs | 74 ++++++++++++++++------------------- 6 files changed, 55 insertions(+), 62 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index a7583e9..188d252 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -6,14 +6,14 @@ This document is for maintainers releasing new versions of RustNet. ### 1. Prepare the Release +Update version in Cargo.toml if needed! +Update CHANGELOG.md with release notes + ```bash # Ensure you're on the main branch with latest changes git checkout main git pull origin main -# Update version in Cargo.toml if needed -# Update CHANGELOG.md with release notes - # Test the build cargo build --release cargo test @@ -178,4 +178,4 @@ Examples: - `v0.1.0` → `v0.1.1` (bug fixes) - `v0.1.1` → `v0.2.0` (new features) -- `v0.2.0` → `v1.0.0` (major changes, API stability) \ No newline at end of file +- `v0.2.0` → `v1.0.0` (major changes, API stability) diff --git a/src/app.rs b/src/app.rs index eef97ab..7a2fc9d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -189,7 +189,7 @@ impl App { let stats = Arc::clone(&self.stats); let current_interface = Arc::clone(&self.current_interface); let linktype_storage = Arc::clone(&self.linktype); - let pktap_active = Arc::clone(&self.pktap_active); + let _pktap_active = Arc::clone(&self.pktap_active); thread::spawn(move || { match setup_packet_capture(capture_config) { @@ -203,7 +203,7 @@ impl App { { use crate::network::pktap; if pktap::is_pktap_linktype(linktype) { - pktap_active.store(true, Ordering::Relaxed); + _pktap_active.store(true, Ordering::Relaxed); info!("✓ PKTAP is active - process metadata will be provided directly"); } } diff --git a/src/network/parser.rs b/src/network/parser.rs index 751d6ea..618978e 100644 --- a/src/network/parser.rs +++ b/src/network/parser.rs @@ -589,6 +589,7 @@ impl PacketParser { } // Raw IP packet parsing for PKTAP DLT_RAW + #[cfg(target_os = "macos")] fn parse_raw_ipv4_packet( &self, data: &[u8], @@ -656,6 +657,7 @@ impl PacketParser { } } + #[cfg(target_os = "macos")] fn parse_raw_ipv6_packet( &self, data: &[u8], diff --git a/src/network/platform/linux.rs b/src/network/platform/linux.rs index 35d8f98..8b6e096 100644 --- a/src/network/platform/linux.rs +++ b/src/network/platform/linux.rs @@ -72,8 +72,8 @@ impl LinuxProcessLookup { let entry = entry?; let path = entry.path(); - if let Some(pid_str) = path.file_name().and_then(|s| s.to_str()) { - if let Ok(pid) = pid_str.parse::() { + if let Some(pid_str) = path.file_name().and_then(|s| s.to_str()) + && let Ok(pid) = pid_str.parse::() { if pid == 0 { continue; } @@ -89,16 +89,13 @@ impl LinuxProcessLookup { let fd_dir = path.join("fd"); if let Ok(fd_entries) = fs::read_dir(&fd_dir) { for fd_entry in fd_entries.flatten() { - if let Ok(link) = fs::read_link(fd_entry.path()) { - if let Some(link_str) = link.to_str() { - if let Some(inode) = Self::extract_socket_inode(link_str) { + if let Ok(link) = fs::read_link(fd_entry.path()) + && let Some(link_str) = link.to_str() + && let Some(inode) = Self::extract_socket_inode(link_str) { inode_map.insert(inode, (pid, process_name.clone())); - } - } } } } - } } } @@ -139,15 +136,14 @@ impl LinuxProcessLookup { }; // Get inode - if let Ok(inode) = parts[9].parse::() { - if let Some((pid, name)) = inode_map.get(&inode) { + if let Ok(inode) = parts[9].parse::() + && let Some((pid, name)) = inode_map.get(&inode) { let key = ConnectionKey { protocol, local_addr, remote_addr, }; result.insert(key, (*pid, name.clone())); - } } } @@ -200,10 +196,9 @@ impl ProcessLookup for LinuxProcessLookup { // Try cache first { let cache = self.cache.read().unwrap(); - if cache.last_refresh.elapsed() < Duration::from_secs(2) { - if let Some(process_info) = cache.lookup.get(&key) { + if cache.last_refresh.elapsed() < Duration::from_secs(2) + && let Some(process_info) = cache.lookup.get(&key) { return Some(process_info.clone()); - } } } diff --git a/src/network/platform/mod.rs b/src/network/platform/mod.rs index f376d1d..8486180 100644 --- a/src/network/platform/mod.rs +++ b/src/network/platform/mod.rs @@ -32,8 +32,10 @@ pub trait ProcessLookup: Send + Sync { } /// No-op process lookup for when PKTAP is providing process metadata +#[cfg(target_os = "macos")] pub struct NoOpProcessLookup; +#[cfg(target_os = "macos")] impl ProcessLookup for NoOpProcessLookup { fn get_process_for_connection(&self, _conn: &Connection) -> Option<(u32, String)> { None // PKTAP provides this information directly @@ -46,10 +48,10 @@ impl ProcessLookup for NoOpProcessLookup { /// Create a platform-specific process lookup with PKTAP status awareness pub fn create_process_lookup_with_pktap_status( - pktap_active: bool, + _pktap_active: bool, ) -> Result> { #[cfg(target_os = "macos")] - if pktap_active { + if _pktap_active { log::info!("Using no-op process lookup - PKTAP provides process metadata"); return Ok(Box::new(NoOpProcessLookup)); } diff --git a/src/ui.rs b/src/ui.rs index 293e02a..4a089bc 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -487,46 +487,40 @@ fn draw_connection_details( .split(area); // Connection details - let mut details_text: Vec = Vec::new(); - - details_text.push(Line::from(vec![ - Span::styled("Protocol: ", Style::default().fg(Color::Yellow)), - Span::raw(conn.protocol.to_string()), - ])); - - details_text.push(Line::from(vec![ - Span::styled("Local Address: ", Style::default().fg(Color::Yellow)), - Span::raw(conn.local_addr.to_string()), - ])); - - details_text.push(Line::from(vec![ - Span::styled("Remote Address: ", Style::default().fg(Color::Yellow)), - Span::raw(conn.remote_addr.to_string()), - ])); - - details_text.push(Line::from(vec![ - Span::styled("State: ", Style::default().fg(Color::Yellow)), - Span::raw(conn.state()), - ])); - - details_text.push(Line::from(vec![ - Span::styled("Process: ", Style::default().fg(Color::Yellow)), - Span::raw(conn.process_name.clone().unwrap_or_else(|| "-".to_string())), - ])); - - details_text.push(Line::from(vec![ - Span::styled("PID: ", Style::default().fg(Color::Yellow)), - Span::raw( - conn.pid - .map(|p| p.to_string()) - .unwrap_or_else(|| "-".to_string()), - ), - ])); - - details_text.push(Line::from(vec![ - Span::styled("Service: ", Style::default().fg(Color::Yellow)), - Span::raw(conn.service_name.clone().unwrap_or_else(|| "-".to_string())), - ])); + let mut details_text: Vec = vec![ + Line::from(vec![ + Span::styled("Protocol: ", Style::default().fg(Color::Yellow)), + Span::raw(conn.protocol.to_string()), + ]), + Line::from(vec![ + Span::styled("Local Address: ", Style::default().fg(Color::Yellow)), + Span::raw(conn.local_addr.to_string()), + ]), + Line::from(vec![ + Span::styled("Remote Address: ", Style::default().fg(Color::Yellow)), + Span::raw(conn.remote_addr.to_string()), + ]), + Line::from(vec![ + Span::styled("State: ", Style::default().fg(Color::Yellow)), + Span::raw(conn.state()), + ]), + Line::from(vec![ + Span::styled("Process: ", Style::default().fg(Color::Yellow)), + Span::raw(conn.process_name.clone().unwrap_or_else(|| "-".to_string())), + ]), + Line::from(vec![ + Span::styled("PID: ", Style::default().fg(Color::Yellow)), + Span::raw( + conn.pid + .map(|p| p.to_string()) + .unwrap_or_else(|| "-".to_string()), + ), + ]), + Line::from(vec![ + Span::styled("Service: ", Style::default().fg(Color::Yellow)), + Span::raw(conn.service_name.clone().unwrap_or_else(|| "-".to_string())), + ]), + ]; // Add DPI information match &conn.dpi_info {