FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ip6_full_reass.c
Go to the documentation of this file.
1 /*
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 Full Reassembly.
19  *
20  * This file contains the source code for IPv6 full reassembly.
21  */
22 
23 #include <vppinfra/vec.h>
24 #include <vnet/vnet.h>
25 #include <vnet/ip/ip.h>
26 #include <vppinfra/bihash_48_8.h>
28 
29 #define MSEC_PER_SEC 1000
30 #define IP6_FULL_REASS_TIMEOUT_DEFAULT_MS 100
31 #define IP6_FULL_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
32 #define IP6_FULL_REASS_MAX_REASSEMBLIES_DEFAULT 1024
33 #define IP6_FULL_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3
34 #define IP6_FULL_REASS_HT_LOAD_FACTOR (0.75)
35 
36 typedef enum
37 {
44 
45 typedef struct
46 {
47  union
48  {
49  struct
50  {
51  ip6_address_t src;
52  ip6_address_t dst;
55  u8 unused[7];
57  };
58  u64 as_u64[6];
59  };
61 
62 typedef union
63 {
64  struct
65  {
68  };
71 
72 typedef union
73 {
74  struct
75  {
78  };
81 
82 
85 {
87  return vnb->ip.reass.range_first - vnb->ip.reass.fragment_first;
88 }
89 
92 {
94  return clib_min (vnb->ip.reass.range_last, vnb->ip.reass.fragment_last) -
95  (vnb->ip.reass.fragment_first +
97 }
98 
99 typedef struct
100 {
101  // hash table key
103  // time when last packet was received
105  // internal id of this reassembly
107  // buffer index of first buffer in this reassembly context
109  // last octet of packet, ~0 until fragment without more_fragments arrives
111  // length of data collected so far
113  // trace operation counter
115  // next index - used by custom apps (~0 if not set)
117  // error next index - used by custom apps (~0 if not set)
119  // minimum fragment length for this reassembly - used to estimate MTU
121  // number of fragments for this reassembly
123  // thread owning memory for this context (whose pool contains this ctx)
125  // thread which received fragment with offset 0 and which sends out the
126  // completed reassembly
129 
130 typedef struct
131 {
137 
138 typedef struct
139 {
140  // IPv6 config
144  // maximum number of fragments in one reassembly
146  // maximum number of reassemblies
148 
149  // IPv6 runtime
150  clib_bihash_48_8_t hash;
151 
152  // per-thread data
154 
155  // convenience
157 
158  // node index of ip6-drop node
162 
163  /** Worker handoff */
166 
167  // reference count for enabling/disabling feature - per interface
170 
172 
173 #ifndef CLIB_MARCH_VARIANT
175 #endif /* CLIB_MARCH_VARIANT */
176 
177 typedef enum
178 {
185 
186 typedef enum
187 {
196 
197 typedef struct
198 {
206 
207 typedef struct
208 {
220  ip6_frag_hdr_t ip6_frag_header;
222 
223 static void
226 {
229  trace->range_first = vnb->ip.reass.range_first;
230  trace->range_last = vnb->ip.reass.range_last;
233  trace->range_bi = bi;
234 }
235 
236 static u8 *
238 {
240  va_arg (*args, ip6_full_reass_range_trace_t *);
241  s =
242  format (s, "range: [%u, %u], off %d, len %u, bi %u", trace->range_first,
243  trace->range_last, trace->data_offset, trace->data_len,
244  trace->range_bi);
245  return s;
246 }
247 
248 static u8 *
249 format_ip6_full_reass_trace (u8 * s, va_list * args)
250 {
251  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
252  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
253  ip6_full_reass_trace_t *t = va_arg (*args, ip6_full_reass_trace_t *);
254  u32 indent = 0;
255  if (~0 != t->reass_id)
256  {
257  if (t->is_after_handoff)
258  {
259  s =
260  format (s, "%U\n", format_ip6_header, &t->ip6_header,
261  sizeof (t->ip6_header));
262  s =
263  format (s, " %U\n", format_ip6_frag_hdr, &t->ip6_frag_header,
264  sizeof (t->ip6_frag_header));
265  indent = 2;
266  }
267  s =
268  format (s, "%Ureass id: %u, op id: %u, ", format_white_space, indent,
269  t->reass_id, t->op_id);
270  indent = format_get_indent (s);
271  s = format (s, "first bi: %u, data len: %u, ip/fragment[%u, %u]",
274  }
275  switch (t->action)
276  {
277  case RANGE_NEW:
278  s = format (s, "\n%Unew %U", format_white_space, indent,
280  break;
281  case RANGE_OVERLAP:
282  s = format (s, "\n%Uoverlap %U", format_white_space, indent,
284  break;
286  s = format (s, "\n%Uicmp-error - frag_len > 65535 %U",
287  format_white_space, indent,
289  break;
291  s = format (s, "\n%Uicmp-error - frag_len mod 8 != 0 %U",
292  format_white_space, indent,
294  break;
296  s = format (s, "\n%Uicmp-error - reassembly time exceeded",
297  format_white_space, indent);
298  break;
299  case FINALIZE:
300  s = format (s, "\n%Ufinalize reassembly", format_white_space, indent);
301  break;
302  case HANDOFF:
303  s =
304  format (s, "handoff from thread #%u to thread #%u", t->thread_id,
305  t->thread_id_to);
306  break;
307  }
308  return s;
309 }
310 
311 static void
313  ip6_full_reass_t * reass, u32 bi,
314  ip6_frag_hdr_t * ip6_frag_header,
316  u32 thread_id_to)
317 {
320  bool is_after_handoff = false;
323  {
324  // this buffer's trace is gone
325  b->flags &= ~VLIB_BUFFER_IS_TRACED;
326  return;
327  }
329  {
330  is_after_handoff = true;
331  }
332  ip6_full_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
333  t->is_after_handoff = is_after_handoff;
334  if (t->is_after_handoff)
335  {
337  clib_min (sizeof (t->ip6_header), b->current_length));
338  if (ip6_frag_header)
339  {
340  clib_memcpy (&t->ip6_frag_header, ip6_frag_header,
341  sizeof (t->ip6_frag_header));
342  }
343  else
344  {
345  clib_memset (&t->ip6_frag_header, 0, sizeof (t->ip6_frag_header));
346  }
347  }
348  if (reass)
349  {
350  t->reass_id = reass->id;
351  t->op_id = reass->trace_op_counter;
352  t->trace_range.first_bi = reass->first_bi;
353  t->total_data_len = reass->data_len;
354  ++reass->trace_op_counter;
355  }
356  else
357  {
358  t->reass_id = ~0;
359  }
360  t->action = action;
361  t->thread_id = vm->thread_index;
362  t->thread_id_to = thread_id_to;
364  t->fragment_first = vnb->ip.reass.fragment_first;
365  t->fragment_last = vnb->ip.reass.fragment_last;
366 #if 0
367  static u8 *s = NULL;
368  s = format (s, "%U", format_ip6_full_reass_trace, NULL, NULL, t);
369  printf ("%.*s\n", vec_len (s), s);
370  fflush (stdout);
371  vec_reset_length (s);
372 #endif
373 }
374 
375 always_inline void
377  ip6_full_reass_t * reass)
378 {
379  pool_put (rt->pool, reass);
380  --rt->reass_n;
381 }
382 
383 always_inline void
386  ip6_full_reass_t * reass)
387 {
389  kv.key[0] = reass->key.as_u64[0];
390  kv.key[1] = reass->key.as_u64[1];
391  kv.key[2] = reass->key.as_u64[2];
392  kv.key[3] = reass->key.as_u64[3];
393  kv.key[4] = reass->key.as_u64[4];
394  kv.key[5] = reass->key.as_u64[5];
395  clib_bihash_add_del_48_8 (&rm->hash, &kv, 0);
396  ip6_full_reass_free_ctx (rt, reass);
397 }
398 
399 always_inline void
401  ip6_full_reass_t *reass)
402 {
403  u32 range_bi = reass->first_bi;
404  vlib_buffer_t *range_b;
405  vnet_buffer_opaque_t *range_vnb;
406  u32 *to_free = NULL;
407  while (~0 != range_bi)
408  {
409  range_b = vlib_get_buffer (vm, range_bi);
410  range_vnb = vnet_buffer (range_b);
411  u32 bi = range_bi;
412  while (~0 != bi)
413  {
414  vec_add1 (to_free, bi);
416  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
417  {
418  bi = b->next_buffer;
419  b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
420  }
421  else
422  {
423  bi = ~0;
424  }
425  }
426  range_bi = range_vnb->ip.reass.next_range_bi;
427  }
428  /* send to next_error_index */
429  if (~0 != reass->error_next_index)
430  {
431  u32 n_left_to_next, *to_next, next_index;
432 
433  next_index = reass->error_next_index;
434  u32 bi = ~0;
435 
436  while (vec_len (to_free) > 0)
437  {
438  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
439 
440  while (vec_len (to_free) > 0 && n_left_to_next > 0)
441  {
442  bi = vec_pop (to_free);
443 
444  if (~0 != bi)
445  {
446  to_next[0] = bi;
447  to_next += 1;
448  n_left_to_next -= 1;
449  }
450  }
451  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
452  }
453  }
454  else
455  {
456  vlib_buffer_free (vm, to_free, vec_len (to_free));
457  }
458  vec_free (to_free);
459 }
460 
461 always_inline void
463  ip6_full_reass_t * reass, u32 * icmp_bi)
464 {
465  if (~0 == reass->first_bi)
466  {
467  return;
468  }
469  if (~0 == reass->next_index) // custom apps don't want icmp
470  {
472  if (0 == vnet_buffer (b)->ip.reass.fragment_first)
473  {
474  *icmp_bi = reass->first_bi;
475  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
476  {
477  ip6_full_reass_add_trace (vm, node, reass, reass->first_bi, NULL,
479  }
480  // fragment with offset zero received - send icmp message back
481  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
482  {
483  // separate first buffer from chain and steer it towards icmp node
484  b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
485  reass->first_bi = b->next_buffer;
486  }
487  else
488  {
489  reass->first_bi = vnet_buffer (b)->ip.reass.next_range_bi;
490  }
491  icmp6_error_set_vnet_buffer (b, ICMP6_time_exceeded,
492  ICMP6_time_exceeded_fragment_reassembly_time_exceeded,
493  0);
494  }
495  }
496  ip6_full_reass_drop_all (vm, node, reass);
497 }
498 
503  ip6_full_reass_kv_t * kv, u32 * icmp_bi,
504  u8 * do_handoff)
505 {
506  ip6_full_reass_t *reass;
507  f64 now;
508 
509 again:
510 
511  reass = NULL;
512  now = vlib_time_now (vm);
513 
514  if (!clib_bihash_search_48_8 (&rm->hash, &kv->kv, &kv->kv))
515  {
517  {
518  *do_handoff = 1;
519  return NULL;
520  }
521 
522  reass =
525  kv->v.reass_index);
526 
527  if (now > reass->last_heard + rm->timeout)
528  {
529  ip6_full_reass_on_timeout (vm, node, reass, icmp_bi);
530  ip6_full_reass_free (rm, rt, reass);
531  reass = NULL;
532  }
533  }
534 
535  if (reass)
536  {
537  reass->last_heard = now;
538  return reass;
539  }
540 
541  if (rt->reass_n >= rm->max_reass_n)
542  {
543  reass = NULL;
544  return reass;
545  }
546  else
547  {
548  pool_get (rt->pool, reass);
549  clib_memset (reass, 0, sizeof (*reass));
550  reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
551  ++rt->id_counter;
552  reass->first_bi = ~0;
553  reass->last_packet_octet = ~0;
554  reass->data_len = 0;
555  reass->next_index = ~0;
556  reass->error_next_index = ~0;
557  ++rt->reass_n;
558  }
559 
560  reass->key.as_u64[0] = kv->kv.key[0];
561  reass->key.as_u64[1] = kv->kv.key[1];
562  reass->key.as_u64[2] = kv->kv.key[2];
563  reass->key.as_u64[3] = kv->kv.key[3];
564  reass->key.as_u64[4] = kv->kv.key[4];
565  reass->key.as_u64[5] = kv->kv.key[5];
566  kv->v.reass_index = (reass - rt->pool);
568  reass->last_heard = now;
569 
570  int rv = clib_bihash_add_del_48_8 (&rm->hash, &kv->kv, 2);
571  if (rv)
572  {
573  ip6_full_reass_free (rm, rt, reass);
574  reass = NULL;
575  // if other worker created a context already work with the other copy
576  if (-2 == rv)
577  goto again;
578  }
579 
580  return reass;
581 }
582 
587  ip6_full_reass_t * reass, u32 * bi0, u32 * next0,
588  u32 * error0, bool is_custom_app)
589 {
590  *bi0 = reass->first_bi;
591  *error0 = IP6_ERROR_NONE;
592  ip6_frag_hdr_t *frag_hdr;
593  vlib_buffer_t *last_b = NULL;
594  u32 sub_chain_bi = reass->first_bi;
595  u32 total_length = 0;
596  u32 buf_cnt = 0;
597  u32 dropped_cnt = 0;
598  u32 *vec_drop_compress = NULL;
600  do
601  {
602  u32 tmp_bi = sub_chain_bi;
603  vlib_buffer_t *tmp = vlib_get_buffer (vm, tmp_bi);
605  if (!(vnb->ip.reass.range_first >= vnb->ip.reass.fragment_first) &&
606  !(vnb->ip.reass.range_last > vnb->ip.reass.fragment_first))
607  {
609  goto free_buffers_and_return;
610  }
611 
613  u32 trim_front = vnet_buffer (tmp)->ip.reass.ip6_frag_hdr_offset +
614  sizeof (*frag_hdr) + ip6_full_reass_buffer_get_data_offset (tmp);
615  u32 trim_end =
616  vlib_buffer_length_in_chain (vm, tmp) - trim_front - data_len;
617  if (tmp_bi == reass->first_bi)
618  {
619  /* first buffer - keep ip6 header */
621  {
623  goto free_buffers_and_return;
624  }
625  trim_front = 0;
626  trim_end = vlib_buffer_length_in_chain (vm, tmp) - data_len -
627  (vnet_buffer (tmp)->ip.reass.ip6_frag_hdr_offset +
628  sizeof (*frag_hdr));
629  if (!(vlib_buffer_length_in_chain (vm, tmp) - trim_end > 0))
630  {
632  goto free_buffers_and_return;
633  }
634  }
635  u32 keep_data =
636  vlib_buffer_length_in_chain (vm, tmp) - trim_front - trim_end;
637  while (1)
638  {
639  ++buf_cnt;
640  if (trim_front)
641  {
642  if (trim_front > tmp->current_length)
643  {
644  /* drop whole buffer */
645  vec_add1 (vec_drop_compress, tmp_bi);
646  trim_front -= tmp->current_length;
647  if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT))
648  {
650  goto free_buffers_and_return;
651  }
652  tmp->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
653  tmp_bi = tmp->next_buffer;
654  tmp = vlib_get_buffer (vm, tmp_bi);
655  continue;
656  }
657  else
658  {
659  vlib_buffer_advance (tmp, trim_front);
660  trim_front = 0;
661  }
662  }
663  if (keep_data)
664  {
665  if (last_b)
666  {
667  last_b->flags |= VLIB_BUFFER_NEXT_PRESENT;
668  last_b->next_buffer = tmp_bi;
669  }
670  last_b = tmp;
671  if (keep_data <= tmp->current_length)
672  {
673  tmp->current_length = keep_data;
674  keep_data = 0;
675  }
676  else
677  {
678  keep_data -= tmp->current_length;
679  if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT))
680  {
682  goto free_buffers_and_return;
683  }
684  }
685  total_length += tmp->current_length;
686  }
687  else
688  {
689  vec_add1 (vec_drop_compress, tmp_bi);
690  if (reass->first_bi == tmp_bi)
691  {
693  goto free_buffers_and_return;
694  }
695  ++dropped_cnt;
696  }
697  if (tmp->flags & VLIB_BUFFER_NEXT_PRESENT)
698  {
699  tmp_bi = tmp->next_buffer;
700  tmp = vlib_get_buffer (vm, tmp->next_buffer);
701  }
702  else
703  {
704  break;
705  }
706  }
707  sub_chain_bi =
708  vnet_buffer (vlib_get_buffer (vm, sub_chain_bi))->ip.
709  reass.next_range_bi;
710  }
711  while (~0 != sub_chain_bi);
712 
713  if (!last_b)
714  {
716  goto free_buffers_and_return;
717  }
718  last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
719  vlib_buffer_t *first_b = vlib_get_buffer (vm, reass->first_bi);
720  if (total_length < first_b->current_length)
721  {
723  goto free_buffers_and_return;
724  }
725  total_length -= first_b->current_length;
726  first_b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
727  first_b->total_length_not_including_first_buffer = total_length;
728  // drop fragment header
729  vnet_buffer_opaque_t *first_b_vnb = vnet_buffer (first_b);
731  u16 ip6_frag_hdr_offset = first_b_vnb->ip.reass.ip6_frag_hdr_offset;
732  ip6_ext_header_t *prev_hdr;
733  frag_hdr =
734  ip6_ext_header_find (vm, first_b, ip, IP_PROTOCOL_IPV6_FRAGMENTATION,
735  &prev_hdr);
736  if (prev_hdr)
737  {
738  prev_hdr->next_hdr = frag_hdr->next_hdr;
739  }
740  else
741  {
742  ip->protocol = frag_hdr->next_hdr;
743  }
744  if (!((u8 *) frag_hdr - (u8 *) ip == ip6_frag_hdr_offset))
745  {
747  goto free_buffers_and_return;
748  }
749  memmove (frag_hdr, (u8 *) frag_hdr + sizeof (*frag_hdr),
751  sizeof (ip6_frag_hdr_t));
752  first_b->current_length -= sizeof (*frag_hdr);
753  ip->payload_length =
754  clib_host_to_net_u16 (total_length + first_b->current_length -
755  sizeof (*ip));
756  if (!vlib_buffer_chain_linearize (vm, first_b))
757  {
759  goto free_buffers_and_return;
760  }
761  first_b->flags &= ~VLIB_BUFFER_EXT_HDR_VALID;
762  if (PREDICT_FALSE (first_b->flags & VLIB_BUFFER_IS_TRACED))
763  {
764  ip6_full_reass_add_trace (vm, node, reass, reass->first_bi, NULL,
765  FINALIZE, ~0);
766 #if 0
767  // following code does a hexdump of packet fragments to stdout ...
768  do
769  {
770  u32 bi = reass->first_bi;
771  u8 *s = NULL;
772  while (~0 != bi)
773  {
775  s = format (s, "%u: %U\n", bi, format_hexdump,
777  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
778  {
779  bi = b->next_buffer;
780  }
781  else
782  {
783  break;
784  }
785  }
786  printf ("%.*s\n", vec_len (s), s);
787  fflush (stdout);
788  vec_free (s);
789  }
790  while (0);
791 #endif
792  }
793  if (!is_custom_app)
794  {
796  }
797  else
798  {
799  *next0 = reass->next_index;
800  }
801  vnet_buffer (first_b)->ip.reass.estimated_mtu = reass->min_fragment_length;
802  ip6_full_reass_free (rm, rt, reass);
803  reass = NULL;
804 free_buffers_and_return:
805  vlib_buffer_free (vm, vec_drop_compress, vec_len (vec_drop_compress));
806  vec_free (vec_drop_compress);
807  return rv;
808 }
809 
810 always_inline void
812  ip6_full_reass_t * reass,
813  u32 prev_range_bi, u32 new_next_bi)
814 {
815 
816  vlib_buffer_t *new_next_b = vlib_get_buffer (vm, new_next_bi);
817  vnet_buffer_opaque_t *new_next_vnb = vnet_buffer (new_next_b);
818  if (~0 != prev_range_bi)
819  {
820  vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_range_bi);
821  vnet_buffer_opaque_t *prev_vnb = vnet_buffer (prev_b);
822  new_next_vnb->ip.reass.next_range_bi = prev_vnb->ip.reass.next_range_bi;
823  prev_vnb->ip.reass.next_range_bi = new_next_bi;
824  }
825  else
826  {
827  if (~0 != reass->first_bi)
828  {
829  new_next_vnb->ip.reass.next_range_bi = reass->first_bi;
830  }
831  reass->first_bi = new_next_bi;
832  }
833  reass->data_len += ip6_full_reass_buffer_get_data_len (new_next_b);
834 }
835 
840  ip6_full_reass_t * reass, u32 * bi0, u32 * next0,
841  u32 * error0, ip6_frag_hdr_t * frag_hdr,
842  bool is_custom_app, u32 * handoff_thread_idx)
843 {
844  int consumed = 0;
845  vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0);
846  vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
847  if (is_custom_app)
848  {
849  reass->next_index = fvnb->ip.reass.next_index; // store next_index before it's overwritten
850  reass->error_next_index = fvnb->ip.reass.error_next_index; // store error_next_index before it is overwritten
851  }
852 
853  fvnb->ip.reass.ip6_frag_hdr_offset =
854  (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb);
856  if (fb->current_length < sizeof (*fip) ||
857  fvnb->ip.reass.ip6_frag_hdr_offset == 0 ||
858  fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length)
859  {
861  }
862 
863  u32 fragment_first = fvnb->ip.reass.fragment_first =
864  ip6_frag_hdr_offset_bytes (frag_hdr);
865  u32 fragment_length =
867  (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
868  u32 fragment_last = fvnb->ip.reass.fragment_last =
869  fragment_first + fragment_length - 1;
870  int more_fragments = ip6_frag_hdr_more (frag_hdr);
871  u32 candidate_range_bi = reass->first_bi;
872  u32 prev_range_bi = ~0;
873  fvnb->ip.reass.range_first = fragment_first;
874  fvnb->ip.reass.range_last = fragment_last;
875  fvnb->ip.reass.next_range_bi = ~0;
876  if (!more_fragments)
877  {
878  reass->last_packet_octet = fragment_last;
879  }
880  if (~0 == reass->first_bi)
881  {
882  // starting a new reassembly
883  ip6_full_reass_insert_range_in_chain (vm, reass, prev_range_bi, *bi0);
884  reass->min_fragment_length = clib_net_to_host_u16 (fip->payload_length);
885  consumed = 1;
886  reass->fragments_n = 1;
887  goto check_if_done_maybe;
888  }
889  reass->min_fragment_length =
890  clib_min (clib_net_to_host_u16 (fip->payload_length),
891  fvnb->ip.reass.estimated_mtu);
892  while (~0 != candidate_range_bi)
893  {
894  vlib_buffer_t *candidate_b = vlib_get_buffer (vm, candidate_range_bi);
895  vnet_buffer_opaque_t *candidate_vnb = vnet_buffer (candidate_b);
896  if (fragment_first > candidate_vnb->ip.reass.range_last)
897  {
898  // this fragments starts after candidate range
899  prev_range_bi = candidate_range_bi;
900  candidate_range_bi = candidate_vnb->ip.reass.next_range_bi;
901  if (candidate_vnb->ip.reass.range_last < fragment_last &&
902  ~0 == candidate_range_bi)
903  {
904  // special case - this fragment falls beyond all known ranges
905  ip6_full_reass_insert_range_in_chain (vm, reass, prev_range_bi,
906  *bi0);
907  consumed = 1;
908  break;
909  }
910  continue;
911  }
912  if (fragment_last < candidate_vnb->ip.reass.range_first)
913  {
914  // this fragment ends before candidate range without any overlap
915  ip6_full_reass_insert_range_in_chain (vm, reass, prev_range_bi,
916  *bi0);
917  consumed = 1;
918  }
919  else if (fragment_first == candidate_vnb->ip.reass.range_first &&
920  fragment_last == candidate_vnb->ip.reass.range_last)
921  {
922  // duplicate fragment - ignore
923  }
924  else
925  {
926  // overlapping fragment - not allowed by RFC 8200
927  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
928  {
929  ip6_full_reass_add_trace (vm, node, reass, *bi0, frag_hdr,
930  RANGE_OVERLAP, ~0);
931  }
932  ip6_full_reass_drop_all (vm, node, reass);
933  ip6_full_reass_free (rm, rt, reass);
935  *error0 = IP6_ERROR_REASS_OVERLAPPING_FRAGMENT;
936  return IP6_FULL_REASS_RC_OK;
937  }
938  break;
939  }
940  ++reass->fragments_n;
941 check_if_done_maybe:
942  if (consumed)
943  {
944  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
945  {
946  ip6_full_reass_add_trace (vm, node, reass, *bi0, frag_hdr, RANGE_NEW,
947  ~0);
948  }
949  }
950  if (~0 != reass->last_packet_octet &&
951  reass->data_len == reass->last_packet_octet + 1)
952  {
953  *handoff_thread_idx = reass->sendout_thread_index;
954  int handoff =
957  ip6_full_reass_finalize (vm, node, rm, rt, reass, bi0, next0, error0,
958  is_custom_app);
959  if (IP6_FULL_REASS_RC_OK == rc && handoff)
960  {
962  }
963  return rc;
964  }
965  else
966  {
967  if (consumed)
968  {
969  *bi0 = ~0;
970  if (reass->fragments_n > rm->max_reass_len)
971  {
973  }
974  }
975  else
976  {
978  *error0 = IP6_ERROR_REASS_DUPLICATE_FRAGMENT;
979  }
980  }
981  return IP6_FULL_REASS_RC_OK;
982 }
983 
984 always_inline bool
986  vlib_buffer_t * b,
987  ip6_frag_hdr_t * frag_hdr)
988 {
989  ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
990  while (ip6_ext_hdr (tmp->next_hdr))
991  {
993  }
994  if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
995  {
996  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
997  ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
998  0);
999  b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
1000 
1001  return false;
1002  }
1003  return true;
1004 }
1005 
1006 always_inline bool
1008  vlib_buffer_t * b,
1009  ip6_frag_hdr_t * frag_hdr)
1010 {
1013  int more_fragments = ip6_frag_hdr_more (frag_hdr);
1014  u32 fragment_length =
1016  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
1017  if (more_fragments && 0 != fragment_length % 8)
1018  {
1019  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
1020  ICMP6_parameter_problem_erroneous_header_field,
1021  (u8 *) & ip->payload_length - (u8 *) ip);
1022  return false;
1023  }
1024  return true;
1025 }
1026 
1027 always_inline bool
1029  vlib_buffer_t * b,
1030  ip6_frag_hdr_t * frag_hdr)
1031 {
1033  u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
1034  u32 fragment_length =
1036  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
1037  if (fragment_first + fragment_length > 65535)
1038  {
1040  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
1041  ICMP6_parameter_problem_erroneous_header_field,
1042  (u8 *) & frag_hdr->fragment_offset_and_more
1043  - (u8 *) ip0);
1044  return false;
1045  }
1046  return true;
1047 }
1048 
1052  vlib_frame_t * frame, bool is_feature,
1053  bool is_custom_app)
1054 {
1056  u32 n_left_from, n_left_to_next, *to_next, next_index;
1059  clib_spinlock_lock (&rt->lock);
1060 
1061  n_left_from = frame->n_vectors;
1062  next_index = node->cached_next_index;
1063  while (n_left_from > 0)
1064  {
1065  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1066 
1067  while (n_left_from > 0 && n_left_to_next > 0)
1068  {
1069  u32 bi0;
1070  vlib_buffer_t *b0;
1072  u32 error0 = IP6_ERROR_NONE;
1073  u32 icmp_bi = ~0;
1074 
1075  bi0 = from[0];
1076  b0 = vlib_get_buffer (vm, bi0);
1077 
1079  ip6_frag_hdr_t *frag_hdr = NULL;
1080  ip6_ext_header_t *prev_hdr;
1081  if (ip6_ext_hdr (ip0->protocol))
1082  {
1083  frag_hdr =
1084  ip6_ext_header_find (vm, b0, ip0,
1085  IP_PROTOCOL_IPV6_FRAGMENTATION,
1086  &prev_hdr);
1087  }
1088  if (!frag_hdr)
1089  {
1090  // this is a regular packet - no fragmentation
1092  goto skip_reass;
1093  }
1094  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
1095  (u8 *) frag_hdr - (u8 *) ip0;
1096 
1097  if (0 == ip6_frag_hdr_offset (frag_hdr))
1098  {
1099  // first fragment - verify upper-layer is present
1101  (node, b0, frag_hdr))
1102  {
1104  goto skip_reass;
1105  }
1106  }
1107  if (!ip6_full_reass_verify_fragment_multiple_8 (vm, b0, frag_hdr) ||
1109  {
1111  goto skip_reass;
1112  }
1114  u8 do_handoff = 0;
1115 
1116  kv.k.as_u64[0] = ip0->src_address.as_u64[0];
1117  kv.k.as_u64[1] = ip0->src_address.as_u64[1];
1118  kv.k.as_u64[2] = ip0->dst_address.as_u64[0];
1119  kv.k.as_u64[3] = ip0->dst_address.as_u64[1];
1120  kv.k.as_u64[4] =
1122  vnet_buffer (b0)->sw_if_index[VLIB_RX])) << 32 |
1123  (u64) frag_hdr->identification;
1124  kv.k.as_u64[5] = ip0->protocol;
1125 
1126  ip6_full_reass_t *reass =
1127  ip6_full_reass_find_or_create (vm, node, rm, rt, &kv, &icmp_bi,
1128  &do_handoff);
1129 
1130  if (reass)
1131  {
1132  const u32 fragment_first = ip6_frag_hdr_offset (frag_hdr);
1133  if (0 == fragment_first)
1134  {
1135  reass->sendout_thread_index = vm->thread_index;
1136  }
1137  }
1138  if (PREDICT_FALSE (do_handoff))
1139  {
1141  vnet_buffer (b0)->ip.reass.owner_thread_index =
1143  }
1144  else if (reass)
1145  {
1146  u32 handoff_thread_idx;
1147  switch (ip6_full_reass_update
1148  (vm, node, rm, rt, reass, &bi0, &next0, &error0,
1149  frag_hdr, is_custom_app, &handoff_thread_idx))
1150  {
1151  case IP6_FULL_REASS_RC_OK:
1152  /* nothing to do here */
1153  break;
1156  b0 = vlib_get_buffer (vm, bi0);
1157  vnet_buffer (b0)->ip.reass.owner_thread_index =
1158  handoff_thread_idx;
1159  break;
1161  vlib_node_increment_counter (vm, node->node_index,
1162  IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
1163  1);
1164  ip6_full_reass_drop_all (vm, node, reass);
1165  ip6_full_reass_free (rm, rt, reass);
1166  goto next_packet;
1167  break;
1169  vlib_node_increment_counter (vm, node->node_index,
1170  IP6_ERROR_REASS_NO_BUF, 1);
1171  ip6_full_reass_drop_all (vm, node, reass);
1172  ip6_full_reass_free (rm, rt, reass);
1173  goto next_packet;
1174  break;
1176  vlib_node_increment_counter (vm, node->node_index,
1177  IP6_ERROR_REASS_INTERNAL_ERROR,
1178  1);
1179  ip6_full_reass_drop_all (vm, node, reass);
1180  ip6_full_reass_free (rm, rt, reass);
1181  goto next_packet;
1182  break;
1183  }
1184  }
1185  else
1186  {
1187  if (is_feature)
1188  {
1190  }
1191  else
1192  {
1193  vnet_buffer_opaque_t *fvnb = vnet_buffer (b0);
1194  next0 = fvnb->ip.reass.error_next_index;
1195  }
1196  error0 = IP6_ERROR_REASS_LIMIT_REACHED;
1197  }
1198 
1199  if (~0 != bi0)
1200  {
1201  skip_reass:
1202  to_next[0] = bi0;
1203  to_next += 1;
1204  n_left_to_next -= 1;
1205 
1206  /* bi0 might have been updated by reass_finalize, reload */
1207  b0 = vlib_get_buffer (vm, bi0);
1208  if (IP6_ERROR_NONE != error0)
1209  {
1210  b0->error = node->errors[error0];
1211  }
1212 
1213  if (next0 == IP6_FULL_REASSEMBLY_NEXT_HANDOFF)
1214  {
1215  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1216  {
1218  vm, node, NULL, bi0, frag_hdr, HANDOFF,
1219  vnet_buffer (b0)->ip.reass.owner_thread_index);
1220  }
1221  }
1222  else if (is_feature && IP6_ERROR_NONE == error0)
1223  {
1224  vnet_feature_next (&next0, b0);
1225  }
1227  n_left_to_next, bi0, next0);
1228  }
1229 
1230  if (~0 != icmp_bi)
1231  {
1233  to_next[0] = icmp_bi;
1234  to_next += 1;
1235  n_left_to_next -= 1;
1237  n_left_to_next, icmp_bi,
1238  next0);
1239  }
1240  next_packet:
1241  from += 1;
1242  n_left_from -= 1;
1243  }
1244 
1245  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1246  }
1247 
1248  clib_spinlock_unlock (&rt->lock);
1249  return frame->n_vectors;
1250 }
1251 
1253 #define _(sym, string) string,
1255 #undef _
1256 };
1257 
1260  vlib_frame_t * frame)
1261 {
1262  return ip6_full_reassembly_inline (vm, node, frame, false /* is_feature */ ,
1263  false /* is_custom_app */ );
1264 }
1265 
1267  .name = "ip6-full-reassembly",
1268  .vector_size = sizeof (u32),
1269  .format_trace = format_ip6_full_reass_trace,
1271  .error_strings = ip6_full_reassembly_error_strings,
1272  .n_next_nodes = IP6_FULL_REASSEMBLY_N_NEXT,
1273  .next_nodes =
1274  {
1275  [IP6_FULL_REASSEMBLY_NEXT_INPUT] = "ip6-input",
1276  [IP6_FULL_REASSEMBLY_NEXT_DROP] = "ip6-drop",
1277  [IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1278  [IP6_FULL_REASSEMBLY_NEXT_HANDOFF] = "ip6-full-reassembly-handoff",
1279  },
1280 };
1281 
1284  vlib_frame_t * frame)
1285 {
1286  return ip6_full_reassembly_inline (vm, node, frame, true /* is_feature */ ,
1287  false /* is_custom_app */ );
1288 }
1289 
1291  .name = "ip6-full-reassembly-feature",
1292  .vector_size = sizeof (u32),
1293  .format_trace = format_ip6_full_reass_trace,
1295  .error_strings = ip6_full_reassembly_error_strings,
1296  .n_next_nodes = IP6_FULL_REASSEMBLY_N_NEXT,
1297  .next_nodes =
1298  {
1299  [IP6_FULL_REASSEMBLY_NEXT_INPUT] = "ip6-input",
1300  [IP6_FULL_REASSEMBLY_NEXT_DROP] = "ip6-drop",
1301  [IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1302  [IP6_FULL_REASSEMBLY_NEXT_HANDOFF] = "ip6-full-reass-feature-hoff",
1303  },
1304 };
1305 
1306 VNET_FEATURE_INIT (ip6_full_reassembly_feature, static) = {
1307  .arc_name = "ip6-unicast",
1308  .node_name = "ip6-full-reassembly-feature",
1309  .runs_before = VNET_FEATURES ("ip6-lookup",
1310  "ipsec6-input-feature"),
1311  .runs_after = 0,
1312 };
1313 
1314 #ifndef CLIB_MARCH_VARIANT
1315 static u32
1317 {
1319  u32 nbuckets;
1320  u8 i;
1321 
1322  nbuckets = (u32) (rm->max_reass_n / IP6_FULL_REASS_HT_LOAD_FACTOR);
1323 
1324  for (i = 0; i < 31; i++)
1325  if ((1 << i) >= nbuckets)
1326  break;
1327  nbuckets = 1 << i;
1328 
1329  return nbuckets;
1330 }
1331 #endif /* CLIB_MARCH_VARIANT */
1332 
1333 typedef enum
1334 {
1337 
1338 #ifndef CLIB_MARCH_VARIANT
1339 typedef struct
1340 {
1341  int failure;
1342  clib_bihash_48_8_t *new_hash;
1344 
1345 static int
1347 {
1348  ip6_rehash_cb_ctx *ctx = _ctx;
1349  if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1))
1350  {
1351  ctx->failure = 1;
1352  }
1353  return (BIHASH_WALK_CONTINUE);
1354 }
1355 
1356 static void
1357 ip6_full_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
1358  u32 max_reassembly_length,
1359  u32 expire_walk_interval_ms)
1360 {
1361  ip6_full_reass_main.timeout_ms = timeout_ms;
1362  ip6_full_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
1363  ip6_full_reass_main.max_reass_n = max_reassemblies;
1364  ip6_full_reass_main.max_reass_len = max_reassembly_length;
1365  ip6_full_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
1366 }
1367 
1369 ip6_full_reass_set (u32 timeout_ms, u32 max_reassemblies,
1370  u32 max_reassembly_length, u32 expire_walk_interval_ms)
1371 {
1372  u32 old_nbuckets = ip6_full_reass_get_nbuckets ();
1373  ip6_full_reass_set_params (timeout_ms, max_reassemblies,
1374  max_reassembly_length, expire_walk_interval_ms);
1378  u32 new_nbuckets = ip6_full_reass_get_nbuckets ();
1379  if (ip6_full_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
1380  {
1381  clib_bihash_48_8_t new_hash;
1382  clib_memset (&new_hash, 0, sizeof (new_hash));
1384  ctx.failure = 0;
1385  ctx.new_hash = &new_hash;
1386  clib_bihash_init_48_8 (&new_hash, "ip6-full-reass", new_nbuckets,
1387  new_nbuckets * 1024);
1388  clib_bihash_foreach_key_value_pair_48_8 (&ip6_full_reass_main.hash,
1389  ip6_rehash_cb, &ctx);
1390  if (ctx.failure)
1391  {
1392  clib_bihash_free_48_8 (&new_hash);
1393  return -1;
1394  }
1395  else
1396  {
1397  clib_bihash_free_48_8 (&ip6_full_reass_main.hash);
1399  sizeof (ip6_full_reass_main.hash));
1401  }
1402  }
1403  return 0;
1404 }
1405 
1407 ip6_full_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
1408  u32 * max_reassembly_length,
1409  u32 * expire_walk_interval_ms)
1410 {
1411  *timeout_ms = ip6_full_reass_main.timeout_ms;
1412  *max_reassemblies = ip6_full_reass_main.max_reass_n;
1413  *max_reassembly_length = ip6_full_reass_main.max_reass_len;
1414  *expire_walk_interval_ms = ip6_full_reass_main.expire_walk_interval_ms;
1415  return 0;
1416 }
1417 
1418 static clib_error_t *
1420 {
1422  clib_error_t *error = 0;
1423  u32 nbuckets;
1424  vlib_node_t *node;
1425 
1426  rm->vlib_main = vm;
1427 
1431  {
1432  clib_spinlock_init (&rt->lock);
1433  pool_alloc (rt->pool, rm->max_reass_n);
1434  }
1435 
1436  node = vlib_get_node_by_name (vm, (u8 *) "ip6-full-reassembly-expire-walk");
1437  ASSERT (node);
1438  rm->ip6_full_reass_expire_node_idx = node->index;
1439 
1444 
1445  nbuckets = ip6_full_reass_get_nbuckets ();
1446  clib_bihash_init_48_8 (&rm->hash, "ip6-full-reass", nbuckets,
1447  nbuckets * 1024);
1448 
1449  node = vlib_get_node_by_name (vm, (u8 *) "ip6-drop");
1450  ASSERT (node);
1451  rm->ip6_drop_idx = node->index;
1452  node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error");
1453  ASSERT (node);
1454  rm->ip6_icmp_error_idx = node->index;
1455 
1457  return error;
1458  ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
1459  ip6_full_reass_node.index);
1460 
1462  rm->fq_feature_index =
1464 
1465  rm->feature_use_refcount_per_intf = NULL;
1466  return error;
1467 }
1468 
1470 #endif /* CLIB_MARCH_VARIANT */
1471 
1472 static uword
1475 {
1477  uword event_type, *event_data = 0;
1478 
1479  while (true)
1480  {
1483  / (f64) MSEC_PER_SEC);
1484  event_type = vlib_process_get_events (vm, &event_data);
1485 
1486  switch (event_type)
1487  {
1488  case ~0:
1489  /* no events => timeout */
1490  /* fallthrough */
1492  /* nothing to do here */
1493  break;
1494  default:
1495  clib_warning ("BUG: event type 0x%wx", event_type);
1496  break;
1497  }
1498  f64 now = vlib_time_now (vm);
1499 
1500  ip6_full_reass_t *reass;
1501  int *pool_indexes_to_free = NULL;
1502 
1503  uword thread_index = 0;
1504  int index;
1505  const uword nthreads = vlib_num_workers () + 1;
1506  u32 *vec_icmp_bi = NULL;
1507  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1508  {
1511  clib_spinlock_lock (&rt->lock);
1512 
1513  vec_reset_length (pool_indexes_to_free);
1514  pool_foreach_index (index, rt->pool) {
1515  reass = pool_elt_at_index (rt->pool, index);
1516  if (now > reass->last_heard + rm->timeout)
1517  {
1518  vec_add1 (pool_indexes_to_free, index);
1519  }
1520  }
1521  int *i;
1522  vec_foreach (i, pool_indexes_to_free)
1523  {
1524  ip6_full_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1525  u32 icmp_bi = ~0;
1526  ip6_full_reass_on_timeout (vm, node, reass, &icmp_bi);
1527  if (~0 != icmp_bi)
1528  vec_add1 (vec_icmp_bi, icmp_bi);
1529 
1530  ip6_full_reass_free (rm, rt, reass);
1531  }
1532 
1533  clib_spinlock_unlock (&rt->lock);
1534  }
1535 
1536  while (vec_len (vec_icmp_bi) > 0)
1537  {
1538  vlib_frame_t *f =
1540  u32 *to_next = vlib_frame_vector_args (f);
1541  u32 n_left_to_next = VLIB_FRAME_SIZE - f->n_vectors;
1542  int trace_frame = 0;
1543  while (vec_len (vec_icmp_bi) > 0 && n_left_to_next > 0)
1544  {
1545  u32 bi = vec_pop (vec_icmp_bi);
1546  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1547  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
1548  trace_frame = 1;
1549  b->error = node->errors[IP6_ERROR_REASS_TIMEOUT];
1550  to_next[0] = bi;
1551  ++f->n_vectors;
1552  to_next += 1;
1553  n_left_to_next -= 1;
1554  }
1555  f->frame_flags |= (trace_frame * VLIB_FRAME_TRACE);
1557  }
1558 
1559  vec_free (pool_indexes_to_free);
1560  vec_free (vec_icmp_bi);
1561  if (event_data)
1562  {
1563  _vec_len (event_data) = 0;
1564  }
1565  }
1566 
1567  return 0;
1568 }
1569 
1571  .function = ip6_full_reass_walk_expired,
1572  .format_trace = format_ip6_full_reass_trace,
1573  .type = VLIB_NODE_TYPE_PROCESS,
1574  .name = "ip6-full-reassembly-expire-walk",
1575 
1577  .error_strings = ip6_full_reassembly_error_strings,
1578 
1579 };
1580 
1581 static u8 *
1582 format_ip6_full_reass_key (u8 * s, va_list * args)
1583 {
1584  ip6_full_reass_key_t *key = va_arg (*args, ip6_full_reass_key_t *);
1585  s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1586  key->xx_id, format_ip6_address, &key->src, format_ip6_address,
1587  &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1588  return s;
1589 }
1590 
1591 static u8 *
1592 format_ip6_full_reass (u8 * s, va_list * args)
1593 {
1594  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1595  ip6_full_reass_t *reass = va_arg (*args, ip6_full_reass_t *);
1596 
1597  s = format (s, "ID: %lu, key: %U\n first_bi: %u, data_len: %u, "
1598  "last_packet_octet: %u, trace_op_counter: %u\n",
1599  reass->id, format_ip6_full_reass_key, &reass->key,
1600  reass->first_bi, reass->data_len, reass->last_packet_octet,
1601  reass->trace_op_counter);
1602  u32 bi = reass->first_bi;
1603  u32 counter = 0;
1604  while (~0 != bi)
1605  {
1606  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1608  s = format (s, " #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, "
1609  "fragment[%u, %u]\n",
1610  counter, vnb->ip.reass.range_first,
1611  vnb->ip.reass.range_last, bi,
1614  vnb->ip.reass.fragment_first, vnb->ip.reass.fragment_last);
1615  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
1616  {
1617  bi = b->next_buffer;
1618  }
1619  else
1620  {
1621  bi = ~0;
1622  }
1623  }
1624  return s;
1625 }
1626 
1627 static clib_error_t *
1630 {
1632 
1633  vlib_cli_output (vm, "---------------------");
1634  vlib_cli_output (vm, "IP6 reassembly status");
1635  vlib_cli_output (vm, "---------------------");
1636  bool details = false;
1637  if (unformat (input, "details"))
1638  {
1639  details = true;
1640  }
1641 
1642  u32 sum_reass_n = 0;
1643  u64 sum_buffers_n = 0;
1644  ip6_full_reass_t *reass;
1646  const uword nthreads = vlib_num_workers () + 1;
1647  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1648  {
1650  clib_spinlock_lock (&rt->lock);
1651  if (details)
1652  {
1653  pool_foreach (reass, rt->pool) {
1654  vlib_cli_output (vm, "%U", format_ip6_full_reass, vm, reass);
1655  }
1656  }
1657  sum_reass_n += rt->reass_n;
1658  clib_spinlock_unlock (&rt->lock);
1659  }
1660  vlib_cli_output (vm, "---------------------");
1661  vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1662  (long unsigned) sum_reass_n);
1664  "Maximum configured concurrent full IP6 reassemblies per worker-thread: %lu\n",
1665  (long unsigned) rm->max_reass_n);
1667  "Maximum configured amount of fragments "
1668  "per full IP6 reassembly: %lu\n",
1669  (long unsigned) rm->max_reass_len);
1671  "Maximum configured full IP6 reassembly timeout: %lums\n",
1672  (long unsigned) rm->timeout_ms);
1674  "Maximum configured full IP6 reassembly expire walk interval: %lums\n",
1675  (long unsigned) rm->expire_walk_interval_ms);
1676  vlib_cli_output (vm, "Buffers in use: %lu\n",
1677  (long unsigned) sum_buffers_n);
1678  return 0;
1679 }
1680 
1682  .path = "show ip6-full-reassembly",
1683  .short_help = "show ip6-full-reassembly [details]",
1684  .function = show_ip6_full_reass,
1685 };
1686 
1687 #ifndef CLIB_MARCH_VARIANT
1690 {
1691  return vnet_feature_enable_disable ("ip6-unicast",
1692  "ip6-full-reassembly-feature",
1693  sw_if_index, enable_disable, 0, 0);
1694 }
1695 #endif /* CLIB_MARCH_VARIANT */
1696 
1697 #define foreach_ip6_full_reassembly_handoff_error \
1698 _(CONGESTION_DROP, "congestion drop")
1699 
1700 
1701 typedef enum
1702 {
1703 #define _(sym,str) IP6_FULL_REASSEMBLY_HANDOFF_ERROR_##sym,
1705 #undef _
1708 
1710 #define _(sym,string) string,
1712 #undef _
1713 };
1714 
1715 typedef struct
1716 {
1719 
1720 static u8 *
1722 {
1723  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1724  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1726  va_arg (*args, ip6_full_reassembly_handoff_trace_t *);
1727 
1728  s =
1729  format (s, "ip6-full-reassembly-handoff: next-worker %d",
1730  t->next_worker_index);
1731 
1732  return s;
1733 }
1734 
1738  vlib_frame_t * frame, bool is_feature)
1739 {
1741 
1743  u32 n_enq, n_left_from, *from;
1744  u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1745  u32 fq_index;
1746 
1748  n_left_from = frame->n_vectors;
1750 
1751  b = bufs;
1752  ti = thread_indices;
1753 
1754  fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1755 
1756  while (n_left_from > 0)
1757  {
1758  ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1759 
1760  if (PREDICT_FALSE
1761  ((node->flags & VLIB_NODE_FLAG_TRACE)
1762  && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1763  {
1765  vlib_add_trace (vm, node, b[0], sizeof (*t));
1766  t->next_worker_index = ti[0];
1767  }
1768 
1769  n_left_from -= 1;
1770  ti += 1;
1771  b += 1;
1772  }
1773  n_enq = vlib_buffer_enqueue_to_thread (vm, node, fq_index, from,
1774  thread_indices, frame->n_vectors, 1);
1775 
1776  if (n_enq < frame->n_vectors)
1777  vlib_node_increment_counter (vm, node->node_index,
1778  IP6_FULL_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1779  frame->n_vectors - n_enq);
1780  return frame->n_vectors;
1781 }
1782 
1785  vlib_frame_t * frame)
1786 {
1788  false /* is_feature */ );
1789 }
1790 
1792  .name = "ip6-full-reassembly-handoff",
1793  .vector_size = sizeof (u32),
1797 
1798  .n_next_nodes = 1,
1799 
1800  .next_nodes = {
1801  [0] = "error-drop",
1802  },
1803 };
1804 
1805 
1808 {
1809  return ip6_full_reassembly_handoff_inline (vm, node, frame, true /* is_feature */ );
1810 }
1811 
1812 
1814  .name = "ip6-full-reass-feature-hoff",
1815  .vector_size = sizeof (u32),
1819 
1820  .n_next_nodes = 1,
1821 
1822  .next_nodes = {
1823  [0] = "error-drop",
1824  },
1825 };
1826 
1827 #ifndef CLIB_MARCH_VARIANT
1828 int
1830 {
1833  if (is_enable)
1834  {
1836  {
1838  return vnet_feature_enable_disable ("ip6-unicast",
1839  "ip6-full-reassembly-feature",
1840  sw_if_index, 1, 0, 0);
1841  }
1843  }
1844  else
1845  {
1848  return vnet_feature_enable_disable ("ip6-unicast",
1849  "ip6-full-reassembly-feature",
1850  sw_if_index, 0, 0, 0);
1851  }
1852  return -1;
1853 }
1854 #endif
1855 
1856 /*
1857  * fd.io coding-style-patch-verification: ON
1858  *
1859  * Local Variables:
1860  * eval: (c-set-style "gnu")
1861  * End:
1862  */
ip6_full_reass_verify_fragment_multiple_8
static bool ip6_full_reass_verify_fragment_multiple_8(vlib_main_t *vm, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
Definition: ip6_full_reass.c:1007
ip6_full_reass_walk_expired
static uword ip6_full_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, CLIB_UNUSED(vlib_frame_t *f))
Definition: ip6_full_reass.c:1473
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
HANDOFF
@ HANDOFF
Definition: ip6_full_reass.c:194
clib_spinlock_init
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
ip6_full_reass_t::key
ip6_full_reass_key_t key
Definition: ip6_full_reass.c:102
ip6_full_reass_kv_t::v
ip6_full_reass_val_t v
Definition: ip6_full_reass.c:77
tmp
u32 * tmp
Definition: interface_output.c:1096
vlib_buffer_t::next_buffer
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:149
vlib_frame_t::n_vectors
u16 n_vectors
Definition: node.h:387
ip6_full_reass_free_ctx
static void ip6_full_reass_free_ctx(ip6_full_reass_per_thread_t *rt, ip6_full_reass_t *reass)
Definition: ip6_full_reass.c:376
vlib_buffer_free
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:979
ip6_frag_hdr_more
#define ip6_frag_hdr_more(hdr)
Definition: ip6_packet.h:706
ip6_full_reass_per_thread_t::id_counter
u32 id_counter
Definition: ip6_full_reass.c:134
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
ip6_full_reass_kv_t
Definition: ip6_full_reass.c:72
trace
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:870
while
while(n_left_from > 0)
Definition: nat44_ei_hairpinning.c:419
ip6_full_reass_t::memory_owner_thread_index
u32 memory_owner_thread_index
Definition: ip6_full_reass.c:124
ip6_full_reassembly_inline
static uword ip6_full_reassembly_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature, bool is_custom_app)
Definition: ip6_full_reass.c:1050
show_ip6_full_reass
static clib_error_t * show_ip6_full_reass(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
Definition: ip6_full_reass.c:1628
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
ip6_full_reass_main_t::expire_walk_interval_ms
u32 expire_walk_interval_ms
Definition: ip6_full_reass.c:143
bufs
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:717
IP6_EVENT_CONFIG_CHANGED
@ IP6_EVENT_CONFIG_CHANGED
Definition: ip6_full_reass.c:1335
vlib_buffer_enqueue_to_thread
static_always_inline u32 vlib_buffer_enqueue_to_thread(vlib_main_t *vm, vlib_node_runtime_t *node, u32 frame_queue_index, u32 *buffer_indices, u16 *thread_indices, u32 n_packets, int drop_on_congestion)
Definition: buffer_node.h:383
ip6_full_reass.h
IPv6 Reassembly.
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
ip6_full_reass_range_trace_t
Definition: ip6_full_reass.c:197
ip6_full_reass_expire_node
vlib_node_registration_t ip6_full_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip6_full_reass_expire_node)
Definition: ip6_full_reass.c:1570
ip6_full_reass_main_t::per_thread_data
ip6_full_reass_per_thread_t * per_thread_data
Definition: ip6_full_reass.c:153
ip6_full_reassembly_error_strings
static char * ip6_full_reassembly_error_strings[]
Definition: ip6_full_reass.c:1252
ip6_full_reass_t::next_index
u32 next_index
Definition: ip6_full_reass.c:116
ip6_full_reass_t::fragments_n
u32 fragments_n
Definition: ip6_full_reass.c:122
icmp6_error_set_vnet_buffer
void icmp6_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
Definition: icmp6.c:451
ip6_full_reass_insert_range_in_chain
static void ip6_full_reass_insert_range_in_chain(vlib_main_t *vm, ip6_full_reass_t *reass, u32 prev_range_bi, u32 new_next_bi)
Definition: ip6_full_reass.c:811
ip6_full_reass_key_t::as_u64
u64 as_u64[6]
Definition: ip6_full_reass.c:58
ip6_full_reass_range_trace_t::range_last
u16 range_last
Definition: ip6_full_reass.c:200
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
ip6_full_reass_main_t::fq_index
u32 fq_index
Worker handoff.
Definition: ip6_full_reass.c:164
ip6_full_reassembly_handoff_inline
static uword ip6_full_reassembly_handoff_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
Definition: ip6_full_reass.c:1736
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
ip6_full_reass_key_t::frag_id
u32 frag_id
Definition: ip6_full_reass.c:54
ip6_full_reass_on_timeout
static void ip6_full_reass_on_timeout(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_full_reass_t *reass, u32 *icmp_bi)
Definition: ip6_full_reass.c:462
ip6_full_reass_trace_t::is_after_handoff
bool is_after_handoff
Definition: ip6_full_reass.c:218
ip6_full_reass_trace_details
static void ip6_full_reass_trace_details(vlib_main_t *vm, u32 bi, ip6_full_reass_range_trace_t *trace)
Definition: ip6_full_reass.c:224
VNET_FEATURE_INIT
VNET_FEATURE_INIT(ip6_full_reassembly_feature, static)
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
format_ip6_header
format_function_t format_ip6_header
Definition: format.h:95
f
vlib_frame_t * f
Definition: interface_output.c:1098
ip6_rehash_cb_ctx
Definition: ip6_full_reass.c:1339
RANGE_OVERLAP
@ RANGE_OVERLAP
Definition: ip6_full_reass.c:189
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
ip6_full_reass_trace_t::fragment_first
u32 fragment_first
Definition: ip6_full_reass.c:213
ip6_header_t::protocol
u8 protocol
Definition: ip6_packet.h:304
ip6_full_reass_main_t::ip6_icmp_error_idx
u32 ip6_icmp_error_idx
Definition: ip6_full_reass.c:160
vlib_get_buffers
vlib_get_buffers(vm, from, b, n_left_from)
VLIB_FRAME_SIZE
#define VLIB_FRAME_SIZE
Definition: node.h:368
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip6_full_reass_main_t::max_reass_len
u32 max_reass_len
Definition: ip6_full_reass.c:145
ip6_full_reass_trace_t::ip6_header
ip6_header_t ip6_header
Definition: ip6_full_reass.c:219
ip6_full_reassembly_handoff_trace_t::next_worker_index
u32 next_worker_index
Definition: ip6_full_reass.c:1717
vlib_cli_command_t::path
char * path
Definition: cli.h:96
IP6_FULL_REASS_TIMEOUT_DEFAULT_MS
#define IP6_FULL_REASS_TIMEOUT_DEFAULT_MS
Definition: ip6_full_reass.c:30
ip6_full_reass_key_t::src
ip6_address_t src
Definition: ip6_full_reass.c:51
ip6_full_reass_range_trace_t::first_bi
u32 first_bi
Definition: ip6_full_reass.c:204
u16
unsigned short u16
Definition: types.h:57
vlib_call_init_function
#define vlib_call_init_function(vm, x)
Definition: init.h:259
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
ip6_full_reass_main
ip6_full_reass_main_t ip6_full_reass_main
Definition: ip6_full_reass.c:174
ip6_full_reass_main_t::feature_use_refcount_per_intf
u32 * feature_use_refcount_per_intf
Definition: ip6_full_reass.c:168
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
ip6_full_reass_buffer_get_data_offset
static u32 ip6_full_reass_buffer_get_data_offset(vlib_buffer_t *b)
Definition: ip6_full_reass.c:84
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
IP6_FULL_REASS_RC_TOO_MANY_FRAGMENTS
@ IP6_FULL_REASS_RC_TOO_MANY_FRAGMENTS
Definition: ip6_full_reass.c:40
ip6_rehash_cb
static int ip6_rehash_cb(clib_bihash_kv_48_8_t *kv, void *_ctx)
Definition: ip6_full_reass.c:1346
format_hexdump
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:352
ip6_full_reass_set_params
static void ip6_full_reass_set_params(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
Definition: ip6_full_reass.c:1357
vlib_buffer_get_trace_thread
static u32 vlib_buffer_get_trace_thread(vlib_buffer_t *b)
Extract the thread id from a trace handle.
Definition: buffer.h:404
ip6_full_reass_init_function
static clib_error_t * ip6_full_reass_init_function(vlib_main_t *vm)
Definition: ip6_full_reass.c:1419
unformat_input_t
struct _unformat_input_t unformat_input_t
vlib_frame_t::frame_flags
u16 frame_flags
Definition: node.h:375
vlib_frame_t
Definition: node.h:372
vlib_get_frame_to_node
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:184
ip6_rehash_cb_ctx::new_hash
clib_bihash_48_8_t * new_hash
Definition: ip6_full_reass.c:1342
vlib_process_signal_event
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1019
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
ip6_full_reass_t::min_fragment_length
u16 min_fragment_length
Definition: ip6_full_reass.c:120
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
ip6_full_reass_per_thread_t::lock
clib_spinlock_t lock
Definition: ip6_full_reass.c:135
IP6_FULL_REASSEMBLY_NEXT_HANDOFF
@ IP6_FULL_REASSEMBLY_NEXT_HANDOFF
Definition: ip6_full_reass.c:182
ip6_full_reass_main_t::ip6_drop_idx
u32 ip6_drop_idx
Definition: ip6_full_reass.c:159
error
Definition: cJSON.c:88
key
typedef key
Definition: ipsec_types.api:91
i32
signed int i32
Definition: types.h:77
IP6_FULL_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
#define IP6_FULL_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
Definition: ip6_full_reass.c:31
ip6_full_reass_range_trace_t::data_offset
i32 data_offset
Definition: ip6_full_reass.c:202
vlib_frame_queue_main_init
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1561
ip6_full_reass_main_t::hash
clib_bihash_48_8_t hash
Definition: ip6_full_reass.c:150
MSEC_PER_SEC
#define MSEC_PER_SEC
Definition: ip6_full_reass.c:29
IP6_FULL_REASSEMBLY_NEXT_DROP
@ IP6_FULL_REASSEMBLY_NEXT_DROP
Definition: ip6_full_reass.c:180
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vnet_buffer_opaque_t::ip
struct vnet_buffer_opaque_t::@157::@159 ip
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
vec_elt
#define vec_elt(v, i)
Get vector value at index i.
Definition: vec_bootstrap.h:210
vlib_process_get_events
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type,...
Definition: node_funcs.h:583
vlib_put_frame_to_node
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:218
ip6_full_reass_enable_disable
vnet_api_error_t ip6_full_reass_enable_disable(u32 sw_if_index, u8 enable_disable)
Definition: ip6_full_reass.c:1689
ti
u32 ti
Definition: interface_output.c:425
ip6_full_reass_get_nbuckets
static u32 ip6_full_reass_get_nbuckets()
Definition: ip6_full_reass.c:1316
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
ip6_full_reass_rc_t
ip6_full_reass_rc_t
Definition: ip6_full_reass.c:36
ip6_full_reass_buffer_get_data_len
static u16 ip6_full_reass_buffer_get_data_len(vlib_buffer_t *b)
Definition: ip6_full_reass.c:91
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
show_ip6_full_reassembly_cmd
static vlib_cli_command_t show_ip6_full_reassembly_cmd
(constructor) VLIB_CLI_COMMAND (show_ip6_full_reassembly_cmd)
Definition: ip6_full_reass.c:1681
IP6_FULL_REASSEMBLY_N_NEXT
@ IP6_FULL_REASSEMBLY_N_NEXT
Definition: ip6_full_reass.c:183
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vlib_buffer_t::error
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:145
ip6_full_reass_main_t::timeout
f64 timeout
Definition: ip6_full_reass.c:142
ip6_full_reass_val_t::as_u64
u64 as_u64
Definition: ip6_full_reass.c:69
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
RANGE_NEW
@ RANGE_NEW
Definition: ip6_full_reass.c:188
ip6_full_reass_drop_all
static void ip6_full_reass_drop_all(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_full_reass_t *reass)
Definition: ip6_full_reass.c:400
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
ip6_full_reass_trace_t::op_id
u32 op_id
Definition: ip6_full_reass.c:212
ip6_full_reassembly_handoff_trace_t
Definition: ip6_full_reass.c:1715
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
ip6_full_reass_next_t
ip6_full_reass_next_t
Definition: ip6_full_reass.c:177
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
ip6_full_reass_t::error_next_index
u32 error_next_index
Definition: ip6_full_reass.c:118
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ip6_full_reass_main_t
Definition: ip6_full_reass.c:138
vnet_feature_next
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:322
ip6_full_reass_enable_disable_with_refcnt
int ip6_full_reass_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
Definition: ip6_full_reass.c:1829
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
format_ip6_full_reass_range_trace
static u8 * format_ip6_full_reass_range_trace(u8 *s, va_list *args)
Definition: ip6_full_reass.c:237
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
clib_spinlock_lock
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:82
ip6_ext_header_find
static void * ip6_ext_header_find(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6_header, u8 header_type, ip6_ext_header_t **prev_ext_header)
Definition: ip6_packet.h:575
clib_bihash_copied
__clib_export void clib_bihash_copied(void *dst, void *src)
Definition: bihash_all_vector.c:36
IP6_FULL_REASS_RC_OK
@ IP6_FULL_REASS_RC_OK
Definition: ip6_full_reass.c:38
clib_spinlock_s
Definition: lock.h:51
IP6_FULL_REASS_RC_INTERNAL_ERROR
@ IP6_FULL_REASS_RC_INTERNAL_ERROR
Definition: ip6_full_reass.c:39
ip6_full_reass_t
Definition: ip6_full_reass.c:99
ip6_full_reass_trace_t::thread_id
u32 thread_id
Definition: ip6_full_reass.c:216
uword
u64 uword
Definition: types.h:112
ip6_full_reass_trace_t::thread_id_to
u32 thread_id_to
Definition: ip6_full_reass.c:217
ip6_full_reass_val_t::memory_owner_thread_index
u32 memory_owner_thread_index
Definition: ip6_full_reass.c:67
ip6_full_reassembly_feature_handoff_node
vlib_node_registration_t ip6_full_reassembly_feature_handoff_node
(constructor) VLIB_REGISTER_NODE (ip6_full_reassembly_feature_handoff_node)
Definition: ip6_full_reass.c:1813
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:215
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
ip6_full_reass_node
vlib_node_registration_t ip6_full_reass_node
(constructor) VLIB_REGISTER_NODE (ip6_full_reass_node)
Definition: ip6_full_reass.c:1266
format_ip6_full_reass
static u8 * format_ip6_full_reass(u8 *s, va_list *args)
Definition: ip6_full_reass.c:1592
f64
double f64
Definition: types.h:142
ip6_header_t::dst_address
ip6_address_t dst_address
Definition: ip6_packet.h:310
ip6_frag_hdr_offset
#define ip6_frag_hdr_offset(hdr)
Definition: ip6_packet.h:700
ip6_full_reassembly_handoff_node
vlib_node_registration_t ip6_full_reassembly_handoff_node
(constructor) VLIB_REGISTER_NODE (ip6_full_reassembly_handoff_node)
Definition: ip6_full_reass.c:1791
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
ip6_main_t::fib_index_by_sw_if_index
u32 * fib_index_by_sw_if_index
Definition: ip6.h:127
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
ip6_full_reass_key_t::dst
ip6_address_t dst
Definition: ip6_full_reass.c:52
ip6_full_reass_t::data_len
u32 data_len
Definition: ip6_full_reass.c:112
ip6_full_reass_t::first_bi
u32 first_bi
Definition: ip6_full_reass.c:108
clib_min
#define clib_min(x, y)
Definition: clib.h:342
vlib_buffer_chain_linearize
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:1471
ip_main_init
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
vec_pop
#define vec_pop(V)
Returns last element of a vector and decrements its length.
Definition: vec.h:705
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
ICMP_ERROR_FL_TOO_BIG
@ ICMP_ERROR_FL_TOO_BIG
Definition: ip6_full_reass.c:191
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
ip6_full_reass_kv_t::kv
clib_bihash_kv_48_8_t kv
Definition: ip6_full_reass.c:79
ip6_full_reass_find_or_create
static ip6_full_reass_t * ip6_full_reass_find_or_create(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_full_reass_main_t *rm, ip6_full_reass_per_thread_t *rt, ip6_full_reass_kv_t *kv, u32 *icmp_bi, u8 *do_handoff)
Definition: ip6_full_reass.c:500
ip6_full_reass_range_trace_t::range_first
u16 range_first
Definition: ip6_full_reass.c:199
ip6_full_reass_set
vnet_api_error_t ip6_full_reass_set(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
set ip6 reassembly configuration
Definition: ip6_full_reass.c:1369
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2785
ip6_full_reass_get
vnet_api_error_t ip6_full_reass_get(u32 *timeout_ms, u32 *max_reassemblies, u32 *max_reassembly_length, u32 *expire_walk_interval_ms)
get ip6 reassembly configuration
Definition: ip6_full_reass.c:1407
ip6_full_reass_t::id
u64 id
Definition: ip6_full_reass.c:106
ip6_full_reass_event_t
ip6_full_reass_event_t
Definition: ip6_full_reass.c:1333
format_ip6_full_reass_trace
static u8 * format_ip6_full_reass_trace(u8 *s, va_list *args)
Definition: ip6_full_reass.c:249
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
vnet_buffer_opaque_t
Definition: buffer.h:153
ip6_full_reass_main_t::ip6_full_reass_expire_node_idx
u32 ip6_full_reass_expire_node_idx
Definition: ip6_full_reass.c:161
IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR
@ IP6_FULL_REASSEMBLY_NEXT_ICMP_ERROR
Definition: ip6_full_reass.c:181
ip6_full_reass_verify_packet_size_lt_64k
static bool ip6_full_reass_verify_packet_size_lt_64k(vlib_main_t *vm, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
Definition: ip6_full_reass.c:1028
pool_foreach_index
#define pool_foreach_index(i, v)
Definition: pool.h:572
ip6_full_reass_trace_t::action
ip6_full_reass_trace_operation_e action
Definition: ip6_full_reass.c:209
u64
unsigned long u64
Definition: types.h:89
vlib_trace_main_t::trace_buffer_pool
vlib_trace_header_t ** trace_buffer_pool
Definition: trace.h:86
vlib_process_wait_for_event_or_clock
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:755
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
ip6_full_reass_free
static void ip6_full_reass_free(ip6_full_reass_main_t *rm, ip6_full_reass_per_thread_t *rt, ip6_full_reass_t *reass)
Definition: ip6_full_reass.c:384
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
ip6_full_reass_per_thread_t::reass_n
u32 reass_n
Definition: ip6_full_reass.c:133
data_len
u8 data_len
Definition: ikev2_types.api:24
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
ip6_full_reass_finalize
static ip6_full_reass_rc_t ip6_full_reass_finalize(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_full_reass_main_t *rm, ip6_full_reass_per_thread_t *rt, ip6_full_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, bool is_custom_app)
Definition: ip6_full_reass.c:584
ip.h
ip6_ext_hdr
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:524
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
format_ip6_frag_hdr
format_function_t format_ip6_frag_hdr
Definition: format.h:96
ip6_full_reass_t::last_packet_octet
u32 last_packet_octet
Definition: ip6_full_reass.c:110
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
ip6_full_reass_range_trace_t::range_bi
u32 range_bi
Definition: ip6_full_reass.c:201
clib_bihash_kv_48_8_t::key
u64 key[6]
Definition: bihash_48_8.h:41
format_ip6_full_reass_key
static u8 * format_ip6_full_reass_key(u8 *s, va_list *args)
Definition: ip6_full_reass.c:1582
ip6_full_reass_t::sendout_thread_index
u32 sendout_thread_index
Definition: ip6_full_reass.c:127
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
ip6_full_reass_trace_t::fragment_last
u32 fragment_last
Definition: ip6_full_reass.c:214
VLIB_NODE_TYPE_PROCESS
@ VLIB_NODE_TYPE_PROCESS
Definition: node.h:84
as_u64
u64 as_u64
Definition: bihash_doc.h:63
ip6_full_reass_t::trace_op_counter
u32 trace_op_counter
Definition: ip6_full_reass.c:114
ip6_full_reass_trace_t::total_data_len
u32 total_data_len
Definition: ip6_full_reass.c:215
n_vectors
return frame n_vectors
Definition: nat44_ei_hairpinning.c:488
ip6_full_reass_main_t::max_reass_n
u32 max_reass_n
Definition: ip6_full_reass.c:147
ip6_full_reass_key_t::xx_id
u32 xx_id
Definition: ip6_full_reass.c:53
clib_spinlock_unlock
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:121
ip6_full_reass_trace_t::trace_range
ip6_full_reass_range_trace_t trace_range
Definition: ip6_full_reass.c:211
ip6_header_t
Definition: ip6_packet.h:294
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
vec.h
ip6_frag_hdr_offset_bytes
#define ip6_frag_hdr_offset_bytes(hdr)
Definition: ip6_packet.h:703
now
f64 now
Definition: nat44_ei_out2in.c:710
ip6_full_reass_kv_t::k
ip6_full_reass_key_t k
Definition: ip6_full_reass.c:76
foreach_ip6_full_reassembly_handoff_error
#define foreach_ip6_full_reassembly_handoff_error
Definition: ip6_full_reass.c:1697
ip6_full_reass_per_thread_t
Definition: ip6_full_reass.c:130
IP6_FULL_REASSEMBLY_HANDOFF_N_ERROR
@ IP6_FULL_REASSEMBLY_HANDOFF_N_ERROR
Definition: ip6_full_reass.c:1706
ip6_header_t::src_address
ip6_address_t src_address
Definition: ip6_packet.h:310
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
ip6_full_reass_verify_upper_layer_present
static bool ip6_full_reass_verify_upper_layer_present(vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
Definition: ip6_full_reass.c:985
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
ip6_full_reass_main_t::vlib_main
vlib_main_t * vlib_main
Definition: ip6_full_reass.c:156
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
rt
vnet_interface_output_runtime_t * rt
Definition: interface_output.c:419
ip
vl_api_address_t ip
Definition: l2.api:558
ip6_full_reass_t::last_heard
f64 last_heard
Definition: ip6_full_reass.c:104
ip6_full_reass_trace_operation_e
ip6_full_reass_trace_operation_e
Definition: ip6_full_reass.c:186
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
format_ip6_address
format_function_t format_ip6_address
Definition: format.h:91
IP6_FULL_REASS_MAX_REASSEMBLIES_DEFAULT
#define IP6_FULL_REASS_MAX_REASSEMBLIES_DEFAULT
Definition: ip6_full_reass.c:32
IP6_FULL_REASS_HT_LOAD_FACTOR
#define IP6_FULL_REASS_HT_LOAD_FACTOR
Definition: ip6_full_reass.c:34
IP6_FULL_REASS_RC_NO_BUF
@ IP6_FULL_REASS_RC_NO_BUF
Definition: ip6_full_reass.c:41
i
int i
Definition: flowhash_template.h:376
FINALIZE
@ FINALIZE
Definition: ip6_full_reass.c:193
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
ip6_full_reassembly_handoff_error_strings
static char * ip6_full_reassembly_handoff_error_strings[]
Definition: ip6_full_reass.c:1709
pool_alloc
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
Definition: pool.h:367
ip6_full_reass_update
static ip6_full_reass_rc_t ip6_full_reass_update(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_full_reass_main_t *rm, ip6_full_reass_per_thread_t *rt, ip6_full_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, ip6_frag_hdr_t *frag_hdr, bool is_custom_app, u32 *handoff_thread_idx)
Definition: ip6_full_reass.c:837
ip6_register_protocol
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1677
ICMP_ERROR_FL_NOT_MULT_8
@ ICMP_ERROR_FL_NOT_MULT_8
Definition: ip6_full_reass.c:192
rv
int __clib_unused rv
Definition: application.c:491
ip6_full_reass_key_t
Definition: ip6_full_reass.c:45
ICMP_ERROR_RT_EXCEEDED
@ ICMP_ERROR_RT_EXCEEDED
Definition: ip6_full_reass.c:190
ip6_full_reass_trace_t
Definition: ip6_full_reass.c:207
ip6_full_reassembly_handoff_error_t
ip6_full_reassembly_handoff_error_t
Definition: ip6_full_reass.c:1701
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
ip6_full_reass_trace_t::ip6_frag_header
ip6_frag_hdr_t ip6_frag_header
Definition: ip6_full_reass.c:220
ip6_full_reass_node_feature
vlib_node_registration_t ip6_full_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip6_full_reass_node_feature)
Definition: ip6_full_reass.c:1290
vnet.h
vlib_main_t::trace_main
vlib_trace_main_t trace_main
Definition: main.h:176
ip6_ext_next_header
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
Definition: ip6_packet.h:549
ip6_header_t::payload_length
u16 payload_length
Definition: ip6_packet.h:301
ip6_full_reass_main_t::fq_feature_index
u32 fq_feature_index
Definition: ip6_full_reass.c:165
vlib_node_runtime_t
Definition: node.h:454
IP6_FULL_REASSEMBLY_NEXT_INPUT
@ IP6_FULL_REASSEMBLY_NEXT_INPUT
Definition: ip6_full_reass.c:179
ip6_full_reass_trace_t::reass_id
u32 reass_id
Definition: ip6_full_reass.c:210
vlib_buffer_get_trace_index
static u32 vlib_buffer_get_trace_index(vlib_buffer_t *b)
Extract the trace (pool) index from a trace handle.
Definition: buffer.h:416
vlib_cli_command_t
Definition: cli.h:92
VLIB_FRAME_TRACE
#define VLIB_FRAME_TRACE
Definition: node.h:425
from
from
Definition: nat44_ei_hairpinning.c:415
ip6_full_reass_add_trace
static void ip6_full_reass_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_full_reass_t *reass, u32 bi, ip6_frag_hdr_t *ip6_frag_header, ip6_full_reass_trace_operation_e action, u32 thread_id_to)
Definition: ip6_full_reass.c:312
action
vl_api_mac_event_action_t action
Definition: l2.api:211
vlib_buffer_t::total_length_not_including_first_buffer
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:176
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
ip6_full_reass_main_t::timeout_ms
u32 timeout_ms
Definition: ip6_full_reass.c:141
ip6_rehash_cb_ctx::failure
int failure
Definition: ip6_full_reass.c:1341
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
ip6_full_reass_key_t::proto
u8 proto
Definition: ip6_full_reass.c:56
ip6_full_reass_range_trace_t::data_len
u32 data_len
Definition: ip6_full_reass.c:203
clib_bihash_kv_48_8_t
Definition: bihash_48_8.h:39
IP6_FULL_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT
#define IP6_FULL_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT
Definition: ip6_full_reass.c:33
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
ip6_full_reass_val_t::reass_index
u32 reass_index
Definition: ip6_full_reass.c:66
bihash_48_8.h
vnet_api_error_t
vnet_api_error_t
Definition: api_errno.h:162
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
IP6_FULL_REASS_RC_HANDOFF
@ IP6_FULL_REASS_RC_HANDOFF
Definition: ip6_full_reass.c:42
foreach_ip6_error
#define foreach_ip6_error
Definition: ip6_error.h:43
format_ip6_full_reassembly_handoff_trace
static u8 * format_ip6_full_reassembly_handoff_trace(u8 *s, va_list *args)
Definition: ip6_full_reass.c:1721
ip6_full_reass_val_t
Definition: ip6_full_reass.c:62
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
ip6_full_reass_per_thread_t::pool
ip6_full_reass_t * pool
Definition: ip6_full_reass.c:132
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169