diff --git a/Cargo.toml b/Cargo.toml index 043b050..59a3053 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ ipnet = "2.3.0" libc = "0.2.126" log = "0.4" netlink = "0.1.1" -netlink-packet-route = "0.19.0" +netlink-packet-route = "0.21.0" netlink-packet-utils = "0.5.2" nom = "7.1" prost = "0.8" diff --git a/bin/src/util/main.rs b/bin/src/util/main.rs index bd9957d..d174644 100644 --- a/bin/src/util/main.rs +++ b/bin/src/util/main.rs @@ -1,5 +1,6 @@ use std::net::IpAddr; +use bgp_packet::constants::AddressFamilyIdentifier; use bgp_packet::nlri::NLRI; use clap::{Parser, Subcommand}; use eyre::{bail, Result}; @@ -44,6 +45,12 @@ enum Commands { #[arg(default_value_t = 201)] rt_table: u32, }, + /// DumpRoutes prints all routes from the given routing table ID. + DumpRoutes { + /// Selects which table to print routes from. + #[arg(default_value_t = 201)] + rt_table: u32, + }, } #[tokio::main] @@ -78,8 +85,23 @@ async fn main() -> Result<()> { let nexthop: IpAddr = nexthop.parse()?; handle.route_del(prefix, nexthop).await?; } + Some(Commands::DumpRoutes { rt_table }) => {} None => bail!("A subcommand must be specified."), }; Ok(()) } + +/// Implements the route dump CLI functionality. +async fn dump_routes(table: u16) -> Result<()> { + let connector = NetlinkConnector::new(Some(table)).await?; + let routes = connector.dump_routes(AddressFamilyIdentifier::Ipv6).await?; + + for route in routes { + print_route_message(route); + } +} + +fn print_route_message(msg: RouteMessage) { + // Parse the prefix out +} diff --git a/crates/route_client/src/fib_state.rs b/crates/route_client/src/fib_state.rs index 488e173..25a7a51 100644 --- a/crates/route_client/src/fib_state.rs +++ b/crates/route_client/src/fib_state.rs @@ -88,7 +88,7 @@ where /// route_add requests updating the nexthop to a particular path if it is not already /// the best path. pub async fn route_add(&mut self, nlri: &NLRI, nexthop: IpAddr) -> Result<()> { - info!(af = ?self.af, %nlri, %nexthop); + trace!(af = ?self.af, %nlri, %nexthop); // Lookup the path in the Fib, there are three possible outcomes: // 1. The route is not yet known, we add it to the FibState and inject it into the kernel, // 2. The route is known and has a prior nexthop that needs to be updated diff --git a/crates/route_client/src/netlink.rs b/crates/route_client/src/netlink.rs index dc35784..f78d3cd 100644 --- a/crates/route_client/src/netlink.rs +++ b/crates/route_client/src/netlink.rs @@ -139,13 +139,12 @@ impl NetlinkConnector { pub async fn dump_routes( &mut self, address_family: AddressFamilyIdentifier, - table: Option, ) -> Result, rtnetlink::Error> { let mut req = self.handle.route().get(match address_family { AddressFamilyIdentifier::Ipv4 => IpVersion::V4, AddressFamilyIdentifier::Ipv6 => IpVersion::V6, }); - if let Some(table_id) = table { + if let Some(table_id) = self.table { req.message_mut() .attributes .push(RouteAttribute::Table(table_id));