VPP-69: Create fib or bridge domain with arbitrary ID
[vpp.git] / vnet / vnet / ip / ip6_forward.c
index 2bd9efd..a136da3 100644 (file)
@@ -189,6 +189,14 @@ find_ip6_fib_by_table_index_or_id (ip6_main_t * im, u32 table_index_or_id, u32 f
   fib_index = table_index_or_id;
   if (! (flags & IP6_ROUTE_FLAG_FIB_INDEX))
     {
+      if (table_index_or_id == ~0) {
+        table_index_or_id = 0;
+        while (hash_get (im->fib_index_by_table_id, table_index_or_id)) {
+          table_index_or_id++;
+        }
+        return create_fib_with_table_id (im, table_index_or_id);
+      }
+
       p = hash_get (im->fib_index_by_table_id, table_index_or_id);
       if (! p)
        return create_fib_with_table_id (im, table_index_or_id);
@@ -271,7 +279,9 @@ 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 && !(a->flags & IP6_ROUTE_FLAG_KEEP_OLD_ADJACENCY))
+  if (old_adj_index == adj_index 
+      && adj_index != ~0
+      && !(a->flags & IP6_ROUTE_FLAG_KEEP_OLD_ADJACENCY))
     {
       ip_adjacency_t * adj = ip_get_adjacency (lm, adj_index);
       if (adj->share_count > 0)
@@ -367,10 +377,12 @@ ip6_add_del_route_next_hop (ip6_main_t * im,
             }
             else
             {
-              vnm->api_errno = VNET_API_ERROR_UNKNOWN_DESTINATION;
-              error = clib_error_return (0, "next-hop %U/128 not in FIB",
-                                         format_ip6_address, next_hop);
-              goto done;
+             ip_adjacency_t add_adj;
+             add_adj.lookup_next_index = IP_LOOKUP_NEXT_INDIRECT;
+             add_adj.indirect.next_hop.ip6.as_u64[0] = next_hop->as_u64[0];
+             add_adj.indirect.next_hop.ip6.as_u64[1] = next_hop->as_u64[1];
+             add_adj.explicit_fib_index = explicit_fib_index;
+             ip_add_adjacency (lm, &add_adj, 1, &nh_adj_index);
             }
           }
           else
@@ -641,10 +653,11 @@ void ip6_delete_matching_routes (ip6_main_t * im,
   ip6_maybe_remap_adjacencies (im, table_index_or_table_id, flags);
 }
 
-static uword
-ip6_lookup (vlib_main_t * vm,
-           vlib_node_runtime_t * node,
-           vlib_frame_t * frame)
+always_inline uword
+ip6_lookup_inline (vlib_main_t * vm,
+                  vlib_node_runtime_t * node,
+                  vlib_frame_t * frame,
+                  int is_indirect)
 {
   ip6_main_t * im = &ip6_main;
   ip_lookup_main_t * lm = &im->lookup_main;
@@ -669,6 +682,7 @@ ip6_lookup (vlib_main_t * vm,
          ip_lookup_next_t next0, next1;
          ip6_header_t * ip0, * ip1;
          ip_adjacency_t * adj0, * adj1;
+         ip6_address_t * dst_addr0, * dst_addr1;
           u32 fib_index0, fib_index1;
           u32 flow_hash_config0, flow_hash_config1;
 
@@ -694,6 +708,20 @@ ip6_lookup (vlib_main_t * vm,
          ip0 = vlib_buffer_get_current (p0);
          ip1 = vlib_buffer_get_current (p1);
 
+         if (is_indirect)
+           {
+             ip_adjacency_t * iadj0, * iadj1;
+             iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]);
+             iadj1 = ip_get_adjacency (lm, vnet_buffer(p1)->ip.adj_index[VLIB_TX]);
+             dst_addr0 = &iadj0->indirect.next_hop.ip6;
+             dst_addr1 = &iadj1->indirect.next_hop.ip6;
+           }
+         else
+           {
+             dst_addr0 = &ip0->dst_address;
+             dst_addr1 = &ip1->dst_address;
+           }
+
          fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
          fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]);
 
@@ -702,10 +730,8 @@ ip6_lookup (vlib_main_t * vm,
           fib_index1 = (vnet_buffer(p1)->sw_if_index[VLIB_TX] == (u32)~0) ?
             fib_index1 : vnet_buffer(p1)->sw_if_index[VLIB_TX];
 
-         adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, 
-                                                  &ip0->dst_address);
-         adj_index1 = ip6_fib_lookup_with_table (im, fib_index1, 
-                                                  &ip1->dst_address);
+         adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, dst_addr0);
+         adj_index1 = ip6_fib_lookup_with_table (im, fib_index1, dst_addr1);
 
          adj0 = ip_get_adjacency (lm, adj_index0);
          adj1 = ip_get_adjacency (lm, adj_index1);
