FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
cnat_types.c
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 #include <cnat/cnat_types.h>
17 
22 
23 char *cnat_error_strings[] = {
24 #define cnat_error(n,s) s,
25 #include <cnat/cnat_error.def>
26 #undef cnat_error
27 };
28 
29 uword
30 unformat_cnat_ep (unformat_input_t * input, va_list * args)
31 {
32  cnat_endpoint_t *a = va_arg (*args, cnat_endpoint_t *);
33  int port = 0;
34 
35  clib_memset (a, 0, sizeof (*a));
36  if (unformat (input, "%U %d", unformat_ip_address, &a->ce_ip, &port))
37  ;
38  else if (unformat_user (input, unformat_ip_address, &a->ce_ip))
39  ;
40  else if (unformat (input, "%d", &port))
41  ;
42  else
43  return 0;
44  a->ce_port = (u16) port;
45  return 1;
46 }
47 
48 uword
49 unformat_cnat_ep_tuple (unformat_input_t * input, va_list * args)
50 {
51  cnat_endpoint_tuple_t *a = va_arg (*args, cnat_endpoint_tuple_t *);
52  if (unformat (input, "%U->%U", unformat_cnat_ep, &a->src_ep,
54  ;
55  else if (unformat (input, "->%U", unformat_cnat_ep, &a->dst_ep))
56  ;
57  else if (unformat (input, "%U->", unformat_cnat_ep, &a->src_ep))
58  ;
59  else
60  return 0;
61  return 1;
62 }
63 
64 u8 *
65 format_cnat_endpoint (u8 * s, va_list * args)
66 {
67  cnat_endpoint_t *cep = va_arg (*args, cnat_endpoint_t *);
68 
69  s = format (s, "%U;%d", format_ip_address, &cep->ce_ip, cep->ce_port);
70 
71  return (s);
72 }
73 
74 static clib_error_t *
76 {
78  u32 n_vlib_mains = tm->n_vlib_mains;
82 
83  clib_rwlock_init (&cnat_main.ts_lock);
85  clib_bitmap_validate (cnat_main.src_ports, UINT16_MAX);
86  throttle_init (&cnat_throttle, n_vlib_mains, 1e-3);
87 
88  return (NULL);
89 }
90 
91 static clib_error_t *
93 {
95 
105 
107  {
108  if (unformat
109  (input, "session-db-buckets %u", &cm->session_hash_buckets))
110  ;
111  else if (unformat (input, "session-db-memory %U",
113  ;
114  else if (unformat (input, "translation-db-buckets %u",
116  ;
117  else if (unformat (input, "translation-db-memory %U",
119  ;
120  else if (unformat (input, "snat-db-buckets %u", &cm->snat_hash_buckets))
121  ;
122  else if (unformat (input, "snat-db-memory %U",
124  ;
125  else if (unformat (input, "session-cleanup-timeout %f",
126  &cm->scanner_timeout))
127  ;
128  else if (unformat (input, "session-max-age %u", &cm->session_max_age))
129  ;
130  else if (unformat (input, "tcp-max-age %u", &cm->tcp_max_age))
131  ;
132  else
133  return clib_error_return (0, "unknown input '%U'",
134  format_unformat_error, input);
135  }
136 
137  return 0;
138 }
139 
142 
143 /*
144  * fd.io coding-style-patch-verification: ON
145  *
146  * Local Variables:
147  * eval: (c-set-style "gnu")
148  * End:
149  */
enum fib_source_t_ fib_source_t
The different sources that can create a route.
#define CNAT_DEFAULT_TRANSLATION_MEMORY
Definition: cnat_types.h:40
a
Definition: bitmap.h:538
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
throttle_t cnat_throttle
Definition: cnat_types.c:21
add paths without path extensions
Definition: fib_source.h:205
void throttle_init(throttle_t *t, u32 n_threads, f64 time)
Definition: throttle.c:19
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vlib_main_t * vm
Definition: in2out_ed.c:1582
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u32 session_hash_buckets
Definition: cnat_types.h:89
cnat_endpoint_t src_ep
Definition: cnat_types.h:61
unsigned char u8
Definition: types.h:56
#define clib_bitmap_validate(v, n_bits)
Definition: bitmap.h:115
uword unformat_cnat_ep(unformat_input_t *input, va_list *args)
Definition: cnat_types.c:30
cnat_endpoint_t dst_ep
Definition: cnat_types.h:60
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
#define CNAT_DEFAULT_SESSION_MAX_AGE
Definition: cnat_types.h:28
fib_source_t fib_source_allocate(const char *name, fib_source_priority_t prio, fib_source_behaviour_t bh)
Definition: fib_source.c:118
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:63
vnet_crypto_main_t * cm
Definition: quic_crypto.c:53
static void clib_rwlock_init(clib_rwlock_t *p)
Definition: lock.h:150
fib_source_t cnat_fib_source
Definition: cnat_types.c:19
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
cnat_timestamp_t * cnat_timestamps
Definition: cnat_types.c:20
clib_spinlock_t src_ports_lock
Definition: cnat_types.h:120
u8 * format_cnat_endpoint(u8 *s, va_list *args)
Definition: cnat_types.c:65
#define CNAT_FIB_SOURCE_PRIORITY
Definition: cnat_types.h:45
static clib_error_t * cnat_config(vlib_main_t *vm, unformat_input_t *input)
Definition: cnat_types.c:92
uword unformat_ip_address(unformat_input_t *input, va_list *args)
Definition: ip_types.c:41
A throttle Used in the data plane to decide if a given hash should be throttled, i.e.
Definition: throttle.h:28
vlib_thread_main_t vlib_thread_main
Definition: threads.c:35
f64 scanner_timeout
Definition: cnat_types.h:111
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
Definition: init.h:226
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
clib_bitmap_t * src_ports
Definition: cnat_types.h:117
#define CNAT_DEFAULT_TCP_MAX_AGE
Definition: cnat_types.h:30
u8 * format_ip_address(u8 *s, va_list *args)
Definition: ip_types.c:21
#define CNAT_DEFAULT_SNAT_MEMORY
Definition: cnat_types.h:41
#define CNAT_DEFAULT_SNAT_BUCKETS
Definition: cnat_types.h:37
uword session_hash_memory
Definition: cnat_types.h:86
clib_rwlock_t ts_lock
Definition: cnat_types.h:114
#define CNAT_DEFAULT_SESSION_BUCKETS
Definition: cnat_types.h:35
u32 session_max_age
Definition: cnat_types.h:104
u32 translation_hash_buckets
Definition: cnat_types.h:95
#define CNAT_DEFAULT_TRANSLATION_BUCKETS
Definition: cnat_types.h:36
#define CNAT_DEFAULT_SESSION_MEMORY
Definition: cnat_types.h:39
uword unformat_cnat_ep_tuple(unformat_input_t *input, va_list *args)
Definition: cnat_types.c:49
u64 uword
Definition: types.h:112
cnat_main_t cnat_main
Definition: cnat_types.c:18
uword translation_hash_memory
Definition: cnat_types.h:92
u16 port
Definition: lb_types.api:72
unformat_function_t unformat_memory_size
Definition: format.h:296
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
u32 tcp_max_age
Definition: cnat_types.h:108
ip_address_t ce_ip
Definition: cnat_types.h:54
static clib_error_t * cnat_types_init(vlib_main_t *vm)
Definition: cnat_types.c:75
char * cnat_error_strings[]
Definition: cnat_types.c:23
u32 snat_hash_buckets
Definition: cnat_types.h:101
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
uword snat_hash_memory
Definition: cnat_types.h:98
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
#define CNAT_DEFAULT_SCANNER_TIMEOUT
Definition: cnat_types.h:33