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, 0))
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);
491 per_vrf_sessions_register_session (s, thread_index);
496 static_always_inline int
497 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
498 u32 sw_if_index, ip4_header_t * ip, u32 proto,
499 u32 rx_fib_index, u32 thread_index)
501 udp_header_t *udp = ip4_next_header (ip);
502 clib_bihash_kv_16_8_t kv, value;
504 init_ed_k (&kv, ip->dst_address, udp->dst_port, ip->src_address,
505 udp->src_port, sm->outside_fib_index, ip->protocol);
507 /* NAT packet aimed at external address if has active sessions */
508 if (clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
510 /* or is static mappings */
511 ip4_address_t placeholder_addr;
512 u16 placeholder_port;
513 u32 placeholder_fib_index;
514 if (!snat_static_mapping_match
515 (sm, ip->dst_address, udp->dst_port, sm->outside_fib_index, proto,
516 &placeholder_addr, &placeholder_port, &placeholder_fib_index, 1, 0,
523 if (sm->forwarding_enabled)
526 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
530 static_always_inline int
531 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
532 u32 thread_index, f64 now,
533 vlib_main_t * vm, vlib_buffer_t * b)
535 clib_bihash_kv_16_8_t kv, value;
536 snat_session_t *s = 0;
537 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
539 if (!sm->forwarding_enabled)
542 if (ip->protocol == IP_PROTOCOL_ICMP)
544 if (get_icmp_i2o_ed_key (b, ip, 0, ~0, ~0, 0, 0, 0, &kv))
547 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
549 init_ed_k (&kv, ip->src_address, vnet_buffer (b)->ip.reass.l4_src_port,
550 ip->dst_address, vnet_buffer (b)->ip.reass.l4_dst_port, 0,
555 init_ed_k (&kv, ip->src_address, 0, ip->dst_address, 0, 0,
559 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
561 ASSERT (thread_index == ed_value_get_thread_index (&value));
563 pool_elt_at_index (tsm->sessions,
564 ed_value_get_session_index (&value));
565 if (is_fwd_bypass_session (s))
567 if (ip->protocol == IP_PROTOCOL_TCP)
569 if (nat44_set_tcp_session_state_i2o
570 (sm, now, s, b, thread_index))
574 nat44_session_update_counters (s, now,
575 vlib_buffer_length_in_chain (vm, b),
577 /* Per-user LRU list maintenance */
578 nat44_session_update_lru (sm, s, thread_index);
588 static_always_inline int
589 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
590 u16 src_port, u16 dst_port,
591 u32 thread_index, u32 rx_sw_if_index,
594 clib_bihash_kv_16_8_t kv, value;
595 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
598 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
599 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
602 init_ed_k (&kv, ip->src_address, src_port, ip->dst_address, dst_port,
603 tx_fib_index, ip->protocol);
604 if (!clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
606 ASSERT (thread_index == ed_value_get_thread_index (&value));
608 pool_elt_at_index (tsm->sessions,
609 ed_value_get_session_index (&value));
610 if (nat44_is_ses_closed (s))
612 nat_free_session_data (sm, s, thread_index, 0);
613 nat_ed_session_delete (sm, s, thread_index, 1);
616 s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
621 init_ed_k (&kv, ip->dst_address, dst_port, ip->src_address, src_port,
622 rx_fib_index, ip->protocol);
623 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
625 ASSERT (thread_index == ed_value_get_thread_index (&value));
627 pool_elt_at_index (tsm->sessions,
628 ed_value_get_session_index (&value));
629 if (is_fwd_bypass_session (s))
634 pool_foreach (i, sm->output_feature_interfaces,
636 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
646 #ifndef CLIB_MARCH_VARIANT
648 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
649 u32 thread_index, vlib_buffer_t * b,
650 ip4_header_t * ip, ip4_address_t * addr,
651 u16 * port, u32 * fib_index, nat_protocol_t * proto,
652 void *d, void *e, u8 * dont_translate)
656 clib_bihash_kv_16_8_t kv, value;
659 snat_session_t *s = NULL;
660 u16 l_port = 0, r_port = 0; // initialize to workaround gcc warning
661 vlib_main_t *vm = vlib_get_main ();
662 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
665 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
666 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
669 get_icmp_i2o_ed_key (b, ip, rx_fib_index, ~0, ~0, proto, &l_port,
673 b->error = node->errors[err];
674 next = NAT_NEXT_DROP;
678 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
680 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
683 (nat44_ed_not_translate_output_feature
684 (sm, ip, l_port, r_port, thread_index,
685 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
693 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
694 ip, NAT_PROTOCOL_ICMP,
704 (icmp_type_is_error_message
705 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
707 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
708 next = NAT_NEXT_DROP;
713 slow_path_ed (sm, b, ip->src_address, ip->dst_address, l_port, r_port,
714 ip->protocol, rx_fib_index, &s, node, next,
715 thread_index, vlib_time_now (vm));
717 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
729 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
731 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
733 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
734 reass.icmp_type_or_tcp_flags)))
736 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
737 next = NAT_NEXT_DROP;
741 ASSERT (thread_index == ed_value_get_thread_index (&value));
743 pool_elt_at_index (tsm->sessions,
744 ed_value_get_session_index (&value));
749 *addr = s->out2in.addr;
750 *port = s->out2in.port;
751 *fib_index = s->out2in.fib_index;
755 *(snat_session_t **) d = s;
761 static snat_session_t *
762 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
768 vlib_main_t * vm, vlib_node_runtime_t * node)
770 clib_bihash_kv_8_8_t kv, value;
771 clib_bihash_kv_16_8_t s_kv, s_value;
772 snat_static_mapping_t *m;
773 u32 old_addr, new_addr = 0;
775 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
777 u32 outside_fib_index = sm->outside_fib_index;
781 switch (vec_len (sm->outside_fibs))
784 outside_fib_index = sm->outside_fib_index;
787 outside_fib_index = sm->outside_fibs[0].fib_index;
790 outside_fib_index = nat_outside_fib_index_lookup (sm, ip->dst_address);
793 old_addr = ip->src_address.as_u32;
795 init_ed_k (&s_kv, ip->src_address, 0, ip->dst_address, 0, rx_fib_index,
798 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
800 ASSERT (thread_index == ed_value_get_thread_index (&s_value));
802 pool_elt_at_index (tsm->sessions,
803 ed_value_get_session_index (&s_value));
804 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
809 (nat44_ed_maximum_sessions_exceeded
810 (sm, rx_fib_index, thread_index)))
812 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
813 nat_ipfix_logging_max_sessions (thread_index,
814 sm->max_translations_per_thread);
815 nat_elog_notice ("maximum sessions exceeded");
819 init_nat_k (&kv, ip->src_address, 0, rx_fib_index, 0);
821 /* Try to find static mapping first */
822 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
824 m = pool_elt_at_index (sm->static_mappings, value.value);
825 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
832 pool_foreach (s, tsm->sessions, {
833 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
835 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
837 init_ed_k(&s_kv, s->out2in.addr, 0, ip->dst_address, 0, outside_fib_index, ip->protocol);
838 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
846 for (i = 0; i < vec_len (sm->addresses); i++)
848 init_ed_k (&s_kv, sm->addresses[i].addr, 0, ip->dst_address, 0,
849 outside_fib_index, ip->protocol);
850 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
852 new_addr = ip->src_address.as_u32 =
853 sm->addresses[i].addr.as_u32;
861 s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
864 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
865 nat_elog_warn ("create NAT session failed");
869 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
870 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
871 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
872 s->out2in.addr.as_u32 = new_addr;
873 s->out2in.fib_index = outside_fib_index;
874 s->in2out.addr.as_u32 = old_addr;
875 s->in2out.fib_index = rx_fib_index;
876 s->in2out.port = s->out2in.port = ip->protocol;
878 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
880 /* Add to lookup tables */
881 init_ed_kv (&s_kv, s->in2out.addr, 0, ip->dst_address, 0, rx_fib_index,
882 ip->protocol, thread_index, s - tsm->sessions);
883 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
884 nat_elog_notice ("in2out key add failed");
886 init_ed_kv (&s_kv, s->out2in.addr, 0, ip->dst_address, 0,
887 outside_fib_index, ip->protocol, thread_index,
889 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &s_kv, 1))
890 nat_elog_notice ("out2in key add failed");
892 per_vrf_sessions_register_session (s, thread_index);
895 /* Update IP checksum */
897 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
898 ip->checksum = ip_csum_fold (sum);
901 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
903 /* Per-user LRU list maintenance */
904 nat44_session_update_lru (sm, s, thread_index);
907 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
908 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
910 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
911 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
917 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
918 vlib_node_runtime_t * node,
919 vlib_frame_t * frame,
920 int is_output_feature)
922 u32 n_left_from, *from;
923 snat_main_t *sm = &snat_main;
924 f64 now = vlib_time_now (vm);
925 u32 thread_index = vm->thread_index;
926 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
927 u32 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH
928 : NAT_NEXT_IN2OUT_ED_SLOW_PATH;
930 from = vlib_frame_vector_args (frame);
931 n_left_from = frame->n_vectors;
933 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
934 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
935 vlib_get_buffers (vm, from, b, n_left_from);
937 while (n_left_from > 0)
940 u32 sw_if_index0, rx_fib_index0, proto0, new_addr0, old_addr0,
942 u16 old_port0, new_port0;
946 snat_session_t *s0 = 0;
947 clib_bihash_kv_16_8_t kv0, value0;
953 /* Prefetch next iteration. */
954 if (PREDICT_TRUE (n_left_from >= 2))
960 vlib_prefetch_buffer_header (p2, LOAD);
962 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
965 if (is_output_feature)
967 vnet_feature_next (&vnet_buffer2 (b0)->nat.arc_next, b0);
968 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
971 next[0] = vnet_buffer2 (b0)->nat.arc_next;
974 (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) + iph_offset0);
976 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
978 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
980 if (PREDICT_FALSE (ip0->ttl == 1))
982 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
983 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
984 ICMP4_time_exceeded_ttl_exceeded_in_transit,
986 next[0] = NAT_NEXT_ICMP_ERROR;
990 udp0 = ip4_next_header (ip0);
991 tcp0 = (tcp_header_t *) udp0;
992 proto0 = ip_proto_to_nat_proto (ip0->protocol);
994 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1000 if (is_output_feature)
1003 (nat_not_translate_output_feature_fwd
1004 (sm, ip0, thread_index, now, vm, b0)))
1008 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1014 init_ed_k (&kv0, ip0->src_address,
1015 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1016 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1019 // lookup for session
1020 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1022 // session does not exist go slow path
1026 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1028 pool_elt_at_index (tsm->sessions,
1029 ed_value_get_session_index (&value0));
1031 if (PREDICT_FALSE (per_vrf_sessions_is_expired (s0, thread_index)))
1033 // session is closed, go slow path
1034 nat_free_session_data (sm, s0, thread_index, 0);
1035 nat_ed_session_delete (sm, s0, thread_index, 1);
1036 next[0] = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
1040 if (s0->tcp_closed_timestamp)
1042 if (now >= s0->tcp_closed_timestamp)
1044 // session is closed, go slow path, freed in slow path
1049 // session in transitory timeout, drop
1050 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1051 next[0] = NAT_NEXT_DROP;
1056 // drop if session expired
1057 u64 sess_timeout_time;
1059 s0->last_heard + (f64) nat44_session_get_timeout (sm, s0);
1060 if (now >= sess_timeout_time)
1062 nat_free_session_data (sm, s0, thread_index, 0);
1063 nat_ed_session_delete (sm, s0, thread_index, 1);
1064 // session is closed, go slow path
1069 b0->flags |= VNET_BUFFER_F_IS_NATED;
1071 if (!is_output_feature)
1072 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1074 old_addr0 = ip0->src_address.as_u32;
1075 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1076 sum0 = ip0->checksum;
1078 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1080 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1082 ip_csum_update (sum0, ip0->dst_address.as_u32,
1083 s0->ext_host_addr.as_u32, ip4_header_t,
1085 ip0->checksum = ip_csum_fold (sum0);
1087 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1089 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1091 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1093 new_port0 = udp0->src_port = s0->out2in.port;
1094 sum0 = tcp0->checksum;
1096 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1099 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1101 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1104 ip_csum_update (sum0, ip0->dst_address.as_u32,
1105 s0->ext_host_addr.as_u32, ip4_header_t,
1108 ip_csum_update (sum0,
1109 vnet_buffer (b0)->ip.reass.l4_dst_port,
1110 s0->ext_host_port, ip4_header_t, length);
1111 tcp0->dst_port = s0->ext_host_port;
1112 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1114 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1115 tcp0->checksum = ip_csum_fold (sum0);
1117 vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.tcp,
1118 thread_index, sw_if_index0, 1);
1119 if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
1122 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1125 new_port0 = udp0->src_port = s0->out2in.port;
1126 sum0 = udp0->checksum;
1128 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1131 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1132 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1135 ip_csum_update (sum0, ip0->dst_address.as_u32,
1136 s0->ext_host_addr.as_u32, ip4_header_t,
1139 ip_csum_update (sum0, vnet_buffer (b0)->ip.reass.l4_dst_port,
1140 s0->ext_host_port, ip4_header_t, length);
1141 udp0->dst_port = s0->ext_host_port;
1142 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1144 udp0->checksum = ip_csum_fold (sum0);
1145 vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.udp,
1146 thread_index, sw_if_index0, 1);
1150 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1152 new_port0 = udp0->src_port = s0->out2in.port;
1153 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1155 udp0->dst_port = s0->ext_host_port;
1156 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1158 vlib_increment_simple_counter (&sm->counters.fastpath.
1159 in2out_ed.udp, thread_index,
1165 nat44_session_update_counters (s0, now,
1166 vlib_buffer_length_in_chain (vm, b0),
1168 /* Per-user LRU list maintenance */
1169 nat44_session_update_lru (sm, s0, thread_index);
1173 ((node->flags & VLIB_NODE_FLAG_TRACE)
1174 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1176 nat_in2out_ed_trace_t *t =
1177 vlib_add_trace (vm, node, b0, sizeof (*t));
1178 t->sw_if_index = sw_if_index0;
1179 t->next_index = next[0];
1180 t->is_slow_path = 0;
1183 t->session_index = s0 - tsm->sessions;
1185 t->session_index = ~0;
1188 if (next[0] == NAT_NEXT_DROP)
1190 vlib_increment_simple_counter (&sm->counters.fastpath.
1191 in2out_ed.drops, thread_index,
1199 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1201 return frame->n_vectors;
1205 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1206 vlib_node_runtime_t * node,
1207 vlib_frame_t * frame,
1208 int is_output_feature)
1210 u32 n_left_from, *from;
1211 snat_main_t *sm = &snat_main;
1212 f64 now = vlib_time_now (vm);
1213 u32 thread_index = vm->thread_index;
1214 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_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;
1274 vlib_increment_simple_counter (&sm->counters.slowpath.
1275 in2out_ed.other, thread_index,
1280 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1283 icmp_in2out_ed_slow_path (sm, b0, ip0, icmp0, sw_if_index0,
1284 rx_fib_index0, node, next[0], now,
1286 vlib_increment_simple_counter (&sm->counters.slowpath.
1287 in2out_ed.icmp, thread_index,
1292 init_ed_k (&kv0, ip0->src_address,
1293 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1294 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1296 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1298 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1300 pool_elt_at_index (tsm->sessions,
1301 ed_value_get_session_index (&value0));
1303 if (s0->tcp_closed_timestamp && now >= s0->tcp_closed_timestamp)
1305 nat_free_session_data (sm, s0, thread_index, 0);
1306 nat_ed_session_delete (sm, s0, thread_index, 1);
1313 if (is_output_feature)
1316 (nat44_ed_not_translate_output_feature
1317 (sm, ip0, vnet_buffer (b0)->ip.reass.l4_src_port,
1318 vnet_buffer (b0)->ip.reass.l4_dst_port, thread_index,
1319 sw_if_index0, vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1323 * Send DHCP packets to the ipv4 stack, or we won't
1324 * be able to use dhcp client on the outside interface
1327 (proto0 == NAT_PROTOCOL_UDP
1328 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1329 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1330 && ip0->dst_address.as_u32 == 0xffffffff))
1336 (nat44_ed_not_translate
1337 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1343 slow_path_ed (sm, b0, ip0->src_address, ip0->dst_address,
1344 vnet_buffer (b0)->ip.reass.l4_src_port,
1345 vnet_buffer (b0)->ip.reass.l4_dst_port,
1346 ip0->protocol, rx_fib_index0, &s0, node, next[0],
1349 if (PREDICT_FALSE (next[0] == NAT_NEXT_DROP))
1352 if (PREDICT_FALSE (!s0))
1357 b0->flags |= VNET_BUFFER_F_IS_NATED;
1359 if (!is_output_feature)
1360 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1362 old_addr0 = ip0->src_address.as_u32;
1363 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1364 sum0 = ip0->checksum;
1365 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1367 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1368 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1369 s0->ext_host_addr.as_u32, ip4_header_t,
1371 ip0->checksum = ip_csum_fold (sum0);
1373 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1375 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1377 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1379 new_port0 = udp0->src_port = s0->out2in.port;
1380 sum0 = tcp0->checksum;
1382 ip_csum_update (sum0, old_addr0, new_addr0,
1383 ip4_header_t, dst_address);
1385 ip_csum_update (sum0, old_port0, new_port0,
1386 ip4_header_t, length);
1387 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1390 ip_csum_update (sum0, ip0->dst_address.as_u32,
1391 s0->ext_host_addr.as_u32,
1392 ip4_header_t, dst_address);
1394 ip_csum_update (sum0,
1395 vnet_buffer (b0)->ip.reass.l4_dst_port,
1396 s0->ext_host_port, ip4_header_t, length);
1397 tcp0->dst_port = s0->ext_host_port;
1398 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1400 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1401 tcp0->checksum = ip_csum_fold (sum0);
1403 vlib_increment_simple_counter (&sm->counters.slowpath.in2out_ed.tcp,
1404 thread_index, sw_if_index0, 1);
1405 if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
1408 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1411 new_port0 = udp0->src_port = s0->out2in.port;
1412 sum0 = udp0->checksum;
1414 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1417 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1418 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1420 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1421 s0->ext_host_addr.as_u32,
1422 ip4_header_t, dst_address);
1424 ip_csum_update (sum0,
1425 vnet_buffer (b0)->ip.reass.l4_dst_port,
1426 s0->ext_host_port, ip4_header_t, length);
1427 udp0->dst_port = s0->ext_host_port;
1428 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1430 udp0->checksum = ip_csum_fold (sum0);
1431 vlib_increment_simple_counter (&sm->counters.slowpath.in2out_ed.udp,
1432 thread_index, sw_if_index0, 1);
1436 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1438 new_port0 = udp0->src_port = s0->out2in.port;
1439 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1441 udp0->dst_port = s0->ext_host_port;
1442 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1444 vlib_increment_simple_counter (&sm->counters.slowpath.
1445 in2out_ed.udp, thread_index,
1451 nat44_session_update_counters (s0, now,
1452 vlib_buffer_length_in_chain
1453 (vm, b0), thread_index);
1454 /* Per-user LRU list maintenance */
1455 nat44_session_update_lru (sm, s0, thread_index);
1458 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1459 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1461 nat_in2out_ed_trace_t *t =
1462 vlib_add_trace (vm, node, b0, sizeof (*t));
1463 t->sw_if_index = sw_if_index0;
1464 t->next_index = next[0];
1465 t->is_slow_path = 1;
1468 t->session_index = s0 - tsm->sessions;
1470 t->session_index = ~0;
1473 if (next[0] == NAT_NEXT_DROP)
1475 vlib_increment_simple_counter (&sm->counters.slowpath.
1476 in2out_ed.drops, thread_index,
1485 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1488 return frame->n_vectors;
1491 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1492 vlib_node_runtime_t * node,
1493 vlib_frame_t * frame)
1495 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1499 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1500 .name = "nat44-ed-in2out",
1501 .vector_size = sizeof (u32),
1502 .sibling_of = "nat-default",
1503 .format_trace = format_nat_in2out_ed_trace,
1504 .type = VLIB_NODE_TYPE_INTERNAL,
1505 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1506 .error_strings = nat_in2out_ed_error_strings,
1507 .runtime_data_bytes = sizeof (snat_runtime_t),
1511 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1512 vlib_node_runtime_t * node,
1513 vlib_frame_t * frame)
1515 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1519 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1520 .name = "nat44-ed-in2out-output",
1521 .vector_size = sizeof (u32),
1522 .sibling_of = "nat-default",
1523 .format_trace = format_nat_in2out_ed_trace,
1524 .type = VLIB_NODE_TYPE_INTERNAL,
1525 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1526 .error_strings = nat_in2out_ed_error_strings,
1527 .runtime_data_bytes = sizeof (snat_runtime_t),
1531 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1532 vlib_node_runtime_t *
1533 node, vlib_frame_t * frame)
1535 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1539 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1540 .name = "nat44-ed-in2out-slowpath",
1541 .vector_size = sizeof (u32),
1542 .sibling_of = "nat-default",
1543 .format_trace = format_nat_in2out_ed_trace,
1544 .type = VLIB_NODE_TYPE_INTERNAL,
1545 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1546 .error_strings = nat_in2out_ed_error_strings,
1547 .runtime_data_bytes = sizeof (snat_runtime_t),
1551 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1554 vlib_frame_t * frame)
1556 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1560 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1561 .name = "nat44-ed-in2out-output-slowpath",
1562 .vector_size = sizeof (u32),
1563 .sibling_of = "nat-default",
1564 .format_trace = format_nat_in2out_ed_trace,
1565 .type = VLIB_NODE_TYPE_INTERNAL,
1566 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1567 .error_strings = nat_in2out_ed_error_strings,
1568 .runtime_data_bytes = sizeof (snat_runtime_t),
1573 format_nat_pre_trace (u8 * s, va_list * args)
1575 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1576 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1577 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1578 return format (s, "in2out next_index %d arc_next_index %d", t->next_index,
1582 VLIB_NODE_FN (nat_pre_in2out_node)
1583 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1585 return nat_pre_node_fn_inline (vm, node, frame,
1586 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1590 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1591 .name = "nat-pre-in2out",
1592 .vector_size = sizeof (u32),
1593 .sibling_of = "nat-default",
1594 .format_trace = format_nat_pre_trace,
1595 .type = VLIB_NODE_TYPE_INTERNAL,
1601 * fd.io coding-style-patch-verification: ON
1604 * eval: (c-set-style "gnu")