]> git.bitcoin.ninja Git - dnsseed-rust/commitdiff
Fix BGP table lookup
authorMatt Corallo <git@bluematt.me>
Mon, 2 Dec 2019 18:17:11 +0000 (13:17 -0500)
committerMatt Corallo <git@bluematt.me>
Mon, 2 Dec 2019 18:58:50 +0000 (13:58 -0500)
src/bgp_client.rs

index e38cffb97208d6fdb5a85c239d6ba7a95b4b0735..c20323d0e9fe6b7a7150e743b479a394fdba04c6 100644 (file)
@@ -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![])
                        } }