Repository: fujiapple852/trippy (language: rust)

Issue:
Check for valid paris/dublin protocol modes (udp) at startup
Trippy does not fail on startup if you select, for example, `paris` and `icmp`.


Discussion / hints:

Fix patch:
diff --git a/src/config.rs b/src/config.rs
index 42548676a..9c427b8d9 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -483,21 +483,17 @@ impl TrippyConfig {
             cfg_file_tui.tui_as_mode,
             constants::DEFAULT_TUI_AS_MODE,
         );
-
         let columns = cfg_layer(
             args.tui_custom_columns,
             cfg_file_tui.tui_custom_columns,
             String::from(constants::DEFAULT_CUSTOM_COLUMNS),
         );
-
         let tui_custom_columns = TuiColumns::try_from(columns.as_str())?;
-
         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,
@@ -604,6 +600,7 @@ impl TrippyConfig {
         validate_privilege(privilege_mode, has_privileges, needs_privileges)?;
         validate_logging(mode, verbose)?;
         validate_strategy(multipath_strategy, unprivileged)?;
+        validate_protocol_strategy(protocol, multipath_strategy)?;
         validate_multi(mode, protocol, &args.targets, dns_resolve_all)?;
         validate_ttl(first_ttl, max_ttl)?;
         validate_max_inflight(max_inflight)?;
@@ -768,6 +765,7 @@ fn cfg_layer_bool_flag(fst: bool, snd: Option<bool>, default: bool) -> bool {
     }
 }
 
+/// Validate privileges.
 fn validate_privilege(
     privilege_mode: PrivilegeMode,
     has_privileges: bool,
@@ -795,6 +793,7 @@ fn validate_privilege(
     }
 }
 
+/// Validate the TUI custom columns.
 fn validate_tui_custom_columns(tui_custom_columns: &TuiColumns) -> anyhow::Result<()> {
     let duplicates = tui_custom_columns.find_duplicates();
     if tui_custom_columns.0.is_empty() {
@@ -809,6 +808,7 @@ fn validate_tui_custom_columns(tui_custom_columns: &TuiColumns) -> anyhow::Resul
     }
 }
 
+/// Validate the logging mode.
 fn validate_logging(mode: Mode, verbose: bool) -> anyhow::Result<()> {
     if matches!(mode, Mode::Tui) && verbose {
         Err(anyhow!("cannot enable verbose logging in tui mode"))
@@ -817,7 +817,7 @@ fn validate_logging(mode: Mode, verbose: bool) -> anyhow::Result<()> {
     }
 }
 
-/// Validate the tracing strategy against the privilege mode.
+/// Validate the multipath strategy against the privilege mode.
 fn validate_strategy(strategy: MultipathStrategy, unprivileged: bool) -> anyhow::Result<()> {
     match (strategy, unprivileged) {
         (MultipathStrategy::Dublin, true) => Err(anyhow!(
@@ -830,6 +830,28 @@ fn validate_strategy(strategy: MultipathStrategy, unprivileged: bool) -> anyhow:
     }
 }
 
+/// Validate the protocol against the multipath strategy.
+fn validate_protocol_strategy(
+    protocol: Protocol,
+    strategy: MultipathStrategy,
+) -> anyhow::Result<()> {
+    match (protocol, strategy) {
+        (Protocol::Tcp | Protocol::Icmp, MultipathStrategy::Classic) | (Protocol::Udp, _) => Ok(()),
+        (Protocol::Icmp, MultipathStrategy::Paris) => {
+            Err(anyhow!("Paris multipath strategy not support for icmp"))
+        }
+        (Protocol::Icmp, MultipathStrategy::Dublin) => {
+            Err(anyhow!("Dublin multipath strategy not support for icmp"))
+        }
+        (Protocol::Tcp, MultipathStrategy::Paris) => Err(anyhow!(
+            "Paris multipath strategy not yet supported for tcp"
+        )),
+        (Protocol::Tcp, MultipathStrategy::Dublin) => Err(anyhow!(
+            "Dublin multipath strategy not yet supported for tcp"
+        )),
+    }
+}
+
 /// We only allow multiple targets to be specified for the Tui and for `Icmp` tracing.
 fn validate_multi(
     mode: Mode,


Test patch: