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