2 * Copyright (c) 2020 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.
16 #include <nat/nat64/nat64.h>
17 #include <vnet/ip/ip4_to_ip6.h>
18 #include <vnet/fib/ip4_fib.h>
19 #include <vnet/udp/udp.h>
25 } nat64_out2in_trace_t;
28 format_nat64_out2in_trace (u8 * s, va_list * args)
30 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
31 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
32 nat64_out2in_trace_t *t = va_arg (*args, nat64_out2in_trace_t *);
35 format (s, "NAT64-out2in: sw_if_index %d, next index %d", t->sw_if_index,
41 #define foreach_nat64_out2in_error \
42 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
43 _(NO_TRANSLATION, "no translation") \
48 #define _(sym,str) NAT64_OUT2IN_ERROR_##sym,
49 foreach_nat64_out2in_error
52 } nat64_out2in_error_t;
54 static char *nat64_out2in_error_strings[] = {
55 #define _(sym,string) string,
56 foreach_nat64_out2in_error
62 NAT64_OUT2IN_NEXT_IP6_LOOKUP,
63 NAT64_OUT2IN_NEXT_IP4_LOOKUP,
64 NAT64_OUT2IN_NEXT_DROP,
66 } nat64_out2in_next_t;
68 typedef struct nat64_out2in_set_ctx_t_
73 } nat64_out2in_set_ctx_t;
76 nat64_out2in_tcp_udp (vlib_main_t * vm, vlib_buffer_t * b,
77 nat64_out2in_set_ctx_t * ctx)
85 ip4_address_t old_src, old_dst;
87 nat64_main_t *nm = &nat64_main;
88 nat64_db_bib_entry_t *bibe;
89 nat64_db_st_entry_t *ste;
92 ip6_address_t ip6_saddr;
93 u8 proto = vnet_buffer (b)->ip.reass.ip_proto;
94 u16 dport = vnet_buffer (b)->ip.reass.l4_dst_port;
95 u16 sport = vnet_buffer (b)->ip.reass.l4_src_port;
96 u32 sw_if_index, fib_index;
97 nat64_db_t *db = &nm->db[ctx->thread_index];
99 ip4 = vlib_buffer_get_current (b);
101 udp_header_t *udp = ip4_next_header (ip4);
102 tcp_header_t *tcp = ip4_next_header (ip4);
103 if (!vnet_buffer (b)->ip.reass.is_non_first_fragment)
105 if (ip4->protocol == IP_PROTOCOL_UDP)
107 checksum = &udp->checksum;
108 //UDP checksum is optional over IPv4 but mandatory for IPv6
109 //We do not check udp->length sanity but use our safe computed value instead
110 if (PREDICT_FALSE (!*checksum))
113 clib_host_to_net_u16 (ip4->length) - sizeof (*ip4);
114 csum = ip_incremental_checksum (0, udp, udp_len);
116 ip_csum_with_carry (csum, clib_host_to_net_u16 (udp_len));
118 ip_csum_with_carry (csum,
119 clib_host_to_net_u16 (IP_PROTOCOL_UDP));
121 ip_csum_with_carry (csum, *((u64 *) (&ip4->src_address)));
122 *checksum = ~ip_csum_fold (csum);
127 checksum = &tcp->checksum;
131 old_src.as_u32 = ip4->src_address.as_u32;
132 old_dst.as_u32 = ip4->dst_address.as_u32;
134 // Deal with fragmented packets
135 u16 frag_offset = ip4_get_fragment_offset (ip4);
136 if (PREDICT_FALSE (ip4_get_fragment_more (ip4) || frag_offset))
139 (ip6_header_t *) u8_ptr_add (ip4,
140 sizeof (*ip4) - sizeof (*ip6) -
143 (ip6_frag_hdr_t *) u8_ptr_add (ip4, sizeof (*ip4) - sizeof (*frag));
144 frag_id = frag_id_4to6 (ip4->fragment_id);
145 vlib_buffer_advance (b, sizeof (*ip4) - sizeof (*ip6) - sizeof (*frag));
149 ip6 = (ip6_header_t *) (((u8 *) ip4) + sizeof (*ip4) - sizeof (*ip6));
150 vlib_buffer_advance (b, sizeof (*ip4) - sizeof (*ip6));
154 ip6->ip_version_traffic_class_and_flow_label =
155 clib_host_to_net_u32 ((6 << 28) + (ip4->tos << 20));
156 ip6->payload_length = u16_net_add (ip4->length, -sizeof (*ip4));
157 ip6->hop_limit = ip4->ttl;
158 ip6->protocol = ip4->protocol;
160 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
161 fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
163 clib_memset (&saddr, 0, sizeof (saddr));
164 saddr.ip4.as_u32 = ip4->src_address.as_u32;
165 clib_memset (&daddr, 0, sizeof (daddr));
166 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
169 nat64_db_st_entry_find (db, &daddr, &saddr, dport, sport, proto,
173 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
179 bibe = nat64_db_bib_entry_find (db, &daddr, dport, proto, fib_index, 0);
184 nat64_compose_ip6 (&ip6_saddr, &old_src, bibe->fib_index);
186 nat64_db_st_entry_create (ctx->thread_index, db, bibe, &ip6_saddr,
192 vlib_set_simple_counter (&nm->total_sessions, ctx->thread_index, 0,
193 db->st.st_entries_num);
196 ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
197 ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
199 ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
200 ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
202 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
204 nat64_session_reset_timeout (ste, ctx->vm);
206 if (PREDICT_FALSE (frag != NULL))
208 frag->next_hdr = ip6->protocol;
209 frag->identification = frag_id;
211 frag->fragment_offset_and_more =
212 ip6_frag_hdr_offset_and_more (frag_offset, 1);
213 ip6->protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
214 ip6->payload_length = u16_net_add (ip6->payload_length, sizeof (*frag));
217 if (!vnet_buffer (b)->ip.reass.is_non_first_fragment)
219 udp->dst_port = bibe->in_port;
221 if (proto == IP_PROTOCOL_TCP)
223 nat64_tcp_session_set_state (ste, tcp, 0);
226 csum = ip_csum_sub_even (*checksum, dport);
227 csum = ip_csum_add_even (csum, udp->dst_port);
228 csum = ip_csum_sub_even (csum, old_src.as_u32);
229 csum = ip_csum_sub_even (csum, old_dst.as_u32);
230 csum = ip_csum_add_even (csum, ip6->src_address.as_u64[0]);
231 csum = ip_csum_add_even (csum, ip6->src_address.as_u64[1]);
232 csum = ip_csum_add_even (csum, ip6->dst_address.as_u64[0]);
233 csum = ip_csum_add_even (csum, ip6->dst_address.as_u64[1]);
234 *checksum = ip_csum_fold (csum);
241 nat64_out2in_icmp_set_cb (vlib_buffer_t * b, ip4_header_t * ip4,
242 ip6_header_t * ip6, void *arg)
244 nat64_main_t *nm = &nat64_main;
245 nat64_out2in_set_ctx_t *ctx = arg;
246 nat64_db_bib_entry_t *bibe;
247 nat64_db_st_entry_t *ste;
248 ip46_address_t saddr, daddr;
249 ip6_address_t ip6_saddr;
250 u32 sw_if_index, fib_index;
251 icmp46_header_t *icmp = ip4_next_header (ip4);
252 nat64_db_t *db = &nm->db[ctx->thread_index];
254 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
255 fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
257 clib_memset (&saddr, 0, sizeof (saddr));
258 saddr.ip4.as_u32 = ip4->src_address.as_u32;
259 clib_memset (&daddr, 0, sizeof (daddr));
260 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
262 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
264 u16 out_id = ((u16 *) (icmp))[2];
266 nat64_db_st_entry_find (db, &daddr, &saddr, out_id, 0,
267 IP_PROTOCOL_ICMP, fib_index, 0);
272 nat64_db_bib_entry_by_index (db, IP_PROTOCOL_ICMP,
280 nat64_db_bib_entry_find (db, &daddr, out_id,
281 IP_PROTOCOL_ICMP, fib_index, 0);
285 nat64_compose_ip6 (&ip6_saddr, &ip4->src_address, bibe->fib_index);
287 nat64_db_st_entry_create (ctx->thread_index, db,
288 bibe, &ip6_saddr, &saddr.ip4, 0);
293 vlib_set_simple_counter (&nm->total_sessions, ctx->thread_index, 0,
294 db->st.st_entries_num);
297 nat64_session_reset_timeout (ste, ctx->vm);
299 ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
300 ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
302 ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
303 ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
304 ((u16 *) (icmp))[2] = bibe->in_port;
306 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
310 ip6_header_t *inner_ip6 = (ip6_header_t *) u8_ptr_add (icmp, 8);
312 nat64_compose_ip6 (&ip6->src_address, &ip4->src_address,
313 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX]);
314 ip6->dst_address.as_u64[0] = inner_ip6->src_address.as_u64[0];
315 ip6->dst_address.as_u64[1] = inner_ip6->src_address.as_u64[1];
322 nat64_out2in_inner_icmp_set_cb (vlib_buffer_t * b, ip4_header_t * ip4,
323 ip6_header_t * ip6, void *arg)
325 nat64_main_t *nm = &nat64_main;
326 nat64_out2in_set_ctx_t *ctx = arg;
327 nat64_db_bib_entry_t *bibe;
328 nat64_db_st_entry_t *ste;
329 ip46_address_t saddr, daddr;
330 u32 sw_if_index, fib_index;
331 u8 proto = ip4->protocol;
332 nat64_db_t *db = &nm->db[ctx->thread_index];
334 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
336 fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP6, sw_if_index);
338 clib_memset (&saddr, 0, sizeof (saddr));
339 saddr.ip4.as_u32 = ip4->src_address.as_u32;
340 clib_memset (&daddr, 0, sizeof (daddr));
341 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
343 if (proto == IP_PROTOCOL_ICMP6)
345 icmp46_header_t *icmp = ip4_next_header (ip4);
346 u16 out_id = ((u16 *) (icmp))[2];
347 proto = IP_PROTOCOL_ICMP;
350 (icmp->type == ICMP6_echo_request
351 || icmp->type == ICMP6_echo_reply))
355 nat64_db_st_entry_find (db, &saddr, &daddr, out_id, 0, proto,
360 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
364 ip6->dst_address.as_u64[0] = ste->in_r_addr.as_u64[0];
365 ip6->dst_address.as_u64[1] = ste->in_r_addr.as_u64[1];
366 ip6->src_address.as_u64[0] = bibe->in_addr.as_u64[0];
367 ip6->src_address.as_u64[1] = bibe->in_addr.as_u64[1];
368 ((u16 *) (icmp))[2] = bibe->in_port;
370 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
374 udp_header_t *udp = ip4_next_header (ip4);
375 tcp_header_t *tcp = ip4_next_header (ip4);
376 u16 dport = udp->dst_port;
377 u16 sport = udp->src_port;
382 nat64_db_st_entry_find (db, &saddr, &daddr, sport, dport, proto,
387 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
391 nat64_compose_ip6 (&ip6->dst_address, &daddr.ip4, bibe->fib_index);
392 ip6->src_address.as_u64[0] = bibe->in_addr.as_u64[0];
393 ip6->src_address.as_u64[1] = bibe->in_addr.as_u64[1];
394 udp->src_port = bibe->in_port;
396 if (proto == IP_PROTOCOL_UDP)
397 checksum = &udp->checksum;
399 checksum = &tcp->checksum;
402 csum = ip_csum_sub_even (*checksum, sport);
403 csum = ip_csum_add_even (csum, udp->src_port);
404 *checksum = ip_csum_fold (csum);
407 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
414 nat64_out2in_unk_proto (vlib_main_t * vm, vlib_buffer_t * p,
415 nat64_out2in_set_ctx_t * ctx)
417 ip4_header_t *ip4 = vlib_buffer_get_current (p);
419 ip6_frag_hdr_t *frag;
422 nat64_main_t *nm = &nat64_main;
423 nat64_db_bib_entry_t *bibe;
424 nat64_db_st_entry_t *ste;
425 ip46_address_t saddr, daddr;
426 ip6_address_t ip6_saddr;
427 u32 sw_if_index, fib_index;
428 u8 proto = ip4->protocol;
429 nat64_db_t *db = &nm->db[ctx->thread_index];
431 // Deal with fragmented packets
432 u16 frag_offset = ip4_get_fragment_offset (ip4);
433 if (PREDICT_FALSE (ip4_get_fragment_more (ip4) || frag_offset))
436 (ip6_header_t *) u8_ptr_add (ip4,
437 sizeof (*ip4) - sizeof (*ip6) -
440 (ip6_frag_hdr_t *) u8_ptr_add (ip4, sizeof (*ip4) - sizeof (*frag));
441 frag_id = frag_id_4to6 (ip4->fragment_id);
442 vlib_buffer_advance (p, sizeof (*ip4) - sizeof (*ip6) - sizeof (*frag));
446 ip6 = (ip6_header_t *) (((u8 *) ip4) + sizeof (*ip4) - sizeof (*ip6));
447 vlib_buffer_advance (p, sizeof (*ip4) - sizeof (*ip6));
451 ip6->ip_version_traffic_class_and_flow_label =
452 clib_host_to_net_u32 ((6 << 28) + (ip4->tos << 20));
453 ip6->payload_length = u16_net_add (ip4->length, -sizeof (*ip4));
454 ip6->hop_limit = ip4->ttl;
455 ip6->protocol = ip4->protocol;
457 if (PREDICT_FALSE (frag != NULL))
459 frag->next_hdr = ip6->protocol;
460 frag->identification = frag_id;
462 frag->fragment_offset_and_more =
463 ip6_frag_hdr_offset_and_more (frag_offset, 1);
464 ip6->protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
465 ip6->payload_length = u16_net_add (ip6->payload_length, sizeof (*frag));
468 sw_if_index = vnet_buffer (ctx->b)->sw_if_index[VLIB_RX];
469 fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
471 clib_memset (&saddr, 0, sizeof (saddr));
472 saddr.ip4.as_u32 = ip4->src_address.as_u32;
473 clib_memset (&daddr, 0, sizeof (daddr));
474 daddr.ip4.as_u32 = ip4->dst_address.as_u32;
477 nat64_db_st_entry_find (db, &daddr, &saddr, 0, 0, proto, fib_index, 0);
480 bibe = nat64_db_bib_entry_by_index (db, proto, ste->bibe_index);
486 bibe = nat64_db_bib_entry_find (db, &daddr, 0, proto, fib_index, 0);
491 nat64_compose_ip6 (&ip6_saddr, &ip4->src_address, bibe->fib_index);
492 ste = nat64_db_st_entry_create (ctx->thread_index, db,
493 bibe, &ip6_saddr, &saddr.ip4, 0);
498 vlib_set_simple_counter (&nm->total_sessions, ctx->thread_index, 0,
499 db->st.st_entries_num);
502 nat64_session_reset_timeout (ste, ctx->vm);
504 ip6->src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
505 ip6->src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
507 ip6->dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
508 ip6->dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
510 vnet_buffer (ctx->b)->sw_if_index[VLIB_TX] = bibe->fib_index;
515 VLIB_NODE_FN (nat64_out2in_node) (vlib_main_t * vm,
516 vlib_node_runtime_t * node,
517 vlib_frame_t * frame)
519 u32 n_left_from, *from, *to_next;
520 nat64_out2in_next_t next_index;
521 nat64_main_t *nm = &nat64_main;
522 u32 thread_index = vm->thread_index;
524 from = vlib_frame_vector_args (frame);
525 n_left_from = frame->n_vectors;
526 next_index = node->cached_next_index;
527 while (n_left_from > 0)
531 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
533 while (n_left_from > 0 && n_left_to_next > 0)
540 nat64_out2in_set_ctx_t ctx0;
544 /* speculatively enqueue b0 to the current next frame */
552 b0 = vlib_get_buffer (vm, bi0);
553 ip40 = vlib_buffer_get_current (b0);
557 ctx0.thread_index = thread_index;
559 next0 = NAT64_OUT2IN_NEXT_IP6_LOOKUP;
561 proto0 = ip_proto_to_nat_proto (ip40->protocol);
562 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
563 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
565 if (nat64_out2in_unk_proto (vm, b0, &ctx0))
567 next0 = NAT64_OUT2IN_NEXT_DROP;
568 b0->error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
570 vlib_increment_simple_counter (&nm->counters.out2in.other,
571 thread_index, sw_if_index0, 1);
575 if (proto0 == NAT_PROTOCOL_ICMP)
577 vlib_increment_simple_counter (&nm->counters.out2in.icmp,
578 thread_index, sw_if_index0, 1);
580 (b0, nat64_out2in_icmp_set_cb, &ctx0,
581 nat64_out2in_inner_icmp_set_cb, &ctx0))
583 next0 = NAT64_OUT2IN_NEXT_DROP;
584 b0->error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
590 if (proto0 == NAT_PROTOCOL_TCP)
591 vlib_increment_simple_counter (&nm->counters.out2in.tcp,
592 thread_index, sw_if_index0, 1);
594 vlib_increment_simple_counter (&nm->counters.out2in.udp,
595 thread_index, sw_if_index0, 1);
597 if (nat64_out2in_tcp_udp (vm, b0, &ctx0))
599 udp0 = ip4_next_header (ip40);
601 * Send DHCP packets to the ipv4 stack, or we won't
602 * be able to use dhcp client on the outside interface
604 if ((proto0 == NAT_PROTOCOL_UDP)
605 && (udp0->dst_port ==
606 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client)))
608 next0 = NAT64_OUT2IN_NEXT_IP4_LOOKUP;
611 next0 = NAT64_OUT2IN_NEXT_DROP;
612 b0->error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
618 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
619 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
621 nat64_out2in_trace_t *t =
622 vlib_add_trace (vm, node, b0, sizeof (*t));
623 t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
624 t->next_index = next0;
627 if (next0 == NAT64_OUT2IN_NEXT_DROP)
629 vlib_increment_simple_counter (&nm->counters.out2in.drops,
630 thread_index, sw_if_index0, 1);
633 /* verify speculative enqueue, maybe switch current next frame */
634 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
635 n_left_to_next, bi0, next0);
637 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
639 return frame->n_vectors;
643 VLIB_REGISTER_NODE (nat64_out2in_node) = {
644 .name = "nat64-out2in",
645 .vector_size = sizeof (u32),
646 .format_trace = format_nat64_out2in_trace,
647 .type = VLIB_NODE_TYPE_INTERNAL,
648 .n_errors = ARRAY_LEN (nat64_out2in_error_strings),
649 .error_strings = nat64_out2in_error_strings,
650 .n_next_nodes = NAT64_OUT2IN_N_NEXT,
651 /* edit / add dispositions here */
653 [NAT64_OUT2IN_NEXT_DROP] = "error-drop",
654 [NAT64_OUT2IN_NEXT_IP6_LOOKUP] = "ip6-lookup",
655 [NAT64_OUT2IN_NEXT_IP4_LOOKUP] = "ip4-lookup",
660 typedef struct nat64_out2in_frag_set_ctx_t_
668 } nat64_out2in_frag_set_ctx_t;
670 #define foreach_nat64_out2in_handoff_error \
671 _(CONGESTION_DROP, "congestion drop") \
672 _(SAME_WORKER, "same worker") \
673 _(DO_HANDOFF, "do handoff")
677 #define _(sym,str) NAT64_OUT2IN_HANDOFF_ERROR_##sym,
678 foreach_nat64_out2in_handoff_error
680 NAT64_OUT2IN_HANDOFF_N_ERROR,
681 } nat64_out2in_handoff_error_t;
683 static char *nat64_out2in_handoff_error_strings[] = {
684 #define _(sym,string) string,
685 foreach_nat64_out2in_handoff_error
691 u32 next_worker_index;
692 } nat64_out2in_handoff_trace_t;
695 format_nat64_out2in_handoff_trace (u8 * s, va_list * args)
697 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
698 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
699 nat64_out2in_handoff_trace_t *t =
700 va_arg (*args, nat64_out2in_handoff_trace_t *);
703 format (s, "NAT64-OUT2IN-HANDOFF: next-worker %d", t->next_worker_index);
708 VLIB_NODE_FN (nat64_out2in_handoff_node) (vlib_main_t * vm,
709 vlib_node_runtime_t * node,
710 vlib_frame_t * frame)
712 nat64_main_t *nm = &nat64_main;
713 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
714 u32 n_enq, n_left_from, *from;
715 u16 thread_indices[VLIB_FRAME_SIZE], *ti;
717 u32 thread_index = vm->thread_index;
718 u32 do_handoff = 0, same_worker = 0;
720 from = vlib_frame_vector_args (frame);
721 n_left_from = frame->n_vectors;
722 vlib_get_buffers (vm, from, bufs, n_left_from);
727 fq_index = nm->fq_out2in_index;
729 while (n_left_from > 0)
733 ip0 = vlib_buffer_get_current (b[0]);
734 ti[0] = nat64_get_worker_out2in (b[0], ip0);
736 if (ti[0] != thread_index)
742 ((node->flags & VLIB_NODE_FLAG_TRACE)
743 && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
745 nat64_out2in_handoff_trace_t *t =
746 vlib_add_trace (vm, node, b[0], sizeof (*t));
747 t->next_worker_index = ti[0];
756 vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices,
757 frame->n_vectors, 1);
759 if (n_enq < frame->n_vectors)
760 vlib_node_increment_counter (vm, node->node_index,
761 NAT64_OUT2IN_HANDOFF_ERROR_CONGESTION_DROP,
762 frame->n_vectors - n_enq);
763 vlib_node_increment_counter (vm, node->node_index,
764 NAT64_OUT2IN_HANDOFF_ERROR_SAME_WORKER,
766 vlib_node_increment_counter (vm, node->node_index,
767 NAT64_OUT2IN_HANDOFF_ERROR_DO_HANDOFF,
770 return frame->n_vectors;
774 VLIB_REGISTER_NODE (nat64_out2in_handoff_node) = {
775 .name = "nat64-out2in-handoff",
776 .vector_size = sizeof (u32),
777 .format_trace = format_nat64_out2in_handoff_trace,
778 .type = VLIB_NODE_TYPE_INTERNAL,
779 .n_errors = ARRAY_LEN(nat64_out2in_handoff_error_strings),
780 .error_strings = nat64_out2in_handoff_error_strings,
791 * fd.io coding-style-patch-verification: ON
794 * eval: (c-set-style "gnu")