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