FD.io VPP  v19.01.3-6-g70449b9b9
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 ();
85  virtio_main_t *vim = &virtio_main;
86  tap_main_t *tm = &tap_main;
89  int i;
90  int old_netns_fd = -1;
91  struct ifreq ifr;
92  size_t hdrsz;
93  struct vhost_memory *vhost_mem = 0;
94  virtio_if_t *vif = 0;
95  clib_error_t *err = 0;
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 & (1ULL << 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 & (1ULL << VIRTIO_RING_F_INDIRECT_DESC)) == 0)
142  {
143  args->rv = VNET_API_ERROR_UNSUPPORTED;
144  args->error = clib_error_return (0, "vhost-net backend doesn't support "
145  "VIRTIO_RING_F_INDIRECT_DESC feature");
146  goto error;
147  }
148 
149  if ((vif->remote_features & (1ULL << VIRTIO_F_VERSION_1)) == 0)
150  {
151  args->rv = VNET_API_ERROR_UNSUPPORTED;
152  args->error = clib_error_return (0, "vhost-net backend doesn't support "
153  "VIRTIO_F_VERSION_1 features");
154  goto error;
155  }
156 
157  vif->features |= 1ULL << VIRTIO_NET_F_MRG_RXBUF;
158  vif->features |= 1ULL << VIRTIO_F_VERSION_1;
159  vif->features |= 1ULL << VIRTIO_RING_F_INDIRECT_DESC;
160 
161  _IOCTL (vif->fd, VHOST_SET_FEATURES, &vif->features);
162 
163  if ((vif->tap_fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0)
164  {
165  args->rv = VNET_API_ERROR_SYSCALL_ERROR_2;
166  args->error = clib_error_return_unix (0, "open '/dev/net/tun'");
167  goto error;
168  }
169 
170  ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR;
171  _IOCTL (vif->tap_fd, TUNSETIFF, (void *) &ifr);
172  vif->ifindex = if_nametoindex (ifr.ifr_ifrn.ifrn_name);
173 
174  unsigned int offload = 0;
175  hdrsz = sizeof (struct virtio_net_hdr_v1);
176  _IOCTL (vif->tap_fd, TUNSETOFFLOAD, offload);
177  _IOCTL (vif->tap_fd, TUNSETVNETHDRSZ, &hdrsz);
178  _IOCTL (vif->fd, VHOST_SET_OWNER, 0);
179 
180  /* if namespace is specified, all further netlink messages should be excuted
181  after we change our net namespace */
182  if (args->host_namespace)
183  {
184  int fd;
185  int rc;
186  old_netns_fd = open ("/proc/self/ns/net", O_RDONLY);
187  if ((fd = open_netns_fd ((char *) args->host_namespace)) == -1)
188  {
189  args->rv = VNET_API_ERROR_SYSCALL_ERROR_2;
190  args->error = clib_error_return_unix (0, "open_netns_fd '%s'",
191  args->host_namespace);
192  goto error;
193  }
194  args->error = vnet_netlink_set_link_netns (vif->ifindex, fd,
195  (char *) args->host_if_name);
196  if (args->error)
197  {
198  args->rv = VNET_API_ERROR_NETLINK_ERROR;
199  goto error;
200  }
201  rc = setns (fd, CLONE_NEWNET);
202  close (fd);
203  if (rc == -1)
204  {
205  args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
206  args->error = clib_error_return_unix (0, "setns '%s'",
207  args->host_namespace);
208  goto error;
209  }
210  if ((vif->ifindex = if_nametoindex ((char *) args->host_if_name)) == 0)
211  {
212  args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
213  args->error = clib_error_return_unix (0, "if_nametoindex '%s'",
214  args->host_if_name);
215  goto error;
216  }
217  }
218  else
219  {
220  if (args->host_if_name)
221  {
223  (char *)
224  args->host_if_name);
225  if (args->error)
226  {
227  args->rv = VNET_API_ERROR_NETLINK_ERROR;
228  goto error;
229  }
230  }
231  }
232 
234  {
236  args->host_mac_addr);
237  if (args->error)
238  {
239  args->rv = VNET_API_ERROR_NETLINK_ERROR;
240  goto error;
241  }
242  }
243 
244  if (args->host_bridge)
245  {
247  (char *) args->host_bridge);
248  if (args->error)
249  {
250  args->rv = VNET_API_ERROR_NETLINK_ERROR;
251  goto error;
252  }
253  }
254 
255 
256  if (args->host_ip4_prefix_len)
257  {
259  &args->host_ip4_addr,
260  args->host_ip4_prefix_len);
261  if (args->error)
262  {
263  args->rv = VNET_API_ERROR_NETLINK_ERROR;
264  goto error;
265  }
266  }
267 
268  if (args->host_ip6_prefix_len)
269  {
271  &args->host_ip6_addr,
272  args->host_ip6_prefix_len);
273  if (args->error)
274  {
275  args->rv = VNET_API_ERROR_NETLINK_ERROR;
276  goto error;
277  }
278  }
279 
280  args->error = vnet_netlink_set_link_state (vif->ifindex, 1 /* UP */ );
281  if (args->error)
282  {
283  args->rv = VNET_API_ERROR_NETLINK_ERROR;
284  goto error;
285  }
286 
287  if (args->host_ip4_gw_set)
288  {
289  args->error = vnet_netlink_add_ip4_route (0, 0, &args->host_ip4_gw);
290  if (args->error)
291  {
292  args->rv = VNET_API_ERROR_NETLINK_ERROR;
293  goto error;
294  }
295  }
296 
297  if (args->host_ip6_gw_set)
298  {
299  args->error = vnet_netlink_add_ip6_route (0, 0, &args->host_ip6_gw);
300  if (args->error)
301  {
302  args->rv = VNET_API_ERROR_NETLINK_ERROR;
303  goto error;
304  }
305  }
306 
307  /* switch back to old net namespace */
308  if (args->host_namespace)
309  {
310  if (setns (old_netns_fd, CLONE_NEWNET) == -1)
311  {
312  args->rv = VNET_API_ERROR_SYSCALL_ERROR_2;
313  args->error = clib_error_return_unix (0, "setns '%s'",
314  args->host_namespace);
315  goto error;
316  }
317  }
318 
319  /* Set vhost memory table */
320  i = sizeof (struct vhost_memory) + sizeof (struct vhost_memory_region);
321  vhost_mem = clib_mem_alloc (i);
322  clib_memset (vhost_mem, 0, i);
323  vhost_mem->nregions = 1;
324  vhost_mem->regions[0].memory_size = (1ULL << 47) - 4096;
325  _IOCTL (vif->fd, VHOST_SET_MEM_TABLE, vhost_mem);
326 
327  if ((args->error = virtio_vring_init (vm, vif, 0, args->rx_ring_sz)))
328  {
329  args->rv = VNET_API_ERROR_INIT_FAILED;
330  goto error;
331  }
332 
333  if ((args->error = virtio_vring_init (vm, vif, 1, args->tx_ring_sz)))
334  {
335  args->rv = VNET_API_ERROR_INIT_FAILED;
336  goto error;
337  }
338 
339  if (!args->mac_addr_set)
340  {
341  f64 now = vlib_time_now (vm);
342  u32 rnd;
343  rnd = (u32) (now * 1e6);
344  rnd = random_u32 (&rnd);
345 
346  memcpy (args->mac_addr + 2, &rnd, sizeof (rnd));
347  args->mac_addr[0] = 2;
348  args->mac_addr[1] = 0xfe;
349  }
350  vif->rx_ring_sz = args->rx_ring_sz != 0 ? args->rx_ring_sz : 256;
351  vif->tx_ring_sz = args->tx_ring_sz != 0 ? args->tx_ring_sz : 256;
352  vif->host_if_name = args->host_if_name;
353  args->host_if_name = 0;
354  vif->net_ns = args->host_namespace;
355  args->host_namespace = 0;
356  vif->host_bridge = args->host_bridge;
357  args->host_bridge = 0;
358  clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6);
361  if (args->host_ip4_prefix_len)
362  clib_memcpy (&vif->host_ip4_addr, &args->host_ip4_addr, 4);
363  if (args->host_ip6_prefix_len)
364  clib_memcpy (&vif->host_ip6_addr, &args->host_ip6_addr, 16);
365 
367  vif->dev_instance,
368  args->mac_addr,
369  &vif->hw_if_index,
371  if (args->error)
372  {
373  args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
374  goto error;
375  }
376 
377  tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 1);
378  sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
379  vif->sw_if_index = sw->sw_if_index;
380  args->sw_if_index = vif->sw_if_index;
381  hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
384  virtio_input_node.index);
388  vif->per_interface_next_index = ~0;
389  vif->type = VIRTIO_IF_TYPE_TAP;
390  vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
393  if (thm->n_vlib_mains > 1)
394  clib_spinlock_init (&vif->lockp);
395  goto done;
396 
397 error:
398  if (err)
399  {
400  ASSERT (args->error == 0);
401  args->error = err;
402  args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
403  }
404  if (vif->tap_fd != -1)
405  close (vif->tap_fd);
406  if (vif->fd != -1)
407  close (vif->fd);
408  vec_foreach_index (i, vif->vrings) virtio_vring_free (vm, vif, i);
409  vec_free (vif->vrings);
410  clib_memset (vif, 0, sizeof (virtio_if_t));
411  pool_put (vim->interfaces, vif);
412 
413 done:
414  if (vhost_mem)
415  clib_mem_free (vhost_mem);
416  if (old_netns_fd != -1)
417  close (old_netns_fd);
418 }
419 
420 int
422 {
423  vnet_main_t *vnm = vnet_get_main ();
424  virtio_main_t *mm = &virtio_main;
425  tap_main_t *tm = &tap_main;
426  int i;
427  virtio_if_t *vif;
429 
430  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
431  if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
432  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
433 
434  vif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
435 
436  /* bring down the interface */
440 
442  vif->hw_if_index = ~0;
443 
444  if (vif->tap_fd != -1)
445  close (vif->tap_fd);
446  if (vif->fd != -1)
447  close (vif->fd);
448 
449  vec_foreach_index (i, vif->vrings) virtio_vring_free (vm, vif, i);
450  vec_free (vif->vrings);
451 
452  tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 0);
453  clib_spinlock_free (&vif->lockp);
454  clib_memset (vif, 0, sizeof (*vif));
455  pool_put (mm->interfaces, vif);
456 
457  return 0;
458 }
459 
460 int
462 {
463  vnet_main_t *vnm = vnet_get_main ();
464  virtio_main_t *mm = &virtio_main;
465  virtio_if_t *vif;
467  tap_interface_details_t *r_tapids = NULL;
468  tap_interface_details_t *tapid = NULL;
469 
470  /* *INDENT-OFF* */
471  pool_foreach (vif, mm->interfaces,
472  vec_add2(r_tapids, tapid, 1);
473  clib_memset (tapid, 0, sizeof (*tapid));
474  tapid->id = vif->id;
475  tapid->sw_if_index = vif->sw_if_index;
476  hi = vnet_get_hw_interface (vnm, vif->hw_if_index);
477  clib_memcpy(tapid->dev_name, hi->name,
478  MIN (ARRAY_LEN (tapid->dev_name) - 1,
479  strlen ((const char *) hi->name)));
480  tapid->rx_ring_sz = vif->rx_ring_sz;
481  tapid->tx_ring_sz = vif->tx_ring_sz;
482  clib_memcpy(tapid->host_mac_addr, vif->host_mac_addr, 6);
483  if (vif->host_if_name)
484  {
486  MIN (ARRAY_LEN (tapid->host_if_name) - 1,
487  strlen ((const char *) vif->host_if_name)));
488  }
489  if (vif->net_ns)
490  {
491  clib_memcpy(tapid->host_namespace, vif->net_ns,
492  MIN (ARRAY_LEN (tapid->host_namespace) - 1,
493  strlen ((const char *) vif->net_ns)));
494  }
495  if (vif->host_bridge)
496  {
497  clib_memcpy(tapid->host_bridge, vif->host_bridge,
498  MIN (ARRAY_LEN (tapid->host_bridge) - 1,
499  strlen ((const char *) vif->host_bridge)));
500  }
501  if (vif->host_ip4_prefix_len)
502  clib_memcpy(tapid->host_ip4_addr, &vif->host_ip4_addr, 4);
504  if (vif->host_ip6_prefix_len)
505  clib_memcpy(tapid->host_ip6_addr, &vif->host_ip6_addr, 16);
507  );
508  /* *INDENT-ON* */
509 
510  *out_tapids = r_tapids;
511 
512  return 0;
513 }
514 
515 static clib_error_t *
517 {
518  tap_main_t *tm = &tap_main;
519  clib_error_t *error = 0;
520 
521  tm->log_default = vlib_log_register_class ("tap", 0);
522  vlib_log_debug (tm->log_default, "initialized");
523 
524  return error;
525 }
526 
528 
529 /*
530  * fd.io coding-style-patch-verification: ON
531  *
532  * Local Variables:
533  * eval: (c-set-style "gnu")
534  * End:
535  */
u32 per_interface_next_index
Definition: virtio.h:102
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:227
vmrglw vmrglh hi
#define vec_foreach_index(var, v)
Iterate over vector indices.
uword * tap_ids
Definition: tap.h:76
vlib_node_registration_t virtio_input_node
(constructor) VLIB_REGISTER_NODE (virtio_input_node)
Definition: node.c:285
virtio_if_t * interfaces
Definition: virtio.h:126
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:73
ip4_address_t host_ip4_addr
Definition: virtio.h:116
u8 host_if_name[64]
Definition: tap.h:61
u8 host_namespace[64]
Definition: tap.h:62
ip4_address_t host_ip4_addr
Definition: tap.h:37
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:323
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)
u32 dev_instance
Definition: virtio.h:99
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:232
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:42
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:564
int i
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
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
virtio_vring_t * vrings
Definition: virtio.h:105
#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:461
u8 host_ip4_gw_set
Definition: tap.h:40
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
static void clib_spinlock_free(clib_spinlock_t *p)
Definition: lock.h:64
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:63
u8 host_ip6_addr[16]
Definition: tap.h:66
u64 features
Definition: virtio.h:107
u32 hw_if_index
Definition: virtio.h:100
u8 host_mac_addr[6]
Definition: tap.h:60
u8 host_ip6_prefix_len
Definition: virtio.h:119
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:490
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u8 * host_bridge
Definition: virtio.h:114
u32 sw_if_index
Definition: vxlan_gbp.api:37
int ifindex
Definition: virtio.h:121
vnet_hw_interface_flags_t flags
Definition: interface.h:516
int tap_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: tap.c:421
#define clib_error_return(e, args...)
Definition: error.h:99
static int ethernet_mac_address_is_zero(const u8 *mac)
Definition: ethernet.h:91
u8 host_mac_addr[6]
Definition: tap.h:35
unsigned int u32
Definition: types.h:88
#define vlib_log_debug(...)
Definition: log.h:54
#define MIN(x, y)
Definition: node.h:31
u32 id
Definition: virtio.h:98
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:57
u8 host_ip4_addr[4]
Definition: tap.h:64
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
int tap_fd
Definition: virtio.h:104
#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
u16 tx_ring_sz
Definition: virtio.h:110
ip4_address_t host_ip4_gw
Definition: tap.h:39
clib_spinlock_t lockp
Definition: virtio.h:96
ip6_address_t host_ip6_addr
Definition: tap.h:41
u8 host_ip4_prefix_len
Definition: tap.h:38
vlib_main_t * vm
Definition: buffer.c:301
#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:118
u8 * net_ns
Definition: virtio.h:113
u32 flags
Definition: virtio.h:95
#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
u16 rx_ring_sz
Definition: virtio.h:111
u8 * host_bridge
Definition: tap.h:36
virtio_if_type_t type
Definition: virtio.h:109
#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:107
ip6_address_t host_ip6_gw
Definition: tap.h:43
clib_error_t * virtio_vring_init(vlib_main_t *vm, virtio_if_t *vif, u16 idx, u16 sz)
Definition: virtio.c:63
u8 * host_if_name
Definition: tap.h:34
u8 host_mac_addr[6]
Definition: virtio.h:115
static void clib_mem_free(void *p)
Definition: mem.h:205
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
Definition: interface.c:277
clib_error_t * virtio_vring_free(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
Definition: virtio.c:155
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:35
u8 host_ip6_gw_set
Definition: tap.h:44
void tap_create_if(vlib_main_t *vm, tap_create_if_args_t *args)
Definition: tap.c:81
tap_main_t tap_main
Definition: tap.c:42
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:103
u8 mac_addr[6]
Definition: tap.h:29
Definition: tap.h:70
clib_error_t * error
Definition: tap.h:48
u8 host_ip4_prefix_len
Definition: virtio.h:117
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:101
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
TAP interface details struct.
Definition: tap.h:52
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
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
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:33
static uword clib_bitmap_first_clear(uword *ai)
Return the lowest numbered clear bit in a bitmap.
Definition: bitmap.h:445
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:79
static clib_error_t * tap_init(vlib_main_t *vm)
Definition: tap.c:516
u8 * host_if_name
Definition: virtio.h:112