FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
tuntap.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * tuntap.c - kernel stack (reverse) punt/inject path
4  *
5  * Copyright (c) 2009 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  * @file
21  * @brief TunTap Kernel stack (reverse) punt/inject path.
22  *
23  * This driver runs in one of two distinct modes:
24  * - "punt/inject" mode, where we send pkts not otherwise processed
25  * by the forwarding to the Linux kernel stack, and
26  *
27  * - "normal interface" mode, where we treat the Linux kernel stack
28  * as a peer.
29  *
30  * By default, we select punt/inject mode.
31  */
32 
33 #include <fcntl.h> /* for open */
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
36 #include <sys/stat.h>
37 #include <sys/types.h>
38 #include <sys/uio.h> /* for iovec */
39 #include <netinet/in.h>
40 
41 #include <linux/if_arp.h>
42 #include <linux/if_tun.h>
43 
44 #include <vlib/vlib.h>
45 #include <vlib/unix/unix.h>
46 
47 #include <vnet/ip/ip.h>
48 #include <vnet/fib/fib_table.h>
49 
50 #include <vnet/ethernet/ethernet.h>
51 #include <vnet/devices/devices.h>
52 #include <vnet/feature/feature.h>
53 
56 
57 static void tuntap_punt_frame (vlib_main_t * vm,
60 static void tuntap_nopunt_frame (vlib_main_t * vm,
63 
64 typedef struct
65 {
68  u8 addr[16];
70 
71 /**
72  * @brief TUNTAP per thread struct
73  */
74 typedef struct
75 {
76  /** Vector of VLIB rx buffers to use. We allocate them in blocks
77  of VLIB_FRAME_SIZE (256). */
79 
80  /** Vector of iovecs for readv/writev calls. */
81  struct iovec *iovecs;
83 
84 /**
85  * @brief TUNTAP node main state
86  */
87 typedef struct
88 {
89  /** per thread variables */
91 
92  /** File descriptors for /dev/net/tun and provisioning socket. */
93  int dev_net_tun_fd, dev_tap_fd;
94 
95  /** Create a "tap" [ethernet] encaps device */
96  int is_ether;
97 
98  /** 1 if a "normal" routed intfc, 0 if a punt/inject interface */
99 
101 
102  /** tap device destination MAC address. Required, or Linux drops pkts */
103  u8 ether_dst_mac[6];
104 
105  /** Interface MTU in bytes and # of default sized buffers. */
106  u32 mtu_bytes, mtu_buffers;
107 
108  /** Linux interface name for tun device. */
109  char *tun_name;
110 
111  /** Pool of subinterface addresses */
113 
114  /** Hash for subif addresses */
116 
117  /** Unix file index */
119 
120  /** For the "normal" interface, if configured */
121  u32 hw_if_index, sw_if_index;
122 
123 } tuntap_main_t;
124 
126  .tun_name = "vnet",
127 
128  /** Suitable defaults for an Ethernet-like tun/tap device */
129  .mtu_bytes = 4096 + 256,
130 };
131 
132 /**
133  * @brief tuntap_tx
134  * @node tuntap-tx
135  *
136  * Output node, writes the buffers comprising the incoming frame
137  * to the tun/tap device, aka hands them to the Linux kernel stack.
138  *
139  * @param *vm - vlib_main_t
140  * @param *node - vlib_node_runtime_t
141  * @param *frame - vlib_frame_t
142  *
143  * @return rc - uword
144  *
145  */
146 static uword
148 {
149  u32 *buffers = vlib_frame_vector_args (frame);
150  uword n_packets = frame->n_vectors;
151  tuntap_main_t *tm = &tuntap_main;
152  vnet_main_t *vnm = vnet_get_main ();
154  u32 n_bytes = 0;
155  int i;
157 
158  for (i = 0; i < n_packets; i++)
159  {
160  struct iovec *iov;
161  vlib_buffer_t *b;
162  uword l;
163 
164  b = vlib_get_buffer (vm, buffers[i]);
165 
166  if (tm->is_ether && (!tm->have_normal_interface))
167  {
170  6);
171  }
172 
173  /* Re-set iovecs if present. */
174  if (tm->threads[thread_index].iovecs)
175  _vec_len (tm->threads[thread_index].iovecs) = 0;
176 
177  /** VLIB buffer chain -> Unix iovec(s). */
178  vec_add2 (tm->threads[thread_index].iovecs, iov, 1);
179  iov->iov_base = b->data + b->current_data;
180  iov->iov_len = l = b->current_length;
181 
182  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_NEXT_PRESENT))
183  {
184  do
185  {
187 
188  vec_add2 (tm->threads[thread_index].iovecs, iov, 1);
189 
190  iov->iov_base = b->data + b->current_data;
191  iov->iov_len = b->current_length;
192  l += b->current_length;
193  }
194  while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
195  }
196 
197  if (writev (tm->dev_net_tun_fd, tm->threads[thread_index].iovecs,
198  vec_len (tm->threads[thread_index].iovecs)) < l)
199  clib_unix_warning ("writev");
200 
201  n_bytes += l;
202  }
203 
204  /* Update tuntap interface output stats. */
207  vm->thread_index,
208  tm->sw_if_index, n_packets, n_bytes);
209 
210 
211  /** The normal interface path flattens the buffer chain */
212  if (tm->have_normal_interface)
213  vlib_buffer_free_no_next (vm, buffers, n_packets);
214  else
215  vlib_buffer_free (vm, buffers, n_packets);
216 
217  return n_packets;
218 }
219 
220 /* *INDENT-OFF* */
222  .function = tuntap_tx,
223  .name = "tuntap-tx",
224  .type = VLIB_NODE_TYPE_INTERNAL,
225  .vector_size = 4,
226 };
227 /* *INDENT-ON* */
228 
229 /**
230  * @brief TUNTAP receive node
231  * @node tuntap-rx
232  *
233  * @param *vm - vlib_main_t
234  * @param *node - vlib_node_runtime_t
235  * @param *frame - vlib_frame_t
236  *
237  * @return rc - uword
238  *
239  */
240 static uword
242 {
243  tuntap_main_t *tm = &tuntap_main;
244  vlib_buffer_t *b;
245  u32 bi;
246  const uword buffer_size = vlib_buffer_get_default_data_size (vm);
248 
249  /** Make sure we have some RX buffers. */
250  {
252  uword n_alloc;
253 
254  if (n_left < VLIB_FRAME_SIZE / 2)
255  {
256  if (!tm->threads[thread_index].rx_buffers)
258 
259  n_alloc =
263  _vec_len (tm->threads[thread_index].rx_buffers) = n_left + n_alloc;
264  }
265  }
266 
267  /** Allocate RX buffers from end of rx_buffers.
268  Turn them into iovecs to pass to readv. */
269  {
270  uword i_rx = vec_len (tm->threads[thread_index].rx_buffers) - 1;
271  vlib_buffer_t *b;
272  word i, n_bytes_left, n_bytes_in_packet;
273 
274  /** We should have enough buffers left for an MTU sized packet. */
276  tm->mtu_buffers);
277 
279  for (i = 0; i < tm->mtu_buffers; i++)
280  {
281  b =
283  tm->threads[thread_index].rx_buffers[i_rx - i]);
284  tm->threads[thread_index].iovecs[i].iov_base = b->data;
285  tm->threads[thread_index].iovecs[i].iov_len = buffer_size;
286  }
287 
288  n_bytes_left =
289  readv (tm->dev_net_tun_fd, tm->threads[thread_index].iovecs,
290  tm->mtu_buffers);
291  n_bytes_in_packet = n_bytes_left;
292  if (n_bytes_left <= 0)
293  {
294  if (errno != EAGAIN)
295  clib_unix_warning ("readv %d", n_bytes_left);
296  return 0;
297  }
298 
299  bi = tm->threads[thread_index].rx_buffers[i_rx];
300 
301  while (1)
302  {
304  b->flags = 0;
305  b->current_data = 0;
306  b->current_length =
307  n_bytes_left < buffer_size ? n_bytes_left : buffer_size;
308 
309  n_bytes_left -= buffer_size;
310 
311  if (n_bytes_left <= 0)
312  {
313  break;
314  }
315 
316  i_rx--;
317  b->flags |= VLIB_BUFFER_NEXT_PRESENT;
319  }
320 
321  /** Interface counters for tuntap interface. */
325  thread_index, tm->sw_if_index, 1, n_bytes_in_packet);
326 
327  _vec_len (tm->threads[thread_index].rx_buffers) = i_rx;
328  }
329 
330  b = vlib_get_buffer (vm, bi);
331 
332  {
333  u32 next_index;
334  uword n_trace = vlib_get_trace_count (vm, node);
335 
336  vnet_buffer (b)->sw_if_index[VLIB_RX] = tm->sw_if_index;
337  vnet_buffer (b)->sw_if_index[VLIB_TX] = (u32) ~ 0;
338 
339  b->error = node->errors[0];
340 
341  if (tm->is_ether)
342  {
344  }
345  else
346  switch (b->data[0] & 0xf0)
347  {
348  case 0x40:
350  break;
351  case 0x60:
353  break;
354  default:
356  break;
357  }
358 
359  /* The linux kernel couldn't care less if our interface is up */
360  if (tm->have_normal_interface)
361  {
362  vnet_main_t *vnm = vnet_get_main ();
364  si = vnet_get_sw_interface (vnm, tm->sw_if_index);
367  }
368 
370 
372 
373  if (PREDICT_FALSE (n_trace > 0 && vlib_trace_buffer (vm, node, next_index, b, /* follow_chain */
374  1)))
375  vlib_set_trace_count (vm, node, n_trace - 1);
376  }
377 
378  return 1;
379 }
380 
381 /**
382  * @brief TUNTAP_RX error strings
383  */
384 static char *tuntap_rx_error_strings[] = {
385  "unknown packet type",
386 };
387 
388 /* *INDENT-OFF* */
390  .function = tuntap_rx,
392  .name = "tuntap-rx",
393  .sibling_of = "device-input",
394  .type = VLIB_NODE_TYPE_INPUT,
395  .state = VLIB_NODE_STATE_INTERRUPT,
396  .vector_size = 4,
397  .n_errors = 1,
398  .error_strings = tuntap_rx_error_strings,
399 };
400 /* *INDENT-ON* */
401 
402 /**
403  * @brief Gets called when file descriptor is ready from epoll.
404  *
405  * @param *uf - clib_file_t
406  *
407  * @return error - clib_error_t
408  */
409 static clib_error_t *
411 {
414  return 0;
415 }
416 
417 /**
418  * @brief Clean up the tun/tap device
419  *
420  * @param *vm - vlib_main_t
421  *
422  * @return error - clib_error_t
423  *
424  */
425 static clib_error_t *
427 {
428  tuntap_main_t *tm = &tuntap_main;
429  struct ifreq ifr;
430  int sfd;
431 
432  /* Not present. */
433  if (!tm->dev_net_tun_fd || tm->dev_net_tun_fd < 0)
434  return 0;
435 
436  sfd = socket (AF_INET, SOCK_STREAM, 0);
437  if (sfd < 0)
438  clib_unix_warning ("provisioning socket");
439 
440  clib_memset (&ifr, 0, sizeof (ifr));
441  strncpy (ifr.ifr_name, tm->tun_name, sizeof (ifr.ifr_name) - 1);
442 
443  /* get flags, modify to bring down interface... */
444  if (ioctl (sfd, SIOCGIFFLAGS, &ifr) < 0)
445  clib_unix_warning ("SIOCGIFFLAGS");
446 
447  ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING);
448 
449  if (ioctl (sfd, SIOCSIFFLAGS, &ifr) < 0)
450  clib_unix_warning ("SIOCSIFFLAGS");
451 
452  /* Turn off persistence */
453  if (ioctl (tm->dev_net_tun_fd, TUNSETPERSIST, 0) < 0)
454  clib_unix_warning ("TUNSETPERSIST");
455  close (tm->dev_tap_fd);
456  if (tm->dev_net_tun_fd >= 0)
457  close (tm->dev_net_tun_fd);
458  if (sfd >= 0)
459  close (sfd);
460 
461  return 0;
462 }
463 
465 
466 /**
467  * @brief CLI function for tun/tap config
468  *
469  * @param *vm - vlib_main_t
470  * @param *input - unformat_input_t
471  *
472  * @return error - clib_error_t
473  *
474  */
475 static clib_error_t *
477 {
478  tuntap_main_t *tm = &tuntap_main;
479  clib_error_t *error = 0;
480  struct ifreq ifr;
481  u8 *name;
482  int flags = IFF_TUN | IFF_NO_PI;
483  int is_enabled = 0, is_ether = 0, have_normal_interface = 0;
484  const uword buffer_size = vlib_buffer_get_default_data_size (vm);
485 
487  {
488  if (unformat (input, "mtu %d", &tm->mtu_bytes))
489  ;
490  else if (unformat (input, "enable"))
491  is_enabled = 1;
492  else if (unformat (input, "disable"))
493  is_enabled = 0;
494  else if (unformat (input, "ethernet") || unformat (input, "ether"))
495  is_ether = 1;
496  else if (unformat (input, "have-normal-interface") ||
497  unformat (input, "have-normal"))
498  have_normal_interface = 1;
499  else if (unformat (input, "name %s", &name))
500  tm->tun_name = (char *) name;
501  else
502  return clib_error_return (0, "unknown input `%U'",
503  format_unformat_error, input);
504  }
505 
506  tm->dev_net_tun_fd = -1;
507  tm->dev_tap_fd = -1;
508 
509  if (is_enabled == 0)
510  return 0;
511 
512  if (geteuid ())
513  {
514  clib_warning ("tuntap disabled: must be superuser");
515  return 0;
516  }
517 
518  tm->is_ether = is_ether;
519  tm->have_normal_interface = have_normal_interface;
520 
521  if (is_ether)
522  flags = IFF_TAP | IFF_NO_PI;
523 
524  if ((tm->dev_net_tun_fd = open ("/dev/net/tun", O_RDWR)) < 0)
525  {
526  error = clib_error_return_unix (0, "open /dev/net/tun");
527  goto done;
528  }
529 
530  clib_memset (&ifr, 0, sizeof (ifr));
531  strncpy (ifr.ifr_name, tm->tun_name, sizeof (ifr.ifr_name) - 1);
532  ifr.ifr_flags = flags;
533  if (ioctl (tm->dev_net_tun_fd, TUNSETIFF, (void *) &ifr) < 0)
534  {
535  error = clib_error_return_unix (0, "ioctl TUNSETIFF");
536  goto done;
537  }
538 
539  /* Make it persistent, at least until we split. */
540  if (ioctl (tm->dev_net_tun_fd, TUNSETPERSIST, 1) < 0)
541  {
542  error = clib_error_return_unix (0, "TUNSETPERSIST");
543  goto done;
544  }
545 
546  /* Open a provisioning socket */
547  if ((tm->dev_tap_fd = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0)
548  {
549  error = clib_error_return_unix (0, "socket");
550  goto done;
551  }
552 
553  /* Find the interface index. */
554  {
555  struct ifreq ifr;
556  struct sockaddr_ll sll;
557 
558  clib_memset (&ifr, 0, sizeof (ifr));
559  strncpy (ifr.ifr_name, tm->tun_name, sizeof (ifr.ifr_name) - 1);
560  if (ioctl (tm->dev_tap_fd, SIOCGIFINDEX, &ifr) < 0)
561  {
562  error = clib_error_return_unix (0, "ioctl SIOCGIFINDEX");
563  goto done;
564  }
565 
566  /* Bind the provisioning socket to the interface. */
567  clib_memset (&sll, 0, sizeof (sll));
568  sll.sll_family = AF_PACKET;
569  sll.sll_ifindex = ifr.ifr_ifindex;
570  sll.sll_protocol = htons (ETH_P_ALL);
571 
572  if (bind (tm->dev_tap_fd, (struct sockaddr *) &sll, sizeof (sll)) < 0)
573  {
574  error = clib_error_return_unix (0, "bind");
575  goto done;
576  }
577  }
578 
579  /* non-blocking I/O on /dev/tapX */
580  {
581  int one = 1;
582  if (ioctl (tm->dev_net_tun_fd, FIONBIO, &one) < 0)
583  {
584  error = clib_error_return_unix (0, "ioctl FIONBIO");
585  goto done;
586  }
587  }
588 
589  tm->mtu_buffers = (tm->mtu_bytes + (buffer_size - 1)) / buffer_size;
590 
591  ifr.ifr_mtu = tm->mtu_bytes;
592  if (ioctl (tm->dev_tap_fd, SIOCSIFMTU, &ifr) < 0)
593  {
594  error = clib_error_return_unix (0, "ioctl SIOCSIFMTU");
595  goto done;
596  }
597 
598  /* get flags, modify to bring up interface... */
599  if (ioctl (tm->dev_tap_fd, SIOCGIFFLAGS, &ifr) < 0)
600  {
601  error = clib_error_return_unix (0, "ioctl SIOCGIFFLAGS");
602  goto done;
603  }
604 
605  ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
606 
607  if (ioctl (tm->dev_tap_fd, SIOCSIFFLAGS, &ifr) < 0)
608  {
609  error = clib_error_return_unix (0, "ioctl SIOCSIFFLAGS");
610  goto done;
611  }
612 
613  if (is_ether)
614  {
615  if (ioctl (tm->dev_tap_fd, SIOCGIFHWADDR, &ifr) < 0)
616  {
617  error = clib_error_return_unix (0, "ioctl SIOCGIFHWADDR");
618  goto done;
619  }
620  else
621  clib_memcpy_fast (tm->ether_dst_mac, ifr.ifr_hwaddr.sa_data, 6);
622  }
623 
624  if (have_normal_interface)
625  {
626  vnet_main_t *vnm = vnet_get_main ();
628  (vnm, tuntap_dev_class.index, 0 /* device instance */ ,
629  tm->ether_dst_mac /* ethernet address */ ,
630  &tm->hw_if_index, 0 /* flag change */ );
631  if (error)
633  tm->sw_if_index = tm->hw_if_index;
635  }
636  else
637  {
638  vnet_main_t *vnm = vnet_get_main ();
640 
642 
644  (vnm, tuntap_dev_class.index, 0 /* device instance */ ,
645  tuntap_interface_class.index, 0);
646  hi = vnet_get_hw_interface (vnm, tm->hw_if_index);
647  tm->sw_if_index = hi->sw_if_index;
648 
649  /* Interface is always up. */
654  }
655 
656  {
657  clib_file_t template = { 0 };
658  template.read_function = tuntap_read_ready;
659  template.file_descriptor = tm->dev_net_tun_fd;
660  template.description = format (0, "vnet tuntap");
661  tm->clib_file_index = clib_file_add (&file_main, &template);
662  }
663 
664 done:
665  if (error)
666  {
667  if (tm->dev_net_tun_fd >= 0)
668  close (tm->dev_net_tun_fd);
669  if (tm->dev_tap_fd >= 0)
670  close (tm->dev_tap_fd);
671  }
672 
673  return error;
674 }
675 
677 
678 /**
679  * @brief Add or Del IP4 address to tun/tap interface
680  *
681  * @param *im - ip4_main_t
682  * @param opaque - uword
683  * @param sw_if_index - u32
684  * @param *address - ip4_address_t
685  * @param is_delete - u32
686  *
687  */
688 void
690  uword opaque,
693  u32 address_length,
694  u32 if_address_index, u32 is_delete)
695 {
696  tuntap_main_t *tm = &tuntap_main;
697  struct ifreq ifr;
698  subif_address_t subif_addr, *ap;
699  uword *p;
700 
701  /** Tuntap disabled, or using a "normal" interface. */
702  if (tm->have_normal_interface || tm->dev_tap_fd < 0)
703  return;
704 
705  /* if the address is being applied to an interface that is not in
706  * the same table/VRF as this tap, then ignore it.
707  * If we don't do this overlapping address spaces in the different tables
708  * breaks the linux host's routing tables */
710  sw_if_index) !=
712  return;
713 
714  /** See if we already know about this subif */
715  clib_memset (&subif_addr, 0, sizeof (subif_addr));
716  subif_addr.sw_if_index = sw_if_index;
717  clib_memcpy_fast (&subif_addr.addr, address, sizeof (*address));
718 
719  p = mhash_get (&tm->subif_mhash, &subif_addr);
720 
721  if (p)
722  ap = pool_elt_at_index (tm->subifs, p[0]);
723  else
724  {
725  pool_get (tm->subifs, ap);
726  *ap = subif_addr;
727  mhash_set (&tm->subif_mhash, ap, ap - tm->subifs, 0);
728  }
729 
730  /* Use subif pool index to select alias device. */
731  clib_memset (&ifr, 0, sizeof (ifr));
732  snprintf (ifr.ifr_name, sizeof (ifr.ifr_name),
733  "%s:%d", tm->tun_name, (int) (ap - tm->subifs));
734 
735  /* the tuntap punt/inject is enabled for IPv4 RX so long as
736  * any vpp interface has an IPv4 address.
737  * this is also ref counted.
738  */
740 
741  if (!is_delete)
742  {
743  struct sockaddr_in *sin;
744 
745  sin = (struct sockaddr_in *) &ifr.ifr_addr;
746 
747  /* Set ipv4 address, netmask. */
748  sin->sin_family = AF_INET;
749  clib_memcpy_fast (&sin->sin_addr.s_addr, address, 4);
750  if (ioctl (tm->dev_tap_fd, SIOCSIFADDR, &ifr) < 0)
751  clib_unix_warning ("ioctl SIOCSIFADDR");
752 
753  sin->sin_addr.s_addr = im->fib_masks[address_length];
754  if (ioctl (tm->dev_tap_fd, SIOCSIFNETMASK, &ifr) < 0)
755  clib_unix_warning ("ioctl SIOCSIFNETMASK");
756  }
757  else
758  {
759  mhash_unset (&tm->subif_mhash, &subif_addr, 0 /* old value ptr */ );
760  pool_put (tm->subifs, ap);
761  }
762 
763  /* get flags, modify to bring up interface... */
764  if (ioctl (tm->dev_tap_fd, SIOCGIFFLAGS, &ifr) < 0)
765  clib_unix_warning ("ioctl SIOCGIFFLAGS");
766 
767  if (is_delete)
768  ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING);
769  else
770  ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
771 
772  if (ioctl (tm->dev_tap_fd, SIOCSIFFLAGS, &ifr) < 0)
773  clib_unix_warning ("ioctl SIOCSIFFLAGS");
774 }
775 
776 /**
777  * @brief workaround for a known include file bug.
778  * including @c <linux/ipv6.h> causes multiple definitions if
779  * @c <netinet/in.h is also included.
780  */
781 struct in6_ifreq
782 {
783  struct in6_addr ifr6_addr;
786 };
787 
788 /**
789  * @brief Add or Del tun/tap interface address.
790  *
791  * Both the v6 interface address API and the way ifconfig
792  * displays subinterfaces differ from their v4 counterparts.
793  * The code given here seems to work but YMMV.
794  *
795  * @param *im - ip6_main_t
796  * @param opaque - uword
797  * @param sw_if_index - u32
798  * @param *address - ip6_address_t
799  * @param address_length - u32
800  * @param if_address_index - u32
801  * @param is_delete - u32
802  */
803 void
805  uword opaque,
807  ip6_address_t * address,
808  u32 address_length,
809  u32 if_address_index, u32 is_delete)
810 {
811  tuntap_main_t *tm = &tuntap_main;
812  struct ifreq ifr;
813  struct in6_ifreq ifr6;
814  subif_address_t subif_addr, *ap;
815  uword *p;
816 
817  /* Tuntap disabled, or using a "normal" interface. */
818  if (tm->have_normal_interface || tm->dev_tap_fd < 0)
819  return;
820 
821  /* if the address is being applied to an interface that is not in
822  * the same table/VRF as this tap, then ignore it.
823  * If we don't do this overlapping address spaces in the different tables
824  * breaks the linux host's routing tables */
826  sw_if_index) !=
828  return;
829 
830  /* See if we already know about this subif */
831  clib_memset (&subif_addr, 0, sizeof (subif_addr));
832  subif_addr.sw_if_index = sw_if_index;
833  subif_addr.is_v6 = 1;
834  clib_memcpy_fast (&subif_addr.addr, address, sizeof (*address));
835 
836  p = mhash_get (&tm->subif_mhash, &subif_addr);
837 
838  if (p)
839  ap = pool_elt_at_index (tm->subifs, p[0]);
840  else
841  {
842  pool_get (tm->subifs, ap);
843  *ap = subif_addr;
844  mhash_set (&tm->subif_mhash, ap, ap - tm->subifs, 0);
845  }
846 
847  /* Use subif pool index to select alias device. */
848  clib_memset (&ifr, 0, sizeof (ifr));
849  clib_memset (&ifr6, 0, sizeof (ifr6));
850  snprintf (ifr.ifr_name, sizeof (ifr.ifr_name),
851  "%s:%d", tm->tun_name, (int) (ap - tm->subifs));
852 
853  /* the tuntap punt/inject is enabled for IPv6 RX so long as
854  * any vpp interface has an IPv6 address.
855  * this is also ref counted.
856  */
858 
859  if (!is_delete)
860  {
861  int sockfd = socket (AF_INET6, SOCK_STREAM, 0);
862  if (sockfd < 0)
863  clib_unix_warning ("get ifindex socket");
864 
865  if (ioctl (sockfd, SIOGIFINDEX, &ifr) < 0)
866  clib_unix_warning ("get ifindex");
867 
868  ifr6.ifr6_ifindex = ifr.ifr_ifindex;
869  ifr6.ifr6_prefixlen = address_length;
870  clib_memcpy_fast (&ifr6.ifr6_addr, address, 16);
871 
872  if (ioctl (sockfd, SIOCSIFADDR, &ifr6) < 0)
873  clib_unix_warning ("set address");
874 
875  if (sockfd >= 0)
876  close (sockfd);
877  }
878  else
879  {
880  int sockfd = socket (AF_INET6, SOCK_STREAM, 0);
881  if (sockfd < 0)
882  clib_unix_warning ("get ifindex socket");
883 
884  if (ioctl (sockfd, SIOGIFINDEX, &ifr) < 0)
885  clib_unix_warning ("get ifindex");
886 
887  ifr6.ifr6_ifindex = ifr.ifr_ifindex;
888  ifr6.ifr6_prefixlen = address_length;
889  clib_memcpy_fast (&ifr6.ifr6_addr, address, 16);
890 
891  if (ioctl (sockfd, SIOCDIFADDR, &ifr6) < 0)
892  clib_unix_warning ("del address");
893 
894  if (sockfd >= 0)
895  close (sockfd);
896 
897  mhash_unset (&tm->subif_mhash, &subif_addr, 0 /* old value ptr */ );
898  pool_put (tm->subifs, ap);
899  }
900 }
901 
902 /**
903  * @brief TX the tun/tap frame
904  *
905  * @param *vm - vlib_main_t
906  * @param *node - vlib_node_runtime_t
907  * @param *frame - vlib_frame_t
908  *
909  */
910 static void
913 {
914  tuntap_tx (vm, node, frame);
916 }
917 
918 /**
919  * @brief Free the tun/tap frame
920  *
921  * @param *vm - vlib_main_t
922  * @param *node - vlib_node_runtime_t
923  * @param *frame - vlib_frame_t
924  *
925  */
926 static void
929 {
930  u32 *buffers = vlib_frame_vector_args (frame);
931  uword n_packets = frame->n_vectors;
932  vlib_buffer_free (vm, buffers, n_packets);
934 }
935 
936 /* *INDENT-OFF* */
938  .name = "tuntap",
940 };
941 /* *INDENT-ON* */
942 
943 /**
944  * @brief Format tun/tap interface name
945  *
946  * @param *s - u8 - formatter string
947  * @param *args - va_list
948  *
949  * @return *s - u8 - formatted string
950  *
951  */
952 static u8 *
953 format_tuntap_interface_name (u8 * s, va_list * args)
954 {
955  u32 i = va_arg (*args, u32);
956 
957  s = format (s, "tuntap-%d", i);
958  return s;
959 }
960 
961 /**
962  * @brief TX packet out tun/tap
963  *
964  * @param *vm - vlib_main_t
965  * @param *node - vlib_node_runtime_t
966  * @param *frame - vlib_frame_t
967  *
968  * @return n_buffers - uword - Packets transmitted
969  *
970  */
971 static uword
974 {
975  tuntap_main_t *tm = &tuntap_main;
976  u32 *buffers = vlib_frame_vector_args (frame);
977  uword n_buffers = frame->n_vectors;
978 
979  /* Normal interface transmit happens only on the normal interface... */
980  if (tm->have_normal_interface)
981  return tuntap_tx (vm, node, frame);
982 
983  vlib_buffer_free (vm, buffers, n_buffers);
984  return n_buffers;
985 }
986 
987 /* *INDENT-OFF* */
989  .name = "tuntap",
990  .tx_function = tuntap_intfc_tx,
991  .format_device_name = format_tuntap_interface_name,
992 };
993 /* *INDENT-ON* */
994 
995 /**
996  * @brief tun/tap node init
997  *
998  * @param *vm - vlib_main_t
999  *
1000  * @return error - clib_error_t
1001  *
1002  */
1003 static clib_error_t *
1005 {
1006  ip4_main_t *im4 = &ip4_main;
1007  ip6_main_t *im6 = &ip6_main;
1010  tuntap_main_t *tm = &tuntap_main;
1012 
1013  mhash_init (&tm->subif_mhash, sizeof (u32), sizeof (subif_address_t));
1014 
1016  cb4.function_opaque = 0;
1018 
1020  cb6.function_opaque = 0;
1024 
1025  return 0;
1026 }
1027 
1028 /* *INDENT-OFF* */
1030 {
1031  .runs_after = VLIB_INITS("ip4_init"),
1032 };
1033 /* *INDENT-ON* */
1034 
1035 /*
1036  * fd.io coding-style-patch-verification: ON
1037  *
1038  * Local Variables:
1039  * eval: (c-set-style "gnu")
1040  * End:
1041  */
vlib.h
vlib_buffer_t::next_buffer
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:149
im
vnet_interface_main_t * im
Definition: interface_output.c:415
vlib_buffer_free
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:979
file_main
clib_file_main_t file_main
Definition: main.c:63
vnet_sw_interface_set_flags
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:523
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
vnet_sw_interface_t
Definition: interface.h:869
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
vnet_device_class_t
struct _vnet_device_class vnet_device_class_t
n_buffers
u32 n_buffers
Definition: interface_output.c:421
in6_ifreq::ifr6_ifindex
int ifr6_ifindex
Definition: tuntap.c:785
in6_ifreq::ifr6_addr
struct in6_addr ifr6_addr
Definition: tuntap.c:783
VNET_INTERFACE_COUNTER_TX
@ VNET_INTERFACE_COUNTER_TX
Definition: interface.h:919
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
ip4_main
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1104
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
ip4_sw_interface_enable_disable
void ip4_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip4_forward.c:602
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
tuntap_main_t::mtu_buffers
u32 mtu_buffers
Definition: tuntap.c:106
name
string name[64]
Definition: fib.api:25
ip4_add_del_interface_address_callback_t
Definition: ip4.h:73
tuntap_main_t::ether_dst_mac
u8 ether_dst_mac[6]
tap device destination MAC address.
Definition: tuntap.c:103
tuntap_exit
static clib_error_t * tuntap_exit(vlib_main_t *vm)
Clean up the tun/tap device.
Definition: tuntap.c:426
VNET_DEVICE_INPUT_NEXT_DROP
@ VNET_DEVICE_INPUT_NEXT_DROP
Definition: devices.h:29
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
VLIB_FRAME_SIZE
#define VLIB_FRAME_SIZE
Definition: node.h:368
tuntap_main_t::mtu_bytes
u32 mtu_bytes
Interface MTU in bytes and # of default sized buffers.
Definition: tuntap.c:106
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
tuntap_tx_node
static vlib_node_registration_t tuntap_tx_node
(constructor) VLIB_REGISTER_NODE (tuntap_tx_node)
Definition: tuntap.c:221
tuntap_rx_error_strings
static char * tuntap_rx_error_strings[]
TUNTAP_RX error strings.
Definition: tuntap.c:384
mhash_t
Definition: mhash.h:46
clib_file::read_function
clib_file_function_t * read_function
Definition: file.h:67
vec_alloc
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
Definition: vec.h:334
vnet_interface_main_t
Definition: interface.h:990
VLIB_NODE_TYPE_INPUT
@ VLIB_NODE_TYPE_INPUT
Definition: node.h:76
fib_table.h
VNET_HW_INTERFACE_CLASS
VNET_HW_INTERFACE_CLASS(tuntap_interface_class, static)
u16
unsigned short u16
Definition: types.h:57
tuntap_main_t::is_ether
int is_ether
Create a "tap" [ethernet] encaps device.
Definition: tuntap.c:96
VNET_SW_INTERFACE_FLAG_ADMIN_UP
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:844
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
mhash_get
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
subif_address_t
Definition: tuntap.c:64
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
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
tuntap_config
static clib_error_t * tuntap_config(vlib_main_t *vm, unformat_input_t *input)
CLI function for tun/tap config.
Definition: tuntap.c:476
VNET_HW_INTERFACE_FLAG_LINK_UP
@ VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:509
tuntap_main_t::clib_file_index
u32 clib_file_index
Unix file index.
Definition: tuntap.c:118
vlib_get_trace_count
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
Definition: trace_funcs.h:212
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
clib_error_report
#define clib_error_report(e)
Definition: error.h:113
unformat_input_t
struct _unformat_input_t unformat_input_t
tuntap_main_t::have_normal_interface
int have_normal_interface
1 if a "normal" routed intfc, 0 if a punt/inject interface
Definition: tuntap.c:100
tuntap_main
static tuntap_main_t tuntap_main
Definition: tuntap.c:125
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
mhash_init
__clib_export void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:168
VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT
@ VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT
Definition: devices.h:28
vlib_frame_t
Definition: node.h:372
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
tuntap_per_thread_t
TUNTAP per thread struct.
Definition: tuntap.c:74
ethernet.h
clib_unix_warning
#define clib_unix_warning(format, args...)
Definition: error.h:68
error
Definition: cJSON.c:88
vnet_sw_interface_t::flags
vnet_sw_interface_flags_t flags
Definition: interface.h:873
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
in6_ifreq
workaround for a known include file bug.
Definition: tuntap.c:781
tuntap_tx
static uword tuntap_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
tuntap_tx
Definition: tuntap.c:147
vlib_buffer_t::current_data
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:119
vlib_thread_main_t::n_vlib_mains
u32 n_vlib_mains
Definition: threads.h:262
tuntap_ip6_add_del_interface_address
void tuntap_ip6_add_del_interface_address(ip6_main_t *im, uword opaque, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
Add or Del tun/tap interface address.
Definition: tuntap.c:804
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vlib_buffer_t::error
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:145
feature.h
vec_add2
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:644
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
vlib_buffer_alloc
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:702
tuntap_rx
static uword tuntap_rx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
TUNTAP receive node.
Definition: tuntap.c:241
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
vnet_get_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
clib_file
Definition: file.h:51
VNET_DEVICE_INPUT_NEXT_IP6_INPUT
@ VNET_DEVICE_INPUT_NEXT_IP6_INPUT
Definition: devices.h:26
subif_address_t::is_v6
u8 is_v6
Definition: tuntap.c:67
tuntap_main_t
TUNTAP node main state.
Definition: tuntap.c:87
ip6_add_del_interface_address_callback_t
Definition: ip6.h:94
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
VNET_DEVICE_INPUT_NEXT_IP4_INPUT
@ VNET_DEVICE_INPUT_NEXT_IP4_INPUT
Definition: devices.h:25
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
ip6_main_t::add_del_interface_address_callbacks
ip6_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Definition: ip6.h:148
vlib_config_function_runtime_t
Definition: init.h:68
vec_validate_aligned
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:534
tuntap_rx_node
static vlib_node_registration_t tuntap_rx_node
(constructor) VLIB_REGISTER_NODE (tuntap_rx_node)
Definition: tuntap.c:389
format_tuntap_interface_name
static u8 * format_tuntap_interface_name(u8 *s, va_list *args)
Format tun/tap interface name.
Definition: tuntap.c:953
tuntap_nopunt_frame
static void tuntap_nopunt_frame(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Free the tun/tap frame.
Definition: tuntap.c:927
uword
u64 uword
Definition: types.h:112
tuntap_main_t::sw_if_index
u32 sw_if_index
Definition: tuntap.c:121
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:215
vlib_main_t::os_punt_frame
void(* os_punt_frame)(struct vlib_main_t *vm, struct vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: main.h:183
tuntap_punt_frame
static void tuntap_punt_frame(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
TX the tun/tap frame.
Definition: tuntap.c:911
VLIB_NODE_FLAG_TRACE_SUPPORTED
#define VLIB_NODE_FLAG_TRACE_SUPPORTED
Definition: node.h:295
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
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
address
manual_print typedef address
Definition: ip_types.api:96
ip4_address_t
Definition: ip4_packet.h:50
VNET_INTERFACE_COUNTER_RX
@ VNET_INTERFACE_COUNTER_RX
Definition: interface.h:915
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
tuntap_init
static clib_error_t * tuntap_init(vlib_main_t *vm)
tun/tap node init
Definition: tuntap.c:1004
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:58
vlib_set_trace_count
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
Definition: trace_funcs.h:226
tuntap_dev_class
static vnet_device_class_t tuntap_dev_class
Definition: tuntap.c:54
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vnet_interface_main_t::combined_sw_if_counters
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:1024
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
vlib_frame_free
void vlib_frame_free(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_frame_t *f)
Definition: main.c:242
ip4_add_del_interface_address_callback_t::function_opaque
uword function_opaque
Definition: ip4.h:76
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2785
tuntap_read_ready
static clib_error_t * tuntap_read_ready(clib_file_t *uf)
Gets called when file descriptor is ready from epoll.
Definition: tuntap.c:410
subif_address_t::sw_if_index
u32 sw_if_index
Definition: tuntap.c:66
ip4_main_t::add_del_interface_address_callbacks
ip4_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Functions to call when interface address changes.
Definition: ip4.h:138
ip4_add_del_interface_address_callback_t::function
ip4_add_del_interface_address_function_t * function
Definition: ip4.h:75
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
ip6_add_del_interface_address_callback_t::function
ip6_add_del_interface_address_function_t * function
Definition: ip6.h:96
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
fib_table_get_index_for_sw_if_index
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:1003
vlib_set_next_frame_buffer
static void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
Definition: node_funcs.h:428
vlib_buffer_get_default_data_size
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:122
ip.h
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vlib_thread_main_t
Definition: threads.h:243
vlib_node_set_interrupt_pending
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:249
tuntap_main_t::tun_name
char * tun_name
Linux interface name for tun device.
Definition: tuntap.c:109
n_bytes
u32 n_bytes
Definition: interface_output.c:421
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
tuntap_main_t::subif_mhash
mhash_t subif_mhash
Hash for subif addresses.
Definition: tuntap.c:115
vlib_buffer_free_no_next
static void vlib_buffer_free_no_next(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers, does not free the buffer chain for each buffer.
Definition: buffer_funcs.h:996
ip6_add_del_interface_address_callback_t::function_opaque
uword function_opaque
Definition: ip6.h:97
tuntap_per_thread_t::rx_buffers
u32 * rx_buffers
Vector of VLIB rx buffers to use.
Definition: tuntap.c:78
si
vnet_sw_interface_t * si
Definition: interface_output.c:418
n_left
u32 n_left
Definition: interface_output.c:1096
ip6_sw_interface_enable_disable
void ip6_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip6_forward.c:240
clib_error_return_unix
#define clib_error_return_unix(e, args...)
Definition: error.h:102
tuntap_per_thread_t::iovecs
struct iovec * iovecs
Vector of iovecs for readv/writev calls.
Definition: tuntap.c:81
clib_file_add
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
Definition: file.h:96
ip6_main_t
Definition: ip6.h:110
in6_ifreq::ifr6_prefixlen
u32 ifr6_prefixlen
Definition: tuntap.c:784
vnet_main
vnet_main_t vnet_main
Definition: misc.c:43
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
tuntap_main_t::dev_net_tun_fd
int dev_net_tun_fd
File descriptors for /dev/net/tun and provisioning socket.
Definition: tuntap.c:93
VLIB_INITS
#define VLIB_INITS(...)
Definition: init.h:352
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
tuntap_main_t::dev_tap_fd
int dev_tap_fd
Definition: tuntap.c:93
clib_error_t
Definition: clib_error.h:21
vnet_hw_interface_set_flags
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:513
tuntap_ip4_add_del_interface_address
void tuntap_ip4_add_del_interface_address(ip4_main_t *im, uword opaque, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
Add or Del IP4 address to tun/tap interface.
Definition: tuntap.c:689
unix.h
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
vnet_feature_start_device_input_x1
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:343
tuntap_main_t::hw_if_index
u32 hw_if_index
For the "normal" interface, if configured.
Definition: tuntap.c:121
i
int i
Definition: flowhash_template.h:376
VNET_HW_INTERFACE_CLASS_FLAG_P2P
@ VNET_HW_INTERFACE_CLASS_FLAG_P2P
a point 2 point interface
Definition: interface.h:394
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
word
i64 word
Definition: types.h:111
devices.h
tuntap_intfc_tx
static uword tuntap_intfc_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
TX packet out tun/tap.
Definition: tuntap.c:972
tuntap_main_t::subifs
subif_address_t * subifs
Pool of subinterface addresses.
Definition: tuntap.c:112
VLIB_MAIN_LOOP_EXIT_FUNCTION
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
Definition: init.h:177
VNET_DEVICE_CLASS
VNET_DEVICE_CLASS(tuntap_dev_class, static)
tuntap_interface_class
static vnet_hw_interface_class_t tuntap_interface_class
Definition: tuntap.c:55
vlib_node_runtime_t
Definition: node.h:454
tuntap_main_t::threads
tuntap_per_thread_t * threads
per thread variables
Definition: tuntap.c:90
vlib_trace_buffer
static __clib_warn_unused_result int vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
Definition: trace_funcs.h:153
vlib_buffer_reset
static void vlib_buffer_reset(vlib_buffer_t *b)
Reset current header & length to state they were in when packet was received.
Definition: buffer.h:305
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
ip4_main_t
IPv4 main type.
Definition: ip4.h:107
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
subif_address_t::addr
u8 addr[16]
Definition: tuntap.c:68
vnet_hw_interface_class_t
struct _vnet_hw_interface_class vnet_hw_interface_class_t
mhash_unset
__clib_export uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:346
vnet_register_interface
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
Definition: interface.c:812
ethernet_register_interface
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, const u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
Definition: interface.c:348
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
mhash_set
static uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
Definition: mhash.h:117
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105