FD.io VPP  v21.01.1
Vector Packet Processing
ip6_sv_reass.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @file
18  * @brief IPv6 Shallow Virtual Reassembly.
19  *
20  * This file contains the source code for IPv6 Shallow Virtual reassembly.
21  */
22 
23 #include <vppinfra/vec.h>
24 #include <vnet/vnet.h>
25 #include <vnet/ip/ip.h>
26 #include <vnet/ip/ip6_to_ip4.h>
27 #include <vppinfra/bihash_48_8.h>
29 
30 #define MSEC_PER_SEC 1000
31 #define IP6_SV_REASS_TIMEOUT_DEFAULT_MS 100
32 #define IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
33 #define IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT 1024
34 #define IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT 3
35 #define IP6_SV_REASS_HT_LOAD_FACTOR (0.75)
36 
37 typedef enum
38 {
44 
45 typedef struct
46 {
47  union
48  {
49  struct
50  {
51  ip6_address_t src;
52  ip6_address_t dst;
55  u8 unused[7];
57  };
58  u64 as_u64[6];
59  };
61 
62 typedef union
63 {
64  struct
65  {
68  };
71 
72 typedef union
73 {
74  struct
75  {
78  };
81 
82 typedef struct
83 {
84  // hash table key
86  // time when last packet was received
88  // internal id of this reassembly
90  // trace operation counter
92  // buffer indexes of buffers in this reassembly in chronological order -
93  // including overlaps and duplicate fragments
95  // set to true when this reassembly is completed
97  // ip protocol
102  // l4 src port
104  // l4 dst port
106  // lru indexes
110 
111 typedef struct
112 {
117  // lru indexes
121 
122 typedef struct
123 {
124  // IPv6 config
128  // maximum number of fragments in one reassembly
130  // maximum number of reassemblies
132 
133  // IPv6 runtime
134  clib_bihash_48_8_t hash;
135 
136  // per-thread data
138 
139  // convenience
142 
143  // node index of ip6-drop node
147 
148  /** Worker handoff */
151 
152  // reference count for enabling/disabling feature - per interface
155 
157 
158 #ifndef CLIB_MARCH_VARIANT
160 #endif /* CLIB_MARCH_VARIANT */
161 
162 typedef enum
163 {
170 
171 typedef enum
172 {
178 
179 typedef struct
180 {
181  ip6_sv_reass_trace_operation_e action;
188 
189 static u8 *
190 format_ip6_sv_reass_trace (u8 * s, va_list * args)
191 {
192  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
193  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
194  ip6_sv_reass_trace_t *t = va_arg (*args, ip6_sv_reass_trace_t *);
195  if (REASS_PASSTHROUGH != t->action)
196  {
197  s = format (s, "reass id: %u, op id: %u ", t->reass_id, t->op_id);
198  }
199  switch (t->action)
200  {
202  s = format (s, "[cached]");
203  break;
204  case REASS_FINISH:
205  s =
206  format (s, "[finish, ip proto=%u, src_port=%u, dst_port=%u]",
207  t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
208  clib_net_to_host_u16 (t->l4_dst_port));
209  break;
211  s =
212  format (s, "[forward, ip proto=%u, src_port=%u, dst_port=%u]",
213  t->ip_proto, clib_net_to_host_u16 (t->l4_src_port),
214  clib_net_to_host_u16 (t->l4_dst_port));
215  break;
216  case REASS_PASSTHROUGH:
217  s = format (s, "[not-fragmented]");
218  break;
219  }
220  return s;
221 }
222 
223 static void
225  ip6_sv_reass_main_t * rm,
226  ip6_sv_reass_t * reass, u32 bi,
227  ip6_sv_reass_trace_operation_e action,
228  u32 ip_proto, u16 l4_src_port, u16 l4_dst_port)
229 {
230  vlib_buffer_t *b = vlib_get_buffer (vm, bi);
233  {
234  // this buffer's trace is gone
235  b->flags &= ~VLIB_BUFFER_IS_TRACED;
236  return;
237  }
238  ip6_sv_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
239  if (reass)
240  {
241  t->reass_id = reass->id;
242  t->op_id = reass->trace_op_counter;
243  ++reass->trace_op_counter;
244  }
245  t->action = action;
246  t->ip_proto = ip_proto;
247  t->l4_src_port = l4_src_port;
248  t->l4_dst_port = l4_dst_port;
249 #if 0
250  static u8 *s = NULL;
251  s = format (s, "%U", format_ip6_sv_reass_trace, NULL, NULL, t);
252  printf ("%.*s\n", vec_len (s), s);
253  fflush (stdout);
254  vec_reset_length (s);
255 #endif
256 }
257 
258 always_inline void
261 {
263  kv.key[0] = reass->key.as_u64[0];
264  kv.key[1] = reass->key.as_u64[1];
265  kv.key[2] = reass->key.as_u64[2];
266  kv.key[3] = reass->key.as_u64[3];
267  kv.key[4] = reass->key.as_u64[4];
268  kv.key[5] = reass->key.as_u64[5];
269  clib_bihash_add_del_48_8 (&rm->hash, &kv, 0);
270  vlib_buffer_free (vm, reass->cached_buffers,
271  vec_len (reass->cached_buffers));
272  vec_free (reass->cached_buffers);
273  reass->cached_buffers = NULL;
274  if (~0 != reass->lru_prev)
275  {
276  ip6_sv_reass_t *lru_prev =
277  pool_elt_at_index (rt->pool, reass->lru_prev);
278  lru_prev->lru_next = reass->lru_next;
279  }
280  if (~0 != reass->lru_next)
281  {
282  ip6_sv_reass_t *lru_next =
283  pool_elt_at_index (rt->pool, reass->lru_next);
284  lru_next->lru_prev = reass->lru_prev;
285  }
286  if (rt->lru_first == reass - rt->pool)
287  {
288  rt->lru_first = reass->lru_next;
289  }
290  if (rt->lru_last == reass - rt->pool)
291  {
292  rt->lru_last = reass->lru_prev;
293  }
294  pool_put (rt->pool, reass);
295  --rt->reass_n;
296 }
297 
298 always_inline void
300 {
301  reass->cached_buffers = NULL;
302  reass->is_complete = false;
303 }
304 
307  ip6_sv_reass_main_t * rm,
309  ip6_sv_reass_kv_t * kv, u32 * icmp_bi,
310  u8 * do_handoff)
311 {
312  ip6_sv_reass_t *reass = NULL;
313  f64 now = vlib_time_now (vm);
314 
315  if (!clib_bihash_search_48_8 (&rm->hash, &kv->kv, &kv->kv))
316  {
317  if (vm->thread_index != kv->v.thread_index)
318  {
319  *do_handoff = 1;
320  return NULL;
321  }
322  reass = pool_elt_at_index (rt->pool, kv->v.reass_index);
323 
324  if (now > reass->last_heard + rm->timeout)
325  {
326  ip6_sv_reass_free (vm, rm, rt, reass);
327  reass = NULL;
328  }
329  }
330 
331  if (reass)
332  {
333  reass->last_heard = now;
334  return reass;
335  }
336 
337  if (rt->reass_n >= rm->max_reass_n)
338  {
339  reass = pool_elt_at_index (rt->pool, rt->lru_first);
340  ip6_sv_reass_free (vm, rm, rt, reass);
341  }
342 
343  pool_get (rt->pool, reass);
344  clib_memset (reass, 0, sizeof (*reass));
345  reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
346  ++rt->id_counter;
347  ip6_sv_reass_init (reass);
348  ++rt->reass_n;
349 
350  reass->lru_prev = reass->lru_next = ~0;
351 
352  if (~0 != rt->lru_last)
353  {
354  ip6_sv_reass_t *lru_last = pool_elt_at_index (rt->pool, rt->lru_last);
355  reass->lru_prev = rt->lru_last;
356  lru_last->lru_next = rt->lru_last = reass - rt->pool;
357  }
358 
359  if (~0 == rt->lru_first)
360  {
361  rt->lru_first = rt->lru_last = reass - rt->pool;
362  }
363 
364  reass->key.as_u64[0] = kv->kv.key[0];
365  reass->key.as_u64[1] = kv->kv.key[1];
366  reass->key.as_u64[2] = kv->kv.key[2];
367  reass->key.as_u64[3] = kv->kv.key[3];
368  reass->key.as_u64[4] = kv->kv.key[4];
369  reass->key.as_u64[5] = kv->kv.key[5];
370  kv->v.reass_index = (reass - rt->pool);
371  kv->v.thread_index = vm->thread_index;
372  reass->last_heard = now;
373 
374  if (clib_bihash_add_del_48_8 (&rm->hash, &kv->kv, 1))
375  {
376  ip6_sv_reass_free (vm, rm, rt, reass);
377  reass = NULL;
378  }
379 
380  return reass;
381 }
382 
383 always_inline ip6_sv_reass_rc_t
386  ip6_sv_reass_t * reass, u32 bi0,
387  ip6_frag_hdr_t * frag_hdr)
388 {
389  vlib_buffer_t *fb = vlib_get_buffer (vm, bi0);
390  vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
391  fvnb->ip.reass.ip6_frag_hdr_offset =
392  (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb);
394  if (fb->current_length < sizeof (*fip) ||
395  fvnb->ip.reass.ip6_frag_hdr_offset == 0 ||
396  fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length)
397  {
399  }
400 
401  u32 fragment_first = fvnb->ip.reass.fragment_first =
402  ip6_frag_hdr_offset_bytes (frag_hdr);
403  u32 fragment_length =
404  vlib_buffer_length_in_chain (vm, fb) -
405  (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
406  u32 fragment_last = fvnb->ip.reass.fragment_last =
407  fragment_first + fragment_length - 1;
408  fvnb->ip.reass.range_first = fragment_first;
409  fvnb->ip.reass.range_last = fragment_last;
410  fvnb->ip.reass.next_range_bi = ~0;
411  if (0 == fragment_first)
412  {
413  if (!ip6_get_port
414  (vm, fb, fip, fb->current_length, &reass->ip_proto,
415  &reass->l4_src_port, &reass->l4_dst_port,
416  &reass->icmp_type_or_tcp_flags, &reass->tcp_ack_number,
417  &reass->tcp_seq_number))
419 
420  reass->is_complete = true;
421  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
422  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
423  {
424  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, REASS_FINISH,
425  reass->ip_proto, reass->l4_src_port,
426  reass->l4_dst_port);
427  }
428  }
429  vec_add1 (reass->cached_buffers, bi0);
430  if (!reass->is_complete)
431  {
432  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
433  {
434  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
436  reass->l4_src_port, reass->l4_dst_port);
437  }
438  if (vec_len (reass->cached_buffers) > rm->max_reass_len)
439  {
441  }
442  }
443  return IP6_SV_REASS_RC_OK;
444 }
445 
446 always_inline bool
448  vlib_buffer_t * b,
449  ip6_frag_hdr_t * frag_hdr)
450 {
451  ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
452  while (ip6_ext_hdr (tmp->next_hdr))
453  {
454  tmp = ip6_ext_next_header (tmp);
455  }
456  if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
457  {
458  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
459  ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
460  0);
461  b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
462 
463  return false;
464  }
465  return true;
466 }
467 
468 always_inline bool
470  vlib_node_runtime_t * node,
471  vlib_buffer_t * b,
472  ip6_frag_hdr_t * frag_hdr)
473 {
476  int more_fragments = ip6_frag_hdr_more (frag_hdr);
477  u32 fragment_length =
479  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
480  if (more_fragments && 0 != fragment_length % 8)
481  {
482  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
483  ICMP6_parameter_problem_erroneous_header_field,
484  (u8 *) & ip->payload_length - (u8 *) ip);
485  return false;
486  }
487  return true;
488 }
489 
490 always_inline bool
492  vlib_node_runtime_t * node,
493  vlib_buffer_t * b,
494  ip6_frag_hdr_t * frag_hdr)
495 {
497  u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
498  u32 fragment_length =
500  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
501  if (fragment_first + fragment_length > 65535)
502  {
504  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
505  ICMP6_parameter_problem_erroneous_header_field,
506  (u8 *) & frag_hdr->fragment_offset_and_more
507  - (u8 *) ip0);
508  return false;
509  }
510  return true;
511 }
512 
515  vlib_node_runtime_t * node,
516  vlib_frame_t * frame, bool is_feature)
517 {
518  u32 *from = vlib_frame_vector_args (frame);
519  u32 n_left_from, n_left_to_next, *to_next, next_index;
522  clib_spinlock_lock (&rt->lock);
523 
524  n_left_from = frame->n_vectors;
525  next_index = node->cached_next_index;
526 
527  while (n_left_from > 0)
528  {
529  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
530 
531  while (n_left_from > 0 && n_left_to_next > 0)
532  {
533  u32 bi0;
534  vlib_buffer_t *b0;
536  u32 error0 = IP6_ERROR_NONE;
537  u32 icmp_bi = ~0;
538 
539  bi0 = from[0];
540  b0 = vlib_get_buffer (vm, bi0);
541 
543  ip6_frag_hdr_t *frag_hdr = NULL;
544  ip6_ext_header_t *prev_hdr;
545  if (ip6_ext_hdr (ip0->protocol))
546  {
547  frag_hdr =
548  ip6_ext_header_find (vm, b0, ip0,
549  IP_PROTOCOL_IPV6_FRAGMENTATION,
550  &prev_hdr);
551  }
552  if (!frag_hdr)
553  {
554  // this is a regular packet - no fragmentation
555  if (!ip6_get_port
556  (vm, b0, ip0, b0->current_length,
557  &(vnet_buffer (b0)->ip.reass.ip_proto),
558  &(vnet_buffer (b0)->ip.reass.l4_src_port),
559  &(vnet_buffer (b0)->ip.reass.l4_dst_port),
560  &(vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags),
561  &(vnet_buffer (b0)->ip.reass.tcp_ack_number),
562  &(vnet_buffer (b0)->ip.reass.tcp_seq_number)))
563  {
564  error0 = IP6_ERROR_REASS_UNSUPP_IP_PROTO;
565  b0->error = node->errors[error0];
567  goto packet_enqueue;
568  }
569  vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
571  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
572  {
573  ip6_sv_reass_add_trace (vm, node, rm, NULL, bi0,
575  vnet_buffer (b0)->ip.reass.ip_proto,
576  vnet_buffer (b0)->ip.
577  reass.l4_src_port,
578  vnet_buffer (b0)->ip.
579  reass.l4_dst_port);
580  }
581  goto packet_enqueue;
582  }
583  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
584  (u8 *) frag_hdr - (u8 *) ip0;
585  if (0 == ip6_frag_hdr_offset (frag_hdr))
586  {
587  // first fragment - verify upper-layer is present
589  (node, b0, frag_hdr))
590  {
592  goto packet_enqueue;
593  }
594  }
596  (vm, node, b0, frag_hdr)
597  || !ip6_sv_reass_verify_packet_size_lt_64k (vm, node, b0,
598  frag_hdr))
599  {
601  goto packet_enqueue;
602  }
603 
605  u8 do_handoff = 0;
606 
607  kv.k.as_u64[0] = ip0->src_address.as_u64[0];
608  kv.k.as_u64[1] = ip0->src_address.as_u64[1];
609  kv.k.as_u64[2] = ip0->dst_address.as_u64[0];
610  kv.k.as_u64[3] = ip0->dst_address.as_u64[1];
611  kv.k.as_u64[4] =
613  vnet_buffer (b0)->sw_if_index[VLIB_RX])) << 32 |
614  (u64) frag_hdr->identification;
615  kv.k.as_u64[5] = ip0->protocol;
616 
617  ip6_sv_reass_t *reass =
618  ip6_sv_reass_find_or_create (vm, node, rm, rt, &kv, &icmp_bi,
619  &do_handoff);
620 
621  if (PREDICT_FALSE (do_handoff))
622  {
624  vnet_buffer (b0)->ip.reass.owner_thread_index =
625  kv.v.thread_index;
626  goto packet_enqueue;
627  }
628 
629  if (!reass)
630  {
632  error0 = IP6_ERROR_REASS_LIMIT_REACHED;
633  b0->error = node->errors[error0];
634  goto packet_enqueue;
635  }
636 
637  if (reass->is_complete)
638  {
639  vnet_buffer (b0)->ip.reass.is_non_first_fragment =
640  ! !ip6_frag_hdr_offset (frag_hdr);
641  vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
642  vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
643  reass->icmp_type_or_tcp_flags;
644  vnet_buffer (b0)->ip.reass.tcp_ack_number =
645  reass->tcp_ack_number;
646  vnet_buffer (b0)->ip.reass.tcp_seq_number =
647  reass->tcp_seq_number;
648  vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
649  vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
651  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
652  {
653  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
655  reass->ip_proto,
656  reass->l4_src_port,
657  reass->l4_dst_port);
658  }
659  goto packet_enqueue;
660  }
661 
662  switch (ip6_sv_reass_update
663  (vm, node, rm, rt, reass, bi0, frag_hdr))
664  {
665  case IP6_SV_REASS_RC_OK:
666  /* nothing to do here */
667  break;
670  IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
671  1);
672  ip6_sv_reass_free (vm, rm, rt, reass);
673  goto next_packet;
674  break;
677  IP6_ERROR_REASS_UNSUPP_IP_PROTO,
678  1);
679  ip6_sv_reass_free (vm, rm, rt, reass);
680  goto next_packet;
681  break;
684  IP6_ERROR_REASS_INTERNAL_ERROR, 1);
685  ip6_sv_reass_free (vm, rm, rt, reass);
686  goto next_packet;
687  break;
688  }
689 
690  if (reass->is_complete)
691  {
692  u32 idx;
693  vec_foreach_index (idx, reass->cached_buffers)
694  {
695  u32 bi0 = vec_elt (reass->cached_buffers, idx);
696  if (0 == n_left_to_next)
697  {
698  vlib_put_next_frame (vm, node, next_index,
699  n_left_to_next);
700  vlib_get_next_frame (vm, node, next_index, to_next,
701  n_left_to_next);
702  }
703  to_next[0] = bi0;
704  to_next += 1;
705  n_left_to_next -= 1;
706  b0 = vlib_get_buffer (vm, bi0);
707  if (is_feature)
708  {
709  vnet_feature_next (&next0, b0);
710  }
711  frag_hdr =
713  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset;
714  vnet_buffer (b0)->ip.reass.is_non_first_fragment =
715  ! !ip6_frag_hdr_offset (frag_hdr);
716  vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
717  vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
718  reass->icmp_type_or_tcp_flags;
719  vnet_buffer (b0)->ip.reass.tcp_ack_number =
720  reass->tcp_ack_number;
721  vnet_buffer (b0)->ip.reass.tcp_seq_number =
722  reass->tcp_seq_number;
723  vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
724  vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
725  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
726  {
727  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
729  reass->ip_proto,
730  reass->l4_src_port,
731  reass->l4_dst_port);
732  }
733  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
734  to_next, n_left_to_next, bi0,
735  next0);
736  }
737  _vec_len (reass->cached_buffers) = 0; // buffers are owned by frame now
738  }
739  goto next_packet;
740 
741  packet_enqueue:
742  to_next[0] = bi0;
743  to_next += 1;
744  n_left_to_next -= 1;
745  if (is_feature && IP6_ERROR_NONE == error0)
746  {
747  b0 = vlib_get_buffer (vm, bi0);
748  vnet_feature_next (&next0, b0);
749  }
750  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
751  n_left_to_next, bi0, next0);
752 
753  if (~0 != icmp_bi)
754  {
756  to_next[0] = icmp_bi;
757  to_next += 1;
758  n_left_to_next -= 1;
759  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
760  n_left_to_next, icmp_bi,
761  next0);
762  }
763 
764  next_packet:
765  from += 1;
766  n_left_from -= 1;
767  }
768 
769  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
770  }
771 
772  clib_spinlock_unlock (&rt->lock);
773  return frame->n_vectors;
774 }
775 
777 #define _(sym, string) string,
779 #undef _
780 };
781 
785 {
786  return ip6_sv_reassembly_inline (vm, node, frame, false /* is_feature */ );
787 }
788 
789 /* *INDENT-OFF* */
791  .name = "ip6-sv-reassembly",
792  .vector_size = sizeof (u32),
793  .format_trace = format_ip6_sv_reass_trace,
794  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
795  .error_strings = ip6_sv_reassembly_error_strings,
796  .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
797  .next_nodes =
798  {
799  [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
800  [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
801  [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
802  [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reassembly-handoff",
803  },
804 };
805 /* *INDENT-ON* */
806 
810 {
811  return ip6_sv_reassembly_inline (vm, node, frame, true /* is_feature */ );
812 }
813 
814 /* *INDENT-OFF* */
816  .name = "ip6-sv-reassembly-feature",
817  .vector_size = sizeof (u32),
818  .format_trace = format_ip6_sv_reass_trace,
819  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
820  .error_strings = ip6_sv_reassembly_error_strings,
821  .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
822  .next_nodes =
823  {
824  [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
825  [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
826  [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
827  [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reass-feature-hoff",
828  },
829 };
830 /* *INDENT-ON* */
831 
832 /* *INDENT-OFF* */
833 VNET_FEATURE_INIT (ip6_sv_reassembly_feature) = {
834  .arc_name = "ip6-unicast",
835  .node_name = "ip6-sv-reassembly-feature",
836  .runs_before = VNET_FEATURES ("ip6-lookup"),
837  .runs_after = 0,
838 };
839 /* *INDENT-ON* */
840 
841 #ifndef CLIB_MARCH_VARIANT
842 static u32
844 {
846  u32 nbuckets;
847  u8 i;
848 
849  nbuckets = (u32) (rm->max_reass_n / IP6_SV_REASS_HT_LOAD_FACTOR);
850 
851  for (i = 0; i < 31; i++)
852  if ((1 << i) >= nbuckets)
853  break;
854  nbuckets = 1 << i;
855 
856  return nbuckets;
857 }
858 #endif /* CLIB_MARCH_VARIANT */
859 
860 typedef enum
861 {
864 
865 #ifndef CLIB_MARCH_VARIANT
866 typedef struct
867 {
868  int failure;
869  clib_bihash_48_8_t *new_hash;
871 
872 static int
874 {
875  ip6_rehash_cb_ctx *ctx = _ctx;
876  if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1))
877  {
878  ctx->failure = 1;
879  }
880  return (BIHASH_WALK_CONTINUE);
881 }
882 
883 static void
884 ip6_sv_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
885  u32 max_reassembly_length,
886  u32 expire_walk_interval_ms)
887 {
888  ip6_sv_reass_main.timeout_ms = timeout_ms;
889  ip6_sv_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
890  ip6_sv_reass_main.max_reass_n = max_reassemblies;
891  ip6_sv_reass_main.max_reass_len = max_reassembly_length;
892  ip6_sv_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
893 }
894 
896 ip6_sv_reass_set (u32 timeout_ms, u32 max_reassemblies,
897  u32 max_reassembly_length, u32 expire_walk_interval_ms)
898 {
899  u32 old_nbuckets = ip6_sv_reass_get_nbuckets ();
900  ip6_sv_reass_set_params (timeout_ms, max_reassemblies,
901  max_reassembly_length, expire_walk_interval_ms);
902  vlib_process_signal_event (ip6_sv_reass_main.vlib_main,
903  ip6_sv_reass_main.ip6_sv_reass_expire_node_idx,
905  u32 new_nbuckets = ip6_sv_reass_get_nbuckets ();
906  if (ip6_sv_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
907  {
908  clib_bihash_48_8_t new_hash;
909  clib_memset (&new_hash, 0, sizeof (new_hash));
911  ctx.failure = 0;
912  ctx.new_hash = &new_hash;
913  clib_bihash_init_48_8 (&new_hash, "ip6-sv-reass", new_nbuckets,
914  new_nbuckets * 1024);
915  clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.hash,
916  ip6_rehash_cb, &ctx);
917  if (ctx.failure)
918  {
919  clib_bihash_free_48_8 (&new_hash);
920  return -1;
921  }
922  else
923  {
924  clib_bihash_free_48_8 (&ip6_sv_reass_main.hash);
925  clib_memcpy_fast (&ip6_sv_reass_main.hash, &new_hash,
926  sizeof (ip6_sv_reass_main.hash));
927  clib_bihash_copied (&ip6_sv_reass_main.hash, &new_hash);
928  }
929  }
930  return 0;
931 }
932 
934 ip6_sv_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
935  u32 * max_reassembly_length, u32 * expire_walk_interval_ms)
936 {
937  *timeout_ms = ip6_sv_reass_main.timeout_ms;
938  *max_reassemblies = ip6_sv_reass_main.max_reass_n;
939  *max_reassembly_length = ip6_sv_reass_main.max_reass_len;
940  *expire_walk_interval_ms = ip6_sv_reass_main.expire_walk_interval_ms;
941  return 0;
942 }
943 
944 static clib_error_t *
946 {
948  clib_error_t *error = 0;
949  u32 nbuckets;
950  vlib_node_t *node;
951 
952  rm->vlib_main = vm;
953  rm->vnet_main = vnet_get_main ();
954 
957  vec_foreach (rt, rm->per_thread_data)
958  {
959  clib_spinlock_init (&rt->lock);
960  pool_alloc (rt->pool, rm->max_reass_n);
961  rt->lru_first = rt->lru_last = ~0;
962  }
963 
964  node = vlib_get_node_by_name (vm, (u8 *) "ip6-sv-reassembly-expire-walk");
965  ASSERT (node);
967 
972 
973  nbuckets = ip6_sv_reass_get_nbuckets ();
974  clib_bihash_init_48_8 (&rm->hash, "ip6-sv-reass", nbuckets,
975  nbuckets * 1024);
976 
977  node = vlib_get_node_by_name (vm, (u8 *) "ip6-drop");
978  ASSERT (node);
979  rm->ip6_drop_idx = node->index;
980  node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error");
981  ASSERT (node);
982  rm->ip6_icmp_error_idx = node->index;
983 
984  if ((error = vlib_call_init_function (vm, ip_main_init)))
985  return error;
986  ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
987  ip6_sv_reass_node.index);
988 
990  rm->fq_feature_index =
992 
994 
995  return error;
996 }
997 
999 #endif /* CLIB_MARCH_VARIANT */
1000 
1001 static uword
1003  vlib_node_runtime_t * node, vlib_frame_t * f)
1004 {
1006  uword event_type, *event_data = 0;
1007 
1008  while (true)
1009  {
1012  / (f64) MSEC_PER_SEC);
1013  event_type = vlib_process_get_events (vm, &event_data);
1014 
1015  switch (event_type)
1016  {
1017  case ~0: /* no events => timeout */
1018  /* nothing to do here */
1019  break;
1021  break;
1022  default:
1023  clib_warning ("BUG: event type 0x%wx", event_type);
1024  break;
1025  }
1026  f64 now = vlib_time_now (vm);
1027 
1028  ip6_sv_reass_t *reass;
1029  int *pool_indexes_to_free = NULL;
1030 
1031  uword thread_index = 0;
1032  int index;
1033  const uword nthreads = vlib_num_workers () + 1;
1034  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1035  {
1036  ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1037  clib_spinlock_lock (&rt->lock);
1038 
1039  vec_reset_length (pool_indexes_to_free);
1040  /* *INDENT-OFF* */
1041  pool_foreach_index (index, rt->pool) {
1042  reass = pool_elt_at_index (rt->pool, index);
1043  if (now > reass->last_heard + rm->timeout)
1044  {
1045  vec_add1 (pool_indexes_to_free, index);
1046  }
1047  }
1048  /* *INDENT-ON* */
1049  int *i;
1050  /* *INDENT-OFF* */
1051  vec_foreach (i, pool_indexes_to_free)
1052  {
1053  ip6_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1054  ip6_sv_reass_free (vm, rm, rt, reass);
1055  }
1056  /* *INDENT-ON* */
1057 
1058  clib_spinlock_unlock (&rt->lock);
1059  }
1060 
1061  vec_free (pool_indexes_to_free);
1062  if (event_data)
1063  {
1064  _vec_len (event_data) = 0;
1065  }
1066  }
1067 
1068  return 0;
1069 }
1070 
1071 /* *INDENT-OFF* */
1073  .function = ip6_sv_reass_walk_expired,
1074  .format_trace = format_ip6_sv_reass_trace,
1075  .type = VLIB_NODE_TYPE_PROCESS,
1076  .name = "ip6-sv-reassembly-expire-walk",
1077 
1078  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
1079  .error_strings = ip6_sv_reassembly_error_strings,
1080 
1081 };
1082 /* *INDENT-ON* */
1083 
1084 static u8 *
1085 format_ip6_sv_reass_key (u8 * s, va_list * args)
1086 {
1087  ip6_sv_reass_key_t *key = va_arg (*args, ip6_sv_reass_key_t *);
1088  s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1090  &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1091  return s;
1092 }
1093 
1094 static u8 *
1095 format_ip6_sv_reass (u8 * s, va_list * args)
1096 {
1097  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1098  ip6_sv_reass_t *reass = va_arg (*args, ip6_sv_reass_t *);
1099 
1100  s = format (s, "ID: %lu, key: %U, trace_op_counter: %u\n",
1101  reass->id, format_ip6_sv_reass_key, &reass->key,
1102  reass->trace_op_counter);
1103  vlib_buffer_t *b;
1104  u32 *bip;
1105  u32 counter = 0;
1106  vec_foreach (bip, reass->cached_buffers)
1107  {
1108  u32 bi = *bip;
1109  do
1110  {
1111  b = vlib_get_buffer (vm, bi);
1112  s = format (s, " #%03u: bi: %u\n", counter, bi);
1113  ++counter;
1114  bi = b->next_buffer;
1115  }
1116  while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
1117  }
1118  return s;
1119 }
1120 
1121 static clib_error_t *
1124 {
1126 
1127  vlib_cli_output (vm, "---------------------");
1128  vlib_cli_output (vm, "IP6 reassembly status");
1129  vlib_cli_output (vm, "---------------------");
1130  bool details = false;
1131  if (unformat (input, "details"))
1132  {
1133  details = true;
1134  }
1135 
1136  u32 sum_reass_n = 0;
1137  u64 sum_buffers_n = 0;
1138  ip6_sv_reass_t *reass;
1139  uword thread_index;
1140  const uword nthreads = vlib_num_workers () + 1;
1141  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1142  {
1143  ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1144  clib_spinlock_lock (&rt->lock);
1145  if (details)
1146  {
1147  /* *INDENT-OFF* */
1148  pool_foreach (reass, rt->pool) {
1149  vlib_cli_output (vm, "%U", format_ip6_sv_reass, vm, reass);
1150  }
1151  /* *INDENT-ON* */
1152  }
1153  sum_reass_n += rt->reass_n;
1154  clib_spinlock_unlock (&rt->lock);
1155  }
1156  vlib_cli_output (vm, "---------------------");
1157  vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1158  (long unsigned) sum_reass_n);
1159  vlib_cli_output (vm,
1160  "Maximum configured concurrent shallow virtual IP6 reassemblies per worker-thread: %lu\n",
1161  (long unsigned) rm->max_reass_n);
1162  vlib_cli_output (vm,
1163  "Maximum configured shallow virtual IP6 reassembly timeout: %lums\n",
1164  (long unsigned) rm->timeout_ms);
1165  vlib_cli_output (vm,
1166  "Maximum configured shallow virtual IP6 reassembly expire walk interval: %lums\n",
1167  (long unsigned) rm->expire_walk_interval_ms);
1168  vlib_cli_output (vm, "Buffers in use: %lu\n",
1169  (long unsigned) sum_buffers_n);
1170  return 0;
1171 }
1172 
1173 /* *INDENT-OFF* */
1174 VLIB_CLI_COMMAND (show_ip6_sv_reassembly_cmd, static) = {
1175  .path = "show ip6-sv-reassembly",
1176  .short_help = "show ip6-sv-reassembly [details]",
1177  .function = show_ip6_sv_reass,
1178 };
1179 /* *INDENT-ON* */
1180 
1181 #ifndef CLIB_MARCH_VARIANT
1184 {
1185  return ip6_sv_reass_enable_disable_with_refcnt (sw_if_index,
1186  enable_disable);
1187 }
1188 #endif /* CLIB_MARCH_VARIANT */
1189 
1190 #define foreach_ip6_sv_reassembly_handoff_error \
1191 _(CONGESTION_DROP, "congestion drop")
1192 
1193 
1194 typedef enum
1195 {
1196 #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym,
1198 #undef _
1201 
1202 static char *ip6_sv_reassembly_handoff_error_strings[] = {
1203 #define _(sym,string) string,
1205 #undef _
1206 };
1207 
1208 typedef struct
1209 {
1212 
1213 static u8 *
1215 {
1216  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1217  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1219  va_arg (*args, ip6_sv_reassembly_handoff_trace_t *);
1220 
1221  s =
1222  format (s, "ip6-sv-reassembly-handoff: next-worker %d",
1223  t->next_worker_index);
1224 
1225  return s;
1226 }
1227 
1230  vlib_node_runtime_t * node,
1231  vlib_frame_t * frame, bool is_feature)
1232 {
1234 
1235  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1236  u32 n_enq, n_left_from, *from;
1237  u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1238  u32 fq_index;
1239 
1240  from = vlib_frame_vector_args (frame);
1241  n_left_from = frame->n_vectors;
1242  vlib_get_buffers (vm, from, bufs, n_left_from);
1243 
1244  b = bufs;
1245  ti = thread_indices;
1246 
1247  fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1248 
1249  while (n_left_from > 0)
1250  {
1251  ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1252 
1253  if (PREDICT_FALSE
1254  ((node->flags & VLIB_NODE_FLAG_TRACE)
1255  && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1256  {
1258  vlib_add_trace (vm, node, b[0], sizeof (*t));
1259  t->next_worker_index = ti[0];
1260  }
1261 
1262  n_left_from -= 1;
1263  ti += 1;
1264  b += 1;
1265  }
1266  n_enq =
1267  vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices,
1268  frame->n_vectors, 1);
1269 
1270  if (n_enq < frame->n_vectors)
1272  IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1273  frame->n_vectors - n_enq);
1274  return frame->n_vectors;
1275 }
1276 
1277 VLIB_NODE_FN (ip6_sv_reassembly_handoff_node) (vlib_main_t * vm,
1279  vlib_frame_t * frame)
1280 {
1281  return ip6_sv_reassembly_handoff_inline (vm, node, frame,
1282  false /* is_feature */ );
1283 }
1284 
1285 /* *INDENT-OFF* */
1286 VLIB_REGISTER_NODE (ip6_sv_reassembly_handoff_node) = {
1287  .name = "ip6-sv-reassembly-handoff",
1288  .vector_size = sizeof (u32),
1289  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1290  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1292 
1293  .n_next_nodes = 1,
1294 
1295  .next_nodes = {
1296  [0] = "error-drop",
1297  },
1298 };
1299 
1300 
1301 VLIB_NODE_FN (ip6_sv_reassembly_feature_handoff_node) (vlib_main_t * vm,
1303 {
1304  return ip6_sv_reassembly_handoff_inline (vm, node, frame, true /* is_feature */ );
1305 }
1306 
1307 
1308 /* *INDENT-OFF* */
1309 VLIB_REGISTER_NODE (ip6_sv_reassembly_feature_handoff_node) = {
1310  .name = "ip6-sv-reass-feature-hoff",
1311  .vector_size = sizeof (u32),
1312  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1313  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1315 
1316  .n_next_nodes = 1,
1317 
1318  .next_nodes = {
1319  [0] = "error-drop",
1320  },
1321 };
1322 /* *INDENT-ON* */
1323 
1324 #ifndef CLIB_MARCH_VARIANT
1325 int
1327 {
1329  vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
1330  if (is_enable)
1331  {
1332  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1333  {
1335  return vnet_feature_enable_disable ("ip6-unicast",
1336  "ip6-sv-reassembly-feature",
1337  sw_if_index, 1, 0, 0);
1338  }
1340  }
1341  else
1342  {
1344  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1345  return vnet_feature_enable_disable ("ip6-unicast",
1346  "ip6-sv-reassembly-feature",
1347  sw_if_index, 0, 0, 0);
1348  }
1349  return 0;
1350 }
1351 #endif
1352 
1353 /*
1354  * fd.io coding-style-patch-verification: ON
1355  *
1356  * Local Variables:
1357  * eval: (c-set-style "gnu")
1358  * End:
1359  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
VNET_FEATURE_INIT(ip6_sv_reassembly_feature)
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:124
#define vec_foreach_index(var, v)
Iterate over vector indices.
vnet_api_error_t
Definition: api_errno.h:162
static bool ip6_sv_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)
Definition: ip6_sv_reass.c:491
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:121
#define pool_foreach_index(i, v)
Definition: pool.h:569
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:82
#define CLIB_UNUSED(x)
Definition: clib.h:87
static char * ip6_sv_reassembly_handoff_error_strings[]
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:751
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1668
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:937
static u32 vlib_buffer_get_trace_index(vlib_buffer_t *b)
Extract the trace (pool) index from a trace handle.
Definition: buffer.h:392
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
struct vnet_buffer_opaque_t::@174::@176 ip
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:527
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
Definition: pool.h:360
u64 as_u64
Definition: bihash_doc.h:63
unsigned long u64
Definition: types.h:89
static uword ip6_sv_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
#define IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT
Definition: ip6_sv_reass.c:34
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
clib_bihash_48_8_t * new_hash
ip_proto
Definition: ip_types.api:75
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:280
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:334
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1880
u32 thread_index
Definition: main.h:250
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
static ip6_sv_reass_rc_t ip6_sv_reass_update(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_sv_reass_main_t *rm, ip6_sv_reass_per_thread_t *rt, ip6_sv_reass_t *reass, u32 bi0, ip6_frag_hdr_t *frag_hdr)
Definition: ip6_sv_reass.c:384
#define IP6_SV_REASS_MAX_REASSEMBLIES_DEFAULT
Definition: ip6_sv_reass.c:33
static void ip6_sv_reass_set_params(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
Definition: ip6_sv_reass.c:884
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
Definition: ip6_packet.h:518
u32 * feature_use_refcount_per_intf
Definition: ip6_sv_reass.c:153
vlib_main_t * vm
Definition: in2out_ed.c:1580
#define VLIB_NODE_FN(node)
Definition: node.h:203
static u16 ip6_get_port(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6, u16 buffer_len, u8 *ip_protocol, u16 *src_port, u16 *dst_port, u8 *icmp_type_or_tcp_flags, u32 *tcp_ack_number, u32 *tcp_seq_number)
Get L4 information like port number or ICMP id from IPv6 packet.
Definition: ip6_to_ip4.h:117
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:470
static clib_error_t * ip6_sv_reass_init_function(vlib_main_t *vm)
Definition: ip6_sv_reass.c:945
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:402
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:251
ip6_address_t src_address
Definition: ip6_packet.h:310
unsigned char u8
Definition: types.h:56
#define MSEC_PER_SEC
Definition: ip6_sv_reass.c:30
ip6_sv_reass_key_t k
Definition: ip6_sv_reass.c:76
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static void ip6_sv_reass_free(vlib_main_t *vm, ip6_sv_reass_main_t *rm, ip6_sv_reass_per_thread_t *rt, ip6_sv_reass_t *reass)
Definition: ip6_sv_reass.c:259
double f64
Definition: types.h:142
clib_bihash_48_8_t hash
Definition: ip6_sv_reass.c:134
ip6_address_t dst
Definition: ip6_sv_reass.c:52
vlib_trace_header_t ** trace_buffer_pool
Definition: trace.h:86
ip6_sv_reass_rc_t
Definition: ip6_sv_reass.c:37
ip6_sv_reass_event_t
Definition: ip6_sv_reass.c:860
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
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:579
ip6_sv_reass_trace_operation_e action
Definition: ip6_sv_reass.c:181
description fragment has unexpected format
Definition: map.api:433
static u8 * format_ip6_sv_reass(u8 *s, va_list *args)
ip6_sv_reass_per_thread_t * per_thread_data
Definition: ip6_sv_reass.c:137
static int ip6_rehash_cb(clib_bihash_kv_48_8_t *kv, void *_ctx)
Definition: ip6_sv_reass.c:873
vlib_node_registration_t ip6_sv_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_expire_node)
const cJSON *const b
Definition: cJSON.h:255
static uword ip6_sv_reassembly_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
Definition: ip6_sv_reass.c:514
static bool ip6_sv_reass_verify_fragment_multiple_8(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
Definition: ip6_sv_reass.c:469
unsigned int u32
Definition: types.h:88
#define vlib_call_init_function(vm, x)
Definition: init.h:270
#define VLIB_FRAME_SIZE
Definition: node.h:378
static void * ip6_ext_header_find(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6_header, u8 header_type, ip6_ext_header_t **prev_ext_header)
Definition: ip6_packet.h:544
#define foreach_ip6_sv_reassembly_handoff_error
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:65
#define ip6_frag_hdr_more(hdr)
Definition: ip6_packet.h:675
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
#define IP6_SV_REASS_HT_LOAD_FACTOR
Definition: ip6_sv_reass.c:35
Definition: cJSON.c:84
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
clib_bihash_kv_48_8_t kv
Definition: ip6_sv_reass.c:79
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1015
ip6_sv_reass_val_t v
Definition: ip6_sv_reass.c:77
IPv6 shallow virtual reassembly.
ip6_sv_reass_next_t
Definition: ip6_sv_reass.c:162
vnet_api_error_t ip6_sv_reass_enable_disable(u32 sw_if_index, u8 enable_disable)
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u8 icmp_type_or_tcp_flags
Definition: ip6_sv_reass.c:99
ip6_sv_reassembly_handoff_error_t
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:233
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
ip6_sv_reass_key_t key
Definition: ip6_sv_reass.c:85
ip6_sv_reass_trace_operation_e
Definition: ip6_sv_reass.c:171
#define PREDICT_FALSE(x)
Definition: clib.h:121
#define always_inline
Definition: ipsec.h:28
ip6_main_t ip6_main
Definition: ip6_forward.c:2785
static clib_error_t * show_ip6_sv_reass(vlib_main_t *vm, unformat_input_t *input, CLIB_UNUSED(vlib_cli_command_t *lmd))
ip6_sv_reass_t * pool
Definition: ip6_sv_reass.c:113
u32 node_index
Node index.
Definition: node.h:488
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
#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:391
vlib_main_t * vlib_main
Definition: ip6_sv_reass.c:140
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1231
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:170
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
u16 n_vectors
Definition: node.h:397
format_function_t format_ip6_address
Definition: format.h:91
u32 fq_index
Worker handoff.
Definition: ip6_sv_reass.c:149
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:322
#define clib_warning(format, args...)
Definition: error.h:59
__clib_export void clib_bihash_copied(void *dst, void *src)
static u32 ip6_sv_reass_get_nbuckets()
Definition: ip6_sv_reass.c:843
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:298
vnet_api_error_t ip6_sv_reass_set(u32 timeout_ms, u32 max_reassemblies, u32 max_reassembly_length, u32 expire_walk_interval_ms)
set ip6 reassembly configuration
Definition: ip6_sv_reass.c:896
#define ip6_frag_hdr_offset_bytes(hdr)
Definition: ip6_packet.h:672
#define ARRAY_LEN(x)
Definition: clib.h:67
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:483
static char * ip6_sv_reassembly_error_strings[]
Definition: ip6_sv_reass.c:776
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:493
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1580
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
#define ip6_frag_hdr_offset(hdr)
Definition: ip6_packet.h:669
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:511
#define ASSERT(truth)
#define IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
Definition: ip6_sv_reass.c:32
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:696
vnet_api_error_t ip6_sv_reass_get(u32 *timeout_ms, u32 *max_reassemblies, u32 *max_reassembly_length, u32 *expire_walk_interval_ms)
get ip6 reassembly configuration
Definition: ip6_sv_reass.c:934
ip6_address_t src
Definition: ip6_sv_reass.c:51
static bool ip6_sv_reass_verify_upper_layer_present(vlib_node_runtime_t *node, vlib_buffer_t *b, ip6_frag_hdr_t *frag_hdr)
Definition: ip6_sv_reass.c:447
vlib_trace_main_t trace_main
Definition: main.h:194
IPv6 to IPv4 translation.
int ip6_sv_reass_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
#define VNET_FEATURES(...)
Definition: feature.h:470
static void ip6_sv_reass_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_sv_reass_main_t *rm, ip6_sv_reass_t *reass, u32 bi, ip6_sv_reass_trace_operation_e action, u32 ip_proto, u16 l4_src_port, u16 l4_dst_port)
Definition: ip6_sv_reass.c:224
#define vec_elt(v, i)
Get vector value at index i.
typedef key
Definition: ipsec_types.api:86
u16 payload_length
Definition: ip6_packet.h:301
static void ip6_sv_reass_init(ip6_sv_reass_t *reass)
Definition: ip6_sv_reass.c:299
vl_api_address_t ip
Definition: l2.api:501
vnet_main_t * vnet_main
Definition: ip6_sv_reass.c:141
static uword ip6_sv_reassembly_handoff_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, bool is_feature)
vl_api_mac_event_action_t action
Definition: l2.api:181
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_node_registration_t ip6_sv_reass_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_node)
Definition: ip6_sv_reass.c:790
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
static u8 * format_ip6_sv_reass_key(u8 *s, va_list *args)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: in2out_ed.c:1581
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
ip6_sv_reass_main_t ip6_sv_reass_main
Definition: ip6_sv_reass.c:159
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:297
u32 index
Definition: flow_types.api:221
static ip6_sv_reass_t * ip6_sv_reass_find_or_create(vlib_main_t *vm, vlib_node_runtime_t *node, ip6_sv_reass_main_t *rm, ip6_sv_reass_per_thread_t *rt, ip6_sv_reass_kv_t *kv, u32 *icmp_bi, u8 *do_handoff)
Definition: ip6_sv_reass.c:306
#define foreach_ip6_error
Definition: ip6_error.h:43
static_always_inline u32 vlib_buffer_enqueue_to_thread(vlib_main_t *vm, u32 frame_queue_index, u32 *buffer_indices, u16 *thread_indices, u32 n_packets, int drop_on_congestion)
Definition: buffer_node.h:494
#define vnet_buffer(b)
Definition: buffer.h:417
static u32 vlib_num_workers()
Definition: threads.h:377
#define vec_foreach(var, vec)
Vector iterator.
u16 flags
Copy of main node flags.
Definition: node.h:501
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:634
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
Definition: buffer_funcs.h:280
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:302
static u8 * format_ip6_sv_reassembly_handoff_trace(u8 *s, va_list *args)
u32 * cached_buffers
Definition: ip6_sv_reass.c:94
u32 * fib_index_by_sw_if_index
Definition: ip6.h:127
vlib_node_registration_t ip6_sv_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_node_feature)
Definition: ip6_sv_reass.c:815
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static u8 * format_ip6_sv_reass_trace(u8 *s, va_list *args)
Definition: ip6_sv_reass.c:190
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
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:303
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
ip6_address_t dst_address
Definition: ip6_packet.h:310
#define IP6_SV_REASS_TIMEOUT_DEFAULT_MS
Definition: ip6_sv_reass.c:31