2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * @brief NAT44 endpoint-dependent inside to outside network translation
20 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
22 #include <vnet/pg/pg.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/fib/ip4_fib.h>
26 #include <vnet/udp/udp.h>
27 #include <vppinfra/error.h>
29 #include <nat/nat_ipfix_logging.h>
30 #include <nat/nat_inlines.h>
31 #include <nat/nat44/inlines.h>
32 #include <nat/nat_syslog.h>
33 #include <nat/nat_ha.h>
34 #include <nat/nat44/ed_inlines.h>
36 static char *nat_in2out_ed_error_strings[] = {
37 #define _(sym,string) string,
38 foreach_nat_in2out_ed_error
48 } nat_in2out_ed_trace_t;
51 format_nat_in2out_ed_trace (u8 * s, va_list * args)
53 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
54 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
55 nat_in2out_ed_trace_t *t = va_arg (*args, nat_in2out_ed_trace_t *);
59 t->is_slow_path ? "NAT44_IN2OUT_ED_SLOW_PATH" :
60 "NAT44_IN2OUT_ED_FAST_PATH";
62 s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
63 t->sw_if_index, t->next_index, t->session_index);
68 #ifndef CLIB_MARCH_VARIANT
70 nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void *arg)
72 snat_main_t *sm = &snat_main;
73 nat44_is_idle_session_ctx_t *ctx = arg;
75 u64 sess_timeout_time;
78 ip4_address_t *l_addr, *r_addr;
80 clib_bihash_kv_16_8_t ed_kv;
83 snat_session_key_t key;
84 snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
87 ASSERT (ctx->thread_index == ed_value_get_thread_index (kv));
88 s = pool_elt_at_index (tsm->sessions, ed_value_get_session_index (kv));
89 sess_timeout_time = s->last_heard + (f64) nat44_session_get_timeout (sm, s);
90 if (ctx->now >= sess_timeout_time)
92 if (is_fwd_bypass_session (s))
95 l_addr = &s->out2in.addr;
96 r_addr = &s->ext_host_addr;
97 fib_index = s->out2in.fib_index;
98 if (snat_is_unk_proto_session (s))
100 proto = s->in2out.port;
106 proto = nat_proto_to_ip_proto (s->in2out.protocol);
107 l_port = s->out2in.port;
108 r_port = s->ext_host_port;
110 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0, ~0,
112 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &ed_kv, 0))
113 nat_elog_warn ("out2in_ed key del failed");
115 if (snat_is_unk_proto_session (s))
118 snat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
119 s->in2out.addr.as_u32,
120 s->out2in.addr.as_u32,
124 s->in2out.fib_index);
126 nat_syslog_nat44_sdel (s->user_index, s->in2out.fib_index,
127 &s->in2out.addr, s->in2out.port,
128 &s->ext_host_nat_addr, s->ext_host_nat_port,
129 &s->out2in.addr, s->out2in.port,
130 &s->ext_host_addr, s->ext_host_port,
131 s->in2out.protocol, is_twice_nat_session (s));
133 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
134 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
137 if (is_twice_nat_session (s))
139 for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
141 key.protocol = s->in2out.protocol;
142 key.port = s->ext_host_nat_port;
143 a = sm->twice_nat_addresses + i;
144 if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
146 snat_free_outside_address_and_port (sm->twice_nat_addresses,
154 if (snat_is_session_static (s))
157 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
160 nat_ed_session_delete (sm, s, ctx->thread_index, 1);
169 icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
170 ip4_header_t * ip0, icmp46_header_t * icmp0,
171 u32 sw_if_index0, u32 rx_fib_index0,
172 vlib_node_runtime_t * node, u32 next0, f64 now,
173 u32 thread_index, snat_session_t ** p_s0)
175 vlib_main_t *vm = vlib_get_main ();
177 next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
178 next0, thread_index, p_s0, 0);
179 snat_session_t *s0 = *p_s0;
180 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
183 nat44_session_update_counters (s0, now,
184 vlib_buffer_length_in_chain
185 (vm, b0), thread_index);
186 /* Per-user LRU list maintenance */
187 nat44_session_update_lru (sm, s0, thread_index);
192 static_always_inline u16
193 snat_random_port (u16 min, u16 max)
195 snat_main_t *sm = &snat_main;
196 return min + random_u32 (&sm->random_seed) /
197 (random_u32_max () / (max - min + 1) + 1);
201 nat_ed_alloc_addr_and_port (snat_main_t * sm, u32 rx_fib_index,
202 u32 nat_proto, u32 thread_index,
203 ip4_address_t r_addr, u16 r_port, u8 proto,
204 u16 port_per_thread, u32 snat_thread_index,
206 ip4_address_t * allocated_addr,
207 u16 * allocated_port,
208 clib_bihash_kv_16_8_t * out2in_ed_kv)
211 snat_address_t *a, *ga = 0;
213 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
215 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
217 for (i = 0; i < vec_len (sm->addresses); i++)
219 a = sm->addresses + i;
222 #define _(N, j, n, unused) \
223 case NAT_PROTOCOL_##N: \
224 if (a->fib_index == rx_fib_index) \
226 u16 port = snat_random_port (1, port_per_thread); \
227 u16 attempts = port_per_thread; \
228 while (attempts > 0) \
231 portnum = port_thread_offset + port; \
232 make_ed_kv (&a->addr, &r_addr, proto, s->out2in.fib_index, \
233 clib_host_to_net_u16 (portnum), r_port, thread_index, \
234 s - tsm->sessions, out2in_ed_kv); \
235 int rv = clib_bihash_add_del_16_8 (&sm->out2in_ed, out2in_ed_kv, \
239 ++a->busy_##n##_port_refcounts[portnum]; \
240 a->busy_##n##_ports_per_thread[thread_index]++; \
241 a->busy_##n##_ports++; \
242 *allocated_addr = a->addr; \
243 *allocated_port = clib_host_to_net_u16 (portnum); \
246 port = (port + 1) % port_per_thread; \
249 else if (a->fib_index == ~0) \
255 foreach_nat_protocol;
257 nat_elog_info ("unknown protocol");
264 /* fake fib_index to reuse macro */
269 foreach_nat_protocol;
271 nat_elog_info ("unknown protocol");
278 /* Totally out of translations to use... */
279 snat_ipfix_logging_addresses_exhausted (thread_index, 0);
284 slow_path_ed (snat_main_t * sm,
286 ip4_address_t l_addr,
287 ip4_address_t r_addr,
292 snat_session_t ** sessionp,
293 vlib_node_runtime_t * node, u32 next, u32 thread_index, f64 now)
295 snat_session_t *s = NULL;
296 snat_session_key_t key0, key1;
297 lb_nat_type_t lb = 0;
298 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
299 u32 nat_proto = ip_proto_to_nat_proto (proto);
300 nat_outside_fib_t *outside_fib;
301 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
302 clib_bihash_kv_16_8_t out2in_ed_kv;
303 ip4_address_t allocated_addr;
307 .fp_proto = FIB_PROTOCOL_IP4,
309 .fp_addr = {.ip4.as_u32 = r_addr.as_u32,},
311 nat44_is_idle_session_ctx_t ctx;
313 if (PREDICT_TRUE (nat_proto == NAT_PROTOCOL_TCP))
317 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
319 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
320 return NAT_NEXT_DROP;
324 // TODO: based on fib index do a lookup
326 (nat44_ed_maximum_sessions_exceeded (sm, rx_fib_index, thread_index)))
328 if (!nat_lru_free_one (sm, thread_index, now))
330 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
331 nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
332 nat_elog_notice ("maximum sessions exceeded");
333 return NAT_NEXT_DROP;
339 key1.protocol = key0.protocol = nat_proto;
340 key0.fib_index = rx_fib_index;
341 key1.fib_index = sm->outside_fib_index;
343 /* First try to match static mapping by local address and port */
344 if (snat_static_mapping_match
345 (sm, key0, &key1, 0, 0, 0, &lb, 0, &identity_nat))
347 s = nat_ed_session_alloc (sm, thread_index, now, proto);
350 nat_elog_warn ("create NAT session failed");
351 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
352 return NAT_NEXT_DROP;
354 switch (vec_len (sm->outside_fibs))
357 s->out2in.fib_index = sm->outside_fib_index;
360 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
364 vec_foreach (outside_fib, sm->outside_fibs)
366 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
367 if (FIB_NODE_INDEX_INVALID != fei)
369 if (fib_entry_get_resolving_interface (fei) != ~0)
371 s->out2in.fib_index = outside_fib->fib_index;
380 /* Try to create dynamic translation */
381 if (nat_ed_alloc_addr_and_port (sm, rx_fib_index, nat_proto,
382 thread_index, r_addr, r_port, proto,
384 tsm->snat_thread_index, s,
386 &allocated_port, &out2in_ed_kv))
388 nat_elog_notice ("addresses exhausted");
389 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
390 nat_ed_session_delete (sm, s, thread_index, 1);
391 return NAT_NEXT_DROP;
393 key1.addr = allocated_addr;
394 key1.port = allocated_port;
398 if (PREDICT_FALSE (identity_nat))
403 s = nat_ed_session_alloc (sm, thread_index, now, proto);
406 nat_elog_warn ("create NAT session failed");
407 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
408 return NAT_NEXT_DROP;
410 switch (vec_len (sm->outside_fibs))
413 s->out2in.fib_index = sm->outside_fib_index;
416 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
420 vec_foreach (outside_fib, sm->outside_fibs)
422 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
423 if (FIB_NODE_INDEX_INVALID != fei)
425 if (fib_entry_get_resolving_interface (fei) != ~0)
427 s->out2in.fib_index = outside_fib->fib_index;
436 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
439 make_ed_kv (&key1.addr, &r_addr, proto,
440 s->out2in.fib_index, key1.port, r_port, thread_index,
441 s - tsm->sessions, &out2in_ed_kv);
442 if (clib_bihash_add_or_overwrite_stale_16_8
443 (&sm->out2in_ed, &out2in_ed_kv, nat44_o2i_ed_is_idle_session_cb,
445 nat_elog_notice ("out2in-ed key add failed");
449 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
450 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
451 s->ext_host_addr = r_addr;
452 s->ext_host_port = r_port;
455 s->out2in.protocol = key0.protocol;
457 clib_bihash_kv_16_8_t in2out_ed_kv;
458 make_ed_kv (&l_addr, &r_addr, proto, rx_fib_index, l_port, r_port,
459 thread_index, s - tsm->sessions, &in2out_ed_kv);
461 ctx.thread_index = thread_index;
462 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, &in2out_ed_kv,
463 nat44_i2o_ed_is_idle_session_cb,
465 nat_elog_notice ("in2out-ed key add failed");
470 snat_ipfix_logging_nat44_ses_create (thread_index,
471 s->in2out.addr.as_u32,
472 s->out2in.addr.as_u32,
475 s->out2in.port, s->in2out.fib_index);
477 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
478 &s->in2out.addr, s->in2out.port,
479 &s->ext_host_nat_addr, s->ext_host_nat_port,
480 &s->out2in.addr, s->out2in.port,
481 &s->ext_host_addr, s->ext_host_port,
482 s->in2out.protocol, 0);
484 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
485 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
486 &s->ext_host_nat_addr, s->ext_host_nat_port,
487 s->in2out.protocol, s->in2out.fib_index, s->flags,
493 static_always_inline int
494 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
495 u32 sw_if_index, ip4_header_t * ip, u32 proto,
496 u32 rx_fib_index, u32 thread_index)
498 udp_header_t *udp = ip4_next_header (ip);
499 clib_bihash_kv_16_8_t kv, value;
500 snat_session_key_t key0, key1;
502 make_ed_kv (&ip->dst_address, &ip->src_address, ip->protocol,
503 sm->outside_fib_index, udp->dst_port, udp->src_port, ~0, ~0,
506 /* NAT packet aimed at external address if has active sessions */
507 if (clib_bihash_search_16_8 (&sm->out2in_ed, &kv, &value))
509 key0.addr = ip->dst_address;
510 key0.port = udp->dst_port;
511 key0.protocol = proto;
512 key0.fib_index = sm->outside_fib_index;
513 /* or is static mappings */
514 if (!snat_static_mapping_match (sm, key0, &key1, 1, 0, 0, 0, 0, 0))
520 if (sm->forwarding_enabled)
523 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
527 static_always_inline int
528 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
529 u32 thread_index, f64 now,
530 vlib_main_t * vm, vlib_buffer_t * b)
532 clib_bihash_kv_16_8_t kv, value;
533 snat_session_t *s = 0;
534 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
536 if (!sm->forwarding_enabled)
539 if (ip->protocol == IP_PROTOCOL_ICMP)
541 if (get_icmp_i2o_ed_key (b, ip, 0, ~0, ~0, 0, 0, 0, &kv))
544 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
546 make_ed_kv (&ip->src_address, &ip->dst_address, ip->protocol, 0,
547 vnet_buffer (b)->ip.reass.l4_src_port,
548 vnet_buffer (b)->ip.reass.l4_dst_port, ~0, ~0, &kv);
552 make_ed_kv (&ip->src_address, &ip->dst_address, ip->protocol, 0, 0,
556 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
558 ASSERT (thread_index == ed_value_get_thread_index (&value));
560 pool_elt_at_index (tsm->sessions,
561 ed_value_get_session_index (&value));
562 if (is_fwd_bypass_session (s))
564 if (ip->protocol == IP_PROTOCOL_TCP)
566 if (nat44_set_tcp_session_state_i2o
567 (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,
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 make_ed_kv (&ip->src_address, &ip->dst_address, ip->protocol,
600 tx_fib_index, src_port, dst_port, ~0, ~0, &kv);
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))
609 nat_free_session_data (sm, s, thread_index, 0);
610 nat_ed_session_delete (sm, s, thread_index, 1);
613 s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
618 make_ed_kv (&ip->dst_address, &ip->src_address, ip->protocol,
619 rx_fib_index, dst_port, src_port, ~0, ~0, &kv);
620 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
622 ASSERT (thread_index == ed_value_get_thread_index (&value));
624 pool_elt_at_index (tsm->sessions,
625 ed_value_get_session_index (&value));
626 if (is_fwd_bypass_session (s))
631 pool_foreach (i, sm->output_feature_interfaces,
633 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
643 #ifndef CLIB_MARCH_VARIANT
645 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
646 u32 thread_index, vlib_buffer_t * b, ip4_header_t * ip,
647 u8 * p_proto, snat_session_key_t * p_value,
648 u8 * p_dont_translate, void *d, void *e)
652 snat_session_t *s = 0;
653 u8 dont_translate = 0;
654 clib_bihash_kv_16_8_t kv, value;
657 u16 l_port = 0, r_port = 0; // initialize to workaround gcc warning
658 vlib_main_t *vm = vlib_get_main ();
659 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
661 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
662 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
665 get_icmp_i2o_ed_key (b, ip, rx_fib_index, ~0, ~0, p_proto, &l_port,
669 b->error = node->errors[err];
670 next = NAT_NEXT_DROP;
674 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
676 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
679 (nat44_ed_not_translate_output_feature
680 (sm, ip, l_port, r_port, thread_index,
681 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
689 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
690 ip, NAT_PROTOCOL_ICMP,
700 (icmp_type_is_error_message
701 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
703 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
704 next = NAT_NEXT_DROP;
709 slow_path_ed (sm, b, ip->src_address, ip->dst_address, l_port, r_port,
710 ip->protocol, rx_fib_index, &s, node, next,
711 thread_index, vlib_time_now (vm));
713 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
725 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
727 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
729 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
730 reass.icmp_type_or_tcp_flags)))
732 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
733 next = NAT_NEXT_DROP;
737 ASSERT (thread_index == ed_value_get_thread_index (&value));
739 pool_elt_at_index (tsm->sessions,
740 ed_value_get_session_index (&value));
744 *p_value = s->out2in;
745 *p_dont_translate = dont_translate;
747 *(snat_session_t **) d = s;
752 static snat_session_t *
753 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
759 vlib_main_t * vm, vlib_node_runtime_t * node)
761 clib_bihash_kv_8_8_t kv, value;
762 clib_bihash_kv_16_8_t s_kv, s_value;
763 snat_static_mapping_t *m;
764 u32 old_addr, new_addr = 0;
766 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
768 u32 outside_fib_index = sm->outside_fib_index;
771 nat_outside_fib_t *outside_fib;
772 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
774 .fp_proto = FIB_PROTOCOL_IP4,
777 .ip4.as_u32 = ip->dst_address.as_u32,
781 switch (vec_len (sm->outside_fibs))
784 outside_fib_index = sm->outside_fib_index;
787 outside_fib_index = sm->outside_fibs[0].fib_index;
791 vec_foreach (outside_fib, sm->outside_fibs)
793 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
794 if (FIB_NODE_INDEX_INVALID != fei)
796 if (fib_entry_get_resolving_interface (fei) != ~0)
798 outside_fib_index = outside_fib->fib_index;
806 old_addr = ip->src_address.as_u32;
808 make_ed_kv (&ip->src_address, &ip->dst_address, ip->protocol,
809 rx_fib_index, 0, 0, ~0, ~0, &s_kv);
811 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
813 ASSERT (thread_index == ed_value_get_thread_index (&s_value));
815 pool_elt_at_index (tsm->sessions,
816 ed_value_get_session_index (&s_value));
817 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
822 (nat44_ed_maximum_sessions_exceeded
823 (sm, rx_fib_index, thread_index)))
825 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
826 nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
827 nat_elog_notice ("maximum sessions exceeded");
831 make_sm_kv (&kv, &ip->src_address, 0, rx_fib_index, 0);
833 /* Try to find static mapping first */
834 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
836 m = pool_elt_at_index (sm->static_mappings, value.value);
837 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
844 pool_foreach (s, tsm->sessions, {
845 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
847 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
849 make_ed_kv (&s->out2in.addr, &ip->dst_address, ip->protocol,
850 outside_fib_index, 0, 0, ~0, ~0, &s_kv);
851 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
859 for (i = 0; i < vec_len (sm->addresses); i++)
861 make_ed_kv (&sm->addresses[i].addr, &ip->dst_address,
862 ip->protocol, outside_fib_index, 0, 0, ~0, ~0,
864 if (clib_bihash_search_16_8 (&sm->out2in_ed, &s_kv, &s_value))
866 new_addr = ip->src_address.as_u32 =
867 sm->addresses[i].addr.as_u32;
875 s = nat_ed_session_alloc (sm, thread_index, now, ip->protocol);
878 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
879 nat_elog_warn ("create NAT session failed");
883 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
884 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
885 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
886 s->out2in.addr.as_u32 = new_addr;
887 s->out2in.fib_index = outside_fib_index;
888 s->in2out.addr.as_u32 = old_addr;
889 s->in2out.fib_index = rx_fib_index;
890 s->in2out.port = s->out2in.port = ip->protocol;
892 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
894 /* Add to lookup tables */
895 make_ed_kv (&s->in2out.addr, &ip->dst_address, ip->protocol,
896 rx_fib_index, 0, 0, thread_index, s - tsm->sessions, &s_kv);
897 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
898 nat_elog_notice ("in2out key add failed");
900 make_ed_kv (&s->out2in.addr, &ip->dst_address, ip->protocol,
901 outside_fib_index, 0, 0, thread_index, s - tsm->sessions,
903 if (clib_bihash_add_del_16_8 (&sm->out2in_ed, &s_kv, 1))
904 nat_elog_notice ("out2in key add failed");
907 /* Update IP checksum */
909 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
910 ip->checksum = ip_csum_fold (sum);
913 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
915 /* Per-user LRU list maintenance */
916 nat44_session_update_lru (sm, s, thread_index);
919 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
920 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
922 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
923 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
929 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
930 vlib_node_runtime_t * node,
931 vlib_frame_t * frame,
932 int is_output_feature)
934 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
935 nat_next_t next_index;
936 snat_main_t *sm = &snat_main;
937 f64 now = vlib_time_now (vm);
938 u32 thread_index = vm->thread_index;
939 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
940 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
943 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH :
944 NAT_NEXT_IN2OUT_ED_SLOW_PATH;
946 stats_node_index = sm->ed_in2out_node_index;
948 from = vlib_frame_vector_args (frame);
949 n_left_from = frame->n_vectors;
950 next_index = node->cached_next_index;
952 while (n_left_from > 0)
956 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
958 while (n_left_from > 0 && n_left_to_next > 0)
962 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
963 new_addr0, old_addr0;
964 u16 old_port0, new_port0;
968 snat_session_t *s0 = 0;
969 clib_bihash_kv_16_8_t kv0, value0;
972 /* speculatively enqueue b0 to the current next frame */
980 b0 = vlib_get_buffer (vm, bi0);
982 if (is_output_feature)
984 vnet_feature_next (&vnet_buffer2 (b0)->nat.arc_next, b0);
985 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
988 next0 = vnet_buffer2 (b0)->nat.arc_next;
990 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
993 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
995 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
998 if (PREDICT_FALSE (ip0->ttl == 1))
1000 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1001 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1002 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1004 next0 = NAT_NEXT_ICMP_ERROR;
1008 udp0 = ip4_next_header (ip0);
1009 tcp0 = (tcp_header_t *) udp0;
1010 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1012 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1018 if (is_output_feature)
1020 if (PREDICT_FALSE (nat_not_translate_output_feature_fwd
1021 (sm, ip0, thread_index, now, vm, b0)))
1025 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1031 make_ed_kv (&ip0->src_address, &ip0->dst_address,
1032 ip0->protocol, rx_fib_index0,
1033 vnet_buffer (b0)->ip.reass.l4_src_port,
1034 vnet_buffer (b0)->ip.reass.l4_dst_port, ~0, ~0, &kv0);
1036 // lookup for session
1037 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1039 // session does not exist go slow path
1043 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1045 pool_elt_at_index (tsm->sessions,
1046 ed_value_get_session_index (&value0));
1048 if (s0->tcp_closed_timestamp)
1050 if (now >= s0->tcp_closed_timestamp)
1052 // session is closed, go slow path
1057 // session in transitory timeout, drop
1058 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1059 next0 = NAT_NEXT_DROP;
1064 // drop if session expired
1065 u64 sess_timeout_time;
1066 sess_timeout_time = s0->last_heard +
1067 (f64) nat44_session_get_timeout (sm, s0);
1068 if (now >= sess_timeout_time)
1070 nat_free_session_data (sm, s0, thread_index, 0);
1071 nat_ed_session_delete (sm, s0, thread_index, 1);
1072 // session is closed, go slow path
1077 b0->flags |= VNET_BUFFER_F_IS_NATED;
1079 if (!is_output_feature)
1080 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1082 old_addr0 = ip0->src_address.as_u32;
1083 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1084 sum0 = ip0->checksum;
1085 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1087 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1088 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1089 s0->ext_host_addr.as_u32, ip4_header_t,
1091 ip0->checksum = ip_csum_fold (sum0);
1093 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1095 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1097 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1099 new_port0 = udp0->src_port = s0->out2in.port;
1100 sum0 = tcp0->checksum;
1102 ip_csum_update (sum0, old_addr0, new_addr0,
1103 ip4_header_t, dst_address);
1105 ip_csum_update (sum0, old_port0, new_port0,
1106 ip4_header_t, length);
1107 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1110 ip_csum_update (sum0, ip0->dst_address.as_u32,
1111 s0->ext_host_addr.as_u32,
1112 ip4_header_t, dst_address);
1114 ip_csum_update (sum0,
1115 vnet_buffer (b0)->ip.
1116 reass.l4_dst_port, s0->ext_host_port,
1117 ip4_header_t, length);
1118 tcp0->dst_port = s0->ext_host_port;
1119 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1121 mss_clamping (sm, tcp0, &sum0);
1122 tcp0->checksum = ip_csum_fold (sum0);
1125 if (nat44_set_tcp_session_state_i2o
1126 (sm, now, s0, b0, thread_index))
1129 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1132 new_port0 = udp0->src_port = s0->out2in.port;
1133 sum0 = udp0->checksum;
1135 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1138 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1140 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1142 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1143 s0->ext_host_addr.as_u32,
1144 ip4_header_t, dst_address);
1146 ip_csum_update (sum0,
1147 vnet_buffer (b0)->ip.reass.l4_dst_port,
1148 s0->ext_host_port, ip4_header_t, length);
1149 udp0->dst_port = s0->ext_host_port;
1150 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1152 udp0->checksum = ip_csum_fold (sum0);
1157 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1159 new_port0 = udp0->src_port = s0->out2in.port;
1160 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1162 udp0->dst_port = s0->ext_host_port;
1163 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1170 nat44_session_update_counters (s0, now,
1171 vlib_buffer_length_in_chain
1172 (vm, b0), thread_index);
1173 /* Per-user LRU list maintenance */
1174 nat44_session_update_lru (sm, s0, thread_index);
1177 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1178 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1180 nat_in2out_ed_trace_t *t =
1181 vlib_add_trace (vm, node, b0, sizeof (*t));
1182 t->sw_if_index = sw_if_index0;
1183 t->next_index = next0;
1184 t->is_slow_path = 0;
1187 t->session_index = s0 - tsm->sessions;
1189 t->session_index = ~0;
1192 pkts_processed += next0 == vnet_buffer2 (b0)->nat.arc_next;
1193 /* verify speculative enqueue, maybe switch current next frame */
1194 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1195 to_next, n_left_to_next,
1199 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1202 vlib_node_increment_counter (vm, stats_node_index,
1203 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1205 vlib_node_increment_counter (vm, stats_node_index,
1206 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1207 vlib_node_increment_counter (vm, stats_node_index,
1208 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1209 vlib_node_increment_counter (vm, stats_node_index,
1210 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1212 vlib_node_increment_counter (vm, stats_node_index,
1213 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1215 return frame->n_vectors;
1219 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1220 vlib_node_runtime_t * node,
1221 vlib_frame_t * frame,
1222 int is_output_feature)
1224 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
1225 nat_next_t next_index;
1226 snat_main_t *sm = &snat_main;
1227 f64 now = vlib_time_now (vm);
1228 u32 thread_index = vm->thread_index;
1229 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1230 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1232 stats_node_index = sm->ed_in2out_slowpath_node_index;
1234 from = vlib_frame_vector_args (frame);
1235 n_left_from = frame->n_vectors;
1236 next_index = node->cached_next_index;
1238 while (n_left_from > 0)
1242 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1244 while (n_left_from > 0 && n_left_to_next > 0)
1248 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
1249 new_addr0, old_addr0;
1250 u16 old_port0, new_port0;
1254 icmp46_header_t *icmp0;
1255 snat_session_t *s0 = 0;
1256 clib_bihash_kv_16_8_t kv0, value0;
1259 /* speculatively enqueue b0 to the current next frame */
1265 n_left_to_next -= 1;
1267 b0 = vlib_get_buffer (vm, bi0);
1269 if (is_output_feature)
1270 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1272 next0 = vnet_buffer2 (b0)->nat.arc_next;
1274 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1277 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1279 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1282 if (PREDICT_FALSE (ip0->ttl == 1))
1284 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1285 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1286 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1288 next0 = NAT_NEXT_ICMP_ERROR;
1292 udp0 = ip4_next_header (ip0);
1293 tcp0 = (tcp_header_t *) udp0;
1294 icmp0 = (icmp46_header_t *) udp0;
1295 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1297 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1299 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1304 next0 = NAT_NEXT_DROP;
1310 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1312 next0 = icmp_in2out_ed_slow_path
1313 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1314 node, next0, now, thread_index, &s0);
1320 make_ed_kv (&ip0->src_address, &ip0->dst_address,
1321 ip0->protocol, rx_fib_index0,
1322 vnet_buffer (b0)->ip.reass.l4_src_port,
1323 vnet_buffer (b0)->ip.reass.l4_dst_port, ~0, ~0, &kv0);
1325 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1327 ASSERT (thread_index == ed_value_get_thread_index (&value0));
1329 pool_elt_at_index (tsm->sessions,
1330 ed_value_get_session_index (&value0));
1332 if (s0->tcp_closed_timestamp && now >= s0->tcp_closed_timestamp)
1334 nat_free_session_data (sm, s0, thread_index, 0);
1335 nat_ed_session_delete (sm, s0, thread_index, 1);
1342 if (is_output_feature)
1345 (nat44_ed_not_translate_output_feature
1346 (sm, ip0, vnet_buffer (b0)->ip.reass.l4_src_port,
1347 vnet_buffer (b0)->ip.reass.l4_dst_port, thread_index,
1349 vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1353 * Send DHCP packets to the ipv4 stack, or we won't
1354 * be able to use dhcp client on the outside interface
1357 (proto0 == NAT_PROTOCOL_UDP
1358 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1359 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1360 && ip0->dst_address.as_u32 == 0xffffffff))
1366 (nat44_ed_not_translate
1367 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1373 slow_path_ed (sm, b0, ip0->src_address, ip0->dst_address,
1374 vnet_buffer (b0)->ip.reass.l4_src_port,
1375 vnet_buffer (b0)->ip.reass.l4_dst_port,
1376 ip0->protocol, rx_fib_index0, &s0, node, next0,
1379 if (PREDICT_FALSE (next0 == NAT_NEXT_DROP))
1382 if (PREDICT_FALSE (!s0))
1387 b0->flags |= VNET_BUFFER_F_IS_NATED;
1389 if (!is_output_feature)
1390 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1392 old_addr0 = ip0->src_address.as_u32;
1393 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1394 sum0 = ip0->checksum;
1395 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1397 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1398 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1399 s0->ext_host_addr.as_u32, ip4_header_t,
1401 ip0->checksum = ip_csum_fold (sum0);
1403 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1405 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1407 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1409 new_port0 = udp0->src_port = s0->out2in.port;
1410 sum0 = tcp0->checksum;
1412 ip_csum_update (sum0, old_addr0, new_addr0,
1413 ip4_header_t, dst_address);
1415 ip_csum_update (sum0, old_port0, new_port0,
1416 ip4_header_t, length);
1417 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1420 ip_csum_update (sum0, ip0->dst_address.as_u32,
1421 s0->ext_host_addr.as_u32,
1422 ip4_header_t, dst_address);
1424 ip_csum_update (sum0,
1425 vnet_buffer (b0)->ip.
1426 reass.l4_dst_port, s0->ext_host_port,
1427 ip4_header_t, length);
1428 tcp0->dst_port = s0->ext_host_port;
1429 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1431 mss_clamping (sm, tcp0, &sum0);
1432 tcp0->checksum = ip_csum_fold (sum0);
1435 if (nat44_set_tcp_session_state_i2o
1436 (sm, now, s0, b0, thread_index))
1439 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1442 new_port0 = udp0->src_port = s0->out2in.port;
1443 sum0 = udp0->checksum;
1445 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1448 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1450 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1452 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1453 s0->ext_host_addr.as_u32,
1454 ip4_header_t, dst_address);
1456 ip_csum_update (sum0,
1457 vnet_buffer (b0)->ip.reass.l4_dst_port,
1458 s0->ext_host_port, ip4_header_t, length);
1459 udp0->dst_port = s0->ext_host_port;
1460 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1462 udp0->checksum = ip_csum_fold (sum0);
1467 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1469 new_port0 = udp0->src_port = s0->out2in.port;
1470 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1472 udp0->dst_port = s0->ext_host_port;
1473 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1480 nat44_session_update_counters (s0, now,
1481 vlib_buffer_length_in_chain
1482 (vm, b0), thread_index);
1483 /* Per-user LRU list maintenance */
1484 nat44_session_update_lru (sm, s0, thread_index);
1487 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1488 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1490 nat_in2out_ed_trace_t *t =
1491 vlib_add_trace (vm, node, b0, sizeof (*t));
1492 t->sw_if_index = sw_if_index0;
1493 t->next_index = next0;
1494 t->is_slow_path = 1;
1497 t->session_index = s0 - tsm->sessions;
1499 t->session_index = ~0;
1502 pkts_processed += next0 == vnet_buffer2 (b0)->nat.arc_next;
1504 /* verify speculative enqueue, maybe switch current next frame */
1505 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1506 to_next, n_left_to_next,
1510 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1513 vlib_node_increment_counter (vm, stats_node_index,
1514 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1516 vlib_node_increment_counter (vm, stats_node_index,
1517 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1518 vlib_node_increment_counter (vm, stats_node_index,
1519 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1520 vlib_node_increment_counter (vm, stats_node_index,
1521 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1523 vlib_node_increment_counter (vm, stats_node_index,
1524 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1526 return frame->n_vectors;
1529 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1530 vlib_node_runtime_t * node,
1531 vlib_frame_t * frame)
1533 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1537 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1538 .name = "nat44-ed-in2out",
1539 .vector_size = sizeof (u32),
1540 .sibling_of = "nat-default",
1541 .format_trace = format_nat_in2out_ed_trace,
1542 .type = VLIB_NODE_TYPE_INTERNAL,
1543 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1544 .error_strings = nat_in2out_ed_error_strings,
1545 .runtime_data_bytes = sizeof (snat_runtime_t),
1549 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1550 vlib_node_runtime_t * node,
1551 vlib_frame_t * frame)
1553 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1557 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1558 .name = "nat44-ed-in2out-output",
1559 .vector_size = sizeof (u32),
1560 .sibling_of = "nat-default",
1561 .format_trace = format_nat_in2out_ed_trace,
1562 .type = VLIB_NODE_TYPE_INTERNAL,
1563 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1564 .error_strings = nat_in2out_ed_error_strings,
1565 .runtime_data_bytes = sizeof (snat_runtime_t),
1569 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1570 vlib_node_runtime_t *
1571 node, vlib_frame_t * frame)
1573 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1577 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1578 .name = "nat44-ed-in2out-slowpath",
1579 .vector_size = sizeof (u32),
1580 .sibling_of = "nat-default",
1581 .format_trace = format_nat_in2out_ed_trace,
1582 .type = VLIB_NODE_TYPE_INTERNAL,
1583 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1584 .error_strings = nat_in2out_ed_error_strings,
1585 .runtime_data_bytes = sizeof (snat_runtime_t),
1589 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1592 vlib_frame_t * frame)
1594 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1598 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1599 .name = "nat44-ed-in2out-output-slowpath",
1600 .vector_size = sizeof (u32),
1601 .sibling_of = "nat-default",
1602 .format_trace = format_nat_in2out_ed_trace,
1603 .type = VLIB_NODE_TYPE_INTERNAL,
1604 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1605 .error_strings = nat_in2out_ed_error_strings,
1606 .runtime_data_bytes = sizeof (snat_runtime_t),
1611 format_nat_pre_trace (u8 * s, va_list * args)
1613 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1614 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1615 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1616 return format (s, "in2out next_index %d arc_next_index %d", t->next_index,
1620 VLIB_NODE_FN (nat_pre_in2out_node)
1621 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1623 return nat_pre_node_fn_inline (vm, node, frame,
1624 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1628 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1629 .name = "nat-pre-in2out",
1630 .vector_size = sizeof (u32),
1631 .sibling_of = "nat-default",
1632 .format_trace = format_nat_pre_trace,
1633 .type = VLIB_NODE_TYPE_INTERNAL,
1639 * fd.io coding-style-patch-verification: ON
1642 * eval: (c-set-style "gnu")