2 *------------------------------------------------------------------
3 * dslite_db.h - Stateful DSLITE translation database definitions
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
19 #ifndef __DSLITE_DB_H__
20 #define __DSLITE_DB_H__
23 #include "index_list.h"
24 #include "cnat_ports.h"
26 #include "dslite_defs.h"
28 #define DSLITE_PRINTF(level, ...) \
29 if (dslite_debug_level > level) PLATFORM_DEBUG_PRINT(__VA_ARGS__);
31 #define DSLITE_PRINTF(lvl, ...) \
33 avsm_dispatlib_debug (__VA_ARGS__); \
37 #define HASH_ENHANCE 4
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)
43 #define DSLITE_MAIN_HASH_MASK (DSLITE_MAIN_HASH_SIZE-1)
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)
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
55 #define CNAT_MAX_SESSIONS_PER_BIB 0xFFFF
57 #define FORCE_DEL 1 /* Delete static BIB entries as well */
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 */
68 extern u32 dslite_translation_create_count;
69 extern u32 dslite_translation_delete_count;
70 extern u32 dslite_translation_create_rate;
71 extern u32 dslite_translation_delete_rate;
72 extern u32 dslite_in2out_forwarding_count;
73 extern u32 dslite_in2out_forwarding_rate;
74 extern u32 dslite_out2in_forwarding_count;
75 extern u32 dslite_out2in_forwarding_rate;
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); \
83 /* Jenkins hash, arbitrarily use c as the "answer" */ \
84 hash_mix32(a, b, c); \
88 #define DSLITE_V6_GET_USER_HASH(ipv6, hash, mask) \
89 a = ipv6[0] ^ ipv6[1] ^ ipv6[2] ^ ipv6[3]; \
91 /* Jenkins hash, arbitrarily use c as the "answer" */ \
92 hash_mix32(a, b, c); \
95 #define DSLITE_V4_GET_HASH(in_key, hash, mask) \
96 a = in_key.ipv4 ^ ((in_key.port << 16) | in_key.vrf); \
98 /* Jenkins hash, arbitrarily use c as the "answer" */ \
99 hash_mix32(a, b, c); \
102 #define PRIVATE_V4_ADDR_CHECK(addr, invalid) \
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) \
111 #define V4_MAPPED_V6_CHECK(v6_addr, invalid) \
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))) \
120 extern dslite_table_entry_t dslite_table_array[DSLITE_MAX_DSLITE_ENTRIES];
121 extern dslite_table_entry_t *dslite_table_ptr;
123 #define DSLITE_CMP_V6_KEY(key1, key2) \
124 memcmp(key1, key2, sizeof(dslite_v6_key_t))
126 #define DSLITE_CMP_V4_KEY(key1, key2) \
127 memcmp(key1, key2, sizeof(dslite_v4_key_t))
130 #define DSLITE_CMP_V6_IP(ip1, ip2) \
131 memcmp(ip1, ip2, (sizeof(u32) * 4))
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)
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]))
144 #define DSLITE_CMP_V4_KEY1(key1, key2) \
145 (key1.key64 == key2.key64)
147 cnat_main_db_entry_t*
148 dslite_get_main_db_entry_v2(dslite_db_key_bucket_t *ki,
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);
155 cnat_main_db_entry_t*
156 dslite_main_db_lookup_entry(dslite_db_key_bucket_t *ki);
159 cnat_user_db_entry_t*
160 dslite_user_db_lookup_entry(dslite_db_key_bucket_t *uki);
162 cnat_user_db_entry_t*
163 dslite_user_db_create_entry(dslite_db_key_bucket_t *uki, u32 portmap_index);
165 cnat_main_db_entry_t*
166 dslite_create_main_db_entry_and_hash(dslite_db_key_bucket_t *ki,
167 cnat_db_key_bucket_t *ko,
168 cnat_user_db_entry_t *udb);