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/nat44/ed_inlines.h>
33 #include <nat/lib/nat_inlines.h>
35 /* number of attempts to get a port for ED overloading algorithm, if rolling
36 * a dice this many times doesn't produce a free port, it's treated
37 * as if there were no free ports available to conserve resources */
38 #define ED_PORT_ALLOC_ATTEMPTS (10)
40 static char *nat_in2out_ed_error_strings[] = {
41 #define _(sym,string) string,
42 foreach_nat_in2out_ed_error
51 nat_translation_error_e translation_error;
54 clib_bihash_kv_16_8_t search_key;
56 u8 translation_via_i2of;
58 } nat_in2out_ed_trace_t;
61 format_nat_in2out_ed_trace (u8 * s, va_list * args)
63 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
64 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
65 nat_in2out_ed_trace_t *t = va_arg (*args, nat_in2out_ed_trace_t *);
69 t->is_slow_path ? "NAT44_IN2OUT_ED_SLOW_PATH" :
70 "NAT44_IN2OUT_ED_FAST_PATH";
72 s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
73 t->sw_if_index, t->next_index, t->session_index);
74 if (~0 != t->session_index)
76 s = format (s, ", translation result '%U' via %s",
77 format_nat_ed_translation_error, t->translation_error,
78 t->translation_via_i2of ? "i2of" : "o2if");
79 s = format (s, "\n i2of %U", format_nat_6t_flow, &t->i2of);
80 s = format (s, "\n o2if %U", format_nat_6t_flow, &t->o2if);
84 if (t->lookup_skipped)
86 s = format (s, "\n lookup skipped - cached session index used");
90 s = format (s, "\n search key %U", format_ed_session_kvp,
99 nat_ed_alloc_addr_and_port (snat_main_t *sm, u32 rx_fib_index, u32 nat_proto,
100 u32 thread_index, ip4_address_t r_addr, u16 r_port,
101 u8 proto, u16 port_per_thread,
102 u32 snat_thread_index, snat_session_t *s,
103 ip4_address_t *outside_addr, u16 *outside_port)
106 snat_address_t *a, *ga = 0;
108 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
110 for (i = 0; i < vec_len (sm->addresses); i++)
112 a = sm->addresses + i;
115 #define _(N, j, n, unused) \
116 case NAT_PROTOCOL_##N: \
117 if (a->fib_index == rx_fib_index) \
119 s->o2i.match.daddr = a->addr; \
120 /* first try port suggested by caller */ \
121 u16 port = clib_net_to_host_u16 (*outside_port); \
122 u16 port_offset = port - port_thread_offset; \
123 if (port <= port_thread_offset || \
124 port > port_thread_offset + port_per_thread) \
126 /* need to pick a different port, suggested port doesn't fit in \
127 * this thread's port range */ \
128 port_offset = snat_random_port (0, port_per_thread - 1); \
129 port = port_thread_offset + port_offset; \
131 u16 attempts = ED_PORT_ALLOC_ATTEMPTS; \
134 if (NAT_PROTOCOL_ICMP == nat_proto) \
136 s->o2i.match.sport = clib_host_to_net_u16 (port); \
138 s->o2i.match.dport = clib_host_to_net_u16 (port); \
140 nat_ed_ses_o2i_flow_hash_add_del (sm, thread_index, s, 2)) \
142 ++a->busy_##n##_port_refcounts[port]; \
143 a->busy_##n##_ports_per_thread[thread_index]++; \
144 a->busy_##n##_ports++; \
145 *outside_addr = a->addr; \
146 *outside_port = clib_host_to_net_u16 (port); \
149 port_offset = snat_random_port (0, port_per_thread - 1); \
150 port = port_thread_offset + port_offset; \
153 while (attempts > 0); \
155 else if (a->fib_index == ~0) \
161 foreach_nat_protocol;
163 nat_elog_info ("unknown protocol");
170 /* fake fib_index to reuse macro */
175 foreach_nat_protocol;
177 nat_elog_info ("unknown protocol");
184 /* Totally out of translations to use... */
185 nat_ipfix_logging_addresses_exhausted (thread_index, 0);
189 static_always_inline u32
190 nat_outside_fib_index_lookup (snat_main_t * sm, ip4_address_t addr)
192 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
193 nat_outside_fib_t *outside_fib;
195 .fp_proto = FIB_PROTOCOL_IP4,
197 .fp_addr = {.ip4.as_u32 = addr.as_u32,}
200 // TODO: multiple vrfs none can resolve addr
202 vec_foreach (outside_fib, sm->outside_fibs)
204 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
205 if (FIB_NODE_INDEX_INVALID != fei)
207 if (fib_entry_get_resolving_interface (fei) != ~0)
209 return outside_fib->fib_index;
217 static_always_inline int
218 nat44_ed_external_sm_lookup (snat_main_t *sm, ip4_address_t match_addr,
219 u16 match_port, nat_protocol_t match_protocol,
220 u32 match_fib_index, ip4_address_t *daddr,
223 clib_bihash_kv_8_8_t kv, value;
224 init_nat_k (&kv, match_addr, match_port, match_fib_index, match_protocol);
225 if (clib_bihash_search_8_8 (&sm->static_mapping_by_external, &kv, &value))
227 /* Try address only mapping */
228 init_nat_k (&kv, match_addr, 0, 0, 0);
229 if (clib_bihash_search_8_8 (&sm->static_mapping_by_external, &kv,
234 snat_static_mapping_t *m =
235 pool_elt_at_index (sm->static_mappings, value.value);
236 *daddr = m->local_addr;
239 /* Address only mapping doesn't change port */
240 *dport = is_addr_only_static_mapping (m) ? match_port : m->local_port;
246 slow_path_ed (snat_main_t *sm, vlib_buffer_t *b, ip4_address_t l_addr,
247 ip4_address_t r_addr, u16 l_port, u16 r_port, u8 proto,
248 u32 rx_fib_index, snat_session_t **sessionp,
249 vlib_node_runtime_t *node, u32 next, u32 thread_index, f64 now)
251 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
252 ip4_address_t outside_addr;
254 u32 outside_fib_index;
257 u32 nat_proto = ip_proto_to_nat_proto (proto);
258 snat_session_t *s = NULL;
259 lb_nat_type_t lb = 0;
260 ip4_address_t daddr = r_addr;
263 if (PREDICT_TRUE (nat_proto == NAT_PROTOCOL_TCP))
267 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
269 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
270 return NAT_NEXT_DROP;
275 (nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
277 if (!nat_lru_free_one (sm, thread_index, now))
279 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
280 nat_ipfix_logging_max_sessions (thread_index,
281 sm->max_translations_per_thread);
282 nat_elog_notice ("maximum sessions exceeded");
283 return NAT_NEXT_DROP;
287 outside_fib_index = sm->outside_fib_index;
289 switch (vec_len (sm->outside_fibs))
292 outside_fib_index = sm->outside_fib_index;
295 outside_fib_index = sm->outside_fibs[0].fib_index;
298 outside_fib_index = nat_outside_fib_index_lookup (sm, r_addr);
302 ip4_address_t sm_addr;
305 /* First try to match static mapping by local address and port */
307 if (snat_static_mapping_match (sm, l_addr, l_port, rx_fib_index, nat_proto,
308 &sm_addr, &sm_port, &sm_fib_index, 0, 0, 0,
309 &lb, 0, &is_identity_nat, 0))
318 if (PREDICT_FALSE (is_sm && is_identity_nat))
324 s = nat_ed_session_alloc (sm, thread_index, now, proto);
329 s->in2out.addr = l_addr;
330 s->in2out.port = l_port;
331 s->nat_proto = nat_proto;
332 s->in2out.fib_index = rx_fib_index;
333 s->out2in.fib_index = outside_fib_index;
335 // suggest using local port to allocation function
336 outside_port = l_port;
339 int is_hairpinning = nat44_ed_external_sm_lookup (
340 sm, r_addr, r_port, nat_proto, outside_fib_index, &daddr, &dport);
341 s->flags |= is_hairpinning * SNAT_SESSION_FLAG_HAIRPINNING;
343 // destination addr/port updated with real values in
344 // nat_ed_alloc_addr_and_port
345 nat_6t_o2i_flow_init (sm, thread_index, s, daddr, dport, daddr, 0,
346 s->out2in.fib_index, proto);
347 nat_6t_flow_daddr_rewrite_set (&s->o2i, l_addr.as_u32);
348 if (NAT_PROTOCOL_ICMP == nat_proto)
350 nat_6t_flow_icmp_id_rewrite_set (&s->o2i, l_port);
354 nat_6t_flow_dport_rewrite_set (&s->o2i, l_port);
356 nat_6t_flow_txfib_rewrite_set (&s->o2i, rx_fib_index);
358 if (nat_ed_alloc_addr_and_port (
359 sm, rx_fib_index, nat_proto, thread_index, daddr, dport, proto,
360 sm->port_per_thread, tsm->snat_thread_index, s, &outside_addr,
363 nat_elog_notice ("addresses exhausted");
364 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
365 nat_ed_session_delete (sm, s, thread_index, 1);
366 return NAT_NEXT_DROP;
368 s->out2in.addr = outside_addr;
369 s->out2in.port = outside_port;
374 s->out2in.addr = outside_addr = sm_addr;
375 s->out2in.port = outside_port = sm_port;
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 = outside_fib_index;
381 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
384 int is_hairpinning = nat44_ed_external_sm_lookup (
385 sm, r_addr, r_port, nat_proto, outside_fib_index, &daddr, &dport);
386 s->flags |= is_hairpinning * SNAT_SESSION_FLAG_HAIRPINNING;
388 if (NAT_PROTOCOL_ICMP == nat_proto)
390 nat_6t_o2i_flow_init (sm, thread_index, s, daddr, sm_port, sm_addr,
391 sm_port, s->out2in.fib_index, proto);
392 nat_6t_flow_icmp_id_rewrite_set (&s->o2i, l_port);
396 nat_6t_o2i_flow_init (sm, thread_index, s, daddr, dport, sm_addr,
397 sm_port, s->out2in.fib_index, proto);
398 nat_6t_flow_dport_rewrite_set (&s->o2i, l_port);
400 nat_6t_flow_daddr_rewrite_set (&s->o2i, l_addr.as_u32);
401 nat_6t_flow_txfib_rewrite_set (&s->o2i, rx_fib_index);
402 if (nat_ed_ses_o2i_flow_hash_add_del (sm, thread_index, s, 2))
404 nat_elog_notice ("out2in key add failed");
410 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
411 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
412 s->ext_host_addr = r_addr;
413 s->ext_host_port = r_port;
415 nat_6t_i2o_flow_init (sm, thread_index, s, l_addr, l_port, r_addr, r_port,
416 rx_fib_index, proto);
417 nat_6t_flow_saddr_rewrite_set (&s->i2o, outside_addr.as_u32);
418 nat_6t_flow_daddr_rewrite_set (&s->i2o, daddr.as_u32);
419 if (NAT_PROTOCOL_ICMP == nat_proto)
421 nat_6t_flow_icmp_id_rewrite_set (&s->i2o, outside_port);
425 nat_6t_flow_sport_rewrite_set (&s->i2o, outside_port);
426 nat_6t_flow_dport_rewrite_set (&s->i2o, dport);
428 nat_6t_flow_txfib_rewrite_set (&s->i2o, outside_fib_index);
430 if (nat_ed_ses_i2o_flow_hash_add_del (sm, thread_index, s, 1))
432 nat_elog_notice ("in2out key add failed");
437 nat_ipfix_logging_nat44_ses_create (thread_index,
438 s->in2out.addr.as_u32,
439 s->out2in.addr.as_u32,
442 s->out2in.port, s->in2out.fib_index);
444 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
445 &s->in2out.addr, s->in2out.port,
446 &s->ext_host_nat_addr, s->ext_host_nat_port,
447 &s->out2in.addr, s->out2in.port,
448 &s->ext_host_addr, s->ext_host_port, s->nat_proto,
451 per_vrf_sessions_register_session (s, thread_index);
460 snat_free_outside_address_and_port (sm->addresses, thread_index,
461 &outside_addr, outside_port,
464 nat_ed_session_delete (sm, s, thread_index, 1);
466 *sessionp = s = NULL;
467 return NAT_NEXT_DROP;
470 static_always_inline int
471 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
472 u32 sw_if_index, ip4_header_t * ip, u32 proto,
473 u32 rx_fib_index, u32 thread_index)
475 udp_header_t *udp = ip4_next_header (ip);
476 clib_bihash_kv_16_8_t kv, value;
478 init_ed_k (&kv, ip->dst_address, udp->dst_port, ip->src_address,
479 udp->src_port, sm->outside_fib_index, ip->protocol);
481 /* NAT packet aimed at external address if has active sessions */
482 if (clib_bihash_search_16_8 (&sm->flow_hash, &kv, &value))
484 /* or is static mappings */
485 ip4_address_t placeholder_addr;
486 u16 placeholder_port;
487 u32 placeholder_fib_index;
488 if (!snat_static_mapping_match
489 (sm, ip->dst_address, udp->dst_port, sm->outside_fib_index, proto,
490 &placeholder_addr, &placeholder_port, &placeholder_fib_index, 1, 0,
497 if (sm->forwarding_enabled)
500 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
504 static_always_inline int
505 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
506 u32 thread_index, f64 now,
507 vlib_main_t * vm, vlib_buffer_t * b)
509 clib_bihash_kv_16_8_t kv, value;
510 snat_session_t *s = 0;
511 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
513 if (!sm->forwarding_enabled)
516 if (ip->protocol == IP_PROTOCOL_ICMP)
518 ip4_address_t lookup_saddr, lookup_daddr;
519 u16 lookup_sport, lookup_dport;
521 if (nat_get_icmp_session_lookup_values (b, ip, &lookup_saddr,
522 &lookup_sport, &lookup_daddr,
523 &lookup_dport, &lookup_protocol))
525 init_ed_k (&kv, lookup_saddr, lookup_sport, lookup_daddr, lookup_dport,
528 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
530 init_ed_k (&kv, ip->src_address, vnet_buffer (b)->ip.reass.l4_src_port,
531 ip->dst_address, vnet_buffer (b)->ip.reass.l4_dst_port, 0,
536 init_ed_k (&kv, ip->src_address, 0, ip->dst_address, 0, 0,
540 if (!clib_bihash_search_16_8 (&sm->flow_hash, &kv, &value))
542 ASSERT (thread_index == ed_value_get_thread_index (&value));
544 pool_elt_at_index (tsm->sessions,
545 ed_value_get_session_index (&value));
547 if (is_fwd_bypass_session (s))
549 if (ip->protocol == IP_PROTOCOL_TCP)
551 nat44_set_tcp_session_state_i2o (sm, now, s, b, thread_index);
554 nat44_session_update_counters (s, now,
555 vlib_buffer_length_in_chain (vm, b),
557 /* Per-user LRU list maintenance */
558 nat44_session_update_lru (sm, s, thread_index);
568 static_always_inline int
569 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
570 u16 src_port, u16 dst_port,
571 u32 thread_index, u32 rx_sw_if_index,
572 u32 tx_sw_if_index, f64 now)
574 clib_bihash_kv_16_8_t kv, value;
575 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
578 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
579 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
582 init_ed_k (&kv, ip->src_address, src_port, ip->dst_address, dst_port,
583 tx_fib_index, ip->protocol);
584 if (!clib_bihash_search_16_8 (&sm->flow_hash, &kv, &value))
586 ASSERT (thread_index == ed_value_get_thread_index (&value));
588 pool_elt_at_index (tsm->sessions,
589 ed_value_get_session_index (&value));
590 if (nat44_is_ses_closed (s)
591 && (!s->tcp_closed_timestamp || now >= s->tcp_closed_timestamp))
593 nat_free_session_data (sm, s, thread_index, 0);
594 nat_ed_session_delete (sm, s, thread_index, 1);
600 init_ed_k (&kv, ip->dst_address, dst_port, ip->src_address, src_port,
601 rx_fib_index, ip->protocol);
602 if (!clib_bihash_search_16_8 (&sm->flow_hash, &kv, &value))
604 ASSERT (thread_index == ed_value_get_thread_index (&value));
606 pool_elt_at_index (tsm->sessions,
607 ed_value_get_session_index (&value));
609 if (is_fwd_bypass_session (s))
614 pool_foreach (i, sm->output_feature_interfaces)
616 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
627 icmp_in2out_ed_slow_path (snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
628 icmp46_header_t *icmp, u32 sw_if_index,
629 u32 rx_fib_index, vlib_node_runtime_t *node,
630 u32 next, f64 now, u32 thread_index,
631 nat_protocol_t nat_proto, snat_session_t **s_p)
633 vlib_main_t *vm = vlib_get_main ();
636 snat_session_t *s = NULL;
637 u8 lookup_protocol = ip->protocol;
638 u16 lookup_sport, lookup_dport;
639 ip4_address_t lookup_saddr, lookup_daddr;
641 err = nat_get_icmp_session_lookup_values (b, ip, &lookup_saddr,
642 &lookup_sport, &lookup_daddr,
643 &lookup_dport, &lookup_protocol);
646 b->error = node->errors[err];
647 return NAT_NEXT_DROP;
650 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
652 if (PREDICT_FALSE (nat44_ed_not_translate_output_feature (
653 sm, ip, lookup_sport, lookup_dport, thread_index, sw_if_index,
654 vnet_buffer (b)->sw_if_index[VLIB_TX], now)))
661 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index, ip,
663 rx_fib_index, thread_index)))
669 if (PREDICT_FALSE (icmp_type_is_error_message (
670 vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
672 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
673 return NAT_NEXT_DROP;
676 next = slow_path_ed (sm, b, ip->src_address, ip->dst_address, lookup_sport,
677 lookup_dport, ip->protocol, rx_fib_index, &s, node,
678 next, thread_index, vlib_time_now (vm));
680 if (NAT_NEXT_DROP == next)
683 if (PREDICT_TRUE (!ip4_is_fragment (ip)))
685 ip_csum_t sum = ip_incremental_checksum_buffer (
686 vm, b, (u8 *) icmp - (u8 *) vlib_buffer_get_current (b),
687 ntohs (ip->length) - ip4_header_bytes (ip), 0);
688 checksum = ~ip_csum_fold (sum);
689 if (PREDICT_FALSE (checksum != 0 && checksum != 0xffff))
691 next = NAT_NEXT_DROP;
697 if (PREDICT_TRUE (next != NAT_NEXT_DROP && s))
700 nat44_session_update_counters (
701 s, now, vlib_buffer_length_in_chain (vm, b), thread_index);
702 /* Per-user LRU list maintenance */
703 nat44_session_update_lru (sm, s, thread_index);
709 static snat_session_t *
710 nat44_ed_in2out_slowpath_unknown_proto (snat_main_t *sm, vlib_buffer_t *b,
711 ip4_header_t *ip, u32 rx_fib_index,
712 u32 thread_index, f64 now,
714 vlib_node_runtime_t *node)
716 clib_bihash_kv_8_8_t kv, value;
717 clib_bihash_kv_16_8_t s_kv, s_value;
718 snat_static_mapping_t *m = NULL;
719 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
720 snat_session_t *s = NULL;
721 u32 outside_fib_index = sm->outside_fib_index;
723 ip4_address_t new_src_addr = { 0 };
724 ip4_address_t new_dst_addr = ip->dst_address;
727 nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
729 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
730 nat_ipfix_logging_max_sessions (thread_index,
731 sm->max_translations_per_thread);
732 nat_elog_notice ("maximum sessions exceeded");
736 switch (vec_len (sm->outside_fibs))
739 outside_fib_index = sm->outside_fib_index;
742 outside_fib_index = sm->outside_fibs[0].fib_index;
745 outside_fib_index = nat_outside_fib_index_lookup (sm, ip->dst_address);
749 init_nat_k (&kv, ip->src_address, 0, rx_fib_index, 0);
751 /* Try to find static mapping first */
752 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
754 m = pool_elt_at_index (sm->static_mappings, value.value);
755 new_src_addr = m->external_addr;
759 pool_foreach (s, tsm->sessions)
761 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
763 init_ed_k (&s_kv, s->out2in.addr, 0, ip->dst_address, 0,
764 outside_fib_index, ip->protocol);
765 if (clib_bihash_search_16_8 (&sm->flow_hash, &s_kv, &s_value))
767 new_src_addr = s->out2in.addr;
773 if (!new_src_addr.as_u32)
775 for (i = 0; i < vec_len (sm->addresses); i++)
777 init_ed_k (&s_kv, sm->addresses[i].addr, 0, ip->dst_address, 0,
778 outside_fib_index, ip->protocol);
779 if (clib_bihash_search_16_8 (&sm->flow_hash, &s_kv, &s_value))
781 new_src_addr = sm->addresses[i].addr;
787 if (!new_src_addr.as_u32)
789 // could not allocate address for translation ...
793 s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
796 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
797 nat_elog_warn ("create NAT session failed");
801 nat_6t_i2o_flow_init (sm, thread_index, s, ip->src_address, 0,
802 ip->dst_address, 0, rx_fib_index, ip->protocol);
803 nat_6t_flow_saddr_rewrite_set (&s->i2o, new_src_addr.as_u32);
804 nat_6t_flow_txfib_rewrite_set (&s->i2o, outside_fib_index);
808 nat44_ed_external_sm_lookup (sm, ip->dst_address, 0, NAT_PROTOCOL_OTHER,
809 outside_fib_index, &new_dst_addr, NULL);
810 s->flags |= is_hairpinning * SNAT_SESSION_FLAG_HAIRPINNING;
812 nat_6t_flow_daddr_rewrite_set (&s->i2o, new_dst_addr.as_u32);
813 nat_6t_flow_txfib_rewrite_set (&s->i2o, outside_fib_index);
815 nat_6t_o2i_flow_init (sm, thread_index, s, new_dst_addr, 0, new_src_addr, 0,
816 outside_fib_index, ip->protocol);
817 nat_6t_flow_saddr_rewrite_set (&s->o2i, ip->dst_address.as_u32);
818 nat_6t_flow_daddr_rewrite_set (&s->o2i, ip->src_address.as_u32);
819 nat_6t_flow_txfib_rewrite_set (&s->o2i, rx_fib_index);
821 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
822 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
823 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
824 s->out2in.addr.as_u32 = new_src_addr.as_u32;
825 s->out2in.fib_index = outside_fib_index;
826 s->in2out.addr.as_u32 = ip->src_address.as_u32;
827 s->in2out.fib_index = rx_fib_index;
828 s->in2out.port = s->out2in.port = ip->protocol;
830 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
832 if (nat_ed_ses_i2o_flow_hash_add_del (sm, thread_index, s, 1))
834 nat_elog_notice ("in2out flow hash add failed");
835 nat_ed_session_delete (sm, s, thread_index, 1);
839 if (nat_ed_ses_o2i_flow_hash_add_del (sm, thread_index, s, 1))
841 nat_elog_notice ("out2in flow hash add failed");
842 nat_ed_session_delete (sm, s, thread_index, 1);
846 per_vrf_sessions_register_session (s, thread_index);
849 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
851 /* Per-user LRU list maintenance */
852 nat44_session_update_lru (sm, s, thread_index);
858 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
859 vlib_node_runtime_t * node,
860 vlib_frame_t * frame,
861 int is_output_feature)
863 u32 n_left_from, *from;
864 snat_main_t *sm = &snat_main;
865 f64 now = vlib_time_now (vm);
866 u32 thread_index = vm->thread_index;
867 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
868 u32 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH
869 : NAT_NEXT_IN2OUT_ED_SLOW_PATH;
871 from = vlib_frame_vector_args (frame);
872 n_left_from = frame->n_vectors;
874 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
875 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
876 vlib_get_buffers (vm, from, b, n_left_from);
878 while (n_left_from > 0)
881 u32 sw_if_index0, rx_fib_index0, iph_offset0 = 0;
882 nat_protocol_t proto0;
884 snat_session_t *s0 = 0;
885 clib_bihash_kv_16_8_t kv0, value0;
886 nat_translation_error_e translation_error = NAT_ED_TRNSL_ERR_SUCCESS;
887 nat_6t_flow_t *f = 0;
888 ip4_address_t lookup_saddr, lookup_daddr;
889 u16 lookup_sport, lookup_dport;
891 int lookup_skipped = 0;
896 /* Prefetch next iteration. */
897 if (PREDICT_TRUE (n_left_from >= 2))
903 vlib_prefetch_buffer_header (p2, LOAD);
905 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
908 if (is_output_feature)
910 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
913 next[0] = vnet_buffer2 (b0)->nat.arc_next;
916 (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) + iph_offset0);
918 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
920 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
922 if (PREDICT_FALSE (ip0->ttl == 1))
924 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
925 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
926 ICMP4_time_exceeded_ttl_exceeded_in_transit,
928 next[0] = NAT_NEXT_ICMP_ERROR;
932 proto0 = ip_proto_to_nat_proto (ip0->protocol);
934 if (is_output_feature)
937 (nat_not_translate_output_feature_fwd
938 (sm, ip0, thread_index, now, vm, b0)))
942 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
944 if (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags !=
945 ICMP4_echo_request &&
946 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags !=
948 !icmp_type_is_error_message (
949 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags))
951 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
952 next[0] = NAT_NEXT_DROP;
955 int err = nat_get_icmp_session_lookup_values (
956 b0, ip0, &lookup_saddr, &lookup_sport, &lookup_daddr,
957 &lookup_dport, &lookup_protocol);
960 b0->error = node->errors[err];
961 next[0] = NAT_NEXT_DROP;
967 lookup_protocol = ip0->protocol;
968 lookup_saddr = ip0->src_address;
969 lookup_daddr = ip0->dst_address;
970 lookup_sport = vnet_buffer (b0)->ip.reass.l4_src_port;
971 lookup_dport = vnet_buffer (b0)->ip.reass.l4_dst_port;
974 /* there might be a stashed index in vnet_buffer2 from handoff or
975 * classify node, see if it can be used */
976 if (!pool_is_free_index (tsm->sessions,
977 vnet_buffer2 (b0)->nat.cached_session_index))
979 s0 = pool_elt_at_index (tsm->sessions,
980 vnet_buffer2 (b0)->nat.cached_session_index);
982 nat_6t_flow_match (&s0->i2o, b0, lookup_saddr, lookup_sport,
983 lookup_daddr, lookup_dport, lookup_protocol,
985 // for some hairpinning cases there are two "i2i" flows instead
986 // of i2o and o2i as both hosts are on inside
987 || (s0->flags & SNAT_SESSION_FLAG_HAIRPINNING &&
989 &s0->o2i, b0, lookup_saddr, lookup_sport, lookup_daddr,
990 lookup_dport, lookup_protocol, rx_fib_index0))))
992 /* yes, this is the droid we're looking for */
999 init_ed_k (&kv0, ip0->src_address, lookup_sport, ip0->dst_address,
1000 lookup_dport, rx_fib_index0, lookup_protocol);
1003 if (clib_bihash_search_16_8 (&sm->flow_hash, &kv0, &value0))
1005 // flow does not exist go slow path
1010 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1012 pool_elt_at_index (tsm->sessions,
1013 ed_value_get_session_index (&value0));
1017 if (PREDICT_FALSE (per_vrf_sessions_is_expired (s0, thread_index)))
1019 // session is closed, go slow path
1020 nat_free_session_data (sm, s0, thread_index, 0);
1021 nat_ed_session_delete (sm, s0, thread_index, 1);
1022 next[0] = NAT_NEXT_OUT2IN_ED_SLOW_PATH;
1026 if (s0->tcp_closed_timestamp)
1028 if (now >= s0->tcp_closed_timestamp)
1030 // session is closed, go slow path, freed in 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 (nat_6t_flow_match (&s0->i2o, b0, lookup_saddr, lookup_sport,
1058 lookup_daddr, lookup_dport, lookup_protocol,
1063 else if (s0->flags & SNAT_SESSION_FLAG_HAIRPINNING &&
1064 nat_6t_flow_match (&s0->o2i, b0, lookup_saddr, lookup_sport,
1065 lookup_daddr, lookup_dport, lookup_protocol,
1072 translation_error = NAT_ED_TRNSL_ERR_FLOW_MISMATCH;
1073 nat_free_session_data (sm, s0, thread_index, 0);
1074 nat_ed_session_delete (sm, s0, thread_index, 1);
1075 next[0] = NAT_NEXT_DROP;
1079 if (NAT_ED_TRNSL_ERR_SUCCESS !=
1080 (translation_error = nat_6t_flow_buf_translate (
1081 sm, b0, ip0, f, proto0, is_output_feature)))
1083 nat_free_session_data (sm, s0, thread_index, 0);
1084 nat_ed_session_delete (sm, s0, thread_index, 1);
1085 next[0] = NAT_NEXT_DROP;
1091 case NAT_PROTOCOL_TCP:
1092 vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.tcp,
1093 thread_index, sw_if_index0, 1);
1094 nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index);
1096 case NAT_PROTOCOL_UDP:
1097 vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.udp,
1098 thread_index, sw_if_index0, 1);
1100 case NAT_PROTOCOL_ICMP:
1101 vlib_increment_simple_counter (&sm->counters.fastpath.in2out_ed.icmp,
1102 thread_index, sw_if_index0, 1);
1104 case NAT_PROTOCOL_OTHER:
1105 vlib_increment_simple_counter (
1106 &sm->counters.fastpath.in2out_ed.other, thread_index, sw_if_index0,
1112 nat44_session_update_counters (s0, now,
1113 vlib_buffer_length_in_chain (vm, b0),
1115 /* Per-user LRU list maintenance */
1116 nat44_session_update_lru (sm, s0, thread_index);
1120 ((node->flags & VLIB_NODE_FLAG_TRACE)
1121 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1123 nat_in2out_ed_trace_t *t =
1124 vlib_add_trace (vm, node, b0, sizeof (*t));
1125 t->sw_if_index = sw_if_index0;
1126 t->next_index = next[0];
1127 t->is_slow_path = 0;
1128 t->translation_error = translation_error;
1129 t->lookup_skipped = lookup_skipped;
1130 clib_memcpy (&t->search_key, &kv0, sizeof (t->search_key));
1134 t->session_index = s0 - tsm->sessions;
1135 clib_memcpy (&t->i2of, &s0->i2o, sizeof (t->i2of));
1136 clib_memcpy (&t->o2if, &s0->o2i, sizeof (t->o2if));
1137 t->translation_via_i2of = (&s0->i2o == f);
1141 t->session_index = ~0;
1145 if (next[0] == NAT_NEXT_DROP)
1147 vlib_increment_simple_counter (&sm->counters.fastpath.
1148 in2out_ed.drops, thread_index,
1156 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1158 return frame->n_vectors;
1162 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1163 vlib_node_runtime_t * node,
1164 vlib_frame_t * frame,
1165 int is_output_feature)
1167 u32 n_left_from, *from;
1168 snat_main_t *sm = &snat_main;
1169 f64 now = vlib_time_now (vm);
1170 u32 thread_index = vm->thread_index;
1171 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1173 from = vlib_frame_vector_args (frame);
1174 n_left_from = frame->n_vectors;
1176 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1177 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1178 vlib_get_buffers (vm, from, b, n_left_from);
1180 while (n_left_from > 0)
1183 u32 sw_if_index0, rx_fib_index0, iph_offset0 = 0;
1184 nat_protocol_t proto0;
1187 icmp46_header_t *icmp0;
1188 snat_session_t *s0 = 0;
1189 clib_bihash_kv_16_8_t kv0, value0;
1190 int translation_error = NAT_ED_TRNSL_ERR_SUCCESS;
1194 if (is_output_feature)
1195 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1197 next[0] = vnet_buffer2 (b0)->nat.arc_next;
1199 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1202 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1204 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, sw_if_index0);
1206 if (PREDICT_FALSE (ip0->ttl == 1))
1208 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1209 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1210 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1212 next[0] = NAT_NEXT_ICMP_ERROR;
1216 udp0 = ip4_next_header (ip0);
1217 icmp0 = (icmp46_header_t *) udp0;
1218 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1220 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1222 s0 = nat44_ed_in2out_slowpath_unknown_proto (
1223 sm, b0, ip0, rx_fib_index0, thread_index, now, vm, node);
1225 next[0] = NAT_NEXT_DROP;
1227 if (NAT_ED_TRNSL_ERR_SUCCESS !=
1228 (translation_error = nat_6t_flow_buf_translate (
1229 sm, b0, ip0, &s0->i2o, proto0, is_output_feature)))
1234 vlib_increment_simple_counter (&sm->counters.slowpath.
1235 in2out_ed.other, thread_index,
1240 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1242 next[0] = icmp_in2out_ed_slow_path (sm, b0, ip0, icmp0, sw_if_index0,
1243 rx_fib_index0, node, next[0],
1244 now, thread_index, proto0, &s0);
1245 if (NAT_NEXT_DROP != next[0] && s0 &&
1246 NAT_ED_TRNSL_ERR_SUCCESS !=
1247 (translation_error = nat_6t_flow_buf_translate (
1248 sm, b0, ip0, &s0->i2o, proto0, is_output_feature)))
1253 vlib_increment_simple_counter (&sm->counters.slowpath.
1254 in2out_ed.icmp, thread_index,
1259 init_ed_k (&kv0, ip0->src_address,
1260 vnet_buffer (b0)->ip.reass.l4_src_port, ip0->dst_address,
1261 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1263 if (!clib_bihash_search_16_8 (&sm->flow_hash, &kv0, &value0))
1265 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1267 pool_elt_at_index (tsm->sessions,
1268 ed_value_get_session_index (&value0));
1270 if (s0->tcp_closed_timestamp && now >= s0->tcp_closed_timestamp)
1272 nat_free_session_data (sm, s0, thread_index, 0);
1273 nat_ed_session_delete (sm, s0, thread_index, 1);
1280 if (is_output_feature)
1283 (nat44_ed_not_translate_output_feature
1284 (sm, ip0, vnet_buffer (b0)->ip.reass.l4_src_port,
1285 vnet_buffer (b0)->ip.reass.l4_dst_port, thread_index,
1286 sw_if_index0, vnet_buffer (b0)->sw_if_index[VLIB_TX],
1291 * Send DHCP packets to the ipv4 stack, or we won't
1292 * be able to use dhcp client on the outside interface
1295 (proto0 == NAT_PROTOCOL_UDP
1296 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1297 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1298 && ip0->dst_address.as_u32 == 0xffffffff))
1304 (nat44_ed_not_translate
1305 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1311 slow_path_ed (sm, b0, ip0->src_address, ip0->dst_address,
1312 vnet_buffer (b0)->ip.reass.l4_src_port,
1313 vnet_buffer (b0)->ip.reass.l4_dst_port,
1314 ip0->protocol, rx_fib_index0, &s0, node, next[0],
1317 if (PREDICT_FALSE (next[0] == NAT_NEXT_DROP))
1320 if (PREDICT_FALSE (!s0))
1325 b0->flags |= VNET_BUFFER_F_IS_NATED;
1327 if (NAT_ED_TRNSL_ERR_SUCCESS !=
1328 (translation_error = nat_6t_flow_buf_translate (
1329 sm, b0, ip0, &s0->i2o, proto0, is_output_feature)))
1331 nat_free_session_data (sm, s0, thread_index, 0);
1332 nat_ed_session_delete (sm, s0, thread_index, 1);
1337 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1339 vlib_increment_simple_counter (&sm->counters.slowpath.in2out_ed.tcp,
1340 thread_index, sw_if_index0, 1);
1341 nat44_set_tcp_session_state_i2o (sm, now, s0, b0, thread_index);
1345 vlib_increment_simple_counter (&sm->counters.slowpath.in2out_ed.udp,
1346 thread_index, sw_if_index0, 1);
1350 nat44_session_update_counters (s0, now,
1351 vlib_buffer_length_in_chain
1352 (vm, b0), thread_index);
1353 /* Per-user LRU list maintenance */
1354 nat44_session_update_lru (sm, s0, thread_index);
1357 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1358 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1360 nat_in2out_ed_trace_t *t =
1361 vlib_add_trace (vm, node, b0, sizeof (*t));
1362 t->sw_if_index = sw_if_index0;
1363 t->next_index = next[0];
1364 t->is_slow_path = 1;
1365 t->translation_error = translation_error;
1366 clib_memcpy (&t->search_key, &kv0, sizeof (t->search_key));
1370 t->session_index = s0 - tsm->sessions;
1371 clib_memcpy (&t->i2of, &s0->i2o, sizeof (t->i2of));
1372 clib_memcpy (&t->o2if, &s0->o2i, sizeof (t->o2if));
1373 t->translation_via_i2of = 1;
1378 t->session_index = ~0;
1382 if (next[0] == NAT_NEXT_DROP)
1384 vlib_increment_simple_counter (&sm->counters.slowpath.
1385 in2out_ed.drops, thread_index,
1394 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1397 return frame->n_vectors;
1400 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1401 vlib_node_runtime_t * node,
1402 vlib_frame_t * frame)
1404 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1408 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1409 .name = "nat44-ed-in2out",
1410 .vector_size = sizeof (u32),
1411 .sibling_of = "nat-default",
1412 .format_trace = format_nat_in2out_ed_trace,
1413 .type = VLIB_NODE_TYPE_INTERNAL,
1414 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1415 .error_strings = nat_in2out_ed_error_strings,
1416 .runtime_data_bytes = sizeof (snat_runtime_t),
1420 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1421 vlib_node_runtime_t * node,
1422 vlib_frame_t * frame)
1424 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1428 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1429 .name = "nat44-ed-in2out-output",
1430 .vector_size = sizeof (u32),
1431 .sibling_of = "nat-default",
1432 .format_trace = format_nat_in2out_ed_trace,
1433 .type = VLIB_NODE_TYPE_INTERNAL,
1434 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1435 .error_strings = nat_in2out_ed_error_strings,
1436 .runtime_data_bytes = sizeof (snat_runtime_t),
1440 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1441 vlib_node_runtime_t *
1442 node, vlib_frame_t * frame)
1444 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1448 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1449 .name = "nat44-ed-in2out-slowpath",
1450 .vector_size = sizeof (u32),
1451 .sibling_of = "nat-default",
1452 .format_trace = format_nat_in2out_ed_trace,
1453 .type = VLIB_NODE_TYPE_INTERNAL,
1454 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1455 .error_strings = nat_in2out_ed_error_strings,
1456 .runtime_data_bytes = sizeof (snat_runtime_t),
1460 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1463 vlib_frame_t * frame)
1465 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1469 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1470 .name = "nat44-ed-in2out-output-slowpath",
1471 .vector_size = sizeof (u32),
1472 .sibling_of = "nat-default",
1473 .format_trace = format_nat_in2out_ed_trace,
1474 .type = VLIB_NODE_TYPE_INTERNAL,
1475 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1476 .error_strings = nat_in2out_ed_error_strings,
1477 .runtime_data_bytes = sizeof (snat_runtime_t),
1482 format_nat_pre_trace (u8 * s, va_list * args)
1484 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1485 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1486 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1487 return format (s, "in2out next_index %d arc_next_index %d", t->next_index,
1491 VLIB_NODE_FN (nat_pre_in2out_node)
1492 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1494 return nat_pre_node_fn_inline (vm, node, frame,
1495 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1498 VLIB_NODE_FN (nat_pre_in2out_output_node)
1499 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1501 return nat_pre_node_fn_inline (vm, node, frame,
1502 NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH);
1506 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1507 .name = "nat-pre-in2out",
1508 .vector_size = sizeof (u32),
1509 .sibling_of = "nat-default",
1510 .format_trace = format_nat_pre_trace,
1511 .type = VLIB_NODE_TYPE_INTERNAL,
1515 VLIB_REGISTER_NODE (nat_pre_in2out_output_node) = {
1516 .name = "nat-pre-in2out-output",
1517 .vector_size = sizeof (u32),
1518 .sibling_of = "nat-default",
1519 .format_trace = format_nat_pre_trace,
1520 .type = VLIB_NODE_TYPE_INTERNAL,
1526 * fd.io coding-style-patch-verification: ON
1529 * eval: (c-set-style "gnu")