FD.io VPP  v16.06
Vector Packet Processing
nat64_defs.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * nat64_defs.h - NAT64 structure definiitions
4  *
5  * Copyright (c) 2007-2013 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 __NAT64_DEFS_H__
21 #define __NAT64_DEFS_H__
22 
23 #ifdef TOBE_PORTED
24 #include "spp_platform_common.h"
25 #include "cgse_defs.h"
26 #include "xlat_defs.h"
27 #endif
28 #include "cnat_cli.h"
29 #include "cnat_ports.h"
30 #include "tcp_header_definitions.h"
31 #include "nat64_tcp_sm.h"
32 #include "cnat_db.h"
33 
34 #define NAT64_MAX_FRAG_ID_COUNTERS (256)
35 
36 #define NAT64_MAX_NAT64_ENTRIES 500
37 
38 #define NAT64_MAX_ID (NAT64_MAX_NAT64_ENTRIES-1)
39 
40 #define NAT64_INVALID_ID (0)
41 
42 #define NAT64_MAX_CFG_INSTANCES 64
43 
44 #define NAT64_TABLE_ENTRY_DELETED 0
45 #define NAT64_TABLE_ENTRY_ACTIVE 1
46 #define NAT64_TABLE_ENTRY_DORMANT 2
47 #define NAT64_TABLE_ENTRY_INVALID_UIDB 3
48 
49 #define NAT64_MAX_TRANSLATION_ENTRIES PLATFORM_MAX_TRANSLATION_ENTRIES
50 
51 #define NAT64_WKP_PREFIX_LEN 96
52 #define NAT64_WKP_PREFIX_0 0x0064FF9B
53 #define NAT64_WKP_PREFIX_1 0x00000000
54 #define NAT64_WKP_PREFIX_2 0x00000000
55 #define NAT64_WKP_PREFIX_3 0x00000000
56 
57 
58 /* Reset the expiry time only if it is not 0
59 ** if it is 0 - then queue for delete by clear command
60 **/
61 
62 #define NAT64_TIMEOUT_RST(db) \
63  if(PREDICT_TRUE(db->entry_expires !=0 )) \
64  db->entry_expires = cnat_current_time;
65 
68 
77 
82 
84 
85 typedef struct {
92 
93 typedef struct {
101 
102 typedef struct {
109 
110 typedef struct {
120 
121 typedef struct {
127 
128 typedef struct {
134 
135 typedef struct {
143 
144 typedef struct {
151 
152 
153 
154 typedef struct {
163 
174 
175 typedef struct {
181 
188 
189 typedef struct {
193 
194 typedef struct{
209 
210 typedef struct {
211 
223 
225 
226 /*
227  * nat64_portmap_v2_t
228  * This structure stores information about the IP address and ports
229  * available for NAT for this nat64 instance.
230  */
231 
232 typedef struct {
236  u32 ipv4_address; /* native bit order */
239 
240 /*
241  * nat64_v4_db_key_t
242  * This structure gives information about the v4 transport address
243  * (ipv4, port, protocol)
244  */
245 typedef struct {
248  u16 vrf; //bit0-12:inst_id, bit13:unused, bit14-15:protocol
250 
251 /* Union will be easier while compare/hash */
252 typedef union {
256 /*
257  * nat64_v6_db_key_t
258  * This structure gives information about the v6 transport address
259  * (ipv6, port, protocol)
260  */
261 typedef struct {
262  u32 ipv6[4];
264  u16 vrf; //bit0-12:inst_id, bit13:unused, bit14-15:protocol
266 
267 
268 typedef struct {
276 
277 #define NAT64_UDP_DEF 300 /* 5min */
278 #define NAT64_TCP_TRANS_DEF 240 /* 4min */
279 #define NAT64_TCP_EST_DEF 7200 /* 2Hrs */
280 #define NAT64_TCP_V4_DEF 6 /* 6 sec */
281 #define NAT64_FRAG_DEF 2 /* 2 sec */
282 #define NAT64_ICMP_DEF 60 /* 60 sec */
283 
284 /*
285  * nat64_table_entry_t
286  * This structure is used to store information regarding every nat64 instance.
287  */
288 
289 /* structure will hold the L4 information, of a particular frag stream set
290  * src_port - holds the original src port
291  * dst_port - holds the original dst port
292  * total_len - useful only in ICMP nodes
293  * cnat_port - vlaue used for looksups
294  * next_prot - Protocol after translation */
295 
296 typedef struct l4_frag_info {
305 
306 typedef struct {
308  u16 nat64_id; /* nat64_id value for this table entry - for easy access */
309 
310  u16 v4_uidb_index; /* V4 uidb index */
311  u16 v6_uidb_index; /* V6 uidb index */
312 
317 
318  u16 v4_to_v6_tcp_mss; /* TCP MSS */
319  u16 v6_to_v4_tcp_mss; /* TCP MSS */
320 
321  /*
322  * V6 NAT64 prefix value and mask size
323  */
324  u32 v6_prefix[4];
325  u32 v6_prefix_mask[4];
326 
329 #define IPV4_TOS_OVERRIDE_FLAG 0x1
330 #define IPV6_TOS_OVERRIDE_FLAG 0x2
331 #define NAT64_STFUL_RTSP_ALG_ENABLE 0x4
333 
338 
340 #define NAT64_ADDRESS_DEPENDENT_ENABLE 1
342 #define NAT64_TCP_SECURITY_FLAG_DISABLE 1
344 
346 #define NAT64_TCP_V4_INIT_ENABLE 1
347 
349 #define NAT64_BIB_LOG_ENABLE 0 /* Default */
350 #define NAT64_SESSION_LOG_ENABLE 1
351 
352 #define NAT64_BIDIR_REFRESH 1 /* 1 - timer refresh in both direction */
353 #define NAT64_UNIDIR_REFRESH 0 /* 0 - default (only v6 side refresh timer)*/
354 
355  u8 nat64_refresh_both_direction; /* 0 - default (only v6 side refresh timer) */
356 #define NAT64_BIDIR_REFRESH 1 /* 1 - timer refresh in both direction */
357 
358  u8 udp_zero_checksum; /* 0 - default (calc checksum) */
359 #define NAT64_UDP_ZERO_CHECKSUM_DROP 1 /* 1 -drop */
360 
362 
364 
366 
368  /*
369  * These fields are not used much, let us keep it in the end
370  */
371  u32 v4_vrf_id; /* V4 vrf id */
372  u32 v6_vrf_id; /* V6 vrf id */
373 
374  u32 v4_if_num; /* V4 SVI ifnum */
375  u32 v6_if_num; /* V6 SVI ifnum */
376 
378 
380  u32 pcp_server_addr[4];
382 #define NAT64_FRAG_ENABLE 1
383 #define NAT64_FRAG_DISABLE 0
385  u8 nat64_enable; /* Enable/Disable this instance. */
386 
388 
390 
391 
392 
397 
399 #ifdef TOBE_PORTED
400  spp_node_main_vector_t *nmv;
401 #endif
402 
404 
406 
408 
411 
414 
417 
418  /*
419  * IPv6 Data, everthing in host order except for the addr fields
420  */
422 
426 
427  /*
428  * These Address fields are in Network Order, so that
429  * it is easy to extract the IPv4 address from them
430  */
431  u32 ipv6_src[4];
432 
433  u32 ipv6_dst[4];
434 
439 
441  union {
442  struct _v4_l4_info {
448  } v4_l4_info;
449  struct _v4_icmp_info {
456  u16 old_iden; // length (ICMP extn), ptr (param)
457  u16 new_iden; // ----- do -------------
458  u16 old_seq; // MTU for PTB case
459  u16 new_seq; // ----- do -------------
460  } v4_icmp_info;
461  struct _v4_udp_info {
463  u8 pad0;
464  u8 pad1;
465  u8 pad2;
466  u8 pad3;
467  } v4_udp_info;
468  struct _v4_tcp_info {
474  } v4_tcp_info;
475  } l4_u;
476 
477 
478  l4_frag_info_t *frag_info; /* port for tcp/udp, ident - icmp */
479 
480 
481  /* Counters will be added here */
482  union {
489  } nat64_ctr_u;
492 
493 
496 
499 
500  nat64_v4_key_t v4_src_key; /* Will be translated using Prefix */
501  nat64_v4_key_t v4_dest_key; /* will be the out key for NAT64 */
502 
503  /*
504  * IPv4 data
505  */
509 
512 
516 
519 
520  /*
521  * Pointers to IPv6 headers
522  */
525 
526  union {
527  struct _v6_l4_info {
533  } v6_l4_info;
534  struct _v6_icmp_info {
540  u16 old_iden; // length (ICMP extn), ptr (param)
541  u16 new_iden; // ----- do -------------
542  u16 old_seq; // MTU for PTB case
543  u16 new_seq; // ----- do -------------
544  } v6_icmp_info;
545  struct _v6_udp_info {
547  u8 pad0;
548  u8 pad1;
549  u8 pad2;
550  u8 pad3;
551  } v6_udp_info;
552  struct _v6_tcp_info {
558  } v6_tcp_info;
559  } l4_u;
560 
561  l4_frag_info_t *frag_info; /* port for tcp/udp, ident - icmp */
562 
563  /* Need to add counters here */
564  union {
571  } nat64_ctr_u;
573 
575 
576 #endif
nat64_v4_to_v6_icmp_counter_t * icmp_counter
Definition: nat64_defs.h:567
u8 udp_zero_checksum
Definition: nat64_defs.h:358
u8 octet3_position
Definition: nat64_defs.h:316
u32 nat64_translation_create_count[NAT64_MAX_NAT64_ENTRIES]
u64 nat64_v4_frag_icmp_input_count
Definition: nat64_defs.h:162
u16 rtsp_port
Definition: nat64_defs.h:387
nat64_v6_to_v4_icmp_error_counter_t * icmp_error_counter
Definition: nat64_defs.h:486
tcp_hdr_type * ipv4_tcp_header
Definition: nat64_defs.h:469
u64 nat64_v4_frag_udp_input_count
Definition: nat64_defs.h:161
u32 nat64_in2out_forwarding_count[NAT64_MAX_NAT64_ENTRIES]
ipv6_frag_header_t * ipv6_frag_header
Definition: nat64_defs.h:524
u16 state
Definition: nat64_defs.h:307
cnat_portmap_v2_t * port_map
Definition: nat64_defs.h:363
nat64_tcp_events
Definition: nat64_tcp_sm.h:37
u32 nat64_translation_delete_rate[NAT64_MAX_NAT64_ENTRIES]
u32 rseed_ip
Definition: nat64_defs.h:381
u16 port_limit
Definition: nat64_defs.h:361
u32 nat64_data_path_debug_level
nat64_options_counter_t nat64_options_counters
Definition: nat64_defs.h:221
u16 v4_to_v6_tcp_mss
Definition: nat64_defs.h:318
nat64_counters_t nat64_all_counters[NAT64_MAX_NAT64_ENTRIES]
u16 v6_uidb_index
Definition: nat64_defs.h:311
u8 ftp_flags
Definition: nat64_defs.h:343
struct l4_frag_info l4_frag_info_t
u8 nat64_enable
Definition: nat64_defs.h:385
u32 last_sent_timestamp
Definition: nat64_defs.h:234
struct nat64_common_pipeline_data_ nat64_common_pipeline_data_t
nat64_options_counter_t * options_counter
Definition: nat64_defs.h:570
nat64_v6_to_v4_udp_counter_t * udp_counter
Definition: nat64_defs.h:484
u32 nat64_out2in_forwarding_rate[NAT64_MAX_NAT64_ENTRIES]
u8 ipv4_tos_value
Definition: nat64_defs.h:334
u8 octet2_position
Definition: nat64_defs.h:315
u8 ipv6_mtu_set
Definition: nat64_defs.h:337
u8 ipv6_tos_value
Definition: nat64_defs.h:335
u32 nat64_config_debug_level
u64 nat64_v4_frag_timeout_drop_count
Definition: nat64_defs.h:159
nat64_v6_to_v4_icmp_error_counter_t v64_icmp_error_counters
Definition: nat64_defs.h:218
u64 nat64_v4_frag_throttled_count
Definition: nat64_defs.h:158
nat64_v4_to_v6_icmp_error_counter_t * icmp_error_counter
Definition: nat64_defs.h:568
nat64_v4_to_v6_udp_counter_t v46_udp_counters
Definition: nat64_defs.h:215
unsigned long u64
Definition: types.h:89
nat64_frag_counter_t nat64_frag_counters
Definition: nat64_defs.h:220
u16 nat64_id
Definition: nat64_defs.h:308
udp_hdr_type_t * ipv6_udp_header
Definition: nat64_defs.h:546
nat64_v6_to_v4_icmp_counter_t v64_icmp_counters
Definition: nat64_defs.h:216
u16 dyn_start_port
Definition: nat64_defs.h:377
u32 logging_index
Definition: nat64_defs.h:365
u64 nat64_v6_frag_invalid_input_count
Definition: nat64_defs.h:172
nat64_icmp_gen_counter_t nat64_icmp_gen_counters
Definition: nat64_defs.h:222
u32 nat64_in2out_forwarding_rate[NAT64_MAX_NAT64_ENTRIES]
u32 nat64_translation_delete_count[NAT64_MAX_NAT64_ENTRIES]
u64 nat64_v6_frag_icmp_input_count
Definition: nat64_defs.h:171
u64 nat64_v6_frag_throttled_count
Definition: nat64_defs.h:167
nat64_v4_to_v6_tcp_counter_t v46_tcp_counters
Definition: nat64_defs.h:213
Definition: nat64_defs.h:306
l4_frag_info_t * frag_info
Definition: nat64_defs.h:561
u32 nat64_translation_create_count_old[NAT64_MAX_NAT64_ENTRIES]
nat64_table_entry_t * nat64_entry_ptr
Definition: nat64_defs.h:405
u32 nat64_translation_delete_count_old[NAT64_MAX_NAT64_ENTRIES]
u64 nat64_v6_frag_timeout_drop_count
Definition: nat64_defs.h:168
nat64_tcp_events tcp_event
Definition: nat64_defs.h:473
u8 ubits_reserved_on
Definition: nat64_defs.h:328
nat64_frag_counter_t * frag_counter
Definition: nat64_defs.h:487
nat64_common_pipeline_data_t common_data
Definition: nat64_defs.h:495
udp_hdr_type_t * ipv4_udp_header
Definition: nat64_defs.h:462
u32 v4_if_num
Definition: nat64_defs.h:374
ipv6_header_t * ipv6_header
Definition: nat64_defs.h:523
u8 tcp_policy
Definition: nat64_defs.h:341
u8 octet1_position
Definition: nat64_defs.h:314
u16 pcp_server_port
Definition: nat64_defs.h:379
u8 octet0_position
Definition: nat64_defs.h:313
nat64_v6_to_v4_tcp_counter_t v64_tcp_counters
Definition: nat64_defs.h:212
u16 next_node_idx
Definition: nat64_defs.h:297
struct nat64_v4_to_v6_pipeline_data_ nat64_v4_to_v6_pipeline_data_t
nat64_inst_gen_counter_t nat64_inst_gen_counters[NAT64_MAX_NAT64_ENTRIES]
nat64_v4_to_v6_icmp_counter_t v46_icmp_counters
Definition: nat64_defs.h:217
#define BITS_PER_INST
Definition: cnat_ports.h:30
u32 v6_if_num
Definition: nat64_defs.h:375
nat64_table_entry_t * nat64_table_ptr
u16 v4_uidb_index
Definition: nat64_defs.h:310
u8 v6_prefix_mask_len
Definition: nat64_defs.h:327
nat64_v4_to_v6_tcp_counter_t * tcp_counter
Definition: nat64_defs.h:565
nat64_v4_db_key_t k
Definition: nat64_defs.h:253
nat64_v4_to_v6_udp_counter_t * udp_counter
Definition: nat64_defs.h:566
unsigned int u32
Definition: types.h:88
nat64_tcp_events tcp_event
Definition: nat64_defs.h:557
u32 nat64_out2in_forwarding_count_old[NAT64_MAX_NAT64_ENTRIES]
u8 nat64_refresh_both_direction
Definition: nat64_defs.h:355
u8 tcp_v4_init_enable
Definition: nat64_defs.h:345
u8 feature_flags
Definition: nat64_defs.h:332
u8 df_bit_clear
Definition: nat64_defs.h:336
u32 nat64_out2in_forwarding_count[NAT64_MAX_NAT64_ENTRIES]
struct nat64_v6_to_v4_pipeline_data_ nat64_v6_to_v4_pipeline_data_t
u64 nat64_v4_frag_tcp_input_count
Definition: nat64_defs.h:160
nat64_v6_to_v4_udp_counter_t v64_udp_counters
Definition: nat64_defs.h:214
nat64_v4_to_v6_icmp_error_counter_t v46_icmp_error_counters
Definition: nat64_defs.h:219
l4_frag_info_t * frag_info
Definition: nat64_defs.h:478
nat64_v6_to_v4_icmp_counter_t * icmp_counter
Definition: nat64_defs.h:485
u64 uword
Definition: types.h:112
u32 v6_vrf_id
Definition: nat64_defs.h:372
tcp_hdr_type * ipv6_tcp_header
Definition: nat64_defs.h:553
u64 nat64_v6_frag_udp_input_count
Definition: nat64_defs.h:170
unsigned short u16
Definition: types.h:57
u64 nat64_v6_frag_tcp_input_count
Definition: nat64_defs.h:169
u8 frag_state
Definition: nat64_defs.h:384
#define NAT64_MAX_NAT64_ENTRIES
Definition: nat64_defs.h:36
unsigned char u8
Definition: types.h:56
nat64_options_counter_t * options_counter
Definition: nat64_defs.h:488
nat64_v6_to_v4_tcp_counter_t * tcp_counter
Definition: nat64_defs.h:483
u16 total_length
Definition: nat64_defs.h:300
u8 filtering_policy
Definition: nat64_defs.h:339
u32 v4_vrf_id
Definition: nat64_defs.h:371
u16 * nat64_frag_id_counter_ptr
nat64_icmp_gen_counter_t * icmp_gen_counter
Definition: nat64_defs.h:490
u32 nat64_in2out_forwarding_count_old[NAT64_MAX_NAT64_ENTRIES]
u16 v6_to_v4_tcp_mss
Definition: nat64_defs.h:319
nat64_frag_counter_t * frag_counter
Definition: nat64_defs.h:569
u8 logging_policy
Definition: nat64_defs.h:348
u32 nat64_translation_create_rate[NAT64_MAX_NAT64_ENTRIES]
#define BITS(x)
Definition: clib.h:58
nat64_icmp_gen_counter_t * icmp_gen_counter
Definition: nat64_defs.h:572
nat64_timeout_info_t timeout_info
Definition: nat64_defs.h:367
nat64_common_pipeline_data_t common_data
Definition: nat64_defs.h:410
nat64_table_entry_t nat64_table_array[NAT64_MAX_NAT64_ENTRIES]