ip-neighbor: add ip neighbor flush 74/39674/3
authorOle Troan <otroan@employees.org>
Fri, 13 Oct 2023 06:52:47 +0000 (08:52 +0200)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Mon, 16 Oct 2023 10:52:51 +0000 (10:52 +0000)
Flushing the neighbor cache was only available through API.
Add CLI command. Either flushes whole table (IP4,IP6)
or all neighbors on specified interface.

Type: improvement
Change-Id: Ia8c68fb032a2dfd940a136edc2aee80db5c37685
Signed-off-by: Ole Troan <otroan@employees.org>
src/vnet/ip-neighbor/ip_neighbor.c

index d7450f9..d341698 100644 (file)
@@ -797,7 +797,7 @@ ip_neighbor_cmd (vlib_main_t * vm,
   vnet_main_t *vnm = vnet_get_main ();
   ip_neighbor_flags_t flags;
   u32 sw_if_index = ~0;
-  int is_add = 1;
+  int is_add = 1, is_flush = 0;
   int count = 1;
 
   flags = IP_NEIGHBOR_FLAG_DYNAMIC;
@@ -811,6 +811,8 @@ ip_neighbor_cmd (vlib_main_t * vm,
        ;
       else if (unformat (input, "delete") || unformat (input, "del"))
        is_add = 0;
+      else if (unformat (input, "flush"))
+       is_flush = 1;
       else if (unformat (input, "static"))
        {
          flags |= IP_NEIGHBOR_FLAG_STATIC;
@@ -824,6 +826,13 @@ ip_neighbor_cmd (vlib_main_t * vm,
        break;
     }
 
+  if (is_flush)
+    {
+      ip_neighbor_del_all (AF_IP4, sw_if_index);
+      ip_neighbor_del_all (AF_IP6, sw_if_index);
+      return NULL;
+    }
+
   if (sw_if_index == ~0 ||
       ip_address_is_zero (&ip) || mac_address_is_zero (&mac))
     return clib_error_return (0,
@@ -888,7 +897,7 @@ VLIB_CLI_COMMAND (ip_neighbor_command, static) = {
 };
 VLIB_CLI_COMMAND (ip_neighbor_command2, static) = {
   .path = "ip neighbor",
-  .short_help = "ip neighbor [del] <intfc> <ip-address> <mac-address> "
+  .short_help = "ip neighbor [del] [flush] <intfc> <ip-address> <mac-address> "
                "[static] [no-fib-entry] [count <count>]",
   .function = ip_neighbor_cmd,
 };