FD.io VPP  v16.12-rc0-308-g931be3a
Vector Packet Processing
gre.h
Go to the documentation of this file.
1 /*
2  * gre.h: types/functions for gre.
3  *
4  * Copyright (c) 2012 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef included_gre_h
19 #define included_gre_h
20 
21 #include <vnet/vnet.h>
22 #include <vnet/gre/packet.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/ip/ip4.h>
25 #include <vnet/ip/ip4_packet.h>
26 #include <vnet/pg/pg.h>
27 #include <vnet/ip/format.h>
28 #include <vnet/adj/adj_types.h>
29 
31 
32 typedef enum {
33 #define gre_error(n,s) GRE_ERROR_##n,
34 #include <vnet/gre/error.def>
35 #undef gre_error
36  GRE_N_ERROR,
37 } gre_error_t;
38 
39 typedef struct {
40  /* Name (a c string). */
41  char * name;
42 
43  /* GRE protocol type in host byte order. */
45 
46  /* Node which handles this type. */
48 
49  /* Next index for this type. */
52 
53 typedef struct {
54  /**
55  * Linkage into the FIB object graph
56  */
58 
59  /**
60  * The tunnel's source/local address
61  */
63  /**
64  * The tunnel's destination/remote address
65  */
67  /**
68  * The FIB in which the src.dst address are present
69  */
74 
75  /**
76  * The FIB entry sourced by the tunnel for its destination prefix
77  */
79 
80  /**
81  * The tunnel is a child of the FIB entry for its desintion. This is
82  * so it receives updates when the forwarding information for that entry
83  * changes.
84  * The tunnels sibling index on the FIB entry's dependency list.
85  */
87 
88  /**
89  * on a L2 tunnel this is the VLIB arc from the L2-tx to the l2-midchain
90  */
92 
93  /**
94  * an L2 tunnel always rquires an L2 midchain. cache here for DP.
95  */
97 } gre_tunnel_t;
98 
99 typedef struct {
100  /* pool of tunnel instances */
102 
104 
105  /* Hash tables mapping name/protocol to protocol info index. */
106  uword * protocol_info_by_name, * protocol_info_by_protocol;
107  /* Hash mapping src/dst addr pair to tunnel */
109 
110  /* Free vlib hw_if_indices */
112 
113  /* Mapping from sw_if_index to tunnel index */
115 
116  /* convenience */
119 } gre_main_t;
120 
121 /**
122  * @brief IPv4 and GRE header.
123  *
124 */
125 typedef CLIB_PACKED (struct {
126  ip4_header_t ip4;
127  gre_header_t gre;
128 }) ip4_and_gre_header_t;
129 
132 {
133  uword * p = hash_get (em->protocol_info_by_protocol, protocol);
134  return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
135 }
136 
138 
139 /* Register given node index to take input for given gre type. */
140 void
142  gre_protocol_t protocol,
143  u32 node_index);
144 
146  u32 hw_if_index,
147  u32 flags);
148 
149 extern void gre_tunnel_stack (adj_index_t ai);
150 extern void gre_update_adj (vnet_main_t * vnm,
151  u32 sw_if_index,
152  adj_index_t ai);
153 
157 
161 
162 /* Parse gre protocol as 0xXXXX or protocol name.
163  In either host or network byte order. */
166 
167 /* Parse gre header. */
170 
171 void
173  gre_protocol_t protocol,
174  u32 node_index);
175 
176 /* manually added to the interface output node in gre.c */
177 #define GRE_OUTPUT_NEXT_LOOKUP 1
178 
179 typedef struct {
181 
186 
188  (vnet_gre_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
189 
190 #endif /* included_gre_h */
vnet_main_t * vnet_main
Definition: gre.h:118
Definition: gre.h:99
format_function_t format_gre_header_with_length
Definition: gre.h:156
fib_node_index_t fib_entry_index
The FIB entry sourced by the tunnel for its destination prefix.
Definition: gre.h:78
u32 hw_if_index
Definition: gre.h:71
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:231
typedef CLIB_PACKED(struct{ip4_header_t ip4;gre_header_t gre;}) ip4_and_gre_header_t
IPv4 and GRE header.
a
Definition: bitmap.h:516
uword * protocol_info_by_protocol
Definition: gre.h:106
uword * tunnel_by_key
Definition: gre.h:108
gre_protocol_t protocol
Definition: gre.h:44
char * name
Definition: gre.h:41
u32 outer_fib_index
The FIB in which the src.dst address are present.
Definition: gre.h:70
struct _vlib_node_registration vlib_node_registration_t
struct _vnet_device_class vnet_device_class_t
u32 * tunnel_index_by_sw_if_index
Definition: gre.h:114
ip4_address_t tunnel_dst
The tunnel&#39;s destination/remote address.
Definition: gre.h:66
u32 sibling_index
The tunnel is a child of the FIB entry for its desintion.
Definition: gre.h:86
u32 sw_if_index
Definition: gre.h:72
u32 * free_gre_tunnel_hw_if_indices
Definition: gre.h:111
#define always_inline
Definition: clib.h:84
void gre_tunnel_stack(adj_index_t ai)
gre_tunnel_stack
Definition: interface.c:108
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
adj_index_t l2_adj_index
an L2 tunnel always rquires an L2 midchain.
Definition: gre.h:96
unformat_function_t unformat_gre_header
Definition: gre.h:168
#define hash_get(h, key)
Definition: hash.h:248
unformat_function_t unformat_gre_protocol_net_byte_order
Definition: gre.h:165
u32 node_index
Definition: gre.h:47
An node in the FIB graph.
Definition: fib_node.h:242
vnet_device_class_t gre_l2_device_class
format_function_t format_gre_protocol
Definition: gre.h:154
gre_protocol_t
Definition: packet.h:29
ip4_address_t tunnel_src
The tunnel&#39;s source/local address.
Definition: gre.h:62
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
unsigned int u32
Definition: types.h:88
u32 next_index
Definition: gre.h:50
void gre_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
Definition: gre.c:236
gre_tunnel_t * tunnels
Definition: gre.h:101
gre_main_t gre_main
Definition: gre.h:137
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
vnet_hw_interface_class_t gre_hw_interface_class
vlib_node_registration_t gre_input_node
(constructor) VLIB_REGISTER_NODE (gre_input_node)
Definition: node.c:436
u64 uword
Definition: types.h:112
u32 l2_tx_arc
on a L2 tunnel this is the VLIB arc from the L2-tx to the l2-midchain
Definition: gre.h:91
u8 teb
Definition: gre.h:73
fib_node_t node
Linkage into the FIB object graph.
Definition: gre.h:57
vnet_device_class_t gre_device_class
clib_error_t * gre_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:432
int vnet_gre_add_del_tunnel(vnet_gre_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: interface.c:422
struct _vnet_hw_interface_class vnet_hw_interface_class_t
unsigned char u8
Definition: types.h:56
void gre_register_input_type(vlib_main_t *vm, gre_protocol_t protocol, u32 node_index)
unformat_function_t unformat_pg_gre_header
Definition: gre.h:169
void gre_register_input_protocol(vlib_main_t *vm, gre_protocol_t protocol, u32 node_index)
Definition: node.c:462
unformat_function_t unformat_gre_protocol_host_byte_order
Definition: gre.h:164
static gre_protocol_info_t * gre_get_protocol_info(gre_main_t *em, gre_protocol_t protocol)
Definition: gre.h:131
gre_protocol_info_t * protocol_infos
Definition: gre.h:103
vlib_main_t * vlib_main
Definition: gre.h:117
format_function_t format_gre_header
Definition: gre.h:155
u32 flags
Definition: vhost-user.h:75
gre_error_t
Definition: gre.h:32