FD.io VPP  v16.06
Vector Packet Processing
dslite_db.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * dslite_db.h - Stateful DSLITE translation database definitions
4  *
5  * Copyright (c) 2010-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 #ifndef __DSLITE_DB_H__
20 #define __DSLITE_DB_H__
21 
22 #include "cnat_cli.h"
23 #include "index_list.h"
24 #include "cnat_ports.h"
25 #include "cnat_db.h"
26 #include "dslite_defs.h"
27 
28 #define DSLITE_PRINTF(level, ...) \
29  if (dslite_debug_level > level) PLATFORM_DEBUG_PRINT(__VA_ARGS__);
30 /*
31 #define DSLITE_PRINTF(lvl, ...) \
32 { \
33  avsm_dispatlib_debug (__VA_ARGS__); \
34 }
35 */
36 
37 #define HASH_ENHANCE 4
38 //#define DSLITE_DEF
39 #define DSLITE_MAIN_DB_SIZE (20000000 / PLATFORM_CNAT_INSTS)
40 #define DSLITE_MAIN_HASH_SIZE \
41  (HASH_ENHANCE * PLATFORM_CNAT_MAIN_PRELIM_HASH_SIZE)
42 
43 #define DSLITE_MAIN_HASH_MASK (DSLITE_MAIN_HASH_SIZE-1)
44 
45 
46 /* nb: 200000 users / 64 CNAT = 3125, 76% occupancy */
47 #define DSLITE_USER_HASH_SIZE CNAT_USER_HASH_SIZE
48 #define DSLITE_USER_HASH_MASK (DSLITE_USER_HASH_SIZE-1)
49 
50 /* No. of per ip/port config will be limited to 1000 */
51 #define DSLITE_TIMEOUT_HASH_SIZE 1000
52 #define DSLITE_TIMEOUT_HASH_MASK (DSLITE_TIMEOUT_HASH_SIZE - 1)
53 #define DSLITE_TIMEOUT_FULL_MASK 0xFFFFFFFFFFFFFFFF
54 
55 #define CNAT_MAX_SESSIONS_PER_BIB 0xFFFF
56 
57 #define FORCE_DEL 1 /* Delete static BIB entries as well */
58 
59 /* default timeout values */
60 #define DSLITE_UDP_DEFAULT 300 /* 5 min */
61 #define DSLITE_UDP_MIN 120 /* 2 min */
62 #define DSLITE_TCP_TRANS 240 /* 4 min */
63 #define DSLITE_TCP_EST 7200 /* 2 hrs */
64 #define DSLITE_TCP_V4_SYN 6 /* 6 sec */
65 #define DSLITE_FRAG_MIN 2 /* 2 sec */
66 #define DSLITE_ICMP_DEFAULT 60 /* 1 min */
67 
76 
77 #define DSLITE_V6_GET_HASH(in_key, hash, mask) \
78  a = in_key->ipv6[0] ^ in_key->ipv6[1] ^ in_key->ipv6[2] ^ in_key->ipv6[3] \
79  ^ in_key->ipv4_key.k.ipv4 ^ ((in_key->ipv4_key.k.port << 16) | in_key->ipv4_key.k.vrf); \
80  DSLITE_PRINTF(1, "%x:%x:%x:%x:%x:%x:%x\n", in_key->ipv6[0], in_key->ipv6[1], in_key->ipv6[2], in_key->ipv6[3], \
81  in_key->ipv4_key.k.ipv4, in_key->ipv4_key.k.port, in_key->ipv4_key.k.vrf); \
82  b = c = 0x9e3779b9;\
83  /* Jenkins hash, arbitrarily use c as the "answer" */ \
84  hash_mix32(a, b, c); \
85  hash = c & mask; \
86 
87 
88 #define DSLITE_V6_GET_USER_HASH(ipv6, hash, mask) \
89  a = ipv6[0] ^ ipv6[1] ^ ipv6[2] ^ ipv6[3]; \
90  b = c = 0x9e3779b9;\
91  /* Jenkins hash, arbitrarily use c as the "answer" */ \
92  hash_mix32(a, b, c); \
93  hash = c & mask; \
94 
95 #define DSLITE_V4_GET_HASH(in_key, hash, mask) \
96  a = in_key.ipv4 ^ ((in_key.port << 16) | in_key.vrf); \
97  b = c = 0x9e3779b9; \
98  /* Jenkins hash, arbitrarily use c as the "answer" */ \
99  hash_mix32(a, b, c); \
100  hash = c & mask;
101 
102 #define PRIVATE_V4_ADDR_CHECK(addr, invalid) \
103  invalid = 0; \
104  int range1 = ((addr & 0xFF000000) >> 24); \
105  int range2 = ((addr & 0xFFF00000) >> 20); \
106  int range3 = ((addr & 0xFFFF0000) >> 16); \
107  int range4 = ((addr & 0xFFFFFFF8) >> 3); \
108  if(range1 != 0xa && range2 != 0xac1 && range3 != 0xc0a8 && range4 != 0x18000000) \
109  invalid = 1;
110 
111 #define V4_MAPPED_V6_CHECK(v6_addr, invalid) \
112  invalid = 0; \
113  int word1 = v6_addr[0]; \
114  int word2 = v6_addr[1]; \
115  int word3 = v6_addr[2]; \
116  if(!((word1 == 0) && (word2 == 0) && (word3 == 0x0000FFFF))) \
117  invalid = 1;
118 
119 
122 
123 #define DSLITE_CMP_V6_KEY(key1, key2) \
124  memcmp(key1, key2, sizeof(dslite_v6_key_t))
125 
126 #define DSLITE_CMP_V4_KEY(key1, key2) \
127  memcmp(key1, key2, sizeof(dslite_v4_key_t))
128 
129 
130 #define DSLITE_CMP_V6_IP(ip1, ip2) \
131  memcmp(ip1, ip2, (sizeof(u32) * 4))
132 
133 
134 #define DSLITE_CMP_V6_KEY1(key1, key2) \
135  (key1.ipv6[0] == key2.ipv6[0]) && (key1.ipv6[1] == key2.ipv6[1]) && \
136  (key1.ipv6[2] == key2.ipv6[2]) && (key1.ipv6[3] == key2.ipv6[3]) && \
137  (key1.port == key2.port) && (key1.vrf == key2.vrf)
138 
139 
140 #define DSLITE_CMP_V6_IP1(ip1, ip2) \
141  ((ip1[0] == ip2[0]) && (ip1[1] == ip2[1]) && \
142  (ip1[2] == ip2[2]) && (ip1[3] == ip2[3]))
143 
144 #define DSLITE_CMP_V4_KEY1(key1, key2) \
145  (key1.key64 == key2.key64)
146 
149  port_pair_t port_pair_type,
150  port_type_t port_type,
151  cnat_gen_icmp_info *info,
152  dslite_table_entry_t *dslite_entry_ptr,
153  cnat_key_t *dest_info);
154 
157 
158 
161 
164 
168  cnat_user_db_entry_t *udb);
169 
170 #endif
cnat_user_db_entry_t * dslite_user_db_lookup_entry(dslite_db_key_bucket_t *uki)
Definition: cnat_db_v2.c:2863
u32 dslite_translation_create_count
Definition: cnat_db.h:153
dslite_table_entry_t * dslite_table_ptr
cnat_main_db_entry_t * dslite_get_main_db_entry_v2(dslite_db_key_bucket_t *ki, port_pair_t port_pair_type, port_type_t port_type, cnat_gen_icmp_info *info, dslite_table_entry_t *dslite_entry_ptr, cnat_key_t *dest_info)
Definition: cnat_db_v2.c:3047
port_type_t
Definition: cnat_ports.h:89
Definition: dslite_defs.h:106
cnat_user_db_entry_t * dslite_user_db_create_entry(dslite_db_key_bucket_t *uki, u32 portmap_index)
Definition: cnat_db_v2.c:2897
u32 dslite_in2out_forwarding_count
u32 dslite_translation_delete_rate
dslite_table_entry_t dslite_table_array[DSLITE_MAX_DSLITE_ENTRIES]
Definition: cnat_db.h:285
unsigned int u32
Definition: types.h:88
port_pair_t
Definition: cnat_ports.h:82
#define DSLITE_MAX_DSLITE_ENTRIES
Definition: dslite_defs.h:84
u32 dslite_out2in_forwarding_count
cnat_main_db_entry_t * dslite_create_main_db_entry_and_hash(dslite_db_key_bucket_t *ki, cnat_db_key_bucket_t *ko, cnat_user_db_entry_t *udb)
Definition: cnat_db_v2.c:2930
u32 dslite_translation_delete_count
cnat_main_db_entry_t * dslite_main_db_lookup_entry(dslite_db_key_bucket_t *ki)
Definition: cnat_db_v2.c:2821
u32 dslite_translation_create_rate
u32 dslite_in2out_forwarding_rate
u32 dslite_out2in_forwarding_rate