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