improve linux build warnings

This commit is contained in:
Marco Cadetg
2025-08-29 10:03:24 +02:00
parent 374079ef71
commit a51acfbe28
6 changed files with 55 additions and 62 deletions

View File

@@ -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");
}
}

View File

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

View File

@@ -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::<u32>() {
if let Some(pid_str) = path.file_name().and_then(|s| s.to_str())
&& let Ok(pid) = pid_str.parse::<u32>() {
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::<u64>() {
if let Some((pid, name)) = inode_map.get(&inode) {
if let Ok(inode) = parts[9].parse::<u64>()
&& 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());
}
}
}

View File

@@ -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<Box<dyn ProcessLookup>> {
#[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));
}

View File

@@ -487,46 +487,40 @@ fn draw_connection_details(
.split(area);
// Connection details
let mut details_text: Vec<Line> = 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<Line> = 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 {