turbotap.h revision adff8bfb
1/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#define _GNU_SOURCE
17
18#include <sys/socket.h>
19#include <vlib/vlib.h>
20
21#ifndef __TURBOTAP_H__
22#define __TURBOTAP_H__
23
24#define TUNGETSOCKFD _IOR('T', 224, int)
25#define MAX_SEND 256
26#define MAX_RECV 256
27
28#define TAP_MTU_DEFAULT 1500
29#define TAP_MTU_MAX 65535
30#define TAP_MTU_MIN 68
31
32#define foreach_turbotap_error                            \
33  /* Must be first. */                                  \
34 _(NONE, "no error")                                    \
35 _(READ, "read error")                                  \
36 _(BUFFER_ALLOCATION, "buffer allocation error")	\
37 _(UNKNOWN, "unknown error")
38
39typedef enum {
40#define _(sym,str) TURBOTAP_ERROR_##sym,
41  foreach_turbotap_error
42#undef _
43   TURBOTAP_N_ERROR,
44 } turbotap_error_t;
45
46typedef struct {
47  u32 unix_fd;
48  u32 unix_file_index;
49  u32 provision_fd;
50  u32 sw_if_index;              /* for counters */
51  u32 hw_if_index;
52  u32 is_promisc;
53  struct ifreq ifr;
54  u32 per_interface_next_index;
55  u8 active;                    /* for delete */
56
57  /* mtu count, mtu buffers */
58  u32 mtu_bytes;
59  u32 mtu_buffers;
60
61  /* turbotap */
62  int turbotap_fd;
63  int sock_fd;
64  int rx_ready;
65  struct mmsghdr rx_msg[MAX_RECV];
66  struct mmsghdr tx_msg[MAX_SEND];
67} turbotap_interface_t;
68
69typedef struct {
70  /* Vector of VLIB rx buffers to use. */
71  u32 * rx_buffers;
72
73  /* record and put back unused rx buffers */
74  u32 * unused_buffer_list;
75
76  /*  Default MTU for newly created turbotap interface. */
77  u32 mtu_bytes;
78
79  /* Vector of tap interfaces */
80  turbotap_interface_t * turbotap_interfaces;
81
82  /* Vector of deleted tap interfaces */
83  u32 * turbotap_inactive_interfaces;
84
85  /* Bitmap of tap interfaces with pending reads */
86  uword * pending_read_bitmap;
87
88  /* Hash table to find turbotap interface given hw_if_index */
89  uword * turbotap_interface_index_by_sw_if_index;
90
91  /* Hash table to find turbotap interface given unix fd */
92  uword * turbotap_interface_index_by_unix_fd;
93
94  /* renumbering table */
95  u32 * show_dev_instance_by_real_dev_instance;
96
97  /* 1 => disable CLI */
98  int is_disabled;
99
100  /* convenience */
101  vlib_main_t * vlib_main;
102  vnet_main_t * vnet_main;
103  unix_main_t * unix_main;
104} turbotap_main_t;
105
106extern vnet_device_class_t turbotap_dev_class;
107extern vlib_node_registration_t turbotap_rx_node;
108extern turbotap_main_t turbotap_main;
109
110int vnet_turbotap_connect(vlib_main_t * vm, u8 * intfc_name, u8 *hwaddr_arg,
111						u32 * sw_if_indexp);
112int vnet_turbotap_delete(vlib_main_t *vm, u32 sw_if_index);
113
114#endif
115