From c913fc0fb122b4aa934257340818fcd078b73342 Mon Sep 17 00:00:00 2001 From: Michal Humpula Date: Sun, 1 Mar 2026 08:22:18 +0100 Subject: [PATCH] add constants to routes --- src/routing.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/routing.rs b/src/routing.rs index 8151fdf..c1dd2e8 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -7,6 +7,11 @@ use std::net::Ipv4Addr; const MAIN_TABLE_ID: u8 = 254; +// Route metrics - higher priority = lower number +const FAILOVER_METRIC: u32 = 5; +const PRIMARY_METRIC: u32 = 10; +const SECONDARY_METRIC: u32 = 20; + #[derive(Debug, Clone)] pub struct RouteInfo { pub gateway: Ipv4Addr, @@ -60,8 +65,6 @@ impl RouteManager { } pub fn set_primary_route(&mut self, gateway: Ipv4Addr, interface: String) -> Result<()> { - let primary_metric = 10; - // Remove existing routes for this interface if any if let Some(pos) = self.routes.iter().position(|r| r.interface == interface) { let existing_route = self.routes[pos].clone(); @@ -73,7 +76,7 @@ impl RouteManager { } // Add as primary route - self.add_route(gateway, interface, primary_metric)?; + self.add_route(gateway, interface, PRIMARY_METRIC)?; Ok(()) } @@ -88,20 +91,17 @@ impl RouteManager { self.set_primary_route(primary_gateway, primary_interface)?; // Set secondary route with metric 20 (lower priority) - let secondary_metric = 20; - self.add_route(secondary_gateway, secondary_interface, secondary_metric)?; + self.add_route(secondary_gateway, secondary_interface, SECONDARY_METRIC)?; Ok(()) } pub fn add_failover_route(&mut self, gateway: Ipv4Addr, interface: String) -> Result<()> { - let failover_metric = 5; // Higher priority than both primary (10) and secondary (20) - self.add_route(gateway, interface, failover_metric)?; + self.add_route(gateway, interface, FAILOVER_METRIC)?; Ok(()) } pub fn remove_failover_route(&mut self, gateway: Ipv4Addr, interface: String) -> Result<()> { - let failover_metric = 5; - self.remove_route(gateway, &interface, failover_metric)?; + self.remove_route(gateway, &interface, FAILOVER_METRIC)?; Ok(()) }