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 ed_bihash_kv_t bihash_key;
111 clib_memset (&bihash_key, 0, sizeof (bihash_key));
112 bihash_key.k.dst_address = s->ext_host_addr.as_u32;
113 bihash_key.k.dst_port = s->ext_host_port;
114 bihash_key.k.src_address = s->out2in.addr.as_u32;
115 bihash_key.k.src_port = s->out2in.port;
116 bihash_key.k.protocol = s->out2in.protocol;
117 clib_bihash_add_del_16_8 (&sm->ed_ext_ports, &bihash_key.kv,
120 if (snat_is_unk_proto_session (s))
123 snat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
124 s->in2out.addr.as_u32,
125 s->out2in.addr.as_u32,
129 s->in2out.fib_index);
131 nat_syslog_nat44_sdel (s->user_index, s->in2out.fib_index,
132 &s->in2out.addr, s->in2out.port,
133 &s->ext_host_nat_addr, s->ext_host_nat_port,
134 &s->out2in.addr, s->out2in.port,
135 &s->ext_host_addr, s->ext_host_port,
136 s->in2out.protocol, is_twice_nat_session (s));
138 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
139 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
142 if (is_twice_nat_session (s))
144 for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
146 key.protocol = s->in2out.protocol;
147 key.port = s->ext_host_nat_port;
148 a = sm->twice_nat_addresses + i;
149 if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
151 snat_free_outside_address_and_port (sm->twice_nat_addresses,
159 if (snat_is_session_static (s))
162 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
165 nat44_delete_session (sm, s, ctx->thread_index);
174 icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
175 ip4_header_t * ip0, icmp46_header_t * icmp0,
176 u32 sw_if_index0, u32 rx_fib_index0,
177 vlib_node_runtime_t * node, u32 next0, f64 now,
178 u32 thread_index, snat_session_t ** p_s0)
180 next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
181 next0, thread_index, p_s0, 0);
182 snat_session_t *s0 = *p_s0;
183 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
186 nat44_session_update_counters (s0, now,
187 vlib_buffer_length_in_chain
188 (sm->vlib_main, b0), thread_index);
189 /* Per-user LRU list maintenance */
190 nat44_session_update_lru (sm, s0, thread_index);
195 static_always_inline u16
196 snat_random_port (u16 min, u16 max)
198 snat_main_t *sm = &snat_main;
199 return min + random_u32 (&sm->random_seed) /
200 (random_u32_max () / (max - min + 1) + 1);
204 nat_alloc_addr_and_port_ed (snat_address_t * addresses, u32 fib_index,
205 u32 thread_index, nat_ed_ses_key_t * key,
206 snat_session_key_t * key1, u16 port_per_thread,
207 u32 snat_thread_index)
210 snat_address_t *a, *ga = 0;
213 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
214 ed_bihash_kv_t bihash_key;
215 clib_memset (&bihash_key, 0, sizeof (bihash_key));
216 bihash_key.k.dst_address = key->r_addr.as_u32;
217 bihash_key.k.dst_port = key->r_port;
218 bihash_key.k.protocol = key1->protocol;
220 for (i = 0; i < vec_len (addresses); i++)
223 switch (key1->protocol)
225 #define _(N, j, n, s) \
226 case SNAT_PROTOCOL_##N: \
227 if (a->fib_index == fib_index) \
229 bihash_key.k.src_address = a->addr.as_u32; \
230 u16 port = snat_random_port (1, port_per_thread); \
231 u16 attempts = port_per_thread; \
232 while (attempts > 0) \
235 portnum = port_thread_offset + port; \
236 bihash_key.k.src_port = clib_host_to_net_u16 (portnum); \
237 int rv = clib_bihash_add_del_16_8 ( \
238 &snat_main.ed_ext_ports, &bihash_key.kv, 2 /* is_add */); \
241 ++a->busy_##n##_port_refcounts[portnum]; \
242 a->busy_##n##_ports_per_thread[thread_index]++; \
243 a->busy_##n##_ports++; \
244 key1->addr = a->addr; \
245 key1->port = clib_host_to_net_u16 (portnum); \
248 port = (port + 1) % port_per_thread; \
251 else if (a->fib_index == ~0) \
257 foreach_snat_protocol;
259 nat_elog_info ("unknown protocol");
266 /* fake fib_index to reuse macro */
269 switch (key1->protocol)
271 foreach_snat_protocol;
273 nat_elog_info ("unknown protocol");
280 /* Totally out of translations to use... */
281 snat_ipfix_logging_addresses_exhausted (thread_index, 0);
286 slow_path_ed (snat_main_t * sm,
289 clib_bihash_kv_16_8_t * kv,
290 snat_session_t ** sessionp,
291 vlib_node_runtime_t * node, u32 next, u32 thread_index, f64 now)
293 snat_session_t *s = 0;
295 snat_session_key_t key0, key1;
296 lb_nat_type_t lb = 0, is_sm = 0;
297 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
298 nat_ed_ses_key_t *key = (nat_ed_ses_key_t *) kv->key;
299 u32 proto = ip_proto_to_snat_proto (key->proto);
300 nat_outside_fib_t *outside_fib;
301 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
304 .fp_proto = FIB_PROTOCOL_IP4,
307 .ip4.as_u32 = key->r_addr.as_u32,
310 nat44_is_idle_session_ctx_t ctx;
314 if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
317 (!(cleared = nat44_users_cleanup (thread_index, now))))
319 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
320 nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
321 nat_elog_notice ("maximum sessions exceeded");
322 return NAT_NEXT_DROP;
326 key0.addr = key->l_addr;
327 key0.port = key->l_port;
328 key1.protocol = key0.protocol = proto;
329 key0.fib_index = rx_fib_index;
330 key1.fib_index = sm->outside_fib_index;
332 /* First try to match static mapping by local address and port */
333 if (snat_static_mapping_match
334 (sm, key0, &key1, 0, 0, 0, &lb, 0, &identity_nat))
336 /* Try to create dynamic translation */
337 if (nat_alloc_addr_and_port_ed (sm->addresses, rx_fib_index,
338 thread_index, key, &key1,
340 tsm->snat_thread_index))
342 if (cleared || !nat44_out_of_ports_cleanup (thread_index, now) ||
343 nat_alloc_addr_and_port_ed (sm->addresses, rx_fib_index,
344 thread_index, key, &key1,
346 tsm->snat_thread_index))
348 nat_elog_notice ("addresses exhausted");
349 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
350 return NAT_NEXT_DROP;
356 if (PREDICT_FALSE (identity_nat))
364 if (PREDICT_TRUE (proto == SNAT_PROTOCOL_TCP))
368 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
370 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
372 snat_free_outside_address_and_port (sm->addresses,
373 thread_index, &key1);
374 return NAT_NEXT_DROP;
378 u = nat_user_get_or_create (sm, &key->l_addr, rx_fib_index, thread_index);
381 nat_elog_warn ("create NAT user failed");
383 snat_free_outside_address_and_port (sm->addresses,
384 thread_index, &key1);
385 b->error = node->errors[NAT_IN2OUT_ED_ERROR_CANNOT_CREATE_USER];
386 return NAT_NEXT_DROP;
389 s = nat_ed_session_alloc (sm, u, thread_index, now);
392 nat44_delete_user_with_no_session (sm, u, thread_index);
393 nat_elog_warn ("create NAT session failed");
395 snat_free_outside_address_and_port (sm->addresses,
396 thread_index, &key1);
397 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
398 return NAT_NEXT_DROP;
401 user_session_increment (sm, u, is_sm);
403 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
405 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
406 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
407 s->ext_host_addr = key->r_addr;
408 s->ext_host_port = key->r_port;
411 s->out2in.protocol = key0.protocol;
413 switch (vec_len (sm->outside_fibs))
416 s->out2in.fib_index = sm->outside_fib_index;
419 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
423 vec_foreach (outside_fib, sm->outside_fibs)
425 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
426 if (FIB_NODE_INDEX_INVALID != fei)
428 if (fib_entry_get_resolving_interface (fei) != ~0)
430 s->out2in.fib_index = outside_fib->fib_index;
439 /* Add to lookup tables */
440 kv->value = s - tsm->sessions;
442 ctx.thread_index = thread_index;
443 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, kv,
444 nat44_i2o_ed_is_idle_session_cb,
446 nat_elog_notice ("in2out-ed key add failed");
448 make_ed_kv (kv, &key1.addr, &key->r_addr, key->proto, s->out2in.fib_index,
449 key1.port, key->r_port);
450 kv->value = s - tsm->sessions;
451 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->out2in_ed, kv,
452 nat44_o2i_ed_is_idle_session_cb,
454 nat_elog_notice ("out2in-ed key add failed");
459 snat_ipfix_logging_nat44_ses_create (thread_index,
460 s->in2out.addr.as_u32,
461 s->out2in.addr.as_u32,
464 s->out2in.port, s->in2out.fib_index);
466 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
467 &s->in2out.addr, s->in2out.port,
468 &s->ext_host_nat_addr, s->ext_host_nat_port,
469 &s->out2in.addr, s->out2in.port,
470 &s->ext_host_addr, s->ext_host_port,
471 s->in2out.protocol, 0);
473 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
474 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
475 &s->ext_host_nat_addr, s->ext_host_nat_port,
476 s->in2out.protocol, s->in2out.fib_index, s->flags,
482 static_always_inline int
483 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
484 u32 sw_if_index, ip4_header_t * ip, u32 proto,
485 u32 rx_fib_index, u32 thread_index)
487 udp_header_t *udp = ip4_next_header (ip);
488 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
489 clib_bihash_kv_16_8_t kv, value;
490 snat_session_key_t key0, key1;
492 make_ed_kv (&kv, &ip->dst_address, &ip->src_address, ip->protocol,
493 sm->outside_fib_index, udp->dst_port, udp->src_port);
495 /* NAT packet aimed at external address if */
496 /* has active sessions */
497 if (clib_bihash_search_16_8 (&tsm->out2in_ed, &kv, &value))
499 key0.addr = ip->dst_address;
500 key0.port = udp->dst_port;
501 key0.protocol = proto;
502 key0.fib_index = sm->outside_fib_index;
503 /* or is static mappings */
504 if (!snat_static_mapping_match (sm, key0, &key1, 1, 0, 0, 0, 0, 0))
510 if (sm->forwarding_enabled)
513 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
517 static_always_inline int
518 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
519 u32 thread_index, f64 now,
520 vlib_main_t * vm, vlib_buffer_t * b)
522 nat_ed_ses_key_t key;
523 clib_bihash_kv_16_8_t kv, value;
524 snat_session_t *s = 0;
525 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
527 if (!sm->forwarding_enabled)
530 if (ip->protocol == IP_PROTOCOL_ICMP)
532 key.as_u64[0] = key.as_u64[1] = 0;
533 if (get_icmp_i2o_ed_key (b, ip, &key))
536 kv.key[0] = key.as_u64[0];
537 kv.key[1] = key.as_u64[1];
539 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
541 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, ip->protocol, 0,
542 vnet_buffer (b)->ip.reass.l4_src_port,
543 vnet_buffer (b)->ip.reass.l4_dst_port);
547 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, ip->protocol, 0, 0,
551 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
553 s = pool_elt_at_index (tsm->sessions, value.value);
554 if (is_fwd_bypass_session (s))
556 if (ip->protocol == IP_PROTOCOL_TCP)
558 if (nat44_set_tcp_session_state_i2o
559 (sm, now, s, b, thread_index))
563 nat44_session_update_counters (s, now,
564 vlib_buffer_length_in_chain (vm, b),
566 /* Per-user LRU list maintenance */
567 nat44_session_update_lru (sm, s, thread_index);
577 static_always_inline int
578 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
579 u8 proto, u16 src_port, u16 dst_port,
580 u32 thread_index, u32 rx_sw_if_index,
583 clib_bihash_kv_16_8_t kv, value;
584 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
587 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
588 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
591 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, proto, tx_fib_index,
593 if (!clib_bihash_search_16_8 (&tsm->out2in_ed, &kv, &value))
595 s = pool_elt_at_index (tsm->sessions, value.value);
596 if (nat44_is_ses_closed (s))
598 nat_free_session_data (sm, s, thread_index, 0);
599 nat44_delete_session (sm, s, thread_index);
602 s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
607 make_ed_kv (&kv, &ip->dst_address, &ip->src_address, proto, rx_fib_index,
609 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
611 s = pool_elt_at_index (tsm->sessions, value.value);
612 if (is_fwd_bypass_session (s))
617 pool_foreach (i, sm->output_feature_interfaces,
619 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
629 #ifndef CLIB_MARCH_VARIANT
631 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
632 u32 thread_index, vlib_buffer_t * b, ip4_header_t * ip,
633 u8 * p_proto, snat_session_key_t * p_value,
634 u8 * p_dont_translate, void *d, void *e)
638 nat_ed_ses_key_t key;
639 snat_session_t *s = 0;
640 u8 dont_translate = 0;
641 clib_bihash_kv_16_8_t kv, value;
644 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
646 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
647 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
649 key.as_u64[0] = key.as_u64[1] = 0;
650 err = get_icmp_i2o_ed_key (b, ip, &key);
653 b->error = node->errors[err];
654 next = NAT_NEXT_DROP;
657 key.fib_index = rx_fib_index;
659 kv.key[0] = key.as_u64[0];
660 kv.key[1] = key.as_u64[1];
662 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
664 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
667 (nat44_ed_not_translate_output_feature
668 (sm, ip, key.proto, key.l_port, key.r_port, thread_index,
669 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
677 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
678 ip, SNAT_PROTOCOL_ICMP,
688 (icmp_type_is_error_message
689 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
691 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
692 next = NAT_NEXT_DROP;
696 next = slow_path_ed (sm, b, rx_fib_index, &kv, &s, node, next,
697 thread_index, vlib_time_now (sm->vlib_main));
699 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
711 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
713 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
715 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
716 reass.icmp_type_or_tcp_flags)))
718 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
719 next = NAT_NEXT_DROP;
723 s = pool_elt_at_index (tsm->sessions, value.value);
726 *p_proto = ip_proto_to_snat_proto (key.proto);
729 *p_value = s->out2in;
730 *p_dont_translate = dont_translate;
732 *(snat_session_t **) d = s;
737 static snat_session_t *
738 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
744 vlib_main_t * vm, vlib_node_runtime_t * node)
746 clib_bihash_kv_8_8_t kv, value;
747 clib_bihash_kv_16_8_t s_kv, s_value;
748 snat_static_mapping_t *m;
749 u32 old_addr, new_addr = 0;
752 dlist_elt_t *head, *elt;
753 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
754 u32 elt_index, head_index, ses_index;
756 u32 outside_fib_index = sm->outside_fib_index;
759 nat_outside_fib_t *outside_fib;
760 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
762 .fp_proto = FIB_PROTOCOL_IP4,
765 .ip4.as_u32 = ip->dst_address.as_u32,
769 switch (vec_len (sm->outside_fibs))
772 outside_fib_index = sm->outside_fib_index;
775 outside_fib_index = sm->outside_fibs[0].fib_index;
779 vec_foreach (outside_fib, sm->outside_fibs)
781 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
782 if (FIB_NODE_INDEX_INVALID != fei)
784 if (fib_entry_get_resolving_interface (fei) != ~0)
786 outside_fib_index = outside_fib->fib_index;
794 old_addr = ip->src_address.as_u32;
796 make_ed_kv (&s_kv, &ip->src_address, &ip->dst_address, ip->protocol,
799 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
801 s = pool_elt_at_index (tsm->sessions, s_value.value);
802 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
806 if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
808 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
809 nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
810 nat_elog_notice ("maximum sessions exceeded");
814 u = nat_user_get_or_create (sm, &ip->src_address, rx_fib_index,
818 b->error = node->errors[NAT_IN2OUT_ED_ERROR_CANNOT_CREATE_USER];
819 nat_elog_warn ("create NAT user failed");
823 make_sm_kv (&kv, &ip->src_address, 0, rx_fib_index, 0);
825 /* Try to find static mapping first */
826 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
828 m = pool_elt_at_index (sm->static_mappings, value.value);
829 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
833 /* Fallback to 3-tuple key */
836 /* Choose same out address as for TCP/UDP session to same destination */
837 head_index = u->sessions_per_user_list_head_index;
838 head = pool_elt_at_index (tsm->list_pool, head_index);
839 elt_index = head->next;
840 if (PREDICT_FALSE (elt_index == ~0))
844 elt = pool_elt_at_index (tsm->list_pool, elt_index);
845 ses_index = elt->value;
848 while (ses_index != ~0)
850 s = pool_elt_at_index (tsm->sessions, ses_index);
851 elt_index = elt->next;
852 elt = pool_elt_at_index (tsm->list_pool, elt_index);
853 ses_index = elt->value;
855 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
857 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
859 make_ed_kv (&s_kv, &s->out2in.addr, &ip->dst_address,
860 ip->protocol, outside_fib_index, 0, 0);
861 if (clib_bihash_search_16_8
862 (&tsm->out2in_ed, &s_kv, &s_value))
869 for (i = 0; i < vec_len (sm->addresses); i++)
871 make_ed_kv (&s_kv, &sm->addresses[i].addr, &ip->dst_address,
872 ip->protocol, outside_fib_index, 0, 0);
873 if (clib_bihash_search_16_8 (&tsm->out2in_ed, &s_kv, &s_value))
875 new_addr = ip->src_address.as_u32 =
876 sm->addresses[i].addr.as_u32;
884 s = nat_ed_session_alloc (sm, u, thread_index, now);
887 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
888 nat44_delete_user_with_no_session (sm, u, thread_index);
889 nat_elog_warn ("create NAT session failed");
893 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
894 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
895 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
896 s->out2in.addr.as_u32 = new_addr;
897 s->out2in.fib_index = outside_fib_index;
898 s->in2out.addr.as_u32 = old_addr;
899 s->in2out.fib_index = rx_fib_index;
900 s->in2out.port = s->out2in.port = ip->protocol;
902 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
903 user_session_increment (sm, u, is_sm);
905 /* Add to lookup tables */
906 make_ed_kv (&s_kv, &s->in2out.addr, &ip->dst_address, ip->protocol,
908 s_kv.value = s - tsm->sessions;
909 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
910 nat_elog_notice ("in2out key add failed");
912 make_ed_kv (&s_kv, &s->out2in.addr, &ip->dst_address, ip->protocol,
913 outside_fib_index, 0, 0);
914 s_kv.value = s - tsm->sessions;
915 if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &s_kv, 1))
916 nat_elog_notice ("out2in key add failed");
919 /* Update IP checksum */
921 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
922 ip->checksum = ip_csum_fold (sum);
925 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
927 /* Per-user LRU list maintenance */
928 nat44_session_update_lru (sm, s, thread_index);
931 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
932 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
934 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
935 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
941 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
942 vlib_node_runtime_t * node,
943 vlib_frame_t * frame,
944 int is_output_feature)
946 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
947 nat_next_t next_index;
948 snat_main_t *sm = &snat_main;
949 f64 now = vlib_time_now (vm);
950 u32 thread_index = vm->thread_index;
951 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
952 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
955 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH :
956 NAT_NEXT_IN2OUT_ED_SLOW_PATH;
958 stats_node_index = sm->ed_in2out_node_index;
960 from = vlib_frame_vector_args (frame);
961 n_left_from = frame->n_vectors;
962 next_index = node->cached_next_index;
964 while (n_left_from > 0)
968 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
970 while (n_left_from > 0 && n_left_to_next > 0)
974 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
975 new_addr0, old_addr0;
976 u16 old_port0, new_port0;
980 snat_session_t *s0 = 0;
981 clib_bihash_kv_16_8_t kv0, value0;
984 /* speculatively enqueue b0 to the current next frame */
992 b0 = vlib_get_buffer (vm, bi0);
994 if (is_output_feature)
996 vnet_feature_next (&nat_buffer_opaque (b0)->arc_next, b0);
997 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1000 next0 = nat_buffer_opaque (b0)->arc_next;
1002 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1005 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1007 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1010 if (PREDICT_FALSE (ip0->ttl == 1))
1012 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1013 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1014 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1016 next0 = NAT_NEXT_ICMP_ERROR;
1020 udp0 = ip4_next_header (ip0);
1021 tcp0 = (tcp_header_t *) udp0;
1022 proto0 = ip_proto_to_snat_proto (ip0->protocol);
1024 if (PREDICT_FALSE (proto0 == ~0))
1030 if (is_output_feature)
1032 if (PREDICT_FALSE (nat_not_translate_output_feature_fwd
1033 (sm, ip0, thread_index, now, vm, b0)))
1037 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
1043 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
1044 ip0->protocol, rx_fib_index0,
1045 vnet_buffer (b0)->ip.reass.l4_src_port,
1046 vnet_buffer (b0)->ip.reass.l4_dst_port);
1048 // lookup for session
1049 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1051 // session does not exist go slow path
1055 s0 = pool_elt_at_index (tsm->sessions, value0.value);
1057 if (s0->tcp_close_timestamp)
1059 if (now >= s0->tcp_close_timestamp)
1061 // session is closed, go slow path
1066 // session in transitory timeout, drop
1067 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1068 next0 = NAT_NEXT_DROP;
1073 // drop if session expired
1074 u64 sess_timeout_time;
1075 sess_timeout_time = s0->last_heard +
1076 (f64) nat44_session_get_timeout (sm, s0);
1077 if (now >= sess_timeout_time)
1079 nat_free_session_data (sm, s0, thread_index, 0);
1080 nat44_delete_session (sm, s0, thread_index);
1081 // session is closed, go slow path
1086 b0->flags |= VNET_BUFFER_F_IS_NATED;
1088 if (!is_output_feature)
1089 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1091 old_addr0 = ip0->src_address.as_u32;
1092 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1093 sum0 = ip0->checksum;
1094 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1096 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1097 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1098 s0->ext_host_addr.as_u32, ip4_header_t,
1100 ip0->checksum = ip_csum_fold (sum0);
1102 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1104 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
1106 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1108 new_port0 = udp0->src_port = s0->out2in.port;
1109 sum0 = tcp0->checksum;
1111 ip_csum_update (sum0, old_addr0, new_addr0,
1112 ip4_header_t, dst_address);
1114 ip_csum_update (sum0, old_port0, new_port0,
1115 ip4_header_t, length);
1116 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1119 ip_csum_update (sum0, ip0->dst_address.as_u32,
1120 s0->ext_host_addr.as_u32,
1121 ip4_header_t, dst_address);
1123 ip_csum_update (sum0,
1124 vnet_buffer (b0)->ip.
1125 reass.l4_dst_port, s0->ext_host_port,
1126 ip4_header_t, length);
1127 tcp0->dst_port = s0->ext_host_port;
1128 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1130 mss_clamping (sm, tcp0, &sum0);
1131 tcp0->checksum = ip_csum_fold (sum0);
1134 if (nat44_set_tcp_session_state_i2o
1135 (sm, now, s0, b0, thread_index))
1138 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1141 new_port0 = udp0->src_port = s0->out2in.port;
1142 sum0 = udp0->checksum;
1144 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1147 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1149 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1151 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1152 s0->ext_host_addr.as_u32,
1153 ip4_header_t, dst_address);
1155 ip_csum_update (sum0,
1156 vnet_buffer (b0)->ip.reass.l4_dst_port,
1157 s0->ext_host_port, ip4_header_t, length);
1158 udp0->dst_port = s0->ext_host_port;
1159 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1161 udp0->checksum = ip_csum_fold (sum0);
1166 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1168 new_port0 = udp0->src_port = s0->out2in.port;
1169 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1171 udp0->dst_port = s0->ext_host_port;
1172 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1179 nat44_session_update_counters (s0, now,
1180 vlib_buffer_length_in_chain
1181 (vm, b0), thread_index);
1182 /* Per-user LRU list maintenance */
1183 nat44_session_update_lru (sm, s0, thread_index);
1186 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1187 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1189 nat_in2out_ed_trace_t *t =
1190 vlib_add_trace (vm, node, b0, sizeof (*t));
1191 t->sw_if_index = sw_if_index0;
1192 t->next_index = next0;
1193 t->is_slow_path = 0;
1196 t->session_index = s0 - tsm->sessions;
1198 t->session_index = ~0;
1201 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1202 /* verify speculative enqueue, maybe switch current next frame */
1203 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1204 to_next, n_left_to_next,
1208 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1211 vlib_node_increment_counter (vm, stats_node_index,
1212 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1214 vlib_node_increment_counter (vm, stats_node_index,
1215 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1216 vlib_node_increment_counter (vm, stats_node_index,
1217 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1218 vlib_node_increment_counter (vm, stats_node_index,
1219 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1221 vlib_node_increment_counter (vm, stats_node_index,
1222 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1224 return frame->n_vectors;
1228 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1229 vlib_node_runtime_t * node,
1230 vlib_frame_t * frame,
1231 int is_output_feature)
1233 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
1234 nat_next_t next_index;
1235 snat_main_t *sm = &snat_main;
1236 f64 now = vlib_time_now (vm);
1237 u32 thread_index = vm->thread_index;
1238 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1239 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1241 stats_node_index = sm->ed_in2out_slowpath_node_index;
1243 from = vlib_frame_vector_args (frame);
1244 n_left_from = frame->n_vectors;
1245 next_index = node->cached_next_index;
1247 while (n_left_from > 0)
1251 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1253 while (n_left_from > 0 && n_left_to_next > 0)
1257 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
1258 new_addr0, old_addr0;
1259 u16 old_port0, new_port0;
1263 icmp46_header_t *icmp0;
1264 snat_session_t *s0 = 0;
1265 clib_bihash_kv_16_8_t kv0, value0;
1268 /* speculatively enqueue b0 to the current next frame */
1274 n_left_to_next -= 1;
1276 b0 = vlib_get_buffer (vm, bi0);
1278 if (is_output_feature)
1279 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1281 next0 = nat_buffer_opaque (b0)->arc_next;
1283 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1286 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1288 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1291 if (PREDICT_FALSE (ip0->ttl == 1))
1293 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1294 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1295 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1297 next0 = NAT_NEXT_ICMP_ERROR;
1301 udp0 = ip4_next_header (ip0);
1302 tcp0 = (tcp_header_t *) udp0;
1303 icmp0 = (icmp46_header_t *) udp0;
1304 proto0 = ip_proto_to_snat_proto (ip0->protocol);
1306 if (PREDICT_FALSE (proto0 == ~0))
1308 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1313 next0 = NAT_NEXT_DROP;
1319 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
1321 next0 = icmp_in2out_ed_slow_path
1322 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1323 node, next0, now, thread_index, &s0);
1329 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
1330 ip0->protocol, rx_fib_index0,
1331 vnet_buffer (b0)->ip.reass.l4_src_port,
1332 vnet_buffer (b0)->ip.reass.l4_dst_port);
1334 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1336 s0 = pool_elt_at_index (tsm->sessions, value0.value);
1338 if (s0->tcp_close_timestamp && now >= s0->tcp_close_timestamp)
1340 nat_free_session_data (sm, s0, thread_index, 0);
1341 nat44_delete_session (sm, s0, thread_index);
1348 if (is_output_feature)
1351 (nat44_ed_not_translate_output_feature
1352 (sm, ip0, ip0->protocol,
1353 vnet_buffer (b0)->ip.reass.l4_src_port,
1354 vnet_buffer (b0)->ip.reass.l4_dst_port,
1355 thread_index, sw_if_index0,
1356 vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1360 * Send DHCP packets to the ipv4 stack, or we won't
1361 * be able to use dhcp client on the outside interface
1364 (proto0 == SNAT_PROTOCOL_UDP
1365 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1366 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1367 && ip0->dst_address.as_u32 == 0xffffffff))
1373 (nat44_ed_not_translate
1374 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1379 next0 = slow_path_ed (sm, b0, rx_fib_index0, &kv0, &s0, node,
1380 next0, thread_index, now);
1382 if (PREDICT_FALSE (next0 == NAT_NEXT_DROP))
1385 if (PREDICT_FALSE (!s0))
1390 b0->flags |= VNET_BUFFER_F_IS_NATED;
1392 if (!is_output_feature)
1393 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1395 old_addr0 = ip0->src_address.as_u32;
1396 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1397 sum0 = ip0->checksum;
1398 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1400 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1401 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1402 s0->ext_host_addr.as_u32, ip4_header_t,
1404 ip0->checksum = ip_csum_fold (sum0);
1406 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1408 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
1410 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1412 new_port0 = udp0->src_port = s0->out2in.port;
1413 sum0 = tcp0->checksum;
1415 ip_csum_update (sum0, old_addr0, new_addr0,
1416 ip4_header_t, dst_address);
1418 ip_csum_update (sum0, old_port0, new_port0,
1419 ip4_header_t, length);
1420 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1423 ip_csum_update (sum0, ip0->dst_address.as_u32,
1424 s0->ext_host_addr.as_u32,
1425 ip4_header_t, dst_address);
1427 ip_csum_update (sum0,
1428 vnet_buffer (b0)->ip.
1429 reass.l4_dst_port, s0->ext_host_port,
1430 ip4_header_t, length);
1431 tcp0->dst_port = s0->ext_host_port;
1432 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1434 mss_clamping (sm, tcp0, &sum0);
1435 tcp0->checksum = ip_csum_fold (sum0);
1438 if (nat44_set_tcp_session_state_i2o
1439 (sm, now, s0, b0, thread_index))
1442 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1445 new_port0 = udp0->src_port = s0->out2in.port;
1446 sum0 = udp0->checksum;
1448 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1451 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1453 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1455 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1456 s0->ext_host_addr.as_u32,
1457 ip4_header_t, dst_address);
1459 ip_csum_update (sum0,
1460 vnet_buffer (b0)->ip.reass.l4_dst_port,
1461 s0->ext_host_port, ip4_header_t, length);
1462 udp0->dst_port = s0->ext_host_port;
1463 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1465 udp0->checksum = ip_csum_fold (sum0);
1470 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1472 new_port0 = udp0->src_port = s0->out2in.port;
1473 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1475 udp0->dst_port = s0->ext_host_port;
1476 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1483 nat44_session_update_counters (s0, now,
1484 vlib_buffer_length_in_chain
1485 (vm, b0), thread_index);
1486 /* Per-user LRU list maintenance */
1487 nat44_session_update_lru (sm, s0, thread_index);
1490 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1491 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1493 nat_in2out_ed_trace_t *t =
1494 vlib_add_trace (vm, node, b0, sizeof (*t));
1495 t->sw_if_index = sw_if_index0;
1496 t->next_index = next0;
1497 t->is_slow_path = 1;
1500 t->session_index = s0 - tsm->sessions;
1502 t->session_index = ~0;
1505 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1507 /* verify speculative enqueue, maybe switch current next frame */
1508 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1509 to_next, n_left_to_next,
1513 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1516 vlib_node_increment_counter (vm, stats_node_index,
1517 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1519 vlib_node_increment_counter (vm, stats_node_index,
1520 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1521 vlib_node_increment_counter (vm, stats_node_index,
1522 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1523 vlib_node_increment_counter (vm, stats_node_index,
1524 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1526 vlib_node_increment_counter (vm, stats_node_index,
1527 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1529 return frame->n_vectors;
1532 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1533 vlib_node_runtime_t * node,
1534 vlib_frame_t * frame)
1536 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1540 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1541 .name = "nat44-ed-in2out",
1542 .vector_size = sizeof (u32),
1543 .sibling_of = "nat-default",
1544 .format_trace = format_nat_in2out_ed_trace,
1545 .type = VLIB_NODE_TYPE_INTERNAL,
1546 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1547 .error_strings = nat_in2out_ed_error_strings,
1548 .runtime_data_bytes = sizeof (snat_runtime_t),
1552 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1553 vlib_node_runtime_t * node,
1554 vlib_frame_t * frame)
1556 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1560 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1561 .name = "nat44-ed-in2out-output",
1562 .vector_size = sizeof (u32),
1563 .sibling_of = "nat-default",
1564 .format_trace = format_nat_in2out_ed_trace,
1565 .type = VLIB_NODE_TYPE_INTERNAL,
1566 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1567 .error_strings = nat_in2out_ed_error_strings,
1568 .runtime_data_bytes = sizeof (snat_runtime_t),
1572 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1573 vlib_node_runtime_t *
1574 node, vlib_frame_t * frame)
1576 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1580 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1581 .name = "nat44-ed-in2out-slowpath",
1582 .vector_size = sizeof (u32),
1583 .sibling_of = "nat-default",
1584 .format_trace = format_nat_in2out_ed_trace,
1585 .type = VLIB_NODE_TYPE_INTERNAL,
1586 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1587 .error_strings = nat_in2out_ed_error_strings,
1588 .runtime_data_bytes = sizeof (snat_runtime_t),
1592 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1595 vlib_frame_t * frame)
1597 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1601 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1602 .name = "nat44-ed-in2out-output-slowpath",
1603 .vector_size = sizeof (u32),
1604 .sibling_of = "nat-default",
1605 .format_trace = format_nat_in2out_ed_trace,
1606 .type = VLIB_NODE_TYPE_INTERNAL,
1607 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1608 .error_strings = nat_in2out_ed_error_strings,
1609 .runtime_data_bytes = sizeof (snat_runtime_t),
1614 format_nat_pre_trace (u8 * s, va_list * args)
1616 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1617 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1618 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1619 return format (s, "in2out next_index %d", t->next_index);
1622 VLIB_NODE_FN (nat_pre_in2out_node)
1623 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1625 return nat_pre_node_fn_inline (vm, node, frame,
1626 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1630 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1631 .name = "nat-pre-in2out",
1632 .vector_size = sizeof (u32),
1633 .sibling_of = "nat-default",
1634 .format_trace = format_nat_pre_trace,
1635 .type = VLIB_NODE_TYPE_INTERNAL,
1641 * fd.io coding-style-patch-verification: ON
1644 * eval: (c-set-style "gnu")