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