This commit is contained in:
@ -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"
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -139,13 +139,12 @@ impl NetlinkConnector {
|
||||
pub async fn dump_routes(
|
||||
&mut self,
|
||||
address_family: AddressFamilyIdentifier,
|
||||
table: Option<u32>,
|
||||
) -> Result<Vec<RouteMessage>, 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));
|
||||
|
||||
Reference in New Issue
Block a user