IP6 FIB: Micro optimization in lookup
[vpp.git] / vnet / vnet / ip / ip6_forward.c
index abd3420..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)
@@ -265,6 +270,14 @@ void ip6_add_del_route (ip6_main_t * im, ip6_add_del_route_args_t * a)
       BV(clib_bihash_add_del) (&im->ip6_lookup_table, &kv, 1 /* is_add */);
     }
 
+  /* Avoid spurious reference count increments */
+  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)
+        adj->share_count --;
+    }
+
   /* Delete old adjacency index if present and changed. */
   {
     if (! (a->flags & IP6_ROUTE_FLAG_KEEP_OLD_ADJACENCY)
@@ -922,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;
@@ -1437,7 +1450,7 @@ u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip6
 #if DPDK > 0
   if (p0) 
   {
-    struct rte_mbuf *mb = ((struct rte_mbuf *)p0)-1;
+    struct rte_mbuf *mb = rte_mbuf_from_vlib_buffer(p0);
     u8 nb_segs = mb->nb_segs;
 
     n_this_buffer = (p0->current_length > headers_size ?
@@ -1621,7 +1634,6 @@ ip6_local (vlib_main_t * vm,
          error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1;
 
          ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
-         ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_TCP == IP6_ERROR_TCP_CHECKSUM);
          ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
          error0 = (! good_l4_checksum0
                    ? IP6_ERROR_UDP_CHECKSUM + type0
@@ -1713,7 +1725,6 @@ ip6_local (vlib_main_t * vm,
          error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
 
          ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
-         ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_TCP == IP6_ERROR_TCP_CHECKSUM);
          ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
          error0 = (! good_l4_checksum0
                    ? IP6_ERROR_UDP_CHECKSUM + type0
@@ -1754,7 +1765,6 @@ VLIB_REGISTER_NODE (ip6_local_node,static) = {
   .next_nodes = {
     [IP_LOCAL_NEXT_DROP] = "error-drop",
     [IP_LOCAL_NEXT_PUNT] = "error-punt",
-    // [IP_LOCAL_NEXT_TCP_LOOKUP] = "ip6-tcp-lookup",
     [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
     [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
   },