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 Deterministic/CGN NAT44 outside to inside network translation
20 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/fib/ip4_fib.h>
24 #include <vppinfra/error.h>
25 #include <vppinfra/elog.h>
27 #include <nat/nat_det.h>
28 #include <nat/nat_inlines.h>
32 NAT_DET_OUT2IN_NEXT_DROP,
33 NAT_DET_OUT2IN_NEXT_LOOKUP,
34 NAT_DET_OUT2IN_NEXT_ICMP_ERROR,
35 NAT_DET_OUT2IN_N_NEXT,
36 } nat_det_out2in_next_t;
43 } nat_det_out2in_trace_t;
45 #define foreach_nat_det_out2in_error \
46 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \
47 _(NO_TRANSLATION, "No translation") \
48 _(BAD_ICMP_TYPE, "unsupported ICMP type") \
49 _(OUT2IN_PACKETS, "Good out2in packets processed")
53 #define _(sym,str) NAT_DET_OUT2IN_ERROR_##sym,
54 foreach_nat_det_out2in_error
57 } nat_det_out2in_error_t;
59 static char *nat_det_out2in_error_strings[] = {
60 #define _(sym,string) string,
61 foreach_nat_det_out2in_error
66 format_nat_det_out2in_trace (u8 * s, va_list * args)
68 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
69 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
70 nat_det_out2in_trace_t *t = va_arg (*args, nat_det_out2in_trace_t *);
74 "NAT_DET_OUT2IN: sw_if_index %d, next index %d, session index %d",
75 t->sw_if_index, t->next_index, t->session_index);
79 #ifndef CLIB_MARCH_VARIANT
81 * Get address and port values to be used for ICMP packet translation
82 * and create session if needed
84 * @param[in,out] sm NAT main
85 * @param[in,out] node NAT node runtime
86 * @param[in] thread_index thread index
87 * @param[in,out] b0 buffer containing packet to be translated
88 * @param[in,out] ip0 ip header
89 * @param[out] p_proto protocol used for matching
90 * @param[out] p_value address and port after NAT translation
91 * @param[out] p_dont_translate if packet should not be translated
92 * @param d optional parameter
93 * @param e optional parameter
96 icmp_match_out2in_det (snat_main_t * sm, vlib_node_runtime_t * node,
97 u32 thread_index, vlib_buffer_t * b0,
98 ip4_header_t * ip0, ip4_address_t * addr,
99 u16 * port, u32 * fib_index,
100 nat_protocol_t * proto, void *d, void *e,
103 icmp46_header_t *icmp0;
106 snat_det_out_key_t key0;
108 icmp_echo_header_t *echo0, *inner_echo0 = 0;
109 ip4_header_t *inner_ip0;
111 icmp46_header_t *inner_icmp0;
112 snat_det_map_t *dm0 = 0;
113 ip4_address_t new_addr0 = { {0} };
114 snat_det_session_t *ses0 = 0;
115 ip4_address_t out_addr;
118 icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
119 echo0 = (icmp_echo_header_t *) (icmp0 + 1);
120 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
122 if (!icmp_type_is_error_message
123 (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags))
125 protocol = NAT_PROTOCOL_ICMP;
126 key0.ext_host_addr = ip0->src_address;
127 key0.ext_host_port = 0;
128 key0.out_port = vnet_buffer (b0)->ip.reass.l4_src_port;
129 out_addr = ip0->dst_address;
133 /* if error message, then it's not fragmented and we can access it */
134 inner_ip0 = (ip4_header_t *) (echo0 + 1);
135 l4_header = ip4_next_header (inner_ip0);
136 protocol = ip_proto_to_nat_proto (inner_ip0->protocol);
137 key0.ext_host_addr = inner_ip0->dst_address;
138 out_addr = inner_ip0->src_address;
141 case NAT_PROTOCOL_ICMP:
142 inner_icmp0 = (icmp46_header_t *) l4_header;
143 inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
144 key0.ext_host_port = 0;
145 key0.out_port = inner_echo0->identifier;
147 case NAT_PROTOCOL_UDP:
148 case NAT_PROTOCOL_TCP:
149 key0.ext_host_port = ((tcp_udp_header_t *) l4_header)->dst_port;
150 key0.out_port = ((tcp_udp_header_t *) l4_header)->src_port;
153 b0->error = node->errors[NAT_DET_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
154 next0 = NAT_DET_OUT2IN_NEXT_DROP;
159 dm0 = snat_det_map_by_out (sm, &out_addr);
160 if (PREDICT_FALSE (!dm0))
162 /* Don't NAT packet aimed at the intfc address */
163 if (PREDICT_FALSE (is_interface_addr (sm, node, sw_if_index0,
164 ip0->dst_address.as_u32)))
169 nat_log_info ("unknown dst address: %U",
170 format_ip4_address, &ip0->dst_address);
174 snat_det_reverse (dm0, &ip0->dst_address,
175 clib_net_to_host_u16 (key0.out_port), &new_addr0);
177 ses0 = snat_det_get_ses_by_out (dm0, &new_addr0, key0.as_u64);
178 if (PREDICT_FALSE (!ses0))
180 /* Don't NAT packet aimed at the intfc address */
181 if (PREDICT_FALSE (is_interface_addr (sm, node, sw_if_index0,
182 ip0->dst_address.as_u32)))
187 nat_log_info ("no match src %U:%d dst %U:%d for user %U",
188 format_ip4_address, &key0.ext_host_addr,
189 clib_net_to_host_u16 (key0.ext_host_port),
190 format_ip4_address, &out_addr,
191 clib_net_to_host_u16 (key0.out_port),
192 format_ip4_address, &new_addr0);
193 b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
194 next0 = NAT_DET_OUT2IN_NEXT_DROP;
199 (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_reply
200 && !icmp_type_is_error_message (vnet_buffer (b0)->ip.
201 reass.icmp_type_or_tcp_flags)))
203 b0->error = node->errors[NAT_DET_OUT2IN_ERROR_BAD_ICMP_TYPE];
204 next0 = NAT_DET_OUT2IN_NEXT_DROP;
215 *fib_index = sm->inside_fib_index;
216 *port = ses0->in_port;
219 *(snat_det_session_t **) d = ses0;
221 *(snat_det_map_t **) e = dm0;
226 VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
227 vlib_node_runtime_t * node,
228 vlib_frame_t * frame)
230 u32 n_left_from, *from, *to_next;
231 nat_det_out2in_next_t next_index;
232 u32 pkts_processed = 0;
233 snat_main_t *sm = &snat_main;
234 u32 thread_index = vm->thread_index;
236 from = vlib_frame_vector_args (frame);
237 n_left_from = frame->n_vectors;
238 next_index = node->cached_next_index;
240 while (n_left_from > 0)
244 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
246 while (n_left_from >= 4 && n_left_to_next >= 2)
249 vlib_buffer_t *b0, *b1;
250 u32 next0 = NAT_DET_OUT2IN_NEXT_LOOKUP;
251 u32 next1 = NAT_DET_OUT2IN_NEXT_LOOKUP;
252 u32 sw_if_index0, sw_if_index1;
253 ip4_header_t *ip0, *ip1;
254 ip_csum_t sum0, sum1;
255 ip4_address_t new_addr0, old_addr0, new_addr1, old_addr1;
256 u16 new_port0, old_port0, old_port1, new_port1;
257 udp_header_t *udp0, *udp1;
258 tcp_header_t *tcp0, *tcp1;
260 snat_det_out_key_t key0, key1;
261 snat_det_map_t *dm0, *dm1;
262 snat_det_session_t *ses0 = 0, *ses1 = 0;
263 u32 rx_fib_index0, rx_fib_index1;
264 icmp46_header_t *icmp0, *icmp1;
266 /* Prefetch next iteration. */
268 vlib_buffer_t *p2, *p3;
270 p2 = vlib_get_buffer (vm, from[2]);
271 p3 = vlib_get_buffer (vm, from[3]);
273 vlib_prefetch_buffer_header (p2, LOAD);
274 vlib_prefetch_buffer_header (p3, LOAD);
276 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
277 CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE);
280 /* speculatively enqueue b0 and b1 to the current next frame */
281 to_next[0] = bi0 = from[0];
282 to_next[1] = bi1 = from[1];
288 b0 = vlib_get_buffer (vm, bi0);
289 b1 = vlib_get_buffer (vm, bi1);
291 ip0 = vlib_buffer_get_current (b0);
292 udp0 = ip4_next_header (ip0);
293 tcp0 = (tcp_header_t *) udp0;
295 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
297 if (PREDICT_FALSE (ip0->ttl == 1))
299 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
300 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
301 ICMP4_time_exceeded_ttl_exceeded_in_transit,
303 next0 = NAT_DET_OUT2IN_NEXT_ICMP_ERROR;
307 proto0 = ip_proto_to_nat_proto (ip0->protocol);
309 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
312 ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
313 icmp0 = (icmp46_header_t *) udp0;
315 next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
316 rx_fib_index0, node, next0, thread_index,
321 key0.ext_host_addr = ip0->src_address;
322 key0.ext_host_port = tcp0->src;
323 key0.out_port = tcp0->dst;
325 dm0 = snat_det_map_by_out (sm, &ip0->dst_address);
326 if (PREDICT_FALSE (!dm0))
328 nat_log_info ("unknown dst address: %U",
329 format_ip4_address, &ip0->dst_address);
330 next0 = NAT_DET_OUT2IN_NEXT_DROP;
331 b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
335 snat_det_reverse (dm0, &ip0->dst_address,
336 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
338 ses0 = snat_det_get_ses_by_out (dm0, &new_addr0, key0.as_u64);
339 if (PREDICT_FALSE (!ses0))
341 nat_log_info ("no match src %U:%d dst %U:%d for user %U",
342 format_ip4_address, &ip0->src_address,
343 clib_net_to_host_u16 (tcp0->src),
344 format_ip4_address, &ip0->dst_address,
345 clib_net_to_host_u16 (tcp0->dst),
346 format_ip4_address, &new_addr0);
347 next0 = NAT_DET_OUT2IN_NEXT_DROP;
348 b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
351 old_port0 = udp0->dst_port;
352 udp0->dst_port = new_port0 = ses0->in_port;
354 old_addr0 = ip0->dst_address;
355 ip0->dst_address = new_addr0;
356 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sm->inside_fib_index;
358 sum0 = ip0->checksum;
359 sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
361 dst_address /* changed member */ );
362 ip0->checksum = ip_csum_fold (sum0);
364 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
366 if (tcp0->flags & TCP_FLAG_FIN
367 && ses0->state == SNAT_SESSION_TCP_ESTABLISHED)
368 ses0->state = SNAT_SESSION_TCP_CLOSE_WAIT;
369 else if (tcp0->flags & TCP_FLAG_ACK
370 && ses0->state == SNAT_SESSION_TCP_LAST_ACK)
371 snat_det_ses_close (dm0, ses0);
373 sum0 = tcp0->checksum;
374 sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
376 dst_address /* changed member */ );
377 sum0 = ip_csum_update (sum0, old_port0, new_port0,
378 ip4_header_t /* cheat */ ,
379 length /* changed member */ );
380 tcp0->checksum = ip_csum_fold (sum0);
382 else if (udp0->checksum)
384 sum0 = udp0->checksum;
385 sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
387 dst_address /* changed member */ );
388 sum0 = ip_csum_update (sum0, old_port0, new_port0,
389 ip4_header_t /* cheat */ ,
390 length /* changed member */ );
391 udp0->checksum = ip_csum_fold (sum0);
396 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
397 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
399 nat_det_out2in_trace_t *t =
400 vlib_add_trace (vm, node, b0, sizeof (*t));
401 t->sw_if_index = sw_if_index0;
402 t->next_index = next0;
403 t->session_index = ~0;
405 t->session_index = ses0 - dm0->sessions;
408 pkts_processed += next0 != NAT_DET_OUT2IN_NEXT_DROP;
410 b1 = vlib_get_buffer (vm, bi1);
412 ip1 = vlib_buffer_get_current (b1);
413 udp1 = ip4_next_header (ip1);
414 tcp1 = (tcp_header_t *) udp1;
416 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
418 if (PREDICT_FALSE (ip1->ttl == 1))
420 vnet_buffer (b1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
421 icmp4_error_set_vnet_buffer (b1, ICMP4_time_exceeded,
422 ICMP4_time_exceeded_ttl_exceeded_in_transit,
424 next1 = NAT_DET_OUT2IN_NEXT_ICMP_ERROR;
428 proto1 = ip_proto_to_nat_proto (ip1->protocol);
430 if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP))
433 ip4_fib_table_get_index_for_sw_if_index (sw_if_index1);
434 icmp1 = (icmp46_header_t *) udp1;
436 next1 = icmp_out2in (sm, b1, ip1, icmp1, sw_if_index1,
437 rx_fib_index1, node, next1, thread_index,
442 key1.ext_host_addr = ip1->src_address;
443 key1.ext_host_port = tcp1->src;
444 key1.out_port = tcp1->dst;
446 dm1 = snat_det_map_by_out (sm, &ip1->dst_address);
447 if (PREDICT_FALSE (!dm1))
449 nat_log_info ("unknown dst address: %U",
450 format_ip4_address, &ip1->dst_address);
451 next1 = NAT_DET_OUT2IN_NEXT_DROP;
452 b1->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
456 snat_det_reverse (dm1, &ip1->dst_address,
457 clib_net_to_host_u16 (tcp1->dst), &new_addr1);
459 ses1 = snat_det_get_ses_by_out (dm1, &new_addr1, key1.as_u64);
460 if (PREDICT_FALSE (!ses1))
462 nat_log_info ("no match src %U:%d dst %U:%d for user %U",
463 format_ip4_address, &ip1->src_address,
464 clib_net_to_host_u16 (tcp1->src),
465 format_ip4_address, &ip1->dst_address,
466 clib_net_to_host_u16 (tcp1->dst),
467 format_ip4_address, &new_addr1);
468 next1 = NAT_DET_OUT2IN_NEXT_DROP;
469 b1->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
472 old_port1 = udp1->dst_port;
473 udp1->dst_port = new_port1 = ses1->in_port;
475 old_addr1 = ip1->dst_address;
476 ip1->dst_address = new_addr1;
477 vnet_buffer (b1)->sw_if_index[VLIB_TX] = sm->inside_fib_index;
479 sum1 = ip1->checksum;
480 sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
482 dst_address /* changed member */ );
483 ip1->checksum = ip_csum_fold (sum1);
485 if (PREDICT_TRUE (proto1 == NAT_PROTOCOL_TCP))
487 if (tcp1->flags & TCP_FLAG_FIN
488 && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
489 ses1->state = SNAT_SESSION_TCP_CLOSE_WAIT;
490 else if (tcp1->flags & TCP_FLAG_ACK
491 && ses1->state == SNAT_SESSION_TCP_LAST_ACK)
492 snat_det_ses_close (dm1, ses1);
494 sum1 = tcp1->checksum;
495 sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
497 dst_address /* changed member */ );
498 sum1 = ip_csum_update (sum1, old_port1, new_port1,
499 ip4_header_t /* cheat */ ,
500 length /* changed member */ );
501 tcp1->checksum = ip_csum_fold (sum1);
503 else if (udp1->checksum)
505 sum1 = udp1->checksum;
506 sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
508 dst_address /* changed member */ );
509 sum1 = ip_csum_update (sum1, old_port1, new_port1,
510 ip4_header_t /* cheat */ ,
511 length /* changed member */ );
512 udp1->checksum = ip_csum_fold (sum1);
517 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
518 && (b1->flags & VLIB_BUFFER_IS_TRACED)))
520 nat_det_out2in_trace_t *t =
521 vlib_add_trace (vm, node, b1, sizeof (*t));
522 t->sw_if_index = sw_if_index1;
523 t->next_index = next1;
524 t->session_index = ~0;
526 t->session_index = ses1 - dm1->sessions;
529 pkts_processed += next1 != NAT_DET_OUT2IN_NEXT_DROP;
531 /* verify speculative enqueues, maybe switch current next frame */
532 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
533 to_next, n_left_to_next,
534 bi0, bi1, next0, next1);
537 while (n_left_from > 0 && n_left_to_next > 0)
541 u32 next0 = NAT_DET_OUT2IN_NEXT_LOOKUP;
545 ip4_address_t new_addr0, old_addr0;
546 u16 new_port0, old_port0;
550 snat_det_out_key_t key0;
552 snat_det_session_t *ses0 = 0;
554 icmp46_header_t *icmp0;
556 /* speculatively enqueue b0 to the current next frame */
564 b0 = vlib_get_buffer (vm, bi0);
566 ip0 = vlib_buffer_get_current (b0);
567 udp0 = ip4_next_header (ip0);
568 tcp0 = (tcp_header_t *) udp0;
570 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
572 if (PREDICT_FALSE (ip0->ttl == 1))
574 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
575 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
576 ICMP4_time_exceeded_ttl_exceeded_in_transit,
578 next0 = NAT_DET_OUT2IN_NEXT_ICMP_ERROR;
582 proto0 = ip_proto_to_nat_proto (ip0->protocol);
584 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
587 ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
588 icmp0 = (icmp46_header_t *) udp0;
590 next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
591 rx_fib_index0, node, next0, thread_index,
596 key0.ext_host_addr = ip0->src_address;
597 key0.ext_host_port = tcp0->src;
598 key0.out_port = tcp0->dst;
600 dm0 = snat_det_map_by_out (sm, &ip0->dst_address);
601 if (PREDICT_FALSE (!dm0))
603 nat_log_info ("unknown dst address: %U",
604 format_ip4_address, &ip0->dst_address);
605 next0 = NAT_DET_OUT2IN_NEXT_DROP;
606 b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
610 snat_det_reverse (dm0, &ip0->dst_address,
611 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
613 ses0 = snat_det_get_ses_by_out (dm0, &new_addr0, key0.as_u64);
614 if (PREDICT_FALSE (!ses0))
616 nat_log_info ("no match src %U:%d dst %U:%d for user %U",
617 format_ip4_address, &ip0->src_address,
618 clib_net_to_host_u16 (tcp0->src),
619 format_ip4_address, &ip0->dst_address,
620 clib_net_to_host_u16 (tcp0->dst),
621 format_ip4_address, &new_addr0);
622 next0 = NAT_DET_OUT2IN_NEXT_DROP;
623 b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
626 old_port0 = udp0->dst_port;
627 udp0->dst_port = new_port0 = ses0->in_port;
629 old_addr0 = ip0->dst_address;
630 ip0->dst_address = new_addr0;
631 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sm->inside_fib_index;
633 sum0 = ip0->checksum;
634 sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
636 dst_address /* changed member */ );
637 ip0->checksum = ip_csum_fold (sum0);
639 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
641 if (tcp0->flags & TCP_FLAG_FIN
642 && ses0->state == SNAT_SESSION_TCP_ESTABLISHED)
643 ses0->state = SNAT_SESSION_TCP_CLOSE_WAIT;
644 else if (tcp0->flags & TCP_FLAG_ACK
645 && ses0->state == SNAT_SESSION_TCP_LAST_ACK)
646 snat_det_ses_close (dm0, ses0);
648 sum0 = tcp0->checksum;
649 sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
651 dst_address /* changed member */ );
652 sum0 = ip_csum_update (sum0, old_port0, new_port0,
653 ip4_header_t /* cheat */ ,
654 length /* changed member */ );
655 tcp0->checksum = ip_csum_fold (sum0);
657 else if (udp0->checksum)
659 sum0 = udp0->checksum;
660 sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
662 dst_address /* changed member */ );
663 sum0 = ip_csum_update (sum0, old_port0, new_port0,
664 ip4_header_t /* cheat */ ,
665 length /* changed member */ );
666 udp0->checksum = ip_csum_fold (sum0);
671 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
672 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
674 nat_det_out2in_trace_t *t =
675 vlib_add_trace (vm, node, b0, sizeof (*t));
676 t->sw_if_index = sw_if_index0;
677 t->next_index = next0;
678 t->session_index = ~0;
680 t->session_index = ses0 - dm0->sessions;
683 pkts_processed += next0 != NAT_DET_OUT2IN_NEXT_DROP;
685 /* verify speculative enqueue, maybe switch current next frame */
686 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
687 to_next, n_left_to_next,
691 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
694 vlib_node_increment_counter (vm, sm->det_out2in_node_index,
695 NAT_DET_OUT2IN_ERROR_OUT2IN_PACKETS,
697 return frame->n_vectors;
701 VLIB_REGISTER_NODE (snat_det_out2in_node) = {
702 .name = "nat44-det-out2in",
703 .vector_size = sizeof (u32),
704 .format_trace = format_nat_det_out2in_trace,
705 .type = VLIB_NODE_TYPE_INTERNAL,
706 .n_errors = ARRAY_LEN(nat_det_out2in_error_strings),
707 .error_strings = nat_det_out2in_error_strings,
708 .runtime_data_bytes = sizeof (snat_runtime_t),
709 .n_next_nodes = NAT_DET_OUT2IN_N_NEXT,
710 /* edit / add dispositions here */
712 [NAT_DET_OUT2IN_NEXT_DROP] = "error-drop",
713 [NAT_DET_OUT2IN_NEXT_LOOKUP] = "ip4-lookup",
714 [NAT_DET_OUT2IN_NEXT_ICMP_ERROR] = "ip4-icmp-error",
720 * fd.io coding-style-patch-verification: ON
723 * eval: (c-set-style "gnu")