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>
35 static char *nat_in2out_ed_error_strings[] = {
36 #define _(sym,string) string,
37 foreach_nat_in2out_ed_error
47 } nat_in2out_ed_trace_t;
50 format_nat_in2out_ed_trace (u8 * s, va_list * args)
52 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
53 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
54 nat_in2out_ed_trace_t *t = va_arg (*args, nat_in2out_ed_trace_t *);
58 t->is_slow_path ? "NAT44_IN2OUT_ED_SLOW_PATH" :
59 "NAT44_IN2OUT_ED_FAST_PATH";
61 s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
62 t->sw_if_index, t->next_index, t->session_index);
67 #ifndef CLIB_MARCH_VARIANT
69 nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void *arg)
71 snat_main_t *sm = &snat_main;
72 nat44_is_idle_session_ctx_t *ctx = arg;
74 u64 sess_timeout_time;
75 nat_ed_ses_key_t ed_key;
76 clib_bihash_kv_16_8_t ed_kv;
79 snat_session_key_t key;
80 snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
83 s = pool_elt_at_index (tsm->sessions, kv->value);
84 sess_timeout_time = s->last_heard + (f64) nat44_session_get_timeout (sm, s);
85 if (ctx->now >= sess_timeout_time)
87 if (is_fwd_bypass_session (s))
90 ed_key.l_addr = s->out2in.addr;
91 ed_key.r_addr = s->ext_host_addr;
92 ed_key.fib_index = s->out2in.fib_index;
93 if (snat_is_unk_proto_session (s))
95 ed_key.proto = s->in2out.port;
101 ed_key.proto = snat_proto_to_ip_proto (s->in2out.protocol);
102 ed_key.l_port = s->out2in.port;
103 ed_key.r_port = s->ext_host_port;
105 ed_kv.key[0] = ed_key.as_u64[0];
106 ed_kv.key[1] = ed_key.as_u64[1];
107 if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &ed_kv, 0))
108 nat_elog_warn ("out2in_ed key del failed");
110 if (snat_is_unk_proto_session (s))
113 snat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
114 s->in2out.addr.as_u32,
115 s->out2in.addr.as_u32,
119 s->in2out.fib_index);
121 nat_syslog_nat44_sdel (s->user_index, s->in2out.fib_index,
122 &s->in2out.addr, s->in2out.port,
123 &s->ext_host_nat_addr, s->ext_host_nat_port,
124 &s->out2in.addr, s->out2in.port,
125 &s->ext_host_addr, s->ext_host_port,
126 s->in2out.protocol, is_twice_nat_session (s));
128 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
129 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
132 if (is_twice_nat_session (s))
134 for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
136 key.protocol = s->in2out.protocol;
137 key.port = s->ext_host_nat_port;
138 a = sm->twice_nat_addresses + i;
139 if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
141 snat_free_outside_address_and_port (sm->twice_nat_addresses,
149 if (snat_is_session_static (s))
152 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
155 nat44_delete_session (sm, s, ctx->thread_index);
164 icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
165 ip4_header_t * ip0, icmp46_header_t * icmp0,
166 u32 sw_if_index0, u32 rx_fib_index0,
167 vlib_node_runtime_t * node, u32 next0, f64 now,
168 u32 thread_index, snat_session_t ** p_s0)
170 next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
171 next0, thread_index, p_s0, 0);
172 snat_session_t *s0 = *p_s0;
173 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
176 nat44_session_update_counters (s0, now,
177 vlib_buffer_length_in_chain
178 (sm->vlib_main, b0), thread_index);
179 /* Per-user LRU list maintenance */
180 nat44_session_update_lru (sm, s0, thread_index);
186 slow_path_ed (snat_main_t * sm,
189 clib_bihash_kv_16_8_t * kv,
190 snat_session_t ** sessionp,
191 vlib_node_runtime_t * node, u32 next, u32 thread_index, f64 now)
193 snat_session_t *s = 0;
195 snat_session_key_t key0, key1;
196 lb_nat_type_t lb = 0, is_sm = 0;
197 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
198 nat_ed_ses_key_t *key = (nat_ed_ses_key_t *) kv->key;
199 u32 proto = ip_proto_to_snat_proto (key->proto);
200 nat_outside_fib_t *outside_fib;
201 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
204 .fp_proto = FIB_PROTOCOL_IP4,
207 .ip4.as_u32 = key->r_addr.as_u32,
210 nat44_is_idle_session_ctx_t ctx;
214 if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
217 (!(cleared = nat44_users_cleanup (thread_index, now))))
219 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
220 nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
221 nat_elog_notice ("maximum sessions exceeded");
222 return NAT_NEXT_DROP;
226 key0.addr = key->l_addr;
227 key0.port = key->l_port;
228 key1.protocol = key0.protocol = proto;
229 key0.fib_index = rx_fib_index;
230 key1.fib_index = sm->outside_fib_index;
232 /* First try to match static mapping by local address and port */
233 if (snat_static_mapping_match
234 (sm, key0, &key1, 0, 0, 0, &lb, 0, &identity_nat))
236 /* Try to create dynamic translation */
237 if (snat_alloc_outside_address_and_port (sm->addresses, rx_fib_index,
240 tsm->snat_thread_index))
242 if (cleared || !nat44_out_of_ports_cleanup (thread_index, now) ||
243 snat_alloc_outside_address_and_port (sm->addresses,
244 rx_fib_index, thread_index,
245 &key1, sm->port_per_thread,
246 tsm->snat_thread_index))
248 nat_elog_notice ("addresses exhausted");
249 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
250 return NAT_NEXT_DROP;
256 if (PREDICT_FALSE (identity_nat))
264 if (PREDICT_TRUE (proto == SNAT_PROTOCOL_TCP))
268 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
270 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
272 snat_free_outside_address_and_port (sm->addresses,
273 thread_index, &key1);
274 return NAT_NEXT_DROP;
278 u = nat_user_get_or_create (sm, &key->l_addr, rx_fib_index, thread_index);
281 nat_elog_warn ("create NAT user failed");
283 snat_free_outside_address_and_port (sm->addresses,
284 thread_index, &key1);
285 b->error = node->errors[NAT_IN2OUT_ED_ERROR_CANNOT_CREATE_USER];
286 return NAT_NEXT_DROP;
289 s = nat_ed_session_alloc (sm, u, thread_index, now);
292 nat44_delete_user_with_no_session (sm, u, thread_index);
293 nat_elog_warn ("create NAT session failed");
295 snat_free_outside_address_and_port (sm->addresses,
296 thread_index, &key1);
297 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
298 return NAT_NEXT_DROP;
301 user_session_increment (sm, u, is_sm);
303 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
305 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
306 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
307 s->ext_host_addr = key->r_addr;
308 s->ext_host_port = key->r_port;
311 s->out2in.protocol = key0.protocol;
313 switch (vec_len (sm->outside_fibs))
316 s->out2in.fib_index = sm->outside_fib_index;
319 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
323 vec_foreach (outside_fib, sm->outside_fibs)
325 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
326 if (FIB_NODE_INDEX_INVALID != fei)
328 if (fib_entry_get_resolving_interface (fei) != ~0)
330 s->out2in.fib_index = outside_fib->fib_index;
339 /* Add to lookup tables */
340 kv->value = s - tsm->sessions;
342 ctx.thread_index = thread_index;
343 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, kv,
344 nat44_i2o_ed_is_idle_session_cb,
346 nat_elog_notice ("in2out-ed key add failed");
348 make_ed_kv (kv, &key1.addr, &key->r_addr, key->proto, s->out2in.fib_index,
349 key1.port, key->r_port);
350 kv->value = s - tsm->sessions;
351 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->out2in_ed, kv,
352 nat44_o2i_ed_is_idle_session_cb,
354 nat_elog_notice ("out2in-ed key add failed");
359 snat_ipfix_logging_nat44_ses_create (thread_index,
360 s->in2out.addr.as_u32,
361 s->out2in.addr.as_u32,
364 s->out2in.port, s->in2out.fib_index);
366 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
367 &s->in2out.addr, s->in2out.port,
368 &s->ext_host_nat_addr, s->ext_host_nat_port,
369 &s->out2in.addr, s->out2in.port,
370 &s->ext_host_addr, s->ext_host_port,
371 s->in2out.protocol, 0);
373 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
374 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
375 &s->ext_host_nat_addr, s->ext_host_nat_port,
376 s->in2out.protocol, s->in2out.fib_index, s->flags,
382 static_always_inline int
383 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
384 u32 sw_if_index, ip4_header_t * ip, u32 proto,
385 u32 rx_fib_index, u32 thread_index)
387 udp_header_t *udp = ip4_next_header (ip);
388 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
389 clib_bihash_kv_16_8_t kv, value;
390 snat_session_key_t key0, key1;
392 make_ed_kv (&kv, &ip->dst_address, &ip->src_address, ip->protocol,
393 sm->outside_fib_index, udp->dst_port, udp->src_port);
395 /* NAT packet aimed at external address if */
396 /* has active sessions */
397 if (clib_bihash_search_16_8 (&tsm->out2in_ed, &kv, &value))
399 key0.addr = ip->dst_address;
400 key0.port = udp->dst_port;
401 key0.protocol = proto;
402 key0.fib_index = sm->outside_fib_index;
403 /* or is static mappings */
404 if (!snat_static_mapping_match (sm, key0, &key1, 1, 0, 0, 0, 0, 0))
410 if (sm->forwarding_enabled)
413 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
417 static_always_inline int
418 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
419 u32 thread_index, f64 now,
420 vlib_main_t * vm, vlib_buffer_t * b)
422 nat_ed_ses_key_t key;
423 clib_bihash_kv_16_8_t kv, value;
424 snat_session_t *s = 0;
425 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
427 if (!sm->forwarding_enabled)
430 if (ip->protocol == IP_PROTOCOL_ICMP)
432 key.as_u64[0] = key.as_u64[1] = 0;
433 if (get_icmp_i2o_ed_key (b, ip, &key))
436 kv.key[0] = key.as_u64[0];
437 kv.key[1] = key.as_u64[1];
439 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
441 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, ip->protocol, 0,
442 vnet_buffer (b)->ip.reass.l4_src_port,
443 vnet_buffer (b)->ip.reass.l4_dst_port);
447 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, ip->protocol, 0, 0,
451 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
453 s = pool_elt_at_index (tsm->sessions, value.value);
454 if (is_fwd_bypass_session (s))
456 if (ip->protocol == IP_PROTOCOL_TCP)
458 if (nat44_set_tcp_session_state_i2o (sm, s, b, thread_index))
462 nat44_session_update_counters (s, now,
463 vlib_buffer_length_in_chain (vm, b),
465 /* Per-user LRU list maintenance */
466 nat44_session_update_lru (sm, s, thread_index);
476 static_always_inline int
477 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
478 u8 proto, u16 src_port, u16 dst_port,
479 u32 thread_index, u32 rx_sw_if_index,
482 clib_bihash_kv_16_8_t kv, value;
483 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
486 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
487 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
490 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, proto, tx_fib_index,
492 if (!clib_bihash_search_16_8 (&tsm->out2in_ed, &kv, &value))
494 s = pool_elt_at_index (tsm->sessions, value.value);
495 if (nat44_is_ses_closed (s))
497 nat_free_session_data (sm, s, thread_index, 0);
498 nat44_delete_session (sm, s, thread_index);
501 s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
506 make_ed_kv (&kv, &ip->dst_address, &ip->src_address, proto, rx_fib_index,
508 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
510 s = pool_elt_at_index (tsm->sessions, value.value);
511 if (is_fwd_bypass_session (s))
516 pool_foreach (i, sm->output_feature_interfaces,
518 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
528 #ifndef CLIB_MARCH_VARIANT
530 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
531 u32 thread_index, vlib_buffer_t * b, ip4_header_t * ip,
532 u8 * p_proto, snat_session_key_t * p_value,
533 u8 * p_dont_translate, void *d, void *e)
537 nat_ed_ses_key_t key;
538 snat_session_t *s = 0;
539 u8 dont_translate = 0;
540 clib_bihash_kv_16_8_t kv, value;
543 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
545 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
546 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
548 key.as_u64[0] = key.as_u64[1] = 0;
549 err = get_icmp_i2o_ed_key (b, ip, &key);
552 b->error = node->errors[err];
553 next = NAT_NEXT_DROP;
556 key.fib_index = rx_fib_index;
558 kv.key[0] = key.as_u64[0];
559 kv.key[1] = key.as_u64[1];
561 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
563 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
566 (nat44_ed_not_translate_output_feature
567 (sm, ip, key.proto, key.l_port, key.r_port, thread_index,
568 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
576 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
577 ip, SNAT_PROTOCOL_ICMP,
587 (icmp_type_is_error_message
588 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
590 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
591 next = NAT_NEXT_DROP;
595 next = slow_path_ed (sm, b, rx_fib_index, &kv, &s, node, next,
596 thread_index, vlib_time_now (sm->vlib_main));
598 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
610 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
612 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
614 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
615 reass.icmp_type_or_tcp_flags)))
617 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
618 next = NAT_NEXT_DROP;
622 s = pool_elt_at_index (tsm->sessions, value.value);
625 *p_proto = ip_proto_to_snat_proto (key.proto);
628 *p_value = s->out2in;
629 *p_dont_translate = dont_translate;
631 *(snat_session_t **) d = s;
636 static snat_session_t *
637 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
643 vlib_main_t * vm, vlib_node_runtime_t * node)
645 clib_bihash_kv_8_8_t kv, value;
646 clib_bihash_kv_16_8_t s_kv, s_value;
647 snat_static_mapping_t *m;
648 u32 old_addr, new_addr = 0;
651 dlist_elt_t *head, *elt;
652 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
653 u32 elt_index, head_index, ses_index;
655 u32 outside_fib_index = sm->outside_fib_index;
658 nat_outside_fib_t *outside_fib;
659 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
661 .fp_proto = FIB_PROTOCOL_IP4,
664 .ip4.as_u32 = ip->dst_address.as_u32,
668 switch (vec_len (sm->outside_fibs))
671 outside_fib_index = sm->outside_fib_index;
674 outside_fib_index = sm->outside_fibs[0].fib_index;
678 vec_foreach (outside_fib, sm->outside_fibs)
680 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
681 if (FIB_NODE_INDEX_INVALID != fei)
683 if (fib_entry_get_resolving_interface (fei) != ~0)
685 outside_fib_index = outside_fib->fib_index;
693 old_addr = ip->src_address.as_u32;
695 make_ed_kv (&s_kv, &ip->src_address, &ip->dst_address, ip->protocol,
698 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
700 s = pool_elt_at_index (tsm->sessions, s_value.value);
701 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
705 if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
707 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
708 nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
709 nat_elog_notice ("maximum sessions exceeded");
713 u = nat_user_get_or_create (sm, &ip->src_address, rx_fib_index,
717 b->error = node->errors[NAT_IN2OUT_ED_ERROR_CANNOT_CREATE_USER];
718 nat_elog_warn ("create NAT user failed");
722 make_sm_kv (&kv, &ip->src_address, 0, rx_fib_index, 0);
724 /* Try to find static mapping first */
725 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
727 m = pool_elt_at_index (sm->static_mappings, value.value);
728 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
732 /* Fallback to 3-tuple key */
735 /* Choose same out address as for TCP/UDP session to same destination */
736 head_index = u->sessions_per_user_list_head_index;
737 head = pool_elt_at_index (tsm->list_pool, head_index);
738 elt_index = head->next;
739 if (PREDICT_FALSE (elt_index == ~0))
743 elt = pool_elt_at_index (tsm->list_pool, elt_index);
744 ses_index = elt->value;
747 while (ses_index != ~0)
749 s = pool_elt_at_index (tsm->sessions, ses_index);
750 elt_index = elt->next;
751 elt = pool_elt_at_index (tsm->list_pool, elt_index);
752 ses_index = elt->value;
754 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
756 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
758 make_ed_kv (&s_kv, &s->out2in.addr, &ip->dst_address,
759 ip->protocol, outside_fib_index, 0, 0);
760 if (clib_bihash_search_16_8
761 (&tsm->out2in_ed, &s_kv, &s_value))
768 for (i = 0; i < vec_len (sm->addresses); i++)
770 make_ed_kv (&s_kv, &sm->addresses[i].addr, &ip->dst_address,
771 ip->protocol, outside_fib_index, 0, 0);
772 if (clib_bihash_search_16_8 (&tsm->out2in_ed, &s_kv, &s_value))
774 new_addr = ip->src_address.as_u32 =
775 sm->addresses[i].addr.as_u32;
783 s = nat_ed_session_alloc (sm, u, thread_index, now);
786 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
787 nat44_delete_user_with_no_session (sm, u, thread_index);
788 nat_elog_warn ("create NAT session failed");
792 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
793 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
794 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
795 s->out2in.addr.as_u32 = new_addr;
796 s->out2in.fib_index = outside_fib_index;
797 s->in2out.addr.as_u32 = old_addr;
798 s->in2out.fib_index = rx_fib_index;
799 s->in2out.port = s->out2in.port = ip->protocol;
801 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
802 user_session_increment (sm, u, is_sm);
804 /* Add to lookup tables */
805 make_ed_kv (&s_kv, &s->in2out.addr, &ip->dst_address, ip->protocol,
807 s_kv.value = s - tsm->sessions;
808 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
809 nat_elog_notice ("in2out key add failed");
811 make_ed_kv (&s_kv, &s->out2in.addr, &ip->dst_address, ip->protocol,
812 outside_fib_index, 0, 0);
813 s_kv.value = s - tsm->sessions;
814 if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &s_kv, 1))
815 nat_elog_notice ("out2in key add failed");
818 /* Update IP checksum */
820 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
821 ip->checksum = ip_csum_fold (sum);
824 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
826 /* Per-user LRU list maintenance */
827 nat44_session_update_lru (sm, s, thread_index);
830 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
831 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
833 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
834 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
840 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
841 vlib_node_runtime_t * node,
842 vlib_frame_t * frame,
843 int is_output_feature)
845 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
846 nat_next_t next_index;
847 snat_main_t *sm = &snat_main;
848 f64 now = vlib_time_now (vm);
849 u32 thread_index = vm->thread_index;
850 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
851 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
854 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH :
855 NAT_NEXT_IN2OUT_ED_SLOW_PATH;
857 stats_node_index = sm->ed_in2out_node_index;
859 from = vlib_frame_vector_args (frame);
860 n_left_from = frame->n_vectors;
861 next_index = node->cached_next_index;
863 while (n_left_from > 0)
867 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
869 while (n_left_from > 0 && n_left_to_next > 0)
873 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
874 new_addr0, old_addr0;
875 u16 old_port0, new_port0;
879 snat_session_t *s0 = 0;
880 clib_bihash_kv_16_8_t kv0, value0;
883 /* speculatively enqueue b0 to the current next frame */
891 b0 = vlib_get_buffer (vm, bi0);
893 if (is_output_feature)
895 vnet_feature_next (&nat_buffer_opaque (b0)->arc_next, b0);
896 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
899 next0 = nat_buffer_opaque (b0)->arc_next;
901 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
904 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
906 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
909 if (PREDICT_FALSE (ip0->ttl == 1))
911 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
912 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
913 ICMP4_time_exceeded_ttl_exceeded_in_transit,
915 next0 = NAT_NEXT_ICMP_ERROR;
919 udp0 = ip4_next_header (ip0);
920 tcp0 = (tcp_header_t *) udp0;
921 proto0 = ip_proto_to_snat_proto (ip0->protocol);
923 if (PREDICT_FALSE (proto0 == ~0))
929 if (is_output_feature)
931 if (PREDICT_FALSE (nat_not_translate_output_feature_fwd
932 (sm, ip0, thread_index, now, vm, b0)))
936 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
942 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
943 ip0->protocol, rx_fib_index0,
944 vnet_buffer (b0)->ip.reass.l4_src_port,
945 vnet_buffer (b0)->ip.reass.l4_dst_port);
947 // lookup for session
948 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
950 // session does not exist go slow path
954 s0 = pool_elt_at_index (tsm->sessions, value0.value);
956 // drop if session expired
957 u64 sess_timeout_time;
958 sess_timeout_time = s0->last_heard +
959 (f64) nat44_session_get_timeout (sm, s0);
960 if (now >= sess_timeout_time)
963 nat_free_session_data (sm, s0, thread_index, 0);
964 nat44_delete_session (sm, s0, thread_index);
966 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_SESS_EXPIRED];
967 next0 = NAT_NEXT_DROP;
972 b0->flags |= VNET_BUFFER_F_IS_NATED;
974 if (!is_output_feature)
975 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
977 old_addr0 = ip0->src_address.as_u32;
978 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
979 sum0 = ip0->checksum;
980 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
982 if (PREDICT_FALSE (is_twice_nat_session (s0)))
983 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
984 s0->ext_host_addr.as_u32, ip4_header_t,
986 ip0->checksum = ip_csum_fold (sum0);
988 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
990 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
992 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
994 new_port0 = udp0->src_port = s0->out2in.port;
995 sum0 = tcp0->checksum;
997 ip_csum_update (sum0, old_addr0, new_addr0,
998 ip4_header_t, dst_address);
1000 ip_csum_update (sum0, old_port0, new_port0,
1001 ip4_header_t, length);
1002 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1005 ip_csum_update (sum0, ip0->dst_address.as_u32,
1006 s0->ext_host_addr.as_u32,
1007 ip4_header_t, dst_address);
1009 ip_csum_update (sum0,
1010 vnet_buffer (b0)->ip.
1011 reass.l4_dst_port, s0->ext_host_port,
1012 ip4_header_t, length);
1013 tcp0->dst_port = s0->ext_host_port;
1014 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1016 mss_clamping (sm, tcp0, &sum0);
1017 tcp0->checksum = ip_csum_fold (sum0);
1020 if (nat44_set_tcp_session_state_i2o (sm, s0, b0, thread_index))
1023 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1026 new_port0 = udp0->src_port = s0->out2in.port;
1027 sum0 = udp0->checksum;
1029 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1032 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1034 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1036 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1037 s0->ext_host_addr.as_u32,
1038 ip4_header_t, dst_address);
1040 ip_csum_update (sum0,
1041 vnet_buffer (b0)->ip.reass.l4_dst_port,
1042 s0->ext_host_port, ip4_header_t, length);
1043 udp0->dst_port = s0->ext_host_port;
1044 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1046 udp0->checksum = ip_csum_fold (sum0);
1051 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1053 new_port0 = udp0->src_port = s0->out2in.port;
1054 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1056 udp0->dst_port = s0->ext_host_port;
1057 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1064 nat44_session_update_counters (s0, now,
1065 vlib_buffer_length_in_chain
1066 (vm, b0), thread_index);
1067 /* Per-user LRU list maintenance */
1068 nat44_session_update_lru (sm, s0, thread_index);
1071 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1072 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1074 nat_in2out_ed_trace_t *t =
1075 vlib_add_trace (vm, node, b0, sizeof (*t));
1076 t->sw_if_index = sw_if_index0;
1077 t->next_index = next0;
1078 t->is_slow_path = 0;
1081 t->session_index = s0 - tsm->sessions;
1083 t->session_index = ~0;
1086 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1087 /* verify speculative enqueue, maybe switch current next frame */
1088 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1089 to_next, n_left_to_next,
1093 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1096 vlib_node_increment_counter (vm, stats_node_index,
1097 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1099 vlib_node_increment_counter (vm, stats_node_index,
1100 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1101 vlib_node_increment_counter (vm, stats_node_index,
1102 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1103 vlib_node_increment_counter (vm, stats_node_index,
1104 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1106 vlib_node_increment_counter (vm, stats_node_index,
1107 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1109 return frame->n_vectors;
1113 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1114 vlib_node_runtime_t * node,
1115 vlib_frame_t * frame,
1116 int is_output_feature)
1118 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
1119 nat_next_t next_index;
1120 snat_main_t *sm = &snat_main;
1121 f64 now = vlib_time_now (vm);
1122 u32 thread_index = vm->thread_index;
1123 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1124 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1126 stats_node_index = sm->ed_in2out_slowpath_node_index;
1128 from = vlib_frame_vector_args (frame);
1129 n_left_from = frame->n_vectors;
1130 next_index = node->cached_next_index;
1132 while (n_left_from > 0)
1136 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1138 while (n_left_from > 0 && n_left_to_next > 0)
1142 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
1143 new_addr0, old_addr0;
1144 u16 old_port0, new_port0;
1148 icmp46_header_t *icmp0;
1149 snat_session_t *s0 = 0;
1150 clib_bihash_kv_16_8_t kv0, value0;
1153 /* speculatively enqueue b0 to the current next frame */
1159 n_left_to_next -= 1;
1161 b0 = vlib_get_buffer (vm, bi0);
1163 if (is_output_feature)
1164 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1166 next0 = nat_buffer_opaque (b0)->arc_next;
1168 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1171 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1173 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1176 if (PREDICT_FALSE (ip0->ttl == 1))
1178 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1179 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1180 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1182 next0 = NAT_NEXT_ICMP_ERROR;
1186 udp0 = ip4_next_header (ip0);
1187 tcp0 = (tcp_header_t *) udp0;
1188 icmp0 = (icmp46_header_t *) udp0;
1189 proto0 = ip_proto_to_snat_proto (ip0->protocol);
1191 if (PREDICT_FALSE (proto0 == ~0))
1193 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1198 next0 = NAT_NEXT_DROP;
1204 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
1206 next0 = icmp_in2out_ed_slow_path
1207 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1208 node, next0, now, thread_index, &s0);
1214 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
1215 ip0->protocol, rx_fib_index0,
1216 vnet_buffer (b0)->ip.reass.l4_src_port,
1217 vnet_buffer (b0)->ip.reass.l4_dst_port);
1219 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1222 if (is_output_feature)
1225 (nat44_ed_not_translate_output_feature
1226 (sm, ip0, ip0->protocol,
1227 vnet_buffer (b0)->ip.reass.l4_src_port,
1228 vnet_buffer (b0)->ip.reass.l4_dst_port,
1229 thread_index, sw_if_index0,
1230 vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1234 * Send DHCP packets to the ipv4 stack, or we won't
1235 * be able to use dhcp client on the outside interface
1238 (proto0 == SNAT_PROTOCOL_UDP
1239 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1240 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1241 && ip0->dst_address.as_u32 == 0xffffffff))
1247 (nat44_ed_not_translate
1248 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1253 next0 = slow_path_ed (sm, b0, rx_fib_index0, &kv0, &s0, node,
1254 next0, thread_index, now);
1256 if (PREDICT_FALSE (next0 == NAT_NEXT_DROP))
1259 if (PREDICT_FALSE (!s0))
1265 s0 = pool_elt_at_index (tsm->sessions, value0.value);
1269 b0->flags |= VNET_BUFFER_F_IS_NATED;
1271 if (!is_output_feature)
1272 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1274 old_addr0 = ip0->src_address.as_u32;
1275 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1276 sum0 = ip0->checksum;
1277 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1279 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1280 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1281 s0->ext_host_addr.as_u32, ip4_header_t,
1283 ip0->checksum = ip_csum_fold (sum0);
1285 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1287 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
1289 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1291 new_port0 = udp0->src_port = s0->out2in.port;
1292 sum0 = tcp0->checksum;
1294 ip_csum_update (sum0, old_addr0, new_addr0,
1295 ip4_header_t, dst_address);
1297 ip_csum_update (sum0, old_port0, new_port0,
1298 ip4_header_t, length);
1299 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1302 ip_csum_update (sum0, ip0->dst_address.as_u32,
1303 s0->ext_host_addr.as_u32,
1304 ip4_header_t, dst_address);
1306 ip_csum_update (sum0,
1307 vnet_buffer (b0)->ip.
1308 reass.l4_dst_port, s0->ext_host_port,
1309 ip4_header_t, length);
1310 tcp0->dst_port = s0->ext_host_port;
1311 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1313 mss_clamping (sm, tcp0, &sum0);
1314 tcp0->checksum = ip_csum_fold (sum0);
1317 if (nat44_set_tcp_session_state_i2o (sm, s0, b0, thread_index))
1320 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1323 new_port0 = udp0->src_port = s0->out2in.port;
1324 sum0 = udp0->checksum;
1326 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1329 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1331 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1333 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1334 s0->ext_host_addr.as_u32,
1335 ip4_header_t, dst_address);
1337 ip_csum_update (sum0,
1338 vnet_buffer (b0)->ip.reass.l4_dst_port,
1339 s0->ext_host_port, ip4_header_t, length);
1340 udp0->dst_port = s0->ext_host_port;
1341 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1343 udp0->checksum = ip_csum_fold (sum0);
1348 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1350 new_port0 = udp0->src_port = s0->out2in.port;
1351 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1353 udp0->dst_port = s0->ext_host_port;
1354 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1361 nat44_session_update_counters (s0, now,
1362 vlib_buffer_length_in_chain
1363 (vm, b0), thread_index);
1364 /* Per-user LRU list maintenance */
1365 nat44_session_update_lru (sm, s0, thread_index);
1368 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1369 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1371 nat_in2out_ed_trace_t *t =
1372 vlib_add_trace (vm, node, b0, sizeof (*t));
1373 t->sw_if_index = sw_if_index0;
1374 t->next_index = next0;
1375 t->is_slow_path = 1;
1378 t->session_index = s0 - tsm->sessions;
1380 t->session_index = ~0;
1383 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1385 /* verify speculative enqueue, maybe switch current next frame */
1386 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1387 to_next, n_left_to_next,
1391 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1394 vlib_node_increment_counter (vm, stats_node_index,
1395 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1397 vlib_node_increment_counter (vm, stats_node_index,
1398 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1399 vlib_node_increment_counter (vm, stats_node_index,
1400 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1401 vlib_node_increment_counter (vm, stats_node_index,
1402 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1404 vlib_node_increment_counter (vm, stats_node_index,
1405 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1407 return frame->n_vectors;
1410 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1411 vlib_node_runtime_t * node,
1412 vlib_frame_t * frame)
1414 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1418 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1419 .name = "nat44-ed-in2out",
1420 .vector_size = sizeof (u32),
1421 .sibling_of = "nat-default",
1422 .format_trace = format_nat_in2out_ed_trace,
1423 .type = VLIB_NODE_TYPE_INTERNAL,
1424 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1425 .error_strings = nat_in2out_ed_error_strings,
1426 .runtime_data_bytes = sizeof (snat_runtime_t),
1430 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1431 vlib_node_runtime_t * node,
1432 vlib_frame_t * frame)
1434 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1438 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1439 .name = "nat44-ed-in2out-output",
1440 .vector_size = sizeof (u32),
1441 .sibling_of = "nat-default",
1442 .format_trace = format_nat_in2out_ed_trace,
1443 .type = VLIB_NODE_TYPE_INTERNAL,
1444 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1445 .error_strings = nat_in2out_ed_error_strings,
1446 .runtime_data_bytes = sizeof (snat_runtime_t),
1450 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1451 vlib_node_runtime_t *
1452 node, vlib_frame_t * frame)
1454 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1458 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1459 .name = "nat44-ed-in2out-slowpath",
1460 .vector_size = sizeof (u32),
1461 .sibling_of = "nat-default",
1462 .format_trace = format_nat_in2out_ed_trace,
1463 .type = VLIB_NODE_TYPE_INTERNAL,
1464 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1465 .error_strings = nat_in2out_ed_error_strings,
1466 .runtime_data_bytes = sizeof (snat_runtime_t),
1470 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1473 vlib_frame_t * frame)
1475 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1479 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1480 .name = "nat44-ed-in2out-output-slowpath",
1481 .vector_size = sizeof (u32),
1482 .sibling_of = "nat-default",
1483 .format_trace = format_nat_in2out_ed_trace,
1484 .type = VLIB_NODE_TYPE_INTERNAL,
1485 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1486 .error_strings = nat_in2out_ed_error_strings,
1487 .runtime_data_bytes = sizeof (snat_runtime_t),
1492 format_nat_pre_trace (u8 * s, va_list * args)
1494 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1495 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1496 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1497 return format (s, "in2out next_index %d", t->next_index);
1500 VLIB_NODE_FN (nat_pre_in2out_node)
1501 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1503 return nat_pre_node_fn_inline (vm, node, frame,
1504 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1508 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1509 .name = "nat-pre-in2out",
1510 .vector_size = sizeof (u32),
1511 .sibling_of = "nat-default",
1512 .format_trace = format_nat_pre_trace,
1513 .type = VLIB_NODE_TYPE_INTERNAL,
1519 * fd.io coding-style-patch-verification: ON
1522 * eval: (c-set-style "gnu")