Skip to content

Commit

Permalink
use TOFU only if at least one of the parsing strategies was successful
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Dec 30, 2023
1 parent f0c1d77 commit f7673ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/chart/manage_chart_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn get_max(deque: &VecDeque<(u32, i64)>) -> i64 {

#[cfg(test)]
mod tests {
use pcap::Linktype;
use std::collections::VecDeque;

use crate::chart::manage_chart_data::{get_max, get_min, update_charts_data};
Expand Down Expand Up @@ -167,6 +168,7 @@ mod tests {
style: StyleType::default(),
};
let mut runtime_data = RunTimeData {
link_type: Linktype::ETHERNET,
all_bytes: 0,
all_packets: 0,
tot_sent_bytes: tot_sent + 1111,
Expand Down
5 changes: 3 additions & 2 deletions src/secondary_threads/parse_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ fn get_sniffable_headers<'a>(
) -> Result<PacketHeaders<'a>, ReadError> {
match is_link_type_confirmed {
false => {
*is_link_type_confirmed = true;

let ethernet_result = PacketHeaders::from_ethernet_slice(packet);
let ip_result = PacketHeaders::from_ip_slice(packet);
let null_result = PacketHeaders::from_ip_slice(&packet[4..]);
Expand All @@ -218,17 +216,20 @@ fn get_sniffable_headers<'a>(

match (is_ethernet_sniffable, is_ip_sniffable, is_null_sniffable) {
(true, _, _) => {
*is_link_type_confirmed = true;
*link_type = Linktype::ETHERNET;
info_traffic_mutex.lock().unwrap().link_type = Linktype::ETHERNET;
ethernet_result
}
(_, true, _) => {
*is_link_type_confirmed = true;
// it could be IPV4 as well as IPV6 but it should be the same
*link_type = Linktype::IPV4;
info_traffic_mutex.lock().unwrap().link_type = Linktype::IPV4;
ip_result
}
(_, _, true) => {
*is_link_type_confirmed = true;
// it could be NULL as well as LOOP but it should be the same
*link_type = Linktype::NULL;
info_traffic_mutex.lock().unwrap().link_type = Linktype::NULL;
Expand Down

0 comments on commit f7673ef

Please sign in to comment.