Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more link types: raw IP and null/loopback #421

Merged
merged 16 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/configs/types/config_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use pcap::{Device, DeviceFlags};
use serde::{Deserialize, Serialize};

use crate::networking::types::my_device::MyDevice;
use crate::networking::types::my_link_type::MyLinkType;
#[cfg(not(test))]
use crate::SNIFFNET_LOWERCASE;

Expand Down Expand Up @@ -57,6 +58,7 @@ impl ConfigDevice {
name: device.name,
desc: device.desc,
addresses: Arc::new(Mutex::new(device.addresses)),
link_type: MyLinkType::NotYetAssigned,
};
}
}
Expand All @@ -70,6 +72,7 @@ impl ConfigDevice {
name: standard_device.name,
desc: standard_device.desc,
addresses: Arc::new(Mutex::new(standard_device.addresses)),
link_type: MyLinkType::NotYetAssigned,
}
}
}
Expand Down
47 changes: 32 additions & 15 deletions src/countries/country_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::countries::types::country::Country;
use crate::gui::styles::container::ContainerType;
use crate::gui::styles::svg::SvgType;
use crate::gui::types::message::Message;
use crate::networking::types::data_info_host::DataInfoHost;
use crate::networking::types::traffic_type::TrafficType;
use crate::translations::translations_2::{
local_translation, unknown_translation, your_network_adapter_translation,
Expand All @@ -31,6 +32,7 @@ fn get_flag_from_country(
country: Country,
width: f32,
is_local: bool,
is_loopback: bool,
traffic_type: TrafficType,
language: Language,
) -> (Svg<Renderer<StyleType>>, String) {
Expand Down Expand Up @@ -284,7 +286,11 @@ fn get_flag_from_country(
Country::ZM => ZM,
Country::ZW => ZW,
Country::ZZ => {
if is_local {
if is_loopback {
tooltip = your_network_adapter_translation(language);
svg_style = SvgType::AdaptColor;
COMPUTER
} else if is_local {
tooltip = local_translation(language);
svg_style = SvgType::AdaptColor;
HOME
Expand Down Expand Up @@ -313,13 +319,21 @@ fn get_flag_from_country(
pub fn get_flag_tooltip(
country: Country,
width: f32,
is_local: bool,
traffic_type: TrafficType,
host_info: &DataInfoHost,
language: Language,
font: Font,
) -> Tooltip<'static, Message, Renderer<StyleType>> {
let (content, tooltip) =
get_flag_from_country(country, width, is_local, traffic_type, language);
let is_local = host_info.is_local;
let is_loopback = host_info.is_loopback;
let traffic_type = host_info.traffic_type;
let (content, tooltip) = get_flag_from_country(
country,
width,
is_local,
is_loopback,
traffic_type,
language,
);

let mut tooltip = Tooltip::new(content, tooltip, Position::FollowCursor)
.font(font)
Expand All @@ -335,27 +349,30 @@ pub fn get_flag_tooltip(

pub fn get_computer_tooltip(
is_my_address: bool,
is_local: bool,
traffic_type: TrafficType,
language: Language,
font: Font,
) -> Tooltip<'static, Message, Renderer<StyleType>> {
let content = Svg::new(Handle::from_memory(Vec::from(
match (is_my_address, traffic_type) {
(true, _) => COMPUTER,
(false, TrafficType::Multicast) => MULTICAST,
(false, TrafficType::Broadcast) => BROADCAST,
(false, TrafficType::Unicast) => UNKNOWN,
match (is_my_address, is_local, traffic_type) {
(true, _, _) => COMPUTER,
(false, true, _) => HOME,
(false, false, TrafficType::Multicast) => MULTICAST,
(false, false, TrafficType::Broadcast) => BROADCAST,
(false, false, TrafficType::Unicast) => UNKNOWN,
},
)))
.style(SvgType::AdaptColor)
.width(Length::Fixed(FLAGS_WIDTH_BIG))
.height(Length::Fixed(FLAGS_WIDTH_BIG * 0.75));

let tooltip = match (is_my_address, traffic_type) {
(true, _) => your_network_adapter_translation(language),
(false, TrafficType::Multicast) => "Multicast".to_string(),
(false, TrafficType::Broadcast) => "Broadcast".to_string(),
(false, TrafficType::Unicast) => unknown_translation(language),
let tooltip = match (is_my_address, is_local, traffic_type) {
(true, _, _) => your_network_adapter_translation(language),
(false, true, _) => local_translation(language),
(false, false, TrafficType::Multicast) => "Multicast".to_string(),
(false, false, TrafficType::Broadcast) => "Broadcast".to_string(),
(false, false, TrafficType::Unicast) => unknown_translation(language),
};

Tooltip::new(content, tooltip, Position::FollowCursor)
Expand Down
35 changes: 16 additions & 19 deletions src/gui/pages/connection_details_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use crate::gui::styles::text::TextType;
use crate::gui::styles::types::gradient_type::GradientType;
use crate::gui::types::message::Message;
use crate::gui::types::timing_events::TimingEvents;
use crate::networking::manage_packets::{get_address_to_lookup, get_traffic_type, is_my_address};
use crate::networking::manage_packets::{
get_address_to_lookup, get_traffic_type, is_local_connection, is_my_address,
};
use crate::networking::types::address_port_pair::AddressPortPair;
use crate::networking::types::host::Host;
use crate::networking::types::icmp_type::IcmpType;
Expand Down Expand Up @@ -105,14 +107,7 @@ fn page_content(
if let Some((r_dns, host)) = host_option {
host_info_col = get_host_info_col(&r_dns, &host, font, language);
let host_info = host_info_option.unwrap_or_default();
let flag = get_flag_tooltip(
host.country,
FLAGS_WIDTH_BIG,
host_info.is_local,
host_info.traffic_type,
language,
font,
);
let flag = get_flag_tooltip(host.country, FLAGS_WIDTH_BIG, &host_info, language, font);
let computer = get_local_tooltip(sniffer, &address_to_lookup, key);
if address_to_lookup.eq(&key.address1) {
source_caption = source_caption.push(flag);
Expand Down Expand Up @@ -310,16 +305,15 @@ fn get_local_tooltip(
style, language, ..
} = sniffer.configs.lock().unwrap().settings;

let local_address = if address_to_lookup.eq(&key.address1) {
&key.address2
} else {
&key.address1
};
let my_interface_addresses = &*sniffer.device.addresses.lock().unwrap();
get_computer_tooltip(
is_my_address(
if address_to_lookup.eq(&key.address1) {
&key.address2
} else {
&key.address1
},
my_interface_addresses,
),
is_my_address(local_address, my_interface_addresses),
is_local_connection(local_address, my_interface_addresses),
get_traffic_type(
if address_to_lookup.eq(&key.address1) {
&key.address2
Expand All @@ -338,7 +332,7 @@ fn get_src_or_dest_col(
caption: Row<'static, Message, Renderer<StyleType>>,
ip: &String,
port: Option<u16>,
mac: &str,
mac: &Option<String>,
font: Font,
language: Language,
timing_events: &TimingEvents,
Expand All @@ -348,6 +342,9 @@ fn get_src_or_dest_col(
} else {
address_translation(language)
};

let mac_str = if let Some(val) = mac { val } else { "-" };

Column::new()
.spacing(4)
.push(
Expand All @@ -369,7 +366,7 @@ fn get_src_or_dest_col(
)
.push(TextType::highlighted_subtitle_with_desc(
mac_address_translation(language),
mac,
mac_str,
font,
))
}
Expand Down
8 changes: 3 additions & 5 deletions src/gui/pages/notifications_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,10 @@ fn favorite_notification_log(
language: Language,
font: Font,
) -> Container<'static, Message, Renderer<StyleType>> {
let domain = logged_notification.host.domain;
let country = logged_notification.host.country;
let asn = logged_notification.host.asn;
let asn = &logged_notification.host.asn;

let mut domain_asn_str = domain;
let mut domain_asn_str = logged_notification.host.domain;
if !asn.name.is_empty() {
domain_asn_str.push_str(&format!(" - {}", asn.name));
}
Expand All @@ -327,8 +326,7 @@ fn favorite_notification_log(
.push(get_flag_tooltip(
country,
FLAGS_WIDTH_BIG,
logged_notification.data_info_host.is_local,
logged_notification.data_info_host.traffic_type,
&logged_notification.data_info_host,
language,
font,
))
Expand Down
72 changes: 36 additions & 36 deletions src/gui/pages/overview_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::translations::translations_2::{
data_representation_translation, dropped_packets_translation, host_translation,
only_top_30_hosts_translation,
};
use crate::translations::translations_3::unsupported_link_type_translation;
use crate::utils::formatted_strings::{
get_active_filters_string, get_formatted_bytes_string_with_b, get_percentage_string,
};
Expand Down Expand Up @@ -140,18 +141,27 @@ fn body_no_packets(
language: Language,
waiting: &str,
) -> Column<'static, Message, Renderer<StyleType>> {
let adapter_name = device.name.clone();
let (icon_text, nothing_to_see_text) = if device.addresses.lock().unwrap().is_empty() {
let link_type = device.link_type;
let mut adapter_info = device.name.clone();
adapter_info.push_str(&format!("\n{}", link_type.full_print_on_one_line(language)));
let (icon_text, nothing_to_see_text) = if !link_type.is_supported() {
(
Icon::Warning.to_text().size(60),
no_addresses_translation(language, &adapter_name)
unsupported_link_type_translation(language, &adapter_info)
.horizontal_alignment(Horizontal::Center)
.font(font),
)
} else if device.addresses.lock().unwrap().is_empty() {
(
Icon::Warning.to_text().size(60),
no_addresses_translation(language, &adapter_info)
.horizontal_alignment(Horizontal::Center)
.font(font),
)
} else {
(
Icon::get_hourglass(waiting.len()).size(60),
waiting_translation(language, &adapter_name)
waiting_translation(language, &adapter_info)
.horizontal_alignment(Horizontal::Center)
.font(font),
)
Expand Down Expand Up @@ -295,8 +305,7 @@ fn col_host(width: f32, sniffer: &Sniffer) -> Column<'static, Message, Renderer<
.push(get_flag_tooltip(
host.country,
FLAGS_WIDTH_BIG,
data_info_host.is_local,
data_info_host.traffic_type,
data_info_host,
language,
font,
))
Expand Down Expand Up @@ -419,24 +428,13 @@ fn lazy_col_info(
style, language, ..
} = sniffer.configs.lock().unwrap().settings;
let font = style.get_extension().font;
let filtered_bytes =
sniffer.runtime_data.tot_sent_bytes + sniffer.runtime_data.tot_received_bytes;
let all_bytes = sniffer.runtime_data.all_bytes;

let col_device_filters = col_device_filters(language, font, &sniffer.filters, &sniffer.device);
let col_device = col_device(language, font, &sniffer.device);

let col_data_representation =
col_data_representation(language, font, sniffer.traffic_chart.chart_type);

let col_bytes_packets = col_bytes_packets(
language,
dropped,
total,
filtered,
all_bytes,
filtered_bytes,
font,
);
let col_bytes_packets = col_bytes_packets(language, dropped, total, filtered, font, sniffer);

let content = Column::new()
.align_items(Alignment::Center)
Expand All @@ -445,14 +443,14 @@ fn lazy_col_info(
Row::new()
.height(Length::Fixed(120.0))
.push(
Scrollable::new(col_device_filters)
.width(Length::Fill)
.direction(Direction::Vertical(ScrollbarType::properties())),
Scrollable::new(col_device)
.width(Length::FillPortion(1))
.direction(Direction::Horizontal(ScrollbarType::properties())),
)
.push(Rule::vertical(25))
.push(col_data_representation),
.push(col_data_representation.width(Length::FillPortion(1))),
)
.push(Rule::horizontal(25))
.push(Rule::horizontal(15))
.push(
Scrollable::new(col_bytes_packets)
.width(Length::Fill)
Expand Down Expand Up @@ -507,36 +505,33 @@ fn container_chart(sniffer: &Sniffer, font: Font) -> Container<Message, Renderer
.style(ContainerType::BorderedRound)
}

fn col_device_filters(
fn col_device(
language: Language,
font: Font,
filters: &Filters,
device: &MyDevice,
) -> Column<'static, Message, Renderer<StyleType>> {
let link_type = device.link_type;
#[cfg(not(target_os = "windows"))]
let adapter_info = &device.name;
#[cfg(target_os = "windows")]
let adapter_name = &device.name;
#[cfg(target_os = "windows")]
let adapter_info = device.desc.as_ref().unwrap_or(adapter_name);
let adapter_info = device.desc.as_ref().unwrap_or(&device.name);

Column::new()
.width(Length::FillPortion(1))
.spacing(10)
.push(TextType::highlighted_subtitle_with_desc(
network_adapter_translation(language),
adapter_info,
font,
))
.push(vertical_space(15))
.push(get_active_filters_col(filters, language, font, false))
.push(link_type.link_type_col(language, font))
}

fn col_data_representation(
language: Language,
font: Font,
chart_type: ChartType,
) -> Column<'static, Message, Renderer<StyleType>> {
let mut ret_val = Column::new().spacing(5).width(Length::FillPortion(1)).push(
let mut ret_val = Column::new().spacing(5).push(
Text::new(format!("{}:", data_representation_translation(language)))
.style(TextType::Subtitle)
.font(font),
Expand Down Expand Up @@ -570,10 +565,14 @@ fn col_bytes_packets(
dropped: u32,
total: u128,
filtered: u128,
all_bytes: u128,
filtered_bytes: u128,
font: Font,
sniffer: &Sniffer,
) -> Column<'static, Message, Renderer<StyleType>> {
let filtered_bytes =
sniffer.runtime_data.tot_sent_bytes + sniffer.runtime_data.tot_received_bytes;
let all_bytes = sniffer.runtime_data.all_bytes;
let filters = &sniffer.filters;

let dropped_val = if dropped > 0 {
format!(
"{} {}",
Expand All @@ -594,7 +593,8 @@ fn col_bytes_packets(
};

Column::new()
.spacing(15)
.spacing(10)
.push(get_active_filters_col(filters, language, font, false))
.push(TextType::highlighted_subtitle_with_desc(
filtered_bytes_translation(language),
&bytes_value,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/types/runtime_data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Module defining the `RunTimeData` struct, useful to to generate chart and to display statistics about network traffic
//!

use std::collections::VecDeque;

use crate::notifications::types::logged_notification::LoggedNotification;
Expand Down
Loading
Loading