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/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/fib/ip4_fib.h>
25 #include <vnet/udp/udp_local.h>
26 #include <vppinfra/error.h>
28 #include <nat/lib/ipfix_logging.h>
29 #include <nat/nat_inlines.h>
30 #include <nat/nat44/inlines.h>
31 #include <nat/lib/nat_syslog.h>
32 #include <nat/nat_ha.h>
33 #include <nat/nat44/ed_inlines.h>
34 #include <nat/lib/nat_inlines.h>
36 /* number of attempts to get a port for ED overloading algorithm, if rolling
37 * a dice this many times doesn't produce a free port, it's treated
38 * as if there were no free ports available to conserve resources */
39 #define ED_PORT_ALLOC_ATTEMPTS (10)
41 static char *nat_in2out_ed_error_strings[] = {
42 #define _(sym,string) string,
43 foreach_nat_in2out_ed_error
53 } nat_in2out_ed_trace_t;
56 format_nat_in2out_ed_trace (u8 * s, va_list * args)
58 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
59 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
60 nat_in2out_ed_trace_t *t = va_arg (*args, nat_in2out_ed_trace_t *);
64 t->is_slow_path ? "NAT44_IN2OUT_ED_SLOW_PATH" :
65 "NAT44_IN2OUT_ED_FAST_PATH";
67 s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
68 t->sw_if_index, t->next_index, t->session_index);
73 #ifndef CLIB_MARCH_VARIANT
75 nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void *arg)
77 snat_main_t *sm = &snat_main;
78 nat44_is_idle_session_ctx_t *ctx = arg;
80 u64 sess_timeout_time;
83 ip4_address_t *l_addr, *r_addr;
85 clib_bihash_kv_16_8_t ed_kv;
88 snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
91 ASSERT (ctx->thread_index == ed_value_get_thread_index (kv));
92 s = pool_elt_at_index (tsm->sessions, ed_value_get_session_index (kv));
93 sess_timeout_time = s->last_heard + (f64) nat44_session_get_timeout (sm, s);
94 if (ctx->now >= sess_timeout_time)
96 if (is_fwd_bypass_session (s))
99 l_addr = &s->out2in.addr;
100 r_addr = &s->ext_host_addr;
101 fib_index = s->out2in.fib_index;
102 if (snat_is_unk_proto_session (s))
104 proto = s->in2out.port;
110 proto = nat_proto_to_ip_proto (s->nat_proto);
111 l_port = s->out2in.port;
112 r_port = s->ext_host_port;
114 init_ed_k (&ed_kv, *l_addr, l_port, *r_addr, r_port, fib_index, proto);
115 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &ed_kv, 0))
116 nat_elog_warn ("out2in_ed key del failed");
118 if (snat_is_unk_proto_session (s))
121 nat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
122 s->in2out.addr.as_u32,
123 s->out2in.addr.as_u32,
127 s->in2out.fib_index);
129 nat_syslog_nat44_sdel (s->user_index, s->in2out.fib_index,
130 &s->in2out.addr, s->in2out.port,
131 &s->ext_host_nat_addr, s->ext_host_nat_port,
132 &s->out2in.addr, s->out2in.port,
133 &s->ext_host_addr, s->ext_host_port,
134 s->nat_proto, is_twice_nat_session (s));
136 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
137 s->ext_host_port, s->nat_proto, s->out2in.fib_index,
140 if (is_twice_nat_session (s))
142 for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
144 // TODO FIXME this is obviously broken - which address should be
146 a = sm->twice_nat_addresses + i;
147 if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
149 snat_free_outside_address_and_port (sm->twice_nat_addresses,
151 &s->ext_host_nat_addr,
152 s->ext_host_nat_port,
159 if (snat_is_session_static (s))
162 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
163 &s->out2in.addr, s->out2in.port,
166 nat_ed_session_delete (sm, s, ctx->thread_index, 1);
175 icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
176 ip4_header_t * ip0, icmp46_header_t * icmp0,
177 u32 sw_if_index0, u32 rx_fib_index0,
178 vlib_node_runtime_t * node, u32 next0, f64 now,
179 u32 thread_index, snat_session_t ** p_s0)
181 vlib_main_t *vm = vlib_get_main ();
183 next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
184 next0, thread_index, p_s0, 0);
185 snat_session_t *s0 = *p_s0;
186 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
189 nat44_session_update_counters (s0, now,
190 vlib_buffer_length_in_chain
191 (vm, b0), thread_index);
192 /* Per-user LRU list maintenance */
193 nat44_session_update_lru (sm, s0, thread_index);
199 nat_ed_alloc_addr_and_port (snat_main_t * sm, u32 rx_fib_index,
200 u32 nat_proto, u32 thread_index,
201 ip4_address_t r_addr, u16 r_port, u8 proto,
202 u16 port_per_thread, u32 snat_thread_index,
204 ip4_address_t * outside_addr,
206 clib_bihash_kv_16_8_t * out2in_ed_kv)
209 snat_address_t *a, *ga = 0;
210 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
212 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
214 for (i = 0; i < vec_len (sm->addresses); i++)
216 a = sm->addresses + i;
219 #define _(N, j, n, unused) \
220 case NAT_PROTOCOL_##N: \
221 if (a->fib_index == rx_fib_index) \
223 /* first try port suggested by caller */ \
224 u16 port = clib_net_to_host_u16 (*outside_port); \
225 u16 port_offset = port - port_thread_offset; \
226 if (port <= port_thread_offset || \
227 port > port_thread_offset + port_per_thread) \
229 /* need to pick a different port, suggested port doesn't fit in \
230 * this thread's port range */ \
231 port_offset = snat_random_port (0, port_per_thread - 1); \
232 port = port_thread_offset + port_offset; \
234 u16 attempts = ED_PORT_ALLOC_ATTEMPTS; \
237 init_ed_kv (out2in_ed_kv, a->addr, clib_host_to_net_u16 (port), \
238 r_addr, r_port, s->out2in.fib_index, proto, \
239 thread_index, s - tsm->sessions); \
240 int rv = clib_bihash_add_del_16_8 (&sm->out2in_ed, out2in_ed_kv, \
244 ++a->busy_##n##_port_refcounts[port]; \
245 a->busy_##n##_ports_per_thread[thread_index]++; \
246 a->busy_##n##_ports++; \
247 *outside_addr = a->addr; \
248 *outside_port = clib_host_to_net_u16 (port); \
251 port_offset = snat_random_port (0, port_per_thread - 1); \
252 port = port_thread_offset + port_offset; \
255 while (attempts > 0); \
257 else if (a->fib_index == ~0) \
263 foreach_nat_protocol;
265 nat_elog_info ("unknown protocol");
272 /* fake fib_index to reuse macro */
277 foreach_nat_protocol;
279 nat_elog_info ("unknown protocol");
286 /* Totally out of translations to use... */
287 nat_ipfix_logging_addresses_exhausted (thread_index, 0);
291 static_always_inline u32
292 nat_outside_fib_index_lookup (snat_main_t * sm, ip4_address_t addr)
294 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
295 nat_outside_fib_t *outside_fib;
297 .fp_proto = FIB_PROTOCOL_IP4,
299 .fp_addr = {.ip4.as_u32 = addr.as_u32,}
302 // TODO: multiple vrfs none can resolve addr
304 vec_foreach (outside_fib, sm->outside_fibs)
306 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
307 if (FIB_NODE_INDEX_INVALID != fei)
309 if (fib_entry_get_resolving_interface (fei) != ~0)
311 return outside_fib->fib_index;
320 slow_path_ed (snat_main_t * sm,
322 ip4_address_t l_addr,
323 ip4_address_t r_addr,
328 snat_session_t ** sessionp,
329 vlib_node_runtime_t * node, u32 next, u32 thread_index, f64 now)
331 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
332 clib_bihash_kv_16_8_t out2in_ed_kv;
333 nat44_is_idle_session_ctx_t ctx;
334 ip4_address_t outside_addr;
338 u32 nat_proto = ip_proto_to_nat_proto (proto);
339 snat_session_t *s = NULL;
340 lb_nat_type_t lb = 0;
342 if (PREDICT_TRUE (nat_proto == NAT_PROTOCOL_TCP))
346 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
348 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
349 return NAT_NEXT_DROP;
354 (nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
356 if (!nat_lru_free_one (sm, thread_index, now))
358 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
359 nat_ipfix_logging_max_sessions (thread_index,
360 sm->max_translations_per_thread);
361 nat_elog_notice ("maximum sessions exceeded");
362 return NAT_NEXT_DROP;
366 ip4_address_t sm_addr;
369 /* First try to match static mapping by local address and port */
370 if (snat_static_mapping_match
371 (sm, l_addr, l_port, rx_fib_index, nat_proto, &sm_addr, &sm_port,
372 &sm_fib_index, 0, 0, 0, &lb, 0, &identity_nat, 0))
374 s = nat_ed_session_alloc (sm, thread_index, now, proto);
376 s->in2out.addr = l_addr;
377 s->in2out.port = l_port;
378 s->nat_proto = nat_proto;
379 s->in2out.fib_index = rx_fib_index;
380 s->out2in.fib_index = sm->outside_fib_index;
382 switch (vec_len (sm->outside_fibs))
385 s->out2in.fib_index = sm->outside_fib_index;
388 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
391 s->out2in.fib_index = nat_outside_fib_index_lookup (sm, r_addr);
395 /* Try to create dynamic translation */
396 outside_port = l_port; // suggest using local port to allocation function
397 if (nat_ed_alloc_addr_and_port (sm, rx_fib_index, nat_proto,
398 thread_index, r_addr, r_port, proto,
400 tsm->snat_thread_index, s,
402 &outside_port, &out2in_ed_kv))
404 nat_elog_notice ("addresses exhausted");
405 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
406 nat_ed_session_delete (sm, s, thread_index, 1);
407 return NAT_NEXT_DROP;
409 s->out2in.addr = outside_addr;
410 s->out2in.port = outside_port;
414 if (PREDICT_FALSE (identity_nat))
419 s = nat_ed_session_alloc (sm, thread_index, now, proto);
421 s->out2in.addr = sm_addr;
422 s->out2in.port = sm_port;
423 s->in2out.addr = l_addr;
424 s->in2out.port = l_port;
425 s->nat_proto = nat_proto;
426 s->in2out.fib_index = rx_fib_index;
427 s->out2in.fib_index = sm->outside_fib_index;
428 switch (vec_len (sm->outside_fibs))
431 s->out2in.fib_index = sm->outside_fib_index;
434 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
437 s->out2in.fib_index = nat_outside_fib_index_lookup (sm, r_addr);
441 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
443 init_ed_kv (&out2in_ed_kv, sm_addr, sm_port, r_addr, r_port,
444 s->out2in.fib_index, proto, thread_index,
446 if (clib_bihash_add_or_overwrite_stale_16_8
447 (&sm->out2in_ed, &out2in_ed_kv, nat44_o2i_ed_is_idle_session_cb,
449 nat_elog_notice ("out2in-ed key add failed");
453 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
454 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
455 s->ext_host_addr = r_addr;
456 s->ext_host_port = r_port;
458 clib_bihash_kv_16_8_t in2out_ed_kv;
459 init_ed_kv (&in2out_ed_kv, l_addr, l_port, r_addr, r_port, rx_fib_index,
460 proto, thread_index, s - tsm->sessions);
462 ctx.thread_index = thread_index;
463 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, &in2out_ed_kv,
464 nat44_i2o_ed_is_idle_session_cb,
466 nat_elog_notice ("in2out-ed key add failed");
471 nat_ipfix_logging_nat44_ses_create (thread_index,
472 s->in2out.addr.as_u32,
473 s->out2in.addr.as_u32,
476 s->out2in.port, s->in2out.fib_index);
478 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
479 &s->in2out.addr, s->in2out.port,
480 &s->ext_host_nat_addr, s->ext_host_nat_port,
481 &s->out2in.addr, s->out2in.port,
482 &s->ext_host_addr, s->ext_host_port, s->nat_proto,
485 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
486 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
487 &s->ext_host_nat_addr, s->ext_host_nat_port,
488 s->nat_proto, s->in2out.fib_index, s->flags, thread_index, 0);
490 per_vrf_sessions_register_session (s, thread_index);
495 static_always_inline int
496 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
497 u32 sw_if_index, ip4_header_t * ip, u32 proto,
498 u32 rx_fib_index, u32 thread_index)
500 udp_header_t *udp = ip4_next_header (ip);
501 clib_bihash_kv_16_8_t kv, value;
503 init_ed_k (&kv, ip->dst_address, udp->dst_port, ip->src_address,
504 udp->src_port, sm->outside_fib_index, ip->protocol);
506 /* NAT packet aimed at external address if has active sessions */
507 if (clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
509 /* or is static mappings */
510 ip4_address_t placeholder_addr;
511 u16 placeholder_port;
512 u32 placeholder_fib_index;
513 if (!snat_static_mapping_match
514 (sm, ip->dst_address, udp->dst_port, sm->outside_fib_index, proto,
515 &placeholder_addr, &placeholder_port, &placeholder_fib_index, 1, 0,
522 if (sm->forwarding_enabled)
525 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
529 static_always_inline int
530 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
531 u32 thread_index, f64 now,
532 vlib_main_t * vm, vlib_buffer_t * b)
534 clib_bihash_kv_16_8_t kv, value;
535 snat_session_t *s = 0;
536 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
538 if (!sm->forwarding_enabled)
541 if (ip->protocol == IP_PROTOCOL_ICMP)
543 if (get_icmp_i2o_ed_key (b, ip, 0, ~0, ~0, 0, 0, 0, &kv))
546 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
548 init_ed_k (&kv, ip->src_address, vnet_buffer (b)->ip.reass.l4_src_port,
549 ip->dst_address, vnet_buffer (b)->ip.reass.l4_dst_port, 0,
554 init_ed_k (&kv, ip->src_address, 0, ip->dst_address, 0, 0,
558 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
560 ASSERT (thread_index == ed_value_get_thread_index (&value));
562 pool_elt_at_index (tsm->sessions,
563 ed_value_get_session_index (&value));
564 if (is_fwd_bypass_session (s))
566 if (ip->protocol == IP_PROTOCOL_TCP)
568 nat44_set_tcp_session_state_i2o (sm, now, s, b, thread_index);
571 nat44_session_update_counters (s, now,
572 vlib_buffer_length_in_chain (vm, b),
574 /* Per-user LRU list maintenance */
575 nat44_session_update_lru (sm, s, thread_index);
585 static_always_inline int
586 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
587 u16 src_port, u16 dst_port,
588 u32 thread_index, u32 rx_sw_if_index,
589 u32 tx_sw_if_index, f64 now)
591 clib_bihash_kv_16_8_t kv, value;
592 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
595 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
596 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
599 init_ed_k (&kv, ip->src_address, src_port, ip->dst_address, dst_port,
600 tx_fib_index, ip->protocol);
601 if (!clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
603 ASSERT (thread_index == ed_value_get_thread_index (&value));
605 pool_elt_at_index (tsm->sessions,
606 ed_value_get_session_index (&value));
607 if (nat44_is_ses_closed (s)
608 && (!s->tcp_closed_timestamp || now >= s->tcp_closed_timestamp))
610 nat_free_session_data (sm, s, thread_index, 0);
611 nat_ed_session_delete (sm, s, thread_index, 1);
617 init_ed_k (&kv, ip->dst_address, dst_port, ip->src_address, src_port,
618 rx_fib_index, ip->protocol);
619 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
621 ASSERT (thread_index == ed_value_get_thread_index (&value));
623 pool_elt_at_index (tsm->sessions,
624 ed_value_get_session_index (&value));
625 if (is_fwd_bypass_session (s))
630 pool_foreach (i, sm->output_feature_interfaces,
632 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
642 #ifndef CLIB_MARCH_VARIANT
644 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
645 u32 thread_index, vlib_buffer_t * b,
646 ip4_header_t * ip, ip4_address_t * addr,
647 u16 * port, u32 * fib_index, nat_protocol_t * proto,
648 void *d, void *e, u8 * dont_translate)
652 clib_bihash_kv_16_8_t kv, value;
655 snat_session_t *s = NULL;
656 u16 l_port = 0, r_port = 0; // initialize to workaround gcc warning
657 vlib_main_t *vm = vlib_get_main ();
658 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
660 f64 now = vlib_time_now (vm);
662 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
663 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
666 get_icmp_i2o_ed_key (b, ip, rx_fib_index, ~0, ~0, proto, &l_port,
670 b->error = node->errors[err];
671 next = NAT_NEXT_DROP;
675 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
677 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
680 (nat44_ed_not_translate_output_feature
681 (sm, ip, l_port, r_port, thread_index,
682 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX], now)))
690 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
691 ip, NAT_PROTOCOL_ICMP,
701 (icmp_type_is_error_message
702 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
704 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
705 next = NAT_NEXT_DROP;
710 slow_path_ed (sm, b, ip->src_address, ip->dst_address, l_port, r_port,
711 ip->protocol, rx_fib_index, &s, node, next,
712 thread_index, vlib_time_now (vm));
714 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
726 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
728 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
730 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
731 reass.icmp_type_or_tcp_flags)))
733 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
734 next = NAT_NEXT_DROP;
738 ASSERT (thread_index == ed_value_get_thread_index (&value));
740 pool_elt_at_index (tsm->sessions,
741 ed_value_get_session_index (&value));
746 *addr = s->out2in.addr;
747 *port = s->out2in.port;
748 *fib_index = s->out2in.fib_index;
752 *(snat_session_t **) d = s;
758 static snat_session_t *
759 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
765 vlib_main_t * vm, vlib_node_runtime_t * node)
767 clib_bihash_kv_8_8_t kv, value;
768 clib_bihash_kv_16_8_t s_kv, s_value;
769 snat_static_mapping_t *m;
770 u32 old_addr, new_addr = 0;
772 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
774 u32 outside_fib_index = sm->outside_fib_index;
778 switch (vec_len (sm->outside_fibs))
781 outside_fib_index = sm->outside_fib_index;
784 outside_fib_index = sm->outside_fibs[0].fib_index;
787 outside_fib_index = nat_outside_fib_index_lookup (sm, ip->dst_address);
790 old_addr = ip->src_address.as_u32;
792 init_ed_k (&s_kv, ip->src_address, 0, ip->dst_address, 0, rx_fib_index,
795 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
797 ASSERT (thread_index == ed_value_get_thread_index (&s_value));
799 pool_elt_at_index (tsm->sessions,
800 ed_value_get_session_index (&s_value));
801 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
806 (nat44_ed_maximum_sessions_exceeded
807 (sm, rx_fib_index, thread_index)))
809 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
810 nat_ipfix_logging_max_sessions (thread_index,
811 sm->max_translations_per_thread);
812 nat_elog_notice ("maximum sessions exceeded");
816 init_nat_k (&kv, ip->src_address, 0, rx_fib_index, 0);
818 /* Try to find static mapping first */
819 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
821 m = pool_elt_at_index (sm->static_mappings, value.value);
822 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
829 pool_foreach (s, tsm->sessions, {
830 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
832 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
834 init_ed_k(&s_kv, s->out2in.addr, 0, ip->dst_address, 0, outside_fib_index, ip->protocol);
835 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
843 for (i = 0; i < vec_len (sm->addresses); i++)
845 init_ed_k (&s_kv, sm->addresses[i].addr, 0, ip->dst_address, 0,
846 outside_fib_index, ip->protocol);
847 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
849 new_addr = ip->src_address.as_u32 =
850 sm->addresses[i].addr.as_u32;
858 s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
861 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
862 nat_elog_warn ("create NAT session failed");
866 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
867 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
868 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
869 s->out2in.addr.as_u32 = new_addr;
870 s->out2in.fib_index = outside_fib_index;
871 s->in2out.addr.as_u32 = old_addr;
872 s->in2out.fib_index = rx_fib_index;
873 s->in2out.port = s->out2in.port = ip->protocol;
875 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
877 /* Add to lookup tables */
878 init_ed_kv (&s_kv, s->in2out.addr, 0, ip->dst_address, 0, rx_fib_index,
879 ip->protocol, thread_index, s - tsm->sessions);
880 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
881 nat_elog_notice ("in2out key add failed");
883 init_ed_kv (&s_kv, s->out2in.addr, 0, ip->dst_address, 0,
884 outside_fib_index, ip->protocol, thread_index,
886 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &s_kv, 1))
887 nat_elog_notice ("out2in key add failed");
889 per_vrf_sessions_register_session (s, thread_index);
892 /* Update IP checksum */
894 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
895 ip->checksum = ip_csum_fold (sum);
898 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
900 /* Per-user LRU list maintenance */
901 nat44_session_update_lru (sm, s, thread_index);
904 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
905 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
907 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
908 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
914 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
915 vlib_node_runtime_t * node,
916 vlib_frame_t * frame,
917 int is_output_feature)
919 u32 n_left_from, *from;
920 snat_main_t *sm = &snat_main;
921 f64 now = vlib_time_now (vm);
922 u32 thread_index = vm->thread_index;
923 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
924 u32 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH
925 : NAT_NEXT_IN2OUT_ED_SLOW_PATH;
927 from = vlib_frame_vector_args (frame);
928 n_left_from = frame->n_vectors;
930 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
931 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
932 vlib_get_buffers (vm, from, b, n_left_from);
934 while (n_left_from > 0)
937 u32 sw_if_index0, rx_fib_index0, proto0, new_addr0, old_addr0,
939 u16 old_port0, new_port0;
943 snat_session_t *s0 = 0;
944 clib_bihash_kv_16_8_t kv0, value0;
950 /* Prefetch next iteration. */
951 if (PREDICT_TRUE (n_left_from >= 2))
957 vlib_prefetch_buffer_header (p2, LOAD);
959 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
962 if (is_output_feature)
964 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
967 next[0] = vnet_buffer2 (b0)->nat.arc_next;
970 (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) + iph_offset0);
972 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
974 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
976 if (PREDICT_FALSE (ip0->ttl == 1))
978 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
979 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
980 ICMP4_time_exceeded_ttl_exceeded_in_transit,
982 next[0] = NAT_NEXT_ICMP_ERROR;
986 udp0 = ip4_next_header (ip0);
987 tcp0 = (tcp_header_t *) udp0;
988 proto0 = ip_proto_to_nat_proto (ip0->protocol);
990 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
996 if (is_output_feature)
999 (nat_not_translate_output_feature_fwd
1000 (sm, ip0, thread_index, now, vm, b0)))
1004 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1010 init_ed_k (&kv0, ip0->src_address,
1011 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1012 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1015 // lookup for session
1016 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1018 // session does not exist go slow path
1022 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1024 pool_elt_at_index (tsm->sessions,
1025 ed_value_get_session_index (&value0));
1027 if (PREDICT_FALSE (per_vrf_sessions_is_expired (s0, thread_index)))
1029 // session is closed, go slow path
1030 nat_free_session_data (sm, s0, thread_index, 0);
1031 nat_ed_session_delete (sm, s0, thread_index, 1);
1032 next[0] = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
1036 if (s0->tcp_closed_timestamp)
1038 if (now >= s0->tcp_closed_timestamp)
1040 // session is closed, go slow path, freed in slow path
1045 // session in transitory timeout, drop
1046 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1047 next[0] = NAT_NEXT_DROP;
1052 // drop if session expired
1053 u64 sess_timeout_time;
1055 s0->last_heard + (f64) nat44_session_get_timeout (sm, s0);
1056 if (now >= sess_timeout_time)
1058 nat_free_session_data (sm, s0, thread_index, 0);
1059 nat_ed_session_delete (sm, s0, thread_index, 1);
1060 // session is closed, go slow path
1065 b0->flags |= VNET_BUFFER_F_IS_NATED;
1067 if (!is_output_feature)
1068 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1070 old_addr0 = ip0->src_address.as_u32;
1071 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1072 sum0 = ip0->checksum;
1074 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1076 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1078 ip_csum_update (sum0, ip0->dst_address.as_u32,
1079 s0->ext_host_addr.as_u32, ip4_header_t,
1081 ip0->checksum = ip_csum_fold (sum0);
1083 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1085 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1087 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1089 new_port0 = udp0->src_port = s0->out2in.port;
1090 sum0 = tcp0->checksum;
1092 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1095 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1097 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1100 ip_csum_update (sum0, ip0->dst_address.as_u32,
1101 s0->ext_host_addr.as_u32, ip4_header_t,
1104 ip_csum_update (sum0,
1105 vnet_buffer (b0)->ip.reass.l4_dst_port,
1106 s0->ext_host_port, ip4_header_t, length);
1107 tcp0->dst_port = s0->ext_host_port;
1108 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1110 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1111 tcp0->checksum = ip_csum_fold (sum0);
1113 vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.tcp,
1114 thread_index, sw_if_index0, 1);
1115 nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index);
1117 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1120 new_port0 = udp0->src_port = s0->out2in.port;
1121 sum0 = udp0->checksum;
1123 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1126 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1127 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1130 ip_csum_update (sum0, ip0->dst_address.as_u32,
1131 s0->ext_host_addr.as_u32, ip4_header_t,
1134 ip_csum_update (sum0, vnet_buffer (b0)->ip.reass.l4_dst_port,
1135 s0->ext_host_port, ip4_header_t, length);
1136 udp0->dst_port = s0->ext_host_port;
1137 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1139 udp0->checksum = ip_csum_fold (sum0);
1140 vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.udp,
1141 thread_index, sw_if_index0, 1);
1145 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1147 new_port0 = udp0->src_port = s0->out2in.port;
1148 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1150 udp0->dst_port = s0->ext_host_port;
1151 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1153 vlib_increment_simple_counter (&sm->counters.fastpath.
1154 in2out_ed.udp, thread_index,
1160 nat44_session_update_counters (s0, now,
1161 vlib_buffer_length_in_chain (vm, b0),
1163 /* Per-user LRU list maintenance */
1164 nat44_session_update_lru (sm, s0, thread_index);
1168 ((node->flags & VLIB_NODE_FLAG_TRACE)
1169 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1171 nat_in2out_ed_trace_t *t =
1172 vlib_add_trace (vm, node, b0, sizeof (*t));
1173 t->sw_if_index = sw_if_index0;
1174 t->next_index = next[0];
1175 t->is_slow_path = 0;
1178 t->session_index = s0 - tsm->sessions;
1180 t->session_index = ~0;
1183 if (next[0] == NAT_NEXT_DROP)
1185 vlib_increment_simple_counter (&sm->counters.fastpath.
1186 in2out_ed.drops, thread_index,
1194 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1196 return frame->n_vectors;
1200 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1201 vlib_node_runtime_t * node,
1202 vlib_frame_t * frame,
1203 int is_output_feature)
1205 u32 n_left_from, *from;
1206 snat_main_t *sm = &snat_main;
1207 f64 now = vlib_time_now (vm);
1208 u32 thread_index = vm->thread_index;
1209 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1211 from = vlib_frame_vector_args (frame);
1212 n_left_from = frame->n_vectors;
1214 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1215 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1216 vlib_get_buffers (vm, from, b, n_left_from);
1218 while (n_left_from > 0)
1221 u32 sw_if_index0, rx_fib_index0, proto0, new_addr0, old_addr0,
1223 u16 old_port0, new_port0;
1227 icmp46_header_t *icmp0;
1228 snat_session_t *s0 = 0;
1229 clib_bihash_kv_16_8_t kv0, value0;
1234 if (is_output_feature)
1235 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1237 next[0] = vnet_buffer2 (b0)->nat.arc_next;
1239 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1242 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1244 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
1246 if (PREDICT_FALSE (ip0->ttl == 1))
1248 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1249 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1250 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1252 next[0] = NAT_NEXT_ICMP_ERROR;
1256 udp0 = ip4_next_header (ip0);
1257 tcp0 = (tcp_header_t *) udp0;
1258 icmp0 = (icmp46_header_t *) udp0;
1259 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1261 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1263 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1265 thread_index, now, vm, node);
1267 next[0] = NAT_NEXT_DROP;
1269 vlib_increment_simple_counter (&sm->counters.slowpath.
1270 in2out_ed.other, thread_index,
1275 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1278 icmp_in2out_ed_slow_path (sm, b0, ip0, icmp0, sw_if_index0,
1279 rx_fib_index0, node, next[0], now,
1281 vlib_increment_simple_counter (&sm->counters.slowpath.
1282 in2out_ed.icmp, thread_index,
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],
1319 * Send DHCP packets to the ipv4 stack, or we won't
1320 * be able to use dhcp client on the outside interface
1323 (proto0 == NAT_PROTOCOL_UDP
1324 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1325 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1326 && ip0->dst_address.as_u32 == 0xffffffff))
1332 (nat44_ed_not_translate
1333 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1339 slow_path_ed (sm, b0, ip0->src_address, ip0->dst_address,
1340 vnet_buffer (b0)->ip.reass.l4_src_port,
1341 vnet_buffer (b0)->ip.reass.l4_dst_port,
1342 ip0->protocol, rx_fib_index0, &s0, node, next[0],
1345 if (PREDICT_FALSE (next[0] == NAT_NEXT_DROP))
1348 if (PREDICT_FALSE (!s0))
1353 b0->flags |= VNET_BUFFER_F_IS_NATED;
1355 if (!is_output_feature)
1356 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1358 old_addr0 = ip0->src_address.as_u32;
1359 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1360 sum0 = ip0->checksum;
1361 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1363 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1364 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1365 s0->ext_host_addr.as_u32, ip4_header_t,
1367 ip0->checksum = ip_csum_fold (sum0);
1369 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1371 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1373 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1375 new_port0 = udp0->src_port = s0->out2in.port;
1376 sum0 = tcp0->checksum;
1378 ip_csum_update (sum0, old_addr0, new_addr0,
1379 ip4_header_t, dst_address);
1381 ip_csum_update (sum0, old_port0, new_port0,
1382 ip4_header_t, length);
1383 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1386 ip_csum_update (sum0, ip0->dst_address.as_u32,
1387 s0->ext_host_addr.as_u32,
1388 ip4_header_t, dst_address);
1390 ip_csum_update (sum0,
1391 vnet_buffer (b0)->ip.reass.l4_dst_port,
1392 s0->ext_host_port, ip4_header_t, length);
1393 tcp0->dst_port = s0->ext_host_port;
1394 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1396 mss_clamping (sm->mss_clamping, tcp0, &sum0);
1397 tcp0->checksum = ip_csum_fold (sum0);
1399 vlib_increment_simple_counter (&sm->counters.slowpath.in2out_ed.tcp,
1400 thread_index, sw_if_index0, 1);
1401 nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index);
1403 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1406 new_port0 = udp0->src_port = s0->out2in.port;
1407 sum0 = udp0->checksum;
1409 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1412 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t, length);
1413 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1415 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1416 s0->ext_host_addr.as_u32,
1417 ip4_header_t, dst_address);
1419 ip_csum_update (sum0,
1420 vnet_buffer (b0)->ip.reass.l4_dst_port,
1421 s0->ext_host_port, ip4_header_t, length);
1422 udp0->dst_port = s0->ext_host_port;
1423 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1425 udp0->checksum = ip_csum_fold (sum0);
1426 vlib_increment_simple_counter (&sm->counters.slowpath.in2out_ed.udp,
1427 thread_index, sw_if_index0, 1);
1431 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1433 new_port0 = udp0->src_port = s0->out2in.port;
1434 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1436 udp0->dst_port = s0->ext_host_port;
1437 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1439 vlib_increment_simple_counter (&sm->counters.slowpath.
1440 in2out_ed.udp, thread_index,
1446 nat44_session_update_counters (s0, now,
1447 vlib_buffer_length_in_chain
1448 (vm, b0), thread_index);
1449 /* Per-user LRU list maintenance */
1450 nat44_session_update_lru (sm, s0, thread_index);
1453 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1454 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1456 nat_in2out_ed_trace_t *t =
1457 vlib_add_trace (vm, node, b0, sizeof (*t));
1458 t->sw_if_index = sw_if_index0;
1459 t->next_index = next[0];
1460 t->is_slow_path = 1;
1463 t->session_index = s0 - tsm->sessions;
1465 t->session_index = ~0;
1468 if (next[0] == NAT_NEXT_DROP)
1470 vlib_increment_simple_counter (&sm->counters.slowpath.
1471 in2out_ed.drops, thread_index,
1480 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1483 return frame->n_vectors;
1486 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1487 vlib_node_runtime_t * node,
1488 vlib_frame_t * frame)
1490 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1494 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1495 .name = "nat44-ed-in2out",
1496 .vector_size = sizeof (u32),
1497 .sibling_of = "nat-default",
1498 .format_trace = format_nat_in2out_ed_trace,
1499 .type = VLIB_NODE_TYPE_INTERNAL,
1500 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1501 .error_strings = nat_in2out_ed_error_strings,
1502 .runtime_data_bytes = sizeof (snat_runtime_t),
1506 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1507 vlib_node_runtime_t * node,
1508 vlib_frame_t * frame)
1510 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1514 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1515 .name = "nat44-ed-in2out-output",
1516 .vector_size = sizeof (u32),
1517 .sibling_of = "nat-default",
1518 .format_trace = format_nat_in2out_ed_trace,
1519 .type = VLIB_NODE_TYPE_INTERNAL,
1520 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1521 .error_strings = nat_in2out_ed_error_strings,
1522 .runtime_data_bytes = sizeof (snat_runtime_t),
1526 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1527 vlib_node_runtime_t *
1528 node, vlib_frame_t * frame)
1530 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1534 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1535 .name = "nat44-ed-in2out-slowpath",
1536 .vector_size = sizeof (u32),
1537 .sibling_of = "nat-default",
1538 .format_trace = format_nat_in2out_ed_trace,
1539 .type = VLIB_NODE_TYPE_INTERNAL,
1540 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1541 .error_strings = nat_in2out_ed_error_strings,
1542 .runtime_data_bytes = sizeof (snat_runtime_t),
1546 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1549 vlib_frame_t * frame)
1551 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1555 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1556 .name = "nat44-ed-in2out-output-slowpath",
1557 .vector_size = sizeof (u32),
1558 .sibling_of = "nat-default",
1559 .format_trace = format_nat_in2out_ed_trace,
1560 .type = VLIB_NODE_TYPE_INTERNAL,
1561 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1562 .error_strings = nat_in2out_ed_error_strings,
1563 .runtime_data_bytes = sizeof (snat_runtime_t),
1568 format_nat_pre_trace (u8 * s, va_list * args)
1570 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1571 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1572 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1573 return format (s, "in2out next_index %d arc_next_index %d", t->next_index,
1577 VLIB_NODE_FN (nat_pre_in2out_node)
1578 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1580 return nat_pre_node_fn_inline (vm, node, frame,
1581 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1584 VLIB_NODE_FN (nat_pre_in2out_output_node)
1585 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1587 return nat_pre_node_fn_inline (vm, node, frame,
1588 NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH);
1592 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1593 .name = "nat-pre-in2out",
1594 .vector_size = sizeof (u32),
1595 .sibling_of = "nat-default",
1596 .format_trace = format_nat_pre_trace,
1597 .type = VLIB_NODE_TYPE_INTERNAL,
1601 VLIB_REGISTER_NODE (nat_pre_in2out_output_node) = {
1602 .name = "nat-pre-in2out-output",
1603 .vector_size = sizeof (u32),
1604 .sibling_of = "nat-default",
1605 .format_trace = format_nat_pre_trace,
1606 .type = VLIB_NODE_TYPE_INTERNAL,
1612 * fd.io coding-style-patch-verification: ON
1615 * eval: (c-set-style "gnu")