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