FD.io VPP  v18.07.1-19-g511ce25
Vector Packet Processing
nat.h
Go to the documentation of this file.
1 
2 /*
3  * nat.h - NAT plugin definitions
4  *
5  * Copyright (c) 2016 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 #ifndef __included_nat_h__
19 #define __included_nat_h__
20 
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/ip/icmp46_packet.h>
25 #include <vnet/api_errno.h>
26 #include <vppinfra/bihash_8_8.h>
27 #include <vppinfra/bihash_16_8.h>
28 #include <vppinfra/dlist.h>
29 #include <vppinfra/error.h>
30 #include <vlibapi/api.h>
31 #include <vlib/log.h>
32 
33 
34 #define SNAT_UDP_TIMEOUT 300
35 #define SNAT_UDP_TIMEOUT_MIN 120
36 #define SNAT_TCP_TRANSITORY_TIMEOUT 240
37 #define SNAT_TCP_ESTABLISHED_TIMEOUT 7440
38 #define SNAT_TCP_INCOMING_SYN 6
39 #define SNAT_ICMP_TIMEOUT 60
40 
41 #define NAT_FQ_NELTS 64
42 
43 #define SNAT_FLAG_HAIRPINNING (1 << 0)
44 
45 /* Key */
46 typedef struct {
47  union
48  {
49  struct
50  {
53  u16 protocol:3,
54  fib_index:13;
55  };
57  };
59 
60 typedef struct {
61  union
62  {
63  struct
64  {
67  u32 proto:8,
68  fib_index:24;
71  };
72  u64 as_u64[2];
73  };
75 
76 typedef struct {
77  union
78  {
79  struct
80  {
84  };
86  };
88 
89 typedef struct {
90  union
91  {
92  struct
93  {
96  };
98  };
100 
101 
102 #define foreach_snat_protocol \
103  _(UDP, 0, udp, "udp") \
104  _(TCP, 1, tcp, "tcp") \
105  _(ICMP, 2, icmp, "icmp")
106 
107 typedef enum {
108 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i,
110 #undef _
112 
113 
114 #define foreach_snat_session_state \
115  _(0, UNKNOWN, "unknown") \
116  _(1, UDP_ACTIVE, "udp-active") \
117  _(2, TCP_SYN_SENT, "tcp-syn-sent") \
118  _(3, TCP_ESTABLISHED, "tcp-established") \
119  _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
120  _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
121  _(6, TCP_CLOSING, "tcp-closing") \
122  _(7, TCP_LAST_ACK, "tcp-last-ack") \
123  _(8, TCP_CLOSED, "tcp-closed") \
124  _(9, ICMP_ACTIVE, "icmp-active")
125 
126 typedef enum {
127 #define _(v, N, s) SNAT_SESSION_##N = v,
129 #undef _
131 
132 #define NAT44_SES_I2O_FIN 1
133 #define NAT44_SES_O2I_FIN 2
134 #define NAT44_SES_I2O_FIN_ACK 4
135 #define NAT44_SES_O2I_FIN_ACK 8
136 
137 #define nat44_is_ses_closed(s) s->state == 0xf
138 
139 #define SNAT_SESSION_FLAG_STATIC_MAPPING 1
140 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO 2
141 #define SNAT_SESSION_FLAG_LOAD_BALANCING 4
142 #define SNAT_SESSION_FLAG_TWICE_NAT 8
143 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT 16
144 #define SNAT_SESSION_FLAG_FWD_BYPASS 32
145 
146 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
147 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
148 
149 typedef CLIB_PACKED(struct {
150  snat_session_key_t out2in; /* 0-15 */
151 
152  snat_session_key_t in2out; /* 16-31 */
153 
154  u32 flags; /* 32-35 */
155 
156  /* per-user translations */
157  u32 per_user_index; /* 36-39 */
158 
159  u32 per_user_list_head_index; /* 40-43 */
160 
161  /* Last heard timer */
162  f64 last_heard; /* 44-51 */
163 
164  u64 total_bytes; /* 52-59 */
165 
166  u32 total_pkts; /* 60-63 */
167 
168  /* Outside address */
169  u32 outside_address_index; /* 64-67 */
170 
171  /* External host address and port */
172  ip4_address_t ext_host_addr; /* 68-71 */
173  u16 ext_host_port; /* 72-73 */
174 
175  /* External hos address and port after translation */
176  ip4_address_t ext_host_nat_addr; /* 74-77 */
177  u16 ext_host_nat_port; /* 78-79 */
178 
179  /* TCP session state */
180  u8 state;
181  u32 i2o_fin_seq;
182  u32 o2i_fin_seq;
183 }) snat_session_t;
184 
185 
186 typedef struct {
192 } snat_user_t;
193 
194 typedef struct {
197 #define _(N, i, n, s) \
198  u16 busy_##n##_ports; \
199  u16 * busy_##n##_ports_per_thread; \
200  uword * busy_##n##_port_bitmap;
202 #undef _
203 } snat_address_t;
204 
205 typedef struct {
209 
210 typedef struct {
216 
217 typedef struct {
225  /* vector of sessions */
228 
229 typedef struct {
235 
236 typedef enum {
241 
242 typedef struct {
248  twice_nat_type_t twice_nat;
252  snat_protocol_t proto;
254  u8 *tag;
257 
258 typedef struct {
262 
263 typedef struct {
269  snat_protocol_t proto;
272  int is_add;
273  u8 *tag;
275 
276 typedef struct {
277  /* Main lookup tables */
278  clib_bihash_8_8_t out2in;
279  clib_bihash_8_8_t in2out;
280 
281  /* Endpoint dependent sessions lookup tables */
282  clib_bihash_16_8_t out2in_ed;
283  clib_bihash_16_8_t in2out_ed;
284 
285  /* Find-a-user => src address lookup */
286  clib_bihash_8_8_t user_hash;
287 
288  /* User pool */
290 
291  /* Session pool */
292  snat_session_t * sessions;
293 
294  /* Pool of doubly-linked list elements */
296 
299 
300 struct snat_main_s;
301 
303  vlib_node_runtime_t *node,
304  u32 thread_index,
305  vlib_buffer_t *b0,
306  ip4_header_t *ip0,
307  u8 *p_proto,
308  snat_session_key_t *p_value,
309  u8 *p_dont_translate,
310  void *d,
311  void *e);
312 
313 typedef u32 (snat_get_worker_function_t) (ip4_header_t * ip, u32 rx_fib_index);
314 
315 typedef int nat_alloc_out_addr_and_port_function_t (snat_address_t * addresses,
316  u32 fib_index,
317  u32 thread_index,
318  snat_session_key_t * k,
319  u32 * address_indexp,
321  u32 snat_thread_index);
322 
323 typedef struct snat_main_s {
326 
334 
335  /* Per thread data */
337 
338  /* Find a static mapping by local */
339  clib_bihash_8_8_t static_mapping_by_local;
340 
341  /* Find a static mapping by external */
342  clib_bihash_8_8_t static_mapping_by_external;
343 
344  /* Static mapping pool */
346 
347  /* Interface pool */
350 
351  /* Vector of outside addresses */
352  snat_address_t * addresses;
357 
358  /* vector of outside fibs */
360 
361  /* Vector of twice NAT addresses for extenal hosts */
362  snat_address_t * twice_nat_addresses;
363 
364  /* sw_if_indices whose intfc addresses should be auto-added */
367 
368  /* vector of interface address static mappings to resolve. */
370 
371  /* Randomize port allocation order */
373 
374  /* Worker handoff index */
378 
379  /* in2out and out2in node index */
384 
385  /* Deterministic NAT */
387 
388  /* If forwarding is enabled */
390 
391  /* Config parameters */
407 
408  /* values of various timeouts */
413 
414  /* API message ID base */
416 
417  /* log class */
419 
420  /* convenience */
426 } snat_main_t;
427 
428 extern snat_main_t snat_main;
449 
450 void snat_free_outside_address_and_port (snat_address_t * addresses,
451  u32 thread_index,
452  snat_session_key_t * k);
453 
454 int snat_alloc_outside_address_and_port (snat_address_t * addresses,
455  u32 fib_index,
456  u32 thread_index,
457  snat_session_key_t * k,
458  u32 * address_indexp,
460  u32 snat_thread_index);
461 
463  snat_session_key_t match,
464  snat_session_key_t * mapping,
465  u8 by_external,
466  u8 *is_addr_only,
467  twice_nat_type_t *twice_nat,
468  u8 *lb);
469 
471  u8 p_len,
472  u32 sw_if_index,
473  int is_add);
474 
480 
481 typedef struct {
485 
486 /** \brief Check if SNAT session is created from static mapping.
487  @param s SNAT session
488  @return 1 if SNAT session is created from static mapping otherwise 0
489 */
490 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
491 
492 /** \brief Check if SNAT session for unknown protocol.
493  @param s SNAT session
494  @return 1 if SNAT session for unknown protocol otherwise 0
495 */
496 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
497 
498 /** \brief Check if NAT session is twice NAT.
499  @param s NAT session
500  @return 1 if NAT session is twice NAT
501 */
502 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
503 
504 /** \brief Check if NAT session is load-balancing.
505  @param s NAT session
506  @return 1 if NAT session is load-balancing
507 */
508 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
509 
510 /** \brief Check if NAT session is forwarding bypass.
511  @param s NAT session
512  @return 1 if NAT session is load-balancing
513 */
514 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS)
515 
516 /** \brief Check if NAT session is endpoint dependent.
517  @param s NAT session
518  @return 1 if NAT session is endpoint dependent
519 */
520 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT)
521 
522 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
523 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
524 
525 #define nat_log_err(...) \
526  vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
527 #define nat_log_warn(...) \
528  vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
529 #define nat_log_notice(...) \
530  vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
531 #define nat_log_info(...) \
532  vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
533 #define nat_log_debug(...)\
534  vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
535 
536 /*
537  * Why is this here? Because we don't need to touch this layer to
538  * simply reply to an icmp. We need to change id to a unique
539  * value to NAT an echo request/reply.
540  */
541 
542 typedef struct {
546 
547 typedef struct {
548  u16 src_port, dst_port;
550 
552  u32 thread_index, vlib_buffer_t *b0,
553  ip4_header_t *ip0, u8 *p_proto,
554  snat_session_key_t *p_value,
555  u8 *p_dont_translate, void *d, void *e);
557  u32 thread_index, vlib_buffer_t *b0,
558  ip4_header_t *ip0, u8 *p_proto,
559  snat_session_key_t *p_value,
560  u8 *p_dont_translate, void *d, void *e);
562  u32 thread_index, vlib_buffer_t *b0,
563  ip4_header_t *ip0, u8 *p_proto,
564  snat_session_key_t *p_value,
565  u8 *p_dont_translate, void *d, void *e);
567  u32 thread_index, vlib_buffer_t *b0,
568  ip4_header_t *ip0, u8 *p_proto,
569  snat_session_key_t *p_value,
570  u8 *p_dont_translate, void *d, void *e);
572  u32 thread_index, vlib_buffer_t *b0,
573  ip4_header_t *ip0, u8 *p_proto,
574  snat_session_key_t *p_value,
575  u8 *p_dont_translate, void *d, void *e);
577  u32 thread_index, vlib_buffer_t *b0,
578  ip4_header_t *ip0, u8 *p_proto,
579  snat_session_key_t *p_value,
580  u8 *p_dont_translate, void *d, void *e);
582  u32 thread_index, vlib_buffer_t *b0,
583  ip4_header_t *ip0, u8 *p_proto,
584  snat_session_key_t *p_value,
585  u8 *p_dont_translate, void *d, void *e);
587  u32 thread_index, vlib_buffer_t *b0,
588  ip4_header_t *ip0, u8 *p_proto,
589  snat_session_key_t *p_value,
590  u8 *p_dont_translate, void *d, void *e);
593  u8 twice_nat);
594 int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm,
595  u8 twice_nat);
598  u16 l_port, u16 e_port, u32 vrf_id, int addr_only,
599  u32 sw_if_index, snat_protocol_t proto, int is_add,
600  twice_nat_type_t twice_nat, u8 out2in_only,
601  u8 *tag);
603 int snat_set_workers (uword * bitmap);
604 int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del);
605 int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside,
606  int is_del);
607 int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del,
608  u8 twice_nat);
609 uword unformat_snat_protocol(unformat_input_t * input, va_list * args);
610 u8 * format_snat_protocol(u8 * s, va_list * args);
612  snat_protocol_t proto, u32 vrf_id,
613  nat44_lb_addr_port_t *locals, u8 is_add,
614  twice_nat_type_t twice_nat, u8 out2in_only,
615  u8 *tag);
617  snat_protocol_t proto, u32 vrf_id, int is_in);
619  ip4_address_t *eh_addr, u16 eh_port, u8 proto,
620  u32 vrf_id, int is_in);
621 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
622  u32 thread_index);
624  u32 fib_index, u32 thread_index);
625 snat_session_t * nat_session_alloc_or_recycle (snat_main_t *sm, snat_user_t *u,
626  u32 thread_index);
628  u16 psid_length);
630 
631 #endif /* __included_snat_h__ */
ip4_address_t external_addr
Definition: nat.h:244
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Definition: nat.c:1480
u32 user_memory_size
Definition: nat.h:401
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: nat_api.c:3145
nat_outside_fib_t * outside_fibs
Definition: nat.h:359
vlib_node_registration_t snat_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_src_node)
Definition: in2out.c:116
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Definition: nat.c:187
u32 sessions_per_user_list_head_index
Definition: nat.h:189
u32 vlib_log_class_t
Definition: log.h:21
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat.c:1583
u16 ext_host_port
Definition: nat.h:82
u16 out_port
Definition: nat.h:83
a
Definition: bitmap.h:538
u32 icmp_timeout
Definition: nat.h:412
u32 fq_in2out_output_index
Definition: nat.h:376
u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: in2out.c:4402
u64 as_u64
Definition: bihash_doc.h:63
u32 nsessions
Definition: nat.h:190
#define foreach_snat_session_state
Definition: nat.h:114
unsigned long u64
Definition: types.h:89
ip4_address_t addr
Definition: nat.h:230
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Definition: nat.c:3302
snat_protocol_t proto
Definition: nat.h:252
u16 port_per_thread
Definition: nat.h:332
u32 nstaticsessions
Definition: nat.h:191
u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: out2in.c:286
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
Definition: in2out.c:119
format_function_t format_det_map_ses
Definition: nat.h:479
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
Definition: out2in.c:3293
vlib_node_registration_t nat44_ed_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_src_node)
Definition: in2out.c:124
u32 fib_index
Definition: nat.h:188
format_function_t format_snat_static_mapping
Definition: nat.h:476
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
snat_det_map_t * det_maps
Definition: nat.h:386
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, snat_protocol_t proto, u32 vrf_id, nat44_lb_addr_port_t *locals, u8 is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag)
Definition: nat.c:1221
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
Definition: nat.h:353
u32 num_snat_thread
Definition: nat.h:333
#define foreach_snat_protocol
Definition: nat.h:102
dlist_elt_t * list_pool
Definition: nat.h:295
u8 in_plen
Definition: nat.h:219
vhost_vring_addr_t addr
Definition: vhost_user.h:116
unsigned char u8
Definition: types.h:56
u8 deterministic
Definition: nat.h:394
u32 icmp_match_out2in_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: out2in.c:1822
u16 l_port
Definition: nat.h:69
nat44_lb_addr_port_t * locals
Definition: nat.h:255
int snat_set_workers(uword *bitmap)
Definition: nat.c:1936
u32 user_buckets
Definition: nat.h:400
double f64
Definition: types.h:142
clib_bihash_8_8_t user_hash
Definition: nat.h:286
u32 cached_sw_if_index
Definition: nat.h:482
u16 identifier
Definition: nat.h:543
u32 snat_icmp_match_function_t(struct snat_main_s *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: nat.h:302
void nat_set_alloc_addr_and_port_mape(u16 psid, u16 psid_offset, u16 psid_length)
Definition: nat.c:3456
u32 max_translations_per_user
Definition: nat.h:402
u32( snat_get_worker_function_t)(ip4_header_t *ip, u32 rx_fib_index)
Definition: nat.h:313
clib_bihash_8_8_t in2out
Definition: nat.h:279
u32 in2out_output_node_index
Definition: nat.h:381
u16 r_port
Definition: nat.h:70
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
Definition: out2in.c:1225
ip4_address_t ext_host_addr
Definition: nat.h:81
u32 translation_buckets
Definition: nat.h:397
int nat_alloc_out_addr_and_port_function_t(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u32 *address_indexp, u16 port_per_thread, u32 snat_thread_index)
Definition: nat.h:315
ip4_address_t addr
Definition: nat.h:187
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat, u8 *lb)
Match NAT44 static mapping.
Definition: nat.c:2137
int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Definition: nat.c:657
ip4_main_t * ip4_main
Definition: nat.h:423
vhost_vring_state_t state
Definition: vhost_user.h:115
unsigned int u32
Definition: types.h:88
vlib_node_registration_t snat_in2out_output_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_node)
Definition: in2out.c:112
ip4_address_t local_addr
Definition: nat.h:243
vlib_node_registration_t snat_in2out_output_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node)
Definition: in2out.c:114
uword unformat_snat_protocol(unformat_input_t *input, va_list *args)
Definition: nat.c:2425
snat_protocol_t proto
Definition: nat.h:269
u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: out2in.c:3331
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
Definition: out2in.c:3815
twice_nat_type_t twice_nat
Definition: nat.h:248
u32 max_translations
Definition: nat.h:399
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:366
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
Definition: out2in.c:2768
vlib_node_registration_t snat_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_dst_node)
Definition: in2out.c:115
u32 fib_index
Definition: nat.h:206
clib_bihash_16_8_t out2in_ed
Definition: nat.h:282
snat_det_session_t * sessions
Definition: nat.h:226
vlib_main_t * vlib_main
Definition: nat.h:421
int snat_alloc_outside_address_and_port(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u32 *address_indexp, u16 port_per_thread, u32 snat_thread_index)
Definition: nat.c:2241
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u8 out2in_dpo
Definition: nat.h:395
snat_static_mapping_t * static_mappings
Definition: nat.h:345
u32 inside_fib_index
Definition: nat.h:406
u32 udp_timeout
Definition: nat.h:409
u8 static_mapping_only
Definition: nat.h:392
int nat44_del_ed_session(snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
Definition: nat.c:3412
vlib_node_registration_t nat44_ed_out2in_worker_handoff_node
void nat_set_alloc_addr_and_port_default(void)
Definition: nat.c:3467
void snat_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
Add/del NAT address to FIB.
Definition: nat.c:625
clib_bihash_8_8_t static_mapping_by_external
Definition: nat.h:342
u8 psid_offset
Definition: nat.h:354
int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, u32 vrf_id, int addr_only, u32 sw_if_index, snat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag)
Add static mapping.
Definition: nat.c:798
struct snat_main_s snat_main_t
snat_session_t * nat_session_alloc_or_recycle(snat_main_t *sm, snat_user_t *u, u32 thread_index)
Definition: nat.c:332
api_main_t * api_main
Definition: nat.h:425
u8 out_plen
Definition: nat.h:221
u8 psid_length
Definition: nat.h:355
u32 refcount
Definition: nat.h:207
vnet_main_t * vnet_main
Definition: nat.h:422
u32 inside_vrf_id
Definition: nat.h:405
vlib_node_registration_t nat44_ed_in2out_worker_handoff_node
u32 fq_out2in_index
Definition: nat.h:377
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
u32 flags
Definition: vhost_user.h:110
snat_interface_t * output_feature_interfaces
Definition: nat.h:349
u16 src_port
Definition: nat.h:548
snat_main_t snat_main
Definition: nat.c:36
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
Definition: in2out.c:111
snat_session_state_t
Definition: nat.h:126
snat_user_t * users
Definition: nat.h:289
u32 random_seed
Definition: nat.h:372
clib_bihash_8_8_t out2in
Definition: nat.h:278
vlib_main_t * vm
Definition: buffer.c:294
u32 outside_vrf_id
Definition: nat.h:403
ip4_address_t l_addr
Definition: nat.h:65
u8 static_mapping_connection_tracking
Definition: nat.h:393
snat_get_worker_function_t * worker_in2out_cb
Definition: nat.h:330
format_function_t format_snat_static_map_to_resolve
Definition: nat.h:477
u32 error_node_index
Definition: nat.h:383
u32 sharing_ratio
Definition: nat.h:222
ip4_address_t out_addr
Definition: nat.h:220
u16 psid
Definition: nat.h:356
u32 outside_fib_index
Definition: nat.h:404
typedef CLIB_PACKED(struct{snat_session_key_t out2in;snat_session_key_t in2out;u32 flags;u32 per_user_index;u32 per_user_list_head_index;f64 last_heard;u64 total_bytes;u32 total_pkts;u32 outside_address_index;ip4_address_t ext_host_addr;u16 ext_host_port;ip4_address_t ext_host_nat_addr;u16 ext_host_nat_port;u8 state;u32 i2o_fin_seq;u32 o2i_fin_seq;}) snat_session_t
ip4_address_t addr
Definition: nat.h:51
u32 sw_if_index
Definition: nat.h:259
snat_user_t * nat_user_get_or_create(snat_main_t *sm, ip4_address_t *addr, u32 fib_index, u32 thread_index)
Definition: nat.c:288
void increment_v4_address(ip4_address_t *a)
Definition: nat.c:730
u32 tcp_transitory_timeout
Definition: nat.h:411
ip4_address_t r_addr
Definition: nat.h:66
u32 * auto_add_sw_if_indices
Definition: nat.h:365
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Definition: nat.c:2402
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: in2out.c:500
u32 num_workers
Definition: nat.h:327
Definition: nat.h:238
u32 first_worker_index
Definition: nat.h:328
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, snat_session_key_t *k)
Definition: nat.c:2086
snat_get_worker_function_t * worker_out2in_cb
Definition: nat.h:331
ip4_address_t l_addr
Definition: nat.h:264
snat_icmp_match_function_t * icmp_match_out2in_cb
Definition: nat.h:325
IPv4 main type.
Definition: ip4.h:95
vlib_log_class_t log_class
Definition: nat.h:418
u64 as_u64
Definition: nat.h:97
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
Definition: out2in.c:3629
ip4_address_t addr
Definition: nat.h:94
ip4_address_t in_addr
Definition: nat.h:218
u32 fq_in2out_index
Definition: nat.h:375
u32 out2in_node_index
Definition: nat.h:382
ip4_address_t addr
Definition: nat.h:195
snat_address_t * twice_nat_addresses
Definition: nat.h:362
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
Definition: out2in.c:404
format_function_t format_snat_session
Definition: nat.h:478
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t nat44_ed_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_dst_node)
Definition: in2out.c:123
twice_nat_type_t
Definition: nat.h:236
u16 msg_id_base
Definition: nat.h:415
u16 ports_per_host
Definition: nat.h:223
u32 * workers
Definition: nat.h:329
u64 uword
Definition: types.h:112
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:336
u32 icmp_match_in2out_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: in2out.c:2644
snat_protocol_t
Definition: nat.h:107
snat_det_out_key_t out
Definition: nat.h:212
u32 fib_index
Definition: nat.h:95
snat_address_t * addresses
Definition: nat.h:352
u32 in2out_node_index
Definition: nat.h:380
format_function_t format_snat_user
Definition: nat.h:475
snat_static_map_resolve_t * to_resolve
Definition: nat.h:369
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
Definition: in2out.c:110
vlib_node_registration_t snat_in2out_fast_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)
Definition: in2out.c:109
u8 forwarding_enabled
Definition: nat.h:389
u32 translation_memory_size
Definition: nat.h:398
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat.c:1820
u32 ses_num
Definition: nat.h:224
vlib_node_registration_t nat44_ed_in2out_output_worker_handoff_node
clib_bihash_16_8_t in2out_ed
Definition: nat.h:283
u8 endpoint_dependent
Definition: nat.h:396
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
Definition: in2out.c:107
u8 * format_snat_protocol(u8 *s, va_list *args)
Definition: nat.c:2439
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
Definition: in2out.c:121
ip_lookup_main_t * ip4_lookup_main
Definition: nat.h:424
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
Definition: in2out.c:604
snat_session_t * sessions
Definition: nat.h:292
u32 cached_ip4_address
Definition: nat.h:483
snat_icmp_match_function_t * icmp_match_in2out_cb
Definition: nat.h:324
clib_bihash_8_8_t static_mapping_by_local
Definition: nat.h:339
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, snat_protocol_t proto, u32 vrf_id, int is_in)
Definition: nat.c:3369
u32 fib_index
Definition: nat.h:196
snat_interface_t * interfaces
Definition: nat.h:348
u32 tcp_established_timeout
Definition: nat.h:410