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