udp: fix csum computation when offload disabled
[vpp.git] / src / plugins / srv6-mobile / mobile.h
1 /*
2  * srv6_end.h
3  *
4  * Copyright (c) 2019 Arrcus Inc 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_srv6_end_h__
19 #define __included_srv6_end_h__
20
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/fib/ip4_fib.h>
24 #include <vnet/fib/ip6_fib.h>
25 #include <vnet/srv6/sr.h>
26 #include <vnet/srv6/sr_packet.h>
27
28 #include <vppinfra/error.h>
29 #include <vppinfra/elog.h>
30
31 #define SRV6_GTP_UDP_DST_PORT 2152
32
33 #define SRV6_NHTYPE_NONE        0
34 #define SRV6_NHTYPE_IPV4        1
35 #define SRV6_NHTYPE_IPV6        2
36 #define SRV6_NHTYPE_NON_IP      3
37
38 #ifndef IP_PROTOCOL_IP6_ETHERNET
39 #define IP_PROTOCOL_IP6_ETHERNET        143
40 #endif
41
42 #define SRV6_GTP6_UNKNOW        0
43 #define SRV6_GTP6_DT4           1
44 #define SRV6_GTP6_DT6           2
45 #define SRV6_GTP6_DT46          3
46
47 #define SRV6_GTP4_UNKNOW        0
48 #define SRV6_GTP4_DT4           1
49 #define SRV6_GTP4_DT6           2
50 #define SRV6_GTP4_DT46          3
51
52 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
53 #define BITALIGN2(A,B)          A; B
54 #define BITALIGN3(A,B,C)        A; B; C
55 #else
56 #define BITALIGN2(A,B)          B; A
57 #define BITALIGN3(A,B,C)        C; B; A
58 #endif
59
60 #define GTPU_EXTHDR_FLAG                0x04
61 #define GTPU_SEQ_FLAG                   0x02
62 #define GTPU_EXTHDR_PDU_SESSION         0x85
63
64 #define SRH_TAG_ECHO_REPLY              0x0008
65 #define SRH_TAG_ECHO_REQUEST            0x0004
66 #define SRH_TAG_ERROR_INDICATION        0x0002
67 #define SRH_TAG_END_MARKER              0x0001
68
69 #define GTPU_RECOVERY_IE_TYPE           0x0e
70
71 #define GTPU_IE_MAX_SIZ                 256
72 #define SRH_TLV_USER_PLANE_CONTAINER    0x0a    /* tentative */
73
74 typedef enum mobile_policy_function_list
75 {
76   SRV6_MOBILE_POLICY_UNKNOWN_FUNCTION = 0,
77   SRV6_MOBILE_POLICY_T_M_GTP4_D,
78   SRV6_MOBILE_POLICY_T_M_GTP4_DT4,
79   SRV6_MOBILE_POLICY_T_M_GTP4_DT6,
80   SRV6_MOBILE_POLICY_T_M_GTP4_DT46,
81   SRV6_MOBILE_POLICY_END_M_GTP6_D,
82 } mobile_policy_function_list_t;
83
84 typedef enum mobile_localsid_function_list
85 {
86   SRV6_MOBILE_LOCALSID_UNKNOWN_FUNCTION = 0,
87   SRV6_MOBILE_LOCALSID_END_M_GTP4_E,
88   SRV6_MOBILE_LOCALSID_END_M_GTP6_E,
89   SRV6_MOBILE_LOCALSID_END_M_GTP6_D,
90   SRV6_MOBILE_LOCALSID_END_M_GTP6_D_DI,
91   SRV6_MOBILE_LOCALSID_END_M_GTP6_D_DT4,
92   SRV6_MOBILE_LOCALSID_END_M_GTP6_D_DT6,
93   SRV6_MOBILE_LOCALSID_END_M_GTP6_D_DT46,
94 } mobile_localsid_function_list_t;
95
96 typedef struct
97 {
98   u8 type;
99   u8 restart_counter;
100 } __attribute__ ((packed)) gtpu_recovery_ie;
101
102 typedef struct
103 {
104   u16 seq;
105   u8 npdu_num;
106   u8 nextexthdr;
107 } __attribute__ ((packed)) gtpu_exthdr_t;
108
109 typedef struct
110 {
111   u8 ver_flags;
112   u8 type;
113   u16 length;     /* length in octets of the payload */
114   u32 teid;
115   gtpu_exthdr_t ext[0];
116 } __attribute__ ((packed)) gtpu_header_t;
117
118 #define GTPU_TYPE_ECHO_REQUEST          1
119 #define GTPU_TYPE_ECHO_REPLY            2
120 #define GTPU_TYPE_ERROR_INDICATION      26
121 #define GTPU_TYPE_END_MARKER            254
122 #define GTPU_TYPE_GTPU                  255
123
124 typedef struct
125 {
126   BITALIGN2 (u8 ppi:3,
127              u8 spare:5);
128
129   u8 padding[3];
130 } __attribute__ ((packed)) gtpu_paging_policy_t;
131
132 typedef struct
133 {
134   u8 exthdrlen;
135   BITALIGN2(u8 type:4,
136             u8 spare:4);
137   union {
138     struct gtpu_qfi_bits {BITALIGN3(u8 p:1,
139                                     u8 r:1,
140                                     u8 qfi:6);
141     } bits;
142
143     u8 val;
144   } u;
145
146   gtpu_paging_policy_t  paging[0];
147   u8 nextexthdr;
148 } __attribute__ ((packed)) gtpu_pdu_session_t;
149
150 #define GTPU_PDU_SESSION_P_BIT_MASK     0x80
151 #define GTPU_PDU_SESSION_R_BIT_MASK     0x40
152 #define GTPU_PDU_SESSION_QFI_MASK       0x3f
153
154 #define SRV6_PDU_SESSION_U_BIT_MASK     0x01
155 #define SRV6_PDU_SESSION_R_BIT_MASK     0x02
156 #define SRV6_PDU_SESSION_QFI_MASK       0xfC
157
158 typedef struct
159 {
160   ip4_header_t ip4;            /* 20 bytes */
161   udp_header_t udp;            /* 8 bytes */
162   gtpu_header_t gtpu;        /* 8 bytes */
163 } __attribute__ ((packed)) ip4_gtpu_header_t;
164
165 typedef struct
166 {
167   ip6_header_t ip6;          /* 40 bytes */
168   udp_header_t udp;          /* 8 bytes */
169   gtpu_header_t gtpu;        /* 8 bytes */
170 } __attribute__ ((packed)) ip6_gtpu_header_t;
171
172 #define GTPU_V1_VER   (1<<5)
173
174 #define GTPU_PT_GTP   (1<<4)
175
176 typedef struct
177 {
178   u8 type;
179   u8 length;
180   u8 value[0];
181 } __attribute__ ((packed)) user_plane_sub_tlv_t;
182
183 #define USER_PLANE_SUB_TLV_IE   0x01
184
185 /* SRv6 mobile Plugin Params */
186
187 /* GTP6.D, GTP6.Di */
188 typedef struct srv6_end_gtp6_d_param_s
189 {
190   u8 nhtype;
191
192   ip6_address_t sr_prefix;
193   u32 sr_prefixlen;
194
195   bool drop_in;
196
197   u32 fib_table;
198   u32 fib4_index;
199   u32 fib6_index;
200 } srv6_end_gtp6_d_param_t;
201
202 /* GTP6.DT */
203 typedef struct srv6_end_gtp6_dt_param_s
204 {
205   u8 type;
206
207   u32 fib4_index;
208   u32 fib6_index;
209   u32 local_fib_index;
210 } srv6_end_gtp6_dt_param_t;
211
212 /* GTP6.E */
213 typedef struct srv6_end_gtp6_e_param_s
214 {
215   u32 fib_table;
216   u32 fib4_index;
217   u32 fib6_index;
218 } srv6_end_gtp6_e_param_t;
219
220 /* GTP4.DT */
221 typedef struct srv6_t_gtp4_dt_param_s
222 {
223   u8 type;
224
225   u32 fib4_index;
226   u32 fib6_index;
227   u32 local_fib_index;
228 } srv6_t_gtp4_dt_param_t;
229
230 /* GTP4.E */
231 typedef struct srv6_end_gtp4_e_param_s
232 {
233   u32 v4src_position;
234   ip4_address_t v4src_addr;
235
236   u32 fib_table;
237   u32 fib4_index;
238   u32 fib6_index;
239 } srv6_end_gtp4_e_param_t;
240
241 /* GTP4.D */
242 typedef struct srv6_end_gtp4_d_param_s
243 {
244   u8 nhtype;
245
246   ip6_address_t sr_prefix;
247   u32 sr_prefixlen;
248
249   ip6_address_t v6src_prefix;
250   u32 v6src_prefixlen;
251
252   bool drop_in;
253
254   u32 fib_table;
255   u32 fib4_index;
256   u32 fib6_index;
257 } srv6_end_gtp4_d_param_t;
258
259 typedef struct srv6_end_main_v4_s
260 {
261   vlib_main_t *vlib_main;
262   vnet_main_t *vnet_main;
263
264   u32 end_m_gtp4_e_node_index;
265   u32 error_node_index;
266
267   u32 dst_p_len;                // dst prefix len
268   u32 src_p_len;                // src prefix len
269
270   ip4_gtpu_header_t cache_hdr;
271
272 } srv6_end_main_v4_t;
273
274 typedef struct srv6_t_main_v4_decap_s
275 {
276   vlib_main_t *vlib_main;
277   vnet_main_t *vnet_main;
278
279   u32 t_m_gtp4_d_node_index;
280   u32 error_node_index;
281
282   ip6_header_t cache_hdr;
283 } srv6_t_main_v4_decap_t;
284
285 extern srv6_end_main_v4_t srv6_end_main_v4;
286 extern srv6_t_main_v4_decap_t srv6_t_main_v4_decap;
287 extern vlib_node_registration_t srv6_end_m_gtp4_e;
288
289 typedef struct srv6_end_main_v6_s
290 {
291   vlib_main_t *vlib_main;
292   vnet_main_t *vnet_main;
293
294   u32 end_m_gtp6_e_node_index;
295   u32 error_node_index;
296
297   ip6_gtpu_header_t cache_hdr;
298 } srv6_end_main_v6_t;
299
300 extern srv6_end_main_v6_t srv6_end_main_v6;
301 extern vlib_node_registration_t srv6_end_m_gtp6_e;
302
303 typedef struct srv6_end_main_v6_decap_s
304 {
305   vlib_main_t *vlib_main;
306   vnet_main_t *vnet_main;
307
308   u32 end_m_gtp6_d_node_index;
309   u32 error_node_index;
310
311   ip6_header_t cache_hdr;
312 } srv6_end_main_v6_decap_t;
313
314 extern srv6_end_main_v6_decap_t srv6_end_main_v6_decap;
315 extern vlib_node_registration_t srv6_end_m_gtp6_d;
316
317 typedef struct srv6_end_main_v6_decap_di_s
318 {
319   vlib_main_t *vlib_main;
320   vnet_main_t *vnet_main;
321
322   u32 end_m_gtp6_d_di_node_index;
323   u32 error_node_index;
324
325   ip6srv_combo_header_t cache_hdr;
326 } srv6_end_main_v6_decap_di_t;
327
328 extern srv6_end_main_v6_decap_di_t srv6_end_main_v6_decap_di;
329 extern vlib_node_registration_t srv6_end_m_gtp6_d_di;
330
331 typedef struct srv6_end_main_v6_dt_s
332 {
333   vlib_main_t *vlib_main;
334   vnet_main_t *vnet_main;
335
336   u32 end_m_gtp6_dt_node_index;
337   u32 error_node_index;
338 } srv6_end_main_v6_dt_t;
339
340 extern srv6_end_main_v6_dt_t srv6_end_main_v6_dt;
341 extern vlib_node_registration_t srv6_end_m_gtp6_dt;
342
343 typedef struct srv6_t_main_v4_dt_s
344 {
345   vlib_main_t *vlib_main;
346   vnet_main_t *vnet_main;
347
348   u32 t_m_gtp4_dt_node_index;
349   u32 error_node_index;
350 } srv6_t_main_v4_dt_t;
351
352 extern srv6_t_main_v4_dt_t srv6_t_main_v4_dt;
353 extern vlib_node_registration_t srv6_t_m_gtp4_dt;
354
355 #endif /* __included_srv6_end_h__ */
356
357 /*
358  * fd.io coding-style-patch-verification: ON
359  *
360  * Local Variables:
361  * eval: (c-set-style "gnu")
362  * End:
363  */