From 0d474196b752d00a80209535b60c23d35a492745 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 22 Aug 2019 21:01:25 -0400 Subject: [PATCH] Fix route lookup masking --- src/bgp_client.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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; } -- 2.39.5