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 ICMP Extensions in Tui (#752) #808

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ pub enum AsMode {
Name,
}

/// How to render `icmp` extensions in the hops table.
#[derive(Debug, Copy, Clone, Eq, PartialEq, ValueEnum, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum IcmpExtensionMode {
/// Do not show `icmp` extensions.
Off,
/// Show MPLS label(s) only.
Mpls,
/// Show full `icmp` extension data for all known extensions.
///
/// For MPLS the fields shown are `label`, `ttl`, `exp` & `bos`.
Full,
/// Show full `icmp` extension data for all known and unknown classes.
///
/// This is the same as `Full`, but also shows `class`, `subtype` and
/// `object` for unknown extensions.
All,
}

/// How to render `GeoIp` information in the hop table.
///
/// Note that the hop details view is always shown using the `Long` representation.
Expand Down Expand Up @@ -217,6 +236,7 @@ pub struct TrippyConfig {
pub tui_privacy_max_ttl: u8,
pub tui_address_mode: AddressMode,
pub tui_as_mode: AsMode,
pub tui_icmp_extension_mode: IcmpExtensionMode,
pub tui_geoip_mode: GeoIpMode,
pub tui_max_addrs: Option<u8>,
pub tui_theme: TuiTheme,
Expand Down Expand Up @@ -418,6 +438,13 @@ impl TrippyConfig {
cfg_file_tui.tui_as_mode,
constants::DEFAULT_TUI_AS_MODE,
);

let tui_icmp_extension_mode = cfg_layer(
args.tui_icmp_extension_mode,
cfg_file_tui.tui_icmp_extension_mode,
constants::DEFAULT_TUI_ICMP_EXTENSION_MODE,
);

let tui_geoip_mode = cfg_layer(
args.tui_geoip_mode,
cfg_file_tui.tui_geoip_mode,
Expand Down Expand Up @@ -577,6 +604,7 @@ impl TrippyConfig {
tui_privacy_max_ttl,
tui_address_mode,
tui_as_mode,
tui_icmp_extension_mode,
tui_geoip_mode,
tui_max_addrs,
tui_theme,
Expand Down Expand Up @@ -626,6 +654,7 @@ impl Default for TrippyConfig {
tui_privacy_max_ttl: constants::DEFAULT_TUI_PRIVACY_MAX_TTL,
tui_address_mode: constants::DEFAULT_TUI_ADDRESS_MODE,
tui_as_mode: constants::DEFAULT_TUI_AS_MODE,
tui_icmp_extension_mode: constants::DEFAULT_TUI_ICMP_EXTENSION_MODE,
tui_geoip_mode: constants::DEFAULT_TUI_GEOIP_MODE,
tui_max_addrs: None,
tui_theme: TuiTheme::default(),
Expand Down
8 changes: 6 additions & 2 deletions src/config/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::config::binding::TuiCommandItem;
use crate::config::theme::TuiThemeItem;
use crate::config::{
AddressMode, AsMode, DnsResolveMethodConfig, GeoIpMode, LogFormat, LogSpanEvents, Mode,
MultipathStrategyConfig, Protocol, TuiColor, TuiKeyBinding,
AddressMode, AsMode, DnsResolveMethodConfig, GeoIpMode, IcmpExtensionMode, LogFormat,
LogSpanEvents, Mode, MultipathStrategyConfig, Protocol, TuiColor, TuiKeyBinding,
};
use anyhow::anyhow;
use clap::builder::Styles;
Expand Down Expand Up @@ -161,6 +161,10 @@ pub struct Args {
#[arg(value_enum, long)]
pub tui_as_mode: Option<AsMode>,

/// How to render ICMP extensions [default: mpls]
#[arg(value_enum, long)]
pub tui_icmp_extension_mode: Option<IcmpExtensionMode>,

/// How to render GeoIp information [default: short]
#[arg(value_enum, long)]
pub tui_geoip_mode: Option<GeoIpMode>,
Expand Down
7 changes: 5 additions & 2 deletions src/config/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::{
AddressFamily, AddressMode, AsMode, DnsResolveMethodConfig, GeoIpMode, LogFormat,
LogSpanEvents, Mode, MultipathStrategyConfig, Protocol,
AddressFamily, AddressMode, AsMode, DnsResolveMethodConfig, GeoIpMode, IcmpExtensionMode,
LogFormat, LogSpanEvents, Mode, MultipathStrategyConfig, Protocol,
};
use std::time::Duration;

Expand Down Expand Up @@ -82,6 +82,9 @@ pub const DEFAULT_TUI_PRESERVE_SCREEN: bool = false;
/// The default value for `tui-as-mode`.
pub const DEFAULT_TUI_AS_MODE: AsMode = AsMode::Asn;

/// The default value for `tui-icmp-extension-mode`.
pub const DEFAULT_TUI_ICMP_EXTENSION_MODE: IcmpExtensionMode = IcmpExtensionMode::Off;

/// The default value for `tui-geoip-mode`.
pub const DEFAULT_TUI_GEOIP_MODE: GeoIpMode = GeoIpMode::Off;

Expand Down
6 changes: 4 additions & 2 deletions src/config/file.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::config::binding::TuiKeyBinding;
use crate::config::theme::TuiColor;
use crate::config::{
AddressFamily, AddressMode, AsMode, DnsResolveMethodConfig, GeoIpMode, LogFormat,
LogSpanEvents, Mode, MultipathStrategyConfig, Protocol,
AddressFamily, AddressMode, AsMode, DnsResolveMethodConfig, GeoIpMode, IcmpExtensionMode,
LogFormat, LogSpanEvents, Mode, MultipathStrategyConfig, Protocol,
};
use anyhow::Context;
use etcetera::BaseStrategy;
Expand Down Expand Up @@ -218,6 +218,7 @@ pub struct ConfigTui {
pub tui_privacy_max_ttl: Option<u8>,
pub tui_address_mode: Option<AddressMode>,
pub tui_as_mode: Option<AsMode>,
pub tui_icmp_extension_mode: Option<IcmpExtensionMode>,
pub tui_geoip_mode: Option<GeoIpMode>,
pub tui_max_addrs: Option<u8>,
pub geoip_mmdb_file: Option<String>,
Expand All @@ -232,6 +233,7 @@ impl Default for ConfigTui {
tui_privacy_max_ttl: Some(super::constants::DEFAULT_TUI_PRIVACY_MAX_TTL),
tui_address_mode: Some(super::constants::DEFAULT_TUI_ADDRESS_MODE),
tui_as_mode: Some(super::constants::DEFAULT_TUI_AS_MODE),
tui_icmp_extension_mode: Some(super::constants::DEFAULT_TUI_ICMP_EXTENSION_MODE),
tui_geoip_mode: Some(super::constants::DEFAULT_TUI_GEOIP_MODE),
tui_max_addrs: Some(super::constants::DEFAULT_TUI_MAX_ADDRS),
geoip_mmdb_file: None,
Expand Down
6 changes: 5 additions & 1 deletion src/frontend/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::TuiBindings;
use crate::config::{AddressMode, AsMode, GeoIpMode, TuiTheme};
use crate::config::{IcmpExtensionMode, TuiBindings};
use crate::frontend::binding::Bindings;
use crate::frontend::theme::Theme;
use std::time::Duration;
Expand All @@ -19,6 +19,8 @@ pub struct TuiConfig {
pub lookup_as_info: bool,
/// How to render AS data.
pub as_mode: AsMode,
/// How to render ICMP extensions.
pub icmp_extension_mode: IcmpExtensionMode,
/// How to render GeoIp data.
pub geoip_mode: GeoIpMode,
/// The maximum number of addresses to show per hop.
Expand All @@ -40,6 +42,7 @@ impl TuiConfig {
address_mode: AddressMode,
lookup_as_info: bool,
as_mode: AsMode,
icmp_extension_mode: IcmpExtensionMode,
geoip_mode: GeoIpMode,
max_addrs: Option<u8>,
max_samples: usize,
Expand All @@ -53,6 +56,7 @@ impl TuiConfig {
address_mode,
lookup_as_info,
as_mode,
icmp_extension_mode,
geoip_mode,
max_addrs,
max_samples,
Expand Down
12 changes: 10 additions & 2 deletions src/frontend/render/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use trippy::dns::{ResolveMethod, Resolver};
use trippy::tracing::{PortDirection, TracerProtocol};

/// Render the title, config, target, clock and keyboard controls.
#[allow(clippy::too_many_lines)]
pub fn render(f: &mut Frame<'_>, app: &TuiApp, rect: Rect) {
let header_block = Block::default()
.title(format!(" Trippy v{} ", clap::crate_version!()))
Expand Down Expand Up @@ -83,6 +84,11 @@ pub fn render(f: &mut Frame<'_>, app: &TuiApp, rect: Rect) {
let source = render_source(app);
let dest = render_destination(app);
let target = format!("{source} -> {dest}");
let plural_flows = if app.tracer_data().flows().len() > 1 {
"flows"
} else {
"flow"
};
let left_line = vec![
Line::from(vec![
Span::styled("Target: ", Style::default().add_modifier(Modifier::BOLD)),
Expand All @@ -98,8 +104,10 @@ pub fn render(f: &mut Frame<'_>, app: &TuiApp, rect: Rect) {
Span::styled("Status: ", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(render_status(app)),
Span::raw(format!(
", discovered {} hops",
app.tracer_data().hops(app.selected_flow).len()
", discovered {} hops and {} unique {}",
app.tracer_data().hops(app.selected_flow).len(),
app.tracer_data().flows().len(),
plural_flows
)),
]),
];
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/render/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ fn format_trace_settings(app: &TuiApp) -> Vec<SettingsItem> {
),
SettingsItem::new("packet-size", format!("{}", cfg.packet_size)),
SettingsItem::new("payload-pattern", format!("{}", cfg.payload_pattern)),
SettingsItem::new("icmp-extensions", format!("{}", cfg.icmp_extensions)),
SettingsItem::new("interface", interface),
SettingsItem::new("multipath-strategy", cfg.multipath_strategy.to_string()),
SettingsItem::new("target-port", dst_port),
Expand Down Expand Up @@ -419,7 +420,7 @@ fn format_theme_settings(app: &TuiApp) -> Vec<SettingsItem> {
/// The name and number of items for each tabs in the setting dialog.
pub const SETTINGS_TABS: [(&str, usize); 6] = [
("Tui", 8),
("Trace", 14),
("Trace", 15),
("Dns", 4),
("GeoIp", 1),
("Bindings", 29),
Expand Down
Loading
Loading