@@ -713,13 +739,13 @@ ip6_lookup (vlib_main_t * vm,
           if (PREDICT_FALSE (adj0->explicit_fib_index != ~0))
             {
               adj_index0 = ip6_fib_lookup_with_table 
-                (im, adj0->explicit_fib_index, &ip0->dst_address);
+                (im, adj0->explicit_fib_index, dst_addr0);
               adj0 = ip_get_adjacency (lm, adj_index0);
             }
           if (PREDICT_FALSE (adj1->explicit_fib_index != ~0))
             {
               adj_index1 = ip6_fib_lookup_with_table 
-                (im, adj1->explicit_fib_index, &ip1->dst_address);
+                (im, adj1->explicit_fib_index, dst_addr1);
               adj1 = ip_get_adjacency (lm, adj_index1);
             }
 
@@ -818,6 +844,7 @@ ip6_lookup (vlib_main_t * vm,
          u32 pi0, adj_index0;
          ip_lookup_next_t next0;
          ip_adjacency_t * adj0;
+         ip6_address_t * dst_addr0;
           u32 fib_index0, flow_hash_config0;
 
          pi0 = from[0];
@@ -827,6 +854,17 @@ ip6_lookup (vlib_main_t * vm,
 
          ip0 = vlib_buffer_get_current (p0);
 
+         if (is_indirect)
+           {
+             ip_adjacency_t * iadj0;
+             iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]);
+             dst_addr0 = &iadj0->indirect.next_hop.ip6;
+           }
+         else
+           {
+             dst_addr0 = &ip0->dst_address;
+           }
+
          fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
           fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
             fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
@@ -834,15 +872,14 @@ ip6_lookup (vlib_main_t * vm,
           flow_hash_config0 = 
               vec_elt_at_index (im->fibs,fib_index0)->flow_hash_config;
 
-         adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, 
-                                                  &ip0->dst_address);
+         adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, dst_addr0);
 
          adj0 = ip_get_adjacency (lm, adj_index0);
 
           if (PREDICT_FALSE (adj0->explicit_fib_index != ~0))
             {
-              adj_index0 = ip6_fib_lookup_with_table 
-                (im, adj0->explicit_fib_index, &ip0->dst_address);
+              adj_index0 = ip6_fib_lookup_with_table
+                (im, adj0->explicit_fib_index, dst_addr0);
               adj0 = ip_get_adjacency (lm, adj_index0);
             }
 
@@ -1206,6 +1243,14 @@ ip6_sw_interface_add_del (vnet_main_t * vnm,
 
 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del);
 
+static uword
+ip6_lookup (vlib_main_t * vm,
+           vlib_node_runtime_t * node,
+           vlib_frame_t * frame)
+{
+  return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 0);
+}
+
 VLIB_REGISTER_NODE (ip6_lookup_node) = {
   .function = ip6_lookup,
   .name = "ip6-lookup",
@@ -1215,6 +1260,24 @@ VLIB_REGISTER_NODE (ip6_lookup_node) = {
   .next_nodes = IP6_LOOKUP_NEXT_NODES,
 };
 
+static uword
+ip6_indirect (vlib_main_t * vm,
+             vlib_node_runtime_t * node,
+             vlib_frame_t * frame)
+{
+  return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 1);
+}
+
+
+VLIB_REGISTER_NODE (ip6_indirect_node) = {
+  .function = ip6_indirect,
+  .name = "ip6-indirect",
+  .vector_size = sizeof (u32),
+
+  .n_next_nodes = IP_LOOKUP_N_NEXT,
+  .next_nodes = IP6_LOOKUP_NEXT_NODES,
+};
+
 typedef struct {
   /* Adjacency taken. */
   u32 adj_index;
@@ -1473,7 +1536,7 @@ u16 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, ip6
 
   n_bytes_left = n_this_buffer = payload_length_host_byte_order;
 #if DPDK > 0
-  if (p0
+  if (p0 && n_this_buffer + headers_size  > p0->current_length)
   {
     struct rte_mbuf *mb = rte_mbuf_from_vlib_buffer(p0);
     u8 nb_segs = mb->nb_segs;