mod process;
pub use process::MacOSProcessLookup;
use crate::{DegradationReason, ProcessLookup};
use anyhow::Result;
use std::sync::OnceLock;
static PKTAP_DEGRADATION: OnceLock<DegradationReason> = OnceLock::new();
pub fn report_pktap_degradation(reason: DegradationReason) {
let _ = PKTAP_DEGRADATION.set(reason);
}
pub(crate) fn pktap_degradation() -> DegradationReason {
PKTAP_DEGRADATION
.get()
.cloned()
.unwrap_or(DegradationReason::MissingRootPrivileges)
}
pub struct NoOpProcessLookup;
impl ProcessLookup for NoOpProcessLookup {
fn get_process_for_connection(
&self,
_conn: &rustnet_core::network::types::Connection,
) -> Option<(u32, String)> {
None }
fn refresh(&self) -> Result<()> {
Ok(()) }
fn get_detection_method(&self) -> &str {
"pktap"
}
}
pub fn create_process_lookup(use_pktap: bool) -> Result<Box<dyn ProcessLookup>> {
if use_pktap {
log::info!("Using no-op process lookup - PKTAP provides process metadata");
Ok(Box::new(NoOpProcessLookup))
} else {
log::info!("Using macOS process lookup (lsof)");
Ok(Box::new(MacOSProcessLookup::new()?))
}
}