2 * gre.h: types/functions for gre.
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef included_gre_h
19 #define included_gre_h
21 #include <vnet/vnet.h>
22 #include <vnet/gre/packet.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/pg/pg.h>
25 #include <vnet/ip/format.h>
26 #include <vnet/adj/adj_types.h>
28 extern vnet_hw_interface_class_t gre_hw_interface_class;
32 #define gre_error(n,s) GRE_ERROR_##n,
33 #include <vnet/gre/error.def>
39 * A GRE payload protocol registration
43 /** Name (a c string). */
46 /** GRE protocol type in host byte order. */
47 gre_protocol_t protocol;
49 /** Node which handles this type. */
52 /** Next index for this type. */
54 } gre_protocol_info_t;
57 * @brief The GRE tunnel type
59 typedef enum gre_tunnel_tyoe_t_
62 * L3 GRE (i.e. this tunnel is in L3 mode)
66 * Transparent Ethernet Bridging - the tunnel is in L2 mode
71 #define GRE_TUNNEL_TYPE_NAMES { \
72 [GRE_TUNNEL_TYPE_L3] = "L3", \
73 [GRE_TUNNEL_TYPE_TEB] = "TEB", \
76 #define GRE_TUNNEL_N_TYPES ((gre_tunnel_type_t)GRE_TUNNEL_TYPE_TEB+1)
79 * @brief A representation of a GRE tunnel
84 * Linkage into the FIB object graph
89 * The tunnel's source/local address
91 ip46_address_t tunnel_src;
93 * The tunnel's destination/remote address
95 fib_prefix_t tunnel_dst;
97 * The FIB in which the src.dst address are present
102 gre_tunnel_type_t type;
105 * The FIB entry sourced by the tunnel for its destination prefix
107 fib_node_index_t fib_entry_index;
110 * The tunnel is a child of the FIB entry for its desintion. This is
111 * so it receives updates when the forwarding information for that entry
113 * The tunnels sibling index on the FIB entry's dependency list.
118 * on a L2 tunnel this is the VLIB arc from the L2-tx to the l2-midchain
123 * an L2 tunnel always rquires an L2 midchain. cache here for DP.
125 adj_index_t l2_adj_index;
129 * @brief GRE related global data
134 * pool of tunnel instances
136 gre_tunnel_t *tunnels;
139 * GRE payload protocol registrations
141 gre_protocol_info_t *protocol_infos;
144 * Hash tables mapping name/protocol to protocol info index.
146 uword *protocol_info_by_name, *protocol_info_by_protocol;
149 * Hash mapping ipv4 src/dst addr pair to tunnel
151 uword *tunnel_by_key4;
154 * Hash mapping ipv6 src/dst addr pair to tunnel
156 uword *tunnel_by_key6;
159 * Free vlib hw_if_indices.
160 * A free list per-tunnel type since the interfaces ctreated are fo different
161 * types and we cannot change the type.
163 u32 *free_gre_tunnel_hw_if_indices[GRE_TUNNEL_N_TYPES];
166 * Mapping from sw_if_index to tunnel index
168 u32 *tunnel_index_by_sw_if_index;
170 /* Sparse vector mapping gre protocol in network byte order
172 u16 *next_by_protocol;
175 vlib_main_t *vlib_main;
176 vnet_main_t *vnet_main;
180 * @brief IPv4 and GRE header.
183 typedef CLIB_PACKED (struct {
186 }) ip4_and_gre_header_t;
190 * @brief IPv6 and GRE header.
193 typedef CLIB_PACKED (struct {
196 }) ip6_and_gre_header_t;
199 always_inline gre_protocol_info_t *
200 gre_get_protocol_info (gre_main_t * em, gre_protocol_t protocol)
202 uword *p = hash_get (em->protocol_info_by_protocol, protocol);
203 return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
206 extern gre_main_t gre_main;
208 /* Register given node index to take input for given gre type. */
210 gre_register_input_type (vlib_main_t * vm,
211 gre_protocol_t protocol, u32 node_index);
213 extern clib_error_t *gre_interface_admin_up_down (vnet_main_t * vnm,
214 u32 hw_if_index, u32 flags);
216 extern void gre_tunnel_stack (adj_index_t ai);
217 extern void gre_update_adj (vnet_main_t * vnm,
218 u32 sw_if_index, adj_index_t ai);
220 format_function_t format_gre_protocol;
221 format_function_t format_gre_header;
222 format_function_t format_gre_header_with_length;
224 extern vlib_node_registration_t gre4_input_node;
225 extern vlib_node_registration_t gre6_input_node;
226 extern vnet_device_class_t gre_device_class;
227 extern vnet_device_class_t gre_device_teb_class;
229 /* Parse gre protocol as 0xXXXX or protocol name.
230 In either host or network byte order. */
231 unformat_function_t unformat_gre_protocol_host_byte_order;
232 unformat_function_t unformat_gre_protocol_net_byte_order;
234 /* Parse gre header. */
235 unformat_function_t unformat_gre_header;
236 unformat_function_t unformat_pg_gre_header;
239 gre_register_input_protocol (vlib_main_t * vm,
240 gre_protocol_t protocol, u32 node_index);
242 /* manually added to the interface output node in gre.c */
243 #define GRE_OUTPUT_NEXT_LOOKUP 1
249 ip46_address_t src, dst;
253 } vnet_gre_add_del_tunnel_args_t;
255 int vnet_gre_add_del_tunnel
256 (vnet_gre_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
258 #endif /* included_gre_h */
261 * fd.io coding-style-patch-verification: ON
264 * eval: (c-set-style "gnu")