fib: Source Address Selection
[vpp.git] / src / vnet / ip-neighbor / ip_neighbor.c
index 12ce0d6..2dd8e74 100644 (file)
@@ -386,7 +386,7 @@ ip_neighbor_mk_incomplete_walk (adj_index_t ai, void *ctx)
 }
 
 static void
-ip_neighbor_free (ip_neighbor_t * ipn)
+ip_neighbor_destroy (ip_neighbor_t * ipn)
 {
   ip_address_family_t af;
 
@@ -395,6 +395,9 @@ ip_neighbor_free (ip_neighbor_t * ipn)
   IP_NEIGHBOR_DBG ("free: %U", format_ip_neighbor,
                   ip_neighbor_get_index (ipn));
 
+  ip_neighbor_publish (ip_neighbor_get_index (ipn),
+                      IP_NEIGHBOR_EVENT_REMOVED);
+
   adj_nbr_walk_nh (ipn->ipn_key->ipnk_sw_if_index,
                   ip_address_family_to_fib_proto (af),
                   &ip_addr_46 (&ipn->ipn_key->ipnk_ip),
@@ -426,7 +429,7 @@ ip_neighbor_force_reuse (ip_address_family_t af)
     return (false);
 
   elt = clib_llist_prev (ip_neighbor_elt_pool, ipne_anchor, head);
-  ip_neighbor_free (ip_neighbor_get (elt->ipne_index));
+  ip_neighbor_destroy (ip_neighbor_get (elt->ipne_index));
 
   return (true);
 }
@@ -556,7 +559,7 @@ ip_neighbor_add (const ip_address_t * ip,
 
 check_customers:
   /* Customer(s) requesting event for this address? */
-  ip_neighbor_publish (ip_neighbor_get_index (ipn));
+  ip_neighbor_publish (ip_neighbor_get_index (ipn), IP_NEIGHBOR_EVENT_ADDED);
 
   if (stats_index)
     *stats_index = adj_nbr_find (fproto,
@@ -588,7 +591,7 @@ ip_neighbor_del (const ip_address_t * ip, u32 sw_if_index)
   if (NULL == ipn)
     return (VNET_API_ERROR_NO_SUCH_ENTRY);
 
-  ip_neighbor_free (ipn);
+  ip_neighbor_destroy (ipn);
 
   return (0);
 }
@@ -623,7 +626,8 @@ ip_neighbor_del_all (ip_address_family_t af, u32 sw_if_index)
 
   ip_neighbor_walk (af, sw_if_index, ip_neighbor_del_all_walk_cb, &ctx);
 
-  vec_foreach (ipni, ctx.ipn_del) ip_neighbor_free (ip_neighbor_get (*ipni));
+  vec_foreach (ipni,
+              ctx.ipn_del) ip_neighbor_destroy (ip_neighbor_get (*ipni));
   vec_free (ctx.ipn_del);
 }
 
@@ -1007,22 +1011,19 @@ ip_neighbor_register (ip_address_family_t af, const ip_neighbor_vft_t * vft)
 }
 
 void
-ip_neighbor_probe_dst (const ip_adjacency_t * adj, const ip46_address_t * dst)
+ip_neighbor_probe_dst (u32 sw_if_index,
+                      ip_address_family_t af, const ip46_address_t * dst)
 {
-  if (!vnet_sw_interface_is_admin_up (vnet_get_main (),
-                                     adj->rewrite_header.sw_if_index))
+  if (!vnet_sw_interface_is_admin_up (vnet_get_main (), sw_if_index))
     return;
 
-  switch (adj->ia_nh_proto)
+  switch (af)
     {
-    case FIB_PROTOCOL_IP6:
-      ip6_neighbor_probe_dst (adj, &dst->ip6);
-      break;
-    case FIB_PROTOCOL_IP4:
-      ip4_neighbor_probe_dst (adj, &dst->ip4);
+    case AF_IP6:
+      ip6_neighbor_probe_dst (sw_if_index, &dst->ip6);
       break;
-    case FIB_PROTOCOL_MPLS:
-      ASSERT (0);
+    case AF_IP4:
+      ip4_neighbor_probe_dst (sw_if_index, &dst->ip4);
       break;
     }
 }
