From: Matt Corallo Date: Fri, 23 Aug 2019 01:01:25 +0000 (-0400) Subject: Fix route lookup masking X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0d474196b752d00a80209535b60c23d35a492745;p=dnsseed-rust Fix route lookup masking --- diff --git a/src/bgp_client.rs b/src/bgp_client.rs index 8f264c6..cb33305 100644 --- a/src/bgp_client.rs +++ b/src/bgp_client.rs @@ -46,14 +46,14 @@ impl RoutingTable { ($addrty: ty, $addr: expr, $table: expr, $addr_bits: expr) => { { let mut res = Vec::new(); //TODO: Optimize this! - for i in (0..($addr_bits + 1)).rev() { + for i in (0..$addr_bits).rev() { let mut lookup = $addr.octets(); for b in 0..(i / 8) { - lookup[lookup.len() - b] = 0; + lookup[lookup.len() - b - 1] = 0; } - lookup[lookup.len() - (i/8)] &= !(((1u16 << (i % 8)) - 1) as u8); + lookup[lookup.len() - (i/8) - 1] &= !(((1u16 << (i % 8)) - 1) as u8); let lookup_addr = <$addrty>::from(lookup); - for attrs in $table.range((Included((lookup_addr, $addr_bits, 0)), Included((lookup_addr, $addr_bits, std::u32::MAX)))) { + for attrs in $table.range((Included((lookup_addr, $addr_bits - i as u8, 0)), Included((lookup_addr, $addr_bits - i as u8, std::u32::MAX)))) { res.push(Arc::clone(&attrs.1)); } if !res.is_empty() { break; }