srv6-mobile: Update GTP4/6.D function
[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 /* *INDENT-OFF* */
75 typedef struct
76 {
77   u8 type;
78   u8 restart_counter;
79 } __attribute__ ((packed)) gtpu_recovery_ie;
80 /* *INDENT-ON* */
81
82 /* *INDENT-OFF* */
83 typedef struct
84 {
85   u16 seq;
86   u8 npdu_num;
87   u8 nextexthdr;
88 } __attribute__ ((packed)) gtpu_exthdr_t;
89 /* *INDENT-ON* */
90
91 /* *INDENT-OFF* */
92 typedef struct
93 {
94   u8 ver_flags;
95   u8 type;
96   u16 length;     /* length in octets of the payload */
97   u32 teid;
98   gtpu_exthdr_t ext[0];
99 } __attribute__ ((packed)) gtpu_header_t;
100 /* *INDENT-ON* */
101
102 #define GTPU_TYPE_ECHO_REQUEST          1
103 #define GTPU_TYPE_ECHO_REPLY            2
104 #define GTPU_TYPE_ERROR_INDICATION      26
105 #define GTPU_TYPE_END_MARKER            254
106 #define GTPU_TYPE_GTPU                  255
107
108 /* *INDENT-OFF* */
109 typedef struct
110 {
111   BITALIGN2 (u8 ppi:3,
112              u8 spare:5);
113
114   u8 padding[3];
115 } __attribute__ ((packed)) gtpu_paging_policy_t;
116 /* *INDENT-ON* */
117
118 /* *INDENT-OFF* */
119 typedef struct
120 {
121   u8 exthdrlen;
122   BITALIGN2(u8 type:4,
123             u8 spare:4);
124   union {
125     struct gtpu_qfi_bits {BITALIGN3(u8 p:1,
126                                     u8 r:1,
127                                     u8 qfi:6);
128     } bits;
129
130     u8 val;
131   } u;
132
133   gtpu_paging_policy_t  paging[0];
134   u8 nextexthdr;
135 } __attribute__ ((packed)) gtpu_pdu_session_t;
136 /* *INDENT-ON* */
137
138 #define GTPU_PDU_SESSION_P_BIT_MASK     0x80
139 #define GTPU_PDU_SESSION_R_BIT_MASK     0x40
140 #define GTPU_PDU_SESSION_QFI_MASK       0x3f
141
142 #define SRV6_PDU_SESSION_U_BIT_MASK     0x01
143 #define SRV6_PDU_SESSION_R_BIT_MASK     0x02
144 #define SRV6_PDU_SESSION_QFI_MASK       0xfC
145
146 /* *INDENT-OFF* */
147 typedef struct
148 {
149   ip4_header_t ip4;            /* 20 bytes */
150   udp_header_t udp;            /* 8 bytes */
151   gtpu_header_t gtpu;        /* 8 bytes */
152 } __attribute__ ((packed)) ip4_gtpu_header_t;
153 /* *INDENT-ON* */
154
155 /* *INDENT-OFF* */
156 typedef struct
157 {
158   ip6_header_t ip6;          /* 40 bytes */
159   udp_header_t udp;          /* 8 bytes */
160   gtpu_header_t gtpu;        /* 8 bytes */
161 } __attribute__ ((packed)) ip6_gtpu_header_t;
162 /* *INDENT-ON* */
163
164 #define GTPU_V1_VER   (1<<5)
165
166 #define GTPU_PT_GTP   (1<<4)
167
168 /* *INDENT-OFF* */
169 typedef struct
170 {
171   u8 type;
172   u8 length;
173   u8 value[0];
174 } __attribute__ ((packed)) user_plane_sub_tlv_t;
175 /* *INDENT-ON* */
176
177 #define USER_PLANE_SUB_TLV_IE   0x01
178
179 /* SRv6 mobile Plugin Params */
180
181 /* GTP6.D, GTP6.Di */
182 typedef struct srv6_end_gtp6_d_param_s
183 {
184   u8 nhtype;
185
186   ip6_address_t sr_prefix;
187   u32 sr_prefixlen;
188
189   bool drop_in;
190
191   u32 fib_table;
192   u32 fib4_index;
193   u32 fib6_index;
194 } srv6_end_gtp6_d_param_t;
195
196 /* GTP6.DT */
197 typedef struct srv6_end_gtp6_dt_param_s
198 {
199   u8 type;
200
201   u32 fib4_index;
202   u32 fib6_index;
203   u32 local_fib_index;
204 } srv6_end_gtp6_dt_param_t;
205
206 /* GTP6.E */
207 typedef struct srv6_end_gtp6_e_param_s
208 {
209   u32 fib_table;
210   u32 fib4_index;
211   u32 fib6_index;
212 } srv6_end_gtp6_e_param_t;
213
214 /* GTP4.DT */
215 typedef struct srv6_t_gtp4_dt_param_s
216 {
217   u8 type;
218
219   u32 fib4_index;
220   u32 fib6_index;
221   u32 local_fib_index;
222 } srv6_t_gtp4_dt_param_t;
223
224 /* GTP4.E */
225 typedef struct srv6_end_gtp4_e_param_s
226 {
227   u32 v4src_position;
228   ip4_address_t v4src_addr;
229
230   u32 fib_table;
231   u32 fib4_index;
232   u32 fib6_index;
233 } srv6_end_gtp4_e_param_t;
234
235 /* GTP4.D */
236 typedef struct srv6_end_gtp4_d_param_s
237 {
238   u8 nhtype;
239
240   ip6_address_t sr_prefix;
241   u32 sr_prefixlen;
242
243   ip6_address_t v6src_prefix;
244   u32 v6src_prefixlen;
245
246   bool drop_in;
247
248   u32 fib_table;
249   u32 fib4_index;
250   u32 fib6_index;
251 } srv6_end_gtp4_d_param_t;
252
253 typedef struct srv6_end_main_v4_s
254 {
255   vlib_main_t *vlib_main;
256   vnet_main_t *vnet_main;
257
258   u32 end_m_gtp4_e_node_index;
259   u32 error_node_index;
260
261   u32 dst_p_len;                // dst prefix len
262   u32 src_p_len;                // src prefix len
263
264   ip4_gtpu_header_t cache_hdr;
265
266 } srv6_end_main_v4_t;
267
268 typedef struct srv6_t_main_v4_decap_s
269 {
270   vlib_main_t *vlib_main;
271   vnet_main_t *vnet_main;
272
273   u32 t_m_gtp4_d_node_index;
274   u32 error_node_index;
275
276   ip6_header_t cache_hdr;
277 } srv6_t_main_v4_decap_t;
278
279 extern srv6_end_main_v4_t srv6_end_main_v4;
280 extern srv6_t_main_v4_decap_t srv6_t_main_v4_decap;
281 extern vlib_node_registration_t srv6_end_m_gtp4_e;
282
283 typedef struct srv6_end_main_v6_s
284 {
285   vlib_main_t *vlib_main;
286   vnet_main_t *vnet_main;
287
288   u32 end_m_gtp6_e_node_index;
289   u32 error_node_index;
290
291   ip6_gtpu_header_t cache_hdr;
292 } srv6_end_main_v6_t;
293
294 extern srv6_end_main_v6_t srv6_end_main_v6;
295 extern vlib_node_registration_t srv6_end_m_gtp6_e;
296
297 typedef struct srv6_end_main_v6_decap_s
298 {
299   vlib_main_t *vlib_main;
300   vnet_main_t *vnet_main;
301
302   u32 end_m_gtp6_d_node_index;
303   u32 error_node_index;
304
305   ip6_header_t cache_hdr;
306 } srv6_end_main_v6_decap_t;
307
308 extern srv6_end_main_v6_decap_t srv6_end_main_v6_decap;
309 extern vlib_node_registration_t srv6_end_m_gtp6_d;
310
311 typedef struct srv6_end_main_v6_decap_di_s
312 {
313   vlib_main_t *vlib_main;
314   vnet_main_t *vnet_main;
315
316   u32 end_m_gtp6_d_di_node_index;
317   u32 error_node_index;
318
319   ip6srv_combo_header_t cache_hdr;
320 } srv6_end_main_v6_decap_di_t;
321
322 extern srv6_end_main_v6_decap_di_t srv6_end_main_v6_decap_di;
323 extern vlib_node_registration_t srv6_end_m_gtp6_d_di;
324
325 typedef struct srv6_end_main_v6_dt_s
326 {
327   vlib_main_t *vlib_main;
328   vnet_main_t *vnet_main;
329
330   u32 end_m_gtp6_dt_node_index;
331   u32 error_node_index;
332 } srv6_end_main_v6_dt_t;
333
334 extern srv6_end_main_v6_dt_t srv6_end_main_v6_dt;
335 extern vlib_node_registration_t srv6_end_m_gtp6_dt;
336
337 typedef struct srv6_t_main_v4_dt_s
338 {
339   vlib_main_t *vlib_main;
340   vnet_main_t *vnet_main;
341
342   u32 t_m_gtp4_dt_node_index;
343   u32 error_node_index;
344 } srv6_t_main_v4_dt_t;
345
346 extern srv6_t_main_v4_dt_t srv6_t_main_v4_dt;
347 extern vlib_node_registration_t srv6_t_m_gtp4_dt;
348
349 #endif /* __included_srv6_end_h__ */
350
351 /*
352  * fd.io coding-style-patch-verification: ON
353  *
354  * Local Variables:
355  * eval: (c-set-style "gnu")
356  * End:
357  */