FD.io VPP  v18.04-17-g3a0d853
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 
32 
33 #define SNAT_UDP_TIMEOUT 300
34 #define SNAT_UDP_TIMEOUT_MIN 120
35 #define SNAT_TCP_TRANSITORY_TIMEOUT 240
36 #define SNAT_TCP_ESTABLISHED_TIMEOUT 7440
37 #define SNAT_TCP_INCOMING_SYN 6
38 #define SNAT_ICMP_TIMEOUT 60
39 
40 #define SNAT_FLAG_HAIRPINNING (1 << 0)
41 
42 /* Key */
43 typedef struct {
44  union
45  {
46  struct
47  {
50  u16 protocol:3,
51  fib_index:13;
52  };
54  };
56 
57 typedef struct {
58  union
59  {
60  struct
61  {
64  u32 proto:8,
65  fib_index:24;
68  };
69  u64 as_u64[2];
70  };
72 
73 typedef struct {
74  union
75  {
76  struct
77  {
81  };
83  };
85 
86 typedef struct {
87  union
88  {
89  struct
90  {
93  };
95  };
97 
98 
99 #define foreach_snat_protocol \
100  _(UDP, 0, udp, "udp") \
101  _(TCP, 1, tcp, "tcp") \
102  _(ICMP, 2, icmp, "icmp")
103 
104 typedef enum {
105 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i,
107 #undef _
109 
110 
111 #define foreach_snat_session_state \
112  _(0, UNKNOWN, "unknown") \
113  _(1, UDP_ACTIVE, "udp-active") \
114  _(2, TCP_SYN_SENT, "tcp-syn-sent") \
115  _(3, TCP_ESTABLISHED, "tcp-established") \
116  _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
117  _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
118  _(6, TCP_LAST_ACK, "tcp-last-ack") \
119  _(7, ICMP_ACTIVE, "icmp-active")
120 
121 typedef enum {
122 #define _(v, N, s) SNAT_SESSION_##N = v,
124 #undef _
126 
127 
128 #define SNAT_SESSION_FLAG_STATIC_MAPPING 1
129 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO 2
130 #define SNAT_SESSION_FLAG_LOAD_BALANCING 4
131 #define SNAT_SESSION_FLAG_TWICE_NAT 8
132 
133 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
134 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
135 
136 typedef CLIB_PACKED(struct {
137  snat_session_key_t out2in; /* 0-15 */
138 
139  snat_session_key_t in2out; /* 16-31 */
140 
141  u32 flags; /* 32-35 */
142 
143  /* per-user translations */
144  u32 per_user_index; /* 36-39 */
145 
146  u32 per_user_list_head_index; /* 40-43 */
147 
148  /* Last heard timer */
149  f64 last_heard; /* 44-51 */
150 
151  u64 total_bytes; /* 52-59 */
152 
153  u32 total_pkts; /* 60-63 */
154 
155  /* Outside address */
156  u32 outside_address_index; /* 64-67 */
157 
158  /* External host address and port */
159  ip4_address_t ext_host_addr; /* 68-71 */
160  u16 ext_host_port; /* 72-73 */
161 
162  /* External hos address and port after translation */
163  ip4_address_t ext_host_nat_addr; /* 74-77 */
164  u16 ext_host_nat_port; /* 78-79 */
165 }) snat_session_t;
166 
167 
168 typedef struct {
174 } snat_user_t;
175 
176 typedef struct {
179 #define _(N, i, n, s) \
180  u16 busy_##n##_ports; \
181  u16 * busy_##n##_ports_per_thread; \
182  uword * busy_##n##_port_bitmap;
184 #undef _
185 } snat_address_t;
186 
187 typedef struct {
193 
194 typedef struct {
202  /* vector of sessions */
205 
206 typedef struct {
212 
213 typedef struct {
223  snat_protocol_t proto;
225  u8 *tag;
228 
229 typedef struct {
233 
234 typedef struct {
240  snat_protocol_t proto;
243  int is_add;
244  u8 *tag;
246 
247 typedef struct {
248  /* Main lookup tables */
249  clib_bihash_8_8_t out2in;
250  clib_bihash_8_8_t in2out;
251 
252  /* Find-a-user => src address lookup */
253  clib_bihash_8_8_t user_hash;
254 
255  /* User pool */
257 
258  /* Session pool */
259  snat_session_t * sessions;
260 
261  /* Pool of doubly-linked list elements */
263 
266 
267 struct snat_main_s;
268 
270  vlib_node_runtime_t *node,
271  u32 thread_index,
272  vlib_buffer_t *b0,
273  ip4_header_t *ip0,
274  u8 *p_proto,
275  snat_session_key_t *p_value,
276  u8 *p_dont_translate,
277  void *d,
278  void *e);
279 
280 typedef u32 (snat_get_worker_function_t) (ip4_header_t * ip, u32 rx_fib_index);
281 
282 typedef int nat_alloc_out_addr_and_port_function_t (snat_address_t * addresses,
283  u32 fib_index,
284  u32 thread_index,
285  snat_session_key_t * k,
286  u32 * address_indexp,
288  u32 snat_thread_index);
289 
290 typedef struct snat_main_s {
291  /* Endpoint address dependent sessions lookup tables */
292  clib_bihash_16_8_t out2in_ed;
293  clib_bihash_16_8_t in2out_ed;
294 
297 
306 
307  /* Per thread data */
309 
310  /* Find a static mapping by local */
311  clib_bihash_8_8_t static_mapping_by_local;
312 
313  /* Find a static mapping by external */
314  clib_bihash_8_8_t static_mapping_by_external;
315 
316  /* Static mapping pool */
318 
319  /* Interface pool */
322 
323  /* Vector of outside addresses */
324  snat_address_t * addresses;
329 
330  /* Vector of twice NAT addresses for extenal hosts */
331  snat_address_t * twice_nat_addresses;
332 
333  /* sw_if_indices whose intfc addresses should be auto-added */
336 
337  /* vector of interface address static mappings to resolve. */
339 
340  /* Randomize port allocation order */
342 
343  /* Worker handoff index */
347 
348  /* in2out and out2in node index */
352 
353  /* Deterministic NAT */
355 
356  /* If forwarding is enabled */
358 
359  /* Config parameters */
374 
375  /* values of various timeouts */
380 
381  /* API message ID base */
383 
384  /* convenience */
390 } snat_main_t;
391 
392 extern snat_main_t snat_main;
405 
406 void snat_free_outside_address_and_port (snat_address_t * addresses,
407  u32 thread_index,
408  snat_session_key_t * k,
409  u32 address_index);
410 
411 int snat_alloc_outside_address_and_port (snat_address_t * addresses,
412  u32 fib_index,
413  u32 thread_index,
414  snat_session_key_t * k,
415  u32 * address_indexp,
417  u32 snat_thread_index);
418 
420  snat_session_key_t match,
421  snat_session_key_t * mapping,
422  u8 by_external,
423  u8 *is_addr_only,
424  u8 *twice_nat);
425 
427  u8 p_len,
428  u32 sw_if_index,
429  int is_add);
430 
435 
436 typedef struct {
440 
441 /** \brief Check if SNAT session is created from static mapping.
442  @param s SNAT session
443  @return 1 if SNAT session is created from static mapping otherwise 0
444 */
445 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
446 
447 /** \brief Check if SNAT session for unknown protocol.
448  @param s SNAT session
449  @return 1 if SNAT session for unknown protocol otherwise 0
450 */
451 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
452 
453 /** \brief Check if NAT session is twice NAT.
454  @param s NAT session
455  @return 1 if NAT session is twice NAT
456 */
457 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
458 
459 /** \brief Check if NAT session is load-balancing.
460  @param s NAT session
461  @return 1 if NAT session is load-balancing
462 */
463 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
464 
465 /** \brief Check if NAT session is endpoint dependent.
466  @param s NAT session
467  @return 1 if NAT session is endpoint dependent
468 */
469 #define is_ed_session(s) (snat_is_unk_proto_session (s) || is_twice_nat_session (s) || is_lb_session (s))
470 
471 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
472 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
473 
474 /*
475  * Why is this here? Because we don't need to touch this layer to
476  * simply reply to an icmp. We need to change id to a unique
477  * value to NAT an echo request/reply.
478  */
479 
480 typedef struct {
484 
487 {
488  u32 snat_proto = ~0;
489 
490  snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto;
491  snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto;
492  snat_proto = (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto;
493  snat_proto = (ip_proto == IP_PROTOCOL_ICMP6) ? SNAT_PROTOCOL_ICMP : snat_proto;
494 
495  return snat_proto;
496 }
497 
499 snat_proto_to_ip_proto (snat_protocol_t snat_proto)
500 {
501  u8 ip_proto = ~0;
502 
503  ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
504  ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
505  ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
506 
507  return ip_proto;
508 }
509 
510 typedef struct {
511  u16 src_port, dst_port;
513 
515  u32 thread_index, vlib_buffer_t *b0,
516  ip4_header_t *ip0, u8 *p_proto,
517  snat_session_key_t *p_value,
518  u8 *p_dont_translate, void *d, void *e);
520  u32 thread_index, vlib_buffer_t *b0,
521  ip4_header_t *ip0, u8 *p_proto,
522  snat_session_key_t *p_value,
523  u8 *p_dont_translate, void *d, void *e);
525  u32 thread_index, vlib_buffer_t *b0,
526  ip4_header_t *ip0, u8 *p_proto,
527  snat_session_key_t *p_value,
528  u8 *p_dont_translate, void *d, void *e);
530  u32 thread_index, vlib_buffer_t *b0,
531  ip4_header_t *ip0, u8 *p_proto,
532  snat_session_key_t *p_value,
533  u8 *p_dont_translate, void *d, void *e);
535  u32 thread_index, vlib_buffer_t *b0,
536  ip4_header_t *ip0, u8 *p_proto,
537  snat_session_key_t *p_value,
538  u8 *p_dont_translate, void *d, void *e);
540  u32 thread_index, vlib_buffer_t *b0,
541  ip4_header_t *ip0, u8 *p_proto,
542  snat_session_key_t *p_value,
543  u8 *p_dont_translate, void *d, void *e);
546  u8 twice_nat);
547 int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm,
548  u8 twice_nat);
551  u16 l_port, u16 e_port, u32 vrf_id, int addr_only,
552  u32 sw_if_index, snat_protocol_t proto, int is_add,
553  u8 twice_nat, u8 out2in_only, u8 *tag);
555 int snat_set_workers (uword * bitmap);
556 int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del);
557 int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside,
558  int is_del);
559 int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del,
560  u8 twice_nat);
561 uword unformat_snat_protocol(unformat_input_t * input, va_list * args);
562 u8 * format_snat_protocol(u8 * s, va_list * args);
564  snat_protocol_t proto, u32 vrf_id,
565  nat44_lb_addr_port_t *locals, u8 is_add,
566  u8 twice_nat, u8 out2in_only, u8 *tag);
568  snat_protocol_t proto, u32 vrf_id, int is_in);
569 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
570  u32 thread_index);
572  u32 fib_index, u32 thread_index);
573 snat_session_t * nat_session_alloc_or_recycle (snat_main_t *sm, snat_user_t *u,
574  u32 thread_index);
576  u16 psid_length);
578 
580 icmp_is_error_message (icmp46_header_t * icmp)
581 {
582  switch(icmp->type)
583  {
584  case ICMP4_destination_unreachable:
585  case ICMP4_time_exceeded:
586  case ICMP4_parameter_problem:
587  case ICMP4_source_quench:
588  case ICMP4_redirect:
589  case ICMP4_alternate_host_address:
590  return 1;
591  }
592  return 0;
593 }
594 
597  u32 ip4_addr)
598 {
600  ip4_address_t * first_int_addr;
601 
602  if (PREDICT_FALSE(rt->cached_sw_if_index != sw_if_index0))
603  {
604  first_int_addr =
605  ip4_interface_first_address (sm->ip4_main, sw_if_index0,
606  0 /* just want the address */);
607  rt->cached_sw_if_index = sw_if_index0;
608  if (first_int_addr)
609  rt->cached_ip4_address = first_int_addr->as_u32;
610  else
611  rt->cached_ip4_address = 0;
612  }
613 
614  if (PREDICT_FALSE(ip4_addr == rt->cached_ip4_address))
615  return 1;
616  else
617  return 0;
618 }
619 
622 {
623  if (pool_elts (sm->per_thread_data[thread_index].sessions) >= sm->max_translations)
624  return 1;
625 
626  return 0;
627 }
628 
631  vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
632 {
633  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
634 
635  from = bi_vector;
636  n_left_from = vec_len(bi_vector);
637  next_index = node->cached_next_index;
638  while (n_left_from > 0) {
639  vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
640  while (n_left_from > 0 && n_left_to_next > 0) {
641  u32 bi0 = to_next[0] = from[0];
642  from += 1;
643  n_left_from -= 1;
644  to_next += 1;
645  n_left_to_next -= 1;
646  vlib_buffer_t *p0 = vlib_get_buffer(vm, bi0);
647  p0->error = *error;
648  vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
649  n_left_to_next, bi0, next);
650  }
651  vlib_put_next_frame(vm, node, next_index, n_left_to_next);
652  }
653 }
654 
655 always_inline void
657 {
659  {
660  if (is_static)
661  u->nstaticsessions++;
662  else
663  u->nsessions++;
664  }
665 }
666 
667 #endif /* __included_snat_h__ */
ip4_address_t external_addr
Definition: nat.h:215
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Definition: nat.c:1414
u32 user_memory_size
Definition: nat.h:368
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: nat_api.c:2889
vlib_node_registration_t snat_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_src_node)
Definition: in2out.c:115
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Definition: nat.c:144
u32 sessions_per_user_list_head_index
Definition: nat.h:171
clib_bihash_16_8_t out2in_ed
Definition: nat.h:292
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat.c:1527
u16 ext_host_port
Definition: nat.h:79
u16 out_port
Definition: nat.h:80
a
Definition: bitmap.h:516
u32 icmp_timeout
Definition: nat.h:379
u8 runtime_data[0]
Function dependent node-runtime data.
Definition: node.h:464
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, u8 *twice_nat)
Match NAT44 static mapping.
Definition: nat.c:1969
u32 fq_in2out_output_index
Definition: nat.h:345
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:3372
u64 as_u64
Definition: bihash_doc.h:63
u32 nsessions
Definition: nat.h:172
#define foreach_snat_session_state
Definition: nat.h:111
ip4_address_t addr
Definition: nat.h:207
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Definition: nat.c:2947
snat_protocol_t proto
Definition: nat.h:223
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip4_forward.c:319
u16 port_per_thread
Definition: nat.h:304
u32 nstaticsessions
Definition: nat.h:173
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:386
format_function_t format_det_map_ses
Definition: nat.h:434
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
Definition: out2in.c:2475
u32 fib_index
Definition: nat.h:170
clib_bihash_16_8_t in2out_ed
Definition: nat.h:293
format_function_t format_snat_static_mapping
Definition: nat.h:432
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
snat_det_map_t * det_maps
Definition: nat.h:354
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
Definition: nat.h:325
u32 num_snat_thread
Definition: nat.h:305
#define foreach_snat_protocol
Definition: nat.h:99
dlist_elt_t * list_pool
Definition: nat.h:262
u8 in_plen
Definition: nat.h:196
u8 deterministic
Definition: nat.h:362
u16 l_port
Definition: nat.h:66
nat44_lb_addr_port_t * locals
Definition: nat.h:226
int snat_set_workers(uword *bitmap)
Definition: nat.c:1778
u32 user_buckets
Definition: nat.h:367
clib_bihash_8_8_t user_hash
Definition: nat.h:253
u32 cached_sw_if_index
Definition: nat.h:437
u16 identifier
Definition: nat.h:481
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:269
void nat_set_alloc_addr_and_port_mape(u16 psid, u16 psid_offset, u16 psid_length)
Definition: nat.c:3065
u32 max_translations_per_user
Definition: nat.h:369
u32( snat_get_worker_function_t)(ip4_header_t *ip, u32 rx_fib_index)
Definition: nat.h:280
clib_bihash_8_8_t in2out
Definition: nat.h:250
static void user_session_increment(snat_main_t *sm, snat_user_t *u, u8 is_static)
Definition: nat.h:656
u32 in2out_output_node_index
Definition: nat.h:350
#define static_always_inline
Definition: clib.h:93
u16 r_port
Definition: nat.h:67
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
Definition: out2in.c:1688
ip4_address_t ext_host_addr
Definition: nat.h:78
#define always_inline
Definition: clib.h:92
u32 translation_buckets
Definition: nat.h:364
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:282
ip4_address_t addr
Definition: nat.h:169
ip4_main_t * ip4_main
Definition: nat.h:387
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, u8 twice_nat, u8 out2in_only, u8 *tag)
Add static mapping.
Definition: nat.c:663
unsigned long u64
Definition: types.h:89
vlib_node_registration_t snat_in2out_output_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_node)
Definition: in2out.c:111
ip4_address_t local_addr
Definition: nat.h:214
vlib_node_registration_t snat_in2out_output_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node)
Definition: in2out.c:113
uword unformat_snat_protocol(unformat_input_t *input, va_list *args)
Definition: nat.c:2241
snat_protocol_t proto
Definition: nat.h:240
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:2514
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
Definition: out2in.c:2969
u32 max_translations
Definition: nat.h:366
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:335
vlib_node_registration_t snat_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_dst_node)
Definition: in2out.c:114
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, snat_session_key_t *k, u32 address_index)
Definition: nat.c:1925
snat_det_session_t * sessions
Definition: nat.h:203
vlib_main_t * vlib_main
Definition: nat.h:385
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:2057
struct _unformat_input_t unformat_input_t
u8 out2in_dpo
Definition: nat.h:363
snat_static_mapping_t * static_mappings
Definition: nat.h:317
u32 inside_fib_index
Definition: nat.h:373
u32 udp_timeout
Definition: nat.h:376
u8 static_mapping_only
Definition: nat.h:360
void nat_set_alloc_addr_and_port_default(void)
Definition: nat.c:3076
#define PREDICT_FALSE(x)
Definition: clib.h:105
u32 vlib_error_t
Definition: error.h:44
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:510
clib_bihash_8_8_t static_mapping_by_external
Definition: nat.h:314
u8 psid_offset
Definition: nat.h:326
struct snat_main_s snat_main_t
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
snat_session_t * nat_session_alloc_or_recycle(snat_main_t *sm, snat_user_t *u, u32 thread_index)
Definition: nat.c:285
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:364
api_main_t * api_main
Definition: nat.h:389
u8 out_plen
Definition: nat.h:198
u8 psid_length
Definition: nat.h:327
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;}) snat_session_t
vnet_main_t * vnet_main
Definition: nat.h:386
u32 inside_vrf_id
Definition: nat.h:372
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:130
u32 fq_out2in_index
Definition: nat.h:346
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:199
snat_interface_t * output_feature_interfaces
Definition: nat.h:321
u16 src_port
Definition: nat.h:511
snat_main_t snat_main
Definition: nat.c:35
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
Definition: in2out.c:110
snat_session_state_t
Definition: nat.h:121
snat_user_t * users
Definition: nat.h:256
u32 random_seed
Definition: nat.h:341
clib_bihash_8_8_t out2in
Definition: nat.h:249
vlib_main_t * vm
Definition: buffer.c:294
u32 outside_vrf_id
Definition: nat.h:370
ip4_address_t l_addr
Definition: nat.h:62
u8 static_mapping_connection_tracking
Definition: nat.h:361
snat_get_worker_function_t * worker_in2out_cb
Definition: nat.h:302
format_function_t format_snat_static_map_to_resolve
Definition: nat.h:433
u32 sharing_ratio
Definition: nat.h:199
ip4_address_t out_addr
Definition: nat.h:197
u16 psid
Definition: nat.h:328
u32 outside_fib_index
Definition: nat.h:371
ip4_address_t addr
Definition: nat.h:48
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:454
u32 sw_if_index
Definition: nat.h:230
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:241
void increment_v4_address(ip4_address_t *a)
Definition: nat.c:610
u32 tcp_transitory_timeout
Definition: nat.h:378
ip4_address_t r_addr
Definition: nat.h:63
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, u8 twice_nat, u8 out2in_only, u8 *tag)
Definition: nat.c:1141
u32 * auto_add_sw_if_indices
Definition: nat.h:334
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Definition: nat.c:2218
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:547
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:456
u32 num_workers
Definition: nat.h:298
unsigned int u32
Definition: types.h:88
u32 first_worker_index
Definition: nat.h:299
snat_get_worker_function_t * worker_out2in_cb
Definition: nat.h:303
ip4_address_t l_addr
Definition: nat.h:235
static u32 ip_proto_to_snat_proto(u8 ip_proto)
Definition: nat.h:486
snat_icmp_match_function_t * icmp_match_out2in_cb
Definition: nat.h:296
IPv4 main type.
Definition: ip4.h:95
u64 as_u64
Definition: nat.h:94
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
Definition: out2in.c:2786
ip4_address_t addr
Definition: nat.h:91
ip4_address_t in_addr
Definition: nat.h:195
u32 fq_in2out_index
Definition: nat.h:344
u32 out2in_node_index
Definition: nat.h:351
ip4_address_t addr
Definition: nat.h:177
snat_address_t * twice_nat_addresses
Definition: nat.h:331
u64 uword
Definition: types.h:112
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:536
struct _vlib_node_registration vlib_node_registration_t
void snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Definition: nat.c:542
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
u16 msg_id_base
Definition: nat.h:382
u16 ports_per_host
Definition: nat.h:200
static_always_inline u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
Definition: nat.h:596
u32 * workers
Definition: nat.h:301
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:308
snat_protocol_t
Definition: nat.h:104
snat_det_out_key_t out
Definition: nat.h:189
u32 fib_index
Definition: nat.h:92
snat_address_t * addresses
Definition: nat.h:324
u32 in2out_node_index
Definition: nat.h:349
format_function_t format_snat_user
Definition: nat.h:431
snat_static_map_resolve_t * to_resolve
Definition: nat.h:338
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
Definition: in2out.c:109
vlib_node_registration_t snat_in2out_fast_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)
Definition: in2out.c:108
u8 forwarding_enabled
Definition: nat.h:357
u32 translation_memory_size
Definition: nat.h:365
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat.c:1683
u32 ses_num
Definition: nat.h:201
u32 next_worker
Definition: nat.h:300
static_always_inline void nat_send_all_to_node(vlib_main_t *vm, u32 *bi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
Definition: nat.h:630
vhost_vring_addr_t addr
Definition: vhost-user.h:83
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
Definition: in2out.c:106
u8 * format_snat_protocol(u8 *s, va_list *args)
Definition: nat.c:2255
u32 flags
Definition: vhost-user.h:77
ip_lookup_main_t * ip4_lookup_main
Definition: nat.h:388
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:677
static u8 maximum_sessions_exceeded(snat_main_t *sm, u32 thread_index)
Definition: nat.h:621
snat_session_t * sessions
Definition: nat.h:259
u32 cached_ip4_address
Definition: nat.h:438
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
snat_icmp_match_function_t * icmp_match_in2out_cb
Definition: nat.h:295
clib_bihash_8_8_t static_mapping_by_local
Definition: nat.h:311
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:3014
u32 fib_index
Definition: nat.h:178
snat_interface_t * interfaces
Definition: nat.h:320
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
Definition: nat.h:580
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
Definition: nat.h:499
u32 tcp_established_timeout
Definition: nat.h:377
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128