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/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>
30 extern vnet_hw_interface_class_t gre_hw_interface_class;
33 #define gre_error(n,s) GRE_ERROR_##n,
34 #include <vnet/gre/error.def>
40 /* Name (a c string). */
43 /* GRE protocol type in host byte order. */
44 gre_protocol_t protocol;
46 /* Node which handles this type. */
49 /* Next index for this type. */
51 } gre_protocol_info_t;
55 * Linkage into the FIB object graph
60 * The tunnel's source/local address
62 ip4_address_t tunnel_src;
64 * The tunnel's destination/remote address
66 ip4_address_t tunnel_dst;
68 * The FIB in which the src.dst address are present
76 * The FIB entry sourced by the tunnel for its destination prefix
78 fib_node_index_t fib_entry_index;
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
84 * The tunnels sibling index on the FIB entry's dependency list.
89 * The index of the midchain adjacency created for this tunnel
91 adj_index_t adj_index[FIB_LINK_NUM];
95 /* pool of tunnel instances */
96 gre_tunnel_t *tunnels;
98 gre_protocol_info_t * protocol_infos;
100 /* Hash tables mapping name/protocol to protocol info index. */
101 uword * protocol_info_by_name, * protocol_info_by_protocol;
102 /* Hash mapping src/dst addr pair to tunnel */
103 uword * tunnel_by_key;
105 /* Free vlib hw_if_indices */
106 u32 * free_gre_tunnel_hw_if_indices;
108 /* Mapping from sw_if_index to tunnel index */
109 u32 * tunnel_index_by_sw_if_index;
112 vlib_main_t * vlib_main;
113 vnet_main_t * vnet_main;
117 * @brief IPv4 and GRE header.
120 typedef CLIB_PACKED (struct {
123 }) ip4_and_gre_header_t;
125 always_inline gre_protocol_info_t *
126 gre_get_protocol_info (gre_main_t * em, gre_protocol_t protocol)
128 uword * p = hash_get (em->protocol_info_by_protocol, protocol);
129 return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
134 /* Register given node index to take input for given gre type. */
136 gre_register_input_type (vlib_main_t * vm,
137 gre_protocol_t protocol,
140 void gre_set_adjacency (vnet_rewrite_header_t * rw,
141 uword max_data_bytes,
142 gre_protocol_t protocol);
144 format_function_t format_gre_protocol;
145 format_function_t format_gre_header;
146 format_function_t format_gre_header_with_length;
148 extern vlib_node_registration_t gre_input_node;
149 extern vnet_device_class_t gre_device_class;
151 /* Parse gre protocol as 0xXXXX or protocol name.
152 In either host or network byte order. */
153 unformat_function_t unformat_gre_protocol_host_byte_order;
154 unformat_function_t unformat_gre_protocol_net_byte_order;
156 /* Parse gre header. */
157 unformat_function_t unformat_gre_header;
158 unformat_function_t unformat_pg_gre_header;
161 gre_register_input_protocol (vlib_main_t * vm,
162 gre_protocol_t protocol,
165 /* manually added to the interface output node in gre.c */
166 #define GRE_OUTPUT_NEXT_LOOKUP 1
171 ip4_address_t src, dst;
174 } vnet_gre_add_del_tunnel_args_t;
176 int vnet_gre_add_del_tunnel
177 (vnet_gre_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
179 #endif /* included_gre_h */