ip-neighbor: ARP and ND stats per-interface.
[vpp.git] / src / vnet / ip-neighbor / ip4_neighbor.c
index 9dda50e..368703d 100644 (file)
@@ -41,6 +41,7 @@
 #include <vnet/ethernet/ethernet.h>
 #include <vnet/util/throttle.h>
 #include <vnet/fib/fib_sas.h>
+#include <vnet/ip/ip_sas.h>
 
 /** ARP throttling */
 static throttle_t arp_throttle;
@@ -54,7 +55,8 @@ VLIB_REGISTER_LOG_CLASS (ip4_neighbor_log, static) = {
   vlib_log_debug (ip4_neighbor_log.class, fmt, __VA_ARGS__)
 
 void
-ip4_neighbor_probe_dst (u32 sw_if_index, const ip4_address_t * dst)
+ip4_neighbor_probe_dst (u32 sw_if_index, u32 thread_index,
+                       const ip4_address_t *dst)
 {
   ip4_address_t src;
   adj_index_t ai;
@@ -62,15 +64,16 @@ ip4_neighbor_probe_dst (u32 sw_if_index, const ip4_address_t * dst)
   /* any glean will do, it's just for the rewrite */
   ai = adj_glean_get (FIB_PROTOCOL_IP4, sw_if_index, NULL);
 
-  if (ADJ_INDEX_INVALID != ai && fib_sas4_get (sw_if_index, dst, &src))
+  if (ADJ_INDEX_INVALID != ai &&
+      (fib_sas4_get (sw_if_index, dst, &src) ||
+       ip4_sas_by_sw_if_index (sw_if_index, dst, &src)))
     ip4_neighbor_probe (vlib_get_main (),
                        vnet_get_main (), adj_get (ai), &src, dst);
 }
 
 void
-ip4_neighbor_advertise (vlib_main_t * vm,
-                       vnet_main_t * vnm,
-                       u32 sw_if_index, const ip4_address_t * addr)
+ip4_neighbor_advertise (vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index,
+                       u32 thread_index, const ip4_address_t *addr)
 {
   vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
   ip4_main_t *i4m = &ip4_main;
@@ -79,7 +82,8 @@ ip4_neighbor_advertise (vlib_main_t * vm,
 
   if (NULL == addr)
     {
-      if (fib_sas4_get (sw_if_index, NULL, &tmp))
+      if (fib_sas4_get (sw_if_index, NULL, &tmp) ||
+         ip4_sas_by_sw_if_index (sw_if_index, NULL, &tmp))
        addr = &tmp;
     }
 
@@ -122,6 +126,10 @@ ip4_neighbor_advertise (vlib_main_t * vm,
       to_next[0] = bi;
       f->n_vectors = 1;
       vlib_put_frame_to_node (vm, hi->output_node_index, f);
+
+      vlib_increment_simple_counter (
+       &ip_neighbor_counters[AF_IP4].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_GRAT],
+       thread_index, sw_if_index, 1);
     }
 }
 
@@ -185,7 +193,8 @@ ip4_arp_inline (vlib_main_t * vm,
              /* resolve the incomplete adj */
              resolve0 = adj0->sub_type.nbr.next_hop.ip4;
              /* Src IP address in ARP header. */
-             if (!fib_sas4_get (sw_if_index0, &resolve0, &src0))
+             if (!fib_sas4_get (sw_if_index0, &resolve0, &src0) &&
+                 !ip4_sas_by_sw_if_index (sw_if_index0, &resolve0, &src0))
                {
                  /* No source address available */
                  p0->error = node->errors[IP4_ARP_ERROR_NO_SOURCE_ADDRESS];