2 * Copyright (c) 2017 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 NAT64 IPv4 to IPv6 translation (otside to inside network)
20 #include <nat/nat64.h>
21 #include <nat/nat_inlines.h>
22 #include <vnet/ip/ip4_to_ip6.h>
23 #include <vnet/fib/ip4_fib.h>
24 #include <vnet/udp/udp.h>
30 } nat64_out2in_trace_t;
33 format_nat64_out2in_trace (u8 * s, va_list * args)
35 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
36 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
37 nat64_out2in_trace_t *t = va_arg (*args, nat64_out2in_trace_t *);
40 format (s, "NAT64-out2in: sw_if_index %d, next index %d", t->sw_if_index,
46 #define foreach_nat64_out2in_error \
47 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
48 _(NO_TRANSLATION, "no translation") \
53 #define _(sym,str) NAT64_OUT2IN_ERROR_##sym,
54 foreach_nat64_out2in_error
57 } nat64_out2in_error_t;
59 static char *nat64_out2in_error_strings[] = {
60 #define _(sym,string) string,
61 foreach_nat64_out2in_error
67 NAT64_OUT2IN_NEXT_IP6_LOOKUP,
68 NAT64_OUT2IN_NEXT_IP4_LOOKUP,
69 NAT64_OUT2IN_NEXT_DROP,
71 } nat64_out2in_next_t;
73 typedef struct nat64_out2in_set_ctx_t_
78 } nat64_out2in_set_ctx_t;
81 nat64_out2in_tcp_udp (vlib_main_t * vm, vlib_buffer_t * b,
82 nat64_out2in_set_ctx_t * ctx)
90 ip4_address_t old_src, old_dst;
92 nat64_main_t *nm = &nat64_main;
93 nat64_db_bib_entry_t *bibe;
94 nat64_db_st_entry_t *ste;
97 ip6_address_t ip6_saddr;
98 u8 proto = vnet_buffer (b)->ip.reass.ip_proto;
99 u16 dport = vnet_buffer (b)->ip.reass.l4_dst_port;
100 u16 sport = vnet_buffer (b)->ip.reass.l4_src_port;
101 u32 sw_if_index, fib_index;
102 nat64_db_t *db = &nm->db[ctx->thread_index];
104 ip4 = vlib_buffer_get_current (b);
106 udp_header_t *udp = ip4_next_header (ip4);
107 tcp_header_t *tcp = ip4_next_header (ip4);
108 if (!vnet_buffer (b)->ip.reass.is_non_first_fragment)
110 if (ip4->protocol == IP_PROTOCOL_UDP)
112 checksum = &udp->checksum;
113 //UDP checksum is optional over IPv4 but mandatory for IPv6
114 //We do not check udp->length sanity but use our safe computed value instead
115 if (PREDICT_FALSE (!*checksum))
118 clib_host_to_net_u16 (ip4->length) - sizeof (*ip4);
119 csum = ip_incremental_checksum (0, udp, udp_len);
121 ip_csum_with_carry (csum, clib_host_to_net_u16 (udp_len));
123 ip_csum_with_carry (csum,
124 clib_host_to_net_u16 (IP_PROTOCOL_UDP));
126 ip_csum_with_carry (csum, *((u64 *) (&ip4->src_address)));
127 *checksum = ~ip_csum_fold (csum);
132 checksum = &tcp->checksum;
136 old_src.as_u32 = ip4->src_address.as_u32;
137 old_dst.as_u32 = ip4->dst_address.as_u32;
139 // Deal with fragmented packets
140 u16 frag_offset = ip4_get_fragment_offset (ip4);
141 if (PREDICT_FALSE (ip4_get_fragment_more (ip4) || frag_offset))
144 (ip6_header_t *) u8_ptr_add (ip4,
145 sizeof (*ip4) - sizeof (*ip6) -
148 (ip6_frag_hdr_t *) u8_ptr_add (ip4, sizeof (*ip4) - sizeof (*frag));
149 frag_id = frag_id_4to6 (ip4->fragment_id);
150 vlib_buffer_advance (b, sizeof (*ip4) - sizeof (*ip6) - sizeof (*frag));
154 ip6 = (ip6_header_t *) (((u8 *) ip4) + sizeof (*ip4) - sizeof (*ip6));
155 vlib_buffer_advance (b, sizeof (*ip4) - sizeof (*ip6));
159 ip6->ip_version_traffic_class_and_flow_label =
160 clib_host_to_net_u32 ((6 << 28) + (ip4->tos << 20));
161 ip6->payload_length = u16_net_add (ip4->length, -sizeof (*ip4));
162 ip6->hop_limit = ip4->ttl;
163 ip6->protocol = ip4->protocol;
165 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
166 fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
168 clib_memset (&saddr, 0, sizeof (saddr));
169 saddr.ip4.as_u32 = ip4->src_address.as_u32;
170 clib_memset (&daddr, 0, sizeof (daddr));
171 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
174 nat64_db_st_entry_find (db, &daddr, &saddr, dport, sport, proto,
178 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
184 bibe = nat64_db_bib_entry_find (db, &daddr, dport, proto, fib_index, 0);
189 nat64_compose_ip6 (&ip6_saddr, &old_src, bibe->fib_index);
191 nat64_db_st_entry_create (ctx->thread_index, db, bibe, &ip6_saddr,
197 vlib_set_simple_counter (&nm->total_sessions, ctx->thread_index, 0,
198 db->st.st_entries_num);
201 ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
202 ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
204 ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
205 ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
207 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
209 nat64_session_reset_timeout (ste, ctx->vm);
211 if (PREDICT_FALSE (frag != NULL))
213 frag->next_hdr = ip6->protocol;
214 frag->identification = frag_id;
216 frag->fragment_offset_and_more =
217 ip6_frag_hdr_offset_and_more (frag_offset, 1);
218 ip6->protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
219 ip6->payload_length = u16_net_add (ip6->payload_length, sizeof (*frag));
222 if (!vnet_buffer (b)->ip.reass.is_non_first_fragment)
224 udp->dst_port = bibe->in_port;
226 if (proto == IP_PROTOCOL_TCP)
228 nat64_tcp_session_set_state (ste, tcp, 0);
231 csum = ip_csum_sub_even (*checksum, dport);
232 csum = ip_csum_add_even (csum, udp->dst_port);
233 csum = ip_csum_sub_even (csum, old_src.as_u32);
234 csum = ip_csum_sub_even (csum, old_dst.as_u32);
235 csum = ip_csum_add_even (csum, ip6->src_address.as_u64[0]);
236 csum = ip_csum_add_even (csum, ip6->src_address.as_u64[1]);
237 csum = ip_csum_add_even (csum, ip6->dst_address.as_u64[0]);
238 csum = ip_csum_add_even (csum, ip6->dst_address.as_u64[1]);
239 *checksum = ip_csum_fold (csum);
246 nat64_out2in_icmp_set_cb (vlib_buffer_t * b, ip4_header_t * ip4,
247 ip6_header_t * ip6, void *arg)
249 nat64_main_t *nm = &nat64_main;
250 nat64_out2in_set_ctx_t *ctx = arg;
251 nat64_db_bib_entry_t *bibe;
252 nat64_db_st_entry_t *ste;
253 ip46_address_t saddr, daddr;
254 ip6_address_t ip6_saddr;
255 u32 sw_if_index, fib_index;
256 icmp46_header_t *icmp = ip4_next_header (ip4);
257 nat64_db_t *db = &nm->db[ctx->thread_index];
259 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
260 fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
262 clib_memset (&saddr, 0, sizeof (saddr));
263 saddr.ip4.as_u32 = ip4->src_address.as_u32;
264 clib_memset (&daddr, 0, sizeof (daddr));
265 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
267 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
269 u16 out_id = ((u16 *) (icmp))[2];
271 nat64_db_st_entry_find (db, &daddr, &saddr, out_id, 0,
272 IP_PROTOCOL_ICMP, fib_index, 0);
277 nat64_db_bib_entry_by_index (db, IP_PROTOCOL_ICMP,
285 nat64_db_bib_entry_find (db, &daddr, out_id,
286 IP_PROTOCOL_ICMP, fib_index, 0);
290 nat64_compose_ip6 (&ip6_saddr, &ip4->src_address, bibe->fib_index);
292 nat64_db_st_entry_create (ctx->thread_index, db,
293 bibe, &ip6_saddr, &saddr.ip4, 0);
298 vlib_set_simple_counter (&nm->total_sessions, ctx->thread_index, 0,
299 db->st.st_entries_num);
302 nat64_session_reset_timeout (ste, ctx->vm);
304 ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
305 ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
307 ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
308 ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
309 ((u16 *) (icmp))[2] = bibe->in_port;
311 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
315 ip6_header_t *inner_ip6 = (ip6_header_t *) u8_ptr_add (icmp, 8);
317 nat64_compose_ip6 (&ip6->src_address, &ip4->src_address,
318 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX]);
319 ip6->dst_address.as_u64[0] = inner_ip6->src_address.as_u64[0];
320 ip6->dst_address.as_u64[1] = inner_ip6->src_address.as_u64[1];
327 nat64_out2in_inner_icmp_set_cb (vlib_buffer_t * b, ip4_header_t * ip4,
328 ip6_header_t * ip6, void *arg)
330 nat64_main_t *nm = &nat64_main;
331 nat64_out2in_set_ctx_t *ctx = arg;
332 nat64_db_bib_entry_t *bibe;
333 nat64_db_st_entry_t *ste;
334 ip46_address_t saddr, daddr;
335 u32 sw_if_index, fib_index;
336 u8 proto = ip4->protocol;
337 nat64_db_t *db = &nm->db[ctx->thread_index];
339 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
341 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP6, sw_if_index);
343 clib_memset (&saddr, 0, sizeof (saddr));
344 saddr.ip4.as_u32 = ip4->src_address.as_u32;
345 clib_memset (&daddr, 0, sizeof (daddr));
346 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
348 if (proto == IP_PROTOCOL_ICMP6)
350 icmp46_header_t *icmp = ip4_next_header (ip4);
351 u16 out_id = ((u16 *) (icmp))[2];
352 proto = IP_PROTOCOL_ICMP;
355 (icmp->type == ICMP6_echo_request
356 || icmp->type == ICMP6_echo_reply))
360 nat64_db_st_entry_find (db, &saddr, &daddr, out_id, 0, proto,
365 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
369 ip6->dst_address.as_u64[0] = ste->in_r_addr.as_u64[0];
370 ip6->dst_address.as_u64[1] = ste->in_r_addr.as_u64[1];
371 ip6->src_address.as_u64[0] = bibe->in_addr.as_u64[0];
372 ip6->src_address.as_u64[1] = bibe->in_addr.as_u64[1];
373 ((u16 *) (icmp))[2] = bibe->in_port;
375 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
379 udp_header_t *udp = ip4_next_header (ip4);
380 tcp_header_t *tcp = ip4_next_header (ip4);
381 u16 dport = udp->dst_port;
382 u16 sport = udp->src_port;
387 nat64_db_st_entry_find (db, &saddr, &daddr, sport, dport, proto,
392 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
396 nat64_compose_ip6 (&ip6->dst_address, &daddr.ip4, bibe->fib_index);
397 ip6->src_address.as_u64[0] = bibe->in_addr.as_u64[0];
398 ip6->src_address.as_u64[1] = bibe->in_addr.as_u64[1];
399 udp->src_port = bibe->in_port;
401 if (proto == IP_PROTOCOL_UDP)
402 checksum = &udp->checksum;
404 checksum = &tcp->checksum;
407 csum = ip_csum_sub_even (*checksum, sport);
408 csum = ip_csum_add_even (csum, udp->src_port);
409 *checksum = ip_csum_fold (csum);
412 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
419 nat64_out2in_unk_proto (vlib_main_t * vm, vlib_buffer_t * p,
420 nat64_out2in_set_ctx_t * ctx)
422 ip4_header_t *ip4 = vlib_buffer_get_current (p);
424 ip6_frag_hdr_t *frag;
427 nat64_main_t *nm = &nat64_main;
428 nat64_db_bib_entry_t *bibe;
429 nat64_db_st_entry_t *ste;
430 ip46_address_t saddr, daddr;
431 ip6_address_t ip6_saddr;
432 u32 sw_if_index, fib_index;
433 u8 proto = ip4->protocol;
434 nat64_db_t *db = &nm->db[ctx->thread_index];
436 // Deal with fragmented packets
437 u16 frag_offset = ip4_get_fragment_offset (ip4);
438 if (PREDICT_FALSE (ip4_get_fragment_more (ip4) || frag_offset))
441 (ip6_header_t *) u8_ptr_add (ip4,
442 sizeof (*ip4) - sizeof (*ip6) -
445 (ip6_frag_hdr_t *) u8_ptr_add (ip4, sizeof (*ip4) - sizeof (*frag));
446 frag_id = frag_id_4to6 (ip4->fragment_id);
447 vlib_buffer_advance (p, sizeof (*ip4) - sizeof (*ip6) - sizeof (*frag));
451 ip6 = (ip6_header_t *) (((u8 *) ip4) + sizeof (*ip4) - sizeof (*ip6));
452 vlib_buffer_advance (p, sizeof (*ip4) - sizeof (*ip6));
456 ip6->ip_version_traffic_class_and_flow_label =
457 clib_host_to_net_u32 ((6 << 28) + (ip4->tos << 20));
458 ip6->payload_length = u16_net_add (ip4->length, -sizeof (*ip4));
459 ip6->hop_limit = ip4->ttl;
460 ip6->protocol = ip4->protocol;
462 if (PREDICT_FALSE (frag != NULL))
464 frag->next_hdr = ip6->protocol;
465 frag->identification = frag_id;
467 frag->fragment_offset_and_more =
468 ip6_frag_hdr_offset_and_more (frag_offset, 1);
469 ip6->protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
470 ip6->payload_length = u16_net_add (ip6->payload_length, sizeof (*frag));
473 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
474 fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
476 clib_memset (&saddr, 0, sizeof (saddr));
477 saddr.ip4.as_u32 = ip4->src_address.as_u32;
478 clib_memset (&daddr, 0, sizeof (daddr));
479 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
482 nat64_db_st_entry_find (db, &daddr, &saddr, 0, 0, proto, fib_index, 0);
485 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
491 bibe = nat64_db_bib_entry_find (db, &daddr, 0, proto, fib_index, 0);
496 nat64_compose_ip6 (&ip6_saddr, &ip4->src_address, bibe->fib_index);
497 ste = nat64_db_st_entry_create (ctx->thread_index, db,
498 bibe, &ip6_saddr, &saddr.ip4, 0);
503 vlib_set_simple_counter (&nm->total_sessions, ctx->thread_index, 0,
504 db->st.st_entries_num);
507 nat64_session_reset_timeout (ste, ctx->vm);
509 ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
510 ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
512 ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
513 ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
515 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
520 VLIB_NODE_FN (nat64_out2in_node) (vlib_main_t * vm,
521 vlib_node_runtime_t * node,
522 vlib_frame_t * frame)
524 u32 n_left_from, *from, *to_next;
525 nat64_out2in_next_t next_index;
526 nat64_main_t *nm = &nat64_main;
527 u32 thread_index = vm->thread_index;
529 from = vlib_frame_vector_args (frame);
530 n_left_from = frame->n_vectors;
531 next_index = node->cached_next_index;
532 while (n_left_from > 0)
536 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
538 while (n_left_from > 0 && n_left_to_next > 0)
545 nat64_out2in_set_ctx_t ctx0;
549 /* speculatively enqueue b0 to the current next frame */
557 b0 = vlib_get_buffer (vm, bi0);
558 ip40 = vlib_buffer_get_current (b0);
562 ctx0.thread_index = thread_index;
564 next0 = NAT64_OUT2IN_NEXT_IP6_LOOKUP;
566 proto0 = ip_proto_to_nat_proto (ip40->protocol);
567 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
568 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
570 if (nat64_out2in_unk_proto (vm, b0, &ctx0))
572 next0 = NAT64_OUT2IN_NEXT_DROP;
573 b0->error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
575 vlib_increment_simple_counter (&nm->counters.out2in.other,
576 thread_index, sw_if_index0, 1);
580 if (proto0 == NAT_PROTOCOL_ICMP)
582 vlib_increment_simple_counter (&nm->counters.out2in.icmp,
583 thread_index, sw_if_index0, 1);
585 (b0, nat64_out2in_icmp_set_cb, &ctx0,
586 nat64_out2in_inner_icmp_set_cb, &ctx0))
588 next0 = NAT64_OUT2IN_NEXT_DROP;
589 b0->error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
595 if (proto0 == NAT_PROTOCOL_TCP)
596 vlib_increment_simple_counter (&nm->counters.out2in.tcp,
597 thread_index, sw_if_index0, 1);
599 vlib_increment_simple_counter (&nm->counters.out2in.udp,
600 thread_index, sw_if_index0, 1);
602 if (nat64_out2in_tcp_udp (vm, b0, &ctx0))
604 udp0 = ip4_next_header (ip40);
606 * Send DHCP packets to the ipv4 stack, or we won't
607 * be able to use dhcp client on the outside interface
609 if ((proto0 == NAT_PROTOCOL_UDP)
610 && (udp0->dst_port ==
611 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client)))
613 next0 = NAT64_OUT2IN_NEXT_IP4_LOOKUP;
616 next0 = NAT64_OUT2IN_NEXT_DROP;
617 b0->error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
623 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
624 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
626 nat64_out2in_trace_t *t =
627 vlib_add_trace (vm, node, b0, sizeof (*t));
628 t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
629 t->next_index = next0;
632 if (next0 == NAT64_OUT2IN_NEXT_DROP)
634 vlib_increment_simple_counter (&nm->counters.out2in.drops,
635 thread_index, sw_if_index0, 1);
638 /* verify speculative enqueue, maybe switch current next frame */
639 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
640 n_left_to_next, bi0, next0);
642 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
644 return frame->n_vectors;
648 VLIB_REGISTER_NODE (nat64_out2in_node) = {
649 .name = "nat64-out2in",
650 .vector_size = sizeof (u32),
651 .format_trace = format_nat64_out2in_trace,
652 .type = VLIB_NODE_TYPE_INTERNAL,
653 .n_errors = ARRAY_LEN (nat64_out2in_error_strings),
654 .error_strings = nat64_out2in_error_strings,
655 .n_next_nodes = NAT64_OUT2IN_N_NEXT,
656 /* edit / add dispositions here */
658 [NAT64_OUT2IN_NEXT_DROP] = "error-drop",
659 [NAT64_OUT2IN_NEXT_IP6_LOOKUP] = "ip6-lookup",
660 [NAT64_OUT2IN_NEXT_IP4_LOOKUP] = "ip4-lookup",
665 typedef struct nat64_out2in_frag_set_ctx_t_
673 } nat64_out2in_frag_set_ctx_t;
675 #define foreach_nat64_out2in_handoff_error \
676 _(CONGESTION_DROP, "congestion drop") \
677 _(SAME_WORKER, "same worker") \
678 _(DO_HANDOFF, "do handoff")
682 #define _(sym,str) NAT64_OUT2IN_HANDOFF_ERROR_##sym,
683 foreach_nat64_out2in_handoff_error
685 NAT64_OUT2IN_HANDOFF_N_ERROR,
686 } nat64_out2in_handoff_error_t;
688 static char *nat64_out2in_handoff_error_strings[] = {
689 #define _(sym,string) string,
690 foreach_nat64_out2in_handoff_error
696 u32 next_worker_index;
697 } nat64_out2in_handoff_trace_t;
700 format_nat64_out2in_handoff_trace (u8 * s, va_list * args)
702 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
703 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
704 nat64_out2in_handoff_trace_t *t =
705 va_arg (*args, nat64_out2in_handoff_trace_t *);
708 format (s, "NAT64-OUT2IN-HANDOFF: next-worker %d", t->next_worker_index);
713 VLIB_NODE_FN (nat64_out2in_handoff_node) (vlib_main_t * vm,
714 vlib_node_runtime_t * node,
715 vlib_frame_t * frame)
717 nat64_main_t *nm = &nat64_main;
718 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
719 u32 n_enq, n_left_from, *from;
720 u16 thread_indices[VLIB_FRAME_SIZE], *ti;
722 u32 thread_index = vm->thread_index;
723 u32 do_handoff = 0, same_worker = 0;
725 from = vlib_frame_vector_args (frame);
726 n_left_from = frame->n_vectors;
727 vlib_get_buffers (vm, from, bufs, n_left_from);
732 fq_index = nm->fq_out2in_index;
734 while (n_left_from > 0)
738 ip0 = vlib_buffer_get_current (b[0]);
739 ti[0] = nat64_get_worker_out2in (b[0], ip0);
741 if (ti[0] != thread_index)
747 ((node->flags & VLIB_NODE_FLAG_TRACE)
748 && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
750 nat64_out2in_handoff_trace_t *t =
751 vlib_add_trace (vm, node, b[0], sizeof (*t));
752 t->next_worker_index = ti[0];
761 vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices,
762 frame->n_vectors, 1);
764 if (n_enq < frame->n_vectors)
765 vlib_node_increment_counter (vm, node->node_index,
766 NAT64_OUT2IN_HANDOFF_ERROR_CONGESTION_DROP,
767 frame->n_vectors - n_enq);
768 vlib_node_increment_counter (vm, node->node_index,
769 NAT64_OUT2IN_HANDOFF_ERROR_SAME_WORKER,
771 vlib_node_increment_counter (vm, node->node_index,
772 NAT64_OUT2IN_HANDOFF_ERROR_DO_HANDOFF,
775 return frame->n_vectors;
779 VLIB_REGISTER_NODE (nat64_out2in_handoff_node) = {
780 .name = "nat64-out2in-handoff",
781 .vector_size = sizeof (u32),
782 .format_trace = format_nat64_out2in_handoff_trace,
783 .type = VLIB_NODE_TYPE_INTERNAL,
784 .n_errors = ARRAY_LEN(nat64_out2in_handoff_error_strings),
785 .error_strings = nat64_out2in_handoff_error_strings,
796 * fd.io coding-style-patch-verification: ON
799 * eval: (c-set-style "gnu")