mactime: pass context in reply to mactime_dump
[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     ep->context = mp->context;
196     /* Index is the key for the stats segment combined counters */
197     ep->pool_index = clib_host_to_net_u32 (dev - mm->devices);
198
199     clib_memcpy_fast (ep->mac_address, dev->mac_address,
200                       sizeof (ep->mac_address));
201     ep->data_quota = clib_host_to_net_u64 (dev->data_quota);
202     ep->data_used_in_range = clib_host_to_net_u64 (dev->data_used_in_range);
203     ep->flags = clib_host_to_net_u32 (dev->flags);
204     nranges = vec_len (dev->ranges);
205     ep->nranges = clib_host_to_net_u32 (nranges);
206
207     for (i = 0; i < vec_len (dev->ranges); i++)
208       {
209         ep->ranges[i].start = dev->ranges[i].start;
210         ep->ranges[i].end = dev->ranges[i].end;
211       }
212
213     name_len = vec_len (dev->device_name);
214     name_len = (name_len < ARRAY_LEN(ep->device_name)) ?
215       name_len : ARRAY_LEN(ep->device_name) - 1;
216
217     clib_memcpy_fast (ep->device_name, dev->device_name,
218                       name_len);
219     ep->device_name [ARRAY_LEN(ep->device_name) -1] = 0;
220     vl_api_send_msg (rp, (u8 *)ep);
221   }));
222   /* *INDENT-OFF* */
223
224  send_reply:
225   /* *INDENT-OFF* */
226   REPLY_MACRO2 (VL_API_MACTIME_DUMP_REPLY,
227   ({
228     rmp->table_epoch = clib_host_to_net_u32 (mm->device_table_epoch);
229   }));
230   /* *INDENT-ON* */
231 }
232
233 /** Create a lookup table entry for the indicated mac address
234  */
235 void
236 mactime_send_create_entry_message (u8 * mac_address)
237 {
238   mactime_main_t *mm = &mactime_main;
239   api_main_t *am;
240   vl_shmem_hdr_t *shmem_hdr;
241   u8 *name;
242   vl_api_mactime_add_del_range_t *mp;
243
244   am = &api_main;
245   shmem_hdr = am->shmem_hdr;
246   mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
247   clib_memset (mp, 0, sizeof (*mp));
248   mp->_vl_msg_id = ntohs (VL_API_MACTIME_ADD_DEL_RANGE + mm->msg_id_base);
249   name = format (0, "mac-%U", format_mac_address, mac_address);
250
251   memcpy (mp->device_name, name, vec_len (name));
252   memcpy (mp->mac_address, mac_address, sizeof (mp->mac_address));
253   /* $$$ config: create allow / drop / range */
254   mp->allow = 1;
255   mp->is_add = 1;
256   vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp);
257 }
258
259 /** Add or delete static / dynamic accept/drop configuration for a src mac
260  */
261
262 static void vl_api_mactime_add_del_range_t_handler
263   (vl_api_mactime_add_del_range_t * mp)
264 {
265   mactime_main_t *mm = &mactime_main;
266   vl_api_mactime_add_del_range_reply_t *rmp;
267   mactime_device_t *dp;
268   clib_bihash_kv_8_8_t kv;
269   int found = 1;
270   clib_bihash_8_8_t *lut = &mm->lookup_table;
271   u64 data_quota;
272   int i, rv = 0;
273
274   feature_init (mm);
275
276   /*
277    * Change the table epoch. Skip 0 so clients can code my_table_epoch = 0
278    * to receive a full dump.
279    */
280   mm->device_table_epoch++;
281   if (PREDICT_FALSE (mm->device_table_epoch == 0))
282     mm->device_table_epoch++;
283
284   data_quota = clib_net_to_host_u64 (mp->data_quota);
285
286   clib_memset (&kv, 0, sizeof (kv));
287   memcpy (&kv.key, mp->mac_address, sizeof (mp->mac_address));
288
289   /* See if we have a lookup table entry for this src mac address */
290   if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
291     found = 0;
292
293   /* Add an entry? */
294   if (mp->is_add)
295     {
296       /* Create the device entry? */
297       if (found == 0)
298         {
299           pool_get (mm->devices, dp);
300           clib_memset (dp, 0, sizeof (*dp));
301           vlib_validate_combined_counter (&mm->allow_counters,
302                                           dp - mm->devices);
303           vlib_zero_combined_counter (&mm->allow_counters, dp - mm->devices);
304           vlib_validate_combined_counter (&mm->drop_counters,
305                                           dp - mm->devices);
306           vlib_zero_combined_counter (&mm->drop_counters, dp - mm->devices);
307           mp->device_name[ARRAY_LEN (mp->device_name) - 1] = 0;
308           dp->device_name = format (0, "%s%c", mp->device_name, 0);
309           memcpy (dp->mac_address, mp->mac_address, sizeof (mp->mac_address));
310           for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
311             {
312               clib_timebase_range_t _r, *r = &_r;
313               r->start = mp->ranges[i].start;
314               r->end = mp->ranges[i].end;
315               vec_add1 (dp->ranges, r[0]);
316             }
317           /* If we found some time ranges */
318           if (i)
319             {
320               /* Set allow/drop based on msg flags */
321               if (mp->drop)
322                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_DROP;
323               if (mp->allow)
324                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW;
325               if (mp->allow_quota)
326                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA;
327             }
328           else
329             {
330               /* no ranges, it's a static allow/drop */
331               if (mp->drop)
332                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_DROP;
333               if (mp->allow)
334                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_ALLOW;
335             }
336           if (mp->no_udp_10001)
337             dp->flags |= MACTIME_DEVICE_FLAG_DROP_UDP_10001;
338
339           dp->data_quota = data_quota;
340
341           /* Add the hash table entry */
342           kv.value = dp - mm->devices;
343           clib_bihash_add_del_8_8 (lut, &kv, 1 /* is_add */ );
344         }
345       else                      /* add more ranges, flags, etc. */
346         {
347           dp = pool_elt_at_index (mm->devices, kv.value);
348
349           for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
350             {
351               clib_timebase_range_t _r, *r = &_r;
352               r->start = mp->ranges[i].start;
353               r->end = mp->ranges[i].end;
354               vec_add1 (dp->ranges, r[0]);
355             }
356
357           if (vec_len (dp->ranges))
358             {
359               /* Set allow/drop based on msg flags */
360               if (mp->drop)
361                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_DROP;
362               if (mp->allow)
363                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW;
364               if (mp->allow_quota)
365                 dp->flags = MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA;
366             }
367           else
368             {
369               /* no ranges, it's a static allow/drop */
370               if (mp->drop)
371                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_DROP;
372               if (mp->allow)
373                 dp->flags = MACTIME_DEVICE_FLAG_STATIC_ALLOW;
374             }
375           if (mp->no_udp_10001)
376             dp->flags |= MACTIME_DEVICE_FLAG_DROP_UDP_10001;
377
378           dp->data_quota = data_quota;
379         }
380     }
381   else                          /* delete case */
382     {
383       if (found == 0)
384         {
385           rv = VNET_API_ERROR_NO_SUCH_ENTRY;
386           goto reply;
387         }
388
389       /* find the device entry */
390       dp = pool_elt_at_index (mm->devices, kv.value);
391
392       /* Remove it from the lookup table */
393       clib_bihash_add_del_8_8 (lut, &kv, 0 /* is_add */ );
394       vec_free (dp->ranges);
395       pool_put (mm->devices, dp);
396     }
397
398 reply:
399   REPLY_MACRO (VL_API_MACTIME_ADD_DEL_RANGE_REPLY);
400 }
401
402 #include <mactime/mactime.api.c>
403 static clib_error_t *
404 mactime_init (vlib_main_t * vm)
405 {
406   mactime_main_t *mm = &mactime_main;
407
408   mm->vlib_main = vm;
409   mm->vnet_main = vnet_get_main ();
410
411   /* Ask for a correctly-sized block of API message decode slots */
412   mm->msg_id_base = setup_message_id_table ();
413
414   mm->lookup_table_num_buckets = MACTIME_NUM_BUCKETS;
415   mm->lookup_table_memory_size = MACTIME_MEMORY_SIZE;
416   mm->timezone_offset = -5;     /* US EST / EDT */
417   return 0;
418 }
419
420 VLIB_INIT_FUNCTION (mactime_init);
421
422 static clib_error_t *
423 mactime_config (vlib_main_t * vm, unformat_input_t * input)
424 {
425   mactime_main_t *mm = &mactime_main;
426
427   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
428     {
429       if (unformat (input, "lookup-table-buckets %u",
430                     &mm->lookup_table_num_buckets))
431         ;
432       else if (unformat (input, "lookup-table-memory %U",
433                          unformat_memory_size, &mm->lookup_table_memory_size))
434         ;
435       else if (unformat (input, "timezone_offset %d", &mm->timezone_offset))
436         ;
437       else
438         {
439           return clib_error_return (0, "unknown input '%U'",
440                                     format_unformat_error, input);
441         }
442     }
443   return 0;
444 }
445
446 VLIB_CONFIG_FUNCTION (mactime_config, "mactime");
447
448 /* *INDENT-OFF* */
449 VNET_FEATURE_INIT (mactime, static) =
450 {
451   .arc_name = "device-input",
452   .node_name = "mactime",
453   .runs_before = VNET_FEATURES ("ethernet-input"),
454 };
455 /* *INDENT-ON */
456
457 /* *INDENT-OFF* */
458 VNET_FEATURE_INIT (mactime_tx, static) =
459 {
460   .arc_name = "interface-output",
461   .node_name = "mactime-tx",
462   .runs_before = VNET_FEATURES ("interface-tx"),
463 };
464 /* *INDENT-ON */
465
466 /* *INDENT-OFF* */
467 VLIB_PLUGIN_REGISTER () =
468 {
469   .version = VPP_BUILD_VER,
470   .description = "Time-based MAC Source Address Filter",
471 };
472 /* *INDENT-ON* */
473
474 u8 *
475 format_bytes_with_width (u8 * s, va_list * va)
476 {
477   uword nbytes = va_arg (*va, u64);
478   int width = va_arg (*va, int);
479   f64 nbytes_f64;
480   u8 *fmt;
481   char *suffix = "";
482
483   if (width > 0)
484     fmt = format (0, "%%%d.3f%%s%c", width, 0);
485   else
486     fmt = format (0, "%%.3f%%s%c", 0);
487
488   if (nbytes > (1024ULL * 1024ULL * 1024ULL))
489     {
490       nbytes_f64 = ((f64) nbytes) / (1024.0 * 1024.0 * 1024.0);
491       suffix = "G";
492     }
493   else if (nbytes > (1024ULL * 1024ULL))
494     {
495       nbytes_f64 = ((f64) nbytes) / (1024.0 * 1024.0);
496       suffix = "M";
497     }
498   else if (nbytes > 1024ULL)
499     {
500       nbytes_f64 = ((f64) nbytes) / (1024.0);
501       suffix = "K";
502     }
503   else
504     {
505       nbytes_f64 = (f64) nbytes;
506       suffix = "B";
507     }
508
509   s = format (s, (char *) fmt, nbytes_f64, suffix);
510   vec_free (fmt);
511   return s;
512 }
513
514 static clib_error_t *
515 show_mactime_command_fn (vlib_main_t * vm,
516                          unformat_input_t * input, vlib_cli_command_t * cmd)
517 {
518   mactime_main_t *mm = &mactime_main;
519   mactime_device_t *dp;
520   u8 *macstring = 0;
521   char *status_string;
522   u32 *pool_indices = 0;
523   int verbose = 0;
524   int current_status = 99;
525   int i, j;
526   f64 now;
527   vlib_counter_t allow, drop;
528   ethernet_arp_ip4_entry_t *n, *pool;
529
530   vec_reset_length (mm->arp_cache_copy);
531   pool = ip4_neighbors_pool ();
532
533   /* *INDENT-OFF* */
534   pool_foreach (n, pool,
535   ({
536     vec_add1 (mm->arp_cache_copy, n[0]);
537   }));
538   /* *INDENT-ON* */
539
540   now = clib_timebase_now (&mm->timebase);
541
542   if (PREDICT_FALSE ((now - mm->sunday_midnight) > 86400.0 * 7.0))
543     mm->sunday_midnight = clib_timebase_find_sunday_midnight (now);
544
545   if (unformat (input, "verbose %d", &verbose))
546     ;
547
548   if (unformat (input, "verbose"))
549     verbose = 1;
550
551   if (verbose)
552     vlib_cli_output (vm, "Time now: %U", format_clib_timebase_time, now);
553
554   /* *INDENT-OFF* */
555   pool_foreach (dp, mm->devices,
556   ({
557     vec_add1 (pool_indices, dp - mm->devices);
558   }));
559   /* *INDENT-ON* */
560
561   vlib_cli_output (vm, "%-15s %18s %14s %10s %11s %13s",
562                    "Device Name", "Addresses", "Status",
563                    "AllowPkt", "AllowByte", "DropPkt");
564
565   for (i = 0; i < vec_len (pool_indices); i++)
566     {
567       dp = pool_elt_at_index (mm->devices, pool_indices[i]);
568
569       /* Check dynamic ranges */
570       for (j = 0; j < vec_len (dp->ranges); j++)
571         {
572           clib_timebase_range_t *r = dp->ranges + j;
573           f64 start0, end0;
574
575           start0 = r->start + mm->sunday_midnight;
576           end0 = r->end + mm->sunday_midnight;
577           if (verbose > 1)
578             vlib_cli_output (vm, "  Range %d: %U - %U", j,
579                              format_clib_timebase_time, start0,
580                              format_clib_timebase_time, end0);
581
582           if (now >= start0 && now <= end0)
583             {
584               if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW)
585                 current_status = 3;
586               else if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA)
587                 current_status = 5;
588               else
589                 current_status = 2;
590               if (verbose)
591                 {
592                   vlib_cli_output (vm, "  Time in range %d:", j);
593                   vlib_cli_output (vm, "     %U - %U",
594                                    format_clib_timebase_time, start0,
595                                    format_clib_timebase_time, end0);
596                 }
597               goto print;
598             }
599         }
600       if (verbose && j)
601         vlib_cli_output (vm, "  No range match.");
602       if (dp->flags & MACTIME_DEVICE_FLAG_STATIC_DROP)
603         current_status = 0;
604       if (dp->flags & MACTIME_DEVICE_FLAG_STATIC_ALLOW)
605         current_status = 1;
606       if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW)
607         current_status = 2;
608       if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_DROP)
609         current_status = 3;
610       if (dp->flags & MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA)
611         current_status = 4;
612
613     print:
614       vec_reset_length (macstring);
615       macstring = format (0, "%U", format_mac_address, dp->mac_address);
616       switch (current_status)
617         {
618         case 0:
619           status_string = "static drop";
620           break;
621         case 1:
622           status_string = "static allow";
623           break;
624         case 2:
625           status_string = "dynamic drop";
626           break;
627         case 3:
628           status_string = "dynamic allow";
629           break;
630         case 4:
631           status_string = "d-quota inact";
632           break;
633         case 5:
634           status_string = "d-quota activ";
635           break;
636         default:
637           status_string = "code bug!";
638           break;
639         }
640       vlib_get_combined_counter (&mm->allow_counters, dp - mm->devices,
641                                  &allow);
642       vlib_get_combined_counter (&mm->drop_counters, dp - mm->devices, &drop);
643       vlib_cli_output (vm, "%-15s %18s %14s %10lld %U %13lld",
644                        dp->device_name, macstring, status_string,
645                        allow.packets, format_bytes_with_width, allow.bytes,
646                        10, drop.packets);
647       if (dp->data_quota > 0)
648         vlib_cli_output (vm, "%-54s %s%U %s%U", " ", "Quota ",
649                          format_bytes_with_width, dp->data_quota, 10,
650                          "Use ", format_bytes_with_width,
651                          dp->data_used_in_range, 8);
652       /* This is really only good for small N... */
653       for (j = 0; j < vec_len (mm->arp_cache_copy); j++)
654         {
655           n = mm->arp_cache_copy + j;
656           if (!memcmp (dp->mac_address, n->mac.bytes, sizeof (n->mac)))
657             {
658               vlib_cli_output (vm, "%17s%U", " ", format_ip4_address,
659                                &n->ip4_address);
660             }
661         }
662     }
663   vec_free (macstring);
664   vec_free (pool_indices);
665
666   return 0;
667 }
668
669 /* *INDENT-OFF* */
670 VLIB_CLI_COMMAND (show_mactime_command, static) =
671 {
672   .path = "show mactime",
673   .short_help = "show mactime [verbose]",
674   .function = show_mactime_command_fn,
675 };
676 /* *INDENT-ON* */
677
678 static clib_error_t *
679 clear_mactime_command_fn (vlib_main_t * vm,
680                           unformat_input_t * input, vlib_cli_command_t * cmd)
681 {
682   mactime_main_t *mm = &mactime_main;
683
684   if (mm->feature_initialized == 0)
685     return clib_error_return (0, "feature not enabled");
686
687   vlib_clear_combined_counters (&mm->allow_counters);
688   vlib_clear_combined_counters (&mm->drop_counters);
689   vlib_cli_output (vm, "Mactime counters cleared...");
690   return 0;
691 }
692
693 /* *INDENT-OFF* */
694 VLIB_CLI_COMMAND (clear_mactime_command, static) =
695 {
696   .path = "clear mactime",
697   .short_help = "clear mactime counters",
698   .function = clear_mactime_command_fn,
699 };
700 /* *INDENT-ON* */
701
702
703
704 /*
705  * fd.io coding-style-patch-verification: ON
706  *
707  * Local Variables:
708  * eval: (c-set-style "gnu")
709  * End:
710  */