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>
29 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 /* Name (a c string). */
42 /* GRE protocol type in host byte order. */
43 gre_protocol_t protocol;
45 /* Node which handles this type. */
48 /* Next index for this type. */
50 } gre_protocol_info_t;
53 ip4_address_t tunnel_src;
54 ip4_address_t tunnel_dst;
60 /* pool of tunnel instances */
61 gre_tunnel_t *tunnels;
63 gre_protocol_info_t * protocol_infos;
65 /* Hash tables mapping name/protocol to protocol info index. */
66 uword * protocol_info_by_name, * protocol_info_by_protocol;
67 /* Hash mapping src/dst addr pair to tunnel */
68 uword * tunnel_by_key;
71 vlib_main_t * vlib_main;
72 vnet_main_t * vnet_main;
75 always_inline gre_protocol_info_t *
76 gre_get_protocol_info (gre_main_t * em, gre_protocol_t protocol)
78 uword * p = hash_get (em->protocol_info_by_protocol, protocol);
79 return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
84 /* Register given node index to take input for given gre type. */
86 gre_register_input_type (vlib_main_t * vm,
87 gre_protocol_t protocol,
90 void gre_set_adjacency (vnet_rewrite_header_t * rw,
92 gre_protocol_t protocol);
94 format_function_t format_gre_protocol;
95 format_function_t format_gre_header;
96 format_function_t format_gre_header_with_length;
98 vlib_node_registration_t gre_input_node;
99 vnet_device_class_t gre_device_class;
101 /* Parse gre protocol as 0xXXXX or protocol name.
102 In either host or network byte order. */
103 unformat_function_t unformat_gre_protocol_host_byte_order;
104 unformat_function_t unformat_gre_protocol_net_byte_order;
106 /* Parse gre header. */
107 unformat_function_t unformat_gre_header;
108 unformat_function_t unformat_pg_gre_header;
111 gre_register_input_protocol (vlib_main_t * vm,
112 gre_protocol_t protocol,
115 /* manually added to the interface output node in gre.c */
116 #define GRE_OUTPUT_NEXT_LOOKUP 1
118 #endif /* included_gre_h */