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.
18 * @brief IPv4 Shallow Virtual Reassembly.
20 * This file contains the source code for IPv4 Shallow Virtual reassembly.
23 #include <vppinfra/vec.h>
24 #include <vnet/vnet.h>
25 #include <vnet/ip/ip.h>
26 #include <vnet/ip/ip4_to_ip6.h>
27 #include <vppinfra/fifo.h>
28 #include <vppinfra/bihash_16_8.h>
29 #include <vnet/ip/reass/ip4_sv_reass.h>
31 #define MSEC_PER_SEC 1000
32 #define IP4_SV_REASS_TIMEOUT_DEFAULT_MS 100
33 #define IP4_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
34 #define IP4_SV_REASS_MAX_REASSEMBLIES_DEFAULT 1024
35 #define IP4_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3
36 #define IP4_SV_REASS_HT_LOAD_FACTOR (0.75)
41 IP4_SV_REASS_RC_TOO_MANY_FRAGMENTS,
42 IP4_SV_REASS_RC_UNSUPP_IP_PROTO,
79 clib_bihash_kv_16_8_t kv;
85 ip4_sv_reass_key_t key;
86 // time when last packet was received
88 // internal id of this reassembly
90 // trace operation counter
92 // minimum fragment length for this reassembly - used to estimate MTU
93 u16 min_fragment_length;
94 // buffer indexes of buffers in this reassembly in chronological order -
95 // including overlaps and duplicate fragments
97 // set to true when this reassembly is completed
101 u8 icmp_type_or_tcp_flags;
116 ip4_sv_reass_t *pool;
119 clib_spinlock_t lock;
124 } ip4_sv_reass_per_thread_t;
131 u32 expire_walk_interval_ms;
132 // maximum number of fragments in one reassembly
134 // maximum number of reassemblies
138 clib_bihash_16_8_t hash;
140 ip4_sv_reass_per_thread_t *per_thread_data;
143 vlib_main_t *vlib_main;
144 vnet_main_t *vnet_main;
146 // node index of ip4-drop node
148 u32 ip4_sv_reass_expire_node_idx;
150 /** Worker handoff */
152 u32 fq_feature_index;
154 // reference count for enabling/disabling feature - per interface
155 u32 *feature_use_refcount_per_intf;
157 // reference count for enabling/disabling feature - per interface
158 u32 *output_feature_use_refcount_per_intf;
160 } ip4_sv_reass_main_t;
162 extern ip4_sv_reass_main_t ip4_sv_reass_main;
164 #ifndef CLIB_MARCH_VARIANT
165 ip4_sv_reass_main_t ip4_sv_reass_main;
166 #endif /* CLIB_MARCH_VARIANT */
170 IP4_SV_REASSEMBLY_NEXT_INPUT,
171 IP4_SV_REASSEMBLY_NEXT_DROP,
172 IP4_SV_REASSEMBLY_NEXT_HANDOFF,
173 IP4_SV_REASSEMBLY_N_NEXT,
174 } ip4_sv_reass_next_t;
178 REASS_FRAGMENT_CACHE,
180 REASS_FRAGMENT_FORWARD,
182 } ip4_sv_reass_trace_operation_e;
186 ip4_sv_reass_trace_operation_e action;
192 int l4_layer_truncated;
193 } ip4_sv_reass_trace_t;
195 extern vlib_node_registration_t ip4_sv_reass_node;
196 extern vlib_node_registration_t ip4_sv_reass_node_feature;
199 format_ip4_sv_reass_trace (u8 * s, va_list * args)
201 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
202 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
203 ip4_sv_reass_trace_t *t = va_arg (*args, ip4_sv_reass_trace_t *);
204 if (REASS_PASSTHROUGH != t->action)
206 s = format (s, "reass id: %u, op id: %u ", t->reass_id, t->op_id);
210 case REASS_FRAGMENT_CACHE:
211 s = format (s, "[cached]");
215 format (s, "[finish, ip proto=%u, src_port=%u, dst_port=%u]",
216 t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
217 clib_net_to_host_u16 (t->l4_dst_port));
219 case REASS_FRAGMENT_FORWARD:
221 format (s, "[forward, ip proto=%u, src_port=%u, dst_port=%u]",
222 t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
223 clib_net_to_host_u16 (t->l4_dst_port));
225 case REASS_PASSTHROUGH:
226 s = format (s, "[not-fragmented]");
229 if (t->l4_layer_truncated)
231 s = format (s, " [l4-layer-truncated]");
237 ip4_sv_reass_add_trace (vlib_main_t *vm, vlib_node_runtime_t *node,
238 ip4_sv_reass_t *reass, u32 bi,
239 ip4_sv_reass_trace_operation_e action, u32 ip_proto,
240 u16 l4_src_port, u16 l4_dst_port,
241 int l4_layer_truncated)
243 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
244 if (pool_is_free_index
245 (vm->trace_main.trace_buffer_pool, vlib_buffer_get_trace_index (b)))
247 // this buffer's trace is gone
248 b->flags &= ~VLIB_BUFFER_IS_TRACED;
251 ip4_sv_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
254 t->reass_id = reass->id;
255 t->op_id = reass->trace_op_counter;
256 ++reass->trace_op_counter;
259 t->ip_proto = ip_proto;
260 t->l4_src_port = l4_src_port;
261 t->l4_dst_port = l4_dst_port;
262 t->l4_layer_truncated = l4_layer_truncated;
265 s = format (s, "%U", format_ip4_sv_reass_trace, NULL, NULL, t);
266 printf ("%.*s\n", vec_len (s), s);
268 vec_reset_length (s);
274 ip4_sv_reass_free (vlib_main_t * vm, ip4_sv_reass_main_t * rm,
275 ip4_sv_reass_per_thread_t * rt, ip4_sv_reass_t * reass)
277 clib_bihash_kv_16_8_t kv;
278 kv.key[0] = reass->key.as_u64[0];
279 kv.key[1] = reass->key.as_u64[1];
280 clib_bihash_add_del_16_8 (&rm->hash, &kv, 0);
281 vlib_buffer_free (vm, reass->cached_buffers,
282 vec_len (reass->cached_buffers));
283 vec_free (reass->cached_buffers);
284 reass->cached_buffers = NULL;
285 if (~0 != reass->lru_prev)
287 ip4_sv_reass_t *lru_prev =
288 pool_elt_at_index (rt->pool, reass->lru_prev);
289 lru_prev->lru_next = reass->lru_next;
291 if (~0 != reass->lru_next)
293 ip4_sv_reass_t *lru_next =
294 pool_elt_at_index (rt->pool, reass->lru_next);
295 lru_next->lru_prev = reass->lru_prev;
297 if (rt->lru_first == reass - rt->pool)
299 rt->lru_first = reass->lru_next;
301 if (rt->lru_last == reass - rt->pool)
303 rt->lru_last = reass->lru_prev;
305 pool_put (rt->pool, reass);
310 ip4_sv_reass_init (ip4_sv_reass_t * reass)
312 reass->cached_buffers = NULL;
313 reass->is_complete = false;
316 always_inline ip4_sv_reass_t *
317 ip4_sv_reass_find_or_create (vlib_main_t * vm, ip4_sv_reass_main_t * rm,
318 ip4_sv_reass_per_thread_t * rt,
319 ip4_sv_reass_kv_t * kv, u8 * do_handoff)
321 ip4_sv_reass_t *reass = NULL;
322 f64 now = vlib_time_now (vm);
326 if (!clib_bihash_search_16_8 (&rm->hash, &kv->kv, &kv->kv))
328 if (vm->thread_index != kv->v.thread_index)
333 reass = pool_elt_at_index (rt->pool, kv->v.reass_index);
335 if (now > reass->last_heard + rm->timeout)
337 ip4_sv_reass_free (vm, rm, rt, reass);
344 reass->last_heard = now;
348 if (rt->reass_n >= rm->max_reass_n && rm->max_reass_n)
350 reass = pool_elt_at_index (rt->pool, rt->lru_first);
351 ip4_sv_reass_free (vm, rm, rt, reass);
354 pool_get (rt->pool, reass);
355 clib_memset (reass, 0, sizeof (*reass));
356 reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
358 ip4_sv_reass_init (reass);
360 reass->lru_prev = reass->lru_next = ~0;
362 if (~0 != rt->lru_last)
364 ip4_sv_reass_t *lru_last = pool_elt_at_index (rt->pool, rt->lru_last);
365 reass->lru_prev = rt->lru_last;
366 lru_last->lru_next = rt->lru_last = reass - rt->pool;
369 if (~0 == rt->lru_first)
371 rt->lru_first = rt->lru_last = reass - rt->pool;
374 reass->key.as_u64[0] = kv->kv.key[0];
375 reass->key.as_u64[1] = kv->kv.key[1];
376 kv->v.reass_index = (reass - rt->pool);
377 kv->v.thread_index = vm->thread_index;
378 reass->last_heard = now;
380 int rv = clib_bihash_add_del_16_8 (&rm->hash, &kv->kv, 2);
383 ip4_sv_reass_free (vm, rm, rt, reass);
385 // if other worker created a context already work with the other copy
393 always_inline ip4_sv_reass_rc_t
394 ip4_sv_reass_update (vlib_main_t *vm, vlib_node_runtime_t *node,
395 ip4_sv_reass_main_t *rm, ip4_header_t *ip0,
396 ip4_sv_reass_t *reass, u32 bi0)
398 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
399 ip4_sv_reass_rc_t rc = IP4_SV_REASS_RC_OK;
400 const u32 fragment_first = ip4_get_fragment_offset_bytes (ip0);
401 if (0 == fragment_first)
403 reass->ip_proto = ip0->protocol;
404 reass->l4_src_port = ip4_get_port (ip0, 1);
405 reass->l4_dst_port = ip4_get_port (ip0, 0);
406 if (!reass->l4_src_port || !reass->l4_dst_port)
407 return IP4_SV_REASS_RC_UNSUPP_IP_PROTO;
408 if (IP_PROTOCOL_TCP == reass->ip_proto)
410 reass->icmp_type_or_tcp_flags = ((tcp_header_t *) (ip0 + 1))->flags;
411 reass->tcp_ack_number = ((tcp_header_t *) (ip0 + 1))->ack_number;
412 reass->tcp_seq_number = ((tcp_header_t *) (ip0 + 1))->seq_number;
414 else if (IP_PROTOCOL_ICMP == reass->ip_proto)
416 reass->icmp_type_or_tcp_flags =
417 ((icmp46_header_t *) (ip0 + 1))->type;
419 reass->is_complete = true;
420 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
421 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
423 ip4_sv_reass_add_trace (
424 vm, node, reass, bi0, REASS_FINISH, reass->ip_proto,
425 reass->l4_src_port, reass->l4_dst_port,
426 vnet_buffer (b0)->ip.reass.l4_layer_truncated);
429 vec_add1 (reass->cached_buffers, bi0);
430 if (!reass->is_complete)
432 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
434 ip4_sv_reass_add_trace (
435 vm, node, reass, bi0, REASS_FRAGMENT_CACHE, ~0, ~0, ~0,
436 vnet_buffer (b0)->ip.reass.l4_layer_truncated);
438 if (vec_len (reass->cached_buffers) > rm->max_reass_len)
440 rc = IP4_SV_REASS_RC_TOO_MANY_FRAGMENTS;
447 l4_layer_truncated (ip4_header_t *ip)
449 static const int l4_layer_length[256] = {
450 [IP_PROTOCOL_TCP] = sizeof (tcp_header_t),
451 [IP_PROTOCOL_UDP] = sizeof (udp_header_t),
452 [IP_PROTOCOL_ICMP] = sizeof (icmp46_header_t),
455 return ((u8 *) ip + ip4_header_bytes (ip) + l4_layer_length[ip->protocol] >
456 (u8 *) ip + clib_net_to_host_u16 (ip->length));
460 ip4_sv_reass_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
461 vlib_frame_t * frame, bool is_feature,
462 bool is_output_feature, bool is_custom)
464 u32 *from = vlib_frame_vector_args (frame);
465 u32 n_left_from, n_left_to_next, *to_next, next_index;
466 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
467 ip4_sv_reass_per_thread_t *rt = &rm->per_thread_data[vm->thread_index];
468 clib_spinlock_lock (&rt->lock);
470 n_left_from = frame->n_vectors;
471 next_index = node->cached_next_index;
473 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
474 vlib_get_buffers (vm, from, bufs, n_left_from);
475 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
478 /* optimistic case first - no fragments */
479 while (n_left_from >= 2)
481 vlib_buffer_t *b0, *b1;
488 /* Prefetch next iteration. */
489 if (PREDICT_TRUE (n_left_from >= 4))
491 vlib_buffer_t *p2, *p3;
496 vlib_prefetch_buffer_header (p2, LOAD);
497 vlib_prefetch_buffer_header (p3, LOAD);
499 clib_prefetch_load (p2->data);
500 clib_prefetch_load (p3->data);
504 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
505 (is_output_feature ? 1 : 0) *
507 ip.save_rewrite_length);
509 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b1),
510 (is_output_feature ? 1 : 0) *
512 ip.save_rewrite_length);
515 (ip4_get_fragment_more (ip0) || ip4_get_fragment_offset (ip0))
516 || (ip4_get_fragment_more (ip1) || ip4_get_fragment_offset (ip1)))
518 // fragment found, go slow path
522 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
529 vnet_feature_next (&next0, b0);
533 next0 = is_custom ? vnet_buffer (b0)->ip.reass.next_index :
534 IP4_SV_REASSEMBLY_NEXT_INPUT;
536 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
537 vnet_buffer (b0)->ip.reass.ip_proto = ip0->protocol;
538 if (l4_layer_truncated (ip0))
540 vnet_buffer (b0)->ip.reass.l4_layer_truncated = 1;
541 vnet_buffer (b0)->ip.reass.l4_src_port = 0;
542 vnet_buffer (b0)->ip.reass.l4_dst_port = 0;
546 vnet_buffer (b0)->ip.reass.l4_layer_truncated = 0;
547 if (IP_PROTOCOL_TCP == ip0->protocol)
549 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
550 ((tcp_header_t *) (ip0 + 1))->flags;
551 vnet_buffer (b0)->ip.reass.tcp_ack_number =
552 ((tcp_header_t *) (ip0 + 1))->ack_number;
553 vnet_buffer (b0)->ip.reass.tcp_seq_number =
554 ((tcp_header_t *) (ip0 + 1))->seq_number;
556 else if (IP_PROTOCOL_ICMP == ip0->protocol)
558 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
559 ((icmp46_header_t *) (ip0 + 1))->type;
561 vnet_buffer (b0)->ip.reass.l4_src_port = ip4_get_port (ip0, 1);
562 vnet_buffer (b0)->ip.reass.l4_dst_port = ip4_get_port (ip0, 0);
564 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
566 ip4_sv_reass_add_trace (
567 vm, node, NULL, from[(b - 2) - bufs], REASS_PASSTHROUGH,
568 vnet_buffer (b0)->ip.reass.ip_proto,
569 vnet_buffer (b0)->ip.reass.l4_src_port,
570 vnet_buffer (b0)->ip.reass.l4_dst_port,
571 vnet_buffer (b0)->ip.reass.l4_layer_truncated);
575 vnet_feature_next (&next1, b1);
579 next1 = is_custom ? vnet_buffer (b1)->ip.reass.next_index :
580 IP4_SV_REASSEMBLY_NEXT_INPUT;
582 vnet_buffer (b1)->ip.reass.is_non_first_fragment = 0;
583 vnet_buffer (b1)->ip.reass.ip_proto = ip1->protocol;
584 if (l4_layer_truncated (ip1))
586 vnet_buffer (b1)->ip.reass.l4_layer_truncated = 1;
587 vnet_buffer (b1)->ip.reass.l4_src_port = 0;
588 vnet_buffer (b1)->ip.reass.l4_dst_port = 0;
592 vnet_buffer (b1)->ip.reass.l4_layer_truncated = 0;
593 if (IP_PROTOCOL_TCP == ip1->protocol)
595 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
596 ((tcp_header_t *) (ip1 + 1))->flags;
597 vnet_buffer (b1)->ip.reass.tcp_ack_number =
598 ((tcp_header_t *) (ip1 + 1))->ack_number;
599 vnet_buffer (b1)->ip.reass.tcp_seq_number =
600 ((tcp_header_t *) (ip1 + 1))->seq_number;
602 else if (IP_PROTOCOL_ICMP == ip1->protocol)
604 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
605 ((icmp46_header_t *) (ip1 + 1))->type;
607 vnet_buffer (b1)->ip.reass.l4_src_port = ip4_get_port (ip1, 1);
608 vnet_buffer (b1)->ip.reass.l4_dst_port = ip4_get_port (ip1, 0);
610 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
612 ip4_sv_reass_add_trace (
613 vm, node, NULL, from[(b - 1) - bufs], REASS_PASSTHROUGH,
614 vnet_buffer (b1)->ip.reass.ip_proto,
615 vnet_buffer (b1)->ip.reass.l4_src_port,
616 vnet_buffer (b1)->ip.reass.l4_dst_port,
617 vnet_buffer (b1)->ip.reass.l4_layer_truncated);
626 while (n_left_from > 0)
634 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
635 (is_output_feature ? 1 : 0) *
637 ip.save_rewrite_length);
639 (ip4_get_fragment_more (ip0) || ip4_get_fragment_offset (ip0)))
641 // fragment found, go slow path
645 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
652 vnet_feature_next (&next0, b0);
657 is_custom ? vnet_buffer (b0)->ip.
658 reass.next_index : IP4_SV_REASSEMBLY_NEXT_INPUT;
660 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
661 vnet_buffer (b0)->ip.reass.ip_proto = ip0->protocol;
662 if (l4_layer_truncated (ip0))
664 vnet_buffer (b0)->ip.reass.l4_layer_truncated = 1;
668 vnet_buffer (b0)->ip.reass.l4_layer_truncated = 0;
669 if (IP_PROTOCOL_TCP == ip0->protocol)
671 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
672 ((tcp_header_t *) (ip0 + 1))->flags;
673 vnet_buffer (b0)->ip.reass.tcp_ack_number =
674 ((tcp_header_t *) (ip0 + 1))->ack_number;
675 vnet_buffer (b0)->ip.reass.tcp_seq_number =
676 ((tcp_header_t *) (ip0 + 1))->seq_number;
678 else if (IP_PROTOCOL_ICMP == ip0->protocol)
680 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
681 ((icmp46_header_t *) (ip0 + 1))->type;
683 vnet_buffer (b0)->ip.reass.l4_src_port = ip4_get_port (ip0, 1);
684 vnet_buffer (b0)->ip.reass.l4_dst_port = ip4_get_port (ip0, 0);
686 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
688 ip4_sv_reass_add_trace (
689 vm, node, NULL, from[(b - 1) - bufs], REASS_PASSTHROUGH,
690 vnet_buffer (b0)->ip.reass.ip_proto,
691 vnet_buffer (b0)->ip.reass.l4_src_port,
692 vnet_buffer (b0)->ip.reass.l4_dst_port,
693 vnet_buffer (b0)->ip.reass.l4_layer_truncated);
701 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
710 while (n_left_from > 0)
712 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
714 while (n_left_from > 0 && n_left_to_next > 0)
719 u32 error0 = IP4_ERROR_NONE;
722 b0 = vlib_get_buffer (vm, bi0);
725 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
726 (is_output_feature ? 1 : 0) *
728 ip.save_rewrite_length);
729 if (!ip4_get_fragment_more (ip0) && !ip4_get_fragment_offset (ip0))
731 // this is a regular packet - no fragmentation
734 next0 = vnet_buffer (b0)->ip.reass.next_index;
738 next0 = IP4_SV_REASSEMBLY_NEXT_INPUT;
740 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
741 vnet_buffer (b0)->ip.reass.ip_proto = ip0->protocol;
742 if (l4_layer_truncated (ip0))
744 vnet_buffer (b0)->ip.reass.l4_layer_truncated = 1;
745 vnet_buffer (b0)->ip.reass.l4_src_port = 0;
746 vnet_buffer (b0)->ip.reass.l4_dst_port = 0;
750 vnet_buffer (b0)->ip.reass.l4_layer_truncated = 0;
751 if (IP_PROTOCOL_TCP == ip0->protocol)
753 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
754 ((tcp_header_t *) (ip0 + 1))->flags;
755 vnet_buffer (b0)->ip.reass.tcp_ack_number =
756 ((tcp_header_t *) (ip0 + 1))->ack_number;
757 vnet_buffer (b0)->ip.reass.tcp_seq_number =
758 ((tcp_header_t *) (ip0 + 1))->seq_number;
760 else if (IP_PROTOCOL_ICMP == ip0->protocol)
762 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
763 ((icmp46_header_t *) (ip0 + 1))->type;
765 vnet_buffer (b0)->ip.reass.l4_src_port =
766 ip4_get_port (ip0, 1);
767 vnet_buffer (b0)->ip.reass.l4_dst_port =
768 ip4_get_port (ip0, 0);
770 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
772 ip4_sv_reass_add_trace (
773 vm, node, NULL, bi0, REASS_PASSTHROUGH,
774 vnet_buffer (b0)->ip.reass.ip_proto,
775 vnet_buffer (b0)->ip.reass.l4_src_port,
776 vnet_buffer (b0)->ip.reass.l4_dst_port,
777 vnet_buffer (b0)->ip.reass.l4_layer_truncated);
781 const u32 fragment_first = ip4_get_fragment_offset_bytes (ip0);
782 const u32 fragment_length =
783 clib_net_to_host_u16 (ip0->length) - ip4_header_bytes (ip0);
784 const u32 fragment_last = fragment_first + fragment_length - 1;
785 if (fragment_first > fragment_last || fragment_first + fragment_length > UINT16_MAX - 20 || (fragment_length < 8 && ip4_get_fragment_more (ip0))) // 8 is minimum frag length per RFC 791
787 next0 = IP4_SV_REASSEMBLY_NEXT_DROP;
788 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
789 b0->error = node->errors[error0];
792 ip4_sv_reass_kv_t kv;
796 (u64) vec_elt (ip4_main.fib_index_by_sw_if_index,
797 vnet_buffer (b0)->sw_if_index[VLIB_RX]) |
798 (u64) ip0->src_address.as_u32 << 32;
800 (u64) ip0->dst_address.
801 as_u32 | (u64) ip0->fragment_id << 32 | (u64) ip0->protocol << 48;
803 ip4_sv_reass_t *reass =
804 ip4_sv_reass_find_or_create (vm, rm, rt, &kv, &do_handoff);
806 if (PREDICT_FALSE (do_handoff))
808 next0 = IP4_SV_REASSEMBLY_NEXT_HANDOFF;
809 vnet_buffer (b0)->ip.reass.owner_thread_index =
816 next0 = IP4_SV_REASSEMBLY_NEXT_DROP;
817 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
818 b0->error = node->errors[error0];
822 if (reass->is_complete)
826 next0 = vnet_buffer (b0)->ip.reass.next_index;
830 next0 = IP4_SV_REASSEMBLY_NEXT_INPUT;
832 vnet_buffer (b0)->ip.reass.is_non_first_fragment =
834 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
835 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
836 reass->icmp_type_or_tcp_flags;
837 vnet_buffer (b0)->ip.reass.tcp_ack_number =
838 reass->tcp_ack_number;
839 vnet_buffer (b0)->ip.reass.tcp_seq_number =
840 reass->tcp_seq_number;
841 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
842 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
843 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
845 ip4_sv_reass_add_trace (
846 vm, node, reass, bi0, REASS_FRAGMENT_FORWARD,
847 reass->ip_proto, reass->l4_src_port, reass->l4_dst_port,
848 vnet_buffer (b0)->ip.reass.l4_layer_truncated);
853 ip4_sv_reass_rc_t rc =
854 ip4_sv_reass_update (vm, node, rm, ip0, reass, bi0);
858 case IP4_SV_REASS_RC_OK:
859 /* nothing to do here */
861 case IP4_SV_REASS_RC_TOO_MANY_FRAGMENTS:
862 counter = IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG;
864 case IP4_SV_REASS_RC_UNSUPP_IP_PROTO:
865 counter = IP4_ERROR_REASS_UNSUPP_IP_PROT;
870 vlib_node_increment_counter (vm, node->node_index, counter, 1);
871 ip4_sv_reass_free (vm, rm, rt, reass);
874 if (reass->is_complete)
877 vec_foreach_index (idx, reass->cached_buffers)
879 u32 bi0 = vec_elt (reass->cached_buffers, idx);
880 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
882 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
883 (is_output_feature ? 1 : 0) *
885 ip.save_rewrite_length);
886 u32 next0 = IP4_SV_REASSEMBLY_NEXT_INPUT;
889 vnet_feature_next (&next0, b0);
893 next0 = vnet_buffer (b0)->ip.reass.next_index;
895 if (0 == n_left_to_next)
897 vlib_put_next_frame (vm, node, next_index,
899 vlib_get_next_frame (vm, node, next_index, to_next,
905 vnet_buffer (b0)->ip.reass.is_non_first_fragment =
906 ! !ip4_get_fragment_offset (ip0);
907 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
908 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
909 reass->icmp_type_or_tcp_flags;
910 vnet_buffer (b0)->ip.reass.tcp_ack_number =
911 reass->tcp_ack_number;
912 vnet_buffer (b0)->ip.reass.tcp_seq_number =
913 reass->tcp_seq_number;
914 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
915 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
916 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
918 ip4_sv_reass_add_trace (
919 vm, node, reass, bi0, REASS_FRAGMENT_FORWARD,
920 reass->ip_proto, reass->l4_src_port, reass->l4_dst_port,
921 vnet_buffer (b0)->ip.reass.l4_layer_truncated);
923 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
924 to_next, n_left_to_next, bi0,
927 vec_set_len (reass->cached_buffers,
928 0); // buffers are owned by frame now
936 if (is_feature && IP4_ERROR_NONE == error0)
938 b0 = vlib_get_buffer (vm, bi0);
939 vnet_feature_next (&next0, b0);
941 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
942 to_next, n_left_to_next,
950 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
954 clib_spinlock_unlock (&rt->lock);
955 return frame->n_vectors;
958 static char *ip4_sv_reass_error_strings[] = {
959 #define _(sym, string) string,
964 VLIB_NODE_FN (ip4_sv_reass_node) (vlib_main_t * vm,
965 vlib_node_runtime_t * node,
966 vlib_frame_t * frame)
968 return ip4_sv_reass_inline (vm, node, frame, false /* is_feature */ ,
969 false /* is_output_feature */ ,
970 false /* is_custom */ );
974 VLIB_REGISTER_NODE (ip4_sv_reass_node) = {
975 .name = "ip4-sv-reassembly",
976 .vector_size = sizeof (u32),
977 .format_trace = format_ip4_sv_reass_trace,
978 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
979 .error_strings = ip4_sv_reass_error_strings,
980 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
983 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
984 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
985 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reassembly-handoff",
991 VLIB_NODE_FN (ip4_sv_reass_node_feature) (vlib_main_t * vm,
992 vlib_node_runtime_t * node,
993 vlib_frame_t * frame)
995 return ip4_sv_reass_inline (vm, node, frame, true /* is_feature */ ,
996 false /* is_output_feature */ ,
997 false /* is_custom */ );
1001 VLIB_REGISTER_NODE (ip4_sv_reass_node_feature) = {
1002 .name = "ip4-sv-reassembly-feature",
1003 .vector_size = sizeof (u32),
1004 .format_trace = format_ip4_sv_reass_trace,
1005 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
1006 .error_strings = ip4_sv_reass_error_strings,
1007 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
1010 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
1011 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
1012 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reass-feature-hoff",
1018 VNET_FEATURE_INIT (ip4_sv_reass_feature) = {
1019 .arc_name = "ip4-unicast",
1020 .node_name = "ip4-sv-reassembly-feature",
1021 .runs_before = VNET_FEATURES ("ip4-lookup"),
1026 VLIB_NODE_FN (ip4_sv_reass_node_output_feature) (vlib_main_t * vm,
1027 vlib_node_runtime_t * node,
1028 vlib_frame_t * frame)
1030 return ip4_sv_reass_inline (vm, node, frame, true /* is_feature */ ,
1031 true /* is_output_feature */ ,
1032 false /* is_custom */ );
1037 VLIB_REGISTER_NODE (ip4_sv_reass_node_output_feature) = {
1038 .name = "ip4-sv-reassembly-output-feature",
1039 .vector_size = sizeof (u32),
1040 .format_trace = format_ip4_sv_reass_trace,
1041 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
1042 .error_strings = ip4_sv_reass_error_strings,
1043 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
1046 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
1047 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
1048 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reass-feature-hoff",
1054 VNET_FEATURE_INIT (ip4_sv_reass_output_feature) = {
1055 .arc_name = "ip4-output",
1056 .node_name = "ip4-sv-reassembly-output-feature",
1063 VLIB_REGISTER_NODE (ip4_sv_reass_custom_node) = {
1064 .name = "ip4-sv-reassembly-custom-next",
1065 .vector_size = sizeof (u32),
1066 .format_trace = format_ip4_sv_reass_trace,
1067 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
1068 .error_strings = ip4_sv_reass_error_strings,
1069 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
1072 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
1073 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
1074 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reassembly-handoff",
1080 VLIB_NODE_FN (ip4_sv_reass_custom_node) (vlib_main_t * vm,
1081 vlib_node_runtime_t * node,
1082 vlib_frame_t * frame)
1084 return ip4_sv_reass_inline (vm, node, frame, false /* is_feature */ ,
1085 false /* is_output_feature */ ,
1086 true /* is_custom */ );
1089 #ifndef CLIB_MARCH_VARIANT
1091 ip4_sv_reass_get_nbuckets ()
1093 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1097 nbuckets = (u32) (rm->max_reass_n / IP4_SV_REASS_HT_LOAD_FACTOR);
1099 for (i = 0; i < 31; i++)
1100 if ((1 << i) >= nbuckets)
1106 #endif /* CLIB_MARCH_VARIANT */
1110 IP4_EVENT_CONFIG_CHANGED = 1,
1111 } ip4_sv_reass_event_t;
1116 clib_bihash_16_8_t *new_hash;
1117 } ip4_rehash_cb_ctx;
1119 #ifndef CLIB_MARCH_VARIANT
1121 ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx)
1123 ip4_rehash_cb_ctx *ctx = _ctx;
1124 if (clib_bihash_add_del_16_8 (ctx->new_hash, kv, 1))
1128 return (BIHASH_WALK_CONTINUE);
1132 ip4_sv_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
1133 u32 max_reassembly_length,
1134 u32 expire_walk_interval_ms)
1136 ip4_sv_reass_main.timeout_ms = timeout_ms;
1137 ip4_sv_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
1138 ip4_sv_reass_main.max_reass_n = max_reassemblies;
1139 ip4_sv_reass_main.max_reass_len = max_reassembly_length;
1140 ip4_sv_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
1144 ip4_sv_reass_set (u32 timeout_ms, u32 max_reassemblies,
1145 u32 max_reassembly_length, u32 expire_walk_interval_ms)
1147 u32 old_nbuckets = ip4_sv_reass_get_nbuckets ();
1148 ip4_sv_reass_set_params (timeout_ms, max_reassemblies,
1149 max_reassembly_length, expire_walk_interval_ms);
1150 vlib_process_signal_event (ip4_sv_reass_main.vlib_main,
1151 ip4_sv_reass_main.ip4_sv_reass_expire_node_idx,
1152 IP4_EVENT_CONFIG_CHANGED, 0);
1153 u32 new_nbuckets = ip4_sv_reass_get_nbuckets ();
1154 if (ip4_sv_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
1156 clib_bihash_16_8_t new_hash;
1157 clib_memset (&new_hash, 0, sizeof (new_hash));
1158 ip4_rehash_cb_ctx ctx;
1160 ctx.new_hash = &new_hash;
1161 clib_bihash_init_16_8 (&new_hash, "ip4-dr", new_nbuckets,
1162 new_nbuckets * 1024);
1163 clib_bihash_foreach_key_value_pair_16_8 (&ip4_sv_reass_main.hash,
1164 ip4_rehash_cb, &ctx);
1167 clib_bihash_free_16_8 (&new_hash);
1172 clib_bihash_free_16_8 (&ip4_sv_reass_main.hash);
1173 clib_memcpy_fast (&ip4_sv_reass_main.hash, &new_hash,
1174 sizeof (ip4_sv_reass_main.hash));
1175 clib_bihash_copied (&ip4_sv_reass_main.hash, &new_hash);
1182 ip4_sv_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
1183 u32 * max_reassembly_length, u32 * expire_walk_interval_ms)
1185 *timeout_ms = ip4_sv_reass_main.timeout_ms;
1186 *max_reassemblies = ip4_sv_reass_main.max_reass_n;
1187 *max_reassembly_length = ip4_sv_reass_main.max_reass_len;
1188 *expire_walk_interval_ms = ip4_sv_reass_main.expire_walk_interval_ms;
1192 static clib_error_t *
1193 ip4_sv_reass_init_function (vlib_main_t * vm)
1195 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1196 clib_error_t *error = 0;
1201 rm->vnet_main = vnet_get_main ();
1203 vec_validate (rm->per_thread_data, vlib_num_workers ());
1204 ip4_sv_reass_per_thread_t *rt;
1205 vec_foreach (rt, rm->per_thread_data)
1207 clib_spinlock_init (&rt->lock);
1208 pool_alloc (rt->pool, rm->max_reass_n);
1209 rt->lru_first = rt->lru_last = ~0;
1212 node = vlib_get_node_by_name (vm, (u8 *) "ip4-sv-reassembly-expire-walk");
1214 rm->ip4_sv_reass_expire_node_idx = node->index;
1216 ip4_sv_reass_set_params (IP4_SV_REASS_TIMEOUT_DEFAULT_MS,
1217 IP4_SV_REASS_MAX_REASSEMBLIES_DEFAULT,
1218 IP4_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT,
1219 IP4_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
1221 nbuckets = ip4_sv_reass_get_nbuckets ();
1222 clib_bihash_init_16_8 (&rm->hash, "ip4-dr", nbuckets, nbuckets * 1024);
1224 node = vlib_get_node_by_name (vm, (u8 *) "ip4-drop");
1226 rm->ip4_drop_idx = node->index;
1228 rm->fq_index = vlib_frame_queue_main_init (ip4_sv_reass_node.index, 0);
1229 rm->fq_feature_index =
1230 vlib_frame_queue_main_init (ip4_sv_reass_node_feature.index, 0);
1232 rm->feature_use_refcount_per_intf = NULL;
1233 rm->output_feature_use_refcount_per_intf = NULL;
1238 VLIB_INIT_FUNCTION (ip4_sv_reass_init_function);
1239 #endif /* CLIB_MARCH_VARIANT */
1242 ip4_sv_reass_walk_expired (vlib_main_t *vm,
1243 CLIB_UNUSED (vlib_node_runtime_t *node),
1244 CLIB_UNUSED (vlib_frame_t *f))
1246 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1247 uword event_type, *event_data = 0;
1251 vlib_process_wait_for_event_or_clock (vm,
1253 rm->expire_walk_interval_ms /
1254 (f64) MSEC_PER_SEC);
1255 event_type = vlib_process_get_events (vm, &event_data);
1260 /* no events => timeout */
1262 case IP4_EVENT_CONFIG_CHANGED:
1263 /* nothing to do here */
1266 clib_warning ("BUG: event type 0x%wx", event_type);
1269 f64 now = vlib_time_now (vm);
1271 ip4_sv_reass_t *reass;
1272 int *pool_indexes_to_free = NULL;
1274 uword thread_index = 0;
1276 const uword nthreads = vlib_num_workers () + 1;
1277 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1279 ip4_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1280 clib_spinlock_lock (&rt->lock);
1282 vec_reset_length (pool_indexes_to_free);
1284 pool_foreach_index (index, rt->pool) {
1285 reass = pool_elt_at_index (rt->pool, index);
1286 if (now > reass->last_heard + rm->timeout)
1288 vec_add1 (pool_indexes_to_free, index);
1294 vec_foreach (i, pool_indexes_to_free)
1296 ip4_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1297 ip4_sv_reass_free (vm, rm, rt, reass);
1301 clib_spinlock_unlock (&rt->lock);
1304 vec_free (pool_indexes_to_free);
1307 vec_set_len (event_data, 0);
1315 VLIB_REGISTER_NODE (ip4_sv_reass_expire_node) = {
1316 .function = ip4_sv_reass_walk_expired,
1317 .type = VLIB_NODE_TYPE_PROCESS,
1318 .name = "ip4-sv-reassembly-expire-walk",
1319 .format_trace = format_ip4_sv_reass_trace,
1320 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
1321 .error_strings = ip4_sv_reass_error_strings,
1327 format_ip4_sv_reass_key (u8 * s, va_list * args)
1329 ip4_sv_reass_key_t *key = va_arg (*args, ip4_sv_reass_key_t *);
1331 format (s, "fib_index: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1332 key->fib_index, format_ip4_address, &key->src, format_ip4_address,
1333 &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1338 format_ip4_sv_reass (u8 * s, va_list * args)
1340 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1341 ip4_sv_reass_t *reass = va_arg (*args, ip4_sv_reass_t *);
1343 s = format (s, "ID: %lu, key: %U trace_op_counter: %u\n",
1344 reass->id, format_ip4_sv_reass_key, &reass->key,
1345 reass->trace_op_counter);
1350 vec_foreach (bip, reass->cached_buffers)
1355 b = vlib_get_buffer (vm, bi);
1356 s = format (s, " #%03u: bi: %u, ", counter, bi);
1358 bi = b->next_buffer;
1360 while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
1365 static clib_error_t *
1366 show_ip4_reass (vlib_main_t * vm,
1367 unformat_input_t * input,
1368 CLIB_UNUSED (vlib_cli_command_t * lmd))
1370 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1372 vlib_cli_output (vm, "---------------------");
1373 vlib_cli_output (vm, "IP4 reassembly status");
1374 vlib_cli_output (vm, "---------------------");
1375 bool details = false;
1376 if (unformat (input, "details"))
1381 u32 sum_reass_n = 0;
1382 ip4_sv_reass_t *reass;
1384 const uword nthreads = vlib_num_workers () + 1;
1385 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1387 ip4_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1388 clib_spinlock_lock (&rt->lock);
1392 pool_foreach (reass, rt->pool) {
1393 vlib_cli_output (vm, "%U", format_ip4_sv_reass, vm, reass);
1397 sum_reass_n += rt->reass_n;
1398 clib_spinlock_unlock (&rt->lock);
1400 vlib_cli_output (vm, "---------------------");
1401 vlib_cli_output (vm, "Current IP4 reassemblies count: %lu\n",
1402 (long unsigned) sum_reass_n);
1403 vlib_cli_output (vm,
1404 "Maximum configured concurrent shallow virtual IP4 reassemblies per worker-thread: %lu\n",
1405 (long unsigned) rm->max_reass_n);
1406 vlib_cli_output (vm,
1407 "Maximum configured amount of fragments per shallow "
1408 "virtual IP4 reassembly: %lu\n",
1409 (long unsigned) rm->max_reass_len);
1410 vlib_cli_output (vm,
1411 "Maximum configured shallow virtual IP4 reassembly timeout: %lums\n",
1412 (long unsigned) rm->timeout_ms);
1413 vlib_cli_output (vm,
1414 "Maximum configured shallow virtual IP4 reassembly expire walk interval: %lums\n",
1415 (long unsigned) rm->expire_walk_interval_ms);
1420 VLIB_CLI_COMMAND (show_ip4_sv_reass_cmd, static) = {
1421 .path = "show ip4-sv-reassembly",
1422 .short_help = "show ip4-sv-reassembly [details]",
1423 .function = show_ip4_reass,
1427 #ifndef CLIB_MARCH_VARIANT
1429 ip4_sv_reass_enable_disable (u32 sw_if_index, u8 enable_disable)
1431 return ip4_sv_reass_enable_disable_with_refcnt (sw_if_index,
1434 #endif /* CLIB_MARCH_VARIANT */
1437 #define foreach_ip4_sv_reass_handoff_error \
1438 _(CONGESTION_DROP, "congestion drop")
1443 #define _(sym,str) IP4_SV_REASSEMBLY_HANDOFF_ERROR_##sym,
1444 foreach_ip4_sv_reass_handoff_error
1446 IP4_SV_REASSEMBLY_HANDOFF_N_ERROR,
1447 } ip4_sv_reass_handoff_error_t;
1449 static char *ip4_sv_reass_handoff_error_strings[] = {
1450 #define _(sym,string) string,
1451 foreach_ip4_sv_reass_handoff_error
1457 u32 next_worker_index;
1458 } ip4_sv_reass_handoff_trace_t;
1461 format_ip4_sv_reass_handoff_trace (u8 * s, va_list * args)
1463 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1464 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1465 ip4_sv_reass_handoff_trace_t *t =
1466 va_arg (*args, ip4_sv_reass_handoff_trace_t *);
1469 format (s, "ip4-sv-reassembly-handoff: next-worker %d",
1470 t->next_worker_index);
1476 ip4_sv_reass_handoff_node_inline (vlib_main_t * vm,
1477 vlib_node_runtime_t * node,
1478 vlib_frame_t * frame, bool is_feature)
1480 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1482 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1483 u32 n_enq, n_left_from, *from;
1484 u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1487 from = vlib_frame_vector_args (frame);
1488 n_left_from = frame->n_vectors;
1489 vlib_get_buffers (vm, from, bufs, n_left_from);
1492 ti = thread_indices;
1494 fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1496 while (n_left_from > 0)
1498 ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1501 ((node->flags & VLIB_NODE_FLAG_TRACE)
1502 && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1504 ip4_sv_reass_handoff_trace_t *t =
1505 vlib_add_trace (vm, node, b[0], sizeof (*t));
1506 t->next_worker_index = ti[0];
1513 n_enq = vlib_buffer_enqueue_to_thread (vm, node, fq_index, from,
1514 thread_indices, frame->n_vectors, 1);
1516 if (n_enq < frame->n_vectors)
1517 vlib_node_increment_counter (vm, node->node_index,
1518 IP4_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1519 frame->n_vectors - n_enq);
1520 return frame->n_vectors;
1523 VLIB_NODE_FN (ip4_sv_reass_handoff_node) (vlib_main_t * vm,
1524 vlib_node_runtime_t * node,
1525 vlib_frame_t * frame)
1527 return ip4_sv_reass_handoff_node_inline (vm, node, frame,
1528 false /* is_feature */ );
1533 VLIB_REGISTER_NODE (ip4_sv_reass_handoff_node) = {
1534 .name = "ip4-sv-reassembly-handoff",
1535 .vector_size = sizeof (u32),
1536 .n_errors = ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1537 .error_strings = ip4_sv_reass_handoff_error_strings,
1538 .format_trace = format_ip4_sv_reass_handoff_trace,
1550 VLIB_NODE_FN (ip4_sv_reass_feature_handoff_node) (vlib_main_t * vm,
1551 vlib_node_runtime_t *
1553 vlib_frame_t * frame)
1555 return ip4_sv_reass_handoff_node_inline (vm, node, frame,
1556 true /* is_feature */ );
1562 VLIB_REGISTER_NODE (ip4_sv_reass_feature_handoff_node) = {
1563 .name = "ip4-sv-reass-feature-hoff",
1564 .vector_size = sizeof (u32),
1565 .n_errors = ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1566 .error_strings = ip4_sv_reass_handoff_error_strings,
1567 .format_trace = format_ip4_sv_reass_handoff_trace,
1577 #ifndef CLIB_MARCH_VARIANT
1579 ip4_sv_reass_enable_disable_with_refcnt (u32 sw_if_index, int is_enable)
1581 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1582 vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
1585 if (!rm->feature_use_refcount_per_intf[sw_if_index])
1587 ++rm->feature_use_refcount_per_intf[sw_if_index];
1588 return vnet_feature_enable_disable ("ip4-unicast",
1589 "ip4-sv-reassembly-feature",
1590 sw_if_index, 1, 0, 0);
1592 ++rm->feature_use_refcount_per_intf[sw_if_index];
1596 if (rm->feature_use_refcount_per_intf[sw_if_index])
1597 --rm->feature_use_refcount_per_intf[sw_if_index];
1598 if (!rm->feature_use_refcount_per_intf[sw_if_index])
1599 return vnet_feature_enable_disable ("ip4-unicast",
1600 "ip4-sv-reassembly-feature",
1601 sw_if_index, 0, 0, 0);
1607 ip4_sv_reass_custom_register_next_node (uword node_index)
1609 return vlib_node_add_next (vlib_get_main (), ip4_sv_reass_custom_node.index,
1614 ip4_sv_reass_output_enable_disable_with_refcnt (u32 sw_if_index,
1617 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1618 vec_validate (rm->output_feature_use_refcount_per_intf, sw_if_index);
1621 if (!rm->output_feature_use_refcount_per_intf[sw_if_index])
1623 ++rm->output_feature_use_refcount_per_intf[sw_if_index];
1624 return vnet_feature_enable_disable ("ip4-output",
1625 "ip4-sv-reassembly-output-feature",
1626 sw_if_index, 1, 0, 0);
1628 ++rm->output_feature_use_refcount_per_intf[sw_if_index];
1632 if (rm->output_feature_use_refcount_per_intf[sw_if_index])
1633 --rm->output_feature_use_refcount_per_intf[sw_if_index];
1634 if (!rm->output_feature_use_refcount_per_intf[sw_if_index])
1635 return vnet_feature_enable_disable ("ip4-output",
1636 "ip4-sv-reassembly-output-feature",
1637 sw_if_index, 0, 0, 0);
1644 * fd.io coding-style-patch-verification: ON
1647 * eval: (c-set-style "gnu")