FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
ip6_reassembly.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 Reassembly.
19  *
20  * This file contains the source code for IPv6 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>
27 #include <vnet/ip/ip6_reassembly.h>
28 
29 #define MSEC_PER_SEC 1000
30 #define IP6_REASS_TIMEOUT_DEFAULT_MS 100
31 #define IP6_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
32 #define IP6_REASS_MAX_REASSEMBLIES_DEFAULT 1024
33 #define IP6_REASS_HT_LOAD_FACTOR (0.75)
34 
35 typedef enum
36 {
41 
42 typedef struct
43 {
44  union
45  {
46  struct
47  {
52  u8 unused[7];
54  };
55  u64 as_u64[6];
56  };
58 
61 {
63  return vnb->ip.reass.range_first - vnb->ip.reass.fragment_first;
64 }
65 
68 {
70  return clib_min (vnb->ip.reass.range_last, vnb->ip.reass.fragment_last) -
71  (vnb->ip.reass.fragment_first + ip6_reass_buffer_get_data_offset (b)) + 1;
72 }
73 
74 typedef struct
75 {
76  // hash table key
78  // time when last packet was received
80  // internal id of this reassembly
82  // buffer index of first buffer in this reassembly context
84  // last octet of packet, ~0 until fragment without more_fragments arrives
86  // length of data collected so far
88  // trace operation counter
90  // next index - used by non-feature node
92  // minimum fragment length for this reassembly - used to estimate MTU
94 } ip6_reass_t;
95 
96 typedef struct
97 {
103 
104 typedef struct
105 {
106  // IPv6 config
111 
112  // IPv6 runtime
113  clib_bihash_48_8_t hash;
114 
115  // per-thread data
117 
118  // convenience
121 
122  // node index of ip6-drop node
126 
128 
130 
131 typedef enum
132 {
138 
139 typedef enum
140 {
148 
149 typedef struct
150 {
158 
159 typedef struct
160 {
161  ip6_reass_trace_operation_e action;
170 
171 static void
174 {
175  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
177  trace->range_first = vnb->ip.reass.range_first;
178  trace->range_last = vnb->ip.reass.range_last;
181  trace->range_bi = bi;
182 }
183 
184 static u8 *
185 format_ip6_reass_range_trace (u8 * s, va_list * args)
186 {
188  s = format (s, "range: [%u, %u], off %d, len %u, bi %u", trace->range_first,
189  trace->range_last, trace->data_offset, trace->data_len,
190  trace->range_bi);
191  return s;
192 }
193 
194 static u8 *
195 format_ip6_reass_trace (u8 * s, va_list * args)
196 {
197  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
198  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
199  ip6_reass_trace_t *t = va_arg (*args, ip6_reass_trace_t *);
200  s = format (s, "reass id: %u, op id: %u ", t->reass_id, t->op_id);
201  u32 indent = format_get_indent (s);
202  s = format (s, "first bi: %u, data len: %u, ip/fragment[%u, %u]",
204  t->fragment_last);
205  switch (t->action)
206  {
207  case RANGE_NEW:
208  s = format (s, "\n%Unew %U", format_white_space, indent,
210  break;
211  case RANGE_OVERLAP:
212  s = format (s, "\n%Uoverlap %U", format_white_space, indent,
214  break;
216  s = format (s, "\n%Uicmp-error - frag_len > 65535 %U",
218  &t->trace_range);
219  break;
221  s = format (s, "\n%Uicmp-error - frag_len mod 8 != 0 %U",
223  &t->trace_range);
224  break;
226  s = format (s, "\n%Uicmp-error - reassembly time exceeded",
227  format_white_space, indent);
228  break;
229  case FINALIZE:
230  s = format (s, "\n%Ufinalize reassembly", format_white_space, indent);
231  break;
232  }
233  return s;
234 }
235 
236 static void
238  ip6_reass_main_t * rm, ip6_reass_t * reass,
239  u32 bi, ip6_reass_trace_operation_e action,
240  u32 size_diff)
241 {
242  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
245  {
246  // this buffer's trace is gone
247  b->flags &= ~VLIB_BUFFER_IS_TRACED;
248  return;
249  }
250  ip6_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
251  t->reass_id = reass->id;
252  t->action = action;
253  ip6_reass_trace_details (vm, bi, &t->trace_range);
254  t->size_diff = size_diff;
255  t->op_id = reass->trace_op_counter;
256  ++reass->trace_op_counter;
257  t->fragment_first = vnb->ip.reass.fragment_first;
258  t->fragment_last = vnb->ip.reass.fragment_last;
259  t->trace_range.first_bi = reass->first_bi;
260  t->total_data_len = reass->data_len;
261 #if 0
262  static u8 *s = NULL;
263  s = format (s, "%U", format_ip6_reass_trace, NULL, NULL, t);
264  printf ("%.*s\n", vec_len (s), s);
265  fflush (stdout);
266  vec_reset_length (s);
267 #endif
268 }
269 
270 always_inline void
272  ip6_reass_t * reass)
273 {
275  kv.key[0] = reass->key.as_u64[0];
276  kv.key[1] = reass->key.as_u64[1];
277  kv.key[2] = reass->key.as_u64[2];
278  kv.key[3] = reass->key.as_u64[3];
279  kv.key[4] = reass->key.as_u64[4];
280  kv.key[5] = reass->key.as_u64[5];
281  clib_bihash_add_del_48_8 (&rm->hash, &kv, 0);
282  pool_put (rt->pool, reass);
283  --rt->reass_n;
284 }
285 
286 always_inline void
288  ip6_reass_t * reass)
289 {
290  u32 range_bi = reass->first_bi;
291  vlib_buffer_t *range_b;
292  vnet_buffer_opaque_t *range_vnb;
293  u32 *to_free = NULL;
294  while (~0 != range_bi)
295  {
296  range_b = vlib_get_buffer (vm, range_bi);
297  range_vnb = vnet_buffer (range_b);
298  u32 bi = range_bi;
299  while (~0 != bi)
300  {
301  vec_add1 (to_free, bi);
302  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
303  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
304  {
305  bi = b->next_buffer;
306  b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
307  }
308  else
309  {
310  bi = ~0;
311  }
312  }
313  range_bi = range_vnb->ip.reass.next_range_bi;
314  }
315  vlib_buffer_free (vm, to_free, vec_len (to_free));
316  vec_free (to_free);
317 }
318 
319 always_inline void
321  ip6_reass_main_t * rm, ip6_reass_t * reass,
322  u32 * icmp_bi)
323 {
324  if (~0 == reass->first_bi)
325  {
326  return;
327  }
328  vlib_buffer_t *b = vlib_get_buffer (vm, reass->first_bi);
329  if (0 == vnet_buffer (b)->ip.reass.fragment_first)
330  {
331  *icmp_bi = reass->first_bi;
332  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
333  {
334  ip6_reass_add_trace (vm, node, rm, reass, reass->first_bi,
336  }
337  // fragment with offset zero received - send icmp message back
338  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
339  {
340  // separate first buffer from chain and steer it towards icmp node
341  b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
342  reass->first_bi = b->next_buffer;
343  }
344  else
345  {
346  reass->first_bi = vnet_buffer (b)->ip.reass.next_range_bi;
347  }
348  icmp6_error_set_vnet_buffer (b, ICMP6_time_exceeded,
349  ICMP6_time_exceeded_fragment_reassembly_time_exceeded,
350  0);
351  }
352  ip6_reass_drop_all (vm, rm, reass);
353 }
354 
358  ip6_reass_key_t * k, u32 * icmp_bi)
359 {
360  ip6_reass_t *reass = NULL;
361  f64 now = vlib_time_now (rm->vlib_main);
362  clib_bihash_kv_48_8_t kv, value;
363  kv.key[0] = k->as_u64[0];
364  kv.key[1] = k->as_u64[1];
365  kv.key[2] = k->as_u64[2];
366  kv.key[3] = k->as_u64[3];
367  kv.key[4] = k->as_u64[4];
368  kv.key[5] = k->as_u64[5];
369 
370  if (!clib_bihash_search_48_8 (&rm->hash, &kv, &value))
371  {
372  reass = pool_elt_at_index (rt->pool, value.value);
373  if (now > reass->last_heard + rm->timeout)
374  {
375  ip6_reass_on_timeout (vm, node, rm, reass, icmp_bi);
376  ip6_reass_free (rm, rt, reass);
377  reass = NULL;
378  }
379  }
380 
381  if (reass)
382  {
383  reass->last_heard = now;
384  return reass;
385  }
386 
387  if (rt->reass_n >= rm->max_reass_n)
388  {
389  reass = NULL;
390  return reass;
391  }
392  else
393  {
394  pool_get (rt->pool, reass);
395  clib_memset (reass, 0, sizeof (*reass));
396  reass->id =
397  ((u64) os_get_thread_index () * 1000000000) + rt->id_counter;
398  ++rt->id_counter;
399  reass->first_bi = ~0;
400  reass->last_packet_octet = ~0;
401  reass->data_len = 0;
402  ++rt->reass_n;
403  }
404 
405  reass->key.as_u64[0] = kv.key[0] = k->as_u64[0];
406  reass->key.as_u64[1] = kv.key[1] = k->as_u64[1];
407  reass->key.as_u64[2] = kv.key[2] = k->as_u64[2];
408  reass->key.as_u64[3] = kv.key[3] = k->as_u64[3];
409  reass->key.as_u64[4] = kv.key[4] = k->as_u64[4];
410  reass->key.as_u64[5] = kv.key[5] = k->as_u64[5];
411  kv.value = reass - rt->pool;
412  reass->last_heard = now;
413 
414  if (clib_bihash_add_del_48_8 (&rm->hash, &kv, 1))
415  {
416  ip6_reass_free (rm, rt, reass);
417  reass = NULL;
418  }
419 
420  return reass;
421 }
422 
423 always_inline ip6_reass_rc_t
426  ip6_reass_t * reass, u32 * bi0, u32 * next0, u32 * error0,
427  bool is_feature)
428 {
429  *bi0 = reass->first_bi;
430  *error0 = IP6_ERROR_NONE;
431  ip6_frag_hdr_t *frag_hdr;
432  vlib_buffer_t *last_b = NULL;
433  u32 sub_chain_bi = reass->first_bi;
434  u32 total_length = 0;
435  u32 buf_cnt = 0;
436  u32 dropped_cnt = 0;
437  u32 *vec_drop_compress = NULL;
438  ip6_reass_rc_t rv = IP6_REASS_RC_OK;
439  do
440  {
441  u32 tmp_bi = sub_chain_bi;
442  vlib_buffer_t *tmp = vlib_get_buffer (vm, tmp_bi);
443  vnet_buffer_opaque_t *vnb = vnet_buffer (tmp);
444  if (!(vnb->ip.reass.range_first >= vnb->ip.reass.fragment_first) &&
445  !(vnb->ip.reass.range_last > vnb->ip.reass.fragment_first))
446  {
448  goto free_buffers_and_return;
449  }
450 
451  u32 data_len = ip6_reass_buffer_get_data_len (tmp);
452  u32 trim_front = vnet_buffer (tmp)->ip.reass.ip6_frag_hdr_offset +
453  sizeof (*frag_hdr) + ip6_reass_buffer_get_data_offset (tmp);
454  u32 trim_end =
455  vlib_buffer_length_in_chain (vm, tmp) - trim_front - data_len;
456  if (tmp_bi == reass->first_bi)
457  {
458  /* first buffer - keep ip6 header */
459  if (0 != ip6_reass_buffer_get_data_offset (tmp))
460  {
462  goto free_buffers_and_return;
463  }
464  trim_front = 0;
465  trim_end = vlib_buffer_length_in_chain (vm, tmp) - data_len -
466  (vnet_buffer (tmp)->ip.reass.ip6_frag_hdr_offset +
467  sizeof (*frag_hdr));
468  if (!(vlib_buffer_length_in_chain (vm, tmp) - trim_end > 0))
469  {
471  goto free_buffers_and_return;
472  }
473  }
474  u32 keep_data =
475  vlib_buffer_length_in_chain (vm, tmp) - trim_front - trim_end;
476  while (1)
477  {
478  ++buf_cnt;
479  if (trim_front)
480  {
481  if (trim_front > tmp->current_length)
482  {
483  /* drop whole buffer */
484  vec_add1 (vec_drop_compress, tmp_bi);
485  trim_front -= tmp->current_length;
486  if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT))
487  {
489  goto free_buffers_and_return;
490  }
491  tmp->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
492  tmp_bi = tmp->next_buffer;
493  tmp = vlib_get_buffer (vm, tmp_bi);
494  continue;
495  }
496  else
497  {
498  vlib_buffer_advance (tmp, trim_front);
499  trim_front = 0;
500  }
501  }
502  if (keep_data)
503  {
504  if (last_b)
505  {
506  last_b->flags |= VLIB_BUFFER_NEXT_PRESENT;
507  last_b->next_buffer = tmp_bi;
508  }
509  last_b = tmp;
510  if (keep_data <= tmp->current_length)
511  {
512  tmp->current_length = keep_data;
513  keep_data = 0;
514  }
515  else
516  {
517  keep_data -= tmp->current_length;
518  if (!(tmp->flags & VLIB_BUFFER_NEXT_PRESENT))
519  {
521  goto free_buffers_and_return;
522  }
523  }
524  total_length += tmp->current_length;
525  }
526  else
527  {
528  vec_add1 (vec_drop_compress, tmp_bi);
529  if (reass->first_bi == tmp_bi)
530  {
532  goto free_buffers_and_return;
533  }
534  ++dropped_cnt;
535  }
536  if (tmp->flags & VLIB_BUFFER_NEXT_PRESENT)
537  {
538  tmp_bi = tmp->next_buffer;
539  tmp = vlib_get_buffer (vm, tmp->next_buffer);
540  }
541  else
542  {
543  break;
544  }
545  }
546  sub_chain_bi =
547  vnet_buffer (vlib_get_buffer (vm, sub_chain_bi))->ip.
548  reass.next_range_bi;
549  }
550  while (~0 != sub_chain_bi);
551 
552  if (!last_b)
553  {
555  goto free_buffers_and_return;
556  }
557  last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
558  vlib_buffer_t *first_b = vlib_get_buffer (vm, reass->first_bi);
559  if (total_length < first_b->current_length)
560  {
562  goto free_buffers_and_return;
563  }
564  total_length -= first_b->current_length;
565  first_b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
566  first_b->total_length_not_including_first_buffer = total_length;
567  // drop fragment header
568  vnet_buffer_opaque_t *first_b_vnb = vnet_buffer (first_b);
569  ip6_header_t *ip = vlib_buffer_get_current (first_b);
570  u16 ip6_frag_hdr_offset = first_b_vnb->ip.reass.ip6_frag_hdr_offset;
571  ip6_ext_header_t *prev_hdr;
572  ip6_ext_header_find_t (ip, prev_hdr, frag_hdr,
573  IP_PROTOCOL_IPV6_FRAGMENTATION);
574  if (prev_hdr)
575  {
576  prev_hdr->next_hdr = frag_hdr->next_hdr;
577  }
578  else
579  {
580  ip->protocol = frag_hdr->next_hdr;
581  }
582  if (!((u8 *) frag_hdr - (u8 *) ip == ip6_frag_hdr_offset))
583  {
585  goto free_buffers_and_return;
586  }
587  memmove (frag_hdr, (u8 *) frag_hdr + sizeof (*frag_hdr),
588  first_b->current_length - ip6_frag_hdr_offset -
589  sizeof (ip6_frag_hdr_t));
590  first_b->current_length -= sizeof (*frag_hdr);
591  ip->payload_length =
592  clib_host_to_net_u16 (total_length + first_b->current_length -
593  sizeof (*ip));
594  if (!vlib_buffer_chain_linearize (vm, first_b))
595  {
596  rv = IP6_REASS_RC_NO_BUF;
597  goto free_buffers_and_return;
598  }
599  if (PREDICT_FALSE (first_b->flags & VLIB_BUFFER_IS_TRACED))
600  {
601  ip6_reass_add_trace (vm, node, rm, reass, reass->first_bi, FINALIZE, 0);
602 #if 0
603  // following code does a hexdump of packet fragments to stdout ...
604  do
605  {
606  u32 bi = reass->first_bi;
607  u8 *s = NULL;
608  while (~0 != bi)
609  {
610  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
611  s = format (s, "%u: %U\n", bi, format_hexdump,
613  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
614  {
615  bi = b->next_buffer;
616  }
617  else
618  {
619  break;
620  }
621  }
622  printf ("%.*s\n", vec_len (s), s);
623  fflush (stdout);
624  vec_free (s);
625  }
626  while (0);
627 #endif
628  }
629  if (is_feature)
630  {
631  *next0 = IP6_REASSEMBLY_NEXT_INPUT;
632  }
633  else
634  {
635  *next0 = reass->next_index;
636  }
637  vnet_buffer (first_b)->ip.reass.estimated_mtu = reass->min_fragment_length;
638  ip6_reass_free (rm, rt, reass);
639  reass = NULL;
640 free_buffers_and_return:
641  vlib_buffer_free (vm, vec_drop_compress, vec_len (vec_drop_compress));
642  vec_free (vec_drop_compress);
643  return rv;
644 }
645 
646 always_inline void
649  ip6_reass_t * reass, u32 prev_range_bi,
650  u32 new_next_bi)
651 {
652 
653  vlib_buffer_t *new_next_b = vlib_get_buffer (vm, new_next_bi);
654  vnet_buffer_opaque_t *new_next_vnb = vnet_buffer (new_next_b);
655  if (~0 != prev_range_bi)
656  {
657  vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_range_bi);
658  vnet_buffer_opaque_t *prev_vnb = vnet_buffer (prev_b);
659  new_next_vnb->ip.reass.next_range_bi = prev_vnb->ip.reass.next_range_bi;
660  prev_vnb->ip.reass.next_range_bi = new_next_bi;
661  }
662  else
663  {
664  if (~0 != reass->first_bi)
665  {
666  new_next_vnb->ip.reass.next_range_bi = reass->first_bi;
667  }
668  reass->first_bi = new_next_bi;
669  }
670  reass->data_len += ip6_reass_buffer_get_data_len (new_next_b);
671 }
672 
673 always_inline ip6_reass_rc_t
676  ip6_reass_t * reass, u32 * bi0, u32 * next0, u32 * error0,
677  ip6_frag_hdr_t * frag_hdr, bool is_feature)
678 {
679  int consumed = 0;
680  vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0);
681  vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
682  reass->next_index = fvnb->ip.reass.next_index; // store next_index before it's overwritten
683  fvnb->ip.reass.ip6_frag_hdr_offset =
684  (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb);
686  if (fb->current_length < sizeof (*fip) ||
687  fvnb->ip.reass.ip6_frag_hdr_offset == 0 ||
688  fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length)
689  {
691  }
692 
693  u32 fragment_first = fvnb->ip.reass.fragment_first =
694  ip6_frag_hdr_offset_bytes (frag_hdr);
695  u32 fragment_length =
696  vlib_buffer_length_in_chain (vm, fb) -
697  (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
698  u32 fragment_last = fvnb->ip.reass.fragment_last =
699  fragment_first + fragment_length - 1;
700  int more_fragments = ip6_frag_hdr_more (frag_hdr);
701  u32 candidate_range_bi = reass->first_bi;
702  u32 prev_range_bi = ~0;
703  fvnb->ip.reass.range_first = fragment_first;
704  fvnb->ip.reass.range_last = fragment_last;
705  fvnb->ip.reass.next_range_bi = ~0;
706  if (!more_fragments)
707  {
708  reass->last_packet_octet = fragment_last;
709  }
710  if (~0 == reass->first_bi)
711  {
712  // starting a new reassembly
713  ip6_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
714  *bi0);
715  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
716  {
717  ip6_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_NEW, 0);
718  }
719  reass->min_fragment_length = clib_net_to_host_u16 (fip->payload_length);
720  *bi0 = ~0;
721  return IP6_REASS_RC_OK;
722  }
723  reass->min_fragment_length =
724  clib_min (clib_net_to_host_u16 (fip->payload_length),
725  fvnb->ip.reass.estimated_mtu);
726  while (~0 != candidate_range_bi)
727  {
728  vlib_buffer_t *candidate_b = vlib_get_buffer (vm, candidate_range_bi);
729  vnet_buffer_opaque_t *candidate_vnb = vnet_buffer (candidate_b);
730  if (fragment_first > candidate_vnb->ip.reass.range_last)
731  {
732  // this fragments starts after candidate range
733  prev_range_bi = candidate_range_bi;
734  candidate_range_bi = candidate_vnb->ip.reass.next_range_bi;
735  if (candidate_vnb->ip.reass.range_last < fragment_last &&
736  ~0 == candidate_range_bi)
737  {
738  // special case - this fragment falls beyond all known ranges
739  ip6_reass_insert_range_in_chain (vm, rm, rt, reass,
740  prev_range_bi, *bi0);
741  consumed = 1;
742  break;
743  }
744  continue;
745  }
746  if (fragment_last < candidate_vnb->ip.reass.range_first)
747  {
748  // this fragment ends before candidate range without any overlap
749  ip6_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
750  *bi0);
751  consumed = 1;
752  }
753  else if (fragment_first == candidate_vnb->ip.reass.range_first &&
754  fragment_last == candidate_vnb->ip.reass.range_last)
755  {
756  // duplicate fragment - ignore
757  }
758  else
759  {
760  // overlapping fragment - not allowed by RFC 8200
761  ip6_reass_drop_all (vm, rm, reass);
762  ip6_reass_free (rm, rt, reass);
763  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
764  {
765  ip6_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_OVERLAP,
766  0);
767  }
768  *next0 = IP6_REASSEMBLY_NEXT_DROP;
769  *error0 = IP6_ERROR_REASS_OVERLAPPING_FRAGMENT;
770  }
771  break;
772  }
773  if (consumed)
774  {
775  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
776  {
777  ip6_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_NEW, 0);
778  }
779  }
780  if (~0 != reass->last_packet_octet &&
781  reass->data_len == reass->last_packet_octet + 1)
782  {
783  return ip6_reass_finalize (vm, node, rm, rt, reass, bi0, next0, error0,
784  is_feature);
785  }
786  else
787  {
788  if (consumed)
789  {
790  *bi0 = ~0;
791  }
792  else
793  {
794  *next0 = IP6_REASSEMBLY_NEXT_DROP;
795  ;
796  *error0 = IP6_ERROR_REASS_DUPLICATE_FRAGMENT;
797  }
798  }
799  return IP6_REASS_RC_OK;
800 }
801 
802 always_inline bool
804  vlib_buffer_t * b,
805  ip6_frag_hdr_t * frag_hdr)
806 {
807  ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
808  while (ip6_ext_hdr (tmp->next_hdr))
809  {
810  tmp = ip6_ext_next_header (tmp);
811  }
812  if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
813  {
814  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
815  ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
816  0);
817  b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
818 
819  return false;
820  }
821  return true;
822 }
823 
824 always_inline bool
826  vlib_node_runtime_t * node,
827  vlib_buffer_t * b,
828  ip6_frag_hdr_t * frag_hdr)
829 {
832  int more_fragments = ip6_frag_hdr_more (frag_hdr);
833  u32 fragment_length =
835  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
836  if (more_fragments && 0 != fragment_length % 8)
837  {
838  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
839  ICMP6_parameter_problem_erroneous_header_field,
840  (u8 *) & ip->payload_length - (u8 *) ip);
841  return false;
842  }
843  return true;
844 }
845 
846 always_inline bool
848  vlib_node_runtime_t * node,
849  vlib_buffer_t * b,
850  ip6_frag_hdr_t * frag_hdr)
851 {
853  u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
854  u32 fragment_length =
856  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
857  if (fragment_first + fragment_length > 65535)
858  {
860  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
861  ICMP6_parameter_problem_erroneous_header_field,
862  (u8 *) & frag_hdr->fragment_offset_and_more
863  - (u8 *) ip0);
864  return false;
865  }
866  return true;
867 }
868 
871  vlib_node_runtime_t * node,
872  vlib_frame_t * frame, bool is_feature)
873 {
874  u32 *from = vlib_frame_vector_args (frame);
875  u32 n_left_from, n_left_to_next, *to_next, next_index;
878  clib_spinlock_lock (&rt->lock);
879 
880  n_left_from = frame->n_vectors;
881  next_index = node->cached_next_index;
882  while (n_left_from > 0)
883  {
884  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
885 
886  while (n_left_from > 0 && n_left_to_next > 0)
887  {
888  u32 bi0;
889  vlib_buffer_t *b0;
891  u32 error0 = IP6_ERROR_NONE;
892  u32 icmp_bi = ~0;
893 
894  bi0 = from[0];
895  b0 = vlib_get_buffer (vm, bi0);
896 
898  ip6_frag_hdr_t *frag_hdr = NULL;
899  ip6_ext_header_t *prev_hdr;
900  if (ip6_ext_hdr (ip0->protocol))
901  {
902  ip6_ext_header_find_t (ip0, prev_hdr, frag_hdr,
903  IP_PROTOCOL_IPV6_FRAGMENTATION);
904  }
905  if (!frag_hdr)
906  {
907  // this is a regular packet - no fragmentation
909  goto skip_reass;
910  }
911  if (0 == ip6_frag_hdr_offset (frag_hdr))
912  {
913  // first fragment - verify upper-layer is present
914  if (!ip6_reass_verify_upper_layer_present (node, b0, frag_hdr))
915  {
917  goto skip_reass;
918  }
919  }
920  if (!ip6_reass_verify_fragment_multiple_8 (vm, node, b0, frag_hdr)
921  || !ip6_reass_verify_packet_size_lt_64k (vm, node, b0,
922  frag_hdr))
923  {
925  goto skip_reass;
926  }
927  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
928  (u8 *) frag_hdr - (u8 *) ip0;
929 
930  ip6_reass_key_t k;
931  k.as_u64[0] = ip0->src_address.as_u64[0];
932  k.as_u64[1] = ip0->src_address.as_u64[1];
933  k.as_u64[2] = ip0->dst_address.as_u64[0];
934  k.as_u64[3] = ip0->dst_address.as_u64[1];
935  k.as_u64[4] =
936  (u64) vnet_buffer (b0)->
937  sw_if_index[VLIB_RX] << 32 | frag_hdr->identification;
938  k.as_u64[5] = ip0->protocol;
939  ip6_reass_t *reass =
940  ip6_reass_find_or_create (vm, node, rm, rt, &k, &icmp_bi);
941 
942  if (reass)
943  {
944  switch (ip6_reass_update (vm, node, rm, rt, reass, &bi0, &next0,
945  &error0, frag_hdr, is_feature))
946  {
947  case IP6_REASS_RC_OK:
948  /* nothing to do here */
949  break;
950  case IP6_REASS_RC_NO_BUF:
951  /* fallthrough */
953  /* drop everything and start with a clean slate */
954  ip6_reass_drop_all (vm, rm, reass);
955  ip6_reass_free (rm, rt, reass);
956  goto next_packet;
957  break;
958  }
959  }
960  else
961  {
962  next0 = IP6_REASSEMBLY_NEXT_DROP;
963  error0 = IP6_ERROR_REASS_LIMIT_REACHED;
964  }
965 
966  b0->error = node->errors[error0];
967 
968  if (~0 != bi0)
969  {
970  skip_reass:
971  to_next[0] = bi0;
972  to_next += 1;
973  n_left_to_next -= 1;
974  if (is_feature && IP6_ERROR_NONE == error0)
975  {
976  b0 = vlib_get_buffer (vm, bi0);
977  vnet_feature_next (&next0, b0);
978  }
979  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
980  n_left_to_next, bi0, next0);
981  }
982 
983  if (~0 != icmp_bi)
984  {
986  to_next[0] = icmp_bi;
987  to_next += 1;
988  n_left_to_next -= 1;
989  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
990  n_left_to_next, icmp_bi,
991  next0);
992  }
993  next_packet:
994  from += 1;
995  n_left_from -= 1;
996  }
997 
998  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
999  }
1000 
1001  clib_spinlock_unlock (&rt->lock);
1002  return frame->n_vectors;
1003 }
1004 
1006 #define _(sym, string) string,
1008 #undef _
1009 };
1010 
1011 static uword
1013  vlib_frame_t * frame)
1014 {
1015  return ip6_reassembly_inline (vm, node, frame, false /* is_feature */ );
1016 }
1017 
1018 /* *INDENT-OFF* */
1020  .function = ip6_reassembly,
1021  .name = "ip6-reassembly",
1022  .vector_size = sizeof (u32),
1023  .format_trace = format_ip6_reass_trace,
1024  .n_errors = ARRAY_LEN (ip6_reassembly_error_strings),
1025  .error_strings = ip6_reassembly_error_strings,
1026  .n_next_nodes = IP6_REASSEMBLY_N_NEXT,
1027  .next_nodes =
1028  {
1029  [IP6_REASSEMBLY_NEXT_INPUT] = "ip6-input",
1030  [IP6_REASSEMBLY_NEXT_DROP] = "ip6-drop",
1031  [IP6_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1032  },
1033 };
1034 /* *INDENT-ON* */
1035 
1037 
1038 static uword
1040  vlib_node_runtime_t * node, vlib_frame_t * frame)
1041 {
1042  return ip6_reassembly_inline (vm, node, frame, true /* is_feature */ );
1043 }
1044 
1045 /* *INDENT-OFF* */
1047  .function = ip6_reassembly_feature,
1048  .name = "ip6-reassembly-feature",
1049  .vector_size = sizeof (u32),
1050  .format_trace = format_ip6_reass_trace,
1051  .n_errors = ARRAY_LEN (ip6_reassembly_error_strings),
1052  .error_strings = ip6_reassembly_error_strings,
1053  .n_next_nodes = IP6_REASSEMBLY_N_NEXT,
1054  .next_nodes =
1055  {
1056  [IP6_REASSEMBLY_NEXT_INPUT] = "ip6-input",
1057  [IP6_REASSEMBLY_NEXT_DROP] = "ip6-drop",
1058  [IP6_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
1059  },
1060 };
1061 /* *INDENT-ON* */
1062 
1064 
1065 /* *INDENT-OFF* */
1067  .arc_name = "ip6-unicast",
1068  .node_name = "ip6-reassembly-feature",
1069  .runs_before = VNET_FEATURES ("ip6-lookup"),
1070  .runs_after = 0,
1071 };
1072 /* *INDENT-ON* */
1073 
1074 static u32
1076 {
1078  u32 nbuckets;
1079  u8 i;
1080 
1081  nbuckets = (u32) (rm->max_reass_n / IP6_REASS_HT_LOAD_FACTOR);
1082 
1083  for (i = 0; i < 31; i++)
1084  if ((1 << i) >= nbuckets)
1085  break;
1086  nbuckets = 1 << i;
1087 
1088  return nbuckets;
1089 }
1090 
1091 typedef enum
1092 {
1095 
1096 typedef struct
1097 {
1098  int failure;
1099  clib_bihash_48_8_t *new_hash;
1101 
1102 static void
1104 {
1105  ip6_rehash_cb_ctx *ctx = _ctx;
1106  if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1))
1107  {
1108  ctx->failure = 1;
1109  }
1110 }
1111 
1112 static void
1113 ip6_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
1114  u32 expire_walk_interval_ms)
1115 {
1116  ip6_reass_main.timeout_ms = timeout_ms;
1117  ip6_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
1118  ip6_reass_main.max_reass_n = max_reassemblies;
1119  ip6_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
1120 }
1121 
1123 ip6_reass_set (u32 timeout_ms, u32 max_reassemblies,
1124  u32 expire_walk_interval_ms)
1125 {
1126  u32 old_nbuckets = ip6_reass_get_nbuckets ();
1127  ip6_reass_set_params (timeout_ms, max_reassemblies,
1128  expire_walk_interval_ms);
1129  vlib_process_signal_event (ip6_reass_main.vlib_main,
1130  ip6_reass_main.ip6_reass_expire_node_idx,
1132  u32 new_nbuckets = ip6_reass_get_nbuckets ();
1133  if (ip6_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
1134  {
1135  clib_bihash_48_8_t new_hash;
1136  clib_memset (&new_hash, 0, sizeof (new_hash));
1138  ctx.failure = 0;
1139  ctx.new_hash = &new_hash;
1140  clib_bihash_init_48_8 (&new_hash, "ip6-reass", new_nbuckets,
1141  new_nbuckets * 1024);
1142  clib_bihash_foreach_key_value_pair_48_8 (&ip6_reass_main.hash,
1143  ip6_rehash_cb, &ctx);
1144  if (ctx.failure)
1145  {
1146  clib_bihash_free_48_8 (&new_hash);
1147  return -1;
1148  }
1149  else
1150  {
1151  clib_bihash_free_48_8 (&ip6_reass_main.hash);
1152  clib_memcpy_fast (&ip6_reass_main.hash, &new_hash,
1153  sizeof (ip6_reass_main.hash));
1154  }
1155  }
1156  return 0;
1157 }
1158 
1160 ip6_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
1161  u32 * expire_walk_interval_ms)
1162 {
1163  *timeout_ms = ip6_reass_main.timeout_ms;
1164  *max_reassemblies = ip6_reass_main.max_reass_n;
1165  *expire_walk_interval_ms = ip6_reass_main.expire_walk_interval_ms;
1166  return 0;
1167 }
1168 
1169 static clib_error_t *
1171 {
1173  clib_error_t *error = 0;
1174  u32 nbuckets;
1175  vlib_node_t *node;
1176 
1177  rm->vlib_main = vm;
1178  rm->vnet_main = vnet_get_main ();
1179 
1182  vec_foreach (rt, rm->per_thread_data)
1183  {
1184  clib_spinlock_init (&rt->lock);
1185  pool_alloc (rt->pool, rm->max_reass_n);
1186  }
1187 
1188  node = vlib_get_node_by_name (vm, (u8 *) "ip6-reassembly-expire-walk");
1189  ASSERT (node);
1190  rm->ip6_reass_expire_node_idx = node->index;
1191 
1195 
1196  nbuckets = ip6_reass_get_nbuckets ();
1197  clib_bihash_init_48_8 (&rm->hash, "ip6-reass", nbuckets, nbuckets * 1024);
1198 
1199  node = vlib_get_node_by_name (vm, (u8 *) "ip6-drop");
1200  ASSERT (node);
1201  rm->ip6_drop_idx = node->index;
1202  node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error");
1203  ASSERT (node);
1204  rm->ip6_icmp_error_idx = node->index;
1205 
1206  if ((error = vlib_call_init_function (vm, ip_main_init)))
1207  return error;
1208  ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
1209  ip6_reass_node.index);
1210 
1211  return error;
1212 }
1213 
1215 
1216 static uword
1218  vlib_node_runtime_t * node, vlib_frame_t * f)
1219 {
1221  uword event_type, *event_data = 0;
1222 
1223  while (true)
1224  {
1227  / (f64) MSEC_PER_SEC);
1228  event_type = vlib_process_get_events (vm, &event_data);
1229 
1230  switch (event_type)
1231  {
1232  case ~0: /* no events => timeout */
1233  /* nothing to do here */
1234  break;
1236  break;
1237  default:
1238  clib_warning ("BUG: event type 0x%wx", event_type);
1239  break;
1240  }
1241  f64 now = vlib_time_now (vm);
1242 
1243  ip6_reass_t *reass;
1244  int *pool_indexes_to_free = NULL;
1245 
1246  uword thread_index = 0;
1247  int index;
1248  const uword nthreads = vlib_num_workers () + 1;
1249  u32 *vec_icmp_bi = NULL;
1250  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1251  {
1252  ip6_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1253  clib_spinlock_lock (&rt->lock);
1254 
1255  vec_reset_length (pool_indexes_to_free);
1256  /* *INDENT-OFF* */
1257  pool_foreach_index (index, rt->pool, ({
1258  reass = pool_elt_at_index (rt->pool, index);
1259  if (now > reass->last_heard + rm->timeout)
1260  {
1261  vec_add1 (pool_indexes_to_free, index);
1262  }
1263  }));
1264  /* *INDENT-ON* */
1265  int *i;
1266  /* *INDENT-OFF* */
1267  vec_foreach (i, pool_indexes_to_free)
1268  {
1269  ip6_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1270  u32 icmp_bi = ~0;
1271  vlib_buffer_t *b = vlib_get_buffer (vm, reass->first_bi);
1272  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
1273  {
1275  b->trace_index))
1276  {
1277  /* the trace is gone, don't trace this buffer anymore */
1278  b->flags &= ~VLIB_BUFFER_IS_TRACED;
1279  }
1280  }
1281  ip6_reass_on_timeout (vm, node, rm, reass, &icmp_bi);
1282  if (~0 != icmp_bi)
1283  {
1284  vec_add1 (vec_icmp_bi, icmp_bi);
1285  }
1286  ip6_reass_free (rm, rt, reass);
1287  }
1288  /* *INDENT-ON* */
1289 
1290  clib_spinlock_unlock (&rt->lock);
1291  }
1292 
1293  while (vec_len (vec_icmp_bi) > 0)
1294  {
1295  vlib_frame_t *f =
1297  u32 *to_next = vlib_frame_vector_args (f);
1298  u32 n_left_to_next = VLIB_FRAME_SIZE - f->n_vectors;
1299  int trace_frame = 0;
1300  while (vec_len (vec_icmp_bi) > 0 && n_left_to_next > 0)
1301  {
1302  u32 bi = vec_pop (vec_icmp_bi);
1303  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1304  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
1305  {
1307  b->trace_index))
1308  {
1309  /* the trace is gone, don't trace this buffer anymore */
1310  b->flags &= ~VLIB_BUFFER_IS_TRACED;
1311  }
1312  else
1313  {
1314  trace_frame = 1;
1315  }
1316  }
1317  b->error = node->errors[IP6_ERROR_REASS_TIMEOUT];
1318  to_next[0] = bi;
1319  ++f->n_vectors;
1320  to_next += 1;
1321  n_left_to_next -= 1;
1322  }
1323  f->frame_flags |= (trace_frame * VLIB_FRAME_TRACE);
1325  }
1326 
1327  vec_free (pool_indexes_to_free);
1328  vec_free (vec_icmp_bi);
1329  if (event_data)
1330  {
1331  _vec_len (event_data) = 0;
1332  }
1333  }
1334 
1335  return 0;
1336 }
1337 
1339 
1340 /* *INDENT-OFF* */
1342  .function = ip6_reass_walk_expired,
1343  .format_trace = format_ip6_reass_trace,
1344  .type = VLIB_NODE_TYPE_PROCESS,
1345  .name = "ip6-reassembly-expire-walk",
1346 
1348  .error_strings = ip6_reassembly_error_strings,
1349 
1350 };
1351 /* *INDENT-ON* */
1352 
1353 static u8 *
1354 format_ip6_reass_key (u8 * s, va_list * args)
1355 {
1356  ip6_reass_key_t *key = va_arg (*args, ip6_reass_key_t *);
1357  s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1359  &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1360  return s;
1361 }
1362 
1363 static u8 *
1364 format_ip6_reass (u8 * s, va_list * args)
1365 {
1366  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1367  ip6_reass_t *reass = va_arg (*args, ip6_reass_t *);
1368 
1369  s = format (s, "ID: %lu, key: %U\n first_bi: %u, data_len: %u, "
1370  "last_packet_octet: %u, trace_op_counter: %u\n",
1371  reass->id, format_ip6_reass_key, &reass->key, reass->first_bi,
1372  reass->data_len, reass->last_packet_octet,
1373  reass->trace_op_counter);
1374  u32 bi = reass->first_bi;
1375  u32 counter = 0;
1376  while (~0 != bi)
1377  {
1378  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1379  vnet_buffer_opaque_t *vnb = vnet_buffer (b);
1380  s = format (s, " #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, "
1381  "fragment[%u, %u]\n",
1382  counter, vnb->ip.reass.range_first,
1383  vnb->ip.reass.range_last, bi,
1386  vnb->ip.reass.fragment_first, vnb->ip.reass.fragment_last);
1387  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
1388  {
1389  bi = b->next_buffer;
1390  }
1391  else
1392  {
1393  bi = ~0;
1394  }
1395  }
1396  return s;
1397 }
1398 
1399 static clib_error_t *
1402 {
1404 
1405  vlib_cli_output (vm, "---------------------");
1406  vlib_cli_output (vm, "IP6 reassembly status");
1407  vlib_cli_output (vm, "---------------------");
1408  bool details = false;
1409  if (unformat (input, "details"))
1410  {
1411  details = true;
1412  }
1413 
1414  u32 sum_reass_n = 0;
1415  u64 sum_buffers_n = 0;
1416  ip6_reass_t *reass;
1417  uword thread_index;
1418  const uword nthreads = vlib_num_workers () + 1;
1419  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1420  {
1421  ip6_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1422  clib_spinlock_lock (&rt->lock);
1423  if (details)
1424  {
1425  /* *INDENT-OFF* */
1426  pool_foreach (reass, rt->pool, {
1427  vlib_cli_output (vm, "%U", format_ip6_reass, vm, reass);
1428  });
1429  /* *INDENT-ON* */
1430  }
1431  sum_reass_n += rt->reass_n;
1432  clib_spinlock_unlock (&rt->lock);
1433  }
1434  vlib_cli_output (vm, "---------------------");
1435  vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1436  (long unsigned) sum_reass_n);
1437  vlib_cli_output (vm, "Maximum configured concurrent IP6 reassemblies per "
1438  "worker-thread: %lu\n", (long unsigned) rm->max_reass_n);
1439  vlib_cli_output (vm, "Buffers in use: %lu\n",
1440  (long unsigned) sum_buffers_n);
1441  return 0;
1442 }
1443 
1444 /* *INDENT-OFF* */
1446  .path = "show ip6-reassembly",
1447  .short_help = "show ip6-reassembly [details]",
1448  .function = show_ip6_reass,
1449 };
1450 /* *INDENT-ON* */
1451 
1454 {
1455  return vnet_feature_enable_disable ("ip6-unicast", "ip6-reassembly-feature",
1456  sw_if_index, enable_disable, 0, 0);
1457 }
1458 
1459 /*
1460  * fd.io coding-style-patch-verification: ON
1461  *
1462  * Local Variables:
1463  * eval: (c-set-style "gnu")
1464  * End:
1465  */
#define IP6_REASS_TIMEOUT_DEFAULT_MS
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
u32 trace_op_counter
static void ip6_reass_drop_all(vlib_main_t *vm, ip6_reass_main_t *rm, ip6_reass_t *reass)
static ip6_reass_rc_t ip6_reass_update(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_reass_main_t *rm, ip6_reass_per_thread_t *rt, ip6_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, ip6_frag_hdr_t *frag_hdr, bool is_feature)
vnet_api_error_t
Definition: api_errno.h:150
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:862
#define clib_min(x, y)
Definition: clib.h:295
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:89
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:74
#define CLIB_UNUSED(x)
Definition: clib.h:82
ip6_reass_next_t
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:673
vnet_main_t * vnet_main
static uword ip6_reassembly(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1461
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:529
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
Definition: pool.h:341
u64 as_u64
Definition: bihash_doc.h:63
IPv6 Reassembly.
#define IP6_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
u64 as_u64[2]
Definition: ip6_packet.h:51
unsigned long u64
Definition: types.h:89
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:304
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:232
static clib_error_t * ip6_reass_init_function(vlib_main_t *vm)
static vlib_node_registration_t ip6_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip6_reass_expire_node)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:525
ip6_reass_trace_operation_e action
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
Definition: ip6_packet.h:525
int i
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
ip6_reass_event_t
ip6_reass_per_thread_t * per_thread_data
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:493
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:267
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
ip6_address_t src_address
Definition: ip6_packet.h:378
static void ip6_reass_trace_details(vlib_main_t *vm, u32 bi, ip6_reass_range_trace_t *trace)
unsigned char u8
Definition: types.h:56
VLIB_NODE_FUNCTION_MULTIARCH(ip6_reass_node, ip6_reassembly)
#define vec_pop(V)
Returns last element of a vector and decrements its length.
Definition: vec.h:619
static u16 ip6_reass_buffer_get_data_len(vlib_buffer_t *b)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define IP6_REASS_HT_LOAD_FACTOR
double f64
Definition: types.h:142
static u32 ip6_reass_get_nbuckets()
vlib_trace_header_t ** trace_buffer_pool
Definition: trace.h:72
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:490
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
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:516
static void ip6_reass_free(ip6_reass_main_t *rm, ip6_reass_per_thread_t *rt, ip6_reass_t *reass)
u32 sw_if_index
Definition: vxlan_gbp.api:37
#define always_inline
Definition: clib.h:98
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:181
vnet_api_error_t ip6_reass_set(u32 timeout_ms, u32 max_reassemblies, u32 expire_walk_interval_ms)
set ip6 reassembly configuration
clib_bihash_48_8_t hash
static u8 * format_ip6_reass_range_trace(u8 *s, va_list *args)
unsigned int u32
Definition: types.h:88
#define vlib_call_init_function(vm, x)
Definition: init.h:260
#define VLIB_FRAME_SIZE
Definition: node.h:401
ip6_reass_main_t ip6_reass_main
static ip6_reass_t * ip6_reass_find_or_create(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_reass_main_t *rm, ip6_reass_per_thread_t *rt, ip6_reass_key_t *k, u32 *icmp_bi)
void icmp6_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
Definition: icmp6.c:446
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:57
static char * ip6_reassembly_error_strings[]
#define ip6_frag_hdr_more(hdr)
Definition: ip6_packet.h:579
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
ip6_reass_key_t key
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:114
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
u16 frame_flags
Definition: node.h:408
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:190
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:214
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
#define PREDICT_FALSE(x)
Definition: clib.h:111
static bool ip6_reass_verify_packet_size_lt_64k(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
static u32 ip6_reass_buffer_get_data_offset(vlib_buffer_t *b)
#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:218
ip6_reass_range_trace_t trace_range
#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:338
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:139
VNET_FEATURE_INIT(ip6_reassembly_feature, static)
static vlib_cli_command_t show_ip6_reassembly_cmd
(constructor) VLIB_CLI_COMMAND (show_ip6_reassembly_cmd)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
u16 n_vectors
Definition: node.h:420
static vlib_node_registration_t ip6_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip6_reass_node_feature)
format_function_t format_ip6_address
Definition: format.h:93
vlib_main_t * vm
Definition: buffer.c:301
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:295
#define clib_warning(format, args...)
Definition: error.h:59
static void ip6_rehash_cb(clib_bihash_kv_48_8_t *kv, void *_ctx)
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:281
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
#define ip6_frag_hdr_offset_bytes(hdr)
Definition: ip6_packet.h:576
#define ARRAY_LEN(x)
Definition: clib.h:62
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:452
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
ip6_reass_rc_t
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:509
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
signed int i32
Definition: types.h:77
static bool ip6_reass_verify_fragment_multiple_8(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
#define ip6_frag_hdr_offset(hdr)
Definition: ip6_packet.h:573
clib_spinlock_t lock
static u8 * format_ip6_reass_key(u8 *s, va_list *args)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:537
static uword ip6_reassembly_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
#define ASSERT(truth)
static ip6_reass_rc_t ip6_reass_finalize(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_reass_main_t *rm, ip6_reass_per_thread_t *rt, ip6_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, bool is_feature)
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:130
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:233
vlib_trace_main_t trace_main
Definition: main.h:135
static clib_error_t * show_ip6_reass(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
u16 min_fragment_length
#define VNET_FEATURES(...)
Definition: feature.h:435
vlib_main_t * vlib_main
static void ip6_reass_insert_range_in_chain(vlib_main_t *vm, ip6_reass_main_t *rm, ip6_reass_per_thread_t *rt, ip6_reass_t *reass, u32 prev_range_bi, u32 new_next_bi)
static u8 * format_ip6_reass_trace(u8 *s, va_list *args)
u32 last_packet_octet
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
static u8 * format_ip6_reass(u8 *s, va_list *args)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:156
struct _vlib_node_registration vlib_node_registration_t
static void ip6_reass_on_timeout(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_reass_main_t *rm, ip6_reass_t *reass, u32 *icmp_bi)
u16 payload_length
Definition: ip6_packet.h:369
#define MSEC_PER_SEC
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword ip6_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
u64 uword
Definition: types.h:112
static void ip6_reass_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_reass_main_t *rm, ip6_reass_t *reass, u32 bi, ip6_reass_trace_operation_e action, u32 size_diff)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
ip6_reass_trace_operation_e
#define VLIB_FRAME_TRACE
Definition: node.h:458
static_always_inline uword os_get_thread_index(void)
Definition: os.h:62
#define foreach_ip6_error
Definition: ip6_error.h:43
#define IP6_REASS_MAX_REASSEMBLIES_DEFAULT
vnet_api_error_t ip6_reass_get(u32 *timeout_ms, u32 *max_reassemblies, u32 *expire_walk_interval_ms)
get ip6 reassembly configuration
#define vnet_buffer(b)
Definition: buffer.h:368
clib_bihash_48_8_t * new_hash
static u32 vlib_num_workers()
Definition: threads.h:366
static vlib_node_registration_t ip6_reass_node
(constructor) VLIB_REGISTER_NODE (ip6_reass_node)
static uword ip6_reassembly_feature(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define vec_foreach(var, vec)
Vector iterator.
vnet_api_error_t ip6_reass_enable_disable(u32 sw_if_index, u8 enable_disable)
#define ip6_ext_header_find_t(i, p, m, t)
Definition: ip6_packet.h:534
static void ip6_reass_set_params(u32 timeout_ms, u32 max_reassemblies, u32 expire_walk_interval_ms)
static bool ip6_reass_verify_upper_layer_present(vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
ip6_address_t dst
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:535
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:117
ip6_address_t src
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62
u32 trace_index
Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is set.
Definition: buffer.h:151
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
Definition: defs.h:46
struct vnet_buffer_opaque_t::@56::@58 ip
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: feature.c:274
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
ip6_address_t dst_address
Definition: ip6_packet.h:378