srv6-mobile
[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_NONE
37 #define IP_PROTOCOL_NONE        59
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 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
46 #define BITALIGN2(A,B)          A; B
47 #define BITALIGN3(A,B,C)        A; B; C
48 #else
49 #define BITALIGN2(A,B)          B; A
50 #define BITALIGN3(A,B,C)        C; B; A
51 #endif
52
53 #define GTPU_EXTHDR_FLAG                0x04
54 #define GTPU_EXTHDR_PDU_SESSION         0x85
55
56 #define SRH_TAG_ECHO_REPLY              0x0008
57 #define SRH_TAG_ECHO_REQUEST            0x0004
58 #define SRH_TAG_ERROR_INDICATION        0x0002
59 #define SRH_TAG_END_MARKER              0x0001
60
61 /* *INDENT-OFF* */
62 typedef struct
63 {
64   u16 seq;
65   u8 npdu_num;
66   u8 nextexthdr;
67 } __attribute__ ((packed)) gtpu_exthdr_t;
68 /* *INDENT-ON* */
69
70 /* *INDENT-OFF* */
71 typedef struct
72 {
73   u8 ver_flags;
74   u8 type;
75   u16 length;     /* length in octets of the payload */
76   u32 teid;
77   gtpu_exthdr_t ext[0];
78 } __attribute__ ((packed)) gtpu_header_t;
79 /* *INDENT-ON* */
80
81 #define GTPU_TYPE_ECHO_REQUEST          1
82 #define GTPU_TYPE_ECHO_REPLY            2
83 #define GTPU_TYPE_ERROR_INDICATION      26
84 #define GTPU_TYPE_END_MARKER            254
85 #define GTPU_TYPE_GTPU                  255
86
87 /* *INDENT-OFF* */
88 typedef struct
89 {
90   BITALIGN2 (u8 ppi:3,
91              u8 spare:5);
92
93   u8 padding[3];
94 } __attribute__ ((packed)) gtpu_paging_policy_t;
95 /* *INDENT-ON* */
96
97 /* *INDENT-OFF* */
98 typedef struct
99 {
100   u8 exthdrlen;
101   BITALIGN2(u8 type:4,
102             u8 spare:4);
103   union {
104     struct gtpu_qfi_bits {BITALIGN3(u8 p:1,
105                                     u8 r:1,
106                                     u8 qfi:6);
107     } bits;
108
109     u8 val;
110   } u;
111
112   gtpu_paging_policy_t  paging[0];
113   u8 nextexthdr;
114 } __attribute__ ((packed)) gtpu_pdu_session_t;
115 /* *INDENT-ON* */
116
117 #define GTPU_PDU_SESSION_P_BIT_MASK     0x80
118 #define GTPU_PDU_SESSION_R_BIT_MASK     0x40
119 #define GTPU_PDU_SESSION_QFI_MASK       0x3f
120
121 #define SRV6_PDU_SESSION_U_BIT_MASK     0x01
122 #define SRV6_PDU_SESSION_R_BIT_MASK     0x02
123 #define SRV6_PDU_SESSION_QFI_MASK       0xfC
124
125 /* *INDENT-OFF* */
126 typedef struct
127 {
128   ip4_header_t ip4;            /* 20 bytes */
129   udp_header_t udp;            /* 8 bytes */
130   gtpu_header_t gtpu;        /* 8 bytes */
131 } __attribute__ ((packed)) ip4_gtpu_header_t;
132 /* *INDENT-ON* */
133
134 /* *INDENT-OFF* */
135 typedef struct
136 {
137   ip6_header_t ip6;          /* 40 bytes */
138   udp_header_t udp;          /* 8 bytes */
139   gtpu_header_t gtpu;        /* 8 bytes */
140 } __attribute__ ((packed)) ip6_gtpu_header_t;
141 /* *INDENT-ON* */
142
143 #define GTPU_V1_VER   (1<<5)
144
145 #define GTPU_PT_GTP   (1<<4)
146
147 typedef struct srv6_end_gtp6_param_s
148 {
149   u8 nhtype;
150
151   ip6_address_t sr_prefix;
152   u32 sr_prefixlen;
153 } srv6_end_gtp6_param_t;
154
155 typedef struct srv6_end_gtp4_param_s
156 {
157   u8 nhtype;
158
159   ip6_address_t sr_prefix;
160   u32 sr_prefixlen;
161
162   ip6_address_t v6src_prefix;
163   u32 v6src_prefixlen;
164
165   u32 v4src_position;
166 } srv6_end_gtp4_param_t;
167
168 typedef struct srv6_end_main_v4_s
169 {
170   vlib_main_t *vlib_main;
171   vnet_main_t *vnet_main;
172
173   u32 end_m_gtp4_e_node_index;
174   u32 error_node_index;
175
176   u32 dst_p_len;                // dst prefix len
177   u32 src_p_len;                // src prefix len
178
179   ip4_gtpu_header_t cache_hdr;
180
181 } srv6_end_main_v4_t;
182
183 typedef struct srv6_t_main_v4_decap_s
184 {
185   vlib_main_t *vlib_main;
186   vnet_main_t *vnet_main;
187
188   u32 t_m_gtp4_d_node_index;
189   u32 error_node_index;
190
191   ip6_header_t cache_hdr;
192 } srv6_t_main_v4_decap_t;
193
194 extern srv6_end_main_v4_t srv6_end_main_v4;
195 extern srv6_t_main_v4_decap_t srv6_t_main_v4_decap;
196 extern vlib_node_registration_t srv6_end_m_gtp4_e;
197
198 typedef struct srv6_end_main_v6_s
199 {
200   vlib_main_t *vlib_main;
201   vnet_main_t *vnet_main;
202
203   u32 end_m_gtp6_e_node_index;
204   u32 error_node_index;
205
206   ip6_gtpu_header_t cache_hdr;
207 } srv6_end_main_v6_t;
208
209 extern srv6_end_main_v6_t srv6_end_main_v6;
210 extern vlib_node_registration_t srv6_end_m_gtp6_e;
211
212 typedef struct srv6_end_main_v6_decap_s
213 {
214   vlib_main_t *vlib_main;
215   vnet_main_t *vnet_main;
216
217   u32 end_m_gtp6_d_node_index;
218   u32 error_node_index;
219
220   ip6_header_t cache_hdr;
221 } srv6_end_main_v6_decap_t;
222
223 extern srv6_end_main_v6_decap_t srv6_end_main_v6_decap;
224 extern vlib_node_registration_t srv6_end_m_gtp6_d;
225
226 typedef struct srv6_end_main_v6_decap_di_s
227 {
228   vlib_main_t *vlib_main;
229   vnet_main_t *vnet_main;
230
231   u32 end_m_gtp6_d_di_node_index;
232   u32 error_node_index;
233
234   ip6srv_combo_header_t cache_hdr;
235 } srv6_end_main_v6_decap_di_t;
236
237 extern srv6_end_main_v6_decap_di_t srv6_end_main_v6_decap_di;
238 extern vlib_node_registration_t srv6_end_m_gtp6_d_di;
239
240 #endif /* __included_srv6_end_h__ */
241
242 /*
243  * fd.io coding-style-patch-verification: ON
244  *
245  * Local Variables:
246  * eval: (c-set-style "gnu")
247  * End:
248  */