From: Matt Corallo Date: Mon, 2 Dec 2019 18:17:11 +0000 (-0500) Subject: Fix BGP table lookup X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ec39152171e7e0a2b5c69dc13b12d417f360ad5b;p=dnsseed-rust Fix BGP table lookup --- 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![]) } }