Skip to content

Commit

Permalink
libpcap-analyzer: use tracing crate for logs (in compatibility mode…
Browse files Browse the repository at this point in the history
… with logs)
  • Loading branch information
pc-anssi authored and chifflier committed Sep 2, 2024
1 parent f2738c8 commit fadd438
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions libpcap-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha1 = { version="0.10", features=["std"], optional=true }
tls-parser = { version="0.12", optional=true }
tracing = { version="0.1", features=["log"] }

[dependencies.rusticata]
# path = "../../rusticata"
Expand Down
3 changes: 3 additions & 0 deletions libpcap-analyzer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use libpcap_tools::*;

use pcap_parser::data::{get_packetdata_raw, PacketData};
use pcap_parser::Linktype;
use tracing::{span, Level};
use std::cmp::min;
use std::net::IpAddr;
use std::ops::DerefMut;
Expand Down Expand Up @@ -1183,6 +1184,8 @@ impl PcapAnalyzer for Analyzer {
if ctx.pcap_index < self.skip_index {
return Ok(());
}
let span = span!(Level::DEBUG, "handle_packet", pcap_index = ctx.pcap_index);
let _enter = span.enter();
match packet.data {
PacketData::L2(data) => self.handle_l2(packet, ctx, data),
PacketData::L3(ethertype, data) => {
Expand Down
5 changes: 5 additions & 0 deletions libpcap-analyzer/src/threaded_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::cmp::min;
use std::panic::AssertUnwindSafe;
use std::sync::{Arc, Barrier};
use std::thread;
use tracing::{span, Level};

pub enum Job<'a> {
Exit,
Expand Down Expand Up @@ -88,6 +89,8 @@ impl<'a> ThreadedAnalyzer<'a> {
}

fn dispatch(&mut self, packet: Packet<'static>, ctx: &ParseContext) -> Result<(), Error> {
let span = span!(Level::DEBUG, "dispatch_packet", pcap_index = ctx.pcap_index);
let _enter = span.enter();
match packet.data {
PacketData::L2(data) => self.handle_l2(packet, ctx, data),
PacketData::L3(ethertype, data) => {
Expand Down Expand Up @@ -298,6 +301,8 @@ fn worker(mut a: Analyzer, idx: usize, r: Receiver<Job>, barrier: Arc<Barrier>)
}
Job::New(packet, ctx, data, ethertype) => {
pcap_index = ctx.pcap_index;
let span = span!(Level::DEBUG, "worker", pcap_index);
let _enter = span.enter();
trace!("thread {}: got a job", idx);
let h3_res = handle_l3(&packet, &ctx, data, ethertype, &mut a);
if h3_res.is_err() {
Expand Down

0 comments on commit fadd438

Please sign in to comment.