IP6 FIB: Micro optimization in lookup
[vpp.git] / vnet / vnet / ip / ip6_forward.c
index a478bab..6c8d18d 100644 (file)
@@ -64,19 +64,24 @@ ip6_fib_lookup_with_table (ip6_main_t * im, u32 fib_index, ip6_address_t * dst)
   int i, len;
   int rv;
   BVT(clib_bihash_kv) kv, value;
+  u64 fib;
 
   len = vec_len (im->prefix_lengths_in_search_order);
 
+  kv.key[0] = dst->as_u64[0];
+  kv.key[1] = dst->as_u64[1];
+  fib = ((u64)((fib_index))<<32);
+
   for (i = 0; i < len; i++)
     {
       int dst_address_length = im->prefix_lengths_in_search_order[i];
       ip6_address_t * mask = &im->fib_masks[dst_address_length];
       
       ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
-      
-      kv.key[0] = dst->as_u64[0] & mask->as_u64[0];
-      kv.key[1] = dst->as_u64[1] & mask->as_u64[1];
-      kv.key[2] = ((u64)((fib_index))<<32) | dst_address_length;
+      //As lengths are decreasing, masks are increasingly specific.
+      kv.key[0] &= mask->as_u64[0];
+      kv.key[1] &= mask->as_u64[1];
+      kv.key[2] = fib | dst_address_length;
       
       rv = BV(clib_bihash_search_inline_2)(&im->ip6_lookup_table, &kv, &value);
       if (rv == 0)
@@ -266,7 +271,7 @@ void ip6_add_del_route (ip6_main_t * im, ip6_add_del_route_args_t * a)
     }
 
   /* Avoid spurious reference count increments */
-  if (old_adj_index == adj_index)
+  if (old_adj_index == adj_index && !(a->flags & IP6_ROUTE_FLAG_KEEP_OLD_ADJACENCY))
     {
       ip_adjacency_t * adj = ip_get_adjacency (lm, adj_index);
       if (adj->share_count > 0)
@@ -930,7 +935,7 @@ ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index,
   if (classify_table_index != (u32) ~0)
     {
       adj->lookup_next_index = IP_LOOKUP_NEXT_CLASSIFY;
-      adj->classify_table_index = classify_table_index;
+      adj->classify.table_index = classify_table_index;
     }
   else
     adj->lookup_next_index = IP_LOOKUP_NEXT_LOCAL;