FD.io VPP  v17.01-9-ge7dcee4
Vector Packet Processing
cnat_pcp_server.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * cnat_pcp_server.h
4  *
5  * Copyright (c) 2009-2012 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #ifndef __CNAT_PCP_SERVER_H__
21 #define __CNAT_PCP_SERVER_H__
22 
23 #include "dslite_defs.h"
24 
25 /* Debug utils of PCP */
26 #define PCP_DBG(debug, ...) \
27  if(PREDICT_FALSE(cnat_pcp_debug_flag >= debug)) { \
28  printf("%s:%s:%d - ", \
29  __FILE__, __FUNCTION__, __LINE__);\
30  printf(__VA_ARGS__);\
31  printf("\n"); \
32  }
33 
34 #define PCP_DUMP_PDATA \
35  if(PREDICT_FALSE(cnat_pcp_debug_flag >= 100)) { \
36  printf("%s:%s:%d - \n", \
37  __FILE__, __FUNCTION__, __LINE__);\
38  printf("src - ip = %X, proto = %d, port = %d i_vrf = %d, o_vrf = %d\n", \
39  pcp_data.src_ip[3], pcp_data.proto, pcp_data.src_port, pcp_data.i_vrf, pcp_data.o_vrf); \
40  printf(" third party ip = %X\n", pcp_data.third_party_ip[3]); \
41  printf("map - ip = %X, port = %d \n", \
42  pcp_data.ext_ip[3], pcp_data.ext_port);\
43  printf("remote - ip = %X, port = %d \n", \
44  pcp_data.peer_ip[3], pcp_data.peer_port); \
45  printf("req life time = %d \n", pcp_data.req_lifetime); \
46  printf("drop = %d \n", pcp_data.drop);\
47  printf("udp_len = %d \n", pcp_data.udp_len); \
48  printf("pm = %p \n", pcp_data.pm); \
49  printf("cnat_proto = %X \n", pcp_data.cnat_proto); \
50  printf("inst_id = %X \n", pcp_data.inst_id); \
51  printf("======================================================\n"); \
52  }
53 
54 #define PCP_DUMP_PACKET(ip, len) pcp_hex_dump(ip, len)
55 
56 #ifdef TOBE_PORTED
57 #define PCP_INCR(counter) pcp_counters.pcp_##counter++ ;
58 #else
59 #define PCP_INCR(counter)
60 #endif
61 
62 typedef struct pcp_debug_counters {
67  /* below all are drops */
94 
95  /* map counters */
106 
107  /* peer counters */
114 
116 
117 typedef struct {
120  u8 pad[5];
121 
122  /* better to have a group structures rather than individual
123  variables, any change in counters is will automatically
124  reflect here */
127 
128 
129 
130 /* PCP opcodes */
131 typedef enum pcp_opcode {
134 }pcp_opcode_t;
135 
136 
137 /* PCP opcodes */
138 typedef enum pcp_options {
142 } pcp_options_t;
143 
144 /* PCP Result codes */
145 typedef enum pcp_result_codes {
161 
162 #define PCP_DISABLED 0
163 #define PCP_ENABLED 1
164 
165 #define PCP_DROP 1
166 
167 #define PCP_STATIC_LIFETIME 0xFFFFFFFF
168 #define PCP_MAX_LIFETIME 0x00015180 /* 24 hours = 86400 seconds*/
169 
170 #define PCP_VERSION_SUPPORTED 1
171 
172 #define PCP_NO_PREF_FAIL_OPTION 0
173 #define PCP_PREF_FAIL_OPTION 1
174 
175 #define CNAT_DEF_PCP_PORT 5351
176 
177 #define PCP_REQ_RESP_BIT 0x80
178 #define PCP_RESPONSE(r_opcode) (r_opcode & PCP_REQ_RESP_BIT)
179 #define PCP_REQUEST(r_opcode) !(PCP_RESPONSE(r_opcode))
180 
181 #define PCP_REQ_OPCODE(r_opcode) (r_opcode & 0x7F)
182 
183 /* 24 bytes */
184 #define PCP_COMMON_HDR_LEN sizeof(pcp_request_t)
185 
186 /* 8 bytes */
187 #define UDP_HDR_LEN sizeof(udp_hdr_type_t)
188 
189 #define PCP_PREF_FAIL_OPTION_SIZE \
190  sizeof(pcp_prefer_fail_option_t)
191 
192 #define PCP_3RD_PARTY_OPTION_SIZE \
193  sizeof(pcp_3rd_party_option_t)
194 
195 #define PCP_MIN_LEN PCP_COMMON_HDR_LEN
196 
197 /* 24+8=32 bytes */
198 #define PCP_MIN_UDP_LEN (PCP_MIN_LEN + UDP_HDR_LEN)
199 
200 #define PCP_MAX_LEN 1024
201 
202 /* 1024+8 = 1032 bytes */
203 #define PCP_MAX_UDP_LEN (PCP_MAX_LEN + UDP_HDR_LEN)
204 
205 /* 24+ 24 = 48 bytes */
206 #define PCP_MAP_OPCODE_MIN_LEN (PCP_COMMON_HDR_LEN + \
207  sizeof( pcp_map_option_specific_data_t))
208 
209 /* 24 + 44 = 68 bytes */
210 #define PCP_PEER_OPCODE_MIN_LEN (PCP_COMMON_HDR_LEN + \
211  sizeof( pcp_peer_option_specific_data_t))
212 
213 /* 48 + 8 = 56 bytes */
214 #define PCP_MAP_OPCODE_MIN_UDP_LEN (PCP_MAP_OPCODE_MIN_LEN + \
215  UDP_HDR_LEN )
216 
217 #define PCP_GET_MAP_OPTION_OFFSET(req) \
218  ((u8*)req + PCP_MAP_OPCODE_MIN_LEN)
219 
220 #define PCP_GET_PEER_OPTION_OFFSET(req) \
221  ((u8*)req + PCP_PEER_OPCODE_MIN_LEN)
222 
223 
224 #define PCP_REQ_TOTAL_LEN(udp) (udp->udp_length - \
225  UDP_HDR_LEN)
226 /* 56 + 4 = 60 bytes */
227 #define PCP_MAP_OPCODE_PREF_FAIL_OPTION_LEN \
228  (PCP_MAP_OPCODE_MIN_UDP_LEN + \
229  sizeof(pcp_prefer_fail_option_t))
230 
231 
232 /* 68 + 8 = 76 bytes */
233 #define PCP_PEER_OPCODE_MIN_UDP_LEN (PCP_PEER_OPCODE_MIN_LEN + \
234  UDP_HDR_LEN)
235 
236 #define PCP_MUST_OPTION(option_code) (option_code & 0x80)
237 
238 
239 
240 /* 56 + 20 = 76*/
241 #define PCP_DSLITE_MAP_OPCODE_MIN_UDP_LEN \
242  ( PCP_MAP_OPCODE_MIN_UDP_LEN + \
243  PCP_3RD_PARTY_OPTION_SIZE)
244 
245 /* 60 + 20 = 80 */
246 #define PCP_DSLITE_MAP_OPCODE_MAX_UDP_LEN \
247  ( PCP_MAP_OPCODE_PREF_FAIL_OPTION_LEN + \
248  PCP_3RD_PARTY_OPTION_SIZE)
249 
250 /* 76 + 20 = 96 */
251 #define PCP_DSLITE_PEER_OPCODE_MIN_UDP_LEN \
252  ( PCP_PEER_OPCODE_MIN_UDP_LEN + \
253  PCP_3RD_PARTY_OPTION_SIZE)
254 
255 
256 #define PCP_SET_CNAT_PROTO(proto) \
257  pcp_data.cnat_proto = (proto == TCP_PROT) ? CNAT_TCP: \
258  (proto == UDP_PROT)? CNAT_UDP : CNAT_ICMP;
259 
260 #define PCP_SET_REQ_LIFETIME() \
261  if(pcp_data.db->flags & CNAT_DB_FLAG_STATIC_PORT) { \
262  pcp_data.db->proto_data.seq_pcp.pcp_lifetime = \
263  PCP_STATIC_LIFETIME; \
264  pcp_data.req_lifetime = PCP_STATIC_LIFETIME; \
265  } else { \
266  pcp_data.db->proto_data.seq_pcp.pcp_lifetime = \
267  pcp_data.req_lifetime + cnat_current_time ; \
268  }
269 
270 
271 /* per second not more than PCP_THROTTLE_LIMIT
272  * delete requests will be handled.
273  * this excludes , specific entries, in which
274  * only one entry needs to be deleted
275  */
276 #define PCP_THROTTLE_LIMIT 2
277 
278 typedef struct pcp_request {
283  u32 ip[4]; /* ipv4 will be represented
284  by the ipv4 mapped ipv6 */
285 } pcp_request_t;
286 
287 typedef struct pcp_response {
294  u32 reserved1[3];
296 
297 
298 typedef struct pcp_options_hdr {
302  u8 data[0];
304 
305 
306 /* same for both request and response */
309  u8 reserved[3];
312  u32 ext_ip[4]; /* ipv4 will be represnted
313  by the ipv4 mapped ipv6 */
315 
316 /* same for both request and response */
319  u8 reserved[3];
322  u32 ext_ip[4]; /* ipv4 will be represented
323  by the ipv4 mapped ipv6 */
326  u32 peer_ip[4];
328 
329 typedef struct pcp_prefer_fail_option {
334 
335 
336 typedef struct pcp_3rd_party_option{
340  u32 ip[4];
342 
343 /* structure used as pipeline data */
344 
345 typedef struct pcp_pipeline_data {
346 
347  union {
348 
349  u8 *p;
352 
353  } l3addr;
354 
359  u32 src_ip[4];
364  u32 ext_ip[4];
366  u32 third_party_ip[4];
367 
368  /* valid for peer opcode */
369  u32 peer_ip[4];
384 
385  /* is packet needs to be dropped ? */
387  /* nat44, dslite, nat64 */
388 #define PCP_SERVICE_NAT44 1
389 #define PCP_SERVICE_DSLITE 2
390 #define PCP_SERVICE_NAT64 3
392 
393 #define PCP_REQ_ENTRY_PRESENT 1
394 #define PCP_REQ_EXT_MAP_PRESENT 1
397 
398 #endif /* __CNAT_PCP_sERVER_H__ */
enum pcp_opcode pcp_opcode_t
udp_hdr_type_t * udp
u8 pad[3]
log2 (size of the packing page block)
Definition: bihash_doc.h:61
pcp_options
struct pcp_response pcp_response_t
struct pcp_prefer_fail_option pcp_prefer_fail_option_t
Definition: cnat_db.h:153
pcp_opcode_t opcode
pcp_request_t * req
dslite_table_entry_t * inst_ptr
Definition: dslite_defs.h:106
pcp_result_codes_t ret_code
cnat_main_db_entry_t * db
unsigned long u64
Definition: types.h:89
ipv6_header_t * ipv6
pcp_result_codes
cnat_portmap_v2_t * pm
struct pcp_debug_counters pcp_debug_counters_t
cnat_vrfmap_t * vrfmap
struct pcp_peer_option_specific_data pcp_peer_option_specific_data_t
enum pcp_options pcp_options_t
struct pcp_map_option_specific_data pcp_map_option_specific_data_t
unsigned int u32
Definition: types.h:88
pcp_response_t * resp
enum pcp_result_codes pcp_result_codes_t
pcp_options_t third_party
struct pcp_3rd_party_option pcp_3rd_party_option_t
pcp_debug_counters_t counters
ipv4_header * ip
pcp_options_t pref_fail
unsigned short u16
Definition: types.h:57
pcp_opcode
unsigned char u8
Definition: types.h:56
struct pcp_request pcp_request_t
struct pcp_options_hdr pcp_options_hdr_t
struct pcp_pipeline_data pcp_pipeline_data_t