2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * @brief NAT44 endpoint-dependent inside to outside network translation
20 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
22 #include <vnet/pg/pg.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/fib/ip4_fib.h>
26 #include <vnet/udp/udp.h>
27 #include <vppinfra/error.h>
29 #include <nat/nat_ipfix_logging.h>
30 #include <nat/nat_inlines.h>
31 #include <nat/nat44/inlines.h>
32 #include <nat/nat_syslog.h>
33 #include <nat/nat_ha.h>
35 static char *nat_in2out_ed_error_strings[] = {
36 #define _(sym,string) string,
37 foreach_nat_in2out_ed_error
47 } nat_in2out_ed_trace_t;
50 format_nat_in2out_ed_trace (u8 * s, va_list * args)
52 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
53 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
54 nat_in2out_ed_trace_t *t = va_arg (*args, nat_in2out_ed_trace_t *);
58 t->is_slow_path ? "NAT44_IN2OUT_ED_SLOW_PATH" :
59 "NAT44_IN2OUT_ED_FAST_PATH";
61 s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
62 t->sw_if_index, t->next_index, t->session_index);
67 #ifndef CLIB_MARCH_VARIANT
69 nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t * kv, void *arg)
71 snat_main_t *sm = &snat_main;
72 nat44_is_idle_session_ctx_t *ctx = arg;
74 u64 sess_timeout_time;
75 nat_ed_ses_key_t ed_key;
76 clib_bihash_kv_16_8_t ed_kv;
79 snat_session_key_t key;
80 snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
83 s = pool_elt_at_index (tsm->sessions, kv->value);
84 sess_timeout_time = s->last_heard + (f64) nat44_session_get_timeout (sm, s);
85 if (ctx->now >= sess_timeout_time)
87 if (is_fwd_bypass_session (s))
90 ed_key.l_addr = s->out2in.addr;
91 ed_key.r_addr = s->ext_host_addr;
92 ed_key.fib_index = s->out2in.fib_index;
93 if (snat_is_unk_proto_session (s))
95 ed_key.proto = s->in2out.port;
101 ed_key.proto = snat_proto_to_ip_proto (s->in2out.protocol);
102 ed_key.l_port = s->out2in.port;
103 ed_key.r_port = s->ext_host_port;
105 ed_kv.key[0] = ed_key.as_u64[0];
106 ed_kv.key[1] = ed_key.as_u64[1];
107 if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &ed_kv, 0))
108 nat_elog_warn ("out2in_ed key del failed");
110 if (snat_is_unk_proto_session (s))
113 snat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
114 s->in2out.addr.as_u32,
115 s->out2in.addr.as_u32,
119 s->in2out.fib_index);
121 nat_syslog_nat44_sdel (s->user_index, s->in2out.fib_index,
122 &s->in2out.addr, s->in2out.port,
123 &s->ext_host_nat_addr, s->ext_host_nat_port,
124 &s->out2in.addr, s->out2in.port,
125 &s->ext_host_addr, s->ext_host_port,
126 s->in2out.protocol, is_twice_nat_session (s));
128 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
129 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
132 if (is_twice_nat_session (s))
134 for (i = 0; i < vec_len (sm->twice_nat_addresses); i++)
136 key.protocol = s->in2out.protocol;
137 key.port = s->ext_host_nat_port;
138 a = sm->twice_nat_addresses + i;
139 if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32)
141 snat_free_outside_address_and_port (sm->twice_nat_addresses,
149 if (snat_is_session_static (s))
152 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
155 nat44_delete_session (sm, s, ctx->thread_index);
164 icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
165 ip4_header_t * ip0, icmp46_header_t * icmp0,
166 u32 sw_if_index0, u32 rx_fib_index0,
167 vlib_node_runtime_t * node, u32 next0, f64 now,
168 u32 thread_index, snat_session_t ** p_s0)
170 next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
171 next0, thread_index, p_s0, 0);
172 snat_session_t *s0 = *p_s0;
173 if (PREDICT_TRUE (next0 != NAT_NEXT_DROP && s0))
176 nat44_session_update_counters (s0, now,
177 vlib_buffer_length_in_chain
178 (sm->vlib_main, b0), thread_index);
179 /* Per-user LRU list maintenance */
180 nat44_session_update_lru (sm, s0, thread_index);
185 static_always_inline u16
186 snat_random_port (u16 min, u16 max)
188 snat_main_t *sm = &snat_main;
189 return min + random_u32 (&sm->random_seed) /
190 (random_u32_max () / (max - min + 1) + 1);
194 nat_ed_alloc_addr_and_port (snat_main_t * sm, u32 fib_index,
195 u32 thread_index, nat_ed_ses_key_t * key,
196 snat_session_key_t * key1, u16 port_per_thread,
197 u32 snat_thread_index,
199 clib_bihash_kv_16_8_t * out2in_ed_kv)
202 snat_address_t *a, *ga = 0;
204 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
206 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
208 for (i = 0; i < vec_len (sm->addresses); i++)
210 a = sm->addresses + i;
211 switch (key1->protocol)
213 #define _(N, j, n, unused) \
214 case SNAT_PROTOCOL_##N: \
215 if (a->fib_index == fib_index) \
217 u16 port = snat_random_port (1, port_per_thread); \
218 u16 attempts = port_per_thread; \
219 while (attempts > 0) \
222 portnum = port_thread_offset + port; \
223 make_ed_kv (out2in_ed_kv, &a->addr, &key->r_addr, key->proto, \
224 s->out2in.fib_index, clib_host_to_net_u16 (portnum), \
226 out2in_ed_kv->value = s - tsm->sessions; \
227 int rv = clib_bihash_add_del_16_8 (&tsm->out2in_ed, out2in_ed_kv, \
231 ++a->busy_##n##_port_refcounts[portnum]; \
232 a->busy_##n##_ports_per_thread[thread_index]++; \
233 a->busy_##n##_ports++; \
234 key1->addr = a->addr; \
235 key1->port = clib_host_to_net_u16 (portnum); \
238 port = (port + 1) % port_per_thread; \
241 else if (a->fib_index == ~0) \
247 foreach_snat_protocol;
249 nat_elog_info ("unknown protocol");
256 /* fake fib_index to reuse macro */
259 switch (key1->protocol)
261 foreach_snat_protocol;
263 nat_elog_info ("unknown protocol");
270 /* Totally out of translations to use... */
271 snat_ipfix_logging_addresses_exhausted (thread_index, 0);
276 slow_path_ed (snat_main_t * sm,
279 clib_bihash_kv_16_8_t * kv,
280 snat_session_t ** sessionp,
281 vlib_node_runtime_t * node, u32 next, u32 thread_index, f64 now)
283 snat_session_t *s = NULL;
284 snat_user_t *u = NULL;
285 snat_session_key_t key0, key1;
286 lb_nat_type_t lb = 0, is_sm = 0;
287 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
288 nat_ed_ses_key_t *key = (nat_ed_ses_key_t *) kv->key;
289 u32 proto = ip_proto_to_snat_proto (key->proto);
290 nat_outside_fib_t *outside_fib;
291 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
292 clib_bihash_kv_16_8_t out2in_ed_kv;
293 bool out2in_ed_inserted = false;
296 .fp_proto = FIB_PROTOCOL_IP4,
299 .ip4.as_u32 = key->r_addr.as_u32,
302 nat44_is_idle_session_ctx_t ctx;
304 if (PREDICT_TRUE (proto == SNAT_PROTOCOL_TCP))
308 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
310 b->error = node->errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
311 return NAT_NEXT_DROP;
315 if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
317 if (!nat_global_lru_free_one (sm, 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))
337 nat_user_get_or_create (sm, &key->l_addr, rx_fib_index, thread_index);
340 nat_elog_warn ("create NAT user failed");
341 b->error = node->errors[NAT_IN2OUT_ED_ERROR_CANNOT_CREATE_USER];
345 s = nat_ed_session_alloc (sm, u, thread_index, now);
348 nat_elog_warn ("create NAT session failed");
349 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
352 switch (vec_len (sm->outside_fibs))
355 s->out2in.fib_index = sm->outside_fib_index;
358 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
362 vec_foreach (outside_fib, sm->outside_fibs)
364 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
365 if (FIB_NODE_INDEX_INVALID != fei)
367 if (fib_entry_get_resolving_interface (fei) != ~0)
369 s->out2in.fib_index = outside_fib->fib_index;
378 /* Try to create dynamic translation */
379 if (nat_ed_alloc_addr_and_port (sm, rx_fib_index,
380 thread_index, key, &key1,
382 tsm->snat_thread_index, s,
385 nat_elog_notice ("addresses exhausted");
386 b->error = node->errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
390 out2in_ed_inserted = true;
394 if (PREDICT_FALSE (identity_nat))
401 nat_user_get_or_create (sm, &key->l_addr, rx_fib_index, thread_index);
404 nat_elog_warn ("create NAT user failed");
405 b->error = node->errors[NAT_IN2OUT_ED_ERROR_CANNOT_CREATE_USER];
409 s = nat_ed_session_alloc (sm, u, thread_index, now);
412 nat44_delete_user_with_no_session (sm, u, thread_index);
413 nat_elog_warn ("create NAT session failed");
414 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
417 switch (vec_len (sm->outside_fibs))
420 s->out2in.fib_index = sm->outside_fib_index;
423 s->out2in.fib_index = sm->outside_fibs[0].fib_index;
427 vec_foreach (outside_fib, sm->outside_fibs)
429 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
430 if (FIB_NODE_INDEX_INVALID != fei)
432 if (fib_entry_get_resolving_interface (fei) != ~0)
434 s->out2in.fib_index = outside_fib->fib_index;
443 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
446 make_ed_kv (&out2in_ed_kv, &key1.addr, &key->r_addr, key->proto,
447 s->out2in.fib_index, key1.port, key->r_port);
448 out2in_ed_kv.value = s - tsm->sessions;
449 if (clib_bihash_add_or_overwrite_stale_16_8
450 (&tsm->out2in_ed, &out2in_ed_kv, nat44_o2i_ed_is_idle_session_cb,
452 nat_elog_notice ("out2in-ed key add failed");
453 out2in_ed_inserted = true;
456 user_session_increment (sm, u, is_sm);
458 s->flags |= SNAT_SESSION_FLAG_LOAD_BALANCING;
459 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
460 s->ext_host_addr = key->r_addr;
461 s->ext_host_port = key->r_port;
464 s->out2in.protocol = key0.protocol;
466 kv->value = s - tsm->sessions;
468 ctx.thread_index = thread_index;
469 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->in2out_ed, kv,
470 nat44_i2o_ed_is_idle_session_cb,
472 nat_elog_notice ("in2out-ed key add failed");
477 snat_ipfix_logging_nat44_ses_create (thread_index,
478 s->in2out.addr.as_u32,
479 s->out2in.addr.as_u32,
482 s->out2in.port, s->in2out.fib_index);
484 nat_syslog_nat44_sadd (s->user_index, s->in2out.fib_index,
485 &s->in2out.addr, s->in2out.port,
486 &s->ext_host_nat_addr, s->ext_host_nat_port,
487 &s->out2in.addr, s->out2in.port,
488 &s->ext_host_addr, s->ext_host_port,
489 s->in2out.protocol, 0);
491 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
492 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
493 &s->ext_host_nat_addr, s->ext_host_nat_port,
494 s->in2out.protocol, s->in2out.fib_index, s->flags,
499 if (out2in_ed_inserted)
501 if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &out2in_ed_kv, 0))
502 nat_elog_notice ("out2in-ed key del failed");
506 nat_free_session_data (sm, s, thread_index, 0);
507 nat44_ed_delete_session (sm, s, thread_index, 1);
511 nat44_delete_user_with_no_session (sm, u, thread_index);
513 return NAT_NEXT_DROP;
516 static_always_inline int
517 nat44_ed_not_translate (snat_main_t * sm, vlib_node_runtime_t * node,
518 u32 sw_if_index, ip4_header_t * ip, u32 proto,
519 u32 rx_fib_index, u32 thread_index)
521 udp_header_t *udp = ip4_next_header (ip);
522 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
523 clib_bihash_kv_16_8_t kv, value;
524 snat_session_key_t key0, key1;
526 make_ed_kv (&kv, &ip->dst_address, &ip->src_address, ip->protocol,
527 sm->outside_fib_index, udp->dst_port, udp->src_port);
529 /* NAT packet aimed at external address if */
530 /* has active sessions */
531 if (clib_bihash_search_16_8 (&tsm->out2in_ed, &kv, &value))
533 key0.addr = ip->dst_address;
534 key0.port = udp->dst_port;
535 key0.protocol = proto;
536 key0.fib_index = sm->outside_fib_index;
537 /* or is static mappings */
538 if (!snat_static_mapping_match (sm, key0, &key1, 1, 0, 0, 0, 0, 0))
544 if (sm->forwarding_enabled)
547 return snat_not_translate_fast (sm, node, sw_if_index, ip, proto,
551 static_always_inline int
552 nat_not_translate_output_feature_fwd (snat_main_t * sm, ip4_header_t * ip,
553 u32 thread_index, f64 now,
554 vlib_main_t * vm, vlib_buffer_t * b)
556 nat_ed_ses_key_t key;
557 clib_bihash_kv_16_8_t kv, value;
558 snat_session_t *s = 0;
559 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
561 if (!sm->forwarding_enabled)
564 if (ip->protocol == IP_PROTOCOL_ICMP)
566 key.as_u64[0] = key.as_u64[1] = 0;
567 if (get_icmp_i2o_ed_key (b, ip, &key))
570 kv.key[0] = key.as_u64[0];
571 kv.key[1] = key.as_u64[1];
573 else if (ip->protocol == IP_PROTOCOL_UDP || ip->protocol == IP_PROTOCOL_TCP)
575 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, ip->protocol, 0,
576 vnet_buffer (b)->ip.reass.l4_src_port,
577 vnet_buffer (b)->ip.reass.l4_dst_port);
581 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, ip->protocol, 0, 0,
585 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
587 s = pool_elt_at_index (tsm->sessions, value.value);
588 if (is_fwd_bypass_session (s))
590 if (ip->protocol == IP_PROTOCOL_TCP)
592 if (nat44_set_tcp_session_state_i2o
593 (sm, now, s, b, thread_index))
597 nat44_session_update_counters (s, now,
598 vlib_buffer_length_in_chain (vm, b),
600 /* Per-user LRU list maintenance */
601 nat44_session_update_lru (sm, s, thread_index);
611 static_always_inline int
612 nat44_ed_not_translate_output_feature (snat_main_t * sm, ip4_header_t * ip,
613 u8 proto, u16 src_port, u16 dst_port,
614 u32 thread_index, u32 rx_sw_if_index,
617 clib_bihash_kv_16_8_t kv, value;
618 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
621 u32 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (rx_sw_if_index);
622 u32 tx_fib_index = ip4_fib_table_get_index_for_sw_if_index (tx_sw_if_index);
625 make_ed_kv (&kv, &ip->src_address, &ip->dst_address, proto, tx_fib_index,
627 if (!clib_bihash_search_16_8 (&tsm->out2in_ed, &kv, &value))
629 s = pool_elt_at_index (tsm->sessions, value.value);
630 if (nat44_is_ses_closed (s))
632 nat_free_session_data (sm, s, thread_index, 0);
633 nat44_delete_session (sm, s, thread_index);
636 s->flags |= SNAT_SESSION_FLAG_OUTPUT_FEATURE;
641 make_ed_kv (&kv, &ip->dst_address, &ip->src_address, proto, rx_fib_index,
643 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
645 s = pool_elt_at_index (tsm->sessions, value.value);
646 if (is_fwd_bypass_session (s))
651 pool_foreach (i, sm->output_feature_interfaces,
653 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
663 #ifndef CLIB_MARCH_VARIANT
665 icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
666 u32 thread_index, vlib_buffer_t * b, ip4_header_t * ip,
667 u8 * p_proto, snat_session_key_t * p_value,
668 u8 * p_dont_translate, void *d, void *e)
672 nat_ed_ses_key_t key;
673 snat_session_t *s = 0;
674 u8 dont_translate = 0;
675 clib_bihash_kv_16_8_t kv, value;
678 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
680 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
681 rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
683 key.as_u64[0] = key.as_u64[1] = 0;
684 err = get_icmp_i2o_ed_key (b, ip, &key);
687 b->error = node->errors[err];
688 next = NAT_NEXT_DROP;
691 key.fib_index = rx_fib_index;
693 kv.key[0] = key.as_u64[0];
694 kv.key[1] = key.as_u64[1];
696 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv, &value))
698 if (vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0)
701 (nat44_ed_not_translate_output_feature
702 (sm, ip, key.proto, key.l_port, key.r_port, thread_index,
703 sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_TX])))
711 if (PREDICT_FALSE (nat44_ed_not_translate (sm, node, sw_if_index,
712 ip, SNAT_PROTOCOL_ICMP,
722 (icmp_type_is_error_message
723 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
725 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
726 next = NAT_NEXT_DROP;
730 next = slow_path_ed (sm, b, rx_fib_index, &kv, &s, node, next,
731 thread_index, vlib_time_now (sm->vlib_main));
733 if (PREDICT_FALSE (next == NAT_NEXT_DROP))
745 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
747 && vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
749 && !icmp_type_is_error_message (vnet_buffer (b)->ip.
750 reass.icmp_type_or_tcp_flags)))
752 b->error = node->errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
753 next = NAT_NEXT_DROP;
757 s = pool_elt_at_index (tsm->sessions, value.value);
760 *p_proto = ip_proto_to_snat_proto (key.proto);
763 *p_value = s->out2in;
764 *p_dont_translate = dont_translate;
766 *(snat_session_t **) d = s;
771 static snat_session_t *
772 nat44_ed_in2out_unknown_proto (snat_main_t * sm,
778 vlib_main_t * vm, vlib_node_runtime_t * node)
780 clib_bihash_kv_8_8_t kv, value;
781 clib_bihash_kv_16_8_t s_kv, s_value;
782 snat_static_mapping_t *m;
783 u32 old_addr, new_addr = 0;
786 dlist_elt_t *head, *elt;
787 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
788 u32 elt_index, head_index, ses_index;
790 u32 outside_fib_index = sm->outside_fib_index;
793 nat_outside_fib_t *outside_fib;
794 fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
796 .fp_proto = FIB_PROTOCOL_IP4,
799 .ip4.as_u32 = ip->dst_address.as_u32,
803 switch (vec_len (sm->outside_fibs))
806 outside_fib_index = sm->outside_fib_index;
809 outside_fib_index = sm->outside_fibs[0].fib_index;
813 vec_foreach (outside_fib, sm->outside_fibs)
815 fei = fib_table_lookup (outside_fib->fib_index, &pfx);
816 if (FIB_NODE_INDEX_INVALID != fei)
818 if (fib_entry_get_resolving_interface (fei) != ~0)
820 outside_fib_index = outside_fib->fib_index;
828 old_addr = ip->src_address.as_u32;
830 make_ed_kv (&s_kv, &ip->src_address, &ip->dst_address, ip->protocol,
833 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &s_kv, &s_value))
835 s = pool_elt_at_index (tsm->sessions, s_value.value);
836 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
840 if (PREDICT_FALSE (nat44_maximum_sessions_exceeded (sm, thread_index)))
842 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
843 nat_ipfix_logging_max_sessions (thread_index, sm->max_translations);
844 nat_elog_notice ("maximum sessions exceeded");
848 u = nat_user_get_or_create (sm, &ip->src_address, rx_fib_index,
852 b->error = node->errors[NAT_IN2OUT_ED_ERROR_CANNOT_CREATE_USER];
853 nat_elog_warn ("create NAT user failed");
857 make_sm_kv (&kv, &ip->src_address, 0, rx_fib_index, 0);
859 /* Try to find static mapping first */
860 if (!clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
862 m = pool_elt_at_index (sm->static_mappings, value.value);
863 new_addr = ip->src_address.as_u32 = m->external_addr.as_u32;
867 /* Fallback to 3-tuple key */
870 /* Choose same out address as for TCP/UDP session to same destination */
871 head_index = u->sessions_per_user_list_head_index;
872 head = pool_elt_at_index (tsm->list_pool, head_index);
873 elt_index = head->next;
874 if (PREDICT_FALSE (elt_index == ~0))
878 elt = pool_elt_at_index (tsm->list_pool, elt_index);
879 ses_index = elt->value;
882 while (ses_index != ~0)
884 s = pool_elt_at_index (tsm->sessions, ses_index);
885 elt_index = elt->next;
886 elt = pool_elt_at_index (tsm->list_pool, elt_index);
887 ses_index = elt->value;
889 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
891 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
893 make_ed_kv (&s_kv, &s->out2in.addr, &ip->dst_address,
894 ip->protocol, outside_fib_index, 0, 0);
895 if (clib_bihash_search_16_8
896 (&tsm->out2in_ed, &s_kv, &s_value))
903 for (i = 0; i < vec_len (sm->addresses); i++)
905 make_ed_kv (&s_kv, &sm->addresses[i].addr, &ip->dst_address,
906 ip->protocol, outside_fib_index, 0, 0);
907 if (clib_bihash_search_16_8 (&tsm->out2in_ed, &s_kv, &s_value))
909 new_addr = ip->src_address.as_u32 =
910 sm->addresses[i].addr.as_u32;
918 s = nat_ed_session_alloc (sm, u, thread_index, now);
921 b->error = node->errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
922 nat44_delete_user_with_no_session (sm, u, thread_index);
923 nat_elog_warn ("create NAT session failed");
927 s->ext_host_addr.as_u32 = ip->dst_address.as_u32;
928 s->flags |= SNAT_SESSION_FLAG_UNKNOWN_PROTO;
929 s->flags |= SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT;
930 s->out2in.addr.as_u32 = new_addr;
931 s->out2in.fib_index = outside_fib_index;
932 s->in2out.addr.as_u32 = old_addr;
933 s->in2out.fib_index = rx_fib_index;
934 s->in2out.port = s->out2in.port = ip->protocol;
936 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
937 user_session_increment (sm, u, is_sm);
939 /* Add to lookup tables */
940 make_ed_kv (&s_kv, &s->in2out.addr, &ip->dst_address, ip->protocol,
942 s_kv.value = s - tsm->sessions;
943 if (clib_bihash_add_del_16_8 (&tsm->in2out_ed, &s_kv, 1))
944 nat_elog_notice ("in2out key add failed");
946 make_ed_kv (&s_kv, &s->out2in.addr, &ip->dst_address, ip->protocol,
947 outside_fib_index, 0, 0);
948 s_kv.value = s - tsm->sessions;
949 if (clib_bihash_add_del_16_8 (&tsm->out2in_ed, &s_kv, 1))
950 nat_elog_notice ("out2in key add failed");
953 /* Update IP checksum */
955 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, src_address);
956 ip->checksum = ip_csum_fold (sum);
959 nat44_session_update_counters (s, now, vlib_buffer_length_in_chain (vm, b),
961 /* Per-user LRU list maintenance */
962 nat44_session_update_lru (sm, s, thread_index);
965 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
966 nat44_ed_hairpinning_unknown_proto (sm, b, ip);
968 if (vnet_buffer (b)->sw_if_index[VLIB_TX] == ~0)
969 vnet_buffer (b)->sw_if_index[VLIB_TX] = outside_fib_index;
975 nat44_ed_in2out_fast_path_node_fn_inline (vlib_main_t * vm,
976 vlib_node_runtime_t * node,
977 vlib_frame_t * frame,
978 int is_output_feature)
980 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
981 nat_next_t next_index;
982 snat_main_t *sm = &snat_main;
983 f64 now = vlib_time_now (vm);
984 u32 thread_index = vm->thread_index;
985 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
986 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
989 def_slow = is_output_feature ? NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH :
990 NAT_NEXT_IN2OUT_ED_SLOW_PATH;
992 stats_node_index = sm->ed_in2out_node_index;
994 from = vlib_frame_vector_args (frame);
995 n_left_from = frame->n_vectors;
996 next_index = node->cached_next_index;
998 while (n_left_from > 0)
1002 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1004 while (n_left_from > 0 && n_left_to_next > 0)
1008 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
1009 new_addr0, old_addr0;
1010 u16 old_port0, new_port0;
1014 snat_session_t *s0 = 0;
1015 clib_bihash_kv_16_8_t kv0, value0;
1018 /* speculatively enqueue b0 to the current next frame */
1024 n_left_to_next -= 1;
1026 b0 = vlib_get_buffer (vm, bi0);
1028 if (is_output_feature)
1030 vnet_feature_next (&nat_buffer_opaque (b0)->arc_next, b0);
1031 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1034 next0 = nat_buffer_opaque (b0)->arc_next;
1036 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1039 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1041 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1044 if (PREDICT_FALSE (ip0->ttl == 1))
1046 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1047 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1048 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1050 next0 = NAT_NEXT_ICMP_ERROR;
1054 udp0 = ip4_next_header (ip0);
1055 tcp0 = (tcp_header_t *) udp0;
1056 proto0 = ip_proto_to_snat_proto (ip0->protocol);
1058 if (PREDICT_FALSE (proto0 == ~0))
1064 if (is_output_feature)
1066 if (PREDICT_FALSE (nat_not_translate_output_feature_fwd
1067 (sm, ip0, thread_index, now, vm, b0)))
1071 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
1077 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
1078 ip0->protocol, rx_fib_index0,
1079 vnet_buffer (b0)->ip.reass.l4_src_port,
1080 vnet_buffer (b0)->ip.reass.l4_dst_port);
1082 // lookup for session
1083 if (clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1085 // session does not exist go slow path
1089 s0 = pool_elt_at_index (tsm->sessions, value0.value);
1091 if (s0->tcp_close_timestamp)
1093 if (now >= s0->tcp_close_timestamp)
1095 // session is closed, go slow path
1100 // session in transitory timeout, drop
1101 b0->error = node->errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1102 next0 = NAT_NEXT_DROP;
1107 // drop if session expired
1108 u64 sess_timeout_time;
1109 sess_timeout_time = s0->last_heard +
1110 (f64) nat44_session_get_timeout (sm, s0);
1111 if (now >= sess_timeout_time)
1113 nat_free_session_data (sm, s0, thread_index, 0);
1114 nat44_delete_session (sm, s0, thread_index);
1115 // session is closed, go slow path
1120 b0->flags |= VNET_BUFFER_F_IS_NATED;
1122 if (!is_output_feature)
1123 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1125 old_addr0 = ip0->src_address.as_u32;
1126 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1127 sum0 = ip0->checksum;
1128 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1130 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1131 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1132 s0->ext_host_addr.as_u32, ip4_header_t,
1134 ip0->checksum = ip_csum_fold (sum0);
1136 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1138 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
1140 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1142 new_port0 = udp0->src_port = s0->out2in.port;
1143 sum0 = tcp0->checksum;
1145 ip_csum_update (sum0, old_addr0, new_addr0,
1146 ip4_header_t, dst_address);
1148 ip_csum_update (sum0, old_port0, new_port0,
1149 ip4_header_t, length);
1150 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1153 ip_csum_update (sum0, ip0->dst_address.as_u32,
1154 s0->ext_host_addr.as_u32,
1155 ip4_header_t, dst_address);
1157 ip_csum_update (sum0,
1158 vnet_buffer (b0)->ip.
1159 reass.l4_dst_port, s0->ext_host_port,
1160 ip4_header_t, length);
1161 tcp0->dst_port = s0->ext_host_port;
1162 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1164 mss_clamping (sm, tcp0, &sum0);
1165 tcp0->checksum = ip_csum_fold (sum0);
1168 if (nat44_set_tcp_session_state_i2o
1169 (sm, now, s0, b0, thread_index))
1172 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1175 new_port0 = udp0->src_port = s0->out2in.port;
1176 sum0 = udp0->checksum;
1178 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1181 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1183 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1185 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1186 s0->ext_host_addr.as_u32,
1187 ip4_header_t, dst_address);
1189 ip_csum_update (sum0,
1190 vnet_buffer (b0)->ip.reass.l4_dst_port,
1191 s0->ext_host_port, ip4_header_t, length);
1192 udp0->dst_port = s0->ext_host_port;
1193 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1195 udp0->checksum = ip_csum_fold (sum0);
1200 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1202 new_port0 = udp0->src_port = s0->out2in.port;
1203 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1205 udp0->dst_port = s0->ext_host_port;
1206 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1213 nat44_session_update_counters (s0, now,
1214 vlib_buffer_length_in_chain
1215 (vm, b0), thread_index);
1216 /* Per-user LRU list maintenance */
1217 nat44_session_update_lru (sm, s0, thread_index);
1220 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1221 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1223 nat_in2out_ed_trace_t *t =
1224 vlib_add_trace (vm, node, b0, sizeof (*t));
1225 t->sw_if_index = sw_if_index0;
1226 t->next_index = next0;
1227 t->is_slow_path = 0;
1230 t->session_index = s0 - tsm->sessions;
1232 t->session_index = ~0;
1235 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1236 /* verify speculative enqueue, maybe switch current next frame */
1237 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1238 to_next, n_left_to_next,
1242 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1245 vlib_node_increment_counter (vm, stats_node_index,
1246 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1248 vlib_node_increment_counter (vm, stats_node_index,
1249 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1250 vlib_node_increment_counter (vm, stats_node_index,
1251 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1252 vlib_node_increment_counter (vm, stats_node_index,
1253 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1255 vlib_node_increment_counter (vm, stats_node_index,
1256 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1258 return frame->n_vectors;
1262 nat44_ed_in2out_slow_path_node_fn_inline (vlib_main_t * vm,
1263 vlib_node_runtime_t * node,
1264 vlib_frame_t * frame,
1265 int is_output_feature)
1267 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
1268 nat_next_t next_index;
1269 snat_main_t *sm = &snat_main;
1270 f64 now = vlib_time_now (vm);
1271 u32 thread_index = vm->thread_index;
1272 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
1273 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1275 stats_node_index = sm->ed_in2out_slowpath_node_index;
1277 from = vlib_frame_vector_args (frame);
1278 n_left_from = frame->n_vectors;
1279 next_index = node->cached_next_index;
1281 while (n_left_from > 0)
1285 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1287 while (n_left_from > 0 && n_left_to_next > 0)
1291 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
1292 new_addr0, old_addr0;
1293 u16 old_port0, new_port0;
1297 icmp46_header_t *icmp0;
1298 snat_session_t *s0 = 0;
1299 clib_bihash_kv_16_8_t kv0, value0;
1302 /* speculatively enqueue b0 to the current next frame */
1308 n_left_to_next -= 1;
1310 b0 = vlib_get_buffer (vm, bi0);
1312 if (is_output_feature)
1313 iph_offset0 = vnet_buffer (b0)->ip.reass.save_rewrite_length;
1315 next0 = nat_buffer_opaque (b0)->arc_next;
1317 ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0) +
1320 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1322 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4,
1325 if (PREDICT_FALSE (ip0->ttl == 1))
1327 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1328 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1329 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1331 next0 = NAT_NEXT_ICMP_ERROR;
1335 udp0 = ip4_next_header (ip0);
1336 tcp0 = (tcp_header_t *) udp0;
1337 icmp0 = (icmp46_header_t *) udp0;
1338 proto0 = ip_proto_to_snat_proto (ip0->protocol);
1340 if (PREDICT_FALSE (proto0 == ~0))
1342 s0 = nat44_ed_in2out_unknown_proto (sm, b0, ip0,
1347 next0 = NAT_NEXT_DROP;
1353 if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
1355 next0 = icmp_in2out_ed_slow_path
1356 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1357 node, next0, now, thread_index, &s0);
1363 make_ed_kv (&kv0, &ip0->src_address, &ip0->dst_address,
1364 ip0->protocol, rx_fib_index0,
1365 vnet_buffer (b0)->ip.reass.l4_src_port,
1366 vnet_buffer (b0)->ip.reass.l4_dst_port);
1368 if (!clib_bihash_search_16_8 (&tsm->in2out_ed, &kv0, &value0))
1370 s0 = pool_elt_at_index (tsm->sessions, value0.value);
1372 if (s0->tcp_close_timestamp && now >= s0->tcp_close_timestamp)
1374 nat_free_session_data (sm, s0, thread_index, 0);
1375 nat44_delete_session (sm, s0, thread_index);
1382 if (is_output_feature)
1385 (nat44_ed_not_translate_output_feature
1386 (sm, ip0, ip0->protocol,
1387 vnet_buffer (b0)->ip.reass.l4_src_port,
1388 vnet_buffer (b0)->ip.reass.l4_dst_port,
1389 thread_index, sw_if_index0,
1390 vnet_buffer (b0)->sw_if_index[VLIB_TX])))
1394 * Send DHCP packets to the ipv4 stack, or we won't
1395 * be able to use dhcp client on the outside interface
1398 (proto0 == SNAT_PROTOCOL_UDP
1399 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1400 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1401 && ip0->dst_address.as_u32 == 0xffffffff))
1407 (nat44_ed_not_translate
1408 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1413 next0 = slow_path_ed (sm, b0, rx_fib_index0, &kv0, &s0, node,
1414 next0, thread_index, now);
1416 if (PREDICT_FALSE (next0 == NAT_NEXT_DROP))
1419 if (PREDICT_FALSE (!s0))
1424 b0->flags |= VNET_BUFFER_F_IS_NATED;
1426 if (!is_output_feature)
1427 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->out2in.fib_index;
1429 old_addr0 = ip0->src_address.as_u32;
1430 new_addr0 = ip0->src_address.as_u32 = s0->out2in.addr.as_u32;
1431 sum0 = ip0->checksum;
1432 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1434 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1435 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1436 s0->ext_host_addr.as_u32, ip4_header_t,
1438 ip0->checksum = ip_csum_fold (sum0);
1440 old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
1442 if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
1444 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1446 new_port0 = udp0->src_port = s0->out2in.port;
1447 sum0 = tcp0->checksum;
1449 ip_csum_update (sum0, old_addr0, new_addr0,
1450 ip4_header_t, dst_address);
1452 ip_csum_update (sum0, old_port0, new_port0,
1453 ip4_header_t, length);
1454 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1457 ip_csum_update (sum0, ip0->dst_address.as_u32,
1458 s0->ext_host_addr.as_u32,
1459 ip4_header_t, dst_address);
1461 ip_csum_update (sum0,
1462 vnet_buffer (b0)->ip.
1463 reass.l4_dst_port, s0->ext_host_port,
1464 ip4_header_t, length);
1465 tcp0->dst_port = s0->ext_host_port;
1466 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1468 mss_clamping (sm, tcp0, &sum0);
1469 tcp0->checksum = ip_csum_fold (sum0);
1472 if (nat44_set_tcp_session_state_i2o
1473 (sm, now, s0, b0, thread_index))
1476 else if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment
1479 new_port0 = udp0->src_port = s0->out2in.port;
1480 sum0 = udp0->checksum;
1482 ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
1485 ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
1487 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1489 sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
1490 s0->ext_host_addr.as_u32,
1491 ip4_header_t, dst_address);
1493 ip_csum_update (sum0,
1494 vnet_buffer (b0)->ip.reass.l4_dst_port,
1495 s0->ext_host_port, ip4_header_t, length);
1496 udp0->dst_port = s0->ext_host_port;
1497 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1499 udp0->checksum = ip_csum_fold (sum0);
1504 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1506 new_port0 = udp0->src_port = s0->out2in.port;
1507 if (PREDICT_FALSE (is_twice_nat_session (s0)))
1509 udp0->dst_port = s0->ext_host_port;
1510 ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
1517 nat44_session_update_counters (s0, now,
1518 vlib_buffer_length_in_chain
1519 (vm, b0), thread_index);
1520 /* Per-user LRU list maintenance */
1521 nat44_session_update_lru (sm, s0, thread_index);
1524 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1525 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1527 nat_in2out_ed_trace_t *t =
1528 vlib_add_trace (vm, node, b0, sizeof (*t));
1529 t->sw_if_index = sw_if_index0;
1530 t->next_index = next0;
1531 t->is_slow_path = 1;
1534 t->session_index = s0 - tsm->sessions;
1536 t->session_index = ~0;
1539 pkts_processed += next0 == nat_buffer_opaque (b0)->arc_next;
1541 /* verify speculative enqueue, maybe switch current next frame */
1542 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1543 to_next, n_left_to_next,
1547 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1550 vlib_node_increment_counter (vm, stats_node_index,
1551 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1553 vlib_node_increment_counter (vm, stats_node_index,
1554 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1555 vlib_node_increment_counter (vm, stats_node_index,
1556 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1557 vlib_node_increment_counter (vm, stats_node_index,
1558 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1560 vlib_node_increment_counter (vm, stats_node_index,
1561 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1563 return frame->n_vectors;
1566 VLIB_NODE_FN (nat44_ed_in2out_node) (vlib_main_t * vm,
1567 vlib_node_runtime_t * node,
1568 vlib_frame_t * frame)
1570 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 0);
1574 VLIB_REGISTER_NODE (nat44_ed_in2out_node) = {
1575 .name = "nat44-ed-in2out",
1576 .vector_size = sizeof (u32),
1577 .sibling_of = "nat-default",
1578 .format_trace = format_nat_in2out_ed_trace,
1579 .type = VLIB_NODE_TYPE_INTERNAL,
1580 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1581 .error_strings = nat_in2out_ed_error_strings,
1582 .runtime_data_bytes = sizeof (snat_runtime_t),
1586 VLIB_NODE_FN (nat44_ed_in2out_output_node) (vlib_main_t * vm,
1587 vlib_node_runtime_t * node,
1588 vlib_frame_t * frame)
1590 return nat44_ed_in2out_fast_path_node_fn_inline (vm, node, frame, 1);
1594 VLIB_REGISTER_NODE (nat44_ed_in2out_output_node) = {
1595 .name = "nat44-ed-in2out-output",
1596 .vector_size = sizeof (u32),
1597 .sibling_of = "nat-default",
1598 .format_trace = format_nat_in2out_ed_trace,
1599 .type = VLIB_NODE_TYPE_INTERNAL,
1600 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1601 .error_strings = nat_in2out_ed_error_strings,
1602 .runtime_data_bytes = sizeof (snat_runtime_t),
1606 VLIB_NODE_FN (nat44_ed_in2out_slowpath_node) (vlib_main_t * vm,
1607 vlib_node_runtime_t *
1608 node, vlib_frame_t * frame)
1610 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 0);
1614 VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node) = {
1615 .name = "nat44-ed-in2out-slowpath",
1616 .vector_size = sizeof (u32),
1617 .sibling_of = "nat-default",
1618 .format_trace = format_nat_in2out_ed_trace,
1619 .type = VLIB_NODE_TYPE_INTERNAL,
1620 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1621 .error_strings = nat_in2out_ed_error_strings,
1622 .runtime_data_bytes = sizeof (snat_runtime_t),
1626 VLIB_NODE_FN (nat44_ed_in2out_output_slowpath_node) (vlib_main_t * vm,
1629 vlib_frame_t * frame)
1631 return nat44_ed_in2out_slow_path_node_fn_inline (vm, node, frame, 1);
1635 VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node) = {
1636 .name = "nat44-ed-in2out-output-slowpath",
1637 .vector_size = sizeof (u32),
1638 .sibling_of = "nat-default",
1639 .format_trace = format_nat_in2out_ed_trace,
1640 .type = VLIB_NODE_TYPE_INTERNAL,
1641 .n_errors = ARRAY_LEN (nat_in2out_ed_error_strings),
1642 .error_strings = nat_in2out_ed_error_strings,
1643 .runtime_data_bytes = sizeof (snat_runtime_t),
1648 format_nat_pre_trace (u8 * s, va_list * args)
1650 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1651 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1652 nat_pre_trace_t *t = va_arg (*args, nat_pre_trace_t *);
1653 return format (s, "in2out next_index %d", t->next_index);
1656 VLIB_NODE_FN (nat_pre_in2out_node)
1657 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1659 return nat_pre_node_fn_inline (vm, node, frame,
1660 NAT_NEXT_IN2OUT_ED_FAST_PATH);
1664 VLIB_REGISTER_NODE (nat_pre_in2out_node) = {
1665 .name = "nat-pre-in2out",
1666 .vector_size = sizeof (u32),
1667 .sibling_of = "nat-default",
1668 .format_trace = format_nat_pre_trace,
1669 .type = VLIB_NODE_TYPE_INTERNAL,
1675 * fd.io coding-style-patch-verification: ON
1678 * eval: (c-set-style "gnu")