Skip to content

Commit

Permalink
fix: fix possiable panic on trace log at online
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Mar 15, 2024
1 parent 45b5a30 commit ba58731
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/net/offline_fluereflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub async fn fluereflow_fileparse(arg: Args) {

if flags.fin == 1 || flags.rst == 1 {
trace!("flow finished");
trace!("flow data: {:?}", flow);
records.push(*flow);
active_flow.remove(flow_key);
}
Expand Down
19 changes: 14 additions & 5 deletions src/net/online_fluereflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub async fn packet_capture(arg: Args) {
}
Ok(packet) => {
trace!("received packet");
// trace!("packet: {:?}", );

let (mut key_value, mut reverse_key) = match parse_keys(packet.clone()) {
Ok(keys) => keys,
Expand Down Expand Up @@ -146,10 +147,10 @@ pub async fn packet_capture(arg: Args) {
//println!("time: {:?}", time);
let pkt = flowdata.min_pkt;
let ttl = flowdata.min_ttl;
trace!(
"current inputed flow{:?}",
active_flow.get(&key_value).unwrap()
);
// trace!(
// "current inputed flow{:?}",
// active_flow.get(&key_value).unwrap()
// );
let flow_key = if is_reverse { &reverse_key } else { &key_value };
if let Some(flow) = active_flow.get_mut(flow_key) {
let update_key = UDFlowKey {
Expand All @@ -165,10 +166,16 @@ pub async fn packet_capture(arg: Args) {
"{} flow updated",
if is_reverse { "reverse" } else { "forward" }
);
trace!(
"flow key detail: {:?}",
flow_key
);

// Check if the flow has finished
if flags.fin == 1 || flags.rst == 1 {
trace!("flow finished");
// plugin_manager.process_flow_data(flow).expect("Failed to process flow data");
trace!("flow data: {:?}", flow);

plugin_manager.process_flow_data(*flow).await.unwrap();

records.push(*flow);
Expand All @@ -193,6 +200,8 @@ pub async fn packet_capture(arg: Args) {
for (key, flow) in active_flow.iter() {
if flow_timeout > 0 && flow.last < (time - (flow_timeout * 1000)) {
trace!("flow expired");
trace!("flow data: {:?}", flow);

plugin_manager.process_flow_data(*flow).await.unwrap();
records.push(*flow);
expired_flows.push(*key);
Expand Down

0 comments on commit ba58731

Please sign in to comment.