FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
ip4_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 IPv4 Reassembly.
19  *
20  * This file contains the source code for IPv4 reassembly.
21  */
22 
23 #include <vppinfra/vec.h>
24 #include <vnet/vnet.h>
25 #include <vnet/ip/ip.h>
26 #include <vppinfra/bihash_24_8.h>
27 #include <vnet/ip/ip4_reassembly.h>
28 
29 #define MSEC_PER_SEC 1000
30 #define IP4_REASS_TIMEOUT_DEFAULT_MS 100
31 #define IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
32 #define IP4_REASS_MAX_REASSEMBLIES_DEFAULT 1024
33 #define IP4_REASS_HT_LOAD_FACTOR (0.75)
34 
35 #define IP4_REASS_DEBUG_BUFFERS 0
36 #if IP4_REASS_DEBUG_BUFFERS
37 #define IP4_REASS_DEBUG_BUFFER(bi, what) \
38  do \
39  { \
40  u32 _bi = bi; \
41  printf (#what "buffer %u", _bi); \
42  vlib_buffer_t *_b = vlib_get_buffer (vm, _bi); \
43  while (_b->flags & VLIB_BUFFER_NEXT_PRESENT) \
44  { \
45  _bi = _b->next_buffer; \
46  printf ("[%u]", _bi); \
47  _b = vlib_get_buffer (vm, _bi); \
48  } \
49  printf ("\n"); \
50  fflush (stdout); \
51  } \
52  while (0)
53 #else
54 #define IP4_REASS_DEBUG_BUFFER(...)
55 #endif
56 
58 
59 typedef struct
60 {
61  union
62  {
63  struct
64  {
65  // align by making this 4 octets even though its a 2 octets field
69  // align by making this 4 octets even though its a 2 octets field
71  // align by making this 4 octets even though its a 1 octet field
74  };
75  u64 as_u64[3];
76  };
78 
81 {
83  return vnb->ip.reass.range_first - vnb->ip.reass.fragment_first;
84 }
85 
88 {
90  ASSERT (vnb->ip.reass.range_first >= vnb->ip.reass.fragment_first);
92 }
93 
96 {
98  return clib_min (vnb->ip.reass.range_last, vnb->ip.reass.fragment_last) -
99  (vnb->ip.reass.fragment_first + ip4_reass_buffer_get_data_offset (b)) + 1;
100 }
101 
104 {
106  ASSERT (vnb->ip.reass.range_last > vnb->ip.reass.fragment_first);
108 }
109 
110 typedef struct
111 {
112  // hash table key
114  // time when last packet was received
116  // internal id of this reassembly
118  // buffer index of first buffer in this reassembly context
120  // last octet of packet, ~0 until fragment without more_fragments arrives
122  // length of data collected so far
124  // trace operation counter
126  // next index - used by non-feature node
128  // minimum fragment length for this reassembly - used to estimate MTU
130 } ip4_reass_t;
131 
132 typedef struct
133 {
140 
141 typedef struct
142 {
143  // IPv4 config
148 
149  // IPv4 runtime
150  clib_bihash_24_8_t hash;
151  // per-thread data
153 
154  // convenience
157 
158  // node index of ip4-drop node
162 
164 
165 typedef enum
166 {
171 
172 typedef enum
173 {
180 
181 typedef struct
182 {
190 
191 typedef struct
192 {
193  ip4_reass_trace_operation_e action;
202 
203 static void
206 {
207  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
209  trace->range_first = vnb->ip.reass.range_first;
210  trace->range_last = vnb->ip.reass.range_last;
213  trace->range_bi = bi;
214 }
215 
216 static u8 *
217 format_ip4_reass_range_trace (u8 * s, va_list * args)
218 {
220  s = format (s, "range: [%u, %u], off %d, len %u, bi %u", trace->range_first,
221  trace->range_last, trace->data_offset, trace->data_len,
222  trace->range_bi);
223  return s;
224 }
225 
226 u8 *
227 format_ip4_reass_trace (u8 * s, va_list * args)
228 {
229  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
230  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
231  ip4_reass_trace_t *t = va_arg (*args, ip4_reass_trace_t *);
232  s = format (s, "reass id: %u, op id: %u ", t->reass_id, t->op_id);
233  u32 indent = format_get_indent (s);
234  s = format (s, "first bi: %u, data len: %u, ip/fragment[%u, %u]",
236  t->fragment_last);
237  switch (t->action)
238  {
239  case RANGE_SHRINK:
240  s = format (s, "\n%Ushrink %U by %u", format_white_space, indent,
242  t->size_diff);
243  break;
244  case RANGE_DISCARD:
245  s = format (s, "\n%Udiscard %U", format_white_space, indent,
247  break;
248  case RANGE_NEW:
249  s = format (s, "\n%Unew %U", format_white_space, indent,
251  break;
252  case RANGE_OVERLAP:
253  s = format (s, "\n%Uoverlapping/ignored %U", format_white_space, indent,
255  break;
256  case FINALIZE:
257  s = format (s, "\n%Ufinalize reassembly", format_white_space, indent);
258  break;
259  }
260  return s;
261 }
262 
263 static void
265  ip4_reass_main_t * rm, ip4_reass_t * reass, u32 bi,
266  ip4_reass_trace_operation_e action, u32 size_diff)
267 {
268  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
271  {
272  // this buffer's trace is gone
273  b->flags &= ~VLIB_BUFFER_IS_TRACED;
274  return;
275  }
276  ip4_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
277  t->reass_id = reass->id;
278  t->action = action;
279  ip4_reass_trace_details (vm, bi, &t->trace_range);
280  t->size_diff = size_diff;
281  t->op_id = reass->trace_op_counter;
282  ++reass->trace_op_counter;
283  t->fragment_first = vnb->ip.reass.fragment_first;
284  t->fragment_last = vnb->ip.reass.fragment_last;
285  t->trace_range.first_bi = reass->first_bi;
286  t->total_data_len = reass->data_len;
287 #if 0
288  static u8 *s = NULL;
289  s = format (s, "%U", format_ip4_reass_trace, NULL, NULL, t);
290  printf ("%.*s\n", vec_len (s), s);
291  fflush (stdout);
292  vec_reset_length (s);
293 #endif
294 }
295 
296 always_inline void
298  ip4_reass_t * reass)
299 {
301  kv.key[0] = reass->key.as_u64[0];
302  kv.key[1] = reass->key.as_u64[1];
303  kv.key[2] = reass->key.as_u64[2];
304  clib_bihash_add_del_24_8 (&rm->hash, &kv, 0);
305  pool_put (rt->pool, reass);
306  --rt->reass_n;
307 }
308 
309 always_inline void
311  ip4_reass_t * reass, u32 ** vec_drop_timeout)
312 {
313  u32 range_bi = reass->first_bi;
314  vlib_buffer_t *range_b;
315  vnet_buffer_opaque_t *range_vnb;
316  while (~0 != range_bi)
317  {
318  range_b = vlib_get_buffer (vm, range_bi);
319  range_vnb = vnet_buffer (range_b);
320  u32 bi = range_bi;
321  while (~0 != bi)
322  {
323  vec_add1 (*vec_drop_timeout, bi);
324  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
325  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
326  {
327  bi = b->next_buffer;
328  b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
329  }
330  else
331  {
332  bi = ~0;
333  }
334  }
335  range_bi = range_vnb->ip.reass.next_range_bi;
336  }
337 }
338 
339 ip4_reass_t *
342  ip4_reass_key_t * k, u32 ** vec_drop_timeout)
343 {
344  ip4_reass_t *reass = NULL;
345  f64 now = vlib_time_now (rm->vlib_main);
346  clib_bihash_kv_24_8_t kv, value;
347  kv.key[0] = k->as_u64[0];
348  kv.key[1] = k->as_u64[1];
349  kv.key[2] = k->as_u64[2];
350 
351  if (!clib_bihash_search_24_8 (&rm->hash, &kv, &value))
352  {
353  reass = pool_elt_at_index (rt->pool, value.value);
354  if (now > reass->last_heard + rm->timeout)
355  {
356  ip4_reass_on_timeout (vm, rm, reass, vec_drop_timeout);
357  ip4_reass_free (rm, rt, reass);
358  reass = NULL;
359  }
360  }
361 
362  if (reass)
363  {
364  reass->last_heard = now;
365  return reass;
366  }
367 
368  if (rt->reass_n >= rm->max_reass_n)
369  {
370  reass = NULL;
371  return reass;
372  }
373  else
374  {
375  pool_get (rt->pool, reass);
376  memset (reass, 0, sizeof (*reass));
377  reass->id =
378  ((u64) os_get_thread_index () * 1000000000) + rt->id_counter;
379  ++rt->id_counter;
380  reass->first_bi = ~0;
381  reass->last_packet_octet = ~0;
382  reass->data_len = 0;
383  ++rt->reass_n;
384  }
385 
386  reass->key.as_u64[0] = kv.key[0] = k->as_u64[0];
387  reass->key.as_u64[1] = kv.key[1] = k->as_u64[1];
388  reass->key.as_u64[2] = kv.key[2] = k->as_u64[2];
389  kv.value = reass - rt->pool;
390  reass->last_heard = now;
391 
392  if (clib_bihash_add_del_24_8 (&rm->hash, &kv, 1))
393  {
394  ip4_reass_free (rm, rt, reass);
395  reass = NULL;
396  }
397 
398  return reass;
399 }
400 
401 always_inline void
404  ip4_reass_t * reass, u32 * bi0, u32 * next0,
405  u32 * error0, u32 ** vec_drop_compress,
406  u32 ** vec_drop_overlap, bool is_feature)
407 {
408  ASSERT (~0 != reass->first_bi);
409  vlib_buffer_t *first_b = vlib_get_buffer (vm, reass->first_bi);
410  vlib_buffer_t *last_b = NULL;
411  u32 sub_chain_bi = reass->first_bi;
412  u32 total_length = 0;
413  u32 buf_cnt = 0;
414  u32 dropped_cnt = 0;
415  do
416  {
417  u32 tmp_bi = sub_chain_bi;
418  vlib_buffer_t *tmp = vlib_get_buffer (vm, tmp_bi);
420  u32 data_len = ip4_reass_buffer_get_data_len (tmp);
421  u32 trim_front =
423  u32 trim_end =
424  vlib_buffer_length_in_chain (vm, tmp) - trim_front - data_len;
425  if (tmp_bi == reass->first_bi)
426  {
427  /* first buffer - keep ip4 header */
429  trim_front = 0;
430  trim_end = vlib_buffer_length_in_chain (vm, tmp) - data_len -
431  ip4_header_bytes (ip);
432  ASSERT (vlib_buffer_length_in_chain (vm, tmp) - trim_end > 0);
433  }
434  u32 keep_data =
435  vlib_buffer_length_in_chain (vm, tmp) - trim_front - trim_end;
436  while (1)
437  {
438  ++buf_cnt;
439  if (trim_front)
440  {
441  if (trim_front > tmp->current_length)
442  {
443  /* drop whole buffer */
444  vec_add1 (*vec_drop_compress, tmp_bi);
445  ++dropped_cnt;
446  trim_front -= tmp->current_length;
447  ASSERT (tmp->flags & VLIB_BUFFER_NEXT_PRESENT);
448  tmp->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
449  tmp_bi = tmp->next_buffer;
450  tmp = vlib_get_buffer (vm, tmp_bi);
451  continue;
452  }
453  else
454  {
455  vlib_buffer_advance (tmp, trim_front);
456  trim_front = 0;
457  }
458  }
459  if (keep_data)
460  {
461  if (last_b)
462  {
463  last_b->flags |= VLIB_BUFFER_NEXT_PRESENT;
464  last_b->next_buffer = tmp_bi;
465  }
466  last_b = tmp;
467  if (keep_data <= tmp->current_length)
468  {
469  tmp->current_length = keep_data;
470  keep_data = 0;
471  }
472  else
473  {
474  keep_data -= tmp->current_length;
475  ASSERT (tmp->flags & VLIB_BUFFER_NEXT_PRESENT);
476  }
477  total_length += tmp->current_length;
478  }
479  else
480  {
481  vec_add1 (*vec_drop_overlap, tmp_bi);
482  ASSERT (reass->first_bi != tmp_bi);
483  ++dropped_cnt;
484  }
485  if (tmp->flags & VLIB_BUFFER_NEXT_PRESENT)
486  {
487  tmp_bi = tmp->next_buffer;
488  tmp = vlib_get_buffer (vm, tmp->next_buffer);
489  }
490  else
491  {
492  break;
493  }
494  }
495  sub_chain_bi =
496  vnet_buffer (vlib_get_buffer (vm, sub_chain_bi))->ip.
497  reass.next_range_bi;
498  }
499  while (~0 != sub_chain_bi);
500 
501  ASSERT (last_b != NULL);
502  last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
503  ASSERT (rt->buffers_n >= (buf_cnt - dropped_cnt));
504  rt->buffers_n -= buf_cnt - dropped_cnt;
505  ASSERT (total_length >= first_b->current_length);
506  total_length -= first_b->current_length;
507  first_b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
508  first_b->total_length_not_including_first_buffer = total_length;
509  ip4_header_t *ip = vlib_buffer_get_current (first_b);
511  ip->length = clib_host_to_net_u16 (first_b->current_length + total_length);
512  ip->checksum = ip4_header_checksum (ip);
513  vlib_buffer_chain_compress (vm, first_b, vec_drop_compress);
514  if (PREDICT_FALSE (first_b->flags & VLIB_BUFFER_IS_TRACED))
515  {
516  ip4_reass_add_trace (vm, node, rm, reass, reass->first_bi, FINALIZE, 0);
517 #if 0
518  // following code does a hexdump of packet fragments to stdout ...
519  do
520  {
521  u32 bi = reass->first_bi;
522  u8 *s = NULL;
523  while (~0 != bi)
524  {
525  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
526  s = format (s, "%u: %U\n", bi, format_hexdump,
528  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
529  {
530  bi = b->next_buffer;
531  }
532  else
533  {
534  break;
535  }
536  }
537  printf ("%.*s\n", vec_len (s), s);
538  fflush (stdout);
539  vec_free (s);
540  }
541  while (0);
542 #endif
543  }
544  *bi0 = reass->first_bi;
545  if (is_feature)
546  {
547  *next0 = IP4_REASSEMBLY_NEXT_INPUT;
548  }
549  else
550  {
551  *next0 = reass->next_index;
552  }
553  vnet_buffer (first_b)->ip.reass.estimated_mtu = reass->min_fragment_length;
554  *error0 = IP4_ERROR_NONE;
555  ip4_reass_free (rm, rt, reass);
556  reass = NULL;
557 }
558 
561 {
562  u32 len = 0;
563  while (b)
564  {
565  ++len;
566  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_NEXT_PRESENT))
567  {
568  b = vlib_get_buffer (vm, b->next_buffer);
569  }
570  else
571  {
572  break;
573  }
574  }
575  return len;
576 }
577 
578 always_inline void
580  ip4_reass_main_t * rm,
582  ip4_reass_t * reass,
583  u32 prev_range_bi, u32 new_next_bi)
584 {
585 
586  vlib_buffer_t *new_next_b = vlib_get_buffer (vm, new_next_bi);
587  vnet_buffer_opaque_t *new_next_vnb = vnet_buffer (new_next_b);
588  if (~0 != prev_range_bi)
589  {
590  vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_range_bi);
591  vnet_buffer_opaque_t *prev_vnb = vnet_buffer (prev_b);
592  new_next_vnb->ip.reass.next_range_bi = prev_vnb->ip.reass.next_range_bi;
593  prev_vnb->ip.reass.next_range_bi = new_next_bi;
594  }
595  else
596  {
597  if (~0 != reass->first_bi)
598  {
599  new_next_vnb->ip.reass.next_range_bi = reass->first_bi;
600  }
601  reass->first_bi = new_next_bi;
602  }
603  reass->data_len += ip4_reass_buffer_get_data_len (new_next_b);
604  rt->buffers_n += ip4_reass_get_buffer_chain_length (vm, new_next_b);
605 }
606 
607 always_inline void
609  vlib_node_runtime_t * node,
610  ip4_reass_main_t * rm,
611  u32 ** vec_drop_overlap,
612  ip4_reass_t * reass, u32 prev_range_bi,
613  u32 discard_bi)
614 {
615  vlib_buffer_t *discard_b = vlib_get_buffer (vm, discard_bi);
616  vnet_buffer_opaque_t *discard_vnb = vnet_buffer (discard_b);
617  if (~0 != prev_range_bi)
618  {
619  vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_range_bi);
620  vnet_buffer_opaque_t *prev_vnb = vnet_buffer (prev_b);
621  ASSERT (prev_vnb->ip.reass.next_range_bi == discard_bi);
622  prev_vnb->ip.reass.next_range_bi = discard_vnb->ip.reass.next_range_bi;
623  }
624  else
625  {
626  reass->first_bi = discard_vnb->ip.reass.next_range_bi;
627  }
628  reass->data_len -= ip4_reass_buffer_get_data_len (discard_b);
629  while (1)
630  {
631  vec_add1 (*vec_drop_overlap, discard_bi);
632  if (PREDICT_FALSE (discard_b->flags & VLIB_BUFFER_IS_TRACED))
633  {
634  ip4_reass_add_trace (vm, node, rm, reass, discard_bi, RANGE_DISCARD,
635  0);
636  }
637  if (discard_b->flags & VLIB_BUFFER_NEXT_PRESENT)
638  {
639  discard_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
640  discard_bi = discard_b->next_buffer;
641  discard_b = vlib_get_buffer (vm, discard_bi);
642  }
643  else
644  {
645  break;
646  }
647  }
648 }
649 
650 always_inline void
653  ip4_reass_t * reass, u32 * bi0, u32 * next0,
654  u32 * error0, u32 ** vec_drop_overlap,
655  u32 ** vec_drop_compress, bool is_feature)
656 {
657  int consumed = 0;
658  vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0);
660  ASSERT (fb->current_length >= sizeof (*fip));
661  vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
662  u32 fragment_first = fvnb->ip.reass.fragment_first =
664  u32 fragment_length =
665  clib_net_to_host_u16 (fip->length) - ip4_header_bytes (fip);
666  u32 fragment_last = fvnb->ip.reass.fragment_last =
667  fragment_first + fragment_length - 1;
668  int more_fragments = ip4_get_fragment_more (fip);
669  u32 candidate_range_bi = reass->first_bi;
670  u32 prev_range_bi = ~0;
671  reass->next_index = fvnb->ip.reass.next_index; // store next_index before it's overwritten
672  fvnb->ip.reass.range_first = fragment_first;
673  fvnb->ip.reass.range_last = fragment_last;
674  fvnb->ip.reass.next_range_bi = ~0;
675  if (!more_fragments)
676  {
677  reass->last_packet_octet = fragment_last;
678  }
679  if (~0 == reass->first_bi)
680  {
681  // starting a new reassembly
682  ip4_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
683  *bi0);
684  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
685  {
686  ip4_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_NEW, 0);
687  }
688  *bi0 = ~0;
689  reass->min_fragment_length = clib_net_to_host_u16 (fip->length);
690  return;
691  }
692  reass->min_fragment_length = clib_min (clib_net_to_host_u16 (fip->length),
693  fvnb->ip.reass.estimated_mtu);
694  while (~0 != candidate_range_bi)
695  {
696  vlib_buffer_t *candidate_b = vlib_get_buffer (vm, candidate_range_bi);
697  vnet_buffer_opaque_t *candidate_vnb = vnet_buffer (candidate_b);
698  if (fragment_first > candidate_vnb->ip.reass.range_last)
699  {
700  // this fragments starts after candidate range
701  prev_range_bi = candidate_range_bi;
702  candidate_range_bi = candidate_vnb->ip.reass.next_range_bi;
703  if (candidate_vnb->ip.reass.range_last < fragment_last &&
704  ~0 == candidate_range_bi)
705  {
706  // special case - this fragment falls beyond all known ranges
707  ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
708  prev_range_bi, *bi0);
709  consumed = 1;
710  break;
711  }
712  continue;
713  }
714  if (fragment_last < candidate_vnb->ip.reass.range_first)
715  {
716  // this fragment ends before candidate range without any overlap
717  ip4_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
718  *bi0);
719  consumed = 1;
720  }
721  else
722  {
723  if (fragment_first >= candidate_vnb->ip.reass.range_first &&
724  fragment_last <= candidate_vnb->ip.reass.range_last)
725  {
726  // this fragment is a (sub)part of existing range, ignore it
727  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
728  {
729  ip4_reass_add_trace (vm, node, rm, reass, *bi0,
730  RANGE_OVERLAP, 0);
731  }
732  break;
733  }
734  int discard_candidate = 0;
735  if (fragment_first < candidate_vnb->ip.reass.range_first)
736  {
737  u32 overlap =
738  fragment_last - candidate_vnb->ip.reass.range_first + 1;
739  if (overlap < ip4_reass_buffer_get_data_len (candidate_b))
740  {
741  candidate_vnb->ip.reass.range_first += overlap;
742  ASSERT (reass->data_len >= overlap);
743  reass->data_len -= overlap;
744  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
745  {
746  ip4_reass_add_trace (vm, node, rm, reass,
747  candidate_range_bi, RANGE_SHRINK,
748  overlap);
749  }
750  ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
751  prev_range_bi, *bi0);
752  consumed = 1;
753  }
754  else
755  {
756  discard_candidate = 1;
757  }
758  }
759  else if (fragment_last > candidate_vnb->ip.reass.range_last)
760  {
761  u32 overlap =
762  candidate_vnb->ip.reass.range_last - fragment_first + 1;
763  if (overlap < ip4_reass_buffer_get_data_len (candidate_b))
764  {
765  fvnb->ip.reass.range_first += overlap;
766  if (~0 != candidate_vnb->ip.reass.next_range_bi)
767  {
768  prev_range_bi = candidate_range_bi;
769  candidate_range_bi =
770  candidate_vnb->ip.reass.next_range_bi;
771  continue;
772  }
773  else
774  {
775  // special case - last range discarded
776  ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
777  candidate_range_bi,
778  *bi0);
779  consumed = 1;
780  }
781  }
782  else
783  {
784  discard_candidate = 1;
785  }
786  }
787  else
788  {
789  discard_candidate = 1;
790  }
791  if (discard_candidate)
792  {
793  u32 next_range_bi = candidate_vnb->ip.reass.next_range_bi;
794  // discard candidate range, probe next range
795  ip4_reass_remove_range_from_chain (vm, node, rm,
796  vec_drop_overlap, reass,
797  prev_range_bi,
798  candidate_range_bi);
799  if (~0 != next_range_bi)
800  {
801  candidate_range_bi = next_range_bi;
802  continue;
803  }
804  else
805  {
806  // special case - last range discarded
807  ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
808  prev_range_bi, *bi0);
809  consumed = 1;
810  }
811  }
812  }
813  break;
814  }
815  if (consumed)
816  {
817  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
818  {
819  ip4_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_NEW, 0);
820  }
821  }
822  if (~0 != reass->last_packet_octet &&
823  reass->data_len == reass->last_packet_octet + 1)
824  {
825  ip4_reass_finalize (vm, node, rm, rt, reass, bi0, next0, error0,
826  vec_drop_compress, vec_drop_overlap, is_feature);
827  }
828  else
829  {
830  if (consumed)
831  {
832  *bi0 = ~0;
833  }
834  else
835  {
836  *next0 = IP4_REASSEMBLY_NEXT_DROP;
837  *error0 = IP4_ERROR_REASS_DUPLICATE_FRAGMENT;
838  }
839  }
840 }
841 
844  vlib_node_runtime_t * node,
845  vlib_frame_t * frame, bool is_feature)
846 {
847  u32 *from = vlib_frame_vector_args (frame);
848  u32 n_left_from, n_left_to_next, *to_next, next_index;
851  clib_spinlock_lock (&rt->lock);
852 
853  n_left_from = frame->n_vectors;
854  next_index = node->cached_next_index;
855  static u32 *vec_drop_timeout = NULL; // indexes of buffers which timed out
856  static u32 *vec_drop_overlap = NULL; // indexes of buffers which were discarded due to overlap
857  static u32 *vec_drop_compress = NULL; // indexes of buffers dicarded due to buffer compression
858  while (n_left_from > 0 || vec_len (vec_drop_timeout) > 0 ||
859  vec_len (vec_drop_overlap) > 0 || vec_len (vec_drop_compress) > 0)
860  {
861  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
862 
863  while (vec_len (vec_drop_timeout) > 0 && n_left_to_next > 0)
864  {
865  u32 bi = vec_pop (vec_drop_timeout);
866  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
867  b->error = node->errors[IP4_ERROR_REASS_TIMEOUT];
868  to_next[0] = bi;
869  to_next += 1;
870  n_left_to_next -= 1;
871  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
872  n_left_to_next, bi,
874  IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_timeout);
875  ASSERT (rt->buffers_n > 0);
876  --rt->buffers_n;
877  }
878 
879  while (vec_len (vec_drop_overlap) > 0 && n_left_to_next > 0)
880  {
881  u32 bi = vec_pop (vec_drop_overlap);
882  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
883  b->error = node->errors[IP4_ERROR_REASS_DUPLICATE_FRAGMENT];
884  to_next[0] = bi;
885  to_next += 1;
886  n_left_to_next -= 1;
887  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
888  n_left_to_next, bi,
890  IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_duplicate_fragment);
891  ASSERT (rt->buffers_n > 0);
892  --rt->buffers_n;
893  }
894 
895  while (vec_len (vec_drop_compress) > 0 && n_left_to_next > 0)
896  {
897  u32 bi = vec_pop (vec_drop_compress);
898  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
899  b->error = node->errors[IP4_ERROR_NONE];
900  to_next[0] = bi;
901  to_next += 1;
902  n_left_to_next -= 1;
903  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
904  n_left_to_next, bi,
906  IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_compress);
907  ASSERT (rt->buffers_n > 0);
908  --rt->buffers_n;
909  }
910 
911  while (n_left_from > 0 && n_left_to_next > 0)
912  {
913  u32 bi0;
914  vlib_buffer_t *b0;
915  u32 next0;
916  u32 error0 = IP4_ERROR_NONE;
917 
918  bi0 = from[0];
919  b0 = vlib_get_buffer (vm, bi0);
920 
922  if (!ip4_get_fragment_more (ip0) && !ip4_get_fragment_offset (ip0))
923  {
924  // this is a whole packet - no fragmentation
925  if (is_feature)
926  {
928  }
929  else
930  {
931  next0 = vnet_buffer (b0)->ip.reass.next_index;
932  }
933  }
934  else
935  {
936  ip4_reass_key_t k;
937  k.src.as_u32 = ip0->src_address.as_u32;
938  k.dst.as_u32 = ip0->dst_address.as_u32;
939  k.xx_id = vnet_buffer (b0)->sw_if_index[VLIB_RX];
940  k.frag_id = ip0->fragment_id;
941  k.proto = ip0->protocol;
942  k.unused = 0;
943  ip4_reass_t *reass =
944  ip4_reass_find_or_create (vm, rm, rt, &k, &vec_drop_timeout);
945 
946  if (reass)
947  {
948  ip4_reass_update (vm, node, rm, rt, reass, &bi0, &next0,
949  &error0, &vec_drop_overlap,
950  &vec_drop_compress, is_feature);
951  }
952  else
953  {
954  next0 = IP4_REASSEMBLY_NEXT_DROP;
955  error0 = IP4_ERROR_REASS_LIMIT_REACHED;
956  }
957 
958  b0->error = node->errors[error0];
959  }
960 
961  if (bi0 != ~0)
962  {
963  to_next[0] = bi0;
964  to_next += 1;
965  n_left_to_next -= 1;
966  if (is_feature && IP4_ERROR_NONE == error0)
967  {
968  vnet_feature_next (vnet_buffer (b0)->sw_if_index[VLIB_RX],
969  &next0, b0);
970  }
971  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
972  n_left_to_next, bi0, next0);
973  IP4_REASS_DEBUG_BUFFER (bi0, enqueue_next);
974  }
975 
976  from += 1;
977  n_left_from -= 1;
978  }
979 
980  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
981  }
982 
983  clib_spinlock_unlock (&rt->lock);
984  return frame->n_vectors;
985 }
986 
988 #define _(sym, string) string,
990 #undef _
991 };
992 
993 static uword
995  vlib_frame_t * frame)
996 {
997  return ip4_reassembly_inline (vm, node, frame, false /* is_feature */ );
998 }
999 
1000 /* *INDENT-OFF* */
1001 VLIB_REGISTER_NODE (ip4_reass_node, static) = {
1002  .function = ip4_reassembly,
1003  .name = "ip4-reassembly",
1004  .vector_size = sizeof (u32),
1005  .format_trace = format_ip4_reass_trace,
1006  .n_errors = ARRAY_LEN (ip4_reassembly_error_strings),
1007  .error_strings = ip4_reassembly_error_strings,
1008  .n_next_nodes = IP4_REASSEMBLY_N_NEXT,
1009  .next_nodes =
1010  {
1011  [IP4_REASSEMBLY_NEXT_INPUT] = "ip4-input",
1012  [IP4_REASSEMBLY_NEXT_DROP] = "ip4-drop",
1013  },
1014 };
1015 /* *INDENT-ON* */
1016 
1018 
1019 static uword
1021  vlib_node_runtime_t * node, vlib_frame_t * frame)
1022 {
1023  return ip4_reassembly_inline (vm, node, frame, true /* is_feature */ );
1024 }
1025 
1026 /* *INDENT-OFF* */
1028  .function = ip4_reassembly_feature,
1029  .name = "ip4-reassembly-feature",
1030  .vector_size = sizeof (u32),
1031  .format_trace = format_ip4_reass_trace,
1032  .n_errors = ARRAY_LEN (ip4_reassembly_error_strings),
1033  .error_strings = ip4_reassembly_error_strings,
1034  .n_next_nodes = IP4_REASSEMBLY_N_NEXT,
1035  .next_nodes =
1036  {
1037  [IP4_REASSEMBLY_NEXT_INPUT] = "ip4-input",
1038  [IP4_REASSEMBLY_NEXT_DROP] = "ip4-drop",
1039  },
1040 };
1041 /* *INDENT-ON* */
1042 
1044 
1045 /* *INDENT-OFF* */
1047  .arc_name = "ip4-unicast",
1048  .node_name = "ip4-reassembly-feature",
1049  .runs_before = VNET_FEATURES ("ip4-lookup"),
1050  .runs_after = 0,
1051 };
1052 /* *INDENT-ON* */
1053 
1056 {
1058  u32 nbuckets;
1059  u8 i;
1060 
1061  nbuckets = (u32) (rm->max_reass_n / IP4_REASS_HT_LOAD_FACTOR);
1062 
1063  for (i = 0; i < 31; i++)
1064  if ((1 << i) >= nbuckets)
1065  break;
1066  nbuckets = 1 << i;
1067 
1068  return nbuckets;
1069 }
1070 
1071 typedef enum
1072 {
1075 
1076 typedef struct
1077 {
1078  int failure;
1079  clib_bihash_24_8_t *new_hash;
1081 
1082 static void
1084 {
1085  ip4_rehash_cb_ctx *ctx = _ctx;
1086  if (clib_bihash_add_del_24_8 (ctx->new_hash, kv, 1))
1087  {
1088  ctx->failure = 1;
1089  }
1090 }
1091 
1092 static void
1093 ip4_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
1094  u32 expire_walk_interval_ms)
1095 {
1096  ip4_reass_main.timeout_ms = timeout_ms;
1097  ip4_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
1098  ip4_reass_main.max_reass_n = max_reassemblies;
1099  ip4_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
1100 }
1101 
1103 ip4_reass_set (u32 timeout_ms, u32 max_reassemblies,
1104  u32 expire_walk_interval_ms)
1105 {
1106  u32 old_nbuckets = ip4_reass_get_nbuckets ();
1107  ip4_reass_set_params (timeout_ms, max_reassemblies,
1108  expire_walk_interval_ms);
1109  vlib_process_signal_event (ip4_reass_main.vlib_main,
1110  ip4_reass_main.ip4_reass_expire_node_idx,
1112  u32 new_nbuckets = ip4_reass_get_nbuckets ();
1113  if (ip4_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
1114  {
1115  clib_bihash_24_8_t new_hash;
1116  memset (&new_hash, 0, sizeof (new_hash));
1118  ctx.failure = 0;
1119  ctx.new_hash = &new_hash;
1120  clib_bihash_init_24_8 (&new_hash, "ip4-reass", new_nbuckets,
1121  new_nbuckets * 1024);
1122  clib_bihash_foreach_key_value_pair_24_8 (&ip4_reass_main.hash,
1123  ip4_rehash_cb, &ctx);
1124  if (ctx.failure)
1125  {
1126  clib_bihash_free_24_8 (&new_hash);
1127  return -1;
1128  }
1129  else
1130  {
1131  clib_bihash_free_24_8 (&ip4_reass_main.hash);
1132  clib_memcpy (&ip4_reass_main.hash, &new_hash,
1133  sizeof (ip4_reass_main.hash));
1134  }
1135  }
1136  return 0;
1137 }
1138 
1140 ip4_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
1141  u32 * expire_walk_interval_ms)
1142 {
1143  *timeout_ms = ip4_reass_main.timeout_ms;
1144  *max_reassemblies = ip4_reass_main.max_reass_n;
1145  *expire_walk_interval_ms = ip4_reass_main.expire_walk_interval_ms;
1146  return 0;
1147 }
1148 
1149 static clib_error_t *
1151 {
1153  clib_error_t *error = 0;
1154  u32 nbuckets;
1155  vlib_node_t *node;
1156 
1157  rm->vlib_main = vm;
1158  rm->vnet_main = vnet_get_main ();
1159 
1162  vec_foreach (rt, rm->per_thread_data)
1163  {
1164  clib_spinlock_init (&rt->lock);
1165  pool_alloc (rt->pool, rm->max_reass_n);
1166  }
1167 
1168  node = vlib_get_node_by_name (vm, (u8 *) "ip4-reassembly-expire-walk");
1169  ASSERT (node);
1170  rm->ip4_reass_expire_node_idx = node->index;
1171 
1175 
1176  nbuckets = ip4_reass_get_nbuckets ();
1177  clib_bihash_init_24_8 (&rm->hash, "ip4-reass", nbuckets, nbuckets * 1024);
1178 
1179  node = vlib_get_node_by_name (vm, (u8 *) "ip4-drop");
1180  ASSERT (node);
1181  rm->ip4_drop_idx = node->index;
1182 
1183  return error;
1184 }
1185 
1187 
1188 static uword
1190  vlib_node_runtime_t * node, vlib_frame_t * f)
1191 {
1193  uword event_type, *event_data = 0;
1194 
1195  while (true)
1196  {
1199  / (f64) MSEC_PER_SEC);
1200  event_type = vlib_process_get_events (vm, &event_data);
1201 
1202  switch (event_type)
1203  {
1204  case ~0: /* no events => timeout */
1205  /* nothing to do here */
1206  break;
1208  break;
1209  default:
1210  clib_warning ("BUG: event type 0x%wx", event_type);
1211  break;
1212  }
1213  f64 now = vlib_time_now (vm);
1214 
1215  ip4_reass_t *reass;
1216  u32 *vec_drop_timeout = NULL;
1217  int *pool_indexes_to_free = NULL;
1218 
1219  uword thread_index = 0;
1220  int index;
1221  const uword nthreads = os_get_nthreads ();
1222  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1223  {
1224  ip4_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1225  clib_spinlock_lock (&rt->lock);
1226 
1227  vec_reset_length (pool_indexes_to_free);
1228  /* *INDENT-OFF* */
1229  pool_foreach_index (index, rt->pool, ({
1230  reass = pool_elt_at_index (rt->pool, index);
1231  if (now > reass->last_heard + rm->timeout)
1232  {
1233  vec_add1 (pool_indexes_to_free, index);
1234  }
1235  }));
1236  /* *INDENT-ON* */
1237  int *i;
1238  /* *INDENT-OFF* */
1239  vec_foreach (i, pool_indexes_to_free)
1240  {
1241  ip4_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1242  u32 before = vec_len (vec_drop_timeout);
1243  vlib_buffer_t *b = vlib_get_buffer (vm, reass->first_bi);
1244  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
1245  {
1247  b->trace_index))
1248  {
1249  /* the trace is gone, don't trace this buffer anymore */
1250  b->flags &= ~VLIB_BUFFER_IS_TRACED;
1251  }
1252  }
1253  ip4_reass_on_timeout (vm, rm, reass, &vec_drop_timeout);
1254  u32 after = vec_len (vec_drop_timeout);
1255  ASSERT (rt->buffers_n >= (after - before));
1256  rt->buffers_n -= (after - before);
1257  ip4_reass_free (rm, rt, reass);
1258  }
1259  /* *INDENT-ON* */
1260 
1261  clib_spinlock_unlock (&rt->lock);
1262  }
1263 
1264  while (vec_len (vec_drop_timeout) > 0)
1265  {
1267  u32 *to_next = vlib_frame_vector_args (f);
1268  u32 n_left_to_next = VLIB_FRAME_SIZE - f->n_vectors;
1269  int trace_frame = 0;
1270  while (vec_len (vec_drop_timeout) > 0 && n_left_to_next > 0)
1271  {
1272  u32 bi = vec_pop (vec_drop_timeout);
1273  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1274  if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
1275  {
1277  b->trace_index))
1278  {
1279  /* the trace is gone, don't trace this buffer anymore */
1280  b->flags &= ~VLIB_BUFFER_IS_TRACED;
1281  }
1282  else
1283  {
1284  trace_frame = 1;
1285  }
1286  }
1287  b->error = node->errors[IP4_ERROR_REASS_TIMEOUT];
1288  to_next[0] = bi;
1289  ++f->n_vectors;
1290  to_next += 1;
1291  n_left_to_next -= 1;
1292  IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_timeout_walk);
1293  }
1294  f->flags |= (trace_frame * VLIB_FRAME_TRACE);
1295  vlib_put_frame_to_node (vm, rm->ip4_drop_idx, f);
1296  }
1297 
1298  vec_free (pool_indexes_to_free);
1299  vec_free (vec_drop_timeout);
1300  if (event_data)
1301  {
1302  _vec_len (event_data) = 0;
1303  }
1304  }
1305 
1306  return 0;
1307 }
1308 
1310 
1311 /* *INDENT-OFF* */
1313  .function = ip4_reass_walk_expired,
1314  .type = VLIB_NODE_TYPE_PROCESS,
1315  .name = "ip4-reassembly-expire-walk",
1316  .format_trace = format_ip4_reass_trace,
1318  .error_strings = ip4_reassembly_error_strings,
1319 
1320 };
1321 /* *INDENT-ON* */
1322 
1323 static u8 *
1324 format_ip4_reass_key (u8 * s, va_list * args)
1325 {
1326  ip4_reass_key_t *key = va_arg (*args, ip4_reass_key_t *);
1327  s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1329  &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1330  return s;
1331 }
1332 
1333 static u8 *
1334 format_ip4_reass (u8 * s, va_list * args)
1335 {
1336  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1337  ip4_reass_t *reass = va_arg (*args, ip4_reass_t *);
1338 
1339  s = format (s, "ID: %lu, key: %U\n first_bi: %u, data_len: %u, "
1340  "last_packet_octet: %u, trace_op_counter: %u\n",
1341  reass->id, format_ip4_reass_key, &reass->key, reass->first_bi,
1342  reass->data_len, reass->last_packet_octet,
1343  reass->trace_op_counter);
1344  u32 bi = reass->first_bi;
1345  u32 counter = 0;
1346  while (~0 != bi)
1347  {
1348  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
1349  vnet_buffer_opaque_t *vnb = vnet_buffer (b);
1350  s = format (s, " #%03u: range: [%u, %u], bi: %u, off: %d, len: %u, "
1351  "fragment[%u, %u]\n",
1352  counter, vnb->ip.reass.range_first,
1353  vnb->ip.reass.range_last, bi,
1356  vnb->ip.reass.fragment_first, vnb->ip.reass.fragment_last);
1357  if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
1358  {
1359  bi = b->next_buffer;
1360  }
1361  else
1362  {
1363  bi = ~0;
1364  }
1365  }
1366  return s;
1367 }
1368 
1369 static clib_error_t *
1372 {
1374 
1375  vlib_cli_output (vm, "---------------------");
1376  vlib_cli_output (vm, "IP4 reassembly status");
1377  vlib_cli_output (vm, "---------------------");
1378  bool details = false;
1379  if (unformat (input, "details"))
1380  {
1381  details = true;
1382  }
1383 
1384  u32 sum_reass_n = 0;
1385  u64 sum_buffers_n = 0;
1386  ip4_reass_t *reass;
1387  uword thread_index;
1388  const uword nthreads = os_get_nthreads ();
1389  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1390  {
1391  ip4_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1392  clib_spinlock_lock (&rt->lock);
1393  if (details)
1394  {
1395  /* *INDENT-OFF* */
1396  pool_foreach (reass, rt->pool, {
1397  vlib_cli_output (vm, "%U", format_ip4_reass, vm, reass);
1398  });
1399  /* *INDENT-ON* */
1400  }
1401  sum_reass_n += rt->reass_n;
1402  sum_buffers_n += rt->buffers_n;
1403  clib_spinlock_unlock (&rt->lock);
1404  }
1405  vlib_cli_output (vm, "---------------------");
1406  vlib_cli_output (vm, "Current IP4 reassemblies count: %lu\n",
1407  (long unsigned) sum_reass_n);
1408  vlib_cli_output (vm,
1409  "Maximum configured concurrent IP4 reassemblies per worker-thread: %lu\n",
1410  (long unsigned) rm->max_reass_n);
1411  vlib_cli_output (vm, "Buffers in use: %lu\n",
1412  (long unsigned) sum_buffers_n);
1413  return 0;
1414 }
1415 
1416 /* *INDENT-OFF* */
1418  .path = "show ip4-reassembly",
1419  .short_help = "show ip4-reassembly [details]",
1420  .function = show_ip4_reass,
1421 };
1422 /* *INDENT-ON* */
1423 
1425 ip4_reass_enable_disable (u32 sw_if_index, u8 enable_disable)
1426 {
1427  return vnet_feature_enable_disable ("ip4-unicast", "ip4-reassembly-feature",
1428  sw_if_index, enable_disable, 0, 0);
1429 }
1430 
1431 /*
1432  * fd.io coding-style-patch-verification: ON
1433  *
1434  * Local Variables:
1435  * eval: (c-set-style "gnu")
1436  * End:
1437  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
static void ip4_reass_insert_range_in_chain(vlib_main_t *vm, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass, u32 prev_range_bi, u32 new_next_bi)
vnet_api_error_t
Definition: api_errno.h:147
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:289
static uword ip4_reassembly_feature(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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:79
VLIB_NODE_FUNCTION_MULTIARCH(ip4_reass_node, ip4_reassembly)
static vlib_node_registration_t ip4_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip4_reass_expire_node)
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:699
static uword ip4_reassembly(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u16 min_fragment_length
ip4_reass_event_t
ip4_address_t src_address
Definition: ip4_packet.h:169
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
u8 * format_ip4_reass_trace(u8 *s, va_list *args)
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
Definition: pool.h:326
u64 as_u64
Definition: bihash_doc.h:63
unsigned long u64
Definition: types.h:89
static void vlib_buffer_chain_compress(vlib_main_t *vm, vlib_buffer_t *first, u32 **discard_vector)
compress buffer chain in a way where the first buffer is at least VLIB_BUFFER_CHAIN_MIN_FIRST_DATA_SI...
static int ip4_header_bytes(ip4_header_t *i)
Definition: ip4_packet.h:232
#define NULL
Definition: clib.h:55
#define IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
static char * ip4_reassembly_error_strings[]
u32 index
Definition: node.h:273
vlib_main_t * vlib_main
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:225
static vlib_node_registration_t ip4_reass_node
(constructor) VLIB_REGISTER_NODE (ip4_reass_node)
ip4_reass_t * ip4_reass_find_or_create(vlib_main_t *vm, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_key_t *k, u32 **vec_drop_timeout)
IPv4 Reassembly.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
static u32 ip4_reass_buffer_get_data_offset_no_check(vlib_buffer_t *b)
int i
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u16 flags_and_fragment_offset
Definition: ip4_packet.h:150
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:451
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:250
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:227
ip4_reass_per_thread_t * per_thread_data
static void ip4_reass_trace_details(vlib_main_t *vm, u32 bi, ip4_reass_range_trace_t *trace)
unsigned char u8
Definition: types.h:56
#define vec_pop(V)
Returns last element of a vector and decrements its length.
Definition: vec.h:617
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
format_function_t format_ip4_address
Definition: format.h:81
vlib_trace_header_t ** trace_buffer_pool
Definition: trace.h:72
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
ip4_reass_key_t key
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:156
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:542
#define always_inline
Definition: clib.h:92
ip4_address_t dst_address
Definition: ip4_packet.h:169
static u32 ip4_reass_get_buffer_chain_length(vlib_main_t *vm, vlib_buffer_t *b)
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
static int ip4_get_fragment_offset(ip4_header_t *i)
Definition: ip4_packet.h:197
static void ip4_reass_free(ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:182
static u16 ip4_reass_buffer_get_data_len(vlib_buffer_t *b)
unsigned int u32
Definition: types.h:88
static void ip4_reass_set_params(u32 timeout_ms, u32 max_reassemblies, u32 expire_walk_interval_ms)
#define VLIB_FRAME_SIZE
Definition: node.h:364
struct vnet_buffer_opaque_t::@57::@59 ip
clib_bihash_24_8_t hash
static uword ip4_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:57
static void ip4_reass_on_timeout(vlib_main_t *vm, ip4_reass_main_t *rm, ip4_reass_t *reass, u32 **vec_drop_timeout)
static uword ip4_reassembly_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
static u8 * format_ip4_reass_key(u8 *s, va_list *args)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
vnet_api_error_t ip4_reass_set(u32 timeout_ms, u32 max_reassemblies, u32 expire_walk_interval_ms)
set ip4 reassembly configuration
vnet_main_t * vnet_main
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:108
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:952
#define IP4_REASS_DEBUG_BUFFER(...)
ip4_address_t dst
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:191
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:202
vnet_api_error_t ip4_reass_get(u32 *timeout_ms, u32 *max_reassemblies, u32 *expire_walk_interval_ms)
get ip4 reassembly configuration
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:273
#define PREDICT_FALSE(x)
Definition: clib.h:105
static vlib_cli_command_t show_ip4_reassembly_cmd
(constructor) VLIB_CLI_COMMAND (show_ip4_reassembly_cmd)
ip4_reass_main_t ip4_reass_main
static_always_inline void vnet_feature_next(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:237
static u16 ip4_reass_buffer_get_data_len_no_check(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
#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:364
static u8 * format_ip4_reass_range_trace(u8 *s, va_list *args)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:135
static void ip4_rehash_cb(clib_bihash_kv_24_8_t *kv, void *_ctx)
ip4_reass_trace_operation_e
#define foreach_ip4_error
Definition: ip4_error.h:43
static clib_error_t * ip4_reass_init_function(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:153
u16 n_vectors
Definition: node.h:380
vlib_main_t * vm
Definition: buffer.c:294
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
ip4_reass_range_trace_t trace_range
static void ip4_reass_remove_range_from_chain(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, u32 **vec_drop_overlap, ip4_reass_t *reass, u32 prev_range_bi, u32 discard_bi)
#define clib_warning(format, args...)
Definition: error.h:59
VNET_FEATURE_INIT(ip4_reassembly_feature, static)
#define clib_memcpy(a, b, c)
Definition: string.h:75
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:281
static void ip4_reass_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, ip4_reass_t *reass, u32 bi, ip4_reass_trace_operation_e action, u32 size_diff)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:270
static clib_error_t * show_ip4_reass(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
#define ARRAY_LEN(x)
Definition: clib.h:59
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:454
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
clib_spinlock_t lock
#define IP4_REASS_MAX_REASSEMBLIES_DEFAULT
#define IP4_REASS_HT_LOAD_FACTOR
vnet_api_error_t ip4_reass_enable_disable(u32 sw_if_index, u8 enable_disable)
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
clib_bihash_24_8_t * new_hash
signed int i32
Definition: types.h:81
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:492
static void ip4_reass_update(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, u32 **vec_drop_overlap, u32 **vec_drop_compress, bool is_feature)
static u32 ip4_reass_get_nbuckets()
#define ASSERT(truth)
long ctx[MAX_CONNS]
Definition: main.c:126
u16 flags
Definition: node.h:371
static u32 ip4_reass_buffer_get_data_offset(vlib_buffer_t *b)
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:126
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:215
vlib_trace_main_t trace_main
Definition: main.h:138
static int ip4_get_fragment_more(ip4_header_t *i)
Definition: ip4_packet.h:203
#define IP4_REASS_TIMEOUT_DEFAULT_MS
#define VNET_FEATURES(...)
Definition: feature.h:391
ip4_reass_next_t
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:55
static int ip4_get_fragment_offset_bytes(ip4_header_t *i)
Definition: ip4_packet.h:226
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:152
struct _vlib_node_registration vlib_node_registration_t
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
ip4_address_t src
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
static void ip4_reass_finalize(vlib_main_t *vm, vlib_node_runtime_t *node, ip4_reass_main_t *rm, ip4_reass_per_thread_t *rt, ip4_reass_t *reass, u32 *bi0, u32 *next0, u32 *error0, u32 **vec_drop_compress, u32 **vec_drop_overlap, bool is_feature)
uword os_get_nthreads(void)
Definition: unix-misc.c:226
ip4_reass_trace_operation_e action
#define VLIB_FRAME_TRACE
Definition: node.h:415
static_always_inline uword os_get_thread_index(void)
Definition: os.h:62
static u8 * format_ip4_reass(u8 *s, va_list *args)
#define vnet_buffer(b)
Definition: buffer.h:360
static u32 vlib_num_workers()
Definition: threads.h:375
#define vec_foreach(var, vec)
Vector iterator.
#define MSEC_PER_SEC
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:485
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:111
static vlib_node_registration_t ip4_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip4_reass_node_feature)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:681
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
u32 trace_index
Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is set.
Definition: buffer.h:147
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:244
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
Definition: defs.h:46
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:233
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".