tap_inject.h revision dfae7756
1/*
2 * Copyright 2016 Intel Corporation
3 *
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#ifndef _TAP_INJECT_H
18#define _TAP_INJECT_H
19
20#include <vnet/plugin/plugin.h>
21#include <vnet/ip/ip.h>
22
23
24#ifndef ETHER_ADDR_LEN
25#define ETHER_ADDR_LEN 6
26#endif
27
28typedef struct {
29  /*
30   * tap-inject can be enabled or disabled in config file or during runtime.
31   * When disabled in config, it is not possible to enable during runtime.
32   *
33   * When the netlink-only option is used, netlink configuration is monitored
34   * and mirrored to the data plane but no traffic is passed between the host
35   * and the data plane.
36   */
37#define TAP_INJECT_F_CONFIG_ENABLE  (1U << 0)
38#define TAP_INJECT_F_CONFIG_DISABLE (1U << 1)
39#define TAP_INJECT_F_CONFIG_NETLINK (1U << 2)
40#define TAP_INJECT_F_ENABLED        (1U << 3)
41
42  u32 flags;
43
44  u32 * sw_if_index_to_tap_fd;
45  u32 * sw_if_index_to_tap_if_index;
46  u32 * tap_fd_to_sw_if_index;
47  u32 * tap_if_index_to_sw_if_index;
48
49  u32 * interfaces_to_enable;
50  u32 * interfaces_to_disable;
51
52  u32 * rx_file_descriptors;
53
54  u32 rx_node_index;
55  u32 tx_node_index;
56  u32 neighbor_node_index;
57
58  u32 * rx_buffers;
59
60} tap_inject_main_t;
61
62
63tap_inject_main_t * tap_inject_get_main (void);
64
65void tap_inject_insert_tap (u32 sw_if_index, u32 tap_fd, u32 tap_if_index);
66void tap_inject_delete_tap (u32 sw_if_index);
67
68u32 tap_inject_lookup_tap_fd (u32 sw_if_index);
69u32 tap_inject_lookup_sw_if_index_from_tap_fd (u32 tap_fd);
70u32 tap_inject_lookup_sw_if_index_from_tap_if_index (u32 tap_if_index);
71
72static inline int
73tap_inject_is_enabled (void)
74{
75  tap_inject_main_t * im = tap_inject_get_main ();
76
77  return !!(im->flags & TAP_INJECT_F_ENABLED);
78}
79
80static inline int
81tap_inject_is_config_enabled (void)
82{
83  tap_inject_main_t * im = tap_inject_get_main ();
84
85  return !!(im->flags & TAP_INJECT_F_CONFIG_ENABLE);
86}
87
88static inline int
89tap_inject_is_config_disabled (void)
90{
91  tap_inject_main_t * im = tap_inject_get_main ();
92
93  return !!(im->flags & TAP_INJECT_F_CONFIG_DISABLE);
94}
95
96
97/* Netlink */
98
99void tap_inject_enable_netlink (void);
100
101
102/* Tap */
103
104clib_error_t * tap_inject_tap_connect (vnet_hw_interface_t * hw);
105clib_error_t * tap_inject_tap_disconnect (u32 sw_if_index);
106
107u8 * format_tap_inject_tap_name (u8 * s, va_list * args);
108
109#endif /* _TAP_INJECT_H */
110