FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
gtpu.h
Go to the documentation of this file.
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/ip/vtep.h>
27 #include <vnet/l2/l2_input.h>
28 #include <vnet/l2/l2_output.h>
29 #include <vnet/l2/l2_bd.h>
30 #include <vnet/ethernet/ethernet.h>
31 #include <vnet/ip/ip4_packet.h>
32 #include <vnet/ip/ip6_packet.h>
33 #include <vnet/udp/udp.h>
34 #include <vnet/dpo/dpo.h>
35 #include <vnet/adj/adj_types.h>
36 #include <vnet/fib/fib_table.h>
37 
38 /**
39  * Bits
40  * Octets 8 7 6 5 4 3 2 1
41  * 1 Version PT (*) E S PN
42  * 2 Message Type
43  * 3 Length (1st Octet)
44  * 4 Length (2nd Octet)
45  * 5 Tunnel Endpoint Identifier (1st Octet)
46  * 6 Tunnel Endpoint Identifier (2nd Octet)
47  * 7 Tunnel Endpoint Identifier (3rd Octet)
48  * 8 Tunnel Endpoint Identifier (4th Octet)
49  * 9 Sequence Number (1st Octet)1) 4)
50  * 10 Sequence Number (2nd Octet)1) 4)
51  * 11 N-PDU Number2) 4)
52  * 12 Next Extension Header Type3) 4)
53 **/
54 
55 typedef struct
56 {
57  u8 ver_flags;
58  u8 type;
59  u16 length; /* length in octets of the data following the fixed part of the header */
60  u32 teid;
65 
66 #define GTPU_V1_HDR_LEN 8
67 
68 #define GTPU_VER_MASK (7<<5)
69 #define GTPU_PT_BIT (1<<4)
70 #define GTPU_E_BIT (1<<2)
71 #define GTPU_S_BIT (1<<1)
72 #define GTPU_PN_BIT (1<<0)
73 #define GTPU_E_S_PN_BIT (7<<0)
74 
75 #define GTPU_V1_VER (1<<5)
76 
77 #define GTPU_PT_GTP (1<<4)
78 #define GTPU_TYPE_GTPU 255
79 
80 /* *INDENT-OFF* */
81 typedef CLIB_PACKED(struct
82 {
83  ip4_header_t ip4; /* 20 bytes */
84  udp_header_t udp; /* 8 bytes */
85  gtpu_header_t gtpu; /* 12 bytes */
87 /* *INDENT-ON* */
88 
89 /* *INDENT-OFF* */
90 typedef CLIB_PACKED(struct
91 {
92  ip6_header_t ip6; /* 40 bytes */
93  udp_header_t udp; /* 8 bytes */
94  gtpu_header_t gtpu; /* 8 bytes */
96 /* *INDENT-ON* */
97 
98 /* *INDENT-OFF* */
99 typedef CLIB_PACKED
100 (struct {
101  /*
102  * Key fields: ip src and gtpu teid on incoming gtpu packet
103  * all fields in NET byte order
104  */
105  union {
106  struct {
107  u32 src;
108  u32 teid;
109  };
110  u64 as_u64;
111  };
112 }) gtpu4_tunnel_key_t;
113 /* *INDENT-ON* */
114 
115 /* *INDENT-OFF* */
116 typedef CLIB_PACKED
117 (struct {
118  /*
119  * Key fields: ip src and gtpu teid on incoming gtpu packet
120  * all fields in NET byte order
121  */
122  ip6_address_t src;
123  u32 teid;
124 }) gtpu6_tunnel_key_t;
125 /* *INDENT-ON* */
126 
127 typedef struct
128 {
129  /* Required for pool_get_aligned */
130  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
131 
132  /* Rewrite string */
134 
135  /* FIB DPO for IP forwarding of gtpu encap packet */
137 
138  /* gtpu local(rx) and remote(tx) TEIDs in HOST byte order */
141 
142  /* tunnel src and dst addresses */
143  ip46_address_t src;
144  ip46_address_t dst;
145 
146  /* mcast packet output intf index (used only if dst is mcast) */
148 
149  /* decap next index */
151 
152  /* The FIB index for src/dst addresses */
154 
155  /* vnet intfc index */
158 
159  /**
160  * Linkage into the FIB object graph
161  */
163 
164  /*
165  * The FIB entry for (depending on gtpu tunnel is unicast or mcast)
166  * sending unicast gtpu encap packets or receiving mcast gtpu packets
167  */
170 
171  /**
172  * The tunnel is a child of the FIB entry for its destination. This is
173  * so it receives updates when the forwarding information for that entry
174  * changes.
175  * The tunnels sibling index on the FIB entry's dependency list.
176  */
178 
179  u32 flow_index; /* infra flow index */
180 } gtpu_tunnel_t;
181 
182 #define foreach_gtpu_input_next \
183 _(DROP, "error-drop") \
184 _(L2_INPUT, "l2-input") \
185 _(IP4_INPUT, "ip4-input") \
186 _(IP6_INPUT, "ip6-input" )
187 
188 typedef enum
189 {
190 #define _(s,n) GTPU_INPUT_NEXT_##s,
192 #undef _
195 
196 typedef enum
197 {
198 #define gtpu_error(n,s) GTPU_ERROR_##n,
199 #include <gtpu/gtpu_error.def>
200 #undef gtpu_error
203 
204 typedef struct
205 {
206  /* vector of encap tunnel instances */
208 
209  /* lookup tunnel by key */
210  uword *gtpu4_tunnel_by_key; /* keyed on ipv4.dst + teid */
211  uword *gtpu6_tunnel_by_key; /* keyed on ipv6.dst + teid */
212 
213  /* local VTEP IPs ref count used by gtpu-bypass node to check if
214  received gtpu packet DIP matches any local VTEP address */
216 
217  /* mcast shared info */
218  uword *mcast_shared; /* keyed on mcast ip46 addr */
219 
220  /* Free vlib hw_if_indices */
222 
223  /* Mapping from sw_if_index to tunnel index */
225 
226  /**
227  * Node type for registering to fib changes.
228  */
230 
231  /* API message ID base */
233 
234  /* convenience */
238 } gtpu_main_t;
239 
240 extern gtpu_main_t gtpu_main;
241 
247 
248 u8 *format_gtpu_encap_trace (u8 * s, va_list * args);
249 
250 typedef struct
251 {
253 #define GTPU_DEL_TUNNEL 0
254 #define GTPU_ADD_TUNNEL 1
255 #define GTPU_UPD_TTEID 2
256  ip46_address_t src, dst;
260  u32 teid; /* local or rx teid */
261  u32 tteid; /* remote or tx teid */
263 
265  (vnet_gtpu_add_mod_del_tunnel_args_t * a, u32 * sw_if_indexp);
266 
267 typedef struct
268 {
272 
275 int vnet_gtpu_add_del_rx_flow (u32 hw_if_index, u32 t_imdex, int is_add);
276 
277 #endif /* included_vnet_gtpu_h */
278 
279 
280 /*
281  * fd.io coding-style-patch-verification: ON
282  *
283  * Local Variables:
284  * eval: (c-set-style "gnu")
285  * End:
286  */
vlib_main_t * vlib_main
Definition: gtpu.h:235
vlib_node_registration_t gtpu4_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu4_encap_node)
Definition: gtpu_encap.c:687
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
vnet_main_t * vnet_main
Definition: gtpu.h:236
a
Definition: bitmap.h:538
u32 teid
Definition: gtpu.h:139
u64 as_u64
Definition: bihash_doc.h:63
unsigned long u64
Definition: types.h:89
u32 * tunnel_index_by_sw_if_index
Definition: gtpu.h:224
fib_node_type_t fib_node_type
Node type for registering to fib changes.
Definition: gtpu.h:229
void vnet_int_gtpu_bypass_mode(u32 sw_if_index, u8 is_ip6, u8 is_enable)
Definition: gtpu.c:945
vl_api_address_t src
Definition: gre.api:54
vlib_node_registration_t gtpu4_flow_input_node
(constructor) VLIB_REGISTER_NODE (gtpu4_flow_input_node)
Definition: gtpu_decap.c:1741
gtpu_input_next_t
Definition: gtpu.h:188
unsigned char u8
Definition: types.h:56
int vnet_gtpu_add_mod_del_tunnel(vnet_gtpu_add_mod_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: gtpu.c:353
dpo_id_t next_dpo
Definition: gtpu.h:136
ip46_address_t src
Definition: gtpu.h:143
vl_api_ip6_address_t ip6
Definition: one.api:424
u16 msg_id_base
Definition: gtpu.h:232
unsigned int u32
Definition: types.h:88
u16 sequence
Definition: gtpu.h:61
bool is_ip6
Definition: ip.api:43
vl_api_fib_path_type_t type
Definition: fib_types.api:123
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
u32 decap_next_index
Definition: gtpu.h:150
unsigned short u16
Definition: types.h:57
u32 tteid
Definition: gtpu.h:140
u32 flow_id_start
Definition: gtpu.h:237
gtpu_input_error_t
Definition: gtpu.h:196
vl_api_ip4_address_t ip4
Definition: one.api:376
adj_index_t mcast_adj_index
Definition: gtpu.h:169
An node in the FIB graph.
Definition: fib_node.h:295
vl_api_address_t dst
Definition: gre.api:55
ip46_address_t dst
Definition: gtpu.h:144
gtpu_main_t gtpu_main
Definition: gtpu.c:36
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
u32 sw_if_index
Definition: gtpu.h:156
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
u32 sibling_index
The tunnel is a child of the FIB entry for its destination.
Definition: gtpu.h:177
#define foreach_gtpu_input_next
Definition: gtpu.h:182
u32 * free_gtpu_tunnel_hw_if_indices
Definition: gtpu.h:221
fib_node_index_t fib_entry_index
Definition: gtpu.h:168
u8 * format_gtpu_encap_trace(u8 *s, va_list *args)
Definition: gtpu.c:52
fib_node_t node
Linkage into the FIB object graph.
Definition: gtpu.h:162
u32 hw_if_index
Definition: gtpu.h:157
u32 encap_fib_index
Definition: gtpu.h:153
u8 pdu_number
Definition: gtpu.h:62
vtep_table_t vtep_table
Definition: gtpu.h:215
uword * gtpu4_tunnel_by_key
Definition: gtpu.h:210
u32 tunnel_index
Definition: gtpu.h:269
vlib_node_registration_t gtpu6_input_node
(constructor) VLIB_REGISTER_NODE (gtpu6_input_node)
Definition: gtpu_decap.c:768
struct _vlib_node_registration vlib_node_registration_t
uword * mcast_shared
Definition: gtpu.h:218
u32 flow_index
Definition: gtpu.h:179
uword * gtpu6_tunnel_by_key
Definition: gtpu.h:211
u64 uword
Definition: types.h:112
vlib_node_registration_t gtpu6_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu6_encap_node)
Definition: gtpu_encap.c:702
Bits Octets 8 7 6 5 4 3 2 1 1 Version PT (*) E S PN 2 Message Type 3 Length (1st Octet) 4 Length...
Definition: mobile.h:90
u8 next_ext_type
Definition: gtpu.h:63
u32 teid
Definition: flow_types.api:182
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
gtpu_tunnel_t * tunnels
Definition: gtpu.h:207
u8 * rewrite
Definition: gtpu.h:133
int vnet_gtpu_add_del_rx_flow(u32 hw_if_index, u32 t_imdex, int is_add)
Definition: gtpu.c:1114
typedef CLIB_PACKED(struct { ip4_header_t ip4;udp_header_t udp;gtpu_header_t gtpu;}) ip4_gtpu_header_t
vlib_node_registration_t gtpu4_input_node
(constructor) VLIB_REGISTER_NODE (gtpu4_input_node)
Definition: gtpu_decap.c:748
u32 mcast_sw_if_index
Definition: gtpu.h:147
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
u32 vnet_gtpu_get_tunnel_index(u32 sw_if_index)
Definition: gtpu.c:1153