FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
mactime.c
Go to the documentation of this file.
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
35 
37 
39 
40 /** \file mactime.c
41  * time-base src-mac filter device-input feature arc implementation
42  */
43 
44 static void
46 {
47  if (mm->feature_initialized == 0)
48  {
49  /* Create the lookup table */
50  clib_bihash_init_8_8 (&mm->lookup_table, "mactime lookup table",
55  &(mm->vlib_main->clib_time));
56  mm->allow_counters.name = "allow";
57  mm->allow_counters.stat_segment_name = "/mactime/allow";
58  mm->drop_counters.name = "drop";
59  mm->drop_counters.stat_segment_name = "/mactime/drop";
60  mm->feature_initialized = 1;
61  }
62 }
63 
64 /** Action function shared between message handler and debug CLI
65 */
66 int
68  int enable_disable)
69 {
71  int rv = 0;
72  static u8 url_init_done;
73 
74  feature_init (mm);
75 
76  /* Utterly wrong? */
78  sw_if_index))
79  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
80 
81  /* Not a physical port? */
84  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
85 
86  vnet_feature_enable_disable ("device-input", "mactime",
87  sw_if_index, enable_disable, 0, 0);
88  vnet_feature_enable_disable ("interface-output", "mactime-tx",
89  sw_if_index, enable_disable, 0, 0);
90  if (url_init_done == 0)
91  {
93  url_init_done = 1;
94  }
95 
96  return rv;
97 }
98 
99 static clib_error_t *
101  unformat_input_t * input,
102  vlib_cli_command_t * cmd)
103 {
105  u32 sw_if_index = ~0;
106  int enable_disable = 1;
107 
108  int rv;
109 
111  {
112  if (unformat (input, "disable"))
113  enable_disable = 0;
114  else if (unformat (input, "%U", unformat_vnet_sw_interface,
115  mm->vnet_main, &sw_if_index))
116  ;
117  else if (unformat (input, "sw_if_index %d", &sw_if_index))
118  ;
119  else
120  break;
121  }
122 
123  if (sw_if_index == ~0)
124  return clib_error_return (0, "Please specify an interface...");
125 
126  rv = mactime_enable_disable (mm, sw_if_index, enable_disable);
127 
128  switch (rv)
129  {
130  case 0:
131  break;
132 
133  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
134  return clib_error_return
135  (0, "Invalid interface, only works on physical ports");
136  break;
137 
138  default:
139  return clib_error_return (0, "mactime_enable_disable returned %d", rv);
140  }
141  return 0;
142 }
143 
144 /* *INDENT-OFF* */
146 {
147  .path = "mactime enable-disable",
148  .short_help =
149  "mactime enable-disable <interface-name> [disable]",
151 };
152 /* *INDENT-ON* */
153 
154 
155 /** Enable / disable time-base src mac filtration on an interface
156  */
157 
160 {
161  vl_api_mactime_enable_disable_reply_t *rmp;
163  int rv;
164 
166 
167  rv = mactime_enable_disable (mm, ntohl (mp->sw_if_index),
168  (int) (mp->enable_disable));
170  REPLY_MACRO (VL_API_MACTIME_ENABLE_DISABLE_REPLY);
171 }
172 
173 static void
175 {
178  mactime_device_t *dev;
181  int rv = 0, i;
182  u32 his_table_epoch = clib_net_to_host_u32 (mp->my_table_epoch);
183  u32 message_size;
184  u32 name_len;
185  u32 nranges;
186 
188  if (rp == 0)
189  return;
190 
191  if (his_table_epoch == mm->device_table_epoch)
192  {
193  rv = VNET_API_ERROR_NO_CHANGE;
194  goto send_reply;
195  }
196 
197  /* *INDENT-OFF* */
198  pool_foreach (dev, mm->devices)
199  {
200  message_size = sizeof(*ep) + vec_len(dev->device_name) +
201  vec_len(dev->ranges) * sizeof(ep->ranges[0]);
202 
203  ep = vl_msg_api_alloc (message_size);
204  memset (ep, 0, message_size);
205  ep->_vl_msg_id = clib_host_to_net_u16 (VL_API_MACTIME_DETAILS
206  + mm->msg_id_base);
207  ep->context = mp->context;
208  /* Index is the key for the stats segment combined counters */
209  ep->pool_index = clib_host_to_net_u32 (dev - mm->devices);
210 
211  clib_memcpy_fast (ep->mac_address, dev->mac_address,
212  sizeof (ep->mac_address));
213  ep->data_quota = clib_host_to_net_u64 (dev->data_quota);
214  ep->data_used_in_range = clib_host_to_net_u64 (dev->data_used_in_range);
215  ep->flags = clib_host_to_net_u32 (dev->flags);
216  nranges = vec_len (dev->ranges);
217  ep->nranges = clib_host_to_net_u32 (nranges);
218 
219  for (i = 0; i < vec_len (dev->ranges); i++)
220  {
221  ep->ranges[i].start = dev->ranges[i].start;
222  ep->ranges[i].end = dev->ranges[i].end;
223  }
224 
225  name_len = vec_len (dev->device_name);
226  name_len = (name_len < ARRAY_LEN(ep->device_name)) ?
227  name_len : ARRAY_LEN(ep->device_name) - 1;
228 
229  clib_memcpy_fast (ep->device_name, dev->device_name,
230  name_len);
231  ep->device_name [ARRAY_LEN(ep->device_name) -1] = 0;
232  vl_api_send_msg (rp, (u8 *)ep);
233  }
234  /* *INDENT-OFF* */
235 
236  send_reply:
237  /* *INDENT-OFF* */
238  REPLY_MACRO2 (VL_API_MACTIME_DUMP_REPLY,
239  ({
240  rmp->table_epoch = clib_host_to_net_u32 (mm->device_table_epoch);
241  }));
242  /* *INDENT-ON* */
243 }
244 
245 /** Create a lookup table entry for the indicated mac address
246  */
247 void
249 {
251  api_main_t *am;
252  vl_shmem_hdr_t *shmem_hdr;
253  u8 *name;
255 
256  am = vlibapi_get_main ();
257  shmem_hdr = am->shmem_hdr;
258  mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
259  clib_memset (mp, 0, sizeof (*mp));
260  mp->_vl_msg_id = ntohs (VL_API_MACTIME_ADD_DEL_RANGE + mm->msg_id_base);
261  name = format (0, "mac-%U", format_mac_address, mac_address);
262 
263  memcpy (mp->device_name, name, vec_len (name));
264  memcpy (mp->mac_address, mac_address, sizeof (mp->mac_address));
265  /* $$$ config: create allow / drop / range */
266  mp->allow = 1;
267  mp->is_add = 1;
268  vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp);
269 }
270 
271 /** Add or delete static / dynamic accept/drop configuration for a src mac
272  */
273 
276 {
278  vl_api_mactime_add_del_range_reply_t *rmp;
279  mactime_device_t *dp;
281  int found = 1;
282  clib_bihash_8_8_t *lut = &mm->lookup_table;
283  u64 data_quota;
284  int i, rv = 0;
285 
286  feature_init (mm);
287 
288  /*
289  * Change the table epoch. Skip 0 so clients can code my_table_epoch = 0
290  * to receive a full dump.
291  */
292  mm->device_table_epoch++;
293  if (PREDICT_FALSE (mm->device_table_epoch == 0))
294  mm->device_table_epoch++;
295 
296  data_quota = clib_net_to_host_u64 (mp->data_quota);
297 
298  clib_memset (&kv, 0, sizeof (kv));
299  memcpy (&kv.key, mp->mac_address, sizeof (mp->mac_address));
300 
301  /* See if we have a lookup table entry for this src mac address */
302  if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
303  found = 0;
304 
305  /* Add an entry? */
306  if (mp->is_add)
307  {
308  /* Create the device entry? */
309  if (found == 0)
310  {
311  pool_get (mm->devices, dp);
312  clib_memset (dp, 0, sizeof (*dp));
314  dp - mm->devices);
317  dp - mm->devices);
319  mp->device_name[ARRAY_LEN (mp->device_name) - 1] = 0;
320  dp->device_name = format (0, "%s%c", mp->device_name, 0);
321  memcpy (dp->mac_address, mp->mac_address, sizeof (mp->mac_address));
322  for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
323  {
324  clib_timebase_range_t _r, *r = &_r;
325  r->start = mp->ranges[i].start;
326  r->end = mp->ranges[i].end;
327  vec_add1 (dp->ranges, r[0]);
328  }
329  /* If we found some time ranges */
330  if (i)
331  {
332  /* Set allow/drop based on msg flags */
333  if (mp->drop)
335  if (mp->allow)
337  if (mp->allow_quota)
339  }
340  else
341  {
342  /* no ranges, it's a static allow/drop */
343  if (mp->drop)
345  if (mp->allow)
347  }
348  if (mp->no_udp_10001)
350 
351  dp->data_quota = data_quota;
352 
353  /* Add the hash table entry */
354  kv.value = dp - mm->devices;
355  clib_bihash_add_del_8_8 (lut, &kv, 1 /* is_add */ );
356  }
357  else /* add more ranges, flags, etc. */
358  {
359  dp = pool_elt_at_index (mm->devices, kv.value);
360 
361  for (i = 0; i < clib_net_to_host_u32 (mp->count); i++)
362  {
363  clib_timebase_range_t _r, *r = &_r;
364  r->start = mp->ranges[i].start;
365  r->end = mp->ranges[i].end;
366  vec_add1 (dp->ranges, r[0]);
367  }
368 
369  if (vec_len (dp->ranges))
370  {
371  /* Set allow/drop based on msg flags */
372  if (mp->drop)
374  if (mp->allow)
376  if (mp->allow_quota)
378  }
379  else
380  {
381  /* no ranges, it's a static allow/drop */
382  if (mp->drop)
384  if (mp->allow)
386  }
387  if (mp->no_udp_10001)
389 
390  dp->data_quota = data_quota;
391  }
392  }
393  else /* delete case */
394  {
395  if (found == 0)
396  {
397  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
398  goto reply;
399  }
400 
401  /* find the device entry */
402  dp = pool_elt_at_index (mm->devices, kv.value);
403 
404  /* Remove it from the lookup table */
405  clib_bihash_add_del_8_8 (lut, &kv, 0 /* is_add */ );
406  vec_free (dp->ranges);
407  pool_put (mm->devices, dp);
408  }
409 
410 reply:
411  REPLY_MACRO (VL_API_MACTIME_ADD_DEL_RANGE_REPLY);
412 }
413 
414 #include <mactime/mactime.api.c>
415 static clib_error_t *
417 {
419 
420  mm->vlib_main = vm;
421  mm->vnet_main = vnet_get_main ();
422 
423  /* Ask for a correctly-sized block of API message decode slots */
425 
428  mm->timezone_offset = -5; /* US EST / EDT */
429  return 0;
430 }
431 
432 /* *INDENT-OFF* */
434 {
435  .runs_after = VLIB_INITS("ip_neighbor_init"),
436 };
437 /* *INDENT-ON* */
438 
439 static clib_error_t *
441 {
443 
445  {
446  if (unformat (input, "lookup-table-buckets %u",
448  ;
449  else if (unformat (input, "lookup-table-memory %U",
451  ;
452  else if (unformat (input, "timezone_offset %d", &mm->timezone_offset))
453  ;
454  else
455  {
456  return clib_error_return (0, "unknown input '%U'",
457  format_unformat_error, input);
458  }
459  }
460  return 0;
461 }
462 
464 
465 /* *INDENT-OFF* */
466 VNET_FEATURE_INIT (mactime, static) =
467 {
468  .arc_name = "device-input",
469  .node_name = "mactime",
470  .runs_before = VNET_FEATURES ("ethernet-input"),
471 };
472 /* *INDENT-ON */
473 
474 /* *INDENT-OFF* */
475 VNET_FEATURE_INIT (mactime_tx, static) = {
476  .arc_name = "interface-output",
477  .node_name = "mactime-tx",
478  .runs_before = VNET_FEATURES ("interface-output-arc-end"),
479 };
480 /* *INDENT-ON */
481 
482 /* *INDENT-OFF* */
484 {
485  .version = VPP_BUILD_VER,
486  .description = "Time-based MAC Source Address Filter",
487 };
488 /* *INDENT-ON* */
489 
490 u8 *
491 format_bytes_with_width (u8 * s, va_list * va)
492 {
493  uword nbytes = va_arg (*va, u64);
494  int width = va_arg (*va, int);
495  f64 nbytes_f64;
496  u8 *fmt;
497  char *suffix = "";
498 
499  if (width > 0)
500  fmt = format (0, "%%%d.3f%%s%c", width, 0);
501  else
502  fmt = format (0, "%%.3f%%s%c", 0);
503 
504  if (nbytes > (1024ULL * 1024ULL * 1024ULL))
505  {
506  nbytes_f64 = ((f64) nbytes) / (1024.0 * 1024.0 * 1024.0);
507  suffix = "G";
508  }
509  else if (nbytes > (1024ULL * 1024ULL))
510  {
511  nbytes_f64 = ((f64) nbytes) / (1024.0 * 1024.0);
512  suffix = "M";
513  }
514  else if (nbytes > 1024ULL)
515  {
516  nbytes_f64 = ((f64) nbytes) / (1024.0);
517  suffix = "K";
518  }
519  else
520  {
521  nbytes_f64 = (f64) nbytes;
522  suffix = "B";
523  }
524 
525  s = format (s, (char *) fmt, nbytes_f64, suffix);
526  vec_free (fmt);
527  return s;
528 }
529 
530 static walk_rc_t
532 {
533  mactime_main_t *mm = ctx;
534 
535  vec_add1 (mm->arp_cache_copy, ipni);
536 
537  return (WALK_CONTINUE);
538 }
539 
540 static clib_error_t *
542  unformat_input_t * input, vlib_cli_command_t * cmd)
543 {
545  mactime_device_t *dp;
546  u8 *macstring = 0;
547  char *status_string;
548  u32 *pool_indices = 0;
549  int verbose = 0;
550  int current_status = 99;
551  int i, j;
552  f64 now;
553  vlib_counter_t allow, drop;
554  ip_neighbor_t *ipn;
555 
556  if (mm->feature_initialized == 0)
557  return clib_error_return
558  (0,
559  "Feature not initialized, suggest 'help mactime enable-disable'...");
560 
562  /* Walk all ip4 neighbours on all interfaces */
564 
565  now = clib_timebase_now (&mm->timebase);
566 
567  if (PREDICT_FALSE ((now - mm->sunday_midnight) > 86400.0 * 7.0))
569 
570  if (unformat (input, "verbose %d", &verbose))
571  ;
572 
573  if (unformat (input, "verbose"))
574  verbose = 1;
575 
576  if (verbose)
577  vlib_cli_output (vm, "Time now: %U", format_clib_timebase_time, now);
578 
579  /* *INDENT-OFF* */
580  pool_foreach (dp, mm->devices)
581  {
582  vec_add1 (pool_indices, dp - mm->devices);
583  }
584  /* *INDENT-ON* */
585 
586  vlib_cli_output (vm, "%-15s %18s %14s %10s %11s %13s",
587  "Device Name", "Addresses", "Status",
588  "AllowPkt", "AllowByte", "DropPkt");
589 
590  for (i = 0; i < vec_len (pool_indices); i++)
591  {
592  dp = pool_elt_at_index (mm->devices, pool_indices[i]);
593 
594  /* Check dynamic ranges */
595  for (j = 0; j < vec_len (dp->ranges); j++)
596  {
597  clib_timebase_range_t *r = dp->ranges + j;
598  f64 start0, end0;
599 
600  start0 = r->start + mm->sunday_midnight;
601  end0 = r->end + mm->sunday_midnight;
602  if (verbose > 1)
603  vlib_cli_output (vm, " Range %d: %U - %U", j,
606 
607  if (now >= start0 && now <= end0)
608  {
610  current_status = 3;
612  current_status = 5;
613  else
614  current_status = 2;
615  if (verbose)
616  {
617  vlib_cli_output (vm, " Time in range %d:", j);
618  vlib_cli_output (vm, " %U - %U",
621  }
622  goto print;
623  }
624  }
625  if (verbose && j)
626  vlib_cli_output (vm, " No range match.");
628  current_status = 0;
630  current_status = 1;
632  current_status = 2;
634  current_status = 3;
636  current_status = 4;
637 
638  print:
639  vec_reset_length (macstring);
640  macstring = format (0, "%U", format_mac_address, dp->mac_address);
641  switch (current_status)
642  {
643  case 0:
644  status_string = "static drop";
645  break;
646  case 1:
647  status_string = "static allow";
648  break;
649  case 2:
650  status_string = "dynamic drop";
651  break;
652  case 3:
653  status_string = "dynamic allow";
654  break;
655  case 4:
656  status_string = "d-quota inact";
657  break;
658  case 5:
659  status_string = "d-quota activ";
660  break;
661  default:
662  status_string = "code bug!";
663  break;
664  }
666  &allow);
667  vlib_get_combined_counter (&mm->drop_counters, dp - mm->devices, &drop);
668  vlib_cli_output (vm, "%-15s %18s %14s %10lld %U %13lld",
669  dp->device_name, macstring, status_string,
670  allow.packets, format_bytes_with_width, allow.bytes,
671  10, drop.packets);
672  if (dp->data_quota > 0)
673  vlib_cli_output (vm, "%-54s %s%U %s%U", " ", "Quota ",
675  "Use ", format_bytes_with_width,
676  dp->data_used_in_range, 8);
677  /* This is really only good for small N... */
678  for (j = 0; j < vec_len (mm->arp_cache_copy); j++)
679  {
680  ipn = ip_neighbor_get (mm->arp_cache_copy[j]);
681  if (!memcmp
682  (dp->mac_address, ipn->ipn_mac.bytes, sizeof (ipn->ipn_mac)))
683  {
684  vlib_cli_output (vm, "%17s%U", " ", format_ip46_address,
686  }
687  }
688  }
689  vec_free (macstring);
690  vec_free (pool_indices);
691 
692  return 0;
693 }
694 
695 /* *INDENT-OFF* */
697 {
698  .path = "show mactime",
699  .short_help = "show mactime [verbose]",
700  .function = show_mactime_command_fn,
701 };
702 /* *INDENT-ON* */
703 
704 static clib_error_t *
706  unformat_input_t * input, vlib_cli_command_t * cmd)
707 {
709 
710  if (mm->feature_initialized == 0)
711  return clib_error_return
712  (0,
713  "Feature not initialized, suggest 'help mactime enable-disable'...");
714 
717  vlib_cli_output (vm, "Mactime counters cleared...");
718  return 0;
719 }
720 
721 /* *INDENT-OFF* */
723 {
724  .path = "clear mactime",
725  .short_help = "clear mactime counters",
726  .function = clear_mactime_command_fn,
727 };
728 /* *INDENT-ON* */
729 
730 
731 
732 /*
733  * fd.io coding-style-patch-verification: ON
734  *
735  * Local Variables:
736  * eval: (c-set-style "gnu")
737  * End:
738  */
ip_neighbor_t_
A representation of an IP neighbour/peer.
Definition: ip_neighbor_types.h:59
mactime_main_t::vnet_main
vnet_main_t * vnet_main
Definition: mactime.h:78
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
clib_timebase_range_t::start
f64 start
Definition: time_range.h:51
mactime_main_t::timebase
clib_timebase_t timebase
Definition: mactime.h:49
vl_api_mactime_add_del_range_t::is_add
bool is_add
add=1, del=0
Definition: mactime.api:82
vl_api_mactime_add_del_range_t::device_name
string device_name[64]
device name
Definition: mactime.api:89
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
vl_api_mactime_add_del_range_t::no_udp_10001
bool no_udp_10001
drop udp to port 10001
Definition: mactime.api:86
api.h
MACTIME_DEVICE_FLAG_DYNAMIC_DROP
#define MACTIME_DEVICE_FLAG_DYNAMIC_DROP
Definition: mactime_device.h:40
mactime_main_t::timezone_offset
i32 timezone_offset
Definition: mactime.h:68
vl_api_mactime_details_t
mactime table entry details
Definition: mactime.api:125
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vnet_sw_interface_t::type
vnet_sw_interface_type_t type
Definition: interface.h:871
vnet_sw_interface_t
Definition: interface.h:869
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
mactime_main_t::device_table_epoch
u32 device_table_epoch
Definition: mactime.h:59
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
ip_neighbor_get_ip
const ip_address_t * ip_neighbor_get_ip(const ip_neighbor_t *ipn)
Definition: ip_neighbor.c:116
vlib_main_t::clib_time
clib_time_t clib_time
Definition: main.h:106
vl_api_mactime_dump_t::client_index
u32 client_index
client index, from api_main
Definition: mactime.api:117
vl_api_mactime_dump_t
dump mactime table
Definition: mactime.api:115
mactime_send_create_entry_message
void mactime_send_create_entry_message(u8 *mac_address)
Create a lookup table entry for the indicated mac address.
Definition: mactime.c:248
MACTIME_MEMORY_SIZE
#define MACTIME_MEMORY_SIZE
Definition: mactime.h:84
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_mactime_dump_t::my_table_epoch
u32 my_table_epoch
to suppress dump if no changes
Definition: mactime.api:119
show_mactime_command_fn
static clib_error_t * show_mactime_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: mactime.c:541
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
name
string name[64]
Definition: fib.api:25
VNET_FEATURE_INIT
VNET_FEATURE_INIT(mactime, static)
ip_neighbor_get
ip_neighbor_t * ip_neighbor_get(index_t ipni)
Definition: ip_neighbor.c:89
vlib_clear_combined_counters
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
Definition: counter.c:61
vl_api_mactime_add_del_range_t_handler
static void vl_api_mactime_add_del_range_t_handler(vl_api_mactime_add_del_range_t *mp)
Add or delete static / dynamic accept/drop configuration for a src mac.
Definition: mactime.c:275
vl_api_mactime_dump_t_handler
static void vl_api_mactime_dump_t_handler(vl_api_mactime_dump_t *mp)
Definition: mactime.c:174
MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA
Definition: mactime_device.h:42
mactime_device_t::device_name
u8 * device_name
Definition: mactime_device.h:27
vl_api_mactime_add_del_range_t::data_quota
u64 data_quota
max bytes this device
Definition: mactime.api:87
mactime_main_t::drop_counters
vlib_combined_counter_main_t drop_counters
Definition: mactime.h:63
MACTIME_DEVICE_FLAG_STATIC_DROP
#define MACTIME_DEVICE_FLAG_STATIC_DROP
Always drop packets from this device.
Definition: mactime_device.h:38
vl_api_mactime_enable_disable_t::enable_disable
bool enable_disable
enable=1, disable=0
Definition: mactime.api:32
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
clib_bihash_kv_8_8_t::value
u64 value
the value
Definition: bihash_8_8.h:44
IP46_TYPE_IP4
@ IP46_TYPE_IP4
Definition: ip46_address.h:26
vlib_cli_command_t::path
char * path
Definition: cli.h:96
clib_bihash_kv_8_8_t::key
u64 key
the key
Definition: bihash_8_8.h:43
mactime_device_t::mac_address
u8 mac_address[6]
Definition: mactime_device.h:28
MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW
Definition: mactime_device.h:41
mactime_enable_disable
int mactime_enable_disable(mactime_main_t *mm, u32 sw_if_index, int enable_disable)
Action function shared between message handler and debug CLI.
Definition: mactime.c:67
am
app_main_t * am
Definition: application.c:489
vlib_validate_combined_counter
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:119
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vl_api_mactime_add_del_range_t::drop
bool drop
drop flag
Definition: mactime.api:83
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vl_api_mactime_add_del_range_t::allow
bool allow
allow flag
Definition: mactime.api:84
AF_IP4
@ AF_IP4
Definition: ip_types.h:23
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
vlib_combined_counter_main_t::name
char * name
The counter collection's name.
Definition: counter.h:206
mactime_main_t::msg_id_base
u16 msg_id_base
Definition: mactime.h:46
clib_timebase_range_t
Definition: time_range.h:49
unformat_input_t
struct _unformat_input_t unformat_input_t
mactime_enable_disable_command_fn
static clib_error_t * mactime_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: mactime.c:100
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
vl_shmem_hdr_
Definition: memory_shared.h:76
vl_msg_api_alloc_as_if_client
void * vl_msg_api_alloc_as_if_client(int nbytes)
Definition: memory_shared.c:236
vl_api_mactime_dump_reply_t::table_epoch
u32 table_epoch
Definition: mactime.api:145
mactime_enable_disable_command
static vlib_cli_command_t mactime_enable_disable_command
(constructor) VLIB_CLI_COMMAND (mactime_enable_disable_command)
Definition: mactime.c:145
format_mac_address
u8 * format_mac_address(u8 *s, va_list *args)
Definition: format.c:58
VLIB_CONFIG_FUNCTION
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:181
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
format_clib_timebase_time
format_function_t format_clib_timebase_time
Definition: time_range.h:70
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
clear_mactime_command_fn
static clib_error_t * clear_mactime_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: mactime.c:705
mactime_device_t
Definition: mactime_device.h:25
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
vl_api_mactime_dump_t::context
u32 context
application context
Definition: mactime.api:118
unformat_memory_size
unformat_function_t unformat_memory_size
Definition: format.h:288
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vl_api_mactime_enable_disable_t
api to enable or disable the time-based src mac filter on an interface
Definition: mactime.api:28
mactime.h
mactime_main_t::lookup_table_num_buckets
u32 lookup_table_num_buckets
Definition: mactime.h:66
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vlib_counter_t
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
vlib_config_function_runtime_t
Definition: init.h:68
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
vl_api_mactime_add_del_range_t::allow_quota
u8 allow_quota
allow subject to quota
Definition: mactime.api:85
mactime_device_t::ranges
clib_timebase_range_t * ranges
Definition: mactime_device.h:34
mactime_main_t::sunday_midnight
f64 sunday_midnight
Definition: mactime.h:52
vl_api_mactime_enable_disable_t::sw_if_index
vl_api_interface_index_t sw_if_index
the interface handle
Definition: mactime.api:33
print
static unsigned char * print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
Definition: cJSON.c:1183
mactime_config
static clib_error_t * mactime_config(vlib_main_t *vm, unformat_input_t *input)
Definition: mactime.c:440
vl_shmem_hdr_::vl_input_queue
svm_queue_t * vl_input_queue
Definition: memory_shared.h:84
uword
u64 uword
Definition: types.h:112
vlib_zero_combined_counter
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
Definition: counter.h:298
mactime_main_t::vlib_main
vlib_main_t * vlib_main
Definition: mactime.h:77
vlibapi_get_main
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:390
ip_neighbor_walk
void ip_neighbor_walk(ip_address_family_t af, u32 sw_if_index, ip_neighbor_walk_cb_t cb, void *ctx)
Definition: ip_neighbor.c:1046
vl_api_mactime_add_del_range_t
configure per src-mac time ranges
Definition: mactime.api:78
f64
double f64
Definition: types.h:142
mactime_main_t::allow_counters
vlib_combined_counter_main_t allow_counters
Definition: mactime.h:62
mactime_init
static clib_error_t * mactime_init(vlib_main_t *vm)
Definition: mactime.c:416
clib_timebase_init
__clib_export void clib_timebase_init(clib_timebase_t *tb, i32 timezone_offset_in_hours, clib_timebase_daylight_time_t daylight_type, clib_time_t *clib_time)
Definition: time_range.c:19
show_mactime_command
static vlib_cli_command_t show_mactime_command
(constructor) VLIB_CLI_COMMAND (show_mactime_command)
Definition: mactime.c:696
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
mac_address_t_::bytes
u8 bytes[6]
Definition: mac_address.h:25
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vl_api_mactime_add_del_range_t::count
u32 count
number of time ranges to follow
Definition: mactime.api:90
mactime_device_t::data_used_in_range
u64 data_used_in_range
Definition: mactime_device.h:30
mactime_device_t::flags
u32 flags
Definition: mactime_device.h:31
vlib_counter_t::packets
counter_t packets
packet counter
Definition: counter_types.h:28
fmt
int cJSON_bool fmt
Definition: cJSON.h:160
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
vnet_interface_main_t::sw_interfaces
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:1015
mactime_main_t::lookup_table_memory_size
uword lookup_table_memory_size
Definition: mactime.h:67
mactime_main_t::devices
mactime_device_t * devices
Definition: mactime.h:58
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
plugin.h
vl_api_mactime_details_t::ranges
vl_api_mactime_time_range_t ranges[nranges]
Definition: mactime.api:135
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
format_bytes_with_width
u8 * format_bytes_with_width(u8 *s, va_list *va)
Definition: mactime.c:491
vlib_get_combined_counter
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:272
vl_api_mactime_add_del_range_t::ranges
vl_api_time_range_t ranges[count]
time ranges, in seconds since Sunday began
Definition: mactime.api:92
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
ip_neighbor.h
mactime_url_init
void mactime_url_init(vlib_main_t *vm)
Definition: builtins.c:158
format_fns.h
u64
unsigned long u64
Definition: types.h:89
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
format
description fragment has unexpected format
Definition: map.api:433
format_ip46_address
format_function_t format_ip46_address
Definition: ip46_address.h:50
mactime_main
mactime_main_t mactime_main
Definition: mactime.c:38
clib_timebase_range_t::end
f64 end
Definition: time_range.h:51
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
clib_timebase_now
static f64 clib_timebase_now(clib_timebase_t *tb)
Definition: time_range.h:88
vlib_counter_t::bytes
counter_t bytes
byte counter
Definition: counter_types.h:29
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
api_helper_macros.h
vlib_combined_counter_main_t::stat_segment_name
char * stat_segment_name
Name in stat segment directory.
Definition: counter.h:207
clib_bihash_kv_8_8_t
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:41
mactime_main_t
Definition: mactime.h:43
mactime_ip_neighbor_copy
static walk_rc_t mactime_ip_neighbor_copy(index_t ipni, void *ctx)
Definition: mactime.c:531
vl_api_mactime_add_del_range_t::mac_address
vl_api_mac_address_t mac_address
src mac address
Definition: mactime.api:88
CLIB_TIMEBASE_DAYLIGHT_USA
@ CLIB_TIMEBASE_DAYLIGHT_USA
Definition: time_range.h:25
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
clear_mactime_command
static vlib_cli_command_t clear_mactime_command
(constructor) VLIB_CLI_COMMAND (clear_mactime_command)
Definition: mactime.c:722
MACTIME_DEVICE_FLAG_STATIC_ALLOW
#define MACTIME_DEVICE_FLAG_STATIC_ALLOW
Definition: mactime_device.h:39
now
f64 now
Definition: nat44_ei_out2in.c:710
mactime_main_t::arp_cache_copy
index_t * arp_cache_copy
Definition: mactime.h:74
MACTIME_NUM_BUCKETS
#define MACTIME_NUM_BUCKETS
Definition: mactime.h:83
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
VLIB_INITS
#define VLIB_INITS(...)
Definition: init.h:352
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_msg_api_send_shmem
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
Definition: memory_shared.c:753
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
i
int i
Definition: flowhash_template.h:376
vl_api_mactime_enable_disable_t_handler
static void vl_api_mactime_enable_disable_t_handler(vl_api_mactime_enable_disable_t *mp)
Enable / disable time-base src mac filtration on an interface.
Definition: mactime.c:159
rv
int __clib_unused rv
Definition: application.c:491
mactime_main_t::lookup_table
clib_bihash_8_8_t lookup_table
Definition: mactime.h:55
vnet.h
VNET_SW_INTERFACE_TYPE_HARDWARE
@ VNET_SW_INTERFACE_TYPE_HARDWARE
Definition: interface.h:764
vlib_cli_command_t
Definition: cli.h:92
clib_timebase_find_sunday_midnight
__clib_export f64 clib_timebase_find_sunday_midnight(f64 start_time)
Definition: time_range.c:221
feature_init
static void feature_init(mactime_main_t *mm)
Definition: mactime.c:45
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
mactime_device_t::data_quota
u64 data_quota
Definition: mactime_device.h:29
ip_neighbor_t_::ipn_mac
mac_address_t ipn_mac
The learned MAC address of the neighbour.
Definition: ip_neighbor_types.h:69
vl_api_mactime_dump_reply_t
dump mactime table reply Includes the vpp table epoch, needed to optimize API traffic
Definition: mactime.api:141
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
mactime_main_t::feature_initialized
int feature_initialized
Definition: mactime.h:71
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
MACTIME_DEVICE_FLAG_DROP_UDP_10001
#define MACTIME_DEVICE_FLAG_DROP_UDP_10001
Definition: mactime_device.h:43
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
mac_address
manual_print typedef u8 mac_address[6]
Definition: ethernet_types.api:19