ARP/ND use path_remove to complement path_add
[vpp.git] / src / vnet / ip / ip6_neighbor.c
index b1a0354..073b67f 100644 (file)
@@ -273,10 +273,23 @@ ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm,
        {
          n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]);
          mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
-         fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
-         pool_put (nm->neighbor_pool, n);
+         if (FIB_NODE_INDEX_INVALID != n->fib_entry_index)
+           {
+             fib_prefix_t pfx = {
+               .fp_len = 128,
+               .fp_proto = FIB_PROTOCOL_IP6,
+               .fp_addr.ip6 = n->key.ip6_address,
+             };
+             fib_table_entry_path_remove
+               (ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index),
+                &pfx,
+                FIB_SOURCE_ADJ,
+                FIB_PROTOCOL_IP6,
+                &pfx.fp_addr,
+                n->key.sw_if_index, ~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
+             pool_put (nm->neighbor_pool, n);
+           }
        }
-
       vec_free (to_delete);
     }
 
@@ -557,7 +570,7 @@ ip6_ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai)
     case IP_LOOKUP_NEXT_PUNT:
     case IP_LOOKUP_NEXT_LOCAL:
     case IP_LOOKUP_NEXT_REWRITE:
-    case IP_LOOKUP_NEXT_LOAD_BALANCE:
+    case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
     case IP_LOOKUP_NEXT_MIDCHAIN:
     case IP_LOOKUP_NEXT_ICMP_ERROR:
     case IP_LOOKUP_N_NEXT:
@@ -582,7 +595,7 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
   u32 next_index;
   pending_resolution_t *pr, *mc;
 
-  if (os_get_cpu_number ())
+  if (vlib_get_thread_index ())
     {
       set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
                                  1 /* set new neighbor */ , is_static,
@@ -610,6 +623,7 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
       mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool,
                 /* old value */ 0);
       n->key = k;
+      n->fib_entry_index = FIB_NODE_INDEX_INVALID;
 
       clib_memcpy (n->link_layer_address,
                   link_layer_address, n_bytes_link_layer_address);
@@ -626,14 +640,17 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
          };
          u32 fib_index;
 
-         fib_index = ip6_main.fib_index_by_sw_if_index[n->key.sw_if_index];
+         fib_index =
+           ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index);
          n->fib_entry_index =
-           fib_table_entry_update_one_path (fib_index, &pfx,
-                                            FIB_SOURCE_ADJ,
-                                            FIB_ENTRY_FLAG_NONE,
-                                            FIB_PROTOCOL_IP6, &pfx.fp_addr,
-                                            n->key.sw_if_index, ~0, 1, NULL,
-                                            FIB_ROUTE_PATH_FLAG_NONE);
+           fib_table_entry_path_add (fib_index, &pfx, FIB_SOURCE_ADJ,
+                                     FIB_ENTRY_FLAG_ATTACHED,
+                                     FIB_PROTOCOL_IP6, &pfx.fp_addr,
+                                     n->key.sw_if_index, ~0, 1, NULL,
+                                     FIB_ROUTE_PATH_FLAG_NONE);
+       }
+      else
+       {
          n->flags |= IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY;
        }
     }
@@ -723,7 +740,7 @@ vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
   uword *p;
   int rv = 0;
 
-  if (os_get_cpu_number ())
+  if (vlib_get_thread_index ())
     {
       set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
                                  0 /* unset */ , 0, 0);
@@ -747,7 +764,21 @@ vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
   adj_nbr_walk_nh6 (sw_if_index,
                    &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL);
 
-  fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
+
+  if (FIB_NODE_INDEX_INVALID != n->fib_entry_index)
+    {
+      fib_prefix_t pfx = {
+       .fp_len = 128,
+       .fp_proto = FIB_PROTOCOL_IP6,
+       .fp_addr.ip6 = n->key.ip6_address,
+      };
+      fib_table_entry_path_remove
+       (ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index),
+        &pfx,
+        FIB_SOURCE_ADJ,
+        FIB_PROTOCOL_IP6,
+        &pfx.fp_addr, n->key.sw_if_index, ~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
+    }
   pool_put (nm->neighbor_pool, n);
 
 out:
@@ -1001,8 +1032,7 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
 
              if (ADJ_INDEX_INVALID != src_adj_index0)
                {
-                 ip_adjacency_t *adj0 =
-                   ip_get_adjacency (&im->lookup_main, src_adj_index0);
+                 ip_adjacency_t *adj0 = adj_get (src_adj_index0);
 
                  /* Allow all realistic-looking rewrite adjacencies to pass */
                  ni0 = adj0->lookup_next_index;
@@ -1028,7 +1058,7 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
 
          /* If src address unspecified or link local, donot learn neighbor MAC */
          if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
-                           !ip6_sadd_unspecified && !ip6_sadd_link_local))
+                           !ip6_sadd_unspecified))
            {
              ip6_neighbor_main_t *nm = &ip6_neighbor_main;
              if (nm->limit_neighbor_cache_size &&
@@ -1041,7 +1071,7 @@ icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
                                              &h0->target_address,
                                              o0->ethernet_address,
                                              sizeof (o0->ethernet_address),
-                                             0, 0);
+                                             0, ip6_sadd_link_local);
            }
 
          if (is_solicitation && error0 == ICMP6_ERROR_NONE)
@@ -1322,8 +1352,7 @@ icmp6_router_solicitation (vlib_main_t * vm,
 
              if (ADJ_INDEX_INVALID != src_adj_index0)
                {
-                 ip_adjacency_t *adj0 = ip_get_adjacency (&im->lookup_main,
-                                                          src_adj_index0);
+                 ip_adjacency_t *adj0 = adj_get (src_adj_index0);
 
                  error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0
                            ?