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