FD.io VPP  v16.06
Vector Packet Processing
cnat_ports.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * cnat_ports.h - port database definitions
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 __CNAT_PORTS_H__
21 #define __CNAT_PORTS_H__
22 
23 #include "platform_common.h"
24 #include "cnat_bulk_port_defs.h"
25 
26 #define PORTS_PER_ADDR 65536
27 
28 #define CNAT_INSTS PLATFORM_CNAT_INSTS
29 
30 #define BITS_PER_INST (PORTS_PER_ADDR)
31 
32 /*
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
35  */
36 #define MIN_STATIC_PORT_RANGE_FOR_RTSP (9900)
37 
38 extern u8 my_instance_number;
39 
40 /*
41  * Now it is a 1-to-1 mapping between bit and port values
42  */
43 static inline u16 bit2port (u32 bit)
44 {
45  return bit;
46 }
47 
48 static inline uword port2bit (u16 port)
49 {
50  return port;
51 }
52 
53 /*
54  * Port bitmap structure
55  * THIS structure is not used to be REMOVED....
56  */
57 
58 
59 typedef struct {
60  u32 ipv4_address; /* native bit order */
66 
67 //cnat_portmap_t *cnat_portmap;
68 
69 
70 typedef struct {
73  u32 ipv4_address; /* native bit order */
77  u32 private_ip_users_count; /* number of private ip's(subscribers) to this
78  public ip */
80 
81 
82 typedef enum {
87 } port_pair_t;
88 
89 typedef enum {
93 } port_type_t;
94 
95 
96 typedef enum {
99 } port_alloc_t;
100 
101 #define PORT_PROBE_LIMIT 20
102 
103 
104 /*
105  * randq1
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.
110  */
111 static inline u32 randq1 (u32 prev)
112 {
113  return (1664525L*prev + 1013904223L);
114 }
115 
118  cnat_portmap_v2_t *pm,
119  port_alloc_t atype,
120  port_pair_t pair_type,
121  u32 i_ipv4_address,
122  u16 i_port,
123  u32 *index,
124  u32 *o_ipv4_address,
125  u16 *o_port,
126  u16 static_port_range
127 #ifndef NO_BULK_LOGGING
128  , bulk_alloc_size_t bulk_size,
129  int *nfv9_log_req
130 #endif /* NO_BULK_LOGGING */
131  , u16 ip_n_to_1
132  );
133 
136  cnat_portmap_v2_t *pm,
137  port_alloc_t atype,
138  u32 *index,
139  u32 ipv4_address,
140  u16 port
141 #ifndef NO_BULK_LOGGING
142  , int *nfv9_log_req,
143  bulk_alloc_size_t bulk_size
144 #endif
145  , u16 ip_n_to_1
146  );
147 
150  cnat_portmap_v2_t *pm,
151  port_alloc_t atype,
152  port_pair_t pair_type,
153  u32 *index,
154  u32 *o_ipv4_address,
155  u16 *o_port,
156  u16 static_port_range
157 #ifndef NO_BULK_LOGGING
158  , bulk_alloc_size_t bulk_size,
159  int *nfv9_log_req
160 #endif
161  , u16 ip_n_to_1,
162  u32 *rseed_ip
163  );
164 
165 
168  cnat_portmap_v2_t *pm,
169  port_alloc_t atype,
170  port_pair_t pair_type,
171  u16 start_range,
172  u16 end_range,
173  u32 *index,
174  u32 *o_ipv4_address,
175  u16 *o_port
176 #ifndef NO_BULK_LOGGING
177  , bulk_alloc_size_t bulk_size,
178  int *nfv9_log_req
179 #endif
180  , u32 *rseed_ip
181  );
182 
183 void cnat_port_free_v2(
184  cnat_portmap_v2_t *pm,
185  int index,
186  port_pair_t ptype,
187  u16 base_port,
188  u16 static_port_range);
189 
191  u16 print_limit);
192 
193 
194 
197  cnat_portmap_v2_t *pm,
198  port_alloc_t atype,
199  port_pair_t pair_type,
200  u32 *i_ipv6_address,
201  u16 i_port,
202  u32 *index,
203  u32 *o_ipv4_address,
204  u16 *o_port);
205 
206 
207 
208 #endif /* __CNAT_PORTS_H__ */
static u16 bit2port(u32 bit)
Definition: cnat_ports.h:43
u8 my_instance_number
Definition: cnat_ports.c:51
u32 private_ip_users_count
Definition: cnat_ports.h:77
static u32 randq1(u32 prev)
Definition: cnat_ports.h:111
cnat_errno_t cnat_static_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 i_ipv4_address, u16 i_port, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1)
Definition: cnat_ports.c:135
cnat_errno_t
Definition: cnat_cli.h:26
port_type_t
Definition: cnat_ports.h:89
cnat_errno_t cnat_dynamic_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1, u32 *rseed_ip)
Definition: cnat_ports.c:554
cnat_errno_t cnat_dynamic_port_alloc_rtsp(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u16 start_range, u16 end_range, u32 *index, u32 *o_ipv4_address, u16 *o_port, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u32 *rseed_ip)
Definition: cnat_ports.c:906
cnat_errno_t nat64_static_port_alloc(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 *i_ipv6_address, u16 i_port, u32 *index, u32 *o_ipv4_address, u16 *o_port)
u32 threshold_crossed
Definition: cnat_ports.h:63
#define BITS_PER_INST
Definition: cnat_ports.h:30
static uword port2bit(u16 port)
Definition: cnat_ports.h:48
unsigned int u32
Definition: types.h:88
cnat_errno_t cnat_mapped_static_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, u32 *index, u32 ipv4_address, u16 port, int *nfv9_log_req, bulk_alloc_size_t bulk_size, u16 ip_n_to_1)
Definition: cnat_ports.c:932
port_alloc_t
Definition: cnat_ports.h:96
port_pair_t
Definition: cnat_ports.h:82
u64 uword
Definition: types.h:112
unsigned short u16
Definition: types.h:57
void cnat_portmap_dump_v2(cnat_portmap_v2_t *pm, u16 print_limit)
Definition: cnat_ports.c:1072
void cnat_port_free_v2(cnat_portmap_v2_t *pm, int index, port_pair_t ptype, u16 base_port, u16 static_port_range)
Definition: cnat_ports.c:1037
unsigned char u8
Definition: types.h:56
bulk_alloc_size_t
#define BITS(x)
Definition: clib.h:58