FD.io VPP  v21.06
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 
988  rm->fq_feature_index =
990 
992 
993  return error;
994 }
995 
997 #endif /* CLIB_MARCH_VARIANT */
998 
999 static uword
1002 {
1004  uword event_type, *event_data = 0;
1005 
1006  while (true)
1007  {
1010  / (f64) MSEC_PER_SEC);
1011  event_type = vlib_process_get_events (vm, &event_data);
1012 
1013  switch (event_type)
1014  {
1015  case ~0: /* no events => timeout */
1016  /* nothing to do here */
1017  break;
1019  break;
1020  default:
1021  clib_warning ("BUG: event type 0x%wx", event_type);
1022  break;
1023  }
1024  f64 now = vlib_time_now (vm);
1025 
1026  ip6_sv_reass_t *reass;
1027  int *pool_indexes_to_free = NULL;
1028 
1029  uword thread_index = 0;
1030  int index;
1031  const uword nthreads = vlib_num_workers () + 1;
1032  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1033  {
1035  clib_spinlock_lock (&rt->lock);
1036 
1037  vec_reset_length (pool_indexes_to_free);
1038  /* *INDENT-OFF* */
1039  pool_foreach_index (index, rt->pool) {
1040  reass = pool_elt_at_index (rt->pool, index);
1041  if (now > reass->last_heard + rm->timeout)
1042  {
1043  vec_add1 (pool_indexes_to_free, index);
1044  }
1045  }
1046  /* *INDENT-ON* */
1047  int *i;
1048  /* *INDENT-OFF* */
1049  vec_foreach (i, pool_indexes_to_free)
1050  {
1051  ip6_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1052  ip6_sv_reass_free (vm, rm, rt, reass);
1053  }
1054  /* *INDENT-ON* */
1055 
1056  clib_spinlock_unlock (&rt->lock);
1057  }
1058 
1059  vec_free (pool_indexes_to_free);
1060  if (event_data)
1061  {
1062  _vec_len (event_data) = 0;
1063  }
1064  }
1065 
1066  return 0;
1067 }
1068 
1069 /* *INDENT-OFF* */
1071  .function = ip6_sv_reass_walk_expired,
1072  .format_trace = format_ip6_sv_reass_trace,
1073  .type = VLIB_NODE_TYPE_PROCESS,
1074  .name = "ip6-sv-reassembly-expire-walk",
1075 
1076  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
1077  .error_strings = ip6_sv_reassembly_error_strings,
1078 
1079 };
1080 /* *INDENT-ON* */
1081 
1082 static u8 *
1083 format_ip6_sv_reass_key (u8 * s, va_list * args)
1084 {
1085  ip6_sv_reass_key_t *key = va_arg (*args, ip6_sv_reass_key_t *);
1086  s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1088  &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1089  return s;
1090 }
1091 
1092 static u8 *
1093 format_ip6_sv_reass (u8 * s, va_list * args)
1094 {
1095  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1096  ip6_sv_reass_t *reass = va_arg (*args, ip6_sv_reass_t *);
1097 
1098  s = format (s, "ID: %lu, key: %U, trace_op_counter: %u\n",
1099  reass->id, format_ip6_sv_reass_key, &reass->key,
1100  reass->trace_op_counter);
1101  vlib_buffer_t *b;
1102  u32 *bip;
1103  u32 counter = 0;
1104  vec_foreach (bip, reass->cached_buffers)
1105  {
1106  u32 bi = *bip;
1107  do
1108  {
1109  b = vlib_get_buffer (vm, bi);
1110  s = format (s, " #%03u: bi: %u\n", counter, bi);
1111  ++counter;
1112  bi = b->next_buffer;
1113  }
1114  while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
1115  }
1116  return s;
1117 }
1118 
1119 static clib_error_t *
1122 {
1124 
1125  vlib_cli_output (vm, "---------------------");
1126  vlib_cli_output (vm, "IP6 reassembly status");
1127  vlib_cli_output (vm, "---------------------");
1128  bool details = false;
1129  if (unformat (input, "details"))
1130  {
1131  details = true;
1132  }
1133 
1134  u32 sum_reass_n = 0;
1135  u64 sum_buffers_n = 0;
1136  ip6_sv_reass_t *reass;
1138  const uword nthreads = vlib_num_workers () + 1;
1139  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1140  {
1142  clib_spinlock_lock (&rt->lock);
1143  if (details)
1144  {
1145  /* *INDENT-OFF* */
1146  pool_foreach (reass, rt->pool) {
1147  vlib_cli_output (vm, "%U", format_ip6_sv_reass, vm, reass);
1148  }
1149  /* *INDENT-ON* */
1150  }
1151  sum_reass_n += rt->reass_n;
1152  clib_spinlock_unlock (&rt->lock);
1153  }
1154  vlib_cli_output (vm, "---------------------");
1155  vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1156  (long unsigned) sum_reass_n);
1157  vlib_cli_output (vm,
1158  "Maximum configured concurrent shallow virtual IP6 reassemblies per worker-thread: %lu\n",
1159  (long unsigned) rm->max_reass_n);
1160  vlib_cli_output (vm,
1161  "Maximum configured amount of fragments per shallow "
1162  "virtual IP6 reassembly: %lu\n",
1163  (long unsigned) rm->max_reass_len);
1164  vlib_cli_output (vm,
1165  "Maximum configured shallow virtual IP6 reassembly timeout: %lums\n",
1166  (long unsigned) rm->timeout_ms);
1167  vlib_cli_output (vm,
1168  "Maximum configured shallow virtual IP6 reassembly expire walk interval: %lums\n",
1169  (long unsigned) rm->expire_walk_interval_ms);
1170  vlib_cli_output (vm, "Buffers in use: %lu\n",
1171  (long unsigned) sum_buffers_n);
1172  return 0;
1173 }
1174 
1175 /* *INDENT-OFF* */
1176 VLIB_CLI_COMMAND (show_ip6_sv_reassembly_cmd, static) = {
1177  .path = "show ip6-sv-reassembly",
1178  .short_help = "show ip6-sv-reassembly [details]",
1179  .function = show_ip6_sv_reass,
1180 };
1181 /* *INDENT-ON* */
1182 
1183 #ifndef CLIB_MARCH_VARIANT
1186 {
1187  return ip6_sv_reass_enable_disable_with_refcnt (sw_if_index,
1188  enable_disable);
1189 }
1190 #endif /* CLIB_MARCH_VARIANT */
1191 
1192 #define foreach_ip6_sv_reassembly_handoff_error \
1193 _(CONGESTION_DROP, "congestion drop")
1194 
1195 
1196 typedef enum
1197 {
1198 #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym,
1200 #undef _
1203 
1204 static char *ip6_sv_reassembly_handoff_error_strings[] = {
1205 #define _(sym,string) string,
1207 #undef _
1208 };
1209 
1210 typedef struct
1211 {
1214 
1215 static u8 *
1217 {
1218  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1219  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1221  va_arg (*args, ip6_sv_reassembly_handoff_trace_t *);
1222 
1223  s =
1224  format (s, "ip6-sv-reassembly-handoff: next-worker %d",
1225  t->next_worker_index);
1226 
1227  return s;
1228 }
1229 
1232  vlib_node_runtime_t * node,
1233  vlib_frame_t * frame, bool is_feature)
1234 {
1236 
1238  u32 n_enq, n_left_from, *from;
1239  u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1240  u32 fq_index;
1241 
1242  from = vlib_frame_vector_args (frame);
1243  n_left_from = frame->n_vectors;
1244  vlib_get_buffers (vm, from, bufs, n_left_from);
1245 
1246  b = bufs;
1247  ti = thread_indices;
1248 
1249  fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1250 
1251  while (n_left_from > 0)
1252  {
1253  ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1254 
1255  if (PREDICT_FALSE
1256  ((node->flags & VLIB_NODE_FLAG_TRACE)
1257  && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1258  {
1260  vlib_add_trace (vm, node, b[0], sizeof (*t));
1261  t->next_worker_index = ti[0];
1262  }
1263 
1264  n_left_from -= 1;
1265  ti += 1;
1266  b += 1;
1267  }
1268  n_enq = vlib_buffer_enqueue_to_thread (vm, node, fq_index, from,
1269  thread_indices, frame->n_vectors, 1);
1270 
1271  if (n_enq < frame->n_vectors)
1273  IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1274  frame->n_vectors - n_enq);
1275  return frame->n_vectors;
1276 }
1277 
1278 VLIB_NODE_FN (ip6_sv_reassembly_handoff_node) (vlib_main_t * vm,
1280  vlib_frame_t * frame)
1281 {
1282  return ip6_sv_reassembly_handoff_inline (vm, node, frame,
1283  false /* is_feature */ );
1284 }
1285 
1286 /* *INDENT-OFF* */
1287 VLIB_REGISTER_NODE (ip6_sv_reassembly_handoff_node) = {
1288  .name = "ip6-sv-reassembly-handoff",
1289  .vector_size = sizeof (u32),
1290  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1291  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1293 
1294  .n_next_nodes = 1,
1295 
1296  .next_nodes = {
1297  [0] = "error-drop",
1298  },
1299 };
1300 
1301 
1302 VLIB_NODE_FN (ip6_sv_reassembly_feature_handoff_node) (vlib_main_t * vm,
1304 {
1305  return ip6_sv_reassembly_handoff_inline (vm, node, frame, true /* is_feature */ );
1306 }
1307 
1308 
1309 /* *INDENT-OFF* */
1310 VLIB_REGISTER_NODE (ip6_sv_reassembly_feature_handoff_node) = {
1311  .name = "ip6-sv-reass-feature-hoff",
1312  .vector_size = sizeof (u32),
1313  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1314  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1316 
1317  .n_next_nodes = 1,
1318 
1319  .next_nodes = {
1320  [0] = "error-drop",
1321  },
1322 };
1323 /* *INDENT-ON* */
1324 
1325 #ifndef CLIB_MARCH_VARIANT
1326 int
1328 {
1330  vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
1331  if (is_enable)
1332  {
1333  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1334  {
1336  return vnet_feature_enable_disable ("ip6-unicast",
1337  "ip6-sv-reassembly-feature",
1338  sw_if_index, 1, 0, 0);
1339  }
1341  }
1342  else
1343  {
1345  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1346  return vnet_feature_enable_disable ("ip6-unicast",
1347  "ip6-sv-reassembly-feature",
1348  sw_if_index, 0, 0, 0);
1349  }
1350  return 0;
1351 }
1352 #endif
1353 
1354 /*
1355  * fd.io coding-style-patch-verification: ON
1356  *
1357  * Local Variables:
1358  * eval: (c-set-style "gnu")
1359  * End:
1360  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:524
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:133
#define vec_foreach_index(var, v)
Iterate over vector indices.
vnet_api_error_t
Definition: api_errno.h:162
vnet_interface_output_runtime_t * rt
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:576
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:82
#define CLIB_UNUSED(x)
Definition: clib.h:90
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:755
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:982
static u32 vlib_buffer_get_trace_index(vlib_buffer_t *b)
Extract the trace (pool) index from a trace handle.
Definition: buffer.h:416
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
Definition: pool.h:367
u64 as_u64
Definition: bihash_doc.h:63
u32 thread_index
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
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:270
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:325
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1572
u32 thread_index
Definition: main.h:213
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:607
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:549
u32 * feature_use_refcount_per_intf
Definition: ip6_sv_reass.c:153
#define VLIB_NODE_FN(node)
Definition: node.h:202
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:461
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:433
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
ip6_address_t src_address
Definition: ip6_packet.h:310
unsigned char u8
Definition: types.h:56
vlib_buffer_t ** b
#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
unsigned int u32
Definition: types.h:88
vlib_frame_t * f
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:172
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:583
vlib_get_buffers(vm, from, b, n_left_from)
return frame n_vectors
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)
vnet_main_t * vnet_get_main(void)
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
#define vlib_call_init_function(vm, x)
Definition: init.h:259
#define VLIB_FRAME_SIZE
Definition: node.h:369
static void * ip6_ext_header_find(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6_header, u8 header_type, ip6_ext_header_t **prev_ext_header)
Definition: ip6_packet.h:575
#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
while(n_left_from > 0)
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
#define ip6_frag_hdr_more(hdr)
Definition: ip6_packet.h:706
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:145
#define IP6_SV_REASS_HT_LOAD_FACTOR
Definition: ip6_sv_reass.c:35
Definition: cJSON.c:88
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
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:1019
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:257
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
ip6_sv_reass_key_t key
Definition: ip6_sv_reass.c:85
u32 * tmp
ip6_sv_reass_trace_operation_e
Definition: ip6_sv_reass.c:171
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)
#define PREDICT_FALSE(x)
Definition: clib.h:124
ip6_main_t ip6_main
Definition: ip6_forward.c:2787
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
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
u32 node_index
Node index.
Definition: node.h:479
#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:395
vlib_main_t * vlib_main
Definition: ip6_sv_reass.c:140
struct vnet_buffer_opaque_t::@157::@159 ip
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
u16 n_vectors
Definition: node.h:388
format_function_t format_ip6_address
Definition: format.h:91
u32 ti
u32 fq_index
Worker handoff.
Definition: ip6_sv_reass.c:149
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:395
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:322
u32 index
Definition: flow_types.api:221
#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:302
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:703
#define ARRAY_LEN(x)
Definition: clib.h:70
static char * ip6_sv_reassembly_error_strings[]
Definition: ip6_sv_reass.c:776
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:524
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
#define ip6_frag_hdr_offset(hdr)
Definition: ip6_packet.h:700
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:498
#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:716
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
#define always_inline
Definition: rdma_mlx5dv.h:23
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_put_next_frame(vm, node, next_index, 0)
vlib_trace_main_t trace_main
Definition: main.h:174
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
nat44_ei_hairpin_src_next_t next_index
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:88
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:558
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:211
#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
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:149
static u8 * format_ip6_sv_reass_key(u8 *s, va_list *args)
VLIB buffer representation.
Definition: buffer.h:111
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:301
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
#define vnet_buffer(b)
Definition: buffer.h:437
static u32 vlib_num_workers()
Definition: threads.h:354
f64 now
#define vec_foreach(var, vec)
Vector iterator.
u16 flags
Copy of main node flags.
Definition: node.h:492
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:292
static u8 * format_ip6_sv_reassembly_handoff_trace(u8 *s, va_list *args)
u32 * cached_buffers
Definition: ip6_sv_reass.c:94
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
u32 * fib_index_by_sw_if_index
Definition: ip6.h:127
static_always_inline u32 vlib_buffer_enqueue_to_thread(vlib_main_t *vm, vlib_node_runtime_t *node, u32 frame_queue_index, u32 *buffer_indices, u16 *thread_indices, u32 n_packets, int drop_on_congestion)
Definition: buffer_node.h:358
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:111
static u8 * format_ip6_sv_reass_trace(u8 *s, va_list *args)
Definition: ip6_sv_reass.c:190
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
Definition: defs.h:46
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