From ec39152171e7e0a2b5c69dc13b12d417f360ad5b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 2 Dec 2019 13:17:11 -0500 Subject: [PATCH] Fix BGP table lookup --- src/bgp_client.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/bgp_client.rs b/src/bgp_client.rs index e38cffb..c20323d 100644 --- a/src/bgp_client.rs +++ b/src/bgp_client.rs @@ -48,18 +48,15 @@ impl RoutingTable { macro_rules! lookup_res { ($addrty: ty, $addr: expr, $table: expr, $addr_bits: expr) => { { //TODO: Optimize this (probably means making the tables btrees)! - for i in (0..$addr_bits).rev() { - let mut lookup = $addr.octets(); - for b in 0..(i / 8) { - lookup[lookup.len() - b - 1] = 0; - } - lookup[lookup.len() - (i/8) - 1] &= !(((1u16 << (i % 8)) - 1) as u8); + let mut lookup = $addr.octets(); + for i in 0..$addr_bits { let lookup_addr = <$addrty>::from(lookup); if let Some(routes) = $table.get(&(lookup_addr, $addr_bits - i as u8)).map(|hm| hm.values()) { if routes.len() > 0 { return ($addr_bits - i as u8, routes.collect()); } } + lookup[lookup.len() - (i/8) - 1] &= !(1u8 << (i % 8)); } (0, vec![]) } } -- 2.39.5