ARP learning fixes (VPP-843)
[vpp.git] / src / vnet / ip / ip6_neighbor.c
index 2af546d..4fd078d 100644 (file)
@@ -273,7 +273,8 @@ 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);
+         if (FIB_NODE_INDEX_INVALID != n->fib_entry_index)
+           fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
          pool_put (nm->neighbor_pool, n);
        }
 
@@ -557,6 +558,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_MCAST_MIDCHAIN:
     case IP_LOOKUP_NEXT_MIDCHAIN:
     case IP_LOOKUP_NEXT_ICMP_ERROR:
     case IP_LOOKUP_N_NEXT:
@@ -609,6 +611,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);
@@ -629,10 +632,13 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
          n->fib_entry_index =
            fib_table_entry_update_one_path (fib_index, &pfx,
                                             FIB_SOURCE_ADJ,
-                                            FIB_ENTRY_FLAG_NONE,
+                                            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;
        }
     }
@@ -746,7 +752,9 @@ 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_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
   pool_put (nm->neighbor_pool, n);
 
 out:
@@ -1000,8 +1008,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;
@@ -1027,7 +1034,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 +1047,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)
@@ -1321,8 +1328,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
                            ?