FD.io VPP  v21.01.1
Vector Packet Processing
cnat_types.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __CNAT_TYPES_H__
17 #define __CNAT_TYPES_H__
18 
19 #include <vppinfra/bihash_24_8.h>
20 #include <vnet/fib/fib_node.h>
21 #include <vnet/fib/fib_source.h>
22 #include <vnet/ip/ip_types.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/util/throttle.h>
25 
26 /* only in the default table for v4 and v6 */
27 #define CNAT_FIB_TABLE 0
28 
29 /* default lifetime of NAT sessions (seconds) */
30 #define CNAT_DEFAULT_SESSION_MAX_AGE 30
31 /* lifetime of TCP conn NAT sessions after SYNACK (seconds) */
32 #define CNAT_DEFAULT_TCP_MAX_AGE 3600
33 /* lifetime of TCP conn NAT sessions after RST/FIN (seconds) */
34 #define CNAT_DEFAULT_TCP_RST_TIMEOUT 5
35 #define CNAT_DEFAULT_SCANNER_TIMEOUT (1.0)
36 
37 #define CNAT_DEFAULT_SESSION_BUCKETS 1024
38 #define CNAT_DEFAULT_TRANSLATION_BUCKETS 1024
39 #define CNAT_DEFAULT_SNAT_BUCKETS 1024
40 
41 #define CNAT_DEFAULT_SESSION_MEMORY (1 << 20)
42 #define CNAT_DEFAULT_TRANSLATION_MEMORY (256 << 10)
43 #define CNAT_DEFAULT_SNAT_MEMORY (64 << 20)
44 
45 /* This should be strictly lower than FIB_SOURCE_INTERFACE
46  * from fib_source.h */
47 #define CNAT_FIB_SOURCE_PRIORITY 0x02
48 
49 /* Initial refcnt for timestamps (2 : session & rsession) */
50 #define CNAT_TIMESTAMP_INIT_REFCNT 2
51 
52 #define MIN_SRC_PORT ((u16) 0xC000)
53 
54 typedef enum
55 {
56  /* Endpoint addr has been resolved */
59 
60 typedef struct cnat_endpoint_t_
61 {
67 
68 typedef struct cnat_endpoint_tuple_t_
69 {
73 
74 typedef struct
75 {
79 
80 typedef struct
81 {
82  u32 dst_address_length_refcounts[129];
86 
87 typedef struct
88 {
89  /* Stores (ip family, prefix & mask) */
90  clib_bihash_24_8_t ip_hash;
91  /* family dependant cache */
93  /* Precomputed ip masks (ip4 & ip6) */
94  ip6_address_t ip_masks[129];
96 
97 typedef struct cnat_main_
98 {
99  /* Memory size of the session bihash */
101 
102  /* Number of buckets of the session bihash */
104 
105  /* Memory size of the translation bihash */
107 
108  /* Number of buckets of the translation bihash */
110 
111  /* Memory size of the source NAT prefix bihash */
113 
114  /* Number of buckets of the source NAT prefix bihash */
116 
117  /* Timeout after which to clear sessions (in seconds) */
119 
120  /* Timeout after which to clear an established TCP
121  * session (in seconds) */
123 
124  /* delay in seconds between two scans of session/clients tables */
126 
127  /* Lock for the timestamp pool */
129 
130  /* Ip4 Address to use for source NATing */
132 
133  /* Ip6 Address to use for source NATing */
135 
136  /* Longest prefix Match table for source NATing */
138 
139  /* Index of the scanner process node */
141 
142  /* Did we do lazy init ? */
144 
145  /* Enable or Disable the scanner on startup */
147 } cnat_main_t;
148 
149 typedef struct cnat_timestamp_t_
150 {
151  /* Last time said session was seen */
153  /* expire after N seconds */
155  /* Users refcount, initially 3 (session, rsession, dpo) */
158 
159 typedef struct cnat_node_ctx_
160 {
167 
169 extern u8 *format_cnat_endpoint (u8 * s, va_list * args);
171  va_list * args);
172 extern uword unformat_cnat_ep (unformat_input_t * input, va_list * args);
175 extern cnat_main_t cnat_main;
177 
178 extern char *cnat_error_strings[];
179 
180 typedef enum
181 {
182 #define cnat_error(n,s) CNAT_ERROR_##n,
183 #include <cnat/cnat_error.def>
184 #undef cnat_error
186 } cnat_error_t;
187 
189 {
193 
194 /**
195  * Lazy initialization when first adding a translation
196  * or using snat
197  */
198 extern void cnat_lazy_init ();
199 
200 /**
201  * Enable/Disable session cleanup
202  */
203 extern void cnat_enable_disable_scanner (cnat_scanner_cmd_t event_type);
204 
205 /**
206  * Resolve endpoint address
207  */
208 extern u8 cnat_resolve_ep (cnat_endpoint_t * ep);
210  ip_address_t * addr);
211 
212 
213 /*
214  * fd.io coding-style-patch-verification: ON
215  *
216  * Local Variables:
217  * eval: (c-set-style "gnu")
218  * End:
219  */
220 
221 #endif
cnat_ep_flag_t
Definition: cnat_types.h:54
enum fib_source_t_ fib_source_t
The different sources that can create a route.
enum cnat_scanner_cmd_t_ cnat_scanner_cmd_t
cnat_endpoint_t snat_ip6
Definition: cnat_types.h:134
unsigned long u64
Definition: types.h:89
u8 default_scanner_state
Definition: cnat_types.h:146
throttle_t cnat_throttle
Definition: cnat_types.c:21
struct cnat_node_ctx_ cnat_node_ctx_t
u32 session_hash_buckets
Definition: cnat_types.h:103
cnat_endpoint_t src_ep
Definition: cnat_types.h:71
vhost_vring_addr_t addr
Definition: vhost_user.h:111
cnat_timestamp_t * cnat_timestamps
Definition: cnat_types.c:20
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
u8 lazy_init_done
Definition: cnat_types.h:143
cnat_endpoint_t dst_ep
Definition: cnat_types.h:70
void cnat_enable_disable_scanner(cnat_scanner_cmd_t event_type)
Enable/Disable session cleanup.
Definition: cnat_types.c:161
u8 cnat_resolve_addr(u32 sw_if_index, ip_address_family_t af, ip_address_t *addr)
Definition: cnat_types.c:30
clib_bihash_24_8_t ip_hash
Definition: cnat_types.h:90
unsigned int u32
Definition: types.h:88
struct cnat_main_ cnat_main_t
uword unformat_cnat_ep_tuple(unformat_input_t *input, va_list *args)
Definition: cnat_types.c:107
uword unformat_cnat_ep(unformat_input_t *input, va_list *args)
Definition: cnat_types.c:74
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
A throttle Used in the data plane to decide if a given hash should be throttled, i.e.
Definition: throttle.h:28
f64 scanner_timeout
Definition: cnat_types.h:125
char * cnat_error_strings[]
Definition: cnat_types.c:23
ip_address_family_t af
Definition: cnat_types.h:164
cnat_main_t cnat_main
Definition: cnat_types.c:18
uword session_hash_memory
Definition: cnat_types.h:100
clib_rwlock_t ts_lock
Definition: cnat_types.h:128
cnat_main_t * cnat_get_main()
Definition: cnat_types.c:233
cnat_snat_pfx_table_t snat_pfx_table
Definition: cnat_types.h:137
cnat_scanner_cmd_t_
Definition: cnat_types.h:188
u32 session_max_age
Definition: cnat_types.h:118
enum ip_address_family_t_ ip_address_family_t
u32 translation_hash_buckets
Definition: cnat_types.h:109
uword * non_empty_dst_address_length_bitmap
Definition: cnat_types.h:84
u64 uword
Definition: types.h:112
fib_source_t cnat_fib_source
Definition: cnat_types.c:19
uword translation_hash_memory
Definition: cnat_types.h:106
u32 tcp_max_age
Definition: cnat_types.h:122
uword scanner_node_index
Definition: cnat_types.h:140
u8 * format_cnat_endpoint(u8 *s, va_list *args)
Definition: cnat_types.c:123
ip_address_t ce_ip
Definition: cnat_types.h:62
void cnat_lazy_init()
Lazy initialization when first adding a translation or using snat.
Definition: cnat_types.c:168
cnat_error_t
Definition: cnat_types.h:180
struct cnat_timestamp_t_ cnat_timestamp_t
cnat_endpoint_t snat_ip4
Definition: cnat_types.h:131
struct cnat_endpoint_tuple_t_ cnat_endpoint_tuple_t
struct cnat_endpoint_t_ cnat_endpoint_t
u32 snat_hash_buckets
Definition: cnat_types.h:115
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
uword snat_hash_memory
Definition: cnat_types.h:112
u8 cnat_resolve_ep(cnat_endpoint_t *ep)
Resolve endpoint address.
Definition: cnat_types.c:64