Skip to content

Commit 339b0c0

Browse files
committed
add IPFIX diagnostic messages in waiting_page
1 parent 80abd64 commit 339b0c0

8 files changed

Lines changed: 129 additions & 130 deletions

File tree

src/gui/pages/waiting_page.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use crate::translations::translations::{
1111
};
1212
use crate::translations::translations_3::unsupported_link_type_translation;
1313
use crate::translations::translations_4::reading_from_pcap_translation;
14+
use crate::translations::translations_6::{
15+
invalid_ipfix_received_translation, make_sure_valid_ipfix_translation,
16+
waiting_ipfix_connections_translation,
17+
};
1418
use crate::utils::types::icon::Icon;
1519
use iced::widget::{Column, Container, Space, Text};
1620
use iced::{Alignment, Length};
@@ -21,27 +25,46 @@ pub fn waiting_page(sniffer: &Sniffer) -> Option<Container<'_, Message, StyleTyp
2125
let dots = &sniffer.dots_pulse.0;
2226
let cs = &sniffer.capture_source;
2327

24-
let pcap_error = sniffer.pcap_error.as_ref();
28+
let capture_error = sniffer.capture_error.as_ref();
2529
let tot_packets = sniffer
2630
.info_traffic
2731
.tot_data_info
2832
.tot_data(DataRepr::Packets);
2933

30-
if pcap_error.is_none() && tot_packets > 0 {
34+
// a rejected IPFIX exporter doesn't stop the others from being read, so the
35+
// page makes way as soon as any traffic is actually observed
36+
if tot_packets > 0 {
3137
return None;
3238
}
3339

3440
let link_type = cs.get_link_type();
35-
let (icon_text, nothing_to_see_text) = if let Some(error) = pcap_error {
36-
(
37-
Icon::Error.to_text().size(60),
38-
format!("{}\n\n{error}", error_translation(language)),
39-
)
41+
let (icon_text, nothing_to_see_text) = if let Some(error) = capture_error {
42+
// the IPFIX collector reports rejected datagrams as an empty error: the
43+
// capture is running fine, so it's a warning and its text is static.
44+
// A non-empty one is a failure to start, and keeps its own message.
45+
if matches!(cs, CaptureSource::Ipfix(_)) && error.is_empty() {
46+
(
47+
Icon::Warning.to_text().size(60),
48+
format!(
49+
"{}\n\n{}",
50+
invalid_ipfix_received_translation(language),
51+
make_sure_valid_ipfix_translation(language)
52+
),
53+
)
54+
} else {
55+
(
56+
Icon::Error.to_text().size(60),
57+
format!("{}\n\n{error}", error_translation(language)),
58+
)
59+
}
4060
} else if matches!(cs, CaptureSource::Ipfix(_)) {
41-
// TODO!
4261
(
43-
Icon::File.to_text().size(60),
44-
reading_from_pcap_translation(language).to_string(),
62+
Icon::get_hourglass(dots.len()).size(60),
63+
format!(
64+
"{}\n\n{}",
65+
waiting_ipfix_connections_translation(language),
66+
make_sure_valid_ipfix_translation(language)
67+
),
4568
)
4669
} else if !link_type.is_supported() {
4770
(

src/gui/sniffer.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ pub struct Sniffer {
105105
pub newer_release_available: Option<bool>,
106106
/// Network device to be analyzed, or PCAP file to be imported
107107
pub capture_source: CaptureSource,
108-
/// Signals if a pcap error occurred
109-
pub pcap_error: Option<String>,
108+
/// Signals if the capture backend reported a problem; empty when the problem
109+
/// is the IPFIX collector rejecting datagrams, whose text the waiting page
110+
/// supplies itself so that it follows a language change
111+
pub capture_error: Option<String>,
110112
/// Messages status
111113
pub dots_pulse: (String, u8),
112114
/// Traffic chart displayed in the Overview page
@@ -170,7 +172,7 @@ impl Sniffer {
170172
logged_notifications: LoggedNotifications::default(),
171173
newer_release_available: None,
172174
capture_source,
173-
pcap_error: None,
175+
capture_error: None,
174176
dots_pulse: (".".to_string(), 0),
175177
traffic_chart: TrafficChart::new(style, language, data_repr),
176178
preview_charts,
@@ -363,6 +365,7 @@ impl Sniffer {
363365
Message::SetIpfixPort(port) => self.set_ipfix_port(port),
364366
Message::PendingHosts(cap_id, host_msgs) => self.pending_hosts(cap_id, host_msgs),
365367
Message::OfflineGap(cap_id, gap) => self.offline_gap(cap_id, gap),
368+
Message::IpfixRejection(cap_id) => self.ipfix_rejection(cap_id),
366369
Message::Periodic => self.periodic(),
367370
Message::ExpandNotification(id, expand) => self.expand_notification(id, expand),
368371
Message::ToggleRemoteNotifications => self.toggle_remote_notifications(),
@@ -858,6 +861,13 @@ impl Sniffer {
858861
}
859862
}
860863

864+
fn ipfix_rejection(&mut self, cap_id: usize) {
865+
if cap_id == self.current_capture_rx.0 {
866+
// the correct translated error is displayed in waiting_page
867+
self.capture_error = Some(String::new());
868+
}
869+
}
870+
861871
fn periodic(&mut self) {
862872
self.update_waiting_dots();
863873
self.capture_source.set_addresses();
@@ -1007,7 +1017,7 @@ impl Sniffer {
10071017
let pcap_path = self.conf.export_pcap.full_path();
10081018
let capture_context =
10091019
CaptureContext::new(&self.capture_source, pcap_path.as_ref(), &self.conf.filters);
1010-
self.pcap_error = capture_context.error().map(ToString::to_string);
1020+
self.capture_error = capture_context.error().map(ToString::to_string);
10111021
self.running_page = Some(self.conf.last_opened_page);
10121022

10131023
if capture_context.error().is_none() {
@@ -1077,6 +1087,9 @@ impl Sniffer {
10771087
BackendTrafficMessage::OfflineGap(cap_id, gap) => {
10781088
Message::OfflineGap(cap_id, gap)
10791089
}
1090+
BackendTrafficMessage::IpfixRejection(cap_id) => {
1091+
Message::IpfixRejection(cap_id)
1092+
}
10801093
});
10811094
}
10821095
}
@@ -1097,7 +1110,7 @@ impl Sniffer {
10971110
self.addresses_resolved = HashMap::new();
10981111
self.latency_statuses = HashMap::new();
10991112
self.logged_notifications = LoggedNotifications::default();
1100-
self.pcap_error = None;
1113+
self.capture_error = None;
11011114
self.traffic_chart = TrafficChart::new(style, language, self.conf.data_repr);
11021115
self.modal = None;
11031116
self.settings_page = None;

src/gui/types/message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pub enum Message {
158158
PendingHosts(usize, Vec<HostMessage>),
159159
/// Sent by offline captures: ticks without packets
160160
OfflineGap(usize, u32),
161+
/// Sent by the IPFIX collector: incoming datagrams aren't decodable as IPFIX
162+
IpfixRejection(usize),
161163
/// Emitted every second to repeat certain tasks (such as fetching the network devices)
162164
Periodic,
163165
/// Expand or collapse the given logged notification

0 commit comments

Comments
 (0)