2 * Copyright (c) 2018 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @brief NAT44 endpoint-dependent inside to outside network translation
20 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
22 #include <vnet/pg/pg.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/fib/ip4_fib.h>
26 #include <vnet/udp/udp.h>
27 #include <vppinfra/error.h>
29 #include <nat/nat_ipfix_logging.h>
30 #include <nat/nat_inlines.h>
31 #include <nat/nat44/inlines.h>
32 #include <nat/nat_syslog.h>
33 #include <nat/nat_ha.h>
34 #include <nat/nat44/ed_inlines.h>
35 #include <nat/lib/nat_inlines.h>
37 /* number of attempts to get a port for ED overloading algorithm, if rolling
38 * a dice this many times doesn't produce a free port, it's treated
39 * as if there were no free ports available to conserve resources */
40 #define ED_PORT_ALLOC_ATTEMPTS (10)
42 static char *nat_in2out_ed_error_strings[] = {
43 #define _(sym,string) string,
44 foreach_nat_in2out_ed_error
54 } nat_in2out_ed_trace_t;
57 format_nat_in2out_ed_trace (u8 * s, va_list * args)
59 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
60 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
61 nat_in2out_ed_trace_t *t = va_arg (*args, nat_in2out_ed_trace_t *);
65 t->is_slow_path ? "NAT44_IN2OUT_ED_SLOW_PATH" :
66 "NAT44_IN2OUT_ED_FAST_PATH";
68 s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
69 t->sw_if_index, t->next_index, t->session_index);
74 #ifndef CLIB_MARCH_VARIANT
76 nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void *arg)
78 snat_main_t *sm = &snat_main;
79 nat44_is_idle_session_ctx_t *ctx = arg;
81 u64 sess_timeout_time;
84 ip4_address_t *l_addr, *r_addr;
86 clib_bihash_kv_16_8_t ed_kv;
89 snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
92 ASSERT (ctx->thread_index == ed_value_get_thread_index (kv));
93 s = pool_elt_at_index (tsm->sessions, ed_value_get_session_index (kv));
94 sess_timeout_time = s->last_heard + (f64) nat44_session_get_timeout (sm, s);
95 if (ctx->now >= sess_timeout_time)
97 if (is_fwd_bypass_session (s))
100 l_addr = &s->out2in.addr;
101 r_addr = &s->ext_host_addr;
102 fib_index = s->out2in.fib_index;
103 if (snat_is_unk_proto_session (s))
105 proto = s->in2out.port;
111 proto = nat_proto_to_ip_proto (s->nat_proto);
112 l_port = s->out2in.port;
113 r_port = s->ext_host_port;
115 init_ed_k (&ed_kv, *l_addr, l_port, *r_addr, r_port, fib_index, proto);
116 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &ed_kv, 0))
117 nat_elog_warn ("out2in_ed key del failed");
119 if (snat_is_unk_proto_session (s))
122 snat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
123 s->in2out.addr.as_u32,
124 s->out2in.addr.as_u32,
128 s->in2out.fib_index);
130 nat_syslog_nat44_sdel (s->user_index, s->in2out.fib_index,
131 &s->in2out.addr, s->in2out.port,
132 &s->ext_host_nat_addr, s->ext_host_nat_port,
133 &s->out2in.addr, s->out2in.port,
134 &s->ext_host_addr, s->ext_host_port,
135 s->nat_proto, is_twice_nat_session (s));
137 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
138 s->ext_host_port, s->nat_proto, s->out2in.fib_index,
141 if (is_twice_nat_session (s))
143 for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
145 // TODO FIXME this is obviously broken - which address should be
147 a = sm->twice_nat_addresses + i;
148 if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
150 snat_free_outside_address_and_port (sm->twice_nat_addresses,
152 &s->ext_host_nat_addr,
153 s->ext_host_nat_port,
160 if (snat_is_session_static (s))
163 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
164 &s->out2in.addr, s->out2in.port,
167 nat_ed_session_delete (sm, s, ctx->thread_index, 1);
176 icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
177 ip4_header_t * ip0, icmp46_header_t * icmp0,
178 u32 sw_if_index0, u32 rx_fib_index0,
179 vlib_node_runtime_t * node, u32 next0, f64 now,
180 u32 thread_index, snat_session_t ** p_s0)
182 vlib_main_t *vm = vlib_get_main ();
184 next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
185 next0, thread_index, p_s0, 0);
186 snat_session_t *s0 = *p_s0;
187 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
190 nat44_session_update_counters (s0, now,
191 vlib_buffer_length_in_chain
192 (vm, b0), thread_index);
193 /* Per-user LRU list maintenance */
194 nat44_session_update_lru (sm, s0, thread_index);
200 nat_ed_alloc_addr_and_port (snat_main_t * sm, u32 rx_fib_index,
201 u32 nat_proto, u32 thread_index,
202 ip4_address_t r_addr, u16 r_port, u8 proto,
203 u16 port_per_thread, u32 snat_thread_index,
205 ip4_address_t * outside_addr,
207 clib_bihash_kv_16_8_t * out2in_ed_kv)
210 snat_address_t *a, *ga = 0;
211 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
213 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
215 for (i = 0; i < vec_len (sm->addresses); i++)
217 a = sm->addresses + i;
220 #define _(N, j, n, unused) \
221 case NAT_PROTOCOL_##N: \
222 if (a->fib_index == rx_fib_index) \
224 /* first try port suggested by caller */ \
225 u16 port = clib_net_to_host_u16 (*outside_port); \
226 u16 port_offset = port - port_thread_offset; \
227 if (port <= port_thread_offset || \
228 port > port_thread_offset + port_per_thread) \
230 /* need to pick a different port, suggested port doesn't fit in \
231 * this thread's port range */ \
232 port_offset = snat_random_port (0, port_per_thread - 1); \
233 port = port_thread_offset + port_offset; \
235 u16 attempts = ED_PORT_ALLOC_ATTEMPTS; \
238 init_ed_kv (out2in_ed_kv, a->addr, clib_host_to_net_u16 (port), \
239 r_addr, r_port, s->out2in.fib_index, proto, \
240 thread_index, s - tsm->sessions); \
241 int rv = clib_bihash_add_del_16_8 (&sm->out2in_ed, out2in_ed_kv, \
245 ++a->busy_##n##_port_refcounts[port]; \
246 a->busy_##n##_ports_per_thread[thread_index]++; \
247 a->busy_##n##_ports++; \
248 *outside_addr = a->addr; \
249 *outside_port = clib_host_to_net_u16 (port); \
252 port_offset = snat_random_port (0, port_per_thread - 1); \
253 port = port_thread_offset + port_offset; \
256 while (attempts > 0); \
258 else if (a->fib_index == ~0) \
264 foreach_nat_protocol;
266 nat_elog_info ("unknown protocol");
273 /* fake fib_index to reuse macro */
278 foreach_nat_protocol;
280 nat_elog_info ("unknown protocol");
287 /* Totally out of translations to use... */
288 snat_ipfix_logging_addresses_exhausted (thread_index, 0);
292 static_always_inline u32
293 nat_outside_fib_index_lookup (snat_main_t * sm, ip4_address_t addr)
295 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
296 nat_outside_fib_t *outside_fib;
298 .fp_proto = FIB_PROTOCOL_IP4,
300 .fp_addr = {.ip4.as_u32 = addr.as_u32,}
303 // TODO: multiple vrfs none can resolve addr
305 vec_foreach (outside_fib, sm->outside_fibs)
307 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
308 if (FIB_NODE_INDEX_INVALID != fei)
310 if (fib_entry_get_resolving_interface (fei) != ~0)
312 return outside_fib->fib_index;
321 slow_path_ed (snat_main_t * sm,
323 ip4_address_t l_addr,
324 ip4_address_t r_addr,
329 snat_session_t ** sessionp,
330 vlib_node_runtime_t * node, u32 next, u32 thread_index, f64 now)
332 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
333 clib_bihash_kv_16_8_t out2in_ed_kv;
334 nat44_is_idle_session_ctx_t ctx;
335 ip4_address_t outside_addr;
339 u32 nat_proto = ip_proto_to_nat_proto (proto);
340 snat_session_t *s = NULL;
341 lb_nat_type_t lb = 0;
343 if (PREDICT_TRUE (nat_proto == NAT_PROTOCOL_TCP))
347 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
349 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
350 return NAT_NEXT_DROP;
355 (nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
357 if (!nat_lru_free_one (sm, thread_index, now))
359 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
360 nat_ipfix_logging_max_sessions (thread_index,
361 sm->max_translations_per_thread);
362 nat_elog_notice ("maximum sessions exceeded");
363 return NAT_NEXT_DROP;
367 ip4_address_t sm_addr;
370 /* First try to match static mapping by local address and port */
371 if (snat_static_mapping_match
372 (sm, l_addr, l_port, rx_fib_index, nat_proto, &sm_addr, &sm_port,
373 &sm_fib_index, 0, 0, 0, &lb, 0, &identity_nat))
375 s = nat_ed_session_alloc (sm, thread_index, now, proto);
377 s->in2out.addr = l_addr;
378 s->in2out.port = l_port;
379 s->nat_proto = nat_proto;
380 s->in2out.fib_index = rx_fib_index;
381 s->out2in.fib_index = sm->outside_fib_index;
383 switch (vec_len (sm->outside_fibs))
386 s->out2in.fib_index = sm->outside_fib_index;
389 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
392 s->out2in.fib_index = nat_outside_fib_index_lookup (sm, r_addr);
396 /* Try to create dynamic translation */
397 outside_port = l_port; // suggest using local port to allocation function
398 if (nat_ed_alloc_addr_and_port (sm, rx_fib_index, nat_proto,
399 thread_index, r_addr, r_port, proto,
401 tsm->snat_thread_index, s,
403 &outside_port, &out2in_ed_kv))
405 nat_elog_notice ("addresses exhausted");
406 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
407 nat_ed_session_delete (sm, s, thread_index, 1);
408 return NAT_NEXT_DROP;
410 s->out2in.addr = outside_addr;
411 s->out2in.port = outside_port;
415 if (PREDICT_FALSE (identity_nat))
420 s = nat_ed_session_alloc (sm, thread_index, now, proto);
422 s->out2in.addr = sm_addr;
423 s->out2in.port = sm_port;
424 s->in2out.addr = l_addr;
425 s->in2out.port = l_port;
426 s->nat_proto = nat_proto;
427 s->in2out.fib_index = rx_fib_index;
428 s->out2in.fib_index = sm->outside_fib_index;
429 switch (vec_len (sm->outside_fibs))
432 s->out2in.fib_index = sm->outside_fib_index;
435 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
438 s->out2in.fib_index = nat_outside_fib_index_lookup (sm, r_addr);
442 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
444 init_ed_kv (&out2in_ed_kv, sm_addr, sm_port, r_addr, r_port,
445 s->out2in.fib_index, proto, thread_index,
447 if (clib_bihash_add_or_overwrite_stale_16_8
448 (&sm->out2in_ed, &out2in_ed_kv, nat44_o2i_ed_is_idle_session_cb,
450 nat_elog_notice ("out2in-ed key add failed");
454 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
455 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
456 s->ext_host_addr = r_addr;
457 s->ext_host_port = r_port;
459 clib_bihash_kv_16_8_t in2out_ed_kv;
460 init_ed_kv (&in2out_ed_kv, l_addr, l_port, r_addr, r_port, rx_fib_index,
461 proto, thread_index, s - tsm->sessions);
463 ctx.thread_index = thread_index;
464 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, &in2out_ed_kv,
465 nat44_i2o_ed_is_idle_session_cb,
467 nat_elog_notice ("in2out-ed key add failed");
472 snat_ipfix_logging_nat44_ses_create (thread_index,
473 s->in2out.addr.as_u32,
474 s->out2in.addr.as_u32,
477 s->out2in.port, s->in2out.fib_index);
479 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
480 &s->in2out.addr, s->in2out.port,
481 &s->ext_host_nat_addr, s->ext_host_nat_port,
482 &s->out2in.addr, s->out2in.port,
483 &s->ext_host_addr, s->ext_host_port, s->nat_proto,
486 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
487 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
488 &s->ext_host_nat_addr, s->ext_host_nat_port,
489 s->nat_proto, s->in2out.fib_index, s->flags, thread_index, 0);
494 static_always_inline int
495 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
496 u32 sw_if_index, ip4_header_t * ip, u32 proto,
497 u32 rx_fib_index, u32 thread_index)
499 udp_header_t *udp = ip4_next_header (ip);
500 clib_bihash_kv_16_8_t kv, value;
502 init_ed_k (&kv, ip->dst_address, udp->dst_port, ip->src_address,
503 udp->src_port, sm->outside_fib_index, ip->protocol);
505 /* NAT packet aimed at external address if has active sessions */
506 if (clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
508 /* or is static mappings */
509 ip4_address_t placeholder_addr;
510 u16 placeholder_port;
511 u32 placeholder_fib_index;
512 if (!snat_static_mapping_match
513 (sm, ip->dst_address, udp->dst_port, sm->outside_fib_index, proto,
514 &placeholder_addr, &placeholder_port, &placeholder_fib_index, 1, 0,
521 if (sm->forwarding_enabled)
524 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
528 static_always_inline int
529 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
530 u32 thread_index, f64 now,
531 vlib_main_t * vm, vlib_buffer_t * b)
533 clib_bihash_kv_16_8_t kv, value;
534 snat_session_t *s = 0;
535 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
537 if (!sm->forwarding_enabled)
540 if (ip->protocol == IP_PROTOCOL_ICMP)
542 if (get_icmp_i2o_ed_key (b, ip, 0, ~0, ~0, 0, 0, 0, &kv))
545 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
547 init_ed_k (&kv, ip->src_address, vnet_buffer (b)->ip.reass.l4_src_port,
548 ip->dst_address, vnet_buffer (b)->ip.reass.l4_dst_port, 0,
553 init_ed_k (&kv, ip->src_address, 0, ip->dst_address, 0, 0,
557 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
559 ASSERT (thread_index == ed_value_get_thread_index (&value));
561 pool_elt_at_index (tsm->sessions,
562 ed_value_get_session_index (&value));
563 if (is_fwd_bypass_session (s))
565 if (ip->protocol == IP_PROTOCOL_TCP)
567 if (nat44_set_tcp_session_state_i2o
568 (sm, now, s, b, thread_index))
572 nat44_session_update_counters (s, now,
573 vlib_buffer_length_in_chain (vm, b),
575 /* Per-user LRU list maintenance */
576 nat44_session_update_lru (sm, s, thread_index);
586 static_always_inline int
587 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
588 u16 src_port, u16 dst_port,
589 u32 thread_index, u32 rx_sw_if_index,
592 clib_bihash_kv_16_8_t kv, value;
593 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
596 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
597 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
600 init_ed_k (&kv, ip->src_address, src_port, ip->dst_address, dst_port,
601 tx_fib_index, ip->protocol);
602 if (!clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
604 ASSERT (thread_index == ed_value_get_thread_index (&value));
606 pool_elt_at_index (tsm->sessions,
607 ed_value_get_session_index (&value));
608 if (nat44_is_ses_closed (s))
610 nat_free_session_data (sm, s, thread_index, 0);
611 nat_ed_session_delete (sm, s, thread_index, 1);
614 s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
619 init_ed_k (&kv, ip->dst_address, dst_port, ip->src_address, src_port,
620 rx_fib_index, ip->protocol);
621 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
623 ASSERT (thread_index == ed_value_get_thread_index (&value));
625 pool_elt_at_index (tsm->sessions,
626 ed_value_get_session_index (&value));
627 if (is_fwd_bypass_session (s))
632 pool_foreach (i, sm->output_feature_interfaces,
634 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
644 #ifndef CLIB_MARCH_VARIANT
646 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
647 u32 thread_index, vlib_buffer_t * b,
648 ip4_header_t * ip, ip4_address_t * addr,
649 u16 * port, u32 * fib_index, nat_protocol_t * proto,
650 void *d, void *e, u8 * dont_translate)
654 clib_bihash_kv_16_8_t kv, value;
657 snat_session_t *s = NULL;
658 u16 l_port = 0, r_port = 0; // initialize to workaround gcc warning
659 vlib_main_t *vm = vlib_get_main ();
660 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
663 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
664 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
667 get_icmp_i2o_ed_key (b, ip, rx_fib_index, ~0, ~0, proto, &l_port,
671 b->error = node->errors[err];
672 next = NAT_NEXT_DROP;
676 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
678 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
681 (nat44_ed_not_translate_output_feature
682 (sm, ip, l_port, r_port, thread_index,
683 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
691 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
692 ip, NAT_PROTOCOL_ICMP,
702 (icmp_type_is_error_message
703 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
705 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
706 next = NAT_NEXT_DROP;
711 slow_path_ed (sm, b, ip->src_address, ip->dst_address, l_port, r_port,
712 ip->protocol, rx_fib_index, &s, node, next,
713 thread_index, vlib_time_now (vm));
715 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
727 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
729 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
731 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
732 reass.icmp_type_or_tcp_flags)))
734 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
735 next = NAT_NEXT_DROP;
739 ASSERT (thread_index == ed_value_get_thread_index (&value));
741 pool_elt_at_index (tsm->sessions,
742 ed_value_get_session_index (&value));
747 *addr = s->out2in.addr;
748 *port = s->out2in.port;
749 *fib_index = s->out2in.fib_index;
753 *(snat_session_t **) d = s;
759 static snat_session_t *
760 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
766 vlib_main_t * vm, vlib_node_runtime_t * node)
768 clib_bihash_kv_8_8_t kv, value;
769 clib_bihash_kv_16_8_t s_kv, s_value;
770 snat_static_mapping_t *m;
771 u32 old_addr, new_addr = 0;
773 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
775 u32 outside_fib_index = sm->outside_fib_index;
779 switch (vec_len (sm->outside_fibs))
782 outside_fib_index = sm->outside_fib_index;
785 outside_fib_index = sm->outside_fibs[0].fib_index;
788 outside_fib_index = nat_outside_fib_index_lookup (sm, ip->dst_address);
791 old_addr = ip->src_address.as_u32;
793 init_ed_k (&s_kv, ip->src_address, 0, ip->dst_address, 0, rx_fib_index,
796 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
798 ASSERT (thread_index == ed_value_get_thread_index (&s_value));
800 pool_elt_at_index (tsm->sessions,
801 ed_value_get_session_index (&s_value));
802 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
807 (nat44_ed_maximum_sessions_exceeded
808 (sm, rx_fib_index, thread_index)))
810 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
811 nat_ipfix_logging_max_sessions (thread_index,
812 sm->max_translations_per_thread);
813 nat_elog_notice ("maximum sessions exceeded");
817 init_nat_k (&kv, ip->src_address, 0, rx_fib_index, 0);
819 /* Try to find static mapping first */
820 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
822 m = pool_elt_at_index (sm->static_mappings, value.value);
823 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
830 pool_foreach (s, tsm->sessions, {
831 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
833 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
835 init_ed_k(&s_kv, s->out2in.addr, 0, ip->dst_address, 0, outside_fib_index, ip->protocol);
836 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
844 for (i = 0; i < vec_len (sm->addresses); i++)
846 init_ed_k (&s_kv, sm->addresses[i].addr, 0, ip->dst_address, 0,
847 outside_fib_index, ip->protocol);
848 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
850 new_addr = ip->src_address.as_u32 =
851 sm->addresses[i].addr.as_u32;
859 s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
862 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
863 nat_elog_warn ("create NAT session failed");
867 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
868 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
869 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
870 s->out2in.addr.as_u32 = new_addr;
871 s->out2in.fib_index = outside_fib_index;
872 s->in2out.addr.as_u32 = old_addr;
873 s->in2out.fib_index = rx_fib_index;
874 s->in2out.port = s->out2in.port = ip->protocol;
876 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
878 /* Add to lookup tables */
879 init_ed_kv (&s_kv, s->in2out.addr, 0, ip->dst_address, 0, rx_fib_index,
880 ip->protocol, thread_index, s - tsm->sessions);
881 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
882 nat_elog_notice ("in2out key add failed");
884 init_ed_kv (&s_kv, s->out2in.addr, 0, ip->dst_address, 0,
885 outside_fib_index, ip->protocol, thread_index,
887 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &s_kv, 1))
888 nat_elog_notice ("out2in key add failed");
891 /* Update IP checksum */
893 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
894 ip->checksum = ip_csum_fold (sum);
897 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
899 /* Per-user LRU list maintenance */
900 nat44_session_update_lru (sm, s, thread_index);
903 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
904 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
906 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
907 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
913 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
914 vlib_node_runtime_t * node,
915 vlib_frame_t * frame,
916 int is_output_feature)
918 u32 n_left_from, *from, pkts_processed = 0, stats_node_index;
919 snat_main_t *sm = &snat_main;
920 f64 now = vlib_time_now (vm);
921 u32 thread_index = vm->thread_index;
922 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
923 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
926 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH :
927 NAT_NEXT_IN2OUT_ED_SLOW_PATH;
929 stats_node_index = sm->ed_in2out_node_index;
931 from = vlib_frame_vector_args (frame);
932 n_left_from = frame->n_vectors;
934 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
935 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
936 vlib_get_buffers (vm, from, b, n_left_from);
938 while (n_left_from > 0)
941 u32 sw_if_index0, rx_fib_index0, proto0, new_addr0, old_addr0,
943 u16 old_port0, new_port0;
947 snat_session_t *s0 = 0;
948 clib_bihash_kv_16_8_t kv0, value0;
954 /* Prefetch next iteration. */
955 if (PREDICT_TRUE (n_left_from >= 2))
961 vlib_prefetch_buffer_header (p2, LOAD);
963 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
966 if (is_output_feature)
968 vnet_feature_next (&vnet_buffer2 (b0)->nat.arc_next, b0);
969 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
972 next[0] = vnet_buffer2 (b0)->nat.arc_next;
975 (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) + iph_offset0);
977 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
979 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
981 if (PREDICT_FALSE (ip0->ttl == 1))
983 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
984 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
985 ICMP4_time_exceeded_ttl_exceeded_in_transit,
987 next[0] = NAT_NEXT_ICMP_ERROR;
991 udp0 = ip4_next_header (ip0);
992 tcp0 = (tcp_header_t *) udp0;
993 proto0 = ip_proto_to_nat_proto (ip0->protocol);
995 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1001 if (is_output_feature)
1004 (nat_not_translate_output_feature_fwd
1005 (sm, ip0, thread_index, now, vm, b0)))
1009 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1015 init_ed_k (&kv0, ip0->src_address,
1016 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1017 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1020 // lookup for session
1021 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1023 // session does not exist go slow path
1027 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1029 pool_elt_at_index (tsm->sessions,
1030 ed_value_get_session_index (&value0));
1032 if (s0->tcp_closed_timestamp)
1034 if (now >= s0->tcp_closed_timestamp)
1036 // session is closed, go slow path
1041 // session in transitory timeout, drop
1042 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1043 next[0] = NAT_NEXT_DROP;
1048 // drop if session expired
1049 u64 sess_timeout_time;
1051 s0->last_heard + (f64) nat44_session_get_timeout (sm, s0);
1052 if (now >= sess_timeout_time)
1054 nat_free_session_data (sm, s0, thread_index, 0);
1055 nat_ed_session_delete (sm, s0, thread_index, 1);
1056 // session is closed, go slow path
1061 b0->flags |= VNET_BUFFER_F_IS_NATED;
1063 if (!is_output_feature)
1064 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1066 old_addr0 = ip0->src_address.as_u32;
1067 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1068 sum0 = ip0->checksum;
1070 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1072 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1074 ip_csum_update (sum0, ip0->dst_address.as_u32,
1075 s0->ext_host_addr.as_u32, ip4_header_t,
1077 ip0->checksum = ip_csum_fold (sum0);
1079 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1081 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1083 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1085 new_port0 = udp0->src_port = s0->out2in.port;
1086 sum0 = tcp0->checksum;
1088 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1091 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1093 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1096 ip_csum_update (sum0, ip0->dst_address.as_u32,
1097 s0->ext_host_addr.as_u32, ip4_header_t,
1100 ip_csum_update (sum0,
1101 vnet_buffer (b0)->ip.reass.l4_dst_port,
1102 s0->ext_host_port, ip4_header_t, length);
1103 tcp0->dst_port = s0->ext_host_port;
1104 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1106 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1107 tcp0->checksum = ip_csum_fold (sum0);
1110 if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
1113 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1116 new_port0 = udp0->src_port = s0->out2in.port;
1117 sum0 = udp0->checksum;
1119 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1122 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1123 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1126 ip_csum_update (sum0, ip0->dst_address.as_u32,
1127 s0->ext_host_addr.as_u32, ip4_header_t,
1130 ip_csum_update (sum0, vnet_buffer (b0)->ip.reass.l4_dst_port,
1131 s0->ext_host_port, ip4_header_t, length);
1132 udp0->dst_port = s0->ext_host_port;
1133 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1135 udp0->checksum = ip_csum_fold (sum0);
1140 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1142 new_port0 = udp0->src_port = s0->out2in.port;
1143 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1145 udp0->dst_port = s0->ext_host_port;
1146 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1153 nat44_session_update_counters (s0, now,
1154 vlib_buffer_length_in_chain (vm, b0),
1156 /* Per-user LRU list maintenance */
1157 nat44_session_update_lru (sm, s0, thread_index);
1161 ((node->flags & VLIB_NODE_FLAG_TRACE)
1162 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1164 nat_in2out_ed_trace_t *t =
1165 vlib_add_trace (vm, node, b0, sizeof (*t));
1166 t->sw_if_index = sw_if_index0;
1167 t->next_index = next[0];
1168 t->is_slow_path = 0;
1171 t->session_index = s0 - tsm->sessions;
1173 t->session_index = ~0;
1176 pkts_processed += next[0] == vnet_buffer2 (b0)->nat.arc_next;
1182 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1185 vlib_node_increment_counter (vm, stats_node_index,
1186 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1188 vlib_node_increment_counter (vm, stats_node_index,
1189 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1190 vlib_node_increment_counter (vm, stats_node_index,
1191 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1192 vlib_node_increment_counter (vm, stats_node_index,
1193 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1195 vlib_node_increment_counter (vm, stats_node_index,
1196 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1198 return frame->n_vectors;
1202 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1203 vlib_node_runtime_t * node,
1204 vlib_frame_t * frame,
1205 int is_output_feature)
1207 u32 n_left_from, *from, pkts_processed = 0, stats_node_index;
1208 snat_main_t *sm = &snat_main;
1209 f64 now = vlib_time_now (vm);
1210 u32 thread_index = vm->thread_index;
1211 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1212 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1214 stats_node_index = sm->ed_in2out_slowpath_node_index;
1216 from = vlib_frame_vector_args (frame);
1217 n_left_from = frame->n_vectors;
1219 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1220 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1221 vlib_get_buffers (vm, from, b, n_left_from);
1223 while (n_left_from > 0)
1226 u32 sw_if_index0, rx_fib_index0, proto0, new_addr0, old_addr0,
1228 u16 old_port0, new_port0;
1232 icmp46_header_t *icmp0;
1233 snat_session_t *s0 = 0;
1234 clib_bihash_kv_16_8_t kv0, value0;
1239 if (is_output_feature)
1240 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1242 next[0] = vnet_buffer2 (b0)->nat.arc_next;
1244 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1247 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1249 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
1251 if (PREDICT_FALSE (ip0->ttl == 1))
1253 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1254 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1255 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1257 next[0] = NAT_NEXT_ICMP_ERROR;
1261 udp0 = ip4_next_header (ip0);
1262 tcp0 = (tcp_header_t *) udp0;
1263 icmp0 = (icmp46_header_t *) udp0;
1264 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1266 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1268 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1270 thread_index, now, vm, node);
1272 next[0] = NAT_NEXT_DROP;
1278 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1280 next[0] = icmp_in2out_ed_slow_path
1281 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1282 node, next[0], now, thread_index, &s0);
1287 init_ed_k (&kv0, ip0->src_address,
1288 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1289 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1291 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1293 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1295 pool_elt_at_index (tsm->sessions,
1296 ed_value_get_session_index (&value0));
1298 if (s0->tcp_closed_timestamp && now >= s0->tcp_closed_timestamp)
1300 nat_free_session_data (sm, s0, thread_index, 0);
1301 nat_ed_session_delete (sm, s0, thread_index, 1);
1308 if (is_output_feature)
1311 (nat44_ed_not_translate_output_feature
1312 (sm, ip0, vnet_buffer (b0)->ip.reass.l4_src_port,
1313 vnet_buffer (b0)->ip.reass.l4_dst_port, thread_index,
1314 sw_if_index0, vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1318 * Send DHCP packets to the ipv4 stack, or we won't
1319 * be able to use dhcp client on the outside interface
1322 (proto0 == NAT_PROTOCOL_UDP
1323 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1324 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1325 && ip0->dst_address.as_u32 == 0xffffffff))
1331 (nat44_ed_not_translate
1332 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1338 slow_path_ed (sm, b0, ip0->src_address, ip0->dst_address,
1339 vnet_buffer (b0)->ip.reass.l4_src_port,
1340 vnet_buffer (b0)->ip.reass.l4_dst_port,
1341 ip0->protocol, rx_fib_index0, &s0, node, next[0],
1344 if (PREDICT_FALSE (next[0] == NAT_NEXT_DROP))
1347 if (PREDICT_FALSE (!s0))
1352 b0->flags |= VNET_BUFFER_F_IS_NATED;
1354 if (!is_output_feature)
1355 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1357 old_addr0 = ip0->src_address.as_u32;
1358 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1359 sum0 = ip0->checksum;
1360 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1362 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1363 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1364 s0->ext_host_addr.as_u32, ip4_header_t,
1366 ip0->checksum = ip_csum_fold (sum0);
1368 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1370 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1372 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1374 new_port0 = udp0->src_port = s0->out2in.port;
1375 sum0 = tcp0->checksum;
1377 ip_csum_update (sum0, old_addr0, new_addr0,
1378 ip4_header_t, dst_address);
1380 ip_csum_update (sum0, old_port0, new_port0,
1381 ip4_header_t, length);
1382 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1385 ip_csum_update (sum0, ip0->dst_address.as_u32,
1386 s0->ext_host_addr.as_u32,
1387 ip4_header_t, dst_address);
1389 ip_csum_update (sum0,
1390 vnet_buffer (b0)->ip.reass.l4_dst_port,
1391 s0->ext_host_port, ip4_header_t, length);
1392 tcp0->dst_port = s0->ext_host_port;
1393 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1395 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1396 tcp0->checksum = ip_csum_fold (sum0);
1399 if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
1402 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1405 new_port0 = udp0->src_port = s0->out2in.port;
1406 sum0 = udp0->checksum;
1408 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1411 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1412 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1414 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1415 s0->ext_host_addr.as_u32,
1416 ip4_header_t, dst_address);
1418 ip_csum_update (sum0,
1419 vnet_buffer (b0)->ip.reass.l4_dst_port,
1420 s0->ext_host_port, ip4_header_t, length);
1421 udp0->dst_port = s0->ext_host_port;
1422 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1424 udp0->checksum = ip_csum_fold (sum0);
1429 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1431 new_port0 = udp0->src_port = s0->out2in.port;
1432 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1434 udp0->dst_port = s0->ext_host_port;
1435 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1442 nat44_session_update_counters (s0, now,
1443 vlib_buffer_length_in_chain
1444 (vm, b0), thread_index);
1445 /* Per-user LRU list maintenance */
1446 nat44_session_update_lru (sm, s0, thread_index);
1449 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1450 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1452 nat_in2out_ed_trace_t *t =
1453 vlib_add_trace (vm, node, b0, sizeof (*t));
1454 t->sw_if_index = sw_if_index0;
1455 t->next_index = next[0];
1456 t->is_slow_path = 1;
1459 t->session_index = s0 - tsm->sessions;
1461 t->session_index = ~0;
1464 pkts_processed += next[0] == vnet_buffer2 (b0)->nat.arc_next;
1471 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1474 vlib_node_increment_counter (vm, stats_node_index,
1475 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1477 vlib_node_increment_counter (vm, stats_node_index,
1478 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1479 vlib_node_increment_counter (vm, stats_node_index,
1480 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1481 vlib_node_increment_counter (vm, stats_node_index,
1482 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1484 vlib_node_increment_counter (vm, stats_node_index,
1485 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1487 return frame->n_vectors;
1490 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1491 vlib_node_runtime_t * node,
1492 vlib_frame_t * frame)
1494 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1498 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1499 .name = "nat44-ed-in2out",
1500 .vector_size = sizeof (u32),
1501 .sibling_of = "nat-default",
1502 .format_trace = format_nat_in2out_ed_trace,
1503 .type = VLIB_NODE_TYPE_INTERNAL,
1504 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1505 .error_strings = nat_in2out_ed_error_strings,
1506 .runtime_data_bytes = sizeof (snat_runtime_t),
1510 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1511 vlib_node_runtime_t * node,
1512 vlib_frame_t * frame)
1514 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1518 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1519 .name = "nat44-ed-in2out-output",
1520 .vector_size = sizeof (u32),
1521 .sibling_of = "nat-default",
1522 .format_trace = format_nat_in2out_ed_trace,
1523 .type = VLIB_NODE_TYPE_INTERNAL,
1524 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1525 .error_strings = nat_in2out_ed_error_strings,
1526 .runtime_data_bytes = sizeof (snat_runtime_t),
1530 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1531 vlib_node_runtime_t *
1532 node, vlib_frame_t * frame)
1534 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1538 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1539 .name = "nat44-ed-in2out-slowpath",
1540 .vector_size = sizeof (u32),
1541 .sibling_of = "nat-default",
1542 .format_trace = format_nat_in2out_ed_trace,
1543 .type = VLIB_NODE_TYPE_INTERNAL,
1544 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1545 .error_strings = nat_in2out_ed_error_strings,
1546 .runtime_data_bytes = sizeof (snat_runtime_t),
1550 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1553 vlib_frame_t * frame)
1555 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1559 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1560 .name = "nat44-ed-in2out-output-slowpath",
1561 .vector_size = sizeof (u32),
1562 .sibling_of = "nat-default",
1563 .format_trace = format_nat_in2out_ed_trace,
1564 .type = VLIB_NODE_TYPE_INTERNAL,
1565 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1566 .error_strings = nat_in2out_ed_error_strings,
1567 .runtime_data_bytes = sizeof (snat_runtime_t),
1572 format_nat_pre_trace (u8 * s, va_list * args)
1574 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1575 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1576 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1577 return format (s, "in2out next_index %d arc_next_index %d", t->next_index,
1581 VLIB_NODE_FN (nat_pre_in2out_node)
1582 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1584 return nat_pre_node_fn_inline (vm, node, frame,
1585 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1589 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1590 .name = "nat-pre-in2out",
1591 .vector_size = sizeof (u32),
1592 .sibling_of = "nat-default",
1593 .format_trace = format_nat_pre_trace,
1594 .type = VLIB_NODE_TYPE_INTERNAL,
1600 * fd.io coding-style-patch-verification: ON
1603 * eval: (c-set-style "gnu")