FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
interface_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * interface_api.c - vnet interface api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/ethernet/ethernet.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/fib/fib_table.h>
28 #include <vnet/mfib/mfib_table.h>
29 #include <vnet/l2/l2_vtr.h>
30 #include <vnet/vnet_msg_enum.h>
31 #include <vnet/fib/fib_api.h>
32 #include <vnet/mfib/mfib_table.h>
33 
34 #include <vlibapi/api_types.h>
35 
36 #include <vnet/ip/ip_types_api.h>
38 
39 #define vl_typedefs /* define message structures */
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_typedefs
42 
43 #define vl_endianfun /* define message structures */
44 #include <vnet/vnet_all_api_h.h>
45 #undef vl_endianfun
46 
47 /* instantiate all the print functions we know about */
48 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
49 #define vl_printfun
50 #include <vnet/vnet_all_api_h.h>
51 #undef vl_printfun
52 
55 
56 #define foreach_vpe_api_msg \
57 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
58 _(HW_INTERFACE_SET_MTU, hw_interface_set_mtu) \
59 _(SW_INTERFACE_SET_MTU, sw_interface_set_mtu) \
60 _(WANT_INTERFACE_EVENTS, want_interface_events) \
61 _(SW_INTERFACE_DUMP, sw_interface_dump) \
62 _(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address) \
63 _(SW_INTERFACE_SET_RX_MODE, sw_interface_set_rx_mode) \
64 _(SW_INTERFACE_RX_PLACEMENT_DUMP, sw_interface_rx_placement_dump) \
65 _(SW_INTERFACE_SET_RX_PLACEMENT, sw_interface_set_rx_placement) \
66 _(SW_INTERFACE_SET_TABLE, sw_interface_set_table) \
67 _(SW_INTERFACE_GET_TABLE, sw_interface_get_table) \
68 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \
69 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats) \
70 _(SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del) \
71 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS, sw_interface_add_del_mac_address) \
72 _(SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address) \
73 _(SW_INTERFACE_GET_MAC_ADDRESS, sw_interface_get_mac_address) \
74 _(CREATE_VLAN_SUBIF, create_vlan_subif) \
75 _(CREATE_SUBIF, create_subif) \
76 _(DELETE_SUBIF, delete_subif) \
77 _(CREATE_LOOPBACK, create_loopback) \
78 _(CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \
79 _(DELETE_LOOPBACK, delete_loopback) \
80 _(INTERFACE_NAME_RENUMBER, interface_name_renumber) \
81 _(COLLECT_DETAILED_INTERFACE_STATS, collect_detailed_interface_stats) \
82 _(SW_INTERFACE_SET_IP_DIRECTED_BROADCAST, \
83  sw_interface_set_ip_directed_broadcast)
84 
85 static void
87 {
88  vl_api_sw_interface_set_flags_reply_t *rmp;
89  vnet_main_t *vnm = vnet_get_main ();
90  int rv = 0;
91  clib_error_t *error;
92  u16 flags;
93 
95 
96  flags =
97  ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
99 
100  error = vnet_sw_interface_set_flags (vnm, ntohl (mp->sw_if_index), flags);
101  if (error)
102  {
103  rv = -1;
104  clib_error_report (error);
105  }
106 
108  REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
109 }
110 
111 static void
113 {
114  vl_api_hw_interface_set_mtu_reply_t *rmp;
115  vnet_main_t *vnm = vnet_get_main ();
116  u32 sw_if_index = ntohl (mp->sw_if_index);
117  u16 mtu = ntohs (mp->mtu);
119  int rv = 0;
120 
122 
123  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
125  {
126  rv = VNET_API_ERROR_INVALID_VALUE;
127  goto bad_sw_if_index;
128  }
129 
132 
133  if (!eif)
134  {
135  rv = VNET_API_ERROR_FEATURE_DISABLED;
136  goto bad_sw_if_index;
137  }
138 
139  if (mtu < hi->min_supported_packet_bytes)
140  {
141  rv = VNET_API_ERROR_INVALID_VALUE;
142  goto bad_sw_if_index;
143  }
144 
145  if (mtu > hi->max_supported_packet_bytes)
146  {
147  rv = VNET_API_ERROR_INVALID_VALUE;
148  goto bad_sw_if_index;
149  }
150 
151  vnet_hw_interface_set_mtu (vnm, si->hw_if_index, mtu);
152 
154  REPLY_MACRO (VL_API_HW_INTERFACE_SET_MTU_REPLY);
155 }
156 
157 static void
159 {
160  vl_api_sw_interface_set_mtu_reply_t *rmp;
161  vnet_main_t *vnm = vnet_get_main ();
162  u32 sw_if_index = ntohl (mp->sw_if_index);
163  int rv = 0;
164  int i;
165  u32 per_protocol_mtu[VNET_N_MTU];
166 
168 
169  for (i = 0; i < VNET_N_MTU; i++)
170  {
171  per_protocol_mtu[i] = ntohl (mp->mtu[i]);
172  clib_warning ("MTU %u", per_protocol_mtu[i]);
173  }
174  vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, per_protocol_mtu);
175 
177  REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY);
178 }
179 
180 static void
183 {
184  vl_api_sw_interface_set_ip_directed_broadcast_reply_t *rmp;
185  u32 sw_if_index = ntohl (mp->sw_if_index);
186  int rv = 0;
187 
189 
191  sw_if_index, mp->enable);
192 
194  REPLY_MACRO (VL_API_SW_INTERFACE_SET_IP_DIRECTED_BROADCAST_REPLY);
195 }
196 
197 static void
200  vnet_sw_interface_t * swif,
201  u8 * interface_name, u32 context)
202 {
205  vnet_device_class_t *dev_class =
207 
208  vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
209  clib_memset (mp, 0, sizeof (*mp));
210  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
211  mp->sw_if_index = ntohl (swif->sw_if_index);
212  mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
213 
214  mp->flags |= (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
218  mp->flags = ntohl (mp->flags);
219 
220  switch (swif->type)
221  {
223  mp->type = IF_API_TYPE_SUB;
224  break;
226  mp->type = IF_API_TYPE_P2P;
227  break;
229  mp->type = IF_API_TYPE_PIPE;
230  break;
231  default:
233  }
234  mp->type = ntohl (mp->type);
235 
238  mp->link_speed = ntohl (hi->link_speed);
239  mp->link_mtu = ntohs (hi->max_packet_bytes);
240  mp->mtu[VNET_MTU_L3] = ntohl (swif->mtu[VNET_MTU_L3]);
241  mp->mtu[VNET_MTU_IP4] = ntohl (swif->mtu[VNET_MTU_IP4]);
242  mp->mtu[VNET_MTU_IP6] = ntohl (swif->mtu[VNET_MTU_IP6]);
243  mp->mtu[VNET_MTU_MPLS] = ntohl (swif->mtu[VNET_MTU_MPLS]);
244 
245  mp->context = context;
246 
247  strncpy ((char *) mp->interface_name,
248  (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
249 
250  if (dev_class && dev_class->name)
251  strncpy ((char *) mp->interface_dev_type, (char *) dev_class->name,
252  ARRAY_LEN (mp->interface_dev_type) - 1);
253 
254  /* Send the L2 address for ethernet physical intfcs */
255  if (swif->sup_sw_if_index == swif->sw_if_index
257  {
260 
261  ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
262  ASSERT (sizeof (mp->l2_address) >= sizeof (ei->address));
264  }
265  else if (swif->sup_sw_if_index != swif->sw_if_index)
266  {
267  vnet_sub_interface_t *sub = &swif->sub;
268  mp->sub_id = ntohl (sub->id);
269  mp->sub_number_of_tags =
270  sub->eth.flags.one_tag + sub->eth.flags.two_tags * 2;
271  mp->sub_outer_vlan_id = ntohs (sub->eth.outer_vlan_id);
272  mp->sub_inner_vlan_id = ntohs (sub->eth.inner_vlan_id);
273  mp->sub_if_flags =
274  ntohl (sub->eth.raw_flags & SUB_IF_API_FLAG_MASK_VNET);
275  }
276 
277  /* vlan tag rewrite data */
278  u32 vtr_op = L2_VTR_DISABLED;
279  u32 vtr_push_dot1q = 0, vtr_tag1 = 0, vtr_tag2 = 0;
280 
281  if (l2vtr_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
282  &vtr_op, &vtr_push_dot1q, &vtr_tag1, &vtr_tag2) != 0)
283  {
284  // error - default to disabled
285  mp->vtr_op = ntohl (L2_VTR_DISABLED);
286  clib_warning ("cannot get vlan tag rewrite for sw_if_index %d",
287  swif->sw_if_index);
288  }
289  else
290  {
291  mp->vtr_op = ntohl (vtr_op);
292  mp->vtr_push_dot1q = ntohl (vtr_push_dot1q);
293  mp->vtr_tag1 = ntohl (vtr_tag1);
294  mp->vtr_tag2 = ntohl (vtr_tag2);
295  }
296 
297  /* pbb tag rewrite data */
298  ethernet_header_t eth_hdr;
299  u32 pbb_vtr_op = L2_VTR_DISABLED;
300  u16 outer_tag = 0;
301  u16 b_vlanid = 0;
302  u32 i_sid = 0;
303  clib_memset (&eth_hdr, 0, sizeof (eth_hdr));
304 
305  if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index,
306  &pbb_vtr_op, &outer_tag, &eth_hdr, &b_vlanid, &i_sid))
307  {
308  mp->sub_if_flags |= ntohl (SUB_IF_API_FLAG_DOT1AH);
311  mp->b_vlanid = b_vlanid;
312  mp->i_sid = i_sid;
313  }
314 
316  if (tag)
317  strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
318 
319  vl_api_send_msg (rp, (u8 *) mp);
320 }
321 
322 static void
324 {
326  vnet_sw_interface_t *swif;
330 
332 
333  if (rp == 0)
334  {
335  clib_warning ("Client %d AWOL", mp->client_index);
336  return;
337  }
338 
339  u8 *filter = 0, *name = 0;
340  sw_if_index = ntohl (mp->sw_if_index);
341 
342  if (!mp->name_filter_valid && sw_if_index != ~0 && sw_if_index != 0)
343  {
344  /* is it a valid sw_if_index? */
345  if (!vnet_sw_if_index_is_api_valid (sw_if_index))
346  return;
347 
348  swif = vec_elt_at_index (im->sw_interfaces, sw_if_index);
349 
351  name =
353  swif, 0);
354  send_sw_interface_details (am, rp, swif, name, mp->context);
355  vec_free (name);
356  return;
357  }
358 
359  if (mp->name_filter_valid)
360  {
361  filter = vl_api_from_api_to_vec (&mp->name_filter);
362  vec_add1 (filter, 0); /* Ensure it's a C string for strcasecmp() */
363  }
364 
365  char *strcasestr (char *, char *); /* lnx hdr file botch */
366  /* *INDENT-OFF* */
367  pool_foreach (swif, im->sw_interfaces,
368  ({
369  if (!vnet_swif_is_api_visible (swif))
370  continue;
371  vec_reset_length(name);
372  name = format (name, "%U%c", format_vnet_sw_interface_name, am->vnet_main,
373  swif, 0);
374 
375  if (filter && !strcasestr((char *) name, (char *) filter))
376  continue;
377 
378  send_sw_interface_details (am, rp, swif, name, mp->context);
379  }));
380  /* *INDENT-ON* */
381 
382  vec_free (name);
383  vec_free (filter);
384 }
385 
386 static void
389 {
390  vlib_main_t *vm = vlib_get_main ();
391  vnet_main_t *vnm = vnet_get_main ();
392  vl_api_sw_interface_add_del_address_reply_t *rmp;
393  int rv = 0;
394  u32 is_del;
395  clib_error_t *error = 0;
396  ip46_address_t address;
397 
399 
400  is_del = mp->is_add == 0;
401  vnm->api_errno = 0;
402 
403  if (mp->del_all)
405  else if (ip_address_decode (&mp->prefix.address, &address) == IP46_TYPE_IP6)
406  error = ip6_add_del_interface_address (vm, ntohl (mp->sw_if_index),
407  (void *) &address.ip6,
408  mp->prefix.len, is_del);
409  else
410  error = ip4_add_del_interface_address (vm, ntohl (mp->sw_if_index),
411  (void *) &address.ip4,
412  mp->prefix.len, is_del);
413 
414  if (error)
415  {
416  rv = vnm->api_errno;
417  clib_error_report (error);
418  goto done;
419  }
420 
422 
423 done:
424  REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_ADDRESS_REPLY);
425 }
426 
427 static void
429 {
430  vl_api_sw_interface_set_table_reply_t *rmp;
431  u32 sw_if_index = ntohl (mp->sw_if_index);
432  u32 table_id = ntohl (mp->vrf_id);
433  int rv = 0;
434 
436 
437  if (mp->is_ipv6)
438  rv = ip_table_bind (FIB_PROTOCOL_IP6, sw_if_index, table_id, 1);
439  else
440  rv = ip_table_bind (FIB_PROTOCOL_IP4, sw_if_index, table_id, 1);
441 
443 
444  REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY);
445 }
446 
447 int
449  u32 sw_if_index, u32 table_id, u8 is_api)
450 {
452  u32 fib_index, mfib_index;
454  mfib_source_t msrc;
455 
456  if (is_api)
457  {
458  src = FIB_SOURCE_API;
459  msrc = MFIB_SOURCE_API;
460  }
461  else
462  {
463  src = FIB_SOURCE_CLI;
464  msrc = MFIB_SOURCE_CLI;
465  }
466 
467  /*
468  * This if table does not exist = error is what we want in the end.
469  */
470  fib_index = fib_table_find (fproto, table_id);
471  mfib_index = mfib_table_find (fproto, table_id);
472 
473  if (~0 == fib_index || ~0 == mfib_index)
474  {
475  return (VNET_API_ERROR_NO_SUCH_FIB);
476  }
477 
478  if (FIB_PROTOCOL_IP6 == fproto)
479  {
480  /*
481  * If the interface already has in IP address, then a change int
482  * VRF is not allowed. The IP address applied must first be removed.
483  * We do not do that automatically here, since VPP has no knowledge
484  * of whether those subnets are valid in the destination VRF.
485  */
486  /* *INDENT-OFF* */
488  ia, sw_if_index,
489  1 /* honor unnumbered */ ,
490  ({
491  return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE);
492  }));
493  /* *INDENT-ON* */
494 
497 
498  /*
499  * tell those that are interested that the binding is changing.
500  */
503  cb->function (&ip6_main, cb->function_opaque,
504  sw_if_index,
505  fib_index,
506  ip6_main.fib_index_by_sw_if_index[sw_if_index]);
507 
508  if (0 == table_id)
509  {
510  /* reset back to default */
511  if (0 != ip6_main.fib_index_by_sw_if_index[sw_if_index])
513  FIB_PROTOCOL_IP6, src);
514  if (0 != ip6_main.mfib_index_by_sw_if_index[sw_if_index])
516  [sw_if_index], FIB_PROTOCOL_IP6, msrc);
517 
518  }
519  else
520  {
521  /* we need to lock the table now it's inuse */
522  fib_table_lock (fib_index, FIB_PROTOCOL_IP6, src);
523  mfib_table_lock (mfib_index, FIB_PROTOCOL_IP6, msrc);
524  }
525 
528  }
529  else
530  {
531  /*
532  * If the interface already has in IP address, then a change int
533  * VRF is not allowed. The IP address applied must first be removed.
534  * We do not do that automatically here, since VPP has no knowledge
535  * of whether those subnets are valid in the destination VRF.
536  */
537  /* *INDENT-OFF* */
539  ia, sw_if_index,
540  1 /* honor unnumbered */ ,
541  ({
542  return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE);
543  }));
544  /* *INDENT-ON* */
545 
548 
549  /*
550  * tell those that are interested that the binding is changing.
551  */
554  cb->function (&ip4_main, cb->function_opaque,
555  sw_if_index,
556  fib_index,
557  ip4_main.fib_index_by_sw_if_index[sw_if_index]);
558 
559  if (0 == table_id)
560  {
561  /* reset back to default */
562  if (0 != ip4_main.fib_index_by_sw_if_index[sw_if_index])
564  FIB_PROTOCOL_IP4, src);
565  if (0 != ip4_main.mfib_index_by_sw_if_index[sw_if_index])
567  [sw_if_index], FIB_PROTOCOL_IP4, msrc);
568 
569  }
570  else
571  {
572  /* we need to lock the table now it's inuse */
574  table_id, src);
575 
577  table_id, msrc);
578  }
579 
582  }
583 
584  return (0);
585 }
586 
587 static void
589  u32 context, int retval, u32 vrf_id)
590 {
592 
593  mp = vl_msg_api_alloc (sizeof (*mp));
594  clib_memset (mp, 0, sizeof (*mp));
595  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_GET_TABLE_REPLY);
596  mp->context = context;
597  mp->retval = htonl (retval);
598  mp->vrf_id = htonl (vrf_id);
599 
600  vl_api_send_msg (reg, (u8 *) mp);
601 }
602 
603 static void
605 {
607  fib_table_t *fib_table = 0;
608  u32 sw_if_index = ~0;
609  u32 fib_index = ~0;
610  u32 table_id = ~0;
611  fib_protocol_t fib_proto = FIB_PROTOCOL_IP4;
612  int rv = 0;
613 
615  if (!reg)
616  return;
617 
619 
620  sw_if_index = ntohl (mp->sw_if_index);
621 
622  if (mp->is_ipv6)
623  fib_proto = FIB_PROTOCOL_IP6;
624 
625  fib_index = fib_table_get_index_for_sw_if_index (fib_proto, sw_if_index);
626  if (fib_index != ~0)
627  {
628  fib_table = fib_table_get (fib_index, fib_proto);
629  table_id = fib_table->ft_table_id;
630  }
631 
633 
634  send_sw_interface_get_table_reply (reg, mp->context, rv, table_id);
635 }
636 
639 {
640  vl_api_sw_interface_set_unnumbered_reply_t *rmp;
641  int rv = 0;
642  vnet_main_t *vnm = vnet_get_main ();
643  u32 sw_if_index = ntohl (mp->sw_if_index);
644  u32 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
645 
646  /*
647  * The API message field names are backwards from
648  * the underlying data structure names.
649  * It's not worth changing them now.
650  */
651  if (!vnet_sw_interface_is_api_valid (vnm, unnumbered_sw_if_index))
652  {
653  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
654  goto done;
655  }
656 
657  /* Only check the "use loop0" field when setting the binding */
658  if (mp->is_add && !vnet_sw_interface_is_api_valid (vnm, sw_if_index))
659  {
660  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
661  goto done;
662  }
663 
664  vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
665  sw_if_index, mp->is_add);
666 done:
667  REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
668 }
669 
670 static void
672  mp)
673 {
674  vl_api_sw_interface_clear_stats_reply_t *rmp;
675 
676  vnet_main_t *vnm = vnet_get_main ();
680  int j, n_counters;
681  int rv = 0;
682 
683  if (mp->sw_if_index != ~0)
685 
686  n_counters = vec_len (im->combined_sw_if_counters);
687 
688  for (j = 0; j < n_counters; j++)
689  {
690  im = &vnm->interface_main;
691  cm = im->combined_sw_if_counters + j;
692  if (mp->sw_if_index == (u32) ~ 0)
694  else
695  vlib_zero_combined_counter (cm, ntohl (mp->sw_if_index));
696  }
697 
698  n_counters = vec_len (im->sw_if_counters);
699 
700  for (j = 0; j < n_counters; j++)
701  {
702  im = &vnm->interface_main;
703  sm = im->sw_if_counters + j;
704  if (mp->sw_if_index == (u32) ~ 0)
706  else
707  vlib_zero_simple_counter (sm, ntohl (mp->sw_if_index));
708  }
709 
711 
712  REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
713 }
714 
715 /*
716  * Events used for sw_interface_events
717  */
719 {
726 };
727 
728 static void
731  vl_api_registration_t * vl_reg,
732  u32 sw_if_index, enum api_events events)
733 {
735 
736  mp = vl_msg_api_alloc (sizeof (*mp));
737  clib_memset (mp, 0, sizeof (*mp));
738  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
739  mp->sw_if_index = ntohl (sw_if_index);
740  mp->client_index = reg->client_index;
741  mp->pid = reg->client_pid;
742  mp->flags = 0;
743  mp->flags |= (events & API_ADMIN_UP_EVENT) ?
745  mp->flags |= (events & API_LINK_STATE_UP_EVENT) ?
747  mp->flags = ntohl (mp->flags);
748  mp->deleted = events & API_SW_INTERFACE_DEL_EVENT ? true : false;
749  vl_api_send_msg (vl_reg, (u8 *) mp);
750 }
751 
752 static uword
755 {
757  uword *event_by_sw_if_index = 0;
759  int i;
760  vl_api_registration_t *vl_reg;
761  uword event_type;
762  uword *event_data = 0;
764 
765  vam->link_state_process_up = 1;
766 
767  while (1)
768  {
770 
771  /* Batch up events */
772  while ((event_type = vlib_process_get_events (vm, &event_data)) != ~0)
773  {
774  for (i = 0; i < vec_len (event_data); i++)
775  {
776  sw_if_index = event_data[i];
777  vec_validate_init_empty (event_by_sw_if_index, sw_if_index, 0);
778  event_by_sw_if_index[sw_if_index] |= event_type;
779  }
780  vec_reset_length (event_data);
781  }
782 
783  for (i = 0; i < vec_len (event_by_sw_if_index); i++)
784  {
785  if (event_by_sw_if_index[i] == 0)
786  continue;
787 
788  /* *INDENT-OFF* */
789  pool_foreach(reg, vam->interface_events_registrations,
790  ({
791  vl_reg = vl_api_client_index_to_registration (reg->client_index);
792  if (vl_reg)
793  send_sw_interface_event (vam, reg, vl_reg, i, event_by_sw_if_index[i]);
794  }));
795  /* *INDENT-ON* */
796  }
797  vec_reset_length (event_by_sw_if_index);
798  }
799 
800  return 0;
801 }
802 
803 static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
804  u32 flags);
806  u32 hw_if_index, u32 flags);
808  u32 sw_if_index,
809  u32 flags);
810 
811 /* *INDENT-OFF* */
812 VLIB_REGISTER_NODE (link_state_process_node,static) = {
813  .function = link_state_process,
814  .type = VLIB_NODE_TYPE_PROCESS,
815  .name = "vpe-link-state-process",
816 };
817 /* *INDENT-ON* */
818 
819 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
820 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
821 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (sw_interface_add_del_function);
822 
823 static clib_error_t *
824 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
825 {
827  vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
828 
829  if (vam->link_state_process_up)
830  {
831  enum api_events event = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ?
835  link_state_process_node.index, event,
836  hi->sw_if_index);
837  }
838  return 0;
839 }
840 
841 static clib_error_t *
842 admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
843 {
845 
846  /*
847  * Note: it's perfectly fair to set a subif admin up / admin down.
848  * Note the subtle distinction between this routine and the previous
849  * routine.
850  */
851  if (vam->link_state_process_up)
852  {
853  enum api_events event = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
856  link_state_process_node.index, event,
857  sw_if_index);
858  }
859  return 0;
860 }
861 
862 static clib_error_t *
864 {
866 
867  if (vam->link_state_process_up)
868  {
869  enum api_events event =
872  link_state_process_node.index, event,
873  sw_if_index);
874  }
875  return 0;
876 }
877 
880 {
881  vnet_main_t *vnm = vnet_get_main ();
882  vl_api_sw_interface_tag_add_del_reply_t *rmp;
883  int rv = 0;
884  u8 *tag;
885  u32 sw_if_index = ntohl (mp->sw_if_index);
886 
888 
889  if (mp->is_add)
890  {
891  if (mp->tag[0] == 0)
892  {
893  rv = VNET_API_ERROR_INVALID_VALUE;
894  goto out;
895  }
896 
897  mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
898  tag = format (0, "%s%c", mp->tag, 0);
899  vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
900  }
901  else
902  vnet_clear_sw_interface_tag (vnm, sw_if_index);
903 
905 out:
906  REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY);
907 }
908 
911 {
912  vl_api_sw_interface_add_del_mac_address_reply_t *rmp;
913  vnet_main_t *vnm = vnet_get_main ();
914  u32 sw_if_index = ntohl (mp->sw_if_index);
916  clib_error_t *error;
917  int rv = 0;
918 
920 
921  /* for subifs, the MAC should be changed on the actual hw if */
922  hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
924  mp->addr, mp->is_add);
925  if (error)
926  {
927  rv = VNET_API_ERROR_UNIMPLEMENTED;
928  clib_error_report (error);
929  goto out;
930  }
931 
933 out:
934  REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY);
935 }
936 
939 {
940  vl_api_sw_interface_set_mac_address_reply_t *rmp;
941  vnet_main_t *vnm = vnet_get_main ();
942  u32 sw_if_index = ntohl (mp->sw_if_index);
944  clib_error_t *error;
945  int rv = 0;
947 
949 
950  si = vnet_get_sw_interface (vnm, sw_if_index);
951  mac_address_decode (mp->mac_address, &mac);
952  error =
954  if (error)
955  {
956  rv = VNET_API_ERROR_UNIMPLEMENTED;
957  clib_error_report (error);
958  goto out;
959  }
960 
962 out:
963  REPLY_MACRO (VL_API_SW_INTERFACE_SET_MAC_ADDRESS_REPLY);
964 }
965 
968 {
971  vnet_main_t *vnm = vnet_get_main ();
972  u32 sw_if_index = ntohl (mp->sw_if_index);
974  ethernet_interface_t *eth_if = 0;
975  int rv = 0;
976 
978 
979  si = vnet_get_sup_sw_interface (vnm, sw_if_index);
982 
984 
986  if (!reg)
987  return;
988  rmp = vl_msg_api_alloc (sizeof (*rmp));
989  rmp->_vl_msg_id = htons (VL_API_SW_INTERFACE_GET_MAC_ADDRESS_REPLY);
990  rmp->context = mp->context;
991  rmp->retval = htonl (rv);
992  if (!rv && eth_if)
994  vl_api_send_msg (reg, (u8 *) rmp);
995 }
996 
999 {
1000  vl_api_sw_interface_set_rx_mode_reply_t *rmp;
1001  vnet_main_t *vnm = vnet_get_main ();
1002  u32 sw_if_index = ntohl (mp->sw_if_index);
1003  vnet_sw_interface_t *si;
1004  clib_error_t *error;
1005  int rv = 0;
1007 
1008  VALIDATE_SW_IF_INDEX (mp);
1009 
1010  si = vnet_get_sw_interface (vnm, sw_if_index);
1012  {
1013  rv = VNET_API_ERROR_INVALID_VALUE;
1014  goto bad_sw_if_index;
1015  }
1016 
1017  rx_mode = (vnet_hw_interface_rx_mode) ntohl (mp->mode);
1018  error = set_hw_interface_change_rx_mode (vnm, si->hw_if_index,
1019  mp->queue_id_valid,
1020  ntohl (mp->queue_id),
1022  rx_mode);
1023 
1024  if (error)
1025  {
1026  rv = VNET_API_ERROR_UNIMPLEMENTED;
1027  clib_error_report (error);
1028  goto out;
1029  }
1030 
1032 out:
1033  REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_MODE_REPLY);
1034 }
1035 
1036 static void
1038  vl_api_registration_t * rp,
1039  u32 sw_if_index, u32 worker_id,
1040  u32 queue_id, u8 mode, u32 context)
1041 {
1043  mp = vl_msg_api_alloc (sizeof (*mp));
1044  clib_memset (mp, 0, sizeof (*mp));
1045 
1046  mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_RX_PLACEMENT_DETAILS);
1047  mp->sw_if_index = htonl (sw_if_index);
1048  mp->queue_id = htonl (queue_id);
1049  mp->worker_id = htonl (worker_id);
1050  mp->mode = htonl (mode);
1051  mp->context = context;
1052 
1053  vl_api_send_msg (rp, (u8 *) mp);
1054 }
1055 
1058 {
1059  vnet_main_t *vnm = vnet_get_main ();
1061  u32 sw_if_index = ntohl (mp->sw_if_index);
1062  vl_api_registration_t *reg;
1063 
1065  if (!reg)
1066  return;
1067 
1068  if (sw_if_index == ~0)
1069  {
1073  (u8 *) "device-input");
1074  uword si;
1075  int index = 0;
1076 
1077  /* *INDENT-OFF* */
1078  foreach_vlib_main (({
1080  ({
1081  rt = vlib_node_get_runtime_data (this_vlib_main, si);
1082  vec_foreach (dq, rt->devices_and_queues)
1083  {
1084  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm,
1085  dq->hw_if_index);
1086  send_interface_rx_placement_details (am, reg, hw->sw_if_index, index,
1087  dq->queue_id, dq->mode, mp->context);
1088  }
1089  }));
1090  index++;
1091  }));
1092  /* *INDENT-ON* */
1093  }
1094  else
1095  {
1096  int i;
1097  vnet_sw_interface_t *si;
1098 
1099  if (!vnet_sw_if_index_is_api_valid (sw_if_index))
1100  {
1101  clib_warning ("sw_if_index %u does not exist", sw_if_index);
1102  goto bad_sw_if_index;
1103  }
1104 
1105  si = vnet_get_sw_interface (vnm, sw_if_index);
1107  {
1108  clib_warning ("interface type is not HARDWARE! P2P, PIPE and SUB"
1109  " interfaces are not supported");
1110  goto bad_sw_if_index;
1111  }
1112 
1114 
1115  for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1116  {
1119  [i], i,
1120  hw->rx_mode_by_queue[i],
1121  mp->context);
1122  }
1123  }
1124 
1126 }
1127 
1130 {
1131  vl_api_sw_interface_set_rx_placement_reply_t *rmp;
1132  vnet_main_t *vnm = vnet_get_main ();
1133  u32 sw_if_index = ntohl (mp->sw_if_index);
1134  vnet_sw_interface_t *si;
1135  clib_error_t *error = 0;
1136  int rv = 0;
1137 
1138  VALIDATE_SW_IF_INDEX (mp);
1139 
1140  si = vnet_get_sw_interface (vnm, sw_if_index);
1142  {
1143  rv = VNET_API_ERROR_INVALID_VALUE;
1144  goto bad_sw_if_index;
1145  }
1146 
1148  ntohl (mp->queue_id),
1149  ntohl (mp->worker_id), mp->is_main);
1150  if (error)
1151  {
1152  rv = VNET_API_ERROR_UNIMPLEMENTED;
1153  clib_error_report (error);
1154  goto out;
1155  }
1156 
1158 out:
1159  REPLY_MACRO (VL_API_SW_INTERFACE_SET_RX_PLACEMENT_REPLY);
1160 }
1161 
1162 static void
1164 {
1166  vnet_main_t *vnm = vnet_get_main ();
1167  u32 sw_if_index = (u32) ~ 0;
1169  int rv = 0;
1170  u32 id;
1171  vnet_sw_interface_t template;
1172  uword *p;
1174  u64 sup_and_sub_key;
1175  vl_api_registration_t *reg;
1176  clib_error_t *error;
1177 
1178  VALIDATE_SW_IF_INDEX (mp);
1179 
1180  hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1181 
1183  {
1184  rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1185  goto out;
1186  }
1187 
1188  id = ntohl (mp->vlan_id);
1189  if (id == 0 || id > 4095)
1190  {
1191  rv = VNET_API_ERROR_INVALID_VLAN;
1192  goto out;
1193  }
1194 
1195  sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
1196 
1197  p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1198  if (p)
1199  {
1200  rv = VNET_API_ERROR_VLAN_ALREADY_EXISTS;
1201  goto out;
1202  }
1203 
1204  clib_memset (&template, 0, sizeof (template));
1205  template.type = VNET_SW_INTERFACE_TYPE_SUB;
1206  template.flood_class = VNET_FLOOD_CLASS_NORMAL;
1207  template.sup_sw_if_index = hi->sw_if_index;
1208  template.sub.id = id;
1209  template.sub.eth.raw_flags = 0;
1210  template.sub.eth.flags.one_tag = 1;
1211  template.sub.eth.outer_vlan_id = id;
1212  template.sub.eth.flags.exact_match = 1;
1213 
1214  error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
1215  if (error)
1216  {
1217  clib_error_report (error);
1218  rv = VNET_API_ERROR_INVALID_REGISTRATION;
1219  goto out;
1220  }
1221 
1222  u64 *kp = clib_mem_alloc (sizeof (*kp));
1223  *kp = sup_and_sub_key;
1224 
1225  hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
1226  hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
1227 
1229 
1230 out:
1232  if (!reg)
1233  return;
1234 
1235  rmp = vl_msg_api_alloc (sizeof (*rmp));
1236  rmp->_vl_msg_id = htons (VL_API_CREATE_VLAN_SUBIF_REPLY);
1237  rmp->context = mp->context;
1238  rmp->retval = htonl (rv);
1239  rmp->sw_if_index = htonl (sw_if_index);
1240  vl_api_send_msg (reg, (u8 *) rmp);
1241 }
1242 
1243 static void
1245 {
1247  vnet_main_t *vnm = vnet_get_main ();
1248  u32 sub_sw_if_index = ~0;
1250  int rv = 0;
1251 
1252  VALIDATE_SW_IF_INDEX (mp);
1253 
1254  hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
1255 
1257  rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
1258  else
1259  rv = vnet_create_sub_interface (ntohl (mp->sw_if_index),
1260  ntohl (mp->sub_id),
1261  ntohl (mp->sub_if_flags),
1262  ntohs (mp->inner_vlan_id),
1263  ntohs (mp->outer_vlan_id),
1264  &sub_sw_if_index);
1265 
1267 
1268  /* *INDENT-OFF* */
1269  REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
1270  ({
1271  rmp->sw_if_index = ntohl(sub_sw_if_index);
1272  }));
1273  /* *INDENT-ON* */
1274 }
1275 
1276 static void
1278 {
1279  vl_api_delete_subif_reply_t *rmp;
1280  int rv;
1281 
1282  rv = vnet_delete_sub_interface (ntohl (mp->sw_if_index));
1283 
1284  REPLY_MACRO (VL_API_DELETE_SUBIF_REPLY);
1285 }
1286 
1287 static void
1289  mp)
1290 {
1291  vl_api_interface_name_renumber_reply_t *rmp;
1292  int rv = 0;
1293 
1294  VALIDATE_SW_IF_INDEX (mp);
1295 
1297  (ntohl (mp->sw_if_index), ntohl (mp->new_show_dev_instance));
1298 
1300 
1301  REPLY_MACRO (VL_API_INTERFACE_NAME_RENUMBER_REPLY);
1302 }
1303 
1304 static void
1306 {
1308  u32 sw_if_index;
1309  int rv;
1311 
1312  mac_address_decode (mp->mac_address, &mac);
1313  rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac, 0, 0);
1314 
1315  /* *INDENT-OFF* */
1316  REPLY_MACRO2(VL_API_CREATE_LOOPBACK_REPLY,
1317  ({
1318  rmp->sw_if_index = ntohl (sw_if_index);
1319  }));
1320  /* *INDENT-ON* */
1321 }
1322 
1325 {
1327  u32 sw_if_index;
1328  u8 is_specified = mp->is_specified;
1329  u32 user_instance = ntohl (mp->user_instance);
1330  int rv;
1332 
1333  mac_address_decode (mp->mac_address, &mac);
1334  rv = vnet_create_loopback_interface (&sw_if_index, (u8 *) & mac,
1335  is_specified, user_instance);
1336 
1337  /* *INDENT-OFF* */
1338  REPLY_MACRO2(VL_API_CREATE_LOOPBACK_INSTANCE_REPLY,
1339  ({
1340  rmp->sw_if_index = ntohl (sw_if_index);
1341  }));
1342  /* *INDENT-ON* */
1343 }
1344 
1345 static void
1347 {
1348  vl_api_delete_loopback_reply_t *rmp;
1349  u32 sw_if_index;
1350  int rv;
1351 
1352  sw_if_index = ntohl (mp->sw_if_index);
1353  rv = vnet_delete_loopback_interface (sw_if_index);
1354 
1355  REPLY_MACRO (VL_API_DELETE_LOOPBACK_REPLY);
1356 }
1357 
1358 static void
1361 {
1362  vl_api_collect_detailed_interface_stats_reply_t *rmp;
1363  int rv = 0;
1364 
1365  rv =
1367  mp->enable_disable);
1368 
1369  REPLY_MACRO (VL_API_COLLECT_DETAILED_INTERFACE_STATS_REPLY);
1370 }
1371 
1372 /*
1373  * vpe_api_hookup
1374  * Add vpe's API message handlers to the table.
1375  * vlib has already mapped shared memory and
1376  * added the client registration handlers.
1377  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1378  */
1379 #define vl_msg_name_crc_list
1380 #include <vnet/interface.api.h>
1381 #undef vl_msg_name_crc_list
1382 
1383 static void
1385 {
1386 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1387  foreach_vl_msg_name_crc_interface;
1388 #undef _
1389 }
1390 
1391 pub_sub_handler (interface_events, INTERFACE_EVENTS);
1392 
1393 static clib_error_t *
1395 {
1396  api_main_t *am = vlibapi_get_main ();
1397 
1398 #define _(N,n) \
1399  vl_msg_api_set_handlers(VL_API_##N, #n, \
1400  vl_api_##n##_t_handler, \
1401  vl_noop_handler, \
1402  vl_api_##n##_t_endian, \
1403  vl_api_##n##_t_print, \
1404  sizeof(vl_api_##n##_t), 1);
1406 #undef _
1407 
1408  /* Mark these APIs as mp safe */
1409  am->is_mp_safe[VL_API_SW_INTERFACE_DUMP] = 1;
1410  am->is_mp_safe[VL_API_SW_INTERFACE_DETAILS] = 1;
1411  am->is_mp_safe[VL_API_SW_INTERFACE_TAG_ADD_DEL] = 1;
1412 
1413  /* Do not replay VL_API_SW_INTERFACE_DUMP messages */
1414  am->api_trace_cfg[VL_API_SW_INTERFACE_DUMP].replay_enable = 0;
1415 
1416  /*
1417  * Set up the (msg_name, crc, message-id) table
1418  */
1420 
1421  return 0;
1422 }
1423 
1425 
1426 /*
1427  * fd.io coding-style-patch-verification: ON
1428  *
1429  * Local Variables:
1430  * eval: (c-set-style "gnu")
1431  * End:
1432  */
static void vl_api_delete_subif_t_handler(vl_api_delete_subif_t *mp)
uword * sibling_bitmap
Definition: node.h:341
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:440
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: lookup.h:213
vl_api_interface_index_t sw_if_index
Definition: interface.api:91
enum fib_source_t_ fib_source_t
The different sources that can create a route.
u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, mfib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: mfib_table.c:613
#define hash_set(h, key, value)
Definition: hash.h:255
ip4_table_bind_function_t * function
Definition: ip4.h:92
vnet_main_t * vnet_main
#define CLIB_UNUSED(x)
Definition: clib.h:82
Enable or disable detailed interface stats.
Definition: interface.api:584
clib_error_t * set_hw_interface_rx_placement(u32 hw_if_index, u32 queue_id, u32 thread_index, u8 is_main)
void vnet_sw_interface_ip_directed_broadcast(vnet_main_t *vnm, u32 sw_if_index, u8 enable)
Definition: interface.c:697
vl_api_if_status_flags_t flags
Definition: interface.api:149
vl_api_mac_address_t mac
Definition: l2.api:491
Get interface&#39;s MAC address.
Definition: interface.api:350
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:593
u32 * mfib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip6.h:198
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static void vl_api_interface_name_renumber_t_handler(vl_api_interface_name_renumber_t *mp)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
vl_api_interface_index_t unnumbered_sw_if_index
Definition: interface.api:283
VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION(link_up_down_function)
ethernet_main_t * ethernet_get_main(vlib_main_t *vm)
Definition: init.c:120
void mac_address_encode(const mac_address_t *in, u8 *out)
static clib_error_t * sw_interface_add_del_function(vnet_main_t *vm, u32 sw_if_index, u32 flags)
Set flags on the interface.
Definition: interface.api:35
vnet_interface_main_t interface_main
Definition: vnet.h:56
static void vl_api_sw_interface_add_del_address_t_handler(vl_api_sw_interface_add_del_address_t *mp)
vl_api_interface_index_t sw_if_index
Definition: interface.api:354
vl_api_interface_index_t sw_if_index
Definition: interface.api:420
unsigned long u64
Definition: types.h:89
#define REPLY_MACRO2(t, body)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
ethernet_interface_t * interfaces
Definition: ethernet.h:286
u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
Definition: fib_table.c:989
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
u8 src_address[6]
Definition: packet.h:56
Set an interface&#39;s rx-placement Rx-Queue placement on specific thread is operational for only hardwar...
Definition: interface.api:400
u32 * input_node_thread_index_by_queue
Definition: interface.h:588
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static void vl_api_delete_loopback_t_handler(vl_api_delete_loopback_t *mp)
vl_api_interface_index_t sw_if_index
Definition: interface.api:461
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
int vnet_interface_name_renumber(u32 sw_if_index, u32 new_show_dev_instance)
Definition: interface.c:1385
static void vnet_clear_sw_interface_tag(vnet_main_t *vnm, u32 sw_if_index)
static void send_sw_interface_event(vpe_api_main_t *am, vpe_client_registration_t *reg, vl_api_registration_t *vl_reg, u32 sw_if_index, enum api_events events)
vl_api_address_t src
Definition: gre.api:60
int i
VLIB_API_INIT_FUNCTION(interface_api_hookup)
vl_api_mac_address_t mac_address
Definition: interface.api:548
#define hash_set_mem(h, key, value)
Definition: hash.h:275
ip_lookup_main_t lookup_main
Definition: ip4.h:107
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
uword * sub_interface_sw_if_index_by_id
Definition: interface.h:571
vlib_main_t * vlib_main
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:121
Set IP4 directed broadcast The directed broadcast enabled a packet sent to the interface&#39;s subnet add...
Definition: interface.api:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static void vl_api_sw_interface_set_unnumbered_t_handler(vl_api_sw_interface_set_unnumbered_t *mp)
static void vl_api_sw_interface_set_rx_placement_t_handler(vl_api_sw_interface_set_rx_placement_t *mp)
vpe_api_main_t vpe_api_main
Definition: interface_api.c:54
struct _vnet_device_class vnet_device_class_t
uword * dq_runtime_index_by_queue
Definition: interface.h:595
void * vl_msg_api_alloc(int nbytes)
static void vl_api_sw_interface_dump_t_handler(vl_api_sw_interface_dump_t *mp)
unsigned char u8
Definition: types.h:56
trace_cfg_t * api_trace_cfg
Current trace configuration.
Definition: api_common.h:272
static void send_interface_rx_placement_details(vpe_api_main_t *am, vl_api_registration_t *rp, u32 sw_if_index, u32 worker_id, u32 queue_id, u8 mode, u32 context)
#define VNET_HW_INTERFACE_FLAG_DUPLEX_MASK
Definition: interface.h:510
static clib_error_t * interface_api_hookup(vlib_main_t *vm)
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u8 id[64]
Definition: dhcp.api:160
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static uword link_state_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
vl_api_mac_address_t mac_address
Definition: interface.api:522
vl_api_mac_address_t b_dmac
Definition: interface.api:183
int ip_table_bind(fib_protocol_t fproto, u32 sw_if_index, u32 table_id, u8 is_api)
vl_api_interface_index_t sw_if_index
Definition: interface.api:62
enum mfib_source_t_ mfib_source_t
Possible [control plane] sources of MFIB entries.
ethernet_main_t ethernet_main
Definition: init.c:45
vl_api_interface_index_t sw_if_index
Definition: interface.api:510
vnet_hw_interface_rx_mode
Definition: interface.h:53
u32 * mfib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:124
Set an interface&#39;s rx-mode.
Definition: interface.api:379
u8 * vl_api_from_api_to_vec(vl_api_string_t *astr)
Definition: api_shared.c:1137
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
Definition: counter.c:61
Clear interface statistics.
Definition: interface.api:292
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:498
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:516
vl_api_address_with_prefix_t prefix
Definition: interface.api:228
static vnet_device_class_t * vnet_get_device_class(vnet_main_t *vnm, u32 dev_class_index)
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:863
u8 dst_address[6]
Definition: packet.h:55
Reply for the vlan subinterface create request.
Definition: interface.api:495
vnet_hw_interface_flags_t flags
Definition: interface.h:523
vl_api_interface_index_t sw_if_index
Definition: interface.api:574
static void vl_api_sw_interface_rx_placement_dump_t_handler(vl_api_sw_interface_rx_placement_dump_t *mp)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static void vl_api_hw_interface_set_mtu_t_handler(vl_api_hw_interface_set_mtu_t *mp)
Get VRF id assigned to interface.
Definition: interface.api:252
int vnet_create_sub_interface(u32 sw_if_index, u32 id, u32 flags, u16 inner_vlan_id, u16 outer_vlan_id, u32 *sub_sw_if_index)
Definition: interface.c:1017
u32 mtu[VNET_N_MTU]
Definition: interface.h:737
unsigned int u32
Definition: types.h:88
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1097
A collection of simple counters.
Definition: counter.h:57
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Definition: ip_types_api.c:161
vl_api_interface_index_t sw_if_index
Definition: interface.api:341
vl_api_gre_tunnel_mode_t mode
Definition: gre.api:55
void vnet_sw_interface_set_protocol_mtu(vnet_main_t *vnm, u32 sw_if_index, u32 mtu[])
Definition: interface.c:676
vl_api_if_status_flags_t flags
Definition: interface.api:92
vl_api_mac_address_t b_smac
Definition: interface.api:184
u32 max_supported_packet_bytes
Definition: interface.h:562
clib_error_t * ip4_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 is_del)
Definition: ip4_forward.c:794
vnet_api_error_t api_errno
Definition: vnet.h:78
static clib_error_t * link_up_down_function(vnet_main_t *vm, u32 hw_if_index, u32 flags)
vnet_crypto_main_t * cm
Definition: quic_crypto.c:41
struct vnet_sub_interface_t::@286::@287::@289 flags
format_function_t format_vnet_sw_interface_name
#define VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT
Definition: interface.h:508
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:519
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:285
vnet_sub_interface_t sub
Definition: interface.h:740
static void vl_api_sw_interface_get_table_t_handler(vl_api_sw_interface_get_table_t *mp)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
void mfib_table_unlock(u32 fib_index, fib_protocol_t proto, mfib_source_t source)
Take a reference counting lock on the table.
Definition: mfib_table.c:777
vl_api_interface_index_t sw_if_index
Definition: interface.api:383
static void send_sw_interface_get_table_reply(vl_api_registration_t *reg, u32 context, int retval, u32 vrf_id)
Set interface L3 MTU.
Definition: interface.api:58
vl_api_interface_index_t sw_if_index
Definition: interface.api:296
int replay_enable
This message can be replayed.
Definition: api_common.h:84
unsigned short u16
Definition: types.h:57
vl_api_interface_index_t sw_if_index
Definition: interface.api:282
uword * sw_if_index_by_sup_and_sub
Definition: interface.h:857
static void vl_api_sw_interface_set_mac_address_t_handler(vl_api_sw_interface_set_mac_address_t *mp)
ip6_table_bind_callback_t * table_bind_callbacks
Functions to call when interface to table biding changes.
Definition: ip6.h:219
Reply to get_sw_interface_vrf.
Definition: interface.api:264
#define REPLY_MACRO(t)
vnet_sw_interface_flags_t flags
Definition: interface.h:720
clib_error_t * set_hw_interface_change_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u8 queue_id_valid, u32 queue_id, vnet_hw_interface_rx_mode mode)
static void vl_api_create_loopback_t_handler(vl_api_create_loopback_t *mp)
ip6_main_t ip6_main
Definition: ip6_forward.c:2703
Create loopback interface instance response.
Definition: interface.api:558
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:862
void mfib_table_lock(u32 fib_index, fib_protocol_t proto, mfib_source_t source)
Release a reference counting lock on the table.
Definition: mfib_table.c:806
void vnet_sw_interface_update_unnumbered(u32 unnumbered_sw_if_index, u32 ip_sw_if_index, u8 enable)
Definition: interface.c:1547
void ip_del_all_interface_addresses(vlib_main_t *vm, u32 sw_if_index)
Definition: ip46_cli.c:82
struct vnet_sub_interface_t::@286 eth
#define foreach_vlib_main(body)
Definition: threads.h:241
Set or delete one or all ip addresses on a specified interface.
Definition: interface.api:220
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1291
vl_api_interface_index_t sw_if_index
Definition: interface.api:242
vnet_hw_interface_class_t ethernet_hw_interface_class
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:225
static void setup_message_id_table(api_main_t *am)
vl_api_interface_index_t sw_if_index
Definition: interface.api:486
int vnet_create_loopback_interface(u32 *sw_if_indexp, u8 *mac_address, u8 is_specified, u32 user_instance)
Definition: interface.c:789
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
#define VNET_HW_INTERFACE_BOND_INFO_SLAVE
Definition: interface.h:582
#define BAD_SW_IF_INDEX_LABEL
vl_api_mac_address_t l2_address
Definition: interface.api:147
static uword vnet_sw_if_index_is_api_valid(u32 sw_if_index)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
vl_api_interface_index_t sw_if_index[default=0xFFFFFFFF]
Definition: interface.api:207
u32 flags
Definition: vhost_user.h:141
From the CLI.
Definition: fib_source.h:76
static void vl_api_sw_interface_set_flags_t_handler(vl_api_sw_interface_set_flags_t *mp)
Definition: interface_api.c:86
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
show the interface&#39;s queue - thread placement This api is used to display the interface and queue wor...
Definition: interface.api:438
int vnet_delete_sub_interface(u32 sw_if_index)
Definition: interface.c:1059
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:342
int vnet_delete_loopback_interface(u32 sw_if_index)
Definition: interface.c:997
static clib_error_t * admin_up_down_function(vnet_main_t *vm, u32 hw_if_index, u32 flags)
vl_api_interface_index_t sw_if_index
Definition: interface.api:53
#define clib_warning(format, args...)
Definition: error.h:59
static void vl_api_sw_interface_add_del_mac_address_t_handler(vl_api_sw_interface_add_del_mac_address_t *mp)
Request all or filtered subset of sw_interface_details.
Definition: interface.api:203
static void vl_api_create_loopback_instance_t_handler(vl_api_create_loopback_instance_t *mp)
Delete sub interface request.
Definition: interface.api:507
#define ARRAY_LEN(x)
Definition: clib.h:62
static void send_sw_interface_details(vpe_api_main_t *am, vl_api_registration_t *rp, vnet_sw_interface_t *swif, u8 *interface_name, u32 context)
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
vl_api_link_duplex_t link_duplex
Definition: interface.api:154
string name[64]
Definition: ip.api:44
#define foreach_vpe_api_msg
Definition: interface_api.c:56
Delete loopback interface request.
Definition: interface.api:570
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(admin_up_down_function)
void fib_table_lock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Release a reference counting lock on the table.
Definition: fib_table.c:1310
foreach_registration_hash u8 link_state_process_up
vl_api_interface_index_t sw_if_index
Definition: interface.api:534
#define ASSERT(truth)
vl_api_interface_index_t sw_if_index
Definition: interface.api:442
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(sw_interface_add_del_function)
manual_print typedef address
Definition: ip_types.api:84
Reply for get interface&#39;s MAC address request.
Definition: interface.api:362
ip_lookup_main_t lookup_main
Definition: ip6.h:180
static void vnet_set_sw_interface_tag(vnet_main_t *vnm, u8 *tag, u32 sw_if_index)
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1156
From the control plane API.
Definition: fib_source.h:72
static void vl_api_sw_interface_tag_add_del_t_handler(vl_api_sw_interface_tag_add_del_t *mp)
#define clib_error_report(e)
Definition: error.h:113
vl_api_interface_index_t sw_if_index
Definition: interface.api:256
vl_api_interface_index_t sw_if_index
Definition: interface.api:404
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
Definition: counter.h:139
static u8 * vnet_get_sw_interface_tag(vnet_main_t *vnm, u32 sw_if_index)
vl_api_interface_index_t sw_if_index
Definition: interface.api:453
static void vl_api_sw_interface_clear_stats_t_handler(vl_api_sw_interface_clear_stats_t *mp)
static void * clib_mem_alloc(uword size)
Definition: mem.h:153
vl_api_interface_index_t sw_if_index
Definition: interface.api:473
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
vl_api_ip4_address_t hi
Definition: arp.api:37
Interface Event generated by want_interface_events.
Definition: interface.api:87
static void vl_api_sw_interface_set_mtu_t_handler(vl_api_sw_interface_set_mtu_t *mp)
ip4_table_bind_callback_t * table_bind_callbacks
Functions to call when interface to table biding changes.
Definition: ip4.h:146
vl_api_interface_index_t sw_if_index
Definition: interface.api:39
static uword vnet_sw_interface_is_api_valid(vnet_main_t *vnm, u32 sw_if_index)
static void vl_api_sw_interface_set_rx_mode_t_handler(vl_api_sw_interface_set_rx_mode_t *mp)
void vnet_hw_interface_set_mtu(vnet_main_t *vnm, u32 hw_if_index, u32 mtu)
Definition: interface.c:724
vl_api_sub_if_flags_t sub_if_flags
Definition: interface.api:464
static void vl_api_create_subif_t_handler(vl_api_create_subif_t *mp)
Create loopback interface instance request.
Definition: interface.api:544
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
Definition: interface.c:940
api_events
vl_api_interface_index_t sw_if_index
Definition: interface.api:588
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vl_api_sub_if_flags_t sub_if_flags
Definition: interface.api:173
Set interface physical MTU.
Definition: interface.api:49
u32 mfib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: mfib_table.c:555
u64 uword
Definition: types.h:112
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:854
Create loopback interface request.
Definition: interface.api:518
ip6_table_bind_function_t * function
Definition: ip6.h:115
Set unnumbered interface add / del request.
Definition: interface.api:278
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
Definition: fib_table.c:29
vl_api_interface_index_t sw_if_index
Definition: interface.api:224
A collection of combined counters.
Definition: counter.h:188
Create a new subinterface with the given vlan id.
Definition: interface.api:482
int vnet_sw_interface_stats_collect_enable_disable(u32 sw_if_index, u8 enable)
Create loopback interface response.
Definition: interface.api:530
#define hash_get_mem(h, key)
Definition: hash.h:269
static void vl_api_sw_interface_set_ip_directed_broadcast_t_handler(vl_api_sw_interface_set_ip_directed_broadcast_t *mp)
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:378
dump the rx queue placement of interface(s)
Definition: interface.api:416
u32 l2vtr_get(vlib_main_t *vlib_main, vnet_main_t *vnet_main, u32 sw_if_index, u32 *vtr_op, u32 *push_dot1q, u32 *vtr_tag1, u32 *vtr_tag2)
Get vtag tag rewrite on the given interface.
Definition: l2_vtr.c:347
vl_api_interface_index_t sw_if_index
Definition: interface.api:140
Set an interface&#39;s MAC address.
Definition: interface.api:337
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:248
void vlib_clear_simple_counters(vlib_simple_counter_main_t *cm)
Clear a collection of simple counters.
Definition: counter.c:44
vnet_sw_interface_type_t type
Definition: interface.h:718
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1079
vl_api_if_status_flags_t flags
Definition: interface.api:40
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, vnet_sw_interface_flags_t flags)
Definition: interface.c:501
pub_sub_handler(interface_events, INTERFACE_EVENTS)
#define vec_foreach(var, vec)
Vector iterator.
static void vl_api_create_vlan_subif_t_handler(vl_api_create_vlan_subif_t *mp)
static void vl_api_collect_detailed_interface_stats_t_handler(vl_api_collect_detailed_interface_stats_t *mp)
clib_error_t * ip6_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 is_del)
Definition: ip6_forward.c:290
clib_error_t * vnet_hw_interface_add_del_mac_address(vnet_main_t *vnm, u32 hw_if_index, const u8 *mac_address, u8 is_add)
Definition: interface.c:1450
u32 vrf_id
Definition: nat.api:821
clib_error_t * vnet_hw_interface_change_mac_address(vnet_main_t *vnm, u32 hw_if_index, const u8 *mac_address)
Definition: interface.c:1538
clib_error_t * vnet_create_sw_interface(vnet_main_t *vnm, vnet_sw_interface_t *template, u32 *sw_if_index)
Definition: interface.c:578
Interface details structure (fix this)
Definition: interface.api:137
static void vl_api_sw_interface_set_table_t_handler(vl_api_sw_interface_set_table_t *mp)
u32 table_id
Definition: fib_types.api:118
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:487
Set / clear software interface tag.
Definition: interface.api:306
Add or delete a secondary MAC address on an interface.
Definition: interface.api:322
Associate the specified interface with a fib table.
Definition: interface.api:238
static void vl_api_sw_interface_get_mac_address_t_handler(vl_api_sw_interface_get_mac_address_t *mp)
u32 * fib_index_by_sw_if_index
Definition: ip6.h:195
void mac_address_decode(const u8 *in, mac_address_t *out)
Conversion functions to/from (decode/encode) API types to VPP internal types.
vl_api_interface_index_t sw_if_index
Definition: interface.api:499
u32 l2pbb_get(vlib_main_t *vlib_main, vnet_main_t *vnet_main, u32 sw_if_index, u32 *vtr_op, u16 *outer_tag, ethernet_header_t *eth_hdr, u16 *b_vlanid, u32 *i_sid)
Get pbb tag rewrite on the given interface.
Definition: l2_vtr.c:686
vl_api_interface_index_t sw_if_index
Definition: interface.api:562
#define VALIDATE_SW_IF_INDEX(mp)
A protocol Independent FIB table.
Definition: fib_table.h:71
vl_api_interface_index_t sw_if_index
Definition: interface.api:311