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 =
954 u32 tcp_closed_drops = 0;
956 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH :
957 NAT_NEXT_IN2OUT_ED_SLOW_PATH;
959 stats_node_index = sm->ed_in2out_node_index;
961 from = vlib_frame_vector_args (frame);
962 n_left_from = frame->n_vectors;
963 next_index = node->cached_next_index;
965 while (n_left_from > 0)
969 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
971 while (n_left_from > 0 && n_left_to_next > 0)
975 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
976 new_addr0, old_addr0;
977 u16 old_port0, new_port0;
981 snat_session_t *s0 = 0;
982 clib_bihash_kv_16_8_t kv0, value0;
985 /* speculatively enqueue b0 to the current next frame */
993 b0 = vlib_get_buffer (vm, bi0);
995 if (is_output_feature)
997 vnet_feature_next (&nat_buffer_opaque (b0)->arc_next, b0);
998 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1001 next0 = nat_buffer_opaque (b0)->arc_next;
1003 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1006 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1008 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1011 if (PREDICT_FALSE (ip0->ttl == 1))
1013 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1014 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1015 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1017 next0 = NAT_NEXT_ICMP_ERROR;
1021 udp0 = ip4_next_header (ip0);
1022 tcp0 = (tcp_header_t *) udp0;
1023 proto0 = ip_proto_to_snat_proto (ip0->protocol);
1025 if (PREDICT_FALSE (proto0 == ~0))
1031 if (is_output_feature)
1033 if (PREDICT_FALSE (nat_not_translate_output_feature_fwd
1034 (sm, ip0, thread_index, now, vm, b0)))
1038 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
1044 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
1045 ip0->protocol, rx_fib_index0,
1046 vnet_buffer (b0)->ip.reass.l4_src_port,
1047 vnet_buffer (b0)->ip.reass.l4_dst_port);
1049 // lookup for session
1050 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1052 // session does not exist go slow path
1056 s0 = pool_elt_at_index (tsm->sessions, value0.value);
1058 if (s0->tcp_close_timestamp)
1060 if (now >= s0->tcp_close_timestamp)
1062 // session is closed, go slow path
1067 // session in transitory timeout, drop
1069 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1070 next0 = NAT_NEXT_DROP;
1075 // drop if session expired
1076 u64 sess_timeout_time;
1077 sess_timeout_time = s0->last_heard +
1078 (f64) nat44_session_get_timeout (sm, s0);
1079 if (now >= sess_timeout_time)
1082 nat_free_session_data (sm, s0, thread_index, 0);
1083 nat44_delete_session (sm, s0, thread_index);
1085 // session no longer exists, go slow path
1090 b0->flags |= VNET_BUFFER_F_IS_NATED;
1092 if (!is_output_feature)
1093 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1095 old_addr0 = ip0->src_address.as_u32;
1096 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1097 sum0 = ip0->checksum;
1098 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1100 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1101 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1102 s0->ext_host_addr.as_u32, ip4_header_t,
1104 ip0->checksum = ip_csum_fold (sum0);
1106 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1108 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
1110 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1112 new_port0 = udp0->src_port = s0->out2in.port;
1113 sum0 = tcp0->checksum;
1115 ip_csum_update (sum0, old_addr0, new_addr0,
1116 ip4_header_t, dst_address);
1118 ip_csum_update (sum0, old_port0, new_port0,
1119 ip4_header_t, length);
1120 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1123 ip_csum_update (sum0, ip0->dst_address.as_u32,
1124 s0->ext_host_addr.as_u32,
1125 ip4_header_t, dst_address);
1127 ip_csum_update (sum0,
1128 vnet_buffer (b0)->ip.
1129 reass.l4_dst_port, s0->ext_host_port,
1130 ip4_header_t, length);
1131 tcp0->dst_port = s0->ext_host_port;
1132 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1134 mss_clamping (sm, tcp0, &sum0);
1135 tcp0->checksum = ip_csum_fold (sum0);
1138 if (nat44_set_tcp_session_state_i2o
1139 (sm, now, s0, b0, thread_index))
1142 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1145 new_port0 = udp0->src_port = s0->out2in.port;
1146 sum0 = udp0->checksum;
1148 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1151 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1153 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1155 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1156 s0->ext_host_addr.as_u32,
1157 ip4_header_t, dst_address);
1159 ip_csum_update (sum0,
1160 vnet_buffer (b0)->ip.reass.l4_dst_port,
1161 s0->ext_host_port, ip4_header_t, length);
1162 udp0->dst_port = s0->ext_host_port;
1163 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1165 udp0->checksum = ip_csum_fold (sum0);
1170 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1172 new_port0 = udp0->src_port = s0->out2in.port;
1173 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1175 udp0->dst_port = s0->ext_host_port;
1176 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1183 nat44_session_update_counters (s0, now,
1184 vlib_buffer_length_in_chain
1185 (vm, b0), thread_index);
1186 /* Per-user LRU list maintenance */
1187 nat44_session_update_lru (sm, s0, thread_index);
1190 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1191 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1193 nat_in2out_ed_trace_t *t =
1194 vlib_add_trace (vm, node, b0, sizeof (*t));
1195 t->sw_if_index = sw_if_index0;
1196 t->next_index = next0;
1197 t->is_slow_path = 0;
1200 t->session_index = s0 - tsm->sessions;
1202 t->session_index = ~0;
1205 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1206 /* verify speculative enqueue, maybe switch current next frame */
1207 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1208 to_next, n_left_to_next,
1212 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1215 vlib_node_increment_counter (vm, stats_node_index,
1216 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1218 vlib_node_increment_counter (vm, stats_node_index,
1219 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1220 vlib_node_increment_counter (vm, stats_node_index,
1221 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1222 vlib_node_increment_counter (vm, stats_node_index,
1223 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1225 vlib_node_increment_counter (vm, stats_node_index,
1226 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1228 return frame->n_vectors;
1232 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1233 vlib_node_runtime_t * node,
1234 vlib_frame_t * frame,
1235 int is_output_feature)
1237 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
1238 nat_next_t next_index;
1239 snat_main_t *sm = &snat_main;
1240 f64 now = vlib_time_now (vm);
1241 u32 thread_index = vm->thread_index;
1242 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1243 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1245 stats_node_index = sm->ed_in2out_slowpath_node_index;
1247 from = vlib_frame_vector_args (frame);
1248 n_left_from = frame->n_vectors;
1249 next_index = node->cached_next_index;
1251 while (n_left_from > 0)
1255 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1257 while (n_left_from > 0 && n_left_to_next > 0)
1261 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
1262 new_addr0, old_addr0;
1263 u16 old_port0, new_port0;
1267 icmp46_header_t *icmp0;
1268 snat_session_t *s0 = 0;
1269 clib_bihash_kv_16_8_t kv0, value0;
1272 /* speculatively enqueue b0 to the current next frame */
1278 n_left_to_next -= 1;
1280 b0 = vlib_get_buffer (vm, bi0);
1282 if (is_output_feature)
1283 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1285 next0 = nat_buffer_opaque (b0)->arc_next;
1287 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1290 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1292 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1295 if (PREDICT_FALSE (ip0->ttl == 1))
1297 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1298 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1299 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1301 next0 = NAT_NEXT_ICMP_ERROR;
1305 udp0 = ip4_next_header (ip0);
1306 tcp0 = (tcp_header_t *) udp0;
1307 icmp0 = (icmp46_header_t *) udp0;
1308 proto0 = ip_proto_to_snat_proto (ip0->protocol);
1310 if (PREDICT_FALSE (proto0 == ~0))
1312 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1317 next0 = NAT_NEXT_DROP;
1323 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
1325 next0 = icmp_in2out_ed_slow_path
1326 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1327 node, next0, now, thread_index, &s0);
1333 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
1334 ip0->protocol, rx_fib_index0,
1335 vnet_buffer (b0)->ip.reass.l4_src_port,
1336 vnet_buffer (b0)->ip.reass.l4_dst_port);
1338 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1340 s0 = pool_elt_at_index (tsm->sessions, value0.value);
1342 if (s0->tcp_close_timestamp && now >= s0->tcp_close_timestamp)
1344 nat_free_session_data (sm, s0, thread_index, 0);
1345 nat44_delete_session (sm, s0, thread_index);
1352 if (is_output_feature)
1355 (nat44_ed_not_translate_output_feature
1356 (sm, ip0, ip0->protocol,
1357 vnet_buffer (b0)->ip.reass.l4_src_port,
1358 vnet_buffer (b0)->ip.reass.l4_dst_port,
1359 thread_index, sw_if_index0,
1360 vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1364 * Send DHCP packets to the ipv4 stack, or we won't
1365 * be able to use dhcp client on the outside interface
1368 (proto0 == SNAT_PROTOCOL_UDP
1369 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1370 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1371 && ip0->dst_address.as_u32 == 0xffffffff))
1377 (nat44_ed_not_translate
1378 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1383 next0 = slow_path_ed (sm, b0, rx_fib_index0, &kv0, &s0, node,
1384 next0, thread_index, now);
1386 if (PREDICT_FALSE (next0 == NAT_NEXT_DROP))
1389 if (PREDICT_FALSE (!s0))
1394 b0->flags |= VNET_BUFFER_F_IS_NATED;
1396 if (!is_output_feature)
1397 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1399 old_addr0 = ip0->src_address.as_u32;
1400 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1401 sum0 = ip0->checksum;
1402 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1404 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1405 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1406 s0->ext_host_addr.as_u32, ip4_header_t,
1408 ip0->checksum = ip_csum_fold (sum0);
1410 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1412 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
1414 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1416 new_port0 = udp0->src_port = s0->out2in.port;
1417 sum0 = tcp0->checksum;
1419 ip_csum_update (sum0, old_addr0, new_addr0,
1420 ip4_header_t, dst_address);
1422 ip_csum_update (sum0, old_port0, new_port0,
1423 ip4_header_t, length);
1424 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1427 ip_csum_update (sum0, ip0->dst_address.as_u32,
1428 s0->ext_host_addr.as_u32,
1429 ip4_header_t, dst_address);
1431 ip_csum_update (sum0,
1432 vnet_buffer (b0)->ip.
1433 reass.l4_dst_port, s0->ext_host_port,
1434 ip4_header_t, length);
1435 tcp0->dst_port = s0->ext_host_port;
1436 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1438 mss_clamping (sm, tcp0, &sum0);
1439 tcp0->checksum = ip_csum_fold (sum0);
1442 if (nat44_set_tcp_session_state_i2o
1443 (sm, now, s0, b0, thread_index))
1446 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1449 new_port0 = udp0->src_port = s0->out2in.port;
1450 sum0 = udp0->checksum;
1452 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1455 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1457 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1459 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1460 s0->ext_host_addr.as_u32,
1461 ip4_header_t, dst_address);
1463 ip_csum_update (sum0,
1464 vnet_buffer (b0)->ip.reass.l4_dst_port,
1465 s0->ext_host_port, ip4_header_t, length);
1466 udp0->dst_port = s0->ext_host_port;
1467 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1469 udp0->checksum = ip_csum_fold (sum0);
1474 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1476 new_port0 = udp0->src_port = s0->out2in.port;
1477 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1479 udp0->dst_port = s0->ext_host_port;
1480 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1487 nat44_session_update_counters (s0, now,
1488 vlib_buffer_length_in_chain
1489 (vm, b0), thread_index);
1490 /* Per-user LRU list maintenance */
1491 nat44_session_update_lru (sm, s0, thread_index);
1494 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1495 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1497 nat_in2out_ed_trace_t *t =
1498 vlib_add_trace (vm, node, b0, sizeof (*t));
1499 t->sw_if_index = sw_if_index0;
1500 t->next_index = next0;
1501 t->is_slow_path = 1;
1504 t->session_index = s0 - tsm->sessions;
1506 t->session_index = ~0;
1509 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1511 /* verify speculative enqueue, maybe switch current next frame */
1512 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1513 to_next, n_left_to_next,
1517 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1520 vlib_node_increment_counter (vm, stats_node_index,
1521 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1523 vlib_node_increment_counter (vm, stats_node_index,
1524 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1525 vlib_node_increment_counter (vm, stats_node_index,
1526 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1527 vlib_node_increment_counter (vm, stats_node_index,
1528 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1530 vlib_node_increment_counter (vm, stats_node_index,
1531 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1533 return frame->n_vectors;
1536 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1537 vlib_node_runtime_t * node,
1538 vlib_frame_t * frame)
1540 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1544 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1545 .name = "nat44-ed-in2out",
1546 .vector_size = sizeof (u32),
1547 .sibling_of = "nat-default",
1548 .format_trace = format_nat_in2out_ed_trace,
1549 .type = VLIB_NODE_TYPE_INTERNAL,
1550 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1551 .error_strings = nat_in2out_ed_error_strings,
1552 .runtime_data_bytes = sizeof (snat_runtime_t),
1556 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1557 vlib_node_runtime_t * node,
1558 vlib_frame_t * frame)
1560 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1564 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1565 .name = "nat44-ed-in2out-output",
1566 .vector_size = sizeof (u32),
1567 .sibling_of = "nat-default",
1568 .format_trace = format_nat_in2out_ed_trace,
1569 .type = VLIB_NODE_TYPE_INTERNAL,
1570 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1571 .error_strings = nat_in2out_ed_error_strings,
1572 .runtime_data_bytes = sizeof (snat_runtime_t),
1576 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1577 vlib_node_runtime_t *
1578 node, vlib_frame_t * frame)
1580 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1584 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1585 .name = "nat44-ed-in2out-slowpath",
1586 .vector_size = sizeof (u32),
1587 .sibling_of = "nat-default",
1588 .format_trace = format_nat_in2out_ed_trace,
1589 .type = VLIB_NODE_TYPE_INTERNAL,
1590 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1591 .error_strings = nat_in2out_ed_error_strings,
1592 .runtime_data_bytes = sizeof (snat_runtime_t),
1596 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1599 vlib_frame_t * frame)
1601 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1605 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1606 .name = "nat44-ed-in2out-output-slowpath",
1607 .vector_size = sizeof (u32),
1608 .sibling_of = "nat-default",
1609 .format_trace = format_nat_in2out_ed_trace,
1610 .type = VLIB_NODE_TYPE_INTERNAL,
1611 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1612 .error_strings = nat_in2out_ed_error_strings,
1613 .runtime_data_bytes = sizeof (snat_runtime_t),
1618 format_nat_pre_trace (u8 * s, va_list * args)
1620 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1621 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1622 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1623 return format (s, "in2out next_index %d", t->next_index);
1626 VLIB_NODE_FN (nat_pre_in2out_node)
1627 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1629 return nat_pre_node_fn_inline (vm, node, frame,
1630 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1634 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1635 .name = "nat-pre-in2out",
1636 .vector_size = sizeof (u32),
1637 .sibling_of = "nat-default",
1638 .format_trace = format_nat_pre_trace,
1639 .type = VLIB_NODE_TYPE_INTERNAL,
1645 * fd.io coding-style-patch-verification: ON
1648 * eval: (c-set-style "gnu")