@@ -1030,7 +1031,9 @@ ip_neighbor_probe_dst (const ip_adjacency_t * adj, const ip46_address_t * dst)
 void
 ip_neighbor_probe (const ip_adjacency_t * adj)
 {
-  ip_neighbor_probe_dst (adj, &adj->sub_type.nbr.next_hop);
+  ip_neighbor_probe_dst (adj->rewrite_header.sw_if_index,
+                        ip_address_family_from_fib_proto (adj->ia_nh_proto),
+                        &adj->sub_type.nbr.next_hop);
 }
 
 void
@@ -1143,7 +1146,6 @@ ip_neighbor_ethernet_change_mac (ethernet_main_t * em,
                                 u32 sw_if_index, uword opaque)
 {
   ip_neighbor_t *ipn;
-  adj_index_t ai;
 
   IP_NEIGHBOR_DBG ("mac-change: %U",
                   format_vnet_sw_if_index_name, vnet_get_main (),
@@ -1161,10 +1163,7 @@ ip_neighbor_ethernet_change_mac (ethernet_main_t * em,
   }));
   /* *INDENT-ON* */
 
-  ai = adj_glean_get (FIB_PROTOCOL_IP4, sw_if_index);
-
-  if (ADJ_INDEX_INVALID != ai)
-    adj_glean_update_rewrite (ai);
+  adj_glean_update_rewrite_itf (sw_if_index);
 }
 
 void
@@ -1220,7 +1219,7 @@ ip_neighbor_flush (ip_address_family_t af, u32 sw_if_index)
   }));
   /* *INDENT-ON* */
 
-  vec_foreach (ipni, ipnis) ip_neighbor_free (ip_neighbor_get (*ipni));
+  vec_foreach (ipni, ipnis) ip_neighbor_destroy (ip_neighbor_get (*ipni));
   vec_free (ipnis);
 }
 
@@ -1273,7 +1272,7 @@ ip_neighbor_sweep (ip_address_family_t af)
 
   vec_foreach (ipni, ctx.ipnsc_stale)
   {
-    ip_neighbor_free (ip_neighbor_get (*ipni));
+    ip_neighbor_destroy (ip_neighbor_get (*ipni));
   }
   vec_free (ctx.ipnsc_stale);
 }
@@ -1407,7 +1406,7 @@ ip_neighbor_add_del_interface_address_v4 (ip4_main_t * im,
       ip_neighbor_walk (AF_IP4, sw_if_index, ip_neighbor_walk_covered, &ctx);
 
       vec_foreach (ipni, ctx.ipnis)
-       ip_neighbor_free (ip_neighbor_get (*ipni));
+       ip_neighbor_destroy (ip_neighbor_get (*ipni));
 
       vec_free (ctx.ipnis);
     }
@@ -1449,7 +1448,7 @@ ip_neighbor_add_del_interface_address_v6 (ip6_main_t * im,
       ip_neighbor_walk (AF_IP6, sw_if_index, ip_neighbor_walk_covered, &ctx);
 
       vec_foreach (ipni, ctx.ipnis)
-       ip_neighbor_free (ip_neighbor_get (*ipni));
+       ip_neighbor_destroy (ip_neighbor_get (*ipni));
 
       vec_free (ctx.ipnis);
     }
@@ -1539,14 +1538,8 @@ ip_neighbour_age_out (index_t ipni, f64 now, f64 * wait)
        }
       else
        {
-         adj_index_t ai;
-
-         ai = adj_glean_get (ip_address_family_to_fib_proto (af),
-                             ip_neighbor_get_sw_if_index (ipn));
-
-         if (ADJ_INDEX_INVALID != ai)
-           ip_neighbor_probe_dst (adj_get (ai),
-                                  &ip_addr_46 (&ipn->ipn_key->ipnk_ip));
+         ip_neighbor_probe_dst (ip_neighbor_get_sw_if_index (ipn),
+                                af, &ip_addr_46 (&ipn->ipn_key->ipnk_ip));
 
          ipn->ipn_n_probes++;
          *wait = 1;
@@ -1623,7 +1616,7 @@ ip_neighbor_age_loop (vlib_main_t * vm,
             else if (IP_NEIGHBOR_AGE_DEAD == res) {
               /* the oldest neighbor is dead, pop it, then restart the walk
                * again from the back */
-              ip_neighbor_free (ip_neighbor_get(elt->ipne_index));
+              ip_neighbor_destroy (ip_neighbor_get(elt->ipne_index));
               goto restart;
             }