2 *------------------------------------------------------------------
3 * cnat_ports.h - port database definitions
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:
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 *------------------------------------------------------------------
20 #ifndef __CNAT_PORTS_H__
21 #define __CNAT_PORTS_H__
23 #include "platform_common.h"
24 #include "cnat_bulk_port_defs.h"
26 #define PORTS_PER_ADDR 65536
28 #define CNAT_INSTS PLATFORM_CNAT_INSTS
30 #define BITS_PER_INST (PORTS_PER_ADDR)
33 * Ensure that atleast few 4 bit ports are available for RTSP
34 * in case we want to map 4 digit inside ports to 4 digit outside ports
36 #define MIN_STATIC_PORT_RANGE_FOR_RTSP (9900)
38 extern u8 my_instance_number;
41 * Now it is a 1-to-1 mapping between bit and port values
43 static inline u16 bit2port (u32 bit)
48 static inline uword port2bit (u16 port)
54 * Port bitmap structure
55 * THIS structure is not used to be REMOVED....
60 u32 ipv4_address; /* native bit order */
63 u32 threshold_crossed;
64 uword bm[(BITS_PER_INST + BITS(uword)-1)/BITS(uword)];
67 //cnat_portmap_t *cnat_portmap;
73 u32 ipv4_address; /* native bit order */
74 u32 last_sent_timestamp;
75 uword bm[(BITS_PER_INST + BITS(uword)-1)/BITS(uword)];
77 u32 private_ip_users_count; /* number of private ip's(subscribers) to this
98 PORT_ALLOC_DIRECTED=2,
101 #define PORT_PROBE_LIMIT 20
106 * Linear congruential random number generator with
107 * extensively studied properties. See Numerical Recipes in C
108 * 2nd Ed. page 284. Known to behave according to the test vector
109 * supplied in the text, on X86 and Octeon.
111 static inline u32 randq1 (u32 prev)
113 return (1664525L*prev + 1013904223L);
117 cnat_static_port_alloc_v2(
118 cnat_portmap_v2_t *pm,
120 port_pair_t pair_type,
126 u16 static_port_range
127 #ifndef NO_BULK_LOGGING
128 , bulk_alloc_size_t bulk_size,
130 #endif /* NO_BULK_LOGGING */
135 cnat_mapped_static_port_alloc_v2 (
136 cnat_portmap_v2_t *pm,
141 #ifndef NO_BULK_LOGGING
143 bulk_alloc_size_t bulk_size
149 cnat_dynamic_port_alloc_v2(
150 cnat_portmap_v2_t *pm,
152 port_pair_t pair_type,
156 u16 static_port_range
157 #ifndef NO_BULK_LOGGING
158 , bulk_alloc_size_t bulk_size,
167 cnat_dynamic_port_alloc_rtsp (
168 cnat_portmap_v2_t *pm,
170 port_pair_t pair_type,
176 #ifndef NO_BULK_LOGGING
177 , bulk_alloc_size_t bulk_size,
183 void cnat_port_free_v2(
184 cnat_portmap_v2_t *pm,
188 u16 static_port_range);
190 void cnat_portmap_dump_v2(cnat_portmap_v2_t *pm,
196 nat64_static_port_alloc (
197 cnat_portmap_v2_t *pm,
199 port_pair_t pair_type,
208 #endif /* __CNAT_PORTS_H__ */