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 static char *nat_in2out_ed_error_strings[] = {
38 #define _(sym,string) string,
39 foreach_nat_in2out_ed_error
49 } nat_in2out_ed_trace_t;
52 format_nat_in2out_ed_trace (u8 * s, va_list * args)
54 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
55 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
56 nat_in2out_ed_trace_t *t = va_arg (*args, nat_in2out_ed_trace_t *);
60 t->is_slow_path ? "NAT44_IN2OUT_ED_SLOW_PATH" :
61 "NAT44_IN2OUT_ED_FAST_PATH";
63 s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
64 t->sw_if_index, t->next_index, t->session_index);
69 #ifndef CLIB_MARCH_VARIANT
71 nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void *arg)
73 snat_main_t *sm = &snat_main;
74 nat44_is_idle_session_ctx_t *ctx = arg;
76 u64 sess_timeout_time;
79 ip4_address_t *l_addr, *r_addr;
81 clib_bihash_kv_16_8_t ed_kv;
84 snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
87 ASSERT (ctx->thread_index == ed_value_get_thread_index (kv));
88 s = pool_elt_at_index (tsm->sessions, ed_value_get_session_index (kv));
89 sess_timeout_time = s->last_heard + (f64) nat44_session_get_timeout (sm, s);
90 if (ctx->now >= sess_timeout_time)
92 if (is_fwd_bypass_session (s))
95 l_addr = &s->out2in.addr;
96 r_addr = &s->ext_host_addr;
97 fib_index = s->out2in.fib_index;
98 if (snat_is_unk_proto_session (s))
100 proto = s->in2out.port;
106 proto = nat_proto_to_ip_proto (s->nat_proto);
107 l_port = s->out2in.port;
108 r_port = s->ext_host_port;
110 init_ed_k (&ed_kv, *l_addr, l_port, *r_addr, r_port, fib_index, proto);
111 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &ed_kv, 0))
112 nat_elog_warn ("out2in_ed key del failed");
114 if (snat_is_unk_proto_session (s))
117 snat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
118 s->in2out.addr.as_u32,
119 s->out2in.addr.as_u32,
123 s->in2out.fib_index);
125 nat_syslog_nat44_sdel (s->user_index, s->in2out.fib_index,
126 &s->in2out.addr, s->in2out.port,
127 &s->ext_host_nat_addr, s->ext_host_nat_port,
128 &s->out2in.addr, s->out2in.port,
129 &s->ext_host_addr, s->ext_host_port,
130 s->nat_proto, is_twice_nat_session (s));
132 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
133 s->ext_host_port, s->nat_proto, s->out2in.fib_index,
136 if (is_twice_nat_session (s))
138 for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
140 // TODO FIXME this is obviously broken - which address should be
142 a = sm->twice_nat_addresses + i;
143 if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
145 snat_free_outside_address_and_port (sm->twice_nat_addresses,
147 &s->ext_host_nat_addr,
148 s->ext_host_nat_port,
155 if (snat_is_session_static (s))
158 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
159 &s->out2in.addr, s->out2in.port,
162 nat_ed_session_delete (sm, s, ctx->thread_index, 1);
171 icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
172 ip4_header_t * ip0, icmp46_header_t * icmp0,
173 u32 sw_if_index0, u32 rx_fib_index0,
174 vlib_node_runtime_t * node, u32 next0, f64 now,
175 u32 thread_index, snat_session_t ** p_s0)
177 vlib_main_t *vm = vlib_get_main ();
179 next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
180 next0, thread_index, p_s0, 0);
181 snat_session_t *s0 = *p_s0;
182 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
185 nat44_session_update_counters (s0, now,
186 vlib_buffer_length_in_chain
187 (vm, b0), thread_index);
188 /* Per-user LRU list maintenance */
189 nat44_session_update_lru (sm, s0, thread_index);
195 nat_ed_alloc_addr_and_port (snat_main_t * sm, u32 rx_fib_index,
196 u32 nat_proto, u32 thread_index,
197 ip4_address_t r_addr, u16 r_port, u8 proto,
198 u16 port_per_thread, u32 snat_thread_index,
200 ip4_address_t * outside_addr,
202 clib_bihash_kv_16_8_t * out2in_ed_kv)
205 snat_address_t *a, *ga = 0;
206 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
208 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
210 for (i = 0; i < vec_len (sm->addresses); i++)
212 a = sm->addresses + i;
215 #define _(N, j, n, unused) \
216 case NAT_PROTOCOL_##N: \
217 if (a->fib_index == rx_fib_index) \
219 /* first try port suggested by caller */ \
220 u16 port = clib_net_to_host_u16 (*outside_port); \
221 u16 port_offset = port - port_thread_offset; \
222 if (port <= port_thread_offset || \
223 port > port_thread_offset + port_per_thread) \
225 /* need to pick a different port, suggested port doesn't fit in \
226 * this thread's port range */ \
227 port_offset = snat_random_port (0, port_per_thread - 1); \
228 port = port_thread_offset + port_offset; \
230 u16 attempts = port_per_thread; \
233 init_ed_kv (out2in_ed_kv, a->addr, clib_host_to_net_u16 (port), \
234 r_addr, r_port, s->out2in.fib_index, proto, \
235 thread_index, s - tsm->sessions); \
236 int rv = clib_bihash_add_del_16_8 (&sm->out2in_ed, out2in_ed_kv, \
240 ++a->busy_##n##_port_refcounts[port]; \
241 a->busy_##n##_ports_per_thread[thread_index]++; \
242 a->busy_##n##_ports++; \
243 *outside_addr = a->addr; \
244 *outside_port = clib_host_to_net_u16 (port); \
247 port_offset = (port_offset + 1) % port_per_thread; \
248 port = port_thread_offset + port_offset; \
251 while (attempts > 0); \
253 else if (a->fib_index == ~0) \
259 foreach_nat_protocol;
261 nat_elog_info ("unknown protocol");
268 /* fake fib_index to reuse macro */
273 foreach_nat_protocol;
275 nat_elog_info ("unknown protocol");
282 /* Totally out of translations to use... */
283 snat_ipfix_logging_addresses_exhausted (thread_index, 0);
287 static_always_inline u32
288 nat_outside_fib_index_lookup (snat_main_t * sm, ip4_address_t addr)
290 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
291 nat_outside_fib_t *outside_fib;
293 .fp_proto = FIB_PROTOCOL_IP4,
295 .fp_addr = {.ip4.as_u32 = addr.as_u32,}
298 // TODO: multiple vrfs none can resolve addr
300 vec_foreach (outside_fib, sm->outside_fibs)
302 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
303 if (FIB_NODE_INDEX_INVALID != fei)
305 if (fib_entry_get_resolving_interface (fei) != ~0)
307 return outside_fib->fib_index;
316 slow_path_ed (snat_main_t * sm,
318 ip4_address_t l_addr,
319 ip4_address_t r_addr,
324 snat_session_t ** sessionp,
325 vlib_node_runtime_t * node, u32 next, u32 thread_index, f64 now)
327 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
328 clib_bihash_kv_16_8_t out2in_ed_kv;
329 nat44_is_idle_session_ctx_t ctx;
330 ip4_address_t outside_addr;
334 u32 nat_proto = ip_proto_to_nat_proto (proto);
335 snat_session_t *s = NULL;
336 lb_nat_type_t lb = 0;
338 if (PREDICT_TRUE (nat_proto == NAT_PROTOCOL_TCP))
342 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
344 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
345 return NAT_NEXT_DROP;
350 (nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
352 if (!nat_lru_free_one (sm, thread_index, now))
354 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
355 nat_ipfix_logging_max_sessions (thread_index,
356 sm->max_translations_per_thread);
357 nat_elog_notice ("maximum sessions exceeded");
358 return NAT_NEXT_DROP;
362 ip4_address_t sm_addr;
365 /* First try to match static mapping by local address and port */
366 if (snat_static_mapping_match
367 (sm, l_addr, l_port, rx_fib_index, nat_proto, &sm_addr, &sm_port,
368 &sm_fib_index, 0, 0, 0, &lb, 0, &identity_nat))
370 s = nat_ed_session_alloc (sm, thread_index, now, proto);
372 s->in2out.addr = l_addr;
373 s->in2out.port = l_port;
374 s->nat_proto = nat_proto;
375 s->in2out.fib_index = rx_fib_index;
376 s->out2in.fib_index = sm->outside_fib_index;
378 switch (vec_len (sm->outside_fibs))
381 s->out2in.fib_index = sm->outside_fib_index;
384 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
387 s->out2in.fib_index = nat_outside_fib_index_lookup (sm, r_addr);
391 /* Try to create dynamic translation */
392 outside_port = l_port; // suggest using local port to allocation function
393 if (nat_ed_alloc_addr_and_port (sm, rx_fib_index, nat_proto,
394 thread_index, r_addr, r_port, proto,
396 tsm->snat_thread_index, s,
398 &outside_port, &out2in_ed_kv))
400 nat_elog_notice ("addresses exhausted");
401 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
402 nat_ed_session_delete (sm, s, thread_index, 1);
403 return NAT_NEXT_DROP;
405 s->out2in.addr = outside_addr;
406 s->out2in.port = outside_port;
410 if (PREDICT_FALSE (identity_nat))
415 s = nat_ed_session_alloc (sm, thread_index, now, proto);
417 s->out2in.addr = sm_addr;
418 s->out2in.port = sm_port;
419 s->in2out.addr = l_addr;
420 s->in2out.port = l_port;
421 s->nat_proto = nat_proto;
422 s->in2out.fib_index = rx_fib_index;
423 s->out2in.fib_index = sm->outside_fib_index;
424 switch (vec_len (sm->outside_fibs))
427 s->out2in.fib_index = sm->outside_fib_index;
430 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
433 s->out2in.fib_index = nat_outside_fib_index_lookup (sm, r_addr);
437 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
439 init_ed_kv (&out2in_ed_kv, sm_addr, sm_port, r_addr, r_port,
440 s->out2in.fib_index, proto, thread_index,
442 if (clib_bihash_add_or_overwrite_stale_16_8
443 (&sm->out2in_ed, &out2in_ed_kv, nat44_o2i_ed_is_idle_session_cb,
445 nat_elog_notice ("out2in-ed key add failed");
449 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
450 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
451 s->ext_host_addr = r_addr;
452 s->ext_host_port = r_port;
454 clib_bihash_kv_16_8_t in2out_ed_kv;
455 init_ed_kv (&in2out_ed_kv, l_addr, l_port, r_addr, r_port, rx_fib_index,
456 proto, thread_index, s - tsm->sessions);
458 ctx.thread_index = thread_index;
459 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, &in2out_ed_kv,
460 nat44_i2o_ed_is_idle_session_cb,
462 nat_elog_notice ("in2out-ed key add failed");
467 snat_ipfix_logging_nat44_ses_create (thread_index,
468 s->in2out.addr.as_u32,
469 s->out2in.addr.as_u32,
472 s->out2in.port, s->in2out.fib_index);
474 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
475 &s->in2out.addr, s->in2out.port,
476 &s->ext_host_nat_addr, s->ext_host_nat_port,
477 &s->out2in.addr, s->out2in.port,
478 &s->ext_host_addr, s->ext_host_port, s->nat_proto,
481 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
482 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
483 &s->ext_host_nat_addr, s->ext_host_nat_port,
484 s->nat_proto, s->in2out.fib_index, s->flags, thread_index, 0);
489 static_always_inline int
490 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
491 u32 sw_if_index, ip4_header_t * ip, u32 proto,
492 u32 rx_fib_index, u32 thread_index)
494 udp_header_t *udp = ip4_next_header (ip);
495 clib_bihash_kv_16_8_t kv, value;
497 init_ed_k (&kv, ip->dst_address, udp->dst_port, ip->src_address,
498 udp->src_port, sm->outside_fib_index, ip->protocol);
500 /* NAT packet aimed at external address if has active sessions */
501 if (clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
503 /* or is static mappings */
504 ip4_address_t dummy_addr;
507 if (!snat_static_mapping_match
508 (sm, ip->dst_address, udp->dst_port, sm->outside_fib_index, proto,
509 &dummy_addr, &dummy_port, &dummy_fib_index, 1, 0, 0, 0, 0, 0))
515 if (sm->forwarding_enabled)
518 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
522 static_always_inline int
523 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
524 u32 thread_index, f64 now,
525 vlib_main_t * vm, vlib_buffer_t * b)
527 clib_bihash_kv_16_8_t kv, value;
528 snat_session_t *s = 0;
529 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
531 if (!sm->forwarding_enabled)
534 if (ip->protocol == IP_PROTOCOL_ICMP)
536 if (get_icmp_i2o_ed_key (b, ip, 0, ~0, ~0, 0, 0, 0, &kv))
539 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
541 init_ed_k (&kv, ip->src_address, vnet_buffer (b)->ip.reass.l4_src_port,
542 ip->dst_address, vnet_buffer (b)->ip.reass.l4_dst_port, 0,
547 init_ed_k (&kv, ip->src_address, 0, ip->dst_address, 0, 0,
551 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
553 ASSERT (thread_index == ed_value_get_thread_index (&value));
555 pool_elt_at_index (tsm->sessions,
556 ed_value_get_session_index (&value));
557 if (is_fwd_bypass_session (s))
559 if (ip->protocol == IP_PROTOCOL_TCP)
561 if (nat44_set_tcp_session_state_i2o
562 (sm, now, s, b, thread_index))
566 nat44_session_update_counters (s, now,
567 vlib_buffer_length_in_chain (vm, b),
569 /* Per-user LRU list maintenance */
570 nat44_session_update_lru (sm, s, thread_index);
580 static_always_inline int
581 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
582 u16 src_port, u16 dst_port,
583 u32 thread_index, u32 rx_sw_if_index,
586 clib_bihash_kv_16_8_t kv, value;
587 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
590 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
591 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
594 init_ed_k (&kv, ip->src_address, src_port, ip->dst_address, dst_port,
595 tx_fib_index, ip->protocol);
596 if (!clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
598 ASSERT (thread_index == ed_value_get_thread_index (&value));
600 pool_elt_at_index (tsm->sessions,
601 ed_value_get_session_index (&value));
602 if (nat44_is_ses_closed (s))
604 nat_free_session_data (sm, s, thread_index, 0);
605 nat_ed_session_delete (sm, s, thread_index, 1);
608 s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
613 init_ed_k (&kv, ip->dst_address, dst_port, ip->src_address, src_port,
614 rx_fib_index, ip->protocol);
615 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
617 ASSERT (thread_index == ed_value_get_thread_index (&value));
619 pool_elt_at_index (tsm->sessions,
620 ed_value_get_session_index (&value));
621 if (is_fwd_bypass_session (s))
626 pool_foreach (i, sm->output_feature_interfaces,
628 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
638 #ifndef CLIB_MARCH_VARIANT
640 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
641 u32 thread_index, vlib_buffer_t * b,
642 ip4_header_t * ip, ip4_address_t * addr,
643 u16 * port, u32 * fib_index, nat_protocol_t * proto,
644 void *d, void *e, u8 * dont_translate)
648 clib_bihash_kv_16_8_t kv, value;
651 snat_session_t *s = NULL;
652 u16 l_port = 0, r_port = 0; // initialize to workaround gcc warning
653 vlib_main_t *vm = vlib_get_main ();
654 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
657 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
658 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
661 get_icmp_i2o_ed_key (b, ip, rx_fib_index, ~0, ~0, proto, &l_port,
665 b->error = node->errors[err];
666 next = NAT_NEXT_DROP;
670 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
672 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
675 (nat44_ed_not_translate_output_feature
676 (sm, ip, l_port, r_port, thread_index,
677 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
685 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
686 ip, NAT_PROTOCOL_ICMP,
696 (icmp_type_is_error_message
697 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
699 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
700 next = NAT_NEXT_DROP;
705 slow_path_ed (sm, b, ip->src_address, ip->dst_address, l_port, r_port,
706 ip->protocol, rx_fib_index, &s, node, next,
707 thread_index, vlib_time_now (vm));
709 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
721 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
723 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
725 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
726 reass.icmp_type_or_tcp_flags)))
728 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
729 next = NAT_NEXT_DROP;
733 ASSERT (thread_index == ed_value_get_thread_index (&value));
735 pool_elt_at_index (tsm->sessions,
736 ed_value_get_session_index (&value));
741 *addr = s->out2in.addr;
742 *port = s->out2in.port;
743 *fib_index = s->out2in.fib_index;
747 *(snat_session_t **) d = s;
753 static snat_session_t *
754 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
760 vlib_main_t * vm, vlib_node_runtime_t * node)
762 clib_bihash_kv_8_8_t kv, value;
763 clib_bihash_kv_16_8_t s_kv, s_value;
764 snat_static_mapping_t *m;
765 u32 old_addr, new_addr = 0;
767 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
769 u32 outside_fib_index = sm->outside_fib_index;
773 switch (vec_len (sm->outside_fibs))
776 outside_fib_index = sm->outside_fib_index;
779 outside_fib_index = sm->outside_fibs[0].fib_index;
782 outside_fib_index = nat_outside_fib_index_lookup (sm, ip->dst_address);
785 old_addr = ip->src_address.as_u32;
787 init_ed_k (&s_kv, ip->src_address, 0, ip->dst_address, 0, rx_fib_index,
790 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
792 ASSERT (thread_index == ed_value_get_thread_index (&s_value));
794 pool_elt_at_index (tsm->sessions,
795 ed_value_get_session_index (&s_value));
796 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
801 (nat44_ed_maximum_sessions_exceeded
802 (sm, rx_fib_index, thread_index)))
804 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
805 nat_ipfix_logging_max_sessions (thread_index,
806 sm->max_translations_per_thread);
807 nat_elog_notice ("maximum sessions exceeded");
811 init_nat_k (&kv, ip->src_address, 0, rx_fib_index, 0);
813 /* Try to find static mapping first */
814 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
816 m = pool_elt_at_index (sm->static_mappings, value.value);
817 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
824 pool_foreach (s, tsm->sessions, {
825 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
827 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
829 init_ed_k(&s_kv, s->out2in.addr, 0, ip->dst_address, 0, outside_fib_index, ip->protocol);
830 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
838 for (i = 0; i < vec_len (sm->addresses); i++)
840 init_ed_k (&s_kv, sm->addresses[i].addr, 0, ip->dst_address, 0,
841 outside_fib_index, ip->protocol);
842 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
844 new_addr = ip->src_address.as_u32 =
845 sm->addresses[i].addr.as_u32;
853 s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
856 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
857 nat_elog_warn ("create NAT session failed");
861 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
862 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
863 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
864 s->out2in.addr.as_u32 = new_addr;
865 s->out2in.fib_index = outside_fib_index;
866 s->in2out.addr.as_u32 = old_addr;
867 s->in2out.fib_index = rx_fib_index;
868 s->in2out.port = s->out2in.port = ip->protocol;
870 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
872 /* Add to lookup tables */
873 init_ed_kv (&s_kv, s->in2out.addr, 0, ip->dst_address, 0, rx_fib_index,
874 ip->protocol, thread_index, s - tsm->sessions);
875 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
876 nat_elog_notice ("in2out key add failed");
878 init_ed_kv (&s_kv, s->out2in.addr, 0, ip->dst_address, 0,
879 outside_fib_index, ip->protocol, thread_index,
881 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &s_kv, 1))
882 nat_elog_notice ("out2in key add failed");
885 /* Update IP checksum */
887 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
888 ip->checksum = ip_csum_fold (sum);
891 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
893 /* Per-user LRU list maintenance */
894 nat44_session_update_lru (sm, s, thread_index);
897 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
898 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
900 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
901 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
907 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
908 vlib_node_runtime_t * node,
909 vlib_frame_t * frame,
910 int is_output_feature)
912 u32 n_left_from, *from, pkts_processed = 0, stats_node_index;
913 snat_main_t *sm = &snat_main;
914 f64 now = vlib_time_now (vm);
915 u32 thread_index = vm->thread_index;
916 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
917 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
920 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH :
921 NAT_NEXT_IN2OUT_ED_SLOW_PATH;
923 stats_node_index = sm->ed_in2out_node_index;
925 from = vlib_frame_vector_args (frame);
926 n_left_from = frame->n_vectors;
928 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
929 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
930 vlib_get_buffers (vm, from, b, n_left_from);
932 while (n_left_from > 0)
935 u32 sw_if_index0, rx_fib_index0, proto0, new_addr0, old_addr0,
937 u16 old_port0, new_port0;
941 snat_session_t *s0 = 0;
942 clib_bihash_kv_16_8_t kv0, value0;
948 /* Prefetch next iteration. */
949 if (PREDICT_TRUE (n_left_from >= 2))
955 vlib_prefetch_buffer_header (p2, LOAD);
957 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
960 if (is_output_feature)
962 vnet_feature_next (&vnet_buffer2 (b0)->nat.arc_next, b0);
963 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
966 next[0] = vnet_buffer2 (b0)->nat.arc_next;
969 (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) + iph_offset0);
971 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
973 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
975 if (PREDICT_FALSE (ip0->ttl == 1))
977 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
978 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
979 ICMP4_time_exceeded_ttl_exceeded_in_transit,
981 next[0] = NAT_NEXT_ICMP_ERROR;
985 udp0 = ip4_next_header (ip0);
986 tcp0 = (tcp_header_t *) udp0;
987 proto0 = ip_proto_to_nat_proto (ip0->protocol);
989 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
995 if (is_output_feature)
998 (nat_not_translate_output_feature_fwd
999 (sm, ip0, thread_index, now, vm, b0)))
1003 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1009 init_ed_k (&kv0, ip0->src_address,
1010 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1011 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1014 // lookup for session
1015 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1017 // session does not exist go slow path
1021 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1023 pool_elt_at_index (tsm->sessions,
1024 ed_value_get_session_index (&value0));
1026 if (s0->tcp_closed_timestamp)
1028 if (now >= s0->tcp_closed_timestamp)
1030 // session is closed, go slow path
1035 // session in transitory timeout, drop
1036 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1037 next[0] = NAT_NEXT_DROP;
1042 // drop if session expired
1043 u64 sess_timeout_time;
1045 s0->last_heard + (f64) nat44_session_get_timeout (sm, s0);
1046 if (now >= sess_timeout_time)
1048 nat_free_session_data (sm, s0, thread_index, 0);
1049 nat_ed_session_delete (sm, s0, thread_index, 1);
1050 // session is closed, go slow path
1055 b0->flags |= VNET_BUFFER_F_IS_NATED;
1057 if (!is_output_feature)
1058 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1060 old_addr0 = ip0->src_address.as_u32;
1061 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1062 sum0 = ip0->checksum;
1064 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1066 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1068 ip_csum_update (sum0, ip0->dst_address.as_u32,
1069 s0->ext_host_addr.as_u32, ip4_header_t,
1071 ip0->checksum = ip_csum_fold (sum0);
1073 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1075 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1077 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1079 new_port0 = udp0->src_port = s0->out2in.port;
1080 sum0 = tcp0->checksum;
1082 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1085 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1087 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1090 ip_csum_update (sum0, ip0->dst_address.as_u32,
1091 s0->ext_host_addr.as_u32, ip4_header_t,
1094 ip_csum_update (sum0,
1095 vnet_buffer (b0)->ip.reass.l4_dst_port,
1096 s0->ext_host_port, ip4_header_t, length);
1097 tcp0->dst_port = s0->ext_host_port;
1098 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1100 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1101 tcp0->checksum = ip_csum_fold (sum0);
1104 if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
1107 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1110 new_port0 = udp0->src_port = s0->out2in.port;
1111 sum0 = udp0->checksum;
1113 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1116 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1117 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1120 ip_csum_update (sum0, ip0->dst_address.as_u32,
1121 s0->ext_host_addr.as_u32, ip4_header_t,
1124 ip_csum_update (sum0, vnet_buffer (b0)->ip.reass.l4_dst_port,
1125 s0->ext_host_port, ip4_header_t, length);
1126 udp0->dst_port = s0->ext_host_port;
1127 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1129 udp0->checksum = ip_csum_fold (sum0);
1134 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1136 new_port0 = udp0->src_port = s0->out2in.port;
1137 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1139 udp0->dst_port = s0->ext_host_port;
1140 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1147 nat44_session_update_counters (s0, now,
1148 vlib_buffer_length_in_chain (vm, b0),
1150 /* Per-user LRU list maintenance */
1151 nat44_session_update_lru (sm, s0, thread_index);
1155 ((node->flags & VLIB_NODE_FLAG_TRACE)
1156 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1158 nat_in2out_ed_trace_t *t =
1159 vlib_add_trace (vm, node, b0, sizeof (*t));
1160 t->sw_if_index = sw_if_index0;
1161 t->next_index = next[0];
1162 t->is_slow_path = 0;
1165 t->session_index = s0 - tsm->sessions;
1167 t->session_index = ~0;
1170 pkts_processed += next[0] == vnet_buffer2 (b0)->nat.arc_next;
1176 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1179 vlib_node_increment_counter (vm, stats_node_index,
1180 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1182 vlib_node_increment_counter (vm, stats_node_index,
1183 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1184 vlib_node_increment_counter (vm, stats_node_index,
1185 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1186 vlib_node_increment_counter (vm, stats_node_index,
1187 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1189 vlib_node_increment_counter (vm, stats_node_index,
1190 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1192 return frame->n_vectors;
1196 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1197 vlib_node_runtime_t * node,
1198 vlib_frame_t * frame,
1199 int is_output_feature)
1201 u32 n_left_from, *from, pkts_processed = 0, stats_node_index;
1202 snat_main_t *sm = &snat_main;
1203 f64 now = vlib_time_now (vm);
1204 u32 thread_index = vm->thread_index;
1205 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1206 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1208 stats_node_index = sm->ed_in2out_slowpath_node_index;
1210 from = vlib_frame_vector_args (frame);
1211 n_left_from = frame->n_vectors;
1213 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1214 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1215 vlib_get_buffers (vm, from, b, n_left_from);
1217 while (n_left_from > 0)
1220 u32 sw_if_index0, rx_fib_index0, proto0, new_addr0, old_addr0,
1222 u16 old_port0, new_port0;
1226 icmp46_header_t *icmp0;
1227 snat_session_t *s0 = 0;
1228 clib_bihash_kv_16_8_t kv0, value0;
1233 if (is_output_feature)
1234 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1236 next[0] = vnet_buffer2 (b0)->nat.arc_next;
1238 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1241 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1243 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
1245 if (PREDICT_FALSE (ip0->ttl == 1))
1247 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1248 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1249 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1251 next[0] = NAT_NEXT_ICMP_ERROR;
1255 udp0 = ip4_next_header (ip0);
1256 tcp0 = (tcp_header_t *) udp0;
1257 icmp0 = (icmp46_header_t *) udp0;
1258 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1260 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1262 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1264 thread_index, now, vm, node);
1266 next[0] = NAT_NEXT_DROP;
1272 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1274 next[0] = icmp_in2out_ed_slow_path
1275 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1276 node, next[0], now, thread_index, &s0);
1281 init_ed_k (&kv0, ip0->src_address,
1282 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1283 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1285 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1287 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1289 pool_elt_at_index (tsm->sessions,
1290 ed_value_get_session_index (&value0));
1292 if (s0->tcp_closed_timestamp && now >= s0->tcp_closed_timestamp)
1294 nat_free_session_data (sm, s0, thread_index, 0);
1295 nat_ed_session_delete (sm, s0, thread_index, 1);
1302 if (is_output_feature)
1305 (nat44_ed_not_translate_output_feature
1306 (sm, ip0, vnet_buffer (b0)->ip.reass.l4_src_port,
1307 vnet_buffer (b0)->ip.reass.l4_dst_port, thread_index,
1308 sw_if_index0, vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1312 * Send DHCP packets to the ipv4 stack, or we won't
1313 * be able to use dhcp client on the outside interface
1316 (proto0 == NAT_PROTOCOL_UDP
1317 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1318 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1319 && ip0->dst_address.as_u32 == 0xffffffff))
1325 (nat44_ed_not_translate
1326 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1332 slow_path_ed (sm, b0, ip0->src_address, ip0->dst_address,
1333 vnet_buffer (b0)->ip.reass.l4_src_port,
1334 vnet_buffer (b0)->ip.reass.l4_dst_port,
1335 ip0->protocol, rx_fib_index0, &s0, node, next[0],
1338 if (PREDICT_FALSE (next[0] == NAT_NEXT_DROP))
1341 if (PREDICT_FALSE (!s0))
1346 b0->flags |= VNET_BUFFER_F_IS_NATED;
1348 if (!is_output_feature)
1349 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1351 old_addr0 = ip0->src_address.as_u32;
1352 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1353 sum0 = ip0->checksum;
1354 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1356 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1357 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1358 s0->ext_host_addr.as_u32, ip4_header_t,
1360 ip0->checksum = ip_csum_fold (sum0);
1362 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1364 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1366 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1368 new_port0 = udp0->src_port = s0->out2in.port;
1369 sum0 = tcp0->checksum;
1371 ip_csum_update (sum0, old_addr0, new_addr0,
1372 ip4_header_t, dst_address);
1374 ip_csum_update (sum0, old_port0, new_port0,
1375 ip4_header_t, length);
1376 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1379 ip_csum_update (sum0, ip0->dst_address.as_u32,
1380 s0->ext_host_addr.as_u32,
1381 ip4_header_t, dst_address);
1383 ip_csum_update (sum0,
1384 vnet_buffer (b0)->ip.reass.l4_dst_port,
1385 s0->ext_host_port, ip4_header_t, length);
1386 tcp0->dst_port = s0->ext_host_port;
1387 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1389 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1390 tcp0->checksum = ip_csum_fold (sum0);
1393 if (nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index))
1396 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1399 new_port0 = udp0->src_port = s0->out2in.port;
1400 sum0 = udp0->checksum;
1402 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1405 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1406 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1408 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1409 s0->ext_host_addr.as_u32,
1410 ip4_header_t, dst_address);
1412 ip_csum_update (sum0,
1413 vnet_buffer (b0)->ip.reass.l4_dst_port,
1414 s0->ext_host_port, ip4_header_t, length);
1415 udp0->dst_port = s0->ext_host_port;
1416 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1418 udp0->checksum = ip_csum_fold (sum0);
1423 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1425 new_port0 = udp0->src_port = s0->out2in.port;
1426 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1428 udp0->dst_port = s0->ext_host_port;
1429 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1436 nat44_session_update_counters (s0, now,
1437 vlib_buffer_length_in_chain
1438 (vm, b0), thread_index);
1439 /* Per-user LRU list maintenance */
1440 nat44_session_update_lru (sm, s0, thread_index);
1443 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1444 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1446 nat_in2out_ed_trace_t *t =
1447 vlib_add_trace (vm, node, b0, sizeof (*t));
1448 t->sw_if_index = sw_if_index0;
1449 t->next_index = next[0];
1450 t->is_slow_path = 1;
1453 t->session_index = s0 - tsm->sessions;
1455 t->session_index = ~0;
1458 pkts_processed += next[0] == vnet_buffer2 (b0)->nat.arc_next;
1465 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1468 vlib_node_increment_counter (vm, stats_node_index,
1469 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1471 vlib_node_increment_counter (vm, stats_node_index,
1472 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1473 vlib_node_increment_counter (vm, stats_node_index,
1474 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1475 vlib_node_increment_counter (vm, stats_node_index,
1476 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1478 vlib_node_increment_counter (vm, stats_node_index,
1479 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1481 return frame->n_vectors;
1484 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1485 vlib_node_runtime_t * node,
1486 vlib_frame_t * frame)
1488 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1492 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1493 .name = "nat44-ed-in2out",
1494 .vector_size = sizeof (u32),
1495 .sibling_of = "nat-default",
1496 .format_trace = format_nat_in2out_ed_trace,
1497 .type = VLIB_NODE_TYPE_INTERNAL,
1498 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1499 .error_strings = nat_in2out_ed_error_strings,
1500 .runtime_data_bytes = sizeof (snat_runtime_t),
1504 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1505 vlib_node_runtime_t * node,
1506 vlib_frame_t * frame)
1508 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1512 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1513 .name = "nat44-ed-in2out-output",
1514 .vector_size = sizeof (u32),
1515 .sibling_of = "nat-default",
1516 .format_trace = format_nat_in2out_ed_trace,
1517 .type = VLIB_NODE_TYPE_INTERNAL,
1518 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1519 .error_strings = nat_in2out_ed_error_strings,
1520 .runtime_data_bytes = sizeof (snat_runtime_t),
1524 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1525 vlib_node_runtime_t *
1526 node, vlib_frame_t * frame)
1528 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1532 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1533 .name = "nat44-ed-in2out-slowpath",
1534 .vector_size = sizeof (u32),
1535 .sibling_of = "nat-default",
1536 .format_trace = format_nat_in2out_ed_trace,
1537 .type = VLIB_NODE_TYPE_INTERNAL,
1538 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1539 .error_strings = nat_in2out_ed_error_strings,
1540 .runtime_data_bytes = sizeof (snat_runtime_t),
1544 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1547 vlib_frame_t * frame)
1549 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1553 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1554 .name = "nat44-ed-in2out-output-slowpath",
1555 .vector_size = sizeof (u32),
1556 .sibling_of = "nat-default",
1557 .format_trace = format_nat_in2out_ed_trace,
1558 .type = VLIB_NODE_TYPE_INTERNAL,
1559 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1560 .error_strings = nat_in2out_ed_error_strings,
1561 .runtime_data_bytes = sizeof (snat_runtime_t),
1566 format_nat_pre_trace (u8 * s, va_list * args)
1568 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1569 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1570 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1571 return format (s, "in2out next_index %d arc_next_index %d", t->next_index,
1575 VLIB_NODE_FN (nat_pre_in2out_node)
1576 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1578 return nat_pre_node_fn_inline (vm, node, frame,
1579 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1583 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1584 .name = "nat-pre-in2out",
1585 .vector_size = sizeof (u32),
1586 .sibling_of = "nat-default",
1587 .format_trace = format_nat_pre_trace,
1588 .type = VLIB_NODE_TYPE_INTERNAL,
1594 * fd.io coding-style-patch-verification: ON
1597 * eval: (c-set-style "gnu")