blob: a7f360eb583c14853216cd8331296434dae782b8 [file] [log] [blame]
Klement Sekerade34c352019-06-25 11:19:22 +00001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16/**
17 * @file
18 * @brief IPv6 Shallow Virtual Reassembly.
19 *
20 * This file contains the source code for IPv6 Shallow Virtual reassembly.
21 */
22
23#include <vppinfra/vec.h>
24#include <vnet/vnet.h>
25#include <vnet/ip/ip.h>
26#include <vnet/ip/ip6_to_ip4.h>
27#include <vppinfra/bihash_48_8.h>
28#include <vnet/ip/reass/ip6_sv_reass.h>
29
30#define MSEC_PER_SEC 1000
31#define IP6_SV_REASS_TIMEOUT_DEFAULT_MS 100
32#define IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
33#define IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT 1024
34#define IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3
35#define IP6_SV_REASS_HT_LOAD_FACTOR (0.75)
36
37typedef enum
38{
39 IP6_SV_REASS_RC_OK,
40 IP6_SV_REASS_RC_TOO_MANY_FRAGMENTS,
41 IP6_SV_REASS_RC_INTERNAL_ERROR,
42 IP6_SV_REASS_RC_UNSUPP_IP_PROTO,
43} ip6_sv_reass_rc_t;
44
45typedef struct
46{
47 union
48 {
49 struct
50 {
51 ip6_address_t src;
52 ip6_address_t dst;
53 u32 xx_id;
54 u32 frag_id;
55 u8 unused[7];
56 u8 proto;
57 };
58 u64 as_u64[6];
59 };
60} ip6_sv_reass_key_t;
61
62typedef union
63{
64 struct
65 {
66 u32 reass_index;
67 u32 thread_index;
68 };
69 u64 as_u64;
70} ip6_sv_reass_val_t;
71
72typedef union
73{
74 struct
75 {
76 ip6_sv_reass_key_t k;
77 ip6_sv_reass_val_t v;
78 };
79 clib_bihash_kv_48_8_t kv;
80} ip6_sv_reass_kv_t;
81
82typedef struct
83{
84 // hash table key
85 ip6_sv_reass_key_t key;
86 // time when last packet was received
87 f64 last_heard;
88 // internal id of this reassembly
89 u64 id;
90 // trace operation counter
91 u32 trace_op_counter;
92 // buffer indexes of buffers in this reassembly in chronological order -
93 // including overlaps and duplicate fragments
94 u32 *cached_buffers;
95 // set to true when this reassembly is completed
96 bool is_complete;
97 // ip protocol
98 u8 ip_proto;
99 // l4 src port
100 u16 l4_src_port;
101 // l4 dst port
102 u16 l4_dst_port;
103 // lru indexes
104 u32 lru_prev;
105 u32 lru_next;
106} ip6_sv_reass_t;
107
108typedef struct
109{
110 ip6_sv_reass_t *pool;
111 u32 reass_n;
112 u32 id_counter;
113 clib_spinlock_t lock;
114 // lru indexes
115 u32 lru_first;
116 u32 lru_last;
117} ip6_sv_reass_per_thread_t;
118
119typedef struct
120{
121 // IPv6 config
122 u32 timeout_ms;
123 f64 timeout;
124 u32 expire_walk_interval_ms;
125 // maximum number of fragments in one reassembly
126 u32 max_reass_len;
127 // maximum number of reassemblies
128 u32 max_reass_n;
129
130 // IPv6 runtime
131 clib_bihash_48_8_t hash;
132
133 // per-thread data
134 ip6_sv_reass_per_thread_t *per_thread_data;
135
136 // convenience
137 vlib_main_t *vlib_main;
138 vnet_main_t *vnet_main;
139
140 // node index of ip6-drop node
141 u32 ip6_drop_idx;
142 u32 ip6_icmp_error_idx;
143 u32 ip6_sv_reass_expire_node_idx;
144
145 /** Worker handoff */
146 u32 fq_index;
147 u32 fq_feature_index;
148
Klement Sekera63c73532019-09-30 14:35:36 +0000149 // reference count for enabling/disabling feature - per interface
150 u32 *feature_use_refcount_per_intf;
Klement Sekerade34c352019-06-25 11:19:22 +0000151} ip6_sv_reass_main_t;
152
153extern ip6_sv_reass_main_t ip6_sv_reass_main;
154
155#ifndef CLIB_MARCH_VARIANT
156ip6_sv_reass_main_t ip6_sv_reass_main;
157#endif /* CLIB_MARCH_VARIANT */
158
159typedef enum
160{
161 IP6_SV_REASSEMBLY_NEXT_INPUT,
162 IP6_SV_REASSEMBLY_NEXT_DROP,
163 IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR,
164 IP6_SV_REASSEMBLY_NEXT_HANDOFF,
165 IP6_SV_REASSEMBLY_N_NEXT,
166} ip6_sv_reass_next_t;
167
168typedef enum
169{
Klement Sekerade34c352019-06-25 11:19:22 +0000170 REASS_FRAGMENT_CACHE,
171 REASS_FINISH,
172 REASS_FRAGMENT_FORWARD,
173} ip6_sv_reass_trace_operation_e;
174
175typedef struct
176{
177 ip6_sv_reass_trace_operation_e action;
178 u32 reass_id;
179 u32 op_id;
180 u8 ip_proto;
181 u16 l4_src_port;
182 u16 l4_dst_port;
183} ip6_sv_reass_trace_t;
184
185static u8 *
186format_ip6_sv_reass_trace (u8 * s, va_list * args)
187{
188 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
189 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
190 ip6_sv_reass_trace_t *t = va_arg (*args, ip6_sv_reass_trace_t *);
191 s = format (s, "reass id: %u, op id: %u ", t->reass_id, t->op_id);
192 switch (t->action)
193 {
Klement Sekerade34c352019-06-25 11:19:22 +0000194 case REASS_FRAGMENT_CACHE:
195 s = format (s, "[cached]");
196 break;
197 case REASS_FINISH:
198 s =
199 format (s, "[finish, ip proto=%u, src_port=%u, dst_port=%u]",
200 t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
201 clib_net_to_host_u16 (t->l4_dst_port));
202 break;
203 case REASS_FRAGMENT_FORWARD:
204 s =
205 format (s, "[forward, ip proto=%u, src_port=%u, dst_port=%u]",
206 t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
207 clib_net_to_host_u16 (t->l4_dst_port));
208 break;
209 }
210 return s;
211}
212
213static void
214ip6_sv_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
215 ip6_sv_reass_main_t * rm,
216 ip6_sv_reass_t * reass, u32 bi,
217 ip6_sv_reass_trace_operation_e action,
218 u32 ip_proto, u16 l4_src_port, u16 l4_dst_port)
219{
220 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
221 ip6_sv_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
222 t->reass_id = reass->id;
223 t->action = action;
224 t->op_id = reass->trace_op_counter;
225 t->ip_proto = ip_proto;
226 t->l4_src_port = l4_src_port;
227 t->l4_dst_port = l4_dst_port;
228 ++reass->trace_op_counter;
229#if 0
230 static u8 *s = NULL;
231 s = format (s, "%U", format_ip6_sv_reass_trace, NULL, NULL, t);
232 printf ("%.*s\n", vec_len (s), s);
233 fflush (stdout);
234 vec_reset_length (s);
235#endif
236}
237
238always_inline void
239ip6_sv_reass_free (vlib_main_t * vm, ip6_sv_reass_main_t * rm,
240 ip6_sv_reass_per_thread_t * rt, ip6_sv_reass_t * reass)
241{
242 clib_bihash_kv_48_8_t kv;
243 kv.key[0] = reass->key.as_u64[0];
244 kv.key[1] = reass->key.as_u64[1];
245 kv.key[2] = reass->key.as_u64[2];
246 kv.key[3] = reass->key.as_u64[3];
247 kv.key[4] = reass->key.as_u64[4];
248 kv.key[5] = reass->key.as_u64[5];
249 clib_bihash_add_del_48_8 (&rm->hash, &kv, 0);
250 vlib_buffer_free (vm, reass->cached_buffers,
251 vec_len (reass->cached_buffers));
252 vec_free (reass->cached_buffers);
253 reass->cached_buffers = NULL;
254 if (~0 != reass->lru_prev)
255 {
256 ip6_sv_reass_t *lru_prev =
257 pool_elt_at_index (rt->pool, reass->lru_prev);
258 lru_prev->lru_next = reass->lru_next;
259 }
260 if (~0 != reass->lru_next)
261 {
262 ip6_sv_reass_t *lru_next =
263 pool_elt_at_index (rt->pool, reass->lru_next);
264 lru_next->lru_prev = reass->lru_prev;
265 }
266 if (rt->lru_first == reass - rt->pool)
267 {
268 rt->lru_first = reass->lru_next;
269 }
270 if (rt->lru_last == reass - rt->pool)
271 {
272 rt->lru_last = reass->lru_prev;
273 }
274 pool_put (rt->pool, reass);
275 --rt->reass_n;
276}
277
278always_inline void
279ip6_sv_reass_init (ip6_sv_reass_t * reass)
280{
281 reass->cached_buffers = NULL;
282 reass->is_complete = false;
283}
284
285always_inline ip6_sv_reass_t *
286ip6_sv_reass_find_or_create (vlib_main_t * vm, vlib_node_runtime_t * node,
287 ip6_sv_reass_main_t * rm,
288 ip6_sv_reass_per_thread_t * rt,
289 ip6_sv_reass_kv_t * kv, u32 * icmp_bi,
290 u8 * do_handoff)
291{
292 ip6_sv_reass_t *reass = NULL;
293 f64 now = vlib_time_now (rm->vlib_main);
294
295 if (!clib_bihash_search_48_8
296 (&rm->hash, (clib_bihash_kv_48_8_t *) kv, (clib_bihash_kv_48_8_t *) kv))
297 {
298 if (vm->thread_index != kv->v.thread_index)
299 {
300 *do_handoff = 1;
301 return NULL;
302 }
303 reass = pool_elt_at_index (rt->pool, kv->v.reass_index);
304
305 if (now > reass->last_heard + rm->timeout)
306 {
307 ip6_sv_reass_free (vm, rm, rt, reass);
308 reass = NULL;
309 }
310 }
311
312 if (reass)
313 {
314 reass->last_heard = now;
315 return reass;
316 }
317
318 if (rt->reass_n >= rm->max_reass_n)
319 {
320 reass = pool_elt_at_index (rt->pool, rt->lru_last);
321 ip6_sv_reass_free (vm, rm, rt, reass);
322 }
323
324 pool_get (rt->pool, reass);
325 clib_memset (reass, 0, sizeof (*reass));
326 reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
327 ++rt->id_counter;
328 ip6_sv_reass_init (reass);
329 ++rt->reass_n;
330
331 reass->lru_prev = reass->lru_next = ~0;
332
333 if (~0 != rt->lru_last)
334 {
335 ip6_sv_reass_t *lru_last = pool_elt_at_index (rt->pool, rt->lru_last);
336 reass->lru_prev = rt->lru_last;
337 lru_last->lru_next = rt->lru_last = reass - rt->pool;
338 }
339
340 if (~0 == rt->lru_first)
341 {
342 rt->lru_first = rt->lru_last = reass - rt->pool;
343 }
344
345 reass->key.as_u64[0] = ((clib_bihash_kv_48_8_t *) kv)->key[0];
346 reass->key.as_u64[1] = ((clib_bihash_kv_48_8_t *) kv)->key[1];
347 reass->key.as_u64[2] = ((clib_bihash_kv_48_8_t *) kv)->key[2];
348 reass->key.as_u64[3] = ((clib_bihash_kv_48_8_t *) kv)->key[3];
349 reass->key.as_u64[4] = ((clib_bihash_kv_48_8_t *) kv)->key[4];
350 reass->key.as_u64[5] = ((clib_bihash_kv_48_8_t *) kv)->key[5];
351 kv->v.reass_index = (reass - rt->pool);
352 kv->v.thread_index = vm->thread_index;
353 reass->last_heard = now;
354
355 if (clib_bihash_add_del_48_8 (&rm->hash, (clib_bihash_kv_48_8_t *) kv, 1))
356 {
357 ip6_sv_reass_free (vm, rm, rt, reass);
358 reass = NULL;
359 }
360
361 return reass;
362}
363
364always_inline ip6_sv_reass_rc_t
365ip6_sv_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
366 ip6_sv_reass_main_t * rm, ip6_sv_reass_per_thread_t * rt,
367 ip6_sv_reass_t * reass, u32 bi0,
368 ip6_frag_hdr_t * frag_hdr)
369{
370 vlib_buffer_t *fb = vlib_get_buffer (vm, bi0);
371 vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
372 fvnb->ip.reass.ip6_frag_hdr_offset =
373 (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb);
374 ip6_header_t *fip = vlib_buffer_get_current (fb);
375 if (fb->current_length < sizeof (*fip) ||
376 fvnb->ip.reass.ip6_frag_hdr_offset == 0 ||
377 fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length)
378 {
379 return IP6_SV_REASS_RC_INTERNAL_ERROR;
380 }
381
382 u32 fragment_first = fvnb->ip.reass.fragment_first =
383 ip6_frag_hdr_offset_bytes (frag_hdr);
384 u32 fragment_length =
385 vlib_buffer_length_in_chain (vm, fb) -
386 (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
387 u32 fragment_last = fvnb->ip.reass.fragment_last =
388 fragment_first + fragment_length - 1;
389 fvnb->ip.reass.range_first = fragment_first;
390 fvnb->ip.reass.range_last = fragment_last;
391 fvnb->ip.reass.next_range_bi = ~0;
392 if (0 == fragment_first)
393 {
394 ip6_ext_header_t *ext_hdr = (void *) frag_hdr;
395 while (ip6_ext_hdr (ext_hdr->next_hdr)
396 && vlib_object_within_buffer_data (vm, fb, ext_hdr,
397 ext_hdr->n_data_u64s * 8))
398 {
399 ext_hdr = ip6_ext_next_header (ext_hdr);
400 }
401 reass->ip_proto = ext_hdr->next_hdr;
402 reass->l4_src_port = ip6_get_port (fip, 1, fb->current_length);
403 reass->l4_dst_port = ip6_get_port (fip, 0, fb->current_length);
404 if (!reass->l4_src_port || !reass->l4_dst_port)
405 return IP6_SV_REASS_RC_UNSUPP_IP_PROTO;
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))
409 {
410 ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, REASS_FINISH,
411 reass->ip_proto, reass->l4_src_port,
412 reass->l4_dst_port);
413 }
414 }
415 vec_add1 (reass->cached_buffers, bi0);
416 if (!reass->is_complete)
417 {
418 if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
419 {
420 ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
421 REASS_FRAGMENT_CACHE, reass->ip_proto,
422 reass->l4_src_port, reass->l4_dst_port);
423 }
424 if (vec_len (reass->cached_buffers) > rm->max_reass_len)
425 {
426 return IP6_SV_REASS_RC_TOO_MANY_FRAGMENTS;
427 }
428 }
429 return IP6_SV_REASS_RC_OK;
430}
431
432always_inline bool
433ip6_sv_reass_verify_upper_layer_present (vlib_node_runtime_t * node,
434 vlib_buffer_t * b,
435 ip6_frag_hdr_t * frag_hdr)
436{
437 ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
438 while (ip6_ext_hdr (tmp->next_hdr))
439 {
440 tmp = ip6_ext_next_header (tmp);
441 }
442 if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
443 {
444 icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
445 ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
446 0);
447 b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
448
449 return false;
450 }
451 return true;
452}
453
454always_inline bool
455ip6_sv_reass_verify_fragment_multiple_8 (vlib_main_t * vm,
456 vlib_node_runtime_t * node,
457 vlib_buffer_t * b,
458 ip6_frag_hdr_t * frag_hdr)
459{
460 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
461 ip6_header_t *ip = vlib_buffer_get_current (b);
462 int more_fragments = ip6_frag_hdr_more (frag_hdr);
463 u32 fragment_length =
464 vlib_buffer_length_in_chain (vm, b) -
465 (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
466 if (more_fragments && 0 != fragment_length % 8)
467 {
468 icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
469 ICMP6_parameter_problem_erroneous_header_field,
470 (u8 *) & ip->payload_length - (u8 *) ip);
471 return false;
472 }
473 return true;
474}
475
476always_inline bool
477ip6_sv_reass_verify_packet_size_lt_64k (vlib_main_t * vm,
478 vlib_node_runtime_t * node,
479 vlib_buffer_t * b,
480 ip6_frag_hdr_t * frag_hdr)
481{
482 vnet_buffer_opaque_t *vnb = vnet_buffer (b);
483 u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
484 u32 fragment_length =
485 vlib_buffer_length_in_chain (vm, b) -
486 (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
487 if (fragment_first + fragment_length > 65535)
488 {
489 ip6_header_t *ip0 = vlib_buffer_get_current (b);
490 icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
491 ICMP6_parameter_problem_erroneous_header_field,
492 (u8 *) & frag_hdr->fragment_offset_and_more
493 - (u8 *) ip0);
494 return false;
495 }
496 return true;
497}
498
499always_inline uword
500ip6_sv_reassembly_inline (vlib_main_t * vm,
501 vlib_node_runtime_t * node,
502 vlib_frame_t * frame, bool is_feature)
503{
504 u32 *from = vlib_frame_vector_args (frame);
505 u32 n_left_from, n_left_to_next, *to_next, next_index;
506 ip6_sv_reass_main_t *rm = &ip6_sv_reass_main;
507 ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[vm->thread_index];
508 clib_spinlock_lock (&rt->lock);
509
510 n_left_from = frame->n_vectors;
511 next_index = node->cached_next_index;
512
513 while (n_left_from > 0)
514 {
515 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
516
517 while (n_left_from > 0 && n_left_to_next > 0)
518 {
519 u32 bi0;
520 vlib_buffer_t *b0;
521 u32 next0 = IP6_SV_REASSEMBLY_NEXT_DROP;
522 u32 error0 = IP6_ERROR_NONE;
523 u32 icmp_bi = ~0;
524
525 bi0 = from[0];
526 b0 = vlib_get_buffer (vm, bi0);
527
528 ip6_header_t *ip0 = vlib_buffer_get_current (b0);
529 ip6_frag_hdr_t *frag_hdr = NULL;
530 ip6_ext_header_t *prev_hdr;
531 if (ip6_ext_hdr (ip0->protocol))
532 {
533 frag_hdr =
534 ip6_ext_header_find (vm, b0, ip0,
535 IP_PROTOCOL_IPV6_FRAGMENTATION,
536 &prev_hdr);
537 }
538 if (!frag_hdr)
539 {
540 // this is a regular packet - no fragmentation
541 vnet_buffer (b0)->ip.reass.ip_proto = ip0->protocol;
542 vnet_buffer (b0)->ip.reass.l4_src_port =
543 ip6_get_port (ip0, 1, b0->current_length);
544 vnet_buffer (b0)->ip.reass.l4_dst_port =
545 ip6_get_port (ip0, 0, b0->current_length);
546 next0 = IP6_SV_REASSEMBLY_NEXT_INPUT;
547 goto packet_enqueue;
548 }
549 if (0 == ip6_frag_hdr_offset (frag_hdr))
550 {
551 // first fragment - verify upper-layer is present
552 if (!ip6_sv_reass_verify_upper_layer_present
553 (node, b0, frag_hdr))
554 {
555 next0 = IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR;
556 goto packet_enqueue;
557 }
558 }
559 if (!ip6_sv_reass_verify_fragment_multiple_8
560 (vm, node, b0, frag_hdr)
561 || !ip6_sv_reass_verify_packet_size_lt_64k (vm, node, b0,
562 frag_hdr))
563 {
564 next0 = IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR;
565 goto packet_enqueue;
566 }
567 vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
568 (u8 *) frag_hdr - (u8 *) ip0;
569
570 ip6_sv_reass_kv_t kv;
571 u8 do_handoff = 0;
572
573 kv.k.as_u64[0] = ip0->src_address.as_u64[0];
574 kv.k.as_u64[1] = ip0->src_address.as_u64[1];
575 kv.k.as_u64[2] = ip0->dst_address.as_u64[0];
576 kv.k.as_u64[3] = ip0->dst_address.as_u64[1];
577 kv.k.as_u64[4] =
578 ((u64) vec_elt (ip6_main.fib_index_by_sw_if_index,
579 vnet_buffer (b0)->sw_if_index[VLIB_RX])) << 32 |
580 (u64) frag_hdr->identification;
581 kv.k.as_u64[5] = ip0->protocol;
582
583 ip6_sv_reass_t *reass =
584 ip6_sv_reass_find_or_create (vm, node, rm, rt, &kv, &icmp_bi,
585 &do_handoff);
586
587 if (PREDICT_FALSE (do_handoff))
588 {
589 next0 = IP6_SV_REASSEMBLY_NEXT_HANDOFF;
590 vnet_buffer (b0)->ip.reass.owner_thread_index =
591 kv.v.thread_index;
Klement Sekera364b20a2019-10-07 09:48:06 +0000592 goto packet_enqueue;
Klement Sekerade34c352019-06-25 11:19:22 +0000593 }
594
595 if (!reass)
596 {
597 next0 = IP6_SV_REASSEMBLY_NEXT_DROP;
598 error0 = IP6_ERROR_REASS_LIMIT_REACHED;
599 goto packet_enqueue;
600 }
601
602 if (reass->is_complete)
603 {
604 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
605 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
606 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
607 next0 = IP6_SV_REASSEMBLY_NEXT_INPUT;
608 error0 = IP6_ERROR_NONE;
609 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
610 {
611 ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
612 REASS_FRAGMENT_FORWARD,
613 reass->ip_proto,
614 reass->l4_src_port,
615 reass->l4_dst_port);
616 }
617 goto packet_enqueue;
618 }
619
620 switch (ip6_sv_reass_update
621 (vm, node, rm, rt, reass, bi0, frag_hdr))
622 {
623 case IP6_SV_REASS_RC_OK:
624 /* nothing to do here */
625 break;
626 case IP6_SV_REASS_RC_TOO_MANY_FRAGMENTS:
627 vlib_node_increment_counter (vm, node->node_index,
628 IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
629 1);
630 ip6_sv_reass_free (vm, rm, rt, reass);
631 goto next_packet;
632 break;
633 case IP6_SV_REASS_RC_UNSUPP_IP_PROTO:
634 vlib_node_increment_counter (vm, node->node_index,
635 IP6_ERROR_REASS_UNSUPP_IP_PROTO,
636 1);
637 ip6_sv_reass_free (vm, rm, rt, reass);
638 goto next_packet;
639 break;
640 case IP6_SV_REASS_RC_INTERNAL_ERROR:
641 vlib_node_increment_counter (vm, node->node_index,
642 IP6_ERROR_REASS_INTERNAL_ERROR, 1);
643 ip6_sv_reass_free (vm, rm, rt, reass);
644 goto next_packet;
645 break;
646 }
647
648 b0->error = node->errors[error0];
649
650 if (reass->is_complete)
651 {
652 u32 idx;
653 vec_foreach_index (idx, reass->cached_buffers)
654 {
655 u32 bi0 = vec_elt (reass->cached_buffers, idx);
656 if (0 == n_left_to_next)
657 {
658 vlib_put_next_frame (vm, node, next_index,
659 n_left_to_next);
660 vlib_get_next_frame (vm, node, next_index, to_next,
661 n_left_to_next);
662 }
663 to_next[0] = bi0;
664 to_next += 1;
665 n_left_to_next -= 1;
666 b0 = vlib_get_buffer (vm, bi0);
667 if (is_feature)
668 {
669 vnet_feature_next (&next0, b0);
670 }
671 vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
672 vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
673 vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
674 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
675 {
676 ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
677 REASS_FRAGMENT_FORWARD,
678 reass->ip_proto,
679 reass->l4_src_port,
680 reass->l4_dst_port);
681 }
682 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
683 to_next, n_left_to_next, bi0,
684 next0);
685 }
686 _vec_len (reass->cached_buffers) = 0; // buffers are owned by frame now
687 }
688 goto next_packet;
689
690 packet_enqueue:
691 to_next[0] = bi0;
692 to_next += 1;
693 n_left_to_next -= 1;
694 if (is_feature && IP6_ERROR_NONE == error0)
695 {
696 b0 = vlib_get_buffer (vm, bi0);
697 vnet_feature_next (&next0, b0);
698 }
699 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
700 n_left_to_next, bi0, next0);
701
702 if (~0 != icmp_bi)
703 {
704 next0 = IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR;
705 to_next[0] = icmp_bi;
706 to_next += 1;
707 n_left_to_next -= 1;
708 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
709 n_left_to_next, icmp_bi,
710 next0);
711 }
712
713 next_packet:
714 from += 1;
715 n_left_from -= 1;
716 }
717
718 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
719 }
720
721 clib_spinlock_unlock (&rt->lock);
722 return frame->n_vectors;
723}
724
725static char *ip6_sv_reassembly_error_strings[] = {
726#define _(sym, string) string,
727 foreach_ip6_error
728#undef _
729};
730
731VLIB_NODE_FN (ip6_sv_reass_node) (vlib_main_t * vm,
732 vlib_node_runtime_t * node,
733 vlib_frame_t * frame)
734{
735 return ip6_sv_reassembly_inline (vm, node, frame, false /* is_feature */ );
736}
737
738/* *INDENT-OFF* */
739VLIB_REGISTER_NODE (ip6_sv_reass_node) = {
740 .name = "ip6-sv-reassembly",
741 .vector_size = sizeof (u32),
742 .format_trace = format_ip6_sv_reass_trace,
743 .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
744 .error_strings = ip6_sv_reassembly_error_strings,
745 .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
746 .next_nodes =
747 {
748 [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
749 [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
750 [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
751 [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reassembly-handoff",
752 },
753};
754/* *INDENT-ON* */
755
756VLIB_NODE_FN (ip6_sv_reass_node_feature) (vlib_main_t * vm,
757 vlib_node_runtime_t * node,
758 vlib_frame_t * frame)
759{
760 return ip6_sv_reassembly_inline (vm, node, frame, true /* is_feature */ );
761}
762
763/* *INDENT-OFF* */
764VLIB_REGISTER_NODE (ip6_sv_reass_node_feature) = {
765 .name = "ip6-sv-reassembly-feature",
766 .vector_size = sizeof (u32),
767 .format_trace = format_ip6_sv_reass_trace,
768 .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
769 .error_strings = ip6_sv_reassembly_error_strings,
770 .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
771 .next_nodes =
772 {
773 [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
774 [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
775 [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
776 [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reass-feature-hoff",
777 },
778};
779/* *INDENT-ON* */
780
781/* *INDENT-OFF* */
782VNET_FEATURE_INIT (ip6_sv_reassembly_feature) = {
783 .arc_name = "ip6-unicast",
784 .node_name = "ip6-sv-reassembly-feature",
785 .runs_before = VNET_FEATURES ("ip6-lookup"),
786 .runs_after = 0,
787};
788/* *INDENT-ON* */
789
790#ifndef CLIB_MARCH_VARIANT
791static u32
792ip6_sv_reass_get_nbuckets ()
793{
794 ip6_sv_reass_main_t *rm = &ip6_sv_reass_main;
795 u32 nbuckets;
796 u8 i;
797
798 nbuckets = (u32) (rm->max_reass_n / IP6_SV_REASS_HT_LOAD_FACTOR);
799
800 for (i = 0; i < 31; i++)
801 if ((1 << i) >= nbuckets)
802 break;
803 nbuckets = 1 << i;
804
805 return nbuckets;
806}
807#endif /* CLIB_MARCH_VARIANT */
808
809typedef enum
810{
811 IP6_EVENT_CONFIG_CHANGED = 1,
812} ip6_sv_reass_event_t;
813
814#ifndef CLIB_MARCH_VARIANT
815typedef struct
816{
817 int failure;
818 clib_bihash_48_8_t *new_hash;
819} ip6_rehash_cb_ctx;
820
821static void
822ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
823{
824 ip6_rehash_cb_ctx *ctx = _ctx;
825 if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1))
826 {
827 ctx->failure = 1;
828 }
829}
830
831static void
832ip6_sv_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
833 u32 max_reassembly_length,
834 u32 expire_walk_interval_ms)
835{
836 ip6_sv_reass_main.timeout_ms = timeout_ms;
837 ip6_sv_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
838 ip6_sv_reass_main.max_reass_n = max_reassemblies;
839 ip6_sv_reass_main.max_reass_len = max_reassembly_length;
840 ip6_sv_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
841}
842
843vnet_api_error_t
844ip6_sv_reass_set (u32 timeout_ms, u32 max_reassemblies,
845 u32 max_reassembly_length, u32 expire_walk_interval_ms)
846{
847 u32 old_nbuckets = ip6_sv_reass_get_nbuckets ();
848 ip6_sv_reass_set_params (timeout_ms, max_reassemblies,
849 max_reassembly_length, expire_walk_interval_ms);
850 vlib_process_signal_event (ip6_sv_reass_main.vlib_main,
851 ip6_sv_reass_main.ip6_sv_reass_expire_node_idx,
852 IP6_EVENT_CONFIG_CHANGED, 0);
853 u32 new_nbuckets = ip6_sv_reass_get_nbuckets ();
854 if (ip6_sv_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
855 {
856 clib_bihash_48_8_t new_hash;
857 clib_memset (&new_hash, 0, sizeof (new_hash));
858 ip6_rehash_cb_ctx ctx;
859 ctx.failure = 0;
860 ctx.new_hash = &new_hash;
861 clib_bihash_init_48_8 (&new_hash, "ip6-sv-reass", new_nbuckets,
862 new_nbuckets * 1024);
863 clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.hash,
864 ip6_rehash_cb, &ctx);
865 if (ctx.failure)
866 {
867 clib_bihash_free_48_8 (&new_hash);
868 return -1;
869 }
870 else
871 {
872 clib_bihash_free_48_8 (&ip6_sv_reass_main.hash);
873 clib_memcpy_fast (&ip6_sv_reass_main.hash, &new_hash,
874 sizeof (ip6_sv_reass_main.hash));
875 clib_bihash_copied (&ip6_sv_reass_main.hash, &new_hash);
876 }
877 }
878 return 0;
879}
880
881vnet_api_error_t
882ip6_sv_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
883 u32 * max_reassembly_length, u32 * expire_walk_interval_ms)
884{
885 *timeout_ms = ip6_sv_reass_main.timeout_ms;
886 *max_reassemblies = ip6_sv_reass_main.max_reass_n;
887 *max_reassembly_length = ip6_sv_reass_main.max_reass_len;
888 *expire_walk_interval_ms = ip6_sv_reass_main.expire_walk_interval_ms;
889 return 0;
890}
891
892static clib_error_t *
893ip6_sv_reass_init_function (vlib_main_t * vm)
894{
895 ip6_sv_reass_main_t *rm = &ip6_sv_reass_main;
896 clib_error_t *error = 0;
897 u32 nbuckets;
898 vlib_node_t *node;
899
900 rm->vlib_main = vm;
901 rm->vnet_main = vnet_get_main ();
902
903 vec_validate (rm->per_thread_data, vlib_num_workers ());
904 ip6_sv_reass_per_thread_t *rt;
905 vec_foreach (rt, rm->per_thread_data)
906 {
907 clib_spinlock_init (&rt->lock);
908 pool_alloc (rt->pool, rm->max_reass_n);
909 rt->lru_first = rt->lru_last = ~0;
910 }
911
912 node = vlib_get_node_by_name (vm, (u8 *) "ip6-sv-reassembly-expire-walk");
913 ASSERT (node);
914 rm->ip6_sv_reass_expire_node_idx = node->index;
915
916 ip6_sv_reass_set_params (IP6_SV_REASS_TIMEOUT_DEFAULT_MS,
917 IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT,
918 IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT,
919 IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
920
921 nbuckets = ip6_sv_reass_get_nbuckets ();
922 clib_bihash_init_48_8 (&rm->hash, "ip6-sv-reass", nbuckets,
923 nbuckets * 1024);
924
925 node = vlib_get_node_by_name (vm, (u8 *) "ip6-drop");
926 ASSERT (node);
927 rm->ip6_drop_idx = node->index;
928 node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error");
929 ASSERT (node);
930 rm->ip6_icmp_error_idx = node->index;
931
932 if ((error = vlib_call_init_function (vm, ip_main_init)))
933 return error;
934 ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
935 ip6_sv_reass_node.index);
936
937 rm->fq_index = vlib_frame_queue_main_init (ip6_sv_reass_node.index, 0);
938 rm->fq_feature_index =
939 vlib_frame_queue_main_init (ip6_sv_reass_node_feature.index, 0);
940
Klement Sekera63c73532019-09-30 14:35:36 +0000941 rm->feature_use_refcount_per_intf = NULL;
942
Klement Sekerade34c352019-06-25 11:19:22 +0000943 return error;
944}
945
946VLIB_INIT_FUNCTION (ip6_sv_reass_init_function);
947#endif /* CLIB_MARCH_VARIANT */
948
949static uword
950ip6_sv_reass_walk_expired (vlib_main_t * vm,
951 vlib_node_runtime_t * node, vlib_frame_t * f)
952{
953 ip6_sv_reass_main_t *rm = &ip6_sv_reass_main;
954 uword event_type, *event_data = 0;
955
956 while (true)
957 {
958 vlib_process_wait_for_event_or_clock (vm,
959 (f64) rm->expire_walk_interval_ms
960 / (f64) MSEC_PER_SEC);
961 event_type = vlib_process_get_events (vm, &event_data);
962
963 switch (event_type)
964 {
965 case ~0: /* no events => timeout */
966 /* nothing to do here */
967 break;
968 case IP6_EVENT_CONFIG_CHANGED:
969 break;
970 default:
971 clib_warning ("BUG: event type 0x%wx", event_type);
972 break;
973 }
974 f64 now = vlib_time_now (vm);
975
976 ip6_sv_reass_t *reass;
977 int *pool_indexes_to_free = NULL;
978
979 uword thread_index = 0;
980 int index;
981 const uword nthreads = vlib_num_workers () + 1;
Klement Sekerade34c352019-06-25 11:19:22 +0000982 for (thread_index = 0; thread_index < nthreads; ++thread_index)
983 {
984 ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
985 clib_spinlock_lock (&rt->lock);
986
987 vec_reset_length (pool_indexes_to_free);
988 /* *INDENT-OFF* */
989 pool_foreach_index (index, rt->pool, ({
990 reass = pool_elt_at_index (rt->pool, index);
991 if (now > reass->last_heard + rm->timeout)
992 {
993 vec_add1 (pool_indexes_to_free, index);
994 }
995 }));
996 /* *INDENT-ON* */
997 int *i;
998 /* *INDENT-OFF* */
999 vec_foreach (i, pool_indexes_to_free)
1000 {
1001 ip6_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1002 ip6_sv_reass_free (vm, rm, rt, reass);
1003 }
1004 /* *INDENT-ON* */
1005
1006 clib_spinlock_unlock (&rt->lock);
1007 }
1008
Klement Sekerade34c352019-06-25 11:19:22 +00001009 vec_free (pool_indexes_to_free);
Klement Sekerade34c352019-06-25 11:19:22 +00001010 if (event_data)
1011 {
1012 _vec_len (event_data) = 0;
1013 }
1014 }
1015
1016 return 0;
1017}
1018
1019/* *INDENT-OFF* */
1020VLIB_REGISTER_NODE (ip6_sv_reass_expire_node) = {
1021 .function = ip6_sv_reass_walk_expired,
1022 .format_trace = format_ip6_sv_reass_trace,
1023 .type = VLIB_NODE_TYPE_PROCESS,
1024 .name = "ip6-sv-reassembly-expire-walk",
1025
1026 .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
1027 .error_strings = ip6_sv_reassembly_error_strings,
1028
1029};
1030/* *INDENT-ON* */
1031
1032static u8 *
1033format_ip6_sv_reass_key (u8 * s, va_list * args)
1034{
1035 ip6_sv_reass_key_t *key = va_arg (*args, ip6_sv_reass_key_t *);
1036 s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1037 key->xx_id, format_ip6_address, &key->src, format_ip6_address,
1038 &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1039 return s;
1040}
1041
1042static u8 *
1043format_ip6_sv_reass (u8 * s, va_list * args)
1044{
1045 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1046 ip6_sv_reass_t *reass = va_arg (*args, ip6_sv_reass_t *);
1047
1048 s = format (s, "ID: %lu, key: %U, trace_op_counter: %u\n",
1049 reass->id, format_ip6_sv_reass_key, &reass->key,
1050 reass->trace_op_counter);
1051 vlib_buffer_t *b;
1052 u32 *bip;
1053 u32 counter = 0;
1054 vec_foreach (bip, reass->cached_buffers)
1055 {
1056 u32 bi = *bip;
1057 do
1058 {
1059 b = vlib_get_buffer (vm, bi);
1060 s = format (s, " #%03u: bi: %u\n", counter, bi);
1061 ++counter;
1062 bi = b->next_buffer;
1063 }
1064 while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
1065 }
1066 return s;
1067}
1068
1069static clib_error_t *
1070show_ip6_sv_reass (vlib_main_t * vm, unformat_input_t * input,
1071 CLIB_UNUSED (vlib_cli_command_t * lmd))
1072{
1073 ip6_sv_reass_main_t *rm = &ip6_sv_reass_main;
1074
1075 vlib_cli_output (vm, "---------------------");
1076 vlib_cli_output (vm, "IP6 reassembly status");
1077 vlib_cli_output (vm, "---------------------");
1078 bool details = false;
1079 if (unformat (input, "details"))
1080 {
1081 details = true;
1082 }
1083
1084 u32 sum_reass_n = 0;
1085 u64 sum_buffers_n = 0;
1086 ip6_sv_reass_t *reass;
1087 uword thread_index;
1088 const uword nthreads = vlib_num_workers () + 1;
1089 for (thread_index = 0; thread_index < nthreads; ++thread_index)
1090 {
1091 ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1092 clib_spinlock_lock (&rt->lock);
1093 if (details)
1094 {
1095 /* *INDENT-OFF* */
1096 pool_foreach (reass, rt->pool, {
1097 vlib_cli_output (vm, "%U", format_ip6_sv_reass, vm, reass);
1098 });
1099 /* *INDENT-ON* */
1100 }
1101 sum_reass_n += rt->reass_n;
1102 clib_spinlock_unlock (&rt->lock);
1103 }
1104 vlib_cli_output (vm, "---------------------");
1105 vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1106 (long unsigned) sum_reass_n);
1107 vlib_cli_output (vm, "Maximum configured concurrent IP6 reassemblies per "
1108 "worker-thread: %lu\n", (long unsigned) rm->max_reass_n);
1109 vlib_cli_output (vm, "Buffers in use: %lu\n",
1110 (long unsigned) sum_buffers_n);
1111 return 0;
1112}
1113
1114/* *INDENT-OFF* */
1115VLIB_CLI_COMMAND (show_ip6_sv_reassembly_cmd, static) = {
1116 .path = "show ip6-sv-reassembly",
1117 .short_help = "show ip6-sv-reassembly [details]",
1118 .function = show_ip6_sv_reass,
1119};
1120/* *INDENT-ON* */
1121
1122#ifndef CLIB_MARCH_VARIANT
1123vnet_api_error_t
1124ip6_sv_reass_enable_disable (u32 sw_if_index, u8 enable_disable)
1125{
1126 return vnet_feature_enable_disable ("ip6-unicast",
1127 "ip6-sv-reassembly-feature",
1128 sw_if_index, enable_disable, 0, 0);
1129}
1130#endif /* CLIB_MARCH_VARIANT */
1131
1132#define foreach_ip6_sv_reassembly_handoff_error \
1133_(CONGESTION_DROP, "congestion drop")
1134
1135
1136typedef enum
1137{
1138#define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym,
1139 foreach_ip6_sv_reassembly_handoff_error
1140#undef _
1141 IP6_SV_REASSEMBLY_HANDOFF_N_ERROR,
1142} ip6_sv_reassembly_handoff_error_t;
1143
1144static char *ip6_sv_reassembly_handoff_error_strings[] = {
1145#define _(sym,string) string,
1146 foreach_ip6_sv_reassembly_handoff_error
1147#undef _
1148};
1149
1150typedef struct
1151{
1152 u32 next_worker_index;
1153} ip6_sv_reassembly_handoff_trace_t;
1154
1155static u8 *
1156format_ip6_sv_reassembly_handoff_trace (u8 * s, va_list * args)
1157{
1158 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1159 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1160 ip6_sv_reassembly_handoff_trace_t *t =
1161 va_arg (*args, ip6_sv_reassembly_handoff_trace_t *);
1162
1163 s =
1164 format (s, "ip6-sv-reassembly-handoff: next-worker %d",
1165 t->next_worker_index);
1166
1167 return s;
1168}
1169
1170always_inline uword
1171ip6_sv_reassembly_handoff_inline (vlib_main_t * vm,
1172 vlib_node_runtime_t * node,
1173 vlib_frame_t * frame, bool is_feature)
1174{
1175 ip6_sv_reass_main_t *rm = &ip6_sv_reass_main;
1176
1177 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1178 u32 n_enq, n_left_from, *from;
1179 u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1180 u32 fq_index;
1181
1182 from = vlib_frame_vector_args (frame);
1183 n_left_from = frame->n_vectors;
1184 vlib_get_buffers (vm, from, bufs, n_left_from);
1185
1186 b = bufs;
1187 ti = thread_indices;
1188
1189 fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1190
1191 while (n_left_from > 0)
1192 {
1193 ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1194
1195 if (PREDICT_FALSE
1196 ((node->flags & VLIB_NODE_FLAG_TRACE)
1197 && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1198 {
1199 ip6_sv_reassembly_handoff_trace_t *t =
1200 vlib_add_trace (vm, node, b[0], sizeof (*t));
1201 t->next_worker_index = ti[0];
1202 }
1203
1204 n_left_from -= 1;
1205 ti += 1;
1206 b += 1;
1207 }
1208 n_enq =
1209 vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices,
1210 frame->n_vectors, 1);
1211
1212 if (n_enq < frame->n_vectors)
1213 vlib_node_increment_counter (vm, node->node_index,
1214 IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1215 frame->n_vectors - n_enq);
1216 return frame->n_vectors;
1217}
1218
1219VLIB_NODE_FN (ip6_sv_reassembly_handoff_node) (vlib_main_t * vm,
1220 vlib_node_runtime_t * node,
1221 vlib_frame_t * frame)
1222{
1223 return ip6_sv_reassembly_handoff_inline (vm, node, frame,
1224 false /* is_feature */ );
1225}
1226
1227/* *INDENT-OFF* */
1228VLIB_REGISTER_NODE (ip6_sv_reassembly_handoff_node) = {
1229 .name = "ip6-sv-reassembly-handoff",
1230 .vector_size = sizeof (u32),
1231 .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1232 .error_strings = ip6_sv_reassembly_handoff_error_strings,
1233 .format_trace = format_ip6_sv_reassembly_handoff_trace,
1234
1235 .n_next_nodes = 1,
1236
1237 .next_nodes = {
1238 [0] = "error-drop",
1239 },
1240};
1241
1242
1243VLIB_NODE_FN (ip6_sv_reassembly_feature_handoff_node) (vlib_main_t * vm,
1244 vlib_node_runtime_t * node, vlib_frame_t * frame)
1245{
1246 return ip6_sv_reassembly_handoff_inline (vm, node, frame, true /* is_feature */ );
1247}
1248
1249
1250/* *INDENT-OFF* */
1251VLIB_REGISTER_NODE (ip6_sv_reassembly_feature_handoff_node) = {
1252 .name = "ip6-sv-reass-feature-hoff",
1253 .vector_size = sizeof (u32),
1254 .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1255 .error_strings = ip6_sv_reassembly_handoff_error_strings,
1256 .format_trace = format_ip6_sv_reassembly_handoff_trace,
1257
1258 .n_next_nodes = 1,
1259
1260 .next_nodes = {
1261 [0] = "error-drop",
1262 },
1263};
1264/* *INDENT-ON* */
1265
1266#ifndef CLIB_MARCH_VARIANT
1267int
1268ip6_sv_reass_enable_disable_with_refcnt (u32 sw_if_index, int is_enable)
1269{
1270 ip6_sv_reass_main_t *rm = &ip6_sv_reass_main;
Klement Sekera63c73532019-09-30 14:35:36 +00001271 vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
Klement Sekerade34c352019-06-25 11:19:22 +00001272 if (is_enable)
1273 {
Klement Sekera63c73532019-09-30 14:35:36 +00001274 if (!rm->feature_use_refcount_per_intf[sw_if_index])
Klement Sekerade34c352019-06-25 11:19:22 +00001275 {
Klement Sekera63c73532019-09-30 14:35:36 +00001276 ++rm->feature_use_refcount_per_intf[sw_if_index];
Klement Sekerade34c352019-06-25 11:19:22 +00001277 return vnet_feature_enable_disable ("ip6-unicast",
1278 "ip6-sv-reassembly-feature",
1279 sw_if_index, 1, 0, 0);
1280 }
Klement Sekera63c73532019-09-30 14:35:36 +00001281 ++rm->feature_use_refcount_per_intf[sw_if_index];
Klement Sekerade34c352019-06-25 11:19:22 +00001282 }
1283 else
1284 {
Klement Sekera63c73532019-09-30 14:35:36 +00001285 --rm->feature_use_refcount_per_intf[sw_if_index];
1286 if (!rm->feature_use_refcount_per_intf[sw_if_index])
Klement Sekerade34c352019-06-25 11:19:22 +00001287 return vnet_feature_enable_disable ("ip6-unicast",
1288 "ip6-sv-reassembly-feature",
1289 sw_if_index, 0, 0, 0);
1290 }
1291 return -1;
1292}
1293#endif
1294
1295/*
1296 * fd.io coding-style-patch-verification: ON
1297 *
1298 * Local Variables:
1299 * eval: (c-set-style "gnu")
1300 * End:
1301 */