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 } ip4_sv_reass_trace_t;
194 extern vlib_node_registration_t ip4_sv_reass_node;
195 extern vlib_node_registration_t ip4_sv_reass_node_feature;
198 format_ip4_sv_reass_trace (u8 * s, va_list * args)
200 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
201 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
202 ip4_sv_reass_trace_t *t = va_arg (*args, ip4_sv_reass_trace_t *);
203 if (REASS_PASSTHROUGH != t->action)
205 s = format (s, "reass id: %u, op id: %u ", t->reass_id, t->op_id);
209 case REASS_FRAGMENT_CACHE:
210 s = format (s, "[cached]");
214 format (s, "[finish, ip proto=%u, src_port=%u, dst_port=%u]",
215 t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
216 clib_net_to_host_u16 (t->l4_dst_port));
218 case REASS_FRAGMENT_FORWARD:
220 format (s, "[forward, ip proto=%u, src_port=%u, dst_port=%u]",
221 t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
222 clib_net_to_host_u16 (t->l4_dst_port));
224 case REASS_PASSTHROUGH:
225 s = format (s, "[not-fragmented]");
232 ip4_sv_reass_add_trace (vlib_main_t *vm, vlib_node_runtime_t *node,
233 ip4_sv_reass_t *reass, u32 bi,
234 ip4_sv_reass_trace_operation_e action, u32 ip_proto,
235 u16 l4_src_port, u16 l4_dst_port)
237 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
238 if (pool_is_free_index
239 (vm->trace_main.trace_buffer_pool, vlib_buffer_get_trace_index (b)))
241 // this buffer's trace is gone
242 b->flags &= ~VLIB_BUFFER_IS_TRACED;
245 ip4_sv_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
248 t->reass_id = reass->id;
249 t->op_id = reass->trace_op_counter;
250 ++reass->trace_op_counter;
253 t->ip_proto = ip_proto;
254 t->l4_src_port = l4_src_port;
255 t->l4_dst_port = l4_dst_port;
258 s = format (s, "%U", format_ip4_sv_reass_trace, NULL, NULL, t);
259 printf ("%.*s\n", vec_len (s), s);
261 vec_reset_length (s);
267 ip4_sv_reass_free (vlib_main_t * vm, ip4_sv_reass_main_t * rm,
268 ip4_sv_reass_per_thread_t * rt, ip4_sv_reass_t * reass)
270 clib_bihash_kv_16_8_t kv;
271 kv.key[0] = reass->key.as_u64[0];
272 kv.key[1] = reass->key.as_u64[1];
273 clib_bihash_add_del_16_8 (&rm->hash, &kv, 0);
274 vlib_buffer_free (vm, reass->cached_buffers,
275 vec_len (reass->cached_buffers));
276 vec_free (reass->cached_buffers);
277 reass->cached_buffers = NULL;
278 if (~0 != reass->lru_prev)
280 ip4_sv_reass_t *lru_prev =
281 pool_elt_at_index (rt->pool, reass->lru_prev);
282 lru_prev->lru_next = reass->lru_next;
284 if (~0 != reass->lru_next)
286 ip4_sv_reass_t *lru_next =
287 pool_elt_at_index (rt->pool, reass->lru_next);
288 lru_next->lru_prev = reass->lru_prev;
290 if (rt->lru_first == reass - rt->pool)
292 rt->lru_first = reass->lru_next;
294 if (rt->lru_last == reass - rt->pool)
296 rt->lru_last = reass->lru_prev;
298 pool_put (rt->pool, reass);
303 ip4_sv_reass_init (ip4_sv_reass_t * reass)
305 reass->cached_buffers = NULL;
306 reass->is_complete = false;
309 always_inline ip4_sv_reass_t *
310 ip4_sv_reass_find_or_create (vlib_main_t * vm, ip4_sv_reass_main_t * rm,
311 ip4_sv_reass_per_thread_t * rt,
312 ip4_sv_reass_kv_t * kv, u8 * do_handoff)
314 ip4_sv_reass_t *reass = NULL;
315 f64 now = vlib_time_now (vm);
317 if (!clib_bihash_search_16_8 (&rm->hash, &kv->kv, &kv->kv))
319 if (vm->thread_index != kv->v.thread_index)
324 reass = pool_elt_at_index (rt->pool, kv->v.reass_index);
326 if (now > reass->last_heard + rm->timeout)
328 ip4_sv_reass_free (vm, rm, rt, reass);
335 reass->last_heard = now;
339 if (rt->reass_n >= rm->max_reass_n && rm->max_reass_n)
341 reass = pool_elt_at_index (rt->pool, rt->lru_first);
342 ip4_sv_reass_free (vm, rm, rt, reass);
345 pool_get (rt->pool, reass);
346 clib_memset (reass, 0, sizeof (*reass));
347 reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
349 ip4_sv_reass_init (reass);
351 reass->lru_prev = reass->lru_next = ~0;
353 if (~0 != rt->lru_last)
355 ip4_sv_reass_t *lru_last = pool_elt_at_index (rt->pool, rt->lru_last);
356 reass->lru_prev = rt->lru_last;
357 lru_last->lru_next = rt->lru_last = reass - rt->pool;
360 if (~0 == rt->lru_first)
362 rt->lru_first = rt->lru_last = reass - rt->pool;
365 reass->key.as_u64[0] = kv->kv.key[0];
366 reass->key.as_u64[1] = kv->kv.key[1];
367 kv->v.reass_index = (reass - rt->pool);
368 kv->v.thread_index = vm->thread_index;
369 reass->last_heard = now;
371 if (clib_bihash_add_del_16_8 (&rm->hash, &kv->kv, 1))
373 ip4_sv_reass_free (vm, rm, rt, reass);
380 always_inline ip4_sv_reass_rc_t
381 ip4_sv_reass_update (vlib_main_t *vm, vlib_node_runtime_t *node,
382 ip4_sv_reass_main_t *rm, ip4_header_t *ip0,
383 ip4_sv_reass_t *reass, u32 bi0)
385 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
386 ip4_sv_reass_rc_t rc = IP4_SV_REASS_RC_OK;
387 const u32 fragment_first = ip4_get_fragment_offset_bytes (ip0);
388 if (0 == fragment_first)
390 reass->ip_proto = ip0->protocol;
391 reass->l4_src_port = ip4_get_port (ip0, 1);
392 reass->l4_dst_port = ip4_get_port (ip0, 0);
393 if (!reass->l4_src_port || !reass->l4_dst_port)
394 return IP4_SV_REASS_RC_UNSUPP_IP_PROTO;
395 if (IP_PROTOCOL_TCP == reass->ip_proto)
397 reass->icmp_type_or_tcp_flags = ((tcp_header_t *) (ip0 + 1))->flags;
398 reass->tcp_ack_number = ((tcp_header_t *) (ip0 + 1))->ack_number;
399 reass->tcp_seq_number = ((tcp_header_t *) (ip0 + 1))->seq_number;
401 else if (IP_PROTOCOL_ICMP == reass->ip_proto)
403 reass->icmp_type_or_tcp_flags =
404 ((icmp46_header_t *) (ip0 + 1))->type;
406 reass->is_complete = true;
407 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
408 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
410 ip4_sv_reass_add_trace (vm, node, reass, bi0, REASS_FINISH,
411 reass->ip_proto, reass->l4_src_port,
415 vec_add1 (reass->cached_buffers, bi0);
416 if (!reass->is_complete)
418 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
420 ip4_sv_reass_add_trace (vm, node, reass, bi0, REASS_FRAGMENT_CACHE,
423 if (vec_len (reass->cached_buffers) > rm->max_reass_len)
425 rc = IP4_SV_REASS_RC_TOO_MANY_FRAGMENTS;
432 ip4_sv_reass_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
433 vlib_frame_t * frame, bool is_feature,
434 bool is_output_feature, bool is_custom)
436 u32 *from = vlib_frame_vector_args (frame);
437 u32 n_left_from, n_left_to_next, *to_next, next_index;
438 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
439 ip4_sv_reass_per_thread_t *rt = &rm->per_thread_data[vm->thread_index];
440 clib_spinlock_lock (&rt->lock);
442 n_left_from = frame->n_vectors;
443 next_index = node->cached_next_index;
445 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
446 vlib_get_buffers (vm, from, bufs, n_left_from);
447 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
450 /* optimistic case first - no fragments */
451 while (n_left_from >= 2)
453 vlib_buffer_t *b0, *b1;
460 /* Prefetch next iteration. */
461 if (PREDICT_TRUE (n_left_from >= 4))
463 vlib_buffer_t *p2, *p3;
468 vlib_prefetch_buffer_header (p2, LOAD);
469 vlib_prefetch_buffer_header (p3, LOAD);
471 clib_prefetch_load (p2->data);
472 clib_prefetch_load (p3->data);
476 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
477 (is_output_feature ? 1 : 0) *
479 ip.save_rewrite_length);
481 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b1),
482 (is_output_feature ? 1 : 0) *
484 ip.save_rewrite_length);
486 (ip4_get_fragment_more (ip0) || ip4_get_fragment_offset (ip0))
487 || (ip4_get_fragment_more (ip1) || ip4_get_fragment_offset (ip1)))
489 // fragment found, go slow path
493 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
500 vnet_feature_next (&next0, b0);
504 next0 = is_custom ? vnet_buffer (b0)->ip.reass.next_index :
505 IP4_SV_REASSEMBLY_NEXT_INPUT;
507 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
508 vnet_buffer (b0)->ip.reass.ip_proto = ip0->protocol;
509 if (IP_PROTOCOL_TCP == ip0->protocol)
511 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
512 ((tcp_header_t *) (ip0 + 1))->flags;
513 vnet_buffer (b0)->ip.reass.tcp_ack_number =
514 ((tcp_header_t *) (ip0 + 1))->ack_number;
515 vnet_buffer (b0)->ip.reass.tcp_seq_number =
516 ((tcp_header_t *) (ip0 + 1))->seq_number;
518 else if (IP_PROTOCOL_ICMP == ip0->protocol)
520 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
521 ((icmp46_header_t *) (ip0 + 1))->type;
523 vnet_buffer (b0)->ip.reass.l4_src_port = ip4_get_port (ip0, 1);
524 vnet_buffer (b0)->ip.reass.l4_dst_port = ip4_get_port (ip0, 0);
525 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
527 ip4_sv_reass_add_trace (vm, node, NULL, from[(b - 2) - bufs],
529 vnet_buffer (b0)->ip.reass.ip_proto,
530 vnet_buffer (b0)->ip.reass.l4_src_port,
531 vnet_buffer (b0)->ip.reass.l4_dst_port);
535 vnet_feature_next (&next1, b1);
539 next1 = is_custom ? vnet_buffer (b1)->ip.reass.next_index :
540 IP4_SV_REASSEMBLY_NEXT_INPUT;
542 vnet_buffer (b1)->ip.reass.is_non_first_fragment = 0;
543 vnet_buffer (b1)->ip.reass.ip_proto = ip1->protocol;
544 if (IP_PROTOCOL_TCP == ip1->protocol)
546 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
547 ((tcp_header_t *) (ip1 + 1))->flags;
548 vnet_buffer (b1)->ip.reass.tcp_ack_number =
549 ((tcp_header_t *) (ip1 + 1))->ack_number;
550 vnet_buffer (b1)->ip.reass.tcp_seq_number =
551 ((tcp_header_t *) (ip1 + 1))->seq_number;
553 else if (IP_PROTOCOL_ICMP == ip1->protocol)
555 vnet_buffer (b1)->ip.reass.icmp_type_or_tcp_flags =
556 ((icmp46_header_t *) (ip1 + 1))->type;
558 vnet_buffer (b1)->ip.reass.l4_src_port = ip4_get_port (ip1, 1);
559 vnet_buffer (b1)->ip.reass.l4_dst_port = ip4_get_port (ip1, 0);
560 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
562 ip4_sv_reass_add_trace (vm, node, NULL, from[(b - 1) - bufs],
564 vnet_buffer (b1)->ip.reass.ip_proto,
565 vnet_buffer (b1)->ip.reass.l4_src_port,
566 vnet_buffer (b1)->ip.reass.l4_dst_port);
575 while (n_left_from > 0)
583 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
584 (is_output_feature ? 1 : 0) *
586 ip.save_rewrite_length);
588 (ip4_get_fragment_more (ip0) || ip4_get_fragment_offset (ip0)))
590 // fragment found, go slow path
594 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
601 vnet_feature_next (&next0, b0);
606 is_custom ? vnet_buffer (b0)->ip.
607 reass.next_index : IP4_SV_REASSEMBLY_NEXT_INPUT;
609 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
610 vnet_buffer (b0)->ip.reass.ip_proto = ip0->protocol;
611 if (IP_PROTOCOL_TCP == ip0->protocol)
613 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
614 ((tcp_header_t *) (ip0 + 1))->flags;
615 vnet_buffer (b0)->ip.reass.tcp_ack_number =
616 ((tcp_header_t *) (ip0 + 1))->ack_number;
617 vnet_buffer (b0)->ip.reass.tcp_seq_number =
618 ((tcp_header_t *) (ip0 + 1))->seq_number;
620 else if (IP_PROTOCOL_ICMP == ip0->protocol)
622 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
623 ((icmp46_header_t *) (ip0 + 1))->type;
625 vnet_buffer (b0)->ip.reass.l4_src_port = ip4_get_port (ip0, 1);
626 vnet_buffer (b0)->ip.reass.l4_dst_port = ip4_get_port (ip0, 0);
627 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
629 ip4_sv_reass_add_trace (vm, node, NULL, from[(b - 1) - bufs],
631 vnet_buffer (b0)->ip.reass.ip_proto,
632 vnet_buffer (b0)->ip.reass.l4_src_port,
633 vnet_buffer (b0)->ip.reass.l4_dst_port);
641 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
650 while (n_left_from > 0)
652 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
654 while (n_left_from > 0 && n_left_to_next > 0)
659 u32 error0 = IP4_ERROR_NONE;
662 b0 = vlib_get_buffer (vm, bi0);
665 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
666 (is_output_feature ? 1 : 0) *
668 ip.save_rewrite_length);
669 if (!ip4_get_fragment_more (ip0) && !ip4_get_fragment_offset (ip0))
671 // this is a regular packet - no fragmentation
674 next0 = vnet_buffer (b0)->ip.reass.next_index;
678 next0 = IP4_SV_REASSEMBLY_NEXT_INPUT;
680 vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
681 vnet_buffer (b0)->ip.reass.ip_proto = ip0->protocol;
682 if (IP_PROTOCOL_TCP == ip0->protocol)
684 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
685 ((tcp_header_t *) (ip0 + 1))->flags;
686 vnet_buffer (b0)->ip.reass.tcp_ack_number =
687 ((tcp_header_t *) (ip0 + 1))->ack_number;
688 vnet_buffer (b0)->ip.reass.tcp_seq_number =
689 ((tcp_header_t *) (ip0 + 1))->seq_number;
691 else if (IP_PROTOCOL_ICMP == ip0->protocol)
693 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
694 ((icmp46_header_t *) (ip0 + 1))->type;
696 vnet_buffer (b0)->ip.reass.l4_src_port = ip4_get_port (ip0, 1);
697 vnet_buffer (b0)->ip.reass.l4_dst_port = ip4_get_port (ip0, 0);
698 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
700 ip4_sv_reass_add_trace (
701 vm, node, NULL, bi0, REASS_PASSTHROUGH,
702 vnet_buffer (b0)->ip.reass.ip_proto,
703 vnet_buffer (b0)->ip.reass.l4_src_port,
704 vnet_buffer (b0)->ip.reass.l4_dst_port);
708 const u32 fragment_first = ip4_get_fragment_offset_bytes (ip0);
709 const u32 fragment_length =
710 clib_net_to_host_u16 (ip0->length) - ip4_header_bytes (ip0);
711 const u32 fragment_last = fragment_first + fragment_length - 1;
712 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
714 next0 = IP4_SV_REASSEMBLY_NEXT_DROP;
715 error0 = IP4_ERROR_REASS_MALFORMED_PACKET;
716 b0->error = node->errors[error0];
719 ip4_sv_reass_kv_t kv;
723 (u64) vec_elt (ip4_main.fib_index_by_sw_if_index,
724 vnet_buffer (b0)->sw_if_index[VLIB_RX]) |
725 (u64) ip0->src_address.as_u32 << 32;
727 (u64) ip0->dst_address.
728 as_u32 | (u64) ip0->fragment_id << 32 | (u64) ip0->protocol << 48;
730 ip4_sv_reass_t *reass =
731 ip4_sv_reass_find_or_create (vm, rm, rt, &kv, &do_handoff);
733 if (PREDICT_FALSE (do_handoff))
735 next0 = IP4_SV_REASSEMBLY_NEXT_HANDOFF;
736 vnet_buffer (b0)->ip.reass.owner_thread_index =
743 next0 = IP4_SV_REASSEMBLY_NEXT_DROP;
744 error0 = IP4_ERROR_REASS_LIMIT_REACHED;
745 b0->error = node->errors[error0];
749 if (reass->is_complete)
753 next0 = vnet_buffer (b0)->ip.reass.next_index;
757 next0 = IP4_SV_REASSEMBLY_NEXT_INPUT;
759 vnet_buffer (b0)->ip.reass.is_non_first_fragment =
761 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
762 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
763 reass->icmp_type_or_tcp_flags;
764 vnet_buffer (b0)->ip.reass.tcp_ack_number =
765 reass->tcp_ack_number;
766 vnet_buffer (b0)->ip.reass.tcp_seq_number =
767 reass->tcp_seq_number;
768 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
769 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
770 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
772 ip4_sv_reass_add_trace (
773 vm, node, reass, bi0, REASS_FRAGMENT_FORWARD,
774 reass->ip_proto, reass->l4_src_port, reass->l4_dst_port);
779 ip4_sv_reass_rc_t rc =
780 ip4_sv_reass_update (vm, node, rm, ip0, reass, bi0);
783 case IP4_SV_REASS_RC_OK:
784 /* nothing to do here */
786 case IP4_SV_REASS_RC_TOO_MANY_FRAGMENTS:
787 vlib_node_increment_counter (vm, node->node_index,
788 IP4_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
790 ip4_sv_reass_free (vm, rm, rt, reass);
793 case IP4_SV_REASS_RC_UNSUPP_IP_PROTO:
794 vlib_node_increment_counter (vm, node->node_index,
795 IP4_ERROR_REASS_UNSUPP_IP_PROT, 1);
796 ip4_sv_reass_free (vm, rm, rt, reass);
800 if (reass->is_complete)
803 vec_foreach_index (idx, reass->cached_buffers)
805 u32 bi0 = vec_elt (reass->cached_buffers, idx);
806 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
808 (ip4_header_t *) u8_ptr_add (vlib_buffer_get_current (b0),
809 (is_output_feature ? 1 : 0) *
811 ip.save_rewrite_length);
812 u32 next0 = IP4_SV_REASSEMBLY_NEXT_INPUT;
815 vnet_feature_next (&next0, b0);
819 next0 = vnet_buffer (b0)->ip.reass.next_index;
821 if (0 == n_left_to_next)
823 vlib_put_next_frame (vm, node, next_index,
825 vlib_get_next_frame (vm, node, next_index, to_next,
831 vnet_buffer (b0)->ip.reass.is_non_first_fragment =
832 ! !ip4_get_fragment_offset (ip0);
833 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
834 vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
835 reass->icmp_type_or_tcp_flags;
836 vnet_buffer (b0)->ip.reass.tcp_ack_number =
837 reass->tcp_ack_number;
838 vnet_buffer (b0)->ip.reass.tcp_seq_number =
839 reass->tcp_seq_number;
840 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
841 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
842 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
844 ip4_sv_reass_add_trace (
845 vm, node, reass, bi0, REASS_FRAGMENT_FORWARD,
846 reass->ip_proto, reass->l4_src_port, reass->l4_dst_port);
848 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
849 to_next, n_left_to_next, bi0,
852 _vec_len (reass->cached_buffers) = 0; // buffers are owned by frame now
860 if (is_feature && IP4_ERROR_NONE == error0)
862 b0 = vlib_get_buffer (vm, bi0);
863 vnet_feature_next (&next0, b0);
865 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
866 to_next, n_left_to_next,
874 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
878 clib_spinlock_unlock (&rt->lock);
879 return frame->n_vectors;
882 static char *ip4_sv_reass_error_strings[] = {
883 #define _(sym, string) string,
888 VLIB_NODE_FN (ip4_sv_reass_node) (vlib_main_t * vm,
889 vlib_node_runtime_t * node,
890 vlib_frame_t * frame)
892 return ip4_sv_reass_inline (vm, node, frame, false /* is_feature */ ,
893 false /* is_output_feature */ ,
894 false /* is_custom */ );
898 VLIB_REGISTER_NODE (ip4_sv_reass_node) = {
899 .name = "ip4-sv-reassembly",
900 .vector_size = sizeof (u32),
901 .format_trace = format_ip4_sv_reass_trace,
902 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
903 .error_strings = ip4_sv_reass_error_strings,
904 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
907 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
908 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
909 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reassembly-handoff",
915 VLIB_NODE_FN (ip4_sv_reass_node_feature) (vlib_main_t * vm,
916 vlib_node_runtime_t * node,
917 vlib_frame_t * frame)
919 return ip4_sv_reass_inline (vm, node, frame, true /* is_feature */ ,
920 false /* is_output_feature */ ,
921 false /* is_custom */ );
925 VLIB_REGISTER_NODE (ip4_sv_reass_node_feature) = {
926 .name = "ip4-sv-reassembly-feature",
927 .vector_size = sizeof (u32),
928 .format_trace = format_ip4_sv_reass_trace,
929 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
930 .error_strings = ip4_sv_reass_error_strings,
931 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
934 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
935 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
936 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reass-feature-hoff",
942 VNET_FEATURE_INIT (ip4_sv_reass_feature) = {
943 .arc_name = "ip4-unicast",
944 .node_name = "ip4-sv-reassembly-feature",
945 .runs_before = VNET_FEATURES ("ip4-lookup"),
950 VLIB_NODE_FN (ip4_sv_reass_node_output_feature) (vlib_main_t * vm,
951 vlib_node_runtime_t * node,
952 vlib_frame_t * frame)
954 return ip4_sv_reass_inline (vm, node, frame, true /* is_feature */ ,
955 true /* is_output_feature */ ,
956 false /* is_custom */ );
961 VLIB_REGISTER_NODE (ip4_sv_reass_node_output_feature) = {
962 .name = "ip4-sv-reassembly-output-feature",
963 .vector_size = sizeof (u32),
964 .format_trace = format_ip4_sv_reass_trace,
965 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
966 .error_strings = ip4_sv_reass_error_strings,
967 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
970 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
971 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
972 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reass-feature-hoff",
978 VNET_FEATURE_INIT (ip4_sv_reass_output_feature) = {
979 .arc_name = "ip4-output",
980 .node_name = "ip4-sv-reassembly-output-feature",
987 VLIB_REGISTER_NODE (ip4_sv_reass_custom_node) = {
988 .name = "ip4-sv-reassembly-custom-next",
989 .vector_size = sizeof (u32),
990 .format_trace = format_ip4_sv_reass_trace,
991 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
992 .error_strings = ip4_sv_reass_error_strings,
993 .n_next_nodes = IP4_SV_REASSEMBLY_N_NEXT,
996 [IP4_SV_REASSEMBLY_NEXT_INPUT] = "ip4-input",
997 [IP4_SV_REASSEMBLY_NEXT_DROP] = "ip4-drop",
998 [IP4_SV_REASSEMBLY_NEXT_HANDOFF] = "ip4-sv-reassembly-handoff",
1004 VLIB_NODE_FN (ip4_sv_reass_custom_node) (vlib_main_t * vm,
1005 vlib_node_runtime_t * node,
1006 vlib_frame_t * frame)
1008 return ip4_sv_reass_inline (vm, node, frame, false /* is_feature */ ,
1009 false /* is_output_feature */ ,
1010 true /* is_custom */ );
1013 #ifndef CLIB_MARCH_VARIANT
1015 ip4_sv_reass_get_nbuckets ()
1017 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1021 nbuckets = (u32) (rm->max_reass_n / IP4_SV_REASS_HT_LOAD_FACTOR);
1023 for (i = 0; i < 31; i++)
1024 if ((1 << i) >= nbuckets)
1030 #endif /* CLIB_MARCH_VARIANT */
1034 IP4_EVENT_CONFIG_CHANGED = 1,
1035 } ip4_sv_reass_event_t;
1040 clib_bihash_16_8_t *new_hash;
1041 } ip4_rehash_cb_ctx;
1043 #ifndef CLIB_MARCH_VARIANT
1045 ip4_rehash_cb (clib_bihash_kv_16_8_t * kv, void *_ctx)
1047 ip4_rehash_cb_ctx *ctx = _ctx;
1048 if (clib_bihash_add_del_16_8 (ctx->new_hash, kv, 1))
1052 return (BIHASH_WALK_CONTINUE);
1056 ip4_sv_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
1057 u32 max_reassembly_length,
1058 u32 expire_walk_interval_ms)
1060 ip4_sv_reass_main.timeout_ms = timeout_ms;
1061 ip4_sv_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
1062 ip4_sv_reass_main.max_reass_n = max_reassemblies;
1063 ip4_sv_reass_main.max_reass_len = max_reassembly_length;
1064 ip4_sv_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
1068 ip4_sv_reass_set (u32 timeout_ms, u32 max_reassemblies,
1069 u32 max_reassembly_length, u32 expire_walk_interval_ms)
1071 u32 old_nbuckets = ip4_sv_reass_get_nbuckets ();
1072 ip4_sv_reass_set_params (timeout_ms, max_reassemblies,
1073 max_reassembly_length, expire_walk_interval_ms);
1074 vlib_process_signal_event (ip4_sv_reass_main.vlib_main,
1075 ip4_sv_reass_main.ip4_sv_reass_expire_node_idx,
1076 IP4_EVENT_CONFIG_CHANGED, 0);
1077 u32 new_nbuckets = ip4_sv_reass_get_nbuckets ();
1078 if (ip4_sv_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
1080 clib_bihash_16_8_t new_hash;
1081 clib_memset (&new_hash, 0, sizeof (new_hash));
1082 ip4_rehash_cb_ctx ctx;
1084 ctx.new_hash = &new_hash;
1085 clib_bihash_init_16_8 (&new_hash, "ip4-dr", new_nbuckets,
1086 new_nbuckets * 1024);
1087 clib_bihash_foreach_key_value_pair_16_8 (&ip4_sv_reass_main.hash,
1088 ip4_rehash_cb, &ctx);
1091 clib_bihash_free_16_8 (&new_hash);
1096 clib_bihash_free_16_8 (&ip4_sv_reass_main.hash);
1097 clib_memcpy_fast (&ip4_sv_reass_main.hash, &new_hash,
1098 sizeof (ip4_sv_reass_main.hash));
1099 clib_bihash_copied (&ip4_sv_reass_main.hash, &new_hash);
1106 ip4_sv_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
1107 u32 * max_reassembly_length, u32 * expire_walk_interval_ms)
1109 *timeout_ms = ip4_sv_reass_main.timeout_ms;
1110 *max_reassemblies = ip4_sv_reass_main.max_reass_n;
1111 *max_reassembly_length = ip4_sv_reass_main.max_reass_len;
1112 *expire_walk_interval_ms = ip4_sv_reass_main.expire_walk_interval_ms;
1116 static clib_error_t *
1117 ip4_sv_reass_init_function (vlib_main_t * vm)
1119 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1120 clib_error_t *error = 0;
1125 rm->vnet_main = vnet_get_main ();
1127 vec_validate (rm->per_thread_data, vlib_num_workers ());
1128 ip4_sv_reass_per_thread_t *rt;
1129 vec_foreach (rt, rm->per_thread_data)
1131 clib_spinlock_init (&rt->lock);
1132 pool_alloc (rt->pool, rm->max_reass_n);
1133 rt->lru_first = rt->lru_last = ~0;
1136 node = vlib_get_node_by_name (vm, (u8 *) "ip4-sv-reassembly-expire-walk");
1138 rm->ip4_sv_reass_expire_node_idx = node->index;
1140 ip4_sv_reass_set_params (IP4_SV_REASS_TIMEOUT_DEFAULT_MS,
1141 IP4_SV_REASS_MAX_REASSEMBLIES_DEFAULT,
1142 IP4_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT,
1143 IP4_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
1145 nbuckets = ip4_sv_reass_get_nbuckets ();
1146 clib_bihash_init_16_8 (&rm->hash, "ip4-dr", nbuckets, nbuckets * 1024);
1148 node = vlib_get_node_by_name (vm, (u8 *) "ip4-drop");
1150 rm->ip4_drop_idx = node->index;
1152 rm->fq_index = vlib_frame_queue_main_init (ip4_sv_reass_node.index, 0);
1153 rm->fq_feature_index =
1154 vlib_frame_queue_main_init (ip4_sv_reass_node_feature.index, 0);
1156 rm->feature_use_refcount_per_intf = NULL;
1157 rm->output_feature_use_refcount_per_intf = NULL;
1162 VLIB_INIT_FUNCTION (ip4_sv_reass_init_function);
1163 #endif /* CLIB_MARCH_VARIANT */
1166 ip4_sv_reass_walk_expired (vlib_main_t *vm,
1167 CLIB_UNUSED (vlib_node_runtime_t *node),
1168 CLIB_UNUSED (vlib_frame_t *f))
1170 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1171 uword event_type, *event_data = 0;
1175 vlib_process_wait_for_event_or_clock (vm,
1177 rm->expire_walk_interval_ms /
1178 (f64) MSEC_PER_SEC);
1179 event_type = vlib_process_get_events (vm, &event_data);
1184 /* no events => timeout */
1186 case IP4_EVENT_CONFIG_CHANGED:
1187 /* nothing to do here */
1190 clib_warning ("BUG: event type 0x%wx", event_type);
1193 f64 now = vlib_time_now (vm);
1195 ip4_sv_reass_t *reass;
1196 int *pool_indexes_to_free = NULL;
1198 uword thread_index = 0;
1200 const uword nthreads = vlib_num_workers () + 1;
1201 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1203 ip4_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1204 clib_spinlock_lock (&rt->lock);
1206 vec_reset_length (pool_indexes_to_free);
1208 pool_foreach_index (index, rt->pool) {
1209 reass = pool_elt_at_index (rt->pool, index);
1210 if (now > reass->last_heard + rm->timeout)
1212 vec_add1 (pool_indexes_to_free, index);
1218 vec_foreach (i, pool_indexes_to_free)
1220 ip4_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1221 ip4_sv_reass_free (vm, rm, rt, reass);
1225 clib_spinlock_unlock (&rt->lock);
1228 vec_free (pool_indexes_to_free);
1231 _vec_len (event_data) = 0;
1239 VLIB_REGISTER_NODE (ip4_sv_reass_expire_node) = {
1240 .function = ip4_sv_reass_walk_expired,
1241 .type = VLIB_NODE_TYPE_PROCESS,
1242 .name = "ip4-sv-reassembly-expire-walk",
1243 .format_trace = format_ip4_sv_reass_trace,
1244 .n_errors = ARRAY_LEN (ip4_sv_reass_error_strings),
1245 .error_strings = ip4_sv_reass_error_strings,
1251 format_ip4_sv_reass_key (u8 * s, va_list * args)
1253 ip4_sv_reass_key_t *key = va_arg (*args, ip4_sv_reass_key_t *);
1256 "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1257 key->xx_id, format_ip4_address, &key->src, format_ip4_address,
1258 &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1263 format_ip4_sv_reass (u8 * s, va_list * args)
1265 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1266 ip4_sv_reass_t *reass = va_arg (*args, ip4_sv_reass_t *);
1268 s = format (s, "ID: %lu, key: %U trace_op_counter: %u\n",
1269 reass->id, format_ip4_sv_reass_key, &reass->key,
1270 reass->trace_op_counter);
1275 vec_foreach (bip, reass->cached_buffers)
1280 b = vlib_get_buffer (vm, bi);
1281 s = format (s, " #%03u: bi: %u, ", counter, bi);
1283 bi = b->next_buffer;
1285 while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
1290 static clib_error_t *
1291 show_ip4_reass (vlib_main_t * vm,
1292 unformat_input_t * input,
1293 CLIB_UNUSED (vlib_cli_command_t * lmd))
1295 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1297 vlib_cli_output (vm, "---------------------");
1298 vlib_cli_output (vm, "IP4 reassembly status");
1299 vlib_cli_output (vm, "---------------------");
1300 bool details = false;
1301 if (unformat (input, "details"))
1306 u32 sum_reass_n = 0;
1307 ip4_sv_reass_t *reass;
1309 const uword nthreads = vlib_num_workers () + 1;
1310 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1312 ip4_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1313 clib_spinlock_lock (&rt->lock);
1317 pool_foreach (reass, rt->pool) {
1318 vlib_cli_output (vm, "%U", format_ip4_sv_reass, vm, reass);
1322 sum_reass_n += rt->reass_n;
1323 clib_spinlock_unlock (&rt->lock);
1325 vlib_cli_output (vm, "---------------------");
1326 vlib_cli_output (vm, "Current IP4 reassemblies count: %lu\n",
1327 (long unsigned) sum_reass_n);
1328 vlib_cli_output (vm,
1329 "Maximum configured concurrent shallow virtual IP4 reassemblies per worker-thread: %lu\n",
1330 (long unsigned) rm->max_reass_n);
1331 vlib_cli_output (vm,
1332 "Maximum configured amount of fragments per shallow "
1333 "virtual IP4 reassembly: %lu\n",
1334 (long unsigned) rm->max_reass_len);
1335 vlib_cli_output (vm,
1336 "Maximum configured shallow virtual IP4 reassembly timeout: %lums\n",
1337 (long unsigned) rm->timeout_ms);
1338 vlib_cli_output (vm,
1339 "Maximum configured shallow virtual IP4 reassembly expire walk interval: %lums\n",
1340 (long unsigned) rm->expire_walk_interval_ms);
1345 VLIB_CLI_COMMAND (show_ip4_sv_reass_cmd, static) = {
1346 .path = "show ip4-sv-reassembly",
1347 .short_help = "show ip4-sv-reassembly [details]",
1348 .function = show_ip4_reass,
1352 #ifndef CLIB_MARCH_VARIANT
1354 ip4_sv_reass_enable_disable (u32 sw_if_index, u8 enable_disable)
1356 return ip4_sv_reass_enable_disable_with_refcnt (sw_if_index,
1359 #endif /* CLIB_MARCH_VARIANT */
1362 #define foreach_ip4_sv_reass_handoff_error \
1363 _(CONGESTION_DROP, "congestion drop")
1368 #define _(sym,str) IP4_SV_REASSEMBLY_HANDOFF_ERROR_##sym,
1369 foreach_ip4_sv_reass_handoff_error
1371 IP4_SV_REASSEMBLY_HANDOFF_N_ERROR,
1372 } ip4_sv_reass_handoff_error_t;
1374 static char *ip4_sv_reass_handoff_error_strings[] = {
1375 #define _(sym,string) string,
1376 foreach_ip4_sv_reass_handoff_error
1382 u32 next_worker_index;
1383 } ip4_sv_reass_handoff_trace_t;
1386 format_ip4_sv_reass_handoff_trace (u8 * s, va_list * args)
1388 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1389 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1390 ip4_sv_reass_handoff_trace_t *t =
1391 va_arg (*args, ip4_sv_reass_handoff_trace_t *);
1394 format (s, "ip4-sv-reassembly-handoff: next-worker %d",
1395 t->next_worker_index);
1401 ip4_sv_reass_handoff_node_inline (vlib_main_t * vm,
1402 vlib_node_runtime_t * node,
1403 vlib_frame_t * frame, bool is_feature)
1405 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1407 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1408 u32 n_enq, n_left_from, *from;
1409 u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1412 from = vlib_frame_vector_args (frame);
1413 n_left_from = frame->n_vectors;
1414 vlib_get_buffers (vm, from, bufs, n_left_from);
1417 ti = thread_indices;
1419 fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1421 while (n_left_from > 0)
1423 ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1426 ((node->flags & VLIB_NODE_FLAG_TRACE)
1427 && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1429 ip4_sv_reass_handoff_trace_t *t =
1430 vlib_add_trace (vm, node, b[0], sizeof (*t));
1431 t->next_worker_index = ti[0];
1438 n_enq = vlib_buffer_enqueue_to_thread (vm, node, fq_index, from,
1439 thread_indices, frame->n_vectors, 1);
1441 if (n_enq < frame->n_vectors)
1442 vlib_node_increment_counter (vm, node->node_index,
1443 IP4_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1444 frame->n_vectors - n_enq);
1445 return frame->n_vectors;
1448 VLIB_NODE_FN (ip4_sv_reass_handoff_node) (vlib_main_t * vm,
1449 vlib_node_runtime_t * node,
1450 vlib_frame_t * frame)
1452 return ip4_sv_reass_handoff_node_inline (vm, node, frame,
1453 false /* is_feature */ );
1458 VLIB_REGISTER_NODE (ip4_sv_reass_handoff_node) = {
1459 .name = "ip4-sv-reassembly-handoff",
1460 .vector_size = sizeof (u32),
1461 .n_errors = ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1462 .error_strings = ip4_sv_reass_handoff_error_strings,
1463 .format_trace = format_ip4_sv_reass_handoff_trace,
1475 VLIB_NODE_FN (ip4_sv_reass_feature_handoff_node) (vlib_main_t * vm,
1476 vlib_node_runtime_t *
1478 vlib_frame_t * frame)
1480 return ip4_sv_reass_handoff_node_inline (vm, node, frame,
1481 true /* is_feature */ );
1487 VLIB_REGISTER_NODE (ip4_sv_reass_feature_handoff_node) = {
1488 .name = "ip4-sv-reass-feature-hoff",
1489 .vector_size = sizeof (u32),
1490 .n_errors = ARRAY_LEN(ip4_sv_reass_handoff_error_strings),
1491 .error_strings = ip4_sv_reass_handoff_error_strings,
1492 .format_trace = format_ip4_sv_reass_handoff_trace,
1502 #ifndef CLIB_MARCH_VARIANT
1504 ip4_sv_reass_enable_disable_with_refcnt (u32 sw_if_index, int is_enable)
1506 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1507 vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
1510 if (!rm->feature_use_refcount_per_intf[sw_if_index])
1512 ++rm->feature_use_refcount_per_intf[sw_if_index];
1513 return vnet_feature_enable_disable ("ip4-unicast",
1514 "ip4-sv-reassembly-feature",
1515 sw_if_index, 1, 0, 0);
1517 ++rm->feature_use_refcount_per_intf[sw_if_index];
1521 if (rm->feature_use_refcount_per_intf[sw_if_index])
1522 --rm->feature_use_refcount_per_intf[sw_if_index];
1523 if (!rm->feature_use_refcount_per_intf[sw_if_index])
1524 return vnet_feature_enable_disable ("ip4-unicast",
1525 "ip4-sv-reassembly-feature",
1526 sw_if_index, 0, 0, 0);
1532 ip4_sv_reass_custom_register_next_node (uword node_index)
1534 return vlib_node_add_next (vlib_get_main (), ip4_sv_reass_custom_node.index,
1539 ip4_sv_reass_output_enable_disable_with_refcnt (u32 sw_if_index,
1542 ip4_sv_reass_main_t *rm = &ip4_sv_reass_main;
1543 vec_validate (rm->output_feature_use_refcount_per_intf, sw_if_index);
1546 if (!rm->output_feature_use_refcount_per_intf[sw_if_index])
1548 ++rm->output_feature_use_refcount_per_intf[sw_if_index];
1549 return vnet_feature_enable_disable ("ip4-output",
1550 "ip4-sv-reassembly-output-feature",
1551 sw_if_index, 1, 0, 0);
1553 ++rm->output_feature_use_refcount_per_intf[sw_if_index];
1557 if (rm->output_feature_use_refcount_per_intf[sw_if_index])
1558 --rm->output_feature_use_refcount_per_intf[sw_if_index];
1559 if (!rm->output_feature_use_refcount_per_intf[sw_if_index])
1560 return vnet_feature_enable_disable ("ip4-output",
1561 "ip4-sv-reassembly-output-feature",
1562 sw_if_index, 0, 0, 0);
1569 * fd.io coding-style-patch-verification: ON
1572 * eval: (c-set-style "gnu")