ARP/ND use path_remove to complement path_add
[vpp.git] / src / vnet / ip / ip6_neighbor.c
index 42edb79..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);
     }
 
@@ -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;
        }
     }
@@ -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:
@@ -1027,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 &&
@@ -1040,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)