ad599d2f09e2f16a4d5835f6017f8c2eba4fd400
[vpp.git] / vnet / vnet / gre / gre.h
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
29 extern vnet_hw_interface_class_t gre_hw_interface_class;
30
31 typedef enum {
32 #define gre_error(n,s) GRE_ERROR_##n,
33 #include <vnet/gre/error.def>
34 #undef gre_error
35   GRE_N_ERROR,
36 } gre_error_t;
37
38 typedef struct {
39   /* Name (a c string). */
40   char * name;
41
42   /* GRE protocol type in host byte order. */
43   gre_protocol_t protocol;
44
45   /* Node which handles this type. */
46   u32 node_index;
47
48   /* Next index for this type. */
49   u32 next_index;
50 } gre_protocol_info_t;
51
52 typedef struct {
53   ip4_address_t tunnel_src;
54   ip4_address_t tunnel_dst;
55   u32 outer_fib_index;
56   u32 hw_if_index;
57   u32 sw_if_index;
58   u8 teb;
59 } gre_tunnel_t;
60
61 typedef struct {
62   /* pool of tunnel instances */
63   gre_tunnel_t *tunnels;
64
65   gre_protocol_info_t * protocol_infos;
66
67   /* Hash tables mapping name/protocol to protocol info index. */
68   uword * protocol_info_by_name, * protocol_info_by_protocol;
69   /* Hash mapping src/dst addr pair to tunnel */
70   uword * tunnel_by_key;
71
72   /* Free vlib hw_if_indices */
73   u32 * free_gre_tunnel_hw_if_indices;
74
75   /* Mapping from sw_if_index to tunnel index */
76   u32 * tunnel_index_by_sw_if_index;
77
78   /* convenience */
79   vlib_main_t * vlib_main;
80   vnet_main_t * vnet_main;
81 } gre_main_t;
82
83 always_inline gre_protocol_info_t *
84 gre_get_protocol_info (gre_main_t * em, gre_protocol_t protocol)
85 {
86   uword * p = hash_get (em->protocol_info_by_protocol, protocol);
87   return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
88 }
89
90 gre_main_t gre_main;
91
92 /* Register given node index to take input for given gre type. */
93 void
94 gre_register_input_type (vlib_main_t * vm,
95                          gre_protocol_t protocol,
96                          u32 node_index);
97
98 void gre_set_adjacency (vnet_rewrite_header_t * rw,
99                         uword max_data_bytes,
100                         gre_protocol_t protocol);
101
102 format_function_t format_gre_protocol;
103 format_function_t format_gre_header;
104 format_function_t format_gre_header_with_length;
105
106 extern vlib_node_registration_t gre_input_node;
107 extern vnet_device_class_t gre_device_class;
108
109 /* Parse gre protocol as 0xXXXX or protocol name.
110    In either host or network byte order. */
111 unformat_function_t unformat_gre_protocol_host_byte_order;
112 unformat_function_t unformat_gre_protocol_net_byte_order;
113
114 /* Parse gre header. */
115 unformat_function_t unformat_gre_header;
116 unformat_function_t unformat_pg_gre_header;
117
118 void
119 gre_register_input_protocol (vlib_main_t * vm,
120                              gre_protocol_t protocol,
121                              u32 node_index);
122
123 /* manually added to the interface output node in gre.c */
124 #define GRE_OUTPUT_NEXT_LOOKUP  1
125
126 typedef struct {
127   u8 is_add;
128
129   ip4_address_t src, dst;
130   u32 outer_fib_id;
131   u8 teb;
132 } vnet_gre_add_del_tunnel_args_t;
133
134 int vnet_gre_add_del_tunnel
135   (vnet_gre_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
136
137 #endif /* included_gre_h */