mactime: add a "top" command to watch device stats
[vpp.git] / src / plugins / mactime / mactime.c
1 /*
2  * mactime.c - time-based src mac address filtration
3  *
4  * Copyright (c) 2018 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <mactime/mactime.h>
21
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
25
26 /* define message IDs */
27 #include <mactime/mactime.api_enum.h>
28 #include <mactime/mactime.api_types.h>
29
30 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
31
32 #define REPLY_MSG_ID_BASE mm->msg_id_base
33 #include <vlibapi/api_helper_macros.h>
34
35 mactime_main_t mactime_main;
36
37 /** \file time-base src-mac filter device-input feature arc implementation
38  */
39
40 static void
41 feature_init (mactime_main_t * mm)
42 {
43   if (mm->feature_initialized == 0)
44     {
45       /* Create the lookup table */
46       clib_bihash_init_8_8 (&mm->lookup_table, "mactime lookup table",
47                             mm->lookup_table_num_buckets,
48                             mm->lookup_table_memory_size);
49       clib_timebase_init (&mm->timebase, mm->timezone_offset,
50                           CLIB_TIMEBASE_DAYLIGHT_USA);
51       mm->allow_counters.name = "allow";
52       mm->allow_counters.stat_segment_name = "/mactime/allow";
53       mm->drop_counters.name = "drop";
54       mm->drop_counters.stat_segment_name = "/mactime/drop";
55       mm->feature_initialized = 1;
56     }
57 }
58
59 /** Action function shared between message handler and debug CLI
60 */
61 int
62 mactime_enable_disable (mactime_main_t * mm, u32 sw_if_index,
63                         int enable_disable)
64 {
65   vnet_sw_interface_t *sw;
66   int rv = 0;
67
68   feature_init (mm);
69
70   /* Utterly wrong? */
71   if (pool_is_free_index (mm->vnet_main->interface_main.sw_interfaces,
72                           sw_if_index))
73     return VNET_API_ERROR_INVALID_SW_IF_INDEX;
74
75   /* Not a physical port? */
76   sw = vnet_get_sw_interface (mm->vnet_main, sw_if_index);
77   if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
78     return VNET_API_ERROR_INVALID_SW_IF_INDEX;
79
80   vnet_feature_enable_disable ("device-input", "mactime",
81                                sw_if_index, enable_disable, 0, 0);
82   vnet_feature_enable_disable ("interface-output", "mactime-tx",
83                                sw_if_index, enable_disable, 0, 0);
84   return rv;
85 }
86
87 static clib_error_t *
88 mactime_enable_disable_command_fn (vlib_main_t * vm,
89                                    unformat_input_t * input,
90                                    vlib_cli_command_t * cmd)
91 {
92   mactime_main_t *mm = &mactime_main;
93   u32 sw_if_index = ~0;
94   int enable_disable = 1;
95
96   int rv;
97
98   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
99     {
100       if (unformat (input, "disable"))
101         enable_disable = 0;
102       else if (unformat (input, "%U", unformat_vnet_sw_interface,
103                          mm->vnet_main, &sw_if_index))
104         ;
105       else if (unformat (input, "sw_if_index %d", &sw_if_index))
106         ;
107       else
108         break;
109     }
110
111   if (sw_if_index == ~0)
112     return clib_error_return (0, "Please specify an interface...");
113
114   rv = mactime_enable_disable (mm, sw_if_index, enable_disable);
115
116   switch (rv)
117     {
118     case 0:
119       break;
120
121     case VNET_API_ERROR_INVALID_SW_IF_INDEX:
122       return clib_error_return
123         (0, "Invalid interface, only works on physical ports");
124       break;
125
126     default:
127       return clib_error_return (0, "mactime_enable_disable returned %d", rv);
128     }
129   return 0;
130 }
131
132 /* *INDENT-OFF* */
133 VLIB_CLI_COMMAND (mactime_enable_disable_command, static) =
134 {
135   .path = "mactime enable-disable",
136   .short_help =
137   "mactime enable-disable <interface-name> [disable]",
138   .function = mactime_enable_disable_command_fn,
139 };
140 /* *INDENT-ON* */
141
142
143 /** Enable / disable time-base src mac filtration on an interface
144  */
145
146 static void vl_api_mactime_enable_disable_t_handler
147   (vl_api_mactime_enable_disable_t * mp)
148 {
149   vl_api_mactime_enable_disable_reply_t *rmp;
150   mactime_main_t *mm = &mactime_main;
151   int rv;
152
153   VALIDATE_SW_IF_INDEX (mp);
154
155   rv = mactime_enable_disable (mm, ntohl (mp->sw_if_index),
156                                (int) (mp->enable_disable));
157   BAD_SW_IF_INDEX_LABEL;
158   REPLY_MACRO (VL_API_MACTIME_ENABLE_DISABLE_REPLY);
159 }
160
161 static void
162 vl_api_mactime_dump_t_handler (vl_api_mactime_dump_t * mp)
163 {
164   vl_api_mactime_details_t *ep;
165   vl_api_mactime_dump_reply_t *rmp;
166   mactime_device_t *dev;
167   mactime_main_t *mm = &mactime_main;
168   vl_api_registration_t *rp;
169   int rv = 0, i;
170   u32 his_table_epoch = clib_net_to_host_u32 (mp->my_table_epoch);
171   u32 message_size;
172   u32 name_len;
173   u32 nranges;
174
175   rp = vl_api_client_index_to_registration (mp->client_index);
176   if (rp == 0)
177     return;
178
179   if (his_table_epoch == mm->device_table_epoch)
180     {
181       rv = VNET_API_ERROR_NO_CHANGE;
182       goto send_reply;
183     }
184
185   /* *INDENT-OFF* */
186   pool_foreach (dev, mm->devices,
187   ({
188     message_size = sizeof(*ep) + vec_len(dev->device_name) +
189       vec_len(dev->ranges) * sizeof(ep->ranges[0]);
190
191     ep = vl_msg_api_alloc (message_size);
192     memset (ep, 0, message_size);
193     ep->_vl_msg_id = clib_host_to_net_u16 (VL_API_MACTIME_DETAILS
194                                            + mm->msg_id_base);
195     /* Index is the key for the stats segment combined counters */
196     ep->pool_index = clib_host_to_net_u32 (dev - mm->devices);
197
198     clib_memcpy_fast (ep->mac_address, dev->mac_address,
199                       sizeof (ep->mac_address));
200     ep->data_quota = clib_host_to_net_u64 (dev->data_quota);
201     ep->data_used_in_range = clib_host_to_net_u64 (dev->data_used_in_range);
202     ep->flags = clib_host_to_net_u32 (dev->flags);
203     nranges = vec_len (dev->ranges);
204     ep->nranges = clib_host_to_net_u32 (nranges);
205
206     for (i = 0; i < vec_len (dev->ranges); i++)
207       {
208         ep->ranges[i].start = dev->ranges[i].start;
209         ep->ranges[i].end = dev->ranges[i].end;
210       }
211
212     name_len = vec_len (dev->device_name);
213     name_len = (name_len < ARRAY_LEN(ep->device_name)) ?
214       name_len : ARRAY_LEN(ep->device_name) - 1;
215
216     clib_memcpy_fast (ep->device_name, dev->device_name,
217                       name_len);
218     ep->device_name [ARRAY_LEN(ep->device_name) -1] = 0;
219     vl_api_send_msg (rp, (u8 *)ep);
220   }));
221   /* *INDENT-OFF* */
222
223  send_reply:
224   /* *INDENT-OFF* */
225   REPLY_MACRO2 (VL_API_MACTIME_DUMP_REPLY,
226   ({
227     rmp->table_epoch = clib_host_to_net_u32 (mm->device_table_epoch);
228   }));
229   /* *INDENT-ON* */
230 }
231
232 /** Create a lookup table entry for the indicated mac address
233  */
234 void
235 mactime_send_create_entry_message (u8 * mac_address)
236 {
237   mactime_main_t *mm = &mactime_main;
238   api_main_t *am;
239   vl_shmem_hdr_t *shmem_hdr;
240   u8 *name;
241   vl_api_mactime_add_del_range_t *mp;
242
243   am = &api_main;
244   shmem_hdr = am->shmem_hdr;
245   mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
246   clib_memset (mp, 0, sizeof (*mp));
247   mp->_vl_msg_id = ntohs (VL_API_MACTIME_ADD_DEL_RANGE + mm->msg_id_base);
248   name = format (0, "mac-%U", format_mac_address, mac_address);
249
250   memcpy (mp->device_name, name, vec_len (name));
251   memcpy (mp->mac_address, mac_address, sizeof (mp->mac_address));
252   /* $$$ config: create allow / drop / range */
253   mp->allow = 1;
254   mp->is_add = 1;
255   vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp);
256 }
257
258 /** Add or delete static / dynamic accept/drop configuration for a src mac
259  */
260
261 static void vl_api_mactime_add_del_range_t_handler
262   (vl_api_mactime_add_del_range_t * mp)
263 {
264   mactime_main_t *mm = &mactime_main;
265   vl_api_mactime_add_del_range_reply_t *rmp;
266   mactime_device_t *dp;
267   clib_bihash_kv_8_8_t kv;
268   int found = 1;
269   clib_bihash_8_8_t *lut = &mm->lookup_table;
270   u64 data_quota;
271   int i, rv = 0;
272
273   feature_init (mm);
274
275   /*
276    * Change the table epoch. Skip 0 so clients can code my_table_epoch = 0
277    * to receive a full dump.
278    */
279   mm->device_table_epoch++;
280   if (PREDICT_FALSE (mm->device_table_epoch == 0))
281     mm->device_table_epoch++;
282
283   data_quota = clib_net_to_host_u64 (mp->data_quota);
284
285   clib_memset (&kv, 0, sizeof (kv));
286   memcpy (&kv.key, mp->mac_address, sizeof (mp->mac_address));
287
288   /* See if we have a lookup table entry for this src mac address */
289   if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
290     found = 0;
291
292   /* Add an entry? */
293   if (mp->is_add)
294     {
295       /* Create the device entry? */
296       if (found == 0)
297         {
298           pool_get (mm->devices, dp);
299           clib_memset (dp, 0, sizeof (*dp));
300           vlib_validate_combined_counter (&mm->allow_counters,
301                                           dp - mm->devices);
302           vlib_zero_combined_counter (&mm->allow_counters, dp - mm->devices);
303           vlib_validate_combined_counter (&mm->drop_counters,
304                                           dp - mm->devices);
305           vlib_zero_combined_counter (&mm->drop_counters, dp - mm->devices);
306           mp->device_name[ARRAY_LEN (mp->device_name) - 1] = 0;
307           dp->device_name = format (0, "%s%c", mp->device_name, 0);
308           memcpy (dp->mac_address, mp->mac_address, sizeof (mp->mac_address));
309           for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
310             {
311               clib_timebase_range_t _r, *r = &_r;
312               r->start = mp->ranges[i].start;
313               r->end = mp->ranges[i].end;
314               vec_add1 (dp->ranges, r[0]);
315             }
316           /* If we found some time ranges */
317           if (i)
318             {
319               /* Set allow/drop based on msg flags */
320               if (mp->drop)
321                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_DROP;
322               if (mp->allow)
323                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW;
324               if (mp->allow_quota)
325                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA;
326             }
327           else
328             {
329               /* no ranges, it's a static allow/drop */
330               if (mp->drop)
331                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_DROP;
332               if (mp->allow)
333                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_ALLOW;
334             }
335           if (mp->no_udp_10001)
336             dp->flags |= MACTIME_DEVICE_FLAG_DROP_UDP_10001;
337
338           dp->data_quota = data_quota;
339
340           /* Add the hash table entry */
341           kv.value = dp - mm->devices;
342           clib_bihash_add_del_8_8 (lut, &kv, 1 /* is_add */ );
343         }
344       else                      /* add more ranges, flags, etc. */
345         {
346           dp = pool_elt_at_index (mm->devices, kv.value);
347
348           for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
349             {
350               clib_timebase_range_t _r, *r = &_r;
351               r->start = mp->ranges[i].start;
352               r->end = mp->ranges[i].end;
353               vec_add1 (dp->ranges, r[0]);
354             }
355
356           if (vec_len (dp->ranges))
357             {
358               /* Set allow/drop based on msg flags */
359               if (mp->drop)
360                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_DROP;
361               if (mp->allow)
362                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW;
363               if (mp->allow_quota)
364                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA;
365             }
366           else
367             {
368               /* no ranges, it's a static allow/drop */
369               if (mp->drop)
370                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_DROP;
371               if (mp->allow)
372                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_ALLOW;
373             }
374           if (mp->no_udp_10001)
375             dp->flags |= MACTIME_DEVICE_FLAG_DROP_UDP_10001;
376
377           dp->data_quota = data_quota;
378         }
379     }
380   else                          /* delete case */
381     {
382       if (found == 0)
383         {
384           rv = VNET_API_ERROR_NO_SUCH_ENTRY;
385           goto reply;
386         }
387
388       /* find the device entry */
389       dp = pool_elt_at_index (mm->devices, kv.value);
390
391       /* Remove it from the lookup table */
392       clib_bihash_add_del_8_8 (lut, &kv, 0 /* is_add */ );
393       vec_free (dp->ranges);
394       pool_put (mm->devices, dp);
395     }
396
397 reply:
398   REPLY_MACRO (VL_API_MACTIME_ADD_DEL_RANGE_REPLY);
399 }
400
401 #include <mactime/mactime.api.c>
402 static clib_error_t *
403 mactime_init (vlib_main_t * vm)
404 {
405   mactime_main_t *mm = &mactime_main;
406
407   mm->vlib_main = vm;
408   mm->vnet_main = vnet_get_main ();
409
410   /* Ask for a correctly-sized block of API message decode slots */
411   mm->msg_id_base = setup_message_id_table ();
412
413   mm->lookup_table_num_buckets = MACTIME_NUM_BUCKETS;
414   mm->lookup_table_memory_size = MACTIME_MEMORY_SIZE;
415   mm->timezone_offset = -5;     /* US EST / EDT */
416   return 0;
417 }
418
419 VLIB_INIT_FUNCTION (mactime_init);
420
421 static clib_error_t *
422 mactime_config (vlib_main_t * vm, unformat_input_t * input)
423 {
424   mactime_main_t *mm = &mactime_main;
425
426   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
427     {
428       if (unformat (input, "lookup-table-buckets %u",
429                     &mm->lookup_table_num_buckets))
430         ;
431       else if (unformat (input, "lookup-table-memory %U",
432                          unformat_memory_size, &mm->lookup_table_memory_size))
433         ;
434       else if (unformat (input, "timezone_offset %d", &mm->timezone_offset))
435         ;
436       else
437         {
438           return clib_error_return (0, "unknown input '%U'",
439                                     format_unformat_error, input);
440         }
441     }
442   return 0;
443 }
444
445 VLIB_CONFIG_FUNCTION (mactime_config, "mactime");
446
447 /* *INDENT-OFF* */
448 VNET_FEATURE_INIT (mactime, static) =
449 {
450   .arc_name = "device-input",
451   .node_name = "mactime",
452   .runs_before = VNET_FEATURES ("ethernet-input"),
453 };
454 /* *INDENT-ON */
455
456 /* *INDENT-OFF* */
457 VNET_FEATURE_INIT (mactime_tx, static) =
458 {
459   .arc_name = "interface-output",
460   .node_name = "mactime-tx",
461   .runs_before = VNET_FEATURES ("interface-tx"),
462 };
463 /* *INDENT-ON */
464
465 /* *INDENT-OFF* */
466 VLIB_PLUGIN_REGISTER () =
467 {
468   .version = VPP_BUILD_VER,
469   .description = "Time-based MAC Source Address Filter",
470 };
471 /* *INDENT-ON* */
472
473 u8 *
474 format_bytes_with_width (u8 * s, va_list * va)
475 {
476   uword nbytes = va_arg (*va, u64);
477   int width = va_arg (*va, int);
478   f64 nbytes_f64;
479   u8 *fmt;
480   char *suffix = "";
481
482   if (width > 0)
483     fmt = format (0, "%%%d.3f%%s%c", width, 0);
484   else
485     fmt = format (0, "%%.3f%%s%c", 0);
486
487   if (nbytes > (1024ULL * 1024ULL * 1024ULL))
488     {
489       nbytes_f64 = ((f64) nbytes) / (1024.0 * 1024.0 * 1024.0);
490       suffix = "G";
491     }
492   else if (nbytes > (1024ULL * 1024ULL))
493     {
494       nbytes_f64 = ((f64) nbytes) / (1024.0 * 1024.0);
495       suffix = "M";
496     }
497   else if (nbytes > 1024ULL)
498     {
499       nbytes_f64 = ((f64) nbytes) / (1024.0);
500       suffix = "K";
501     }
502   else
503     {
504       nbytes_f64 = (f64) nbytes;
505       suffix = "B";
506     }
507
508   s = format (s, (char *) fmt, nbytes_f64, suffix);
509   vec_free (fmt);
510   return s;
511 }
512
513 static clib_error_t *
514 show_mactime_command_fn (vlib_main_t * vm,
515                          unformat_input_t * input, vlib_cli_command_t * cmd)
516 {
517   mactime_main_t *mm = &mactime_main;
518   mactime_device_t *dp;
519   u8 *macstring = 0;
520   char *status_string;
521   u32 *pool_indices = 0;
522   int verbose = 0;
523   int current_status = 99;
524   int i, j;
525   f64 now;
526   vlib_counter_t allow, drop;
527   ethernet_arp_ip4_entry_t *n, *pool;
528
529   vec_reset_length (mm->arp_cache_copy);
530   pool = ip4_neighbors_pool ();
531
532   /* *INDENT-OFF* */
533   pool_foreach (n, pool,
534   ({
535     vec_add1 (mm->arp_cache_copy, n[0]);
536   }));
537   /* *INDENT-ON* */
538
539   now = clib_timebase_now (&mm->timebase);
540
541   if (PREDICT_FALSE ((now - mm->sunday_midnight) > 86400.0 * 7.0))
542     mm->sunday_midnight = clib_timebase_find_sunday_midnight (now);
543
544   if (unformat (input, "verbose %d", &verbose))
545     ;
546
547   if (unformat (input, "verbose"))
548     verbose = 1;
549
550   if (verbose)
551     vlib_cli_output (vm, "Time now: %U", format_clib_timebase_time, now);
552
553   /* *INDENT-OFF* */
554   pool_foreach (dp, mm->devices,
555   ({
556     vec_add1 (pool_indices, dp - mm->devices);
557   }));
558   /* *INDENT-ON* */
559
560   vlib_cli_output (vm, "%-15s %18s %14s %10s %11s %13s",
561                    "Device Name", "Addresses", "Status",
562                    "AllowPkt", "AllowByte", "DropPkt");
563
564   for (i = 0; i < vec_len (pool_indices); i++)
565     {
566       dp = pool_elt_at_index (mm->devices, pool_indices[i]);
567
568       /* Check dynamic ranges */
569       for (j = 0; j < vec_len (dp->ranges); j++)
570         {
571           clib_timebase_range_t *r = dp->ranges + j;
572           f64 start0, end0;
573
574           start0 = r->start + mm->sunday_midnight;
575           end0 = r->end + mm->sunday_midnight;
576           if (verbose > 1)
577             vlib_cli_output (vm, "  Range %d: %U - %U", j,
578                              format_clib_timebase_time, start0,
579                              format_clib_timebase_time, end0);
580
581           if (now >= start0 && now <= end0)
582             {
583               if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW)
584                 current_status = 3;
585               else if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA)
586                 current_status = 5;
587               else
588                 current_status = 2;
589               if (verbose)
590                 {
591                   vlib_cli_output (vm, "  Time in range %d:", j);
592                   vlib_cli_output (vm, "     %U - %U",
593                                    format_clib_timebase_time, start0,
594                                    format_clib_timebase_time, end0);
595                 }
596               goto print;
597             }
598         }
599       if (verbose && j)
600         vlib_cli_output (vm, "  No range match.");
601       if (dp->flags & MACTIME_DEVICE_FLAG_STATIC_DROP)
602         current_status = 0;
603       if (dp->flags & MACTIME_DEVICE_FLAG_STATIC_ALLOW)
604         current_status = 1;
605       if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW)
606         current_status = 2;
607       if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_DROP)
608         current_status = 3;
609       if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA)
610         current_status = 4;
611
612     print:
613       vec_reset_length (macstring);
614       macstring = format (0, "%U", format_mac_address, dp->mac_address);
615       switch (current_status)
616         {
617         case 0:
618           status_string = "static drop";
619           break;
620         case 1:
621           status_string = "static allow";
622           break;
623         case 2:
624           status_string = "dynamic drop";
625           break;
626         case 3:
627           status_string = "dynamic allow";
628           break;
629         case 4:
630           status_string = "d-quota inact";
631           break;
632         case 5:
633           status_string = "d-quota activ";
634           break;
635         default:
636           status_string = "code bug!";
637           break;
638         }
639       vlib_get_combined_counter (&mm->allow_counters, dp - mm->devices,
640                                  &allow);
641       vlib_get_combined_counter (&mm->drop_counters, dp - mm->devices, &drop);
642       vlib_cli_output (vm, "%-15s %18s %14s %10lld %U %13lld",
643                        dp->device_name, macstring, status_string,
644                        allow.packets, format_bytes_with_width, allow.bytes,
645                        10, drop.packets);
646       if (dp->data_quota > 0)
647         vlib_cli_output (vm, "%-54s %s%U %s%U", " ", "Quota ",
648                          format_bytes_with_width, dp->data_quota, 10,
649                          "Use ", format_bytes_with_width,
650                          dp->data_used_in_range, 8);
651       /* This is really only good for small N... */
652       for (j = 0; j < vec_len (mm->arp_cache_copy); j++)
653         {
654           n = mm->arp_cache_copy + j;
655           if (!memcmp (dp->mac_address, n->mac.bytes, sizeof (n->mac)))
656             {
657               vlib_cli_output (vm, "%17s%U", " ", format_ip4_address,
658                                &n->ip4_address);
659             }
660         }
661     }
662   vec_free (macstring);
663   vec_free (pool_indices);
664
665   return 0;
666 }
667
668 /* *INDENT-OFF* */
669 VLIB_CLI_COMMAND (show_mactime_command, static) =
670 {
671   .path = "show mactime",
672   .short_help = "show mactime [verbose]",
673   .function = show_mactime_command_fn,
674 };
675 /* *INDENT-ON* */
676
677 static clib_error_t *
678 clear_mactime_command_fn (vlib_main_t * vm,
679                           unformat_input_t * input, vlib_cli_command_t * cmd)
680 {
681   mactime_main_t *mm = &mactime_main;
682
683   if (mm->feature_initialized == 0)
684     return clib_error_return (0, "feature not enabled");
685
686   vlib_clear_combined_counters (&mm->allow_counters);
687   vlib_clear_combined_counters (&mm->drop_counters);
688   vlib_cli_output (vm, "Mactime counters cleared...");
689   return 0;
690 }
691
692 /* *INDENT-OFF* */
693 VLIB_CLI_COMMAND (clear_mactime_command, static) =
694 {
695   .path = "clear mactime",
696   .short_help = "clear mactime counters",
697   .function = clear_mactime_command_fn,
698 };
699 /* *INDENT-ON* */
700
701
702
703 /*
704  * fd.io coding-style-patch-verification: ON
705  *
706  * Local Variables:
707  * eval: (c-set-style "gnu")
708  * End:
709  */