FD.io VPP  v19.04.1-1-ge4a0f9f
Vector Packet Processing
tap.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #define _GNU_SOURCE
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <fcntl.h>
22 #include <net/if.h>
23 #include <linux/if_tun.h>
24 #include <sys/ioctl.h>
25 #include <linux/virtio_net.h>
26 #include <linux/vhost.h>
27 #include <sys/eventfd.h>
28 #include <sched.h>
29 
30 #include <linux/netlink.h>
31 #include <linux/rtnetlink.h>
32 
33 #include <vlib/vlib.h>
34 #include <vlib/unix/unix.h>
35 #include <vnet/ethernet/ethernet.h>
36 #include <vnet/ip/ip4_packet.h>
37 #include <vnet/ip/ip6_packet.h>
38 #include <vnet/devices/netlink.h>
40 #include <vnet/devices/tap/tap.h>
41 
43 
44 #define _IOCTL(fd,a,...) \
45  if (ioctl (fd, a, __VA_ARGS__) < 0) \
46  { \
47  err = clib_error_return_unix (0, "ioctl(" #a ")"); \
48  goto error; \
49  }
50 
51 static u32
53  u32 flags)
54 {
55  /* nothing for now */
56  //TODO On MTU change call vnet_netlink_set_if_mtu
57  return 0;
58 }
59 
60 static int
61 open_netns_fd (char *netns)
62 {
63  u8 *s = 0;
64  int fd;
65 
66  if (strncmp (netns, "pid:", 4) == 0)
67  s = format (0, "/proc/%u/ns/net%c", atoi (netns + 4), 0);
68  else if (netns[0] == '/')
69  s = format (0, "%s%c", netns, 0);
70  else
71  s = format (0, "/var/run/netns/%s%c", netns, 0);
72 
73  fd = open ((char *) s, O_RDONLY);
74  vec_free (s);
75  return fd;
76 }
77 
78 #define TAP_MAX_INSTANCE 1024
79 
80 void
82 {
83  vnet_main_t *vnm = vnet_get_main ();
84  virtio_main_t *vim = &virtio_main;
85  tap_main_t *tm = &tap_main;
88  int i;
89  int old_netns_fd = -1;
90  struct ifreq ifr;
91  size_t hdrsz;
92  struct vhost_memory *vhost_mem = 0;
93  virtio_if_t *vif = 0;
94  clib_error_t *err = 0;
95  int fd = -1;
96 
97  if (args->id != ~0)
98  {
99  if (clib_bitmap_get (tm->tap_ids, args->id))
100  {
101  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
102  args->error = clib_error_return (0, "interface already exists");
103  return;
104  }
105  }
106  else
107  {
108  args->id = clib_bitmap_first_clear (tm->tap_ids);
109  }
110 
111  if (args->id > TAP_MAX_INSTANCE)
112  {
113  args->rv = VNET_API_ERROR_UNSPECIFIED;
114  args->error = clib_error_return (0, "cannot find free interface id");
115  return;
116  }
117 
118  clib_memset (&ifr, 0, sizeof (ifr));
119  pool_get (vim->interfaces, vif);
120  vif->dev_instance = vif - vim->interfaces;
121  vif->tap_fd = -1;
122  vif->id = args->id;
123 
124  if ((vif->fd = open ("/dev/vhost-net", O_RDWR | O_NONBLOCK)) < 0)
125  {
126  args->rv = VNET_API_ERROR_SYSCALL_ERROR_1;
127  args->error = clib_error_return_unix (0, "open '/dev/vhost-net'");
128  goto error;
129  }
130 
131  _IOCTL (vif->fd, VHOST_GET_FEATURES, &vif->remote_features);
132 
133  if ((vif->remote_features & VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF)) == 0)
134  {
135  args->rv = VNET_API_ERROR_UNSUPPORTED;
136  args->error = clib_error_return (0, "vhost-net backend doesn't support "
137  "VIRTIO_NET_F_MRG_RXBUF feature");
138  goto error;
139  }
140 
141  if ((vif->remote_features & VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC)) ==
142  0)
143  {
144  args->rv = VNET_API_ERROR_UNSUPPORTED;
145  args->error = clib_error_return (0, "vhost-net backend doesn't support "
146  "VIRTIO_RING_F_INDIRECT_DESC feature");
147  goto error;
148  }
149 
150  if ((vif->remote_features & VIRTIO_FEATURE (VIRTIO_F_VERSION_1)) == 0)
151  {
152  args->rv = VNET_API_ERROR_UNSUPPORTED;
153  args->error = clib_error_return (0, "vhost-net backend doesn't support "
154  "VIRTIO_F_VERSION_1 features");
155  goto error;
156  }
157 
158  vif->features |= VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF);
159  vif->features |= VIRTIO_FEATURE (VIRTIO_F_VERSION_1);
160  vif->features |= VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC);
161 
163 
164  _IOCTL (vif->fd, VHOST_SET_FEATURES, &vif->features);
165 
166  if ((vif->tap_fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0)
167  {
168  args->rv = VNET_API_ERROR_SYSCALL_ERROR_2;
169  args->error = clib_error_return_unix (0, "open '/dev/net/tun'");
170  goto error;
171  }
172 
173  ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR;
174  _IOCTL (vif->tap_fd, TUNSETIFF, (void *) &ifr);
175  vif->ifindex = if_nametoindex (ifr.ifr_ifrn.ifrn_name);
176 
177  if (!args->host_if_name)
178  args->host_if_name = (u8 *) ifr.ifr_ifrn.ifrn_name;
179 
180  unsigned int offload = 0;
181  hdrsz = sizeof (struct virtio_net_hdr_v1);
182  if (args->tap_flags & TAP_FLAG_GSO)
183  {
184  offload = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6;
185  vif->gso_enabled = 1;
186  }
187  else
188  {
189  vif->gso_enabled = 0;
190  }
191 
192  _IOCTL (vif->tap_fd, TUNSETOFFLOAD, offload);
193  _IOCTL (vif->tap_fd, TUNSETVNETHDRSZ, &hdrsz);
194  _IOCTL (vif->fd, VHOST_SET_OWNER, 0);
195 
196  /* if namespace is specified, all further netlink messages should be excuted
197  after we change our net namespace */
198  if (args->host_namespace)
199  {
200  old_netns_fd = open ("/proc/self/ns/net", O_RDONLY);
201  if ((fd = open_netns_fd ((char *) args->host_namespace)) == -1)
202  {
203  args->rv = VNET_API_ERROR_SYSCALL_ERROR_2;
204  args->error = clib_error_return_unix (0, "open_netns_fd '%s'",
205  args->host_namespace);
206  goto error;
207  }
208  args->error = vnet_netlink_set_link_netns (vif->ifindex, fd,
209  (char *) args->host_if_name);
210  if (args->error)
211  {
212  args->rv = VNET_API_ERROR_NETLINK_ERROR;
213  goto error;
214  }
215  if (setns (fd, CLONE_NEWNET) == -1)
216  {
217  args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
218  args->error = clib_error_return_unix (0, "setns '%s'",
219  args->host_namespace);
220  goto error;
221  }
222  if ((vif->ifindex = if_nametoindex ((char *) args->host_if_name)) == 0)
223  {
224  args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
225  args->error = clib_error_return_unix (0, "if_nametoindex '%s'",
226  args->host_if_name);
227  goto error;
228  }
229  }
230  else
231  {
232  if (args->host_if_name)
233  {
235  (char *)
236  args->host_if_name);
237  if (args->error)
238  {
239  args->rv = VNET_API_ERROR_NETLINK_ERROR;
240  goto error;
241  }
242  }
243  }
244 
246  {
248  args->host_mac_addr);
249  if (args->error)
250  {
251  args->rv = VNET_API_ERROR_NETLINK_ERROR;
252  goto error;
253  }
254  }
255 
256  if (args->host_bridge)
257  {
259  (char *) args->host_bridge);
260  if (args->error)
261  {
262  args->rv = VNET_API_ERROR_NETLINK_ERROR;
263  goto error;
264  }
265  }
266 
267 
268  if (args->host_ip4_prefix_len)
269  {
271  &args->host_ip4_addr,
272  args->host_ip4_prefix_len);
273  if (args->error)
274  {
275  args->rv = VNET_API_ERROR_NETLINK_ERROR;
276  goto error;
277  }
278  }
279 
280  if (args->host_ip6_prefix_len)
281  {
283  &args->host_ip6_addr,
284  args->host_ip6_prefix_len);
285  if (args->error)
286  {
287  args->rv = VNET_API_ERROR_NETLINK_ERROR;
288  goto error;
289  }
290  }
291 
292  args->error = vnet_netlink_set_link_state (vif->ifindex, 1 /* UP */ );
293  if (args->error)
294  {
295  args->rv = VNET_API_ERROR_NETLINK_ERROR;
296  goto error;
297  }
298 
299  if (args->host_ip4_gw_set)
300  {
301  args->error = vnet_netlink_add_ip4_route (0, 0, &args->host_ip4_gw);
302  if (args->error)
303  {
304  args->rv = VNET_API_ERROR_NETLINK_ERROR;
305  goto error;
306  }
307  }
308 
309  if (args->host_ip6_gw_set)
310  {
311  args->error = vnet_netlink_add_ip6_route (0, 0, &args->host_ip6_gw);
312  if (args->error)
313  {
314  args->rv = VNET_API_ERROR_NETLINK_ERROR;
315  goto error;
316  }
317  }
318 
319  /* switch back to old net namespace */
320  if (args->host_namespace)
321  {
322  if (setns (old_netns_fd, CLONE_NEWNET) == -1)
323  {
324  args->rv = VNET_API_ERROR_SYSCALL_ERROR_2;
325  args->error = clib_error_return_unix (0, "setns '%s'",
326  args->host_namespace);
327  goto error;
328  }
329  }
330 
331  /* Set vhost memory table */
332  i = sizeof (struct vhost_memory) + sizeof (struct vhost_memory_region);
333  vhost_mem = clib_mem_alloc (i);
334  clib_memset (vhost_mem, 0, i);
335  vhost_mem->nregions = 1;
336  vhost_mem->regions[0].memory_size = (1ULL << 47) - 4096;
337  _IOCTL (vif->fd, VHOST_SET_MEM_TABLE, vhost_mem);
338 
339  if ((args->error =
340  virtio_vring_init (vm, vif, RX_QUEUE (0), args->rx_ring_sz)))
341  {
342  args->rv = VNET_API_ERROR_INIT_FAILED;
343  goto error;
344  }
345  vif->num_rxqs = 1;
346 
347  if ((args->error =
348  virtio_vring_init (vm, vif, TX_QUEUE (0), args->tx_ring_sz)))
349  {
350  args->rv = VNET_API_ERROR_INIT_FAILED;
351  goto error;
352  }
353  vif->num_txqs = 1;
354 
355  if (!args->mac_addr_set)
357 
358  clib_memcpy (vif->mac_addr, args->mac_addr, 6);
359 
360  vif->host_if_name = args->host_if_name;
361  args->host_if_name = 0;
362  vif->net_ns = args->host_namespace;
363  args->host_namespace = 0;
364  vif->host_bridge = args->host_bridge;
365  args->host_bridge = 0;
366  clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6);
369  if (args->host_ip4_prefix_len)
370  clib_memcpy (&vif->host_ip4_addr, &args->host_ip4_addr, 4);
371  if (args->host_ip6_prefix_len)
372  clib_memcpy (&vif->host_ip6_addr, &args->host_ip6_addr, 16);
373 
374  vif->type = VIRTIO_IF_TYPE_TAP;
376  vif->dev_instance,
377  vif->mac_addr,
378  &vif->hw_if_index,
380  if (args->error)
381  {
382  args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
383  goto error;
384  }
385 
386  tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 1);
387  sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
388  vif->sw_if_index = sw->sw_if_index;
389  args->sw_if_index = vif->sw_if_index;
390  hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
392  if (args->tap_flags & TAP_FLAG_GSO)
393  {
396  }
398  virtio_input_node.index);
402  vif->per_interface_next_index = ~0;
403  virtio_vring_set_numa_node (vm, vif, RX_QUEUE (0));
404  vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
407  vif->cxq_vring = NULL;
408 
409  goto done;
410 
411 error:
412  if (err)
413  {
414  ASSERT (args->error == 0);
415  args->error = err;
416  args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
417  }
418  if (vif->tap_fd != -1)
419  close (vif->tap_fd);
420  if (vif->fd != -1)
421  close (vif->fd);
423  RX_QUEUE (i));
425  TX_QUEUE (i));
426  vec_free (vif->rxq_vrings);
427  vec_free (vif->txq_vrings);
428  clib_memset (vif, 0, sizeof (virtio_if_t));
429  pool_put (vim->interfaces, vif);
430 
431 done:
432  if (vhost_mem)
433  clib_mem_free (vhost_mem);
434  if (old_netns_fd != -1)
435  close (old_netns_fd);
436  if (fd != -1)
437  close (fd);
438 }
439 
440 int
442 {
443  vnet_main_t *vnm = vnet_get_main ();
444  virtio_main_t *mm = &virtio_main;
445  tap_main_t *tm = &tap_main;
446  int i;
447  virtio_if_t *vif;
449 
450  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
451  if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
452  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
453 
454  vif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
455 
456  if (vif->type != VIRTIO_IF_TYPE_TAP)
457  return VNET_API_ERROR_INVALID_INTERFACE;
458 
459  /* decrement if this was a GSO interface */
462 
463  /* bring down the interface */
467 
469  vif->hw_if_index = ~0;
470 
471  if (vif->tap_fd != -1)
472  close (vif->tap_fd);
473  if (vif->fd != -1)
474  close (vif->fd);
475 
477  RX_QUEUE (i));
479  TX_QUEUE (i));
480  vec_free (vif->rxq_vrings);
481  vec_free (vif->txq_vrings);
482 
483  tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 0);
484  clib_memset (vif, 0, sizeof (*vif));
485  pool_put (mm->interfaces, vif);
486 
487  return 0;
488 }
489 
490 int
492 {
493  vnet_main_t *vnm = vnet_get_main ();
494  virtio_main_t *mm = &virtio_main;
495  virtio_if_t *vif;
496  vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
497  clib_error_t *err = 0;
498 
499  if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
500  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
501 
502  vif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
503 
504  const unsigned int gso_on = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6;
505  const unsigned int gso_off = 0;
506  unsigned int offload = enable_disable ? gso_on : gso_off;
507  _IOCTL (vif->tap_fd, TUNSETOFFLOAD, offload);
508  vif->gso_enabled = enable_disable ? 1 : 0;
509  if (enable_disable)
510  {
512  {
515  }
516  }
517  else
518  {
520  {
523  }
524  }
525 
526 error:
527  if (err)
528  {
529  clib_warning ("Error %s gso on sw_if_index %d",
530  enable_disable ? "enabling" : "disabling", sw_if_index);
531  return VNET_API_ERROR_SYSCALL_ERROR_3;
532  }
533  return 0;
534 }
535 
536 int
538 {
539  vnet_main_t *vnm = vnet_get_main ();
540  virtio_main_t *mm = &virtio_main;
541  virtio_if_t *vif;
542  virtio_vring_t *vring;
544  tap_interface_details_t *r_tapids = NULL;
545  tap_interface_details_t *tapid = NULL;
546 
547  /* *INDENT-OFF* */
548  pool_foreach (vif, mm->interfaces,
549  if (vif->type != VIRTIO_IF_TYPE_TAP)
550  continue;
551  vec_add2(r_tapids, tapid, 1);
552  clib_memset (tapid, 0, sizeof (*tapid));
553  tapid->id = vif->id;
554  tapid->sw_if_index = vif->sw_if_index;
555  hi = vnet_get_hw_interface (vnm, vif->hw_if_index);
556  clib_memcpy(tapid->dev_name, hi->name,
557  MIN (ARRAY_LEN (tapid->dev_name) - 1,
558  strlen ((const char *) hi->name)));
559  vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS(0));
560  tapid->rx_ring_sz = vring->size;
561  vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS(0));
562  tapid->tx_ring_sz = vring->size;
563  clib_memcpy(tapid->host_mac_addr, vif->host_mac_addr, 6);
564  if (vif->host_if_name)
565  {
567  MIN (ARRAY_LEN (tapid->host_if_name) - 1,
568  strlen ((const char *) vif->host_if_name)));
569  }
570  if (vif->net_ns)
571  {
572  clib_memcpy(tapid->host_namespace, vif->net_ns,
573  MIN (ARRAY_LEN (tapid->host_namespace) - 1,
574  strlen ((const char *) vif->net_ns)));
575  }
576  if (vif->host_bridge)
577  {
578  clib_memcpy(tapid->host_bridge, vif->host_bridge,
579  MIN (ARRAY_LEN (tapid->host_bridge) - 1,
580  strlen ((const char *) vif->host_bridge)));
581  }
582  if (vif->host_ip4_prefix_len)
583  clib_memcpy(tapid->host_ip4_addr, &vif->host_ip4_addr, 4);
585  if (vif->host_ip6_prefix_len)
586  clib_memcpy(tapid->host_ip6_addr, &vif->host_ip6_addr, 16);
588  );
589  /* *INDENT-ON* */
590 
591  *out_tapids = r_tapids;
592 
593  return 0;
594 }
595 
596 static clib_error_t *
598 {
599  tap_main_t *tm = &tap_main;
600  clib_error_t *error = 0;
601 
602  tm->log_default = vlib_log_register_class ("tap", 0);
603  vlib_log_debug (tm->log_default, "initialized");
604 
605  return error;
606 }
607 
609 
610 /*
611  * fd.io coding-style-patch-verification: ON
612  *
613  * Local Variables:
614  * eval: (c-set-style "gnu")
615  * End:
616  */
u32 per_interface_next_index
Definition: virtio.h:150
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:227
u32 sw_if_index
Definition: ipsec_gre.api:37
vmrglw vmrglh hi
#define vec_foreach_index(var, v)
Iterate over vector indices.
uword * tap_ids
Definition: tap.h:77
#define TAP_FLAG_GSO
Definition: tap.h:33
vlib_node_registration_t virtio_input_node
(constructor) VLIB_REGISTER_NODE (virtio_input_node)
Definition: node.c:384
void virtio_set_net_hdr_size(virtio_if_t *vif)
Definition: virtio.c:257
virtio_if_t * interfaces
Definition: virtio.h:191
u32 flags
Definition: vhost_user.h:115
static u32 virtio_eth_flag_change(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 flags)
Definition: tap.c:52
vlib_log_class_t log_default
Definition: tap.h:74
ip4_address_t host_ip4_addr
Definition: virtio.h:177
u8 host_if_name[64]
Definition: tap.h:62
u8 host_namespace[64]
Definition: tap.h:63
ip4_address_t host_ip4_addr
Definition: tap.h:38
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:324
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
int tap_gso_enable_disable(vlib_main_t *vm, u32 sw_if_index, int enable_disable)
Definition: tap.c:491
vnet_interface_main_t interface_main
Definition: vnet.h:56
int gso_enabled
Definition: virtio.h:181
u32 dev_instance
Definition: virtio.h:139
#define NULL
Definition: clib.h:58
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u8 host_ip6_prefix_len
Definition: tap.h:43
vnet_device_class_t virtio_device_class
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:560
int i
void virtio_vring_set_numa_node(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
Definition: virtio.c:241
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
Definition: bitmap.h:167
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
int tap_dump_ifs(tap_interface_details_t **out_tapids)
Definition: tap.c:537
u8 host_ip4_gw_set
Definition: tap.h:41
unsigned char u8
Definition: types.h:56
clib_error_t * virtio_vring_free_tx(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
Definition: virtio.c:218
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define clib_memcpy(d, s, n)
Definition: string.h:180
u8 host_bridge[64]
Definition: tap.h:64
u8 host_ip6_addr[16]
Definition: tap.h:67
u64 features
Definition: virtio.h:163
u32 hw_if_index
Definition: virtio.h:140
u8 host_mac_addr[6]
Definition: tap.h:61
u8 host_ip6_prefix_len
Definition: virtio.h:180
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
#define TX_QUEUE_ACCESS(X)
Definition: virtio.h:80
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u8 * host_bridge
Definition: virtio.h:175
int ifindex
Definition: virtio.h:182
vnet_hw_interface_flags_t flags
Definition: interface.h:494
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
int tap_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: tap.c:441
#define clib_error_return(e, args...)
Definition: error.h:99
u8 host_mac_addr[6]
Definition: tap.h:36
unsigned int u32
Definition: types.h:88
#define vlib_log_debug(...)
Definition: log.h:52
#define MIN(x, y)
Definition: node.h:31
u32 id
Definition: virtio.h:147
u16 num_txqs
Definition: virtio.h:170
u8 host_ip4_addr[4]
Definition: tap.h:65
#define TX_QUEUE(X)
Definition: virtio.h:78
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
int tap_fd
Definition: virtio.h:158
#define clib_error_return_unix(e, args...)
Definition: error.h:102
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
ip4_address_t host_ip4_gw
Definition: tap.h:40
ip6_address_t host_ip6_addr
Definition: tap.h:42
u8 host_ip4_prefix_len
Definition: tap.h:39
u16 num_rxqs
Definition: virtio.h:169
virtio_vring_t * rxq_vrings
Definition: virtio.h:161
vlib_main_t * vm
Definition: buffer.c:312
#define TAP_MAX_INSTANCE
Definition: tap.c:78
static int open_netns_fd(char *netns)
Definition: tap.c:61
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
ip6_address_t host_ip6_addr
Definition: virtio.h:179
#define clib_warning(format, args...)
Definition: error.h:59
u8 * net_ns
Definition: virtio.h:174
u8 mac_addr[6]
Definition: virtio.h:172
u32 flags
Definition: virtio.h:137
#define ARRAY_LEN(x)
Definition: clib.h:62
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
u8 * host_bridge
Definition: tap.h:37
virtio_if_type_t type
Definition: virtio.h:144
#define ASSERT(truth)
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
Definition: devices.c:139
u64 remote_features
Definition: virtio.h:163
ip6_address_t host_ip6_gw
Definition: tap.h:44
#define VIRTIO_FEATURE(X)
Definition: virtio.h:76
clib_error_t * virtio_vring_init(vlib_main_t *vm, virtio_if_t *vif, u16 idx, u16 sz)
Definition: virtio.c:65
u8 * host_if_name
Definition: tap.h:35
u8 host_mac_addr[6]
Definition: virtio.h:176
static void clib_mem_free(void *p)
Definition: mem.h:205
unsigned int if_nametoindex(const char *ifname)
static void * clib_mem_alloc(uword size)
Definition: mem.h:132
virtio_main_t virtio_main
Definition: virtio.c:37
u8 host_ip6_gw_set
Definition: tap.h:45
void tap_create_if(vlib_main_t *vm, tap_create_if_args_t *args)
Definition: tap.c:81
#define RX_QUEUE_ACCESS(X)
Definition: virtio.h:81
tap_main_t tap_main
Definition: tap.c:42
static void ethernet_mac_address_generate(u8 *mac)
Definition: mac_address.h:74
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:278
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:504
int fd
Definition: virtio.h:153
u8 mac_addr[6]
Definition: tap.h:29
Definition: tap.h:71
clib_error_t * error
Definition: tap.h:49
u8 host_ip4_prefix_len
Definition: virtio.h:178
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.c:188
u32 sw_if_index
Definition: virtio.h:141
virtio_vring_t * cxq_vring
Definition: virtio.h:183
static int ethernet_mac_address_is_zero(const u8 *mac)
Definition: mac_address.h:68
clib_error_t * virtio_vring_free_rx(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
Definition: virtio.c:170
TAP interface details struct.
Definition: tap.h:53
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:513
int vnet_hw_interface_set_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, vnet_hw_interface_rx_mode mode)
Definition: devices.c:253
u8 * host_namespace
Definition: tap.h:34
static uword clib_bitmap_first_clear(uword *ai)
Return the lowest numbered clear bit in a bitmap.
Definition: bitmap.h:445
#define RX_QUEUE(X)
Definition: virtio.h:79
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:79
virtio_vring_t * txq_vrings
Definition: virtio.h:162
static clib_error_t * tap_init(vlib_main_t *vm)
Definition: tap.c:597
u8 * host_if_name
Definition: virtio.h:173