Add extern to *_main global variable declarations in header files.
[vpp.git] / src / plugins / gtpu / gtpu.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Intel and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef included_vnet_gtpu_h
19 #define included_vnet_gtpu_h
20
21 #include <vppinfra/lock.h>
22 #include <vppinfra/error.h>
23 #include <vppinfra/hash.h>
24 #include <vnet/vnet.h>
25 #include <vnet/ip/ip.h>
26 #include <vnet/l2/l2_input.h>
27 #include <vnet/l2/l2_output.h>
28 #include <vnet/l2/l2_bd.h>
29 #include <vnet/ethernet/ethernet.h>
30 #include <vnet/ip/ip4_packet.h>
31 #include <vnet/ip/ip6_packet.h>
32 #include <vnet/udp/udp.h>
33 #include <vnet/dpo/dpo.h>
34 #include <vnet/adj/adj_types.h>
35 #include <vnet/fib/fib_table.h>
36
37 /**
38  *              Bits
39  * Octets       8       7       6       5       4       3       2       1
40  * 1                      Version       PT      (*)     E       S       PN
41  * 2            Message Type
42  * 3            Length (1st Octet)
43  * 4            Length (2nd Octet)
44  * 5            Tunnel Endpoint Identifier (1st Octet)
45  * 6            Tunnel Endpoint Identifier (2nd Octet)
46  * 7            Tunnel Endpoint Identifier (3rd Octet)
47  * 8            Tunnel Endpoint Identifier (4th Octet)
48  * 9            Sequence Number (1st Octet)1) 4)
49  * 10           Sequence Number (2nd Octet)1) 4)
50  * 11           N-PDU Number2) 4)
51  * 12           Next Extension Header Type3) 4)
52 **/
53
54 typedef struct
55 {
56   u8 ver_flags;
57   u8 type;
58   u16 length;                   /* length in octets of the payload */
59   u32 teid;
60   u16 sequence;
61   u8 pdu_number;
62   u8 next_ext_type;
63 } gtpu_header_t;
64
65 #define GTPU_VER_MASK (7<<5)
66 #define GTPU_PT_BIT   (1<<4)
67 #define GTPU_E_BIT    (1<<2)
68 #define GTPU_S_BIT    (1<<1)
69 #define GTPU_PN_BIT   (1<<0)
70 #define GTPU_E_S_PN_BIT  (7<<0)
71
72 #define GTPU_V1_VER   (1<<5)
73
74 #define GTPU_PT_GTP    (1<<4)
75 #define GTPU_TYPE_GTPU  255
76
77 /* *INDENT-OFF* */
78 typedef CLIB_PACKED(struct
79 {
80   ip4_header_t ip4;            /* 20 bytes */
81   udp_header_t udp;            /* 8 bytes */
82   gtpu_header_t gtpu;          /* 8 bytes */
83 }) ip4_gtpu_header_t;
84 /* *INDENT-ON* */
85
86 /* *INDENT-OFF* */
87 typedef CLIB_PACKED(struct
88 {
89   ip6_header_t ip6;            /* 40 bytes */
90   udp_header_t udp;            /* 8 bytes */
91   gtpu_header_t gtpu;     /* 8 bytes */
92 }) ip6_gtpu_header_t;
93 /* *INDENT-ON* */
94
95 /* *INDENT-OFF* */
96 typedef CLIB_PACKED
97 (struct {
98   /*
99    * Key fields: ip src and gtpu teid on incoming gtpu packet
100    * all fields in NET byte order
101    */
102   union {
103     struct {
104       u32 src;
105       u32 teid;
106     };
107     u64 as_u64;
108   };
109 }) gtpu4_tunnel_key_t;
110 /* *INDENT-ON* */
111
112 /* *INDENT-OFF* */
113 typedef CLIB_PACKED
114 (struct {
115   /*
116    * Key fields: ip src and gtpu teid on incoming gtpu packet
117    * all fields in NET byte order
118    */
119   ip6_address_t src;
120   u32 teid;
121 }) gtpu6_tunnel_key_t;
122 /* *INDENT-ON* */
123
124 typedef struct
125 {
126   /* Rewrite string */
127   u8 *rewrite;
128
129   /* FIB DPO for IP forwarding of gtpu encap packet */
130   dpo_id_t next_dpo;
131
132   /* gtpu teid in HOST byte order */
133   u32 teid;
134
135   /* tunnel src and dst addresses */
136   ip46_address_t src;
137   ip46_address_t dst;
138
139   /* mcast packet output intf index (used only if dst is mcast) */
140   u32 mcast_sw_if_index;
141
142   /* decap next index */
143   u32 decap_next_index;
144
145   /* The FIB index for src/dst addresses */
146   u32 encap_fib_index;
147
148   /* vnet intfc index */
149   u32 sw_if_index;
150   u32 hw_if_index;
151
152   /**
153    * Linkage into the FIB object graph
154    */
155   fib_node_t node;
156
157   /*
158    * The FIB entry for (depending on gtpu tunnel is unicast or mcast)
159    * sending unicast gtpu encap packets or receiving mcast gtpu packets
160    */
161   fib_node_index_t fib_entry_index;
162   adj_index_t mcast_adj_index;
163
164   /**
165    * The tunnel is a child of the FIB entry for its destination. This is
166    * so it receives updates when the forwarding information for that entry
167    * changes.
168    * The tunnels sibling index on the FIB entry's dependency list.
169    */
170   u32 sibling_index;
171 } gtpu_tunnel_t;
172
173 #define foreach_gtpu_input_next        \
174 _(DROP, "error-drop")                  \
175 _(L2_INPUT, "l2-input")                \
176 _(IP4_INPUT,  "ip4-input")             \
177 _(IP6_INPUT, "ip6-input" )
178
179 typedef enum
180 {
181 #define _(s,n) GTPU_INPUT_NEXT_##s,
182   foreach_gtpu_input_next
183 #undef _
184     GTPU_INPUT_N_NEXT,
185 } gtpu_input_next_t;
186
187 typedef enum
188 {
189 #define gtpu_error(n,s) GTPU_ERROR_##n,
190 #include <gtpu/gtpu_error.def>
191 #undef gtpu_error
192   GTPU_N_ERROR,
193 } gtpu_input_error_t;
194
195 typedef struct
196 {
197   /* vector of encap tunnel instances */
198   gtpu_tunnel_t *tunnels;
199
200   /* lookup tunnel by key */
201   uword *gtpu4_tunnel_by_key;   /* keyed on ipv4.dst + teid */
202   uword *gtpu6_tunnel_by_key;   /* keyed on ipv6.dst + teid */
203
204   /* local VTEP IPs ref count used by gtpu-bypass node to check if
205      received gtpu packet DIP matches any local VTEP address */
206   uword *vtep4;                 /* local ip4 VTEPs keyed on their ip4 addr */
207   uword *vtep6;                 /* local ip6 VTEPs keyed on their ip6 addr */
208
209   /* mcast shared info */
210   uword *mcast_shared;          /* keyed on mcast ip46 addr */
211
212   /* Free vlib hw_if_indices */
213   u32 *free_gtpu_tunnel_hw_if_indices;
214
215   /* Mapping from sw_if_index to tunnel index */
216   u32 *tunnel_index_by_sw_if_index;
217
218   /**
219    * Node type for registering to fib changes.
220    */
221   fib_node_type_t fib_node_type;
222
223   /* API message ID base */
224   u16 msg_id_base;
225
226   /* convenience */
227   vlib_main_t *vlib_main;
228   vnet_main_t *vnet_main;
229 } gtpu_main_t;
230
231 extern gtpu_main_t gtpu_main;
232
233 extern vlib_node_registration_t gtpu4_input_node;
234 extern vlib_node_registration_t gtpu6_input_node;
235 extern vlib_node_registration_t gtpu4_encap_node;
236 extern vlib_node_registration_t gtpu6_encap_node;
237
238 u8 *format_gtpu_encap_trace (u8 * s, va_list * args);
239
240 typedef struct
241 {
242   u8 is_add;
243   u8 is_ip6;
244   ip46_address_t src, dst;
245   u32 mcast_sw_if_index;
246   u32 encap_fib_index;
247   u32 decap_next_index;
248   u32 teid;
249 } vnet_gtpu_add_del_tunnel_args_t;
250
251 int vnet_gtpu_add_del_tunnel
252   (vnet_gtpu_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
253
254 void vnet_int_gtpu_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable);
255 #endif /* included_vnet_gtpu_h */
256
257
258 /*
259  * fd.io coding-style-patch-verification: ON
260  *
261  * Local Variables:
262  * eval: (c-set-style "gnu")
263  * End:
264  */