FD.io VPP  v20.09-64-g4f7b92f0a
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);
231  ip6_sv_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
232  if (reass)
233  {
234  t->reass_id = reass->id;
235  t->op_id = reass->trace_op_counter;
236  ++reass->trace_op_counter;
237  }
238  t->action = action;
239  t->ip_proto = ip_proto;
240  t->l4_src_port = l4_src_port;
241  t->l4_dst_port = l4_dst_port;
242 #if 0
243  static u8 *s = NULL;
244  s = format (s, "%U", format_ip6_sv_reass_trace, NULL, NULL, t);
245  printf ("%.*s\n", vec_len (s), s);
246  fflush (stdout);
247  vec_reset_length (s);
248 #endif
249 }
250 
251 always_inline void
254 {
256  kv.key[0] = reass->key.as_u64[0];
257  kv.key[1] = reass->key.as_u64[1];
258  kv.key[2] = reass->key.as_u64[2];
259  kv.key[3] = reass->key.as_u64[3];
260  kv.key[4] = reass->key.as_u64[4];
261  kv.key[5] = reass->key.as_u64[5];
262  clib_bihash_add_del_48_8 (&rm->hash, &kv, 0);
263  vlib_buffer_free (vm, reass->cached_buffers,
264  vec_len (reass->cached_buffers));
265  vec_free (reass->cached_buffers);
266  reass->cached_buffers = NULL;
267  if (~0 != reass->lru_prev)
268  {
269  ip6_sv_reass_t *lru_prev =
270  pool_elt_at_index (rt->pool, reass->lru_prev);
271  lru_prev->lru_next = reass->lru_next;
272  }
273  if (~0 != reass->lru_next)
274  {
275  ip6_sv_reass_t *lru_next =
276  pool_elt_at_index (rt->pool, reass->lru_next);
277  lru_next->lru_prev = reass->lru_prev;
278  }
279  if (rt->lru_first == reass - rt->pool)
280  {
281  rt->lru_first = reass->lru_next;
282  }
283  if (rt->lru_last == reass - rt->pool)
284  {
285  rt->lru_last = reass->lru_prev;
286  }
287  pool_put (rt->pool, reass);
288  --rt->reass_n;
289 }
290 
291 always_inline void
293 {
294  reass->cached_buffers = NULL;
295  reass->is_complete = false;
296 }
297 
300  ip6_sv_reass_main_t * rm,
302  ip6_sv_reass_kv_t * kv, u32 * icmp_bi,
303  u8 * do_handoff)
304 {
305  ip6_sv_reass_t *reass = NULL;
306  f64 now = vlib_time_now (vm);
307 
308  if (!clib_bihash_search_48_8 (&rm->hash, &kv->kv, &kv->kv))
309  {
310  if (vm->thread_index != kv->v.thread_index)
311  {
312  *do_handoff = 1;
313  return NULL;
314  }
315  reass = pool_elt_at_index (rt->pool, kv->v.reass_index);
316 
317  if (now > reass->last_heard + rm->timeout)
318  {
319  ip6_sv_reass_free (vm, rm, rt, reass);
320  reass = NULL;
321  }
322  }
323 
324  if (reass)
325  {
326  reass->last_heard = now;
327  return reass;
328  }
329 
330  if (rt->reass_n >= rm->max_reass_n)
331  {
332  reass = pool_elt_at_index (rt->pool, rt->lru_first);
333  ip6_sv_reass_free (vm, rm, rt, reass);
334  }
335 
336  pool_get (rt->pool, reass);
337  clib_memset (reass, 0, sizeof (*reass));
338  reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
339  ++rt->id_counter;
340  ip6_sv_reass_init (reass);
341  ++rt->reass_n;
342 
343  reass->lru_prev = reass->lru_next = ~0;
344 
345  if (~0 != rt->lru_last)
346  {
347  ip6_sv_reass_t *lru_last = pool_elt_at_index (rt->pool, rt->lru_last);
348  reass->lru_prev = rt->lru_last;
349  lru_last->lru_next = rt->lru_last = reass - rt->pool;
350  }
351 
352  if (~0 == rt->lru_first)
353  {
354  rt->lru_first = rt->lru_last = reass - rt->pool;
355  }
356 
357  reass->key.as_u64[0] = kv->kv.key[0];
358  reass->key.as_u64[1] = kv->kv.key[1];
359  reass->key.as_u64[2] = kv->kv.key[2];
360  reass->key.as_u64[3] = kv->kv.key[3];
361  reass->key.as_u64[4] = kv->kv.key[4];
362  reass->key.as_u64[5] = kv->kv.key[5];
363  kv->v.reass_index = (reass - rt->pool);
364  kv->v.thread_index = vm->thread_index;
365  reass->last_heard = now;
366 
367  if (clib_bihash_add_del_48_8 (&rm->hash, &kv->kv, 1))
368  {
369  ip6_sv_reass_free (vm, rm, rt, reass);
370  reass = NULL;
371  }
372 
373  return reass;
374 }
375 
376 always_inline ip6_sv_reass_rc_t
379  ip6_sv_reass_t * reass, u32 bi0,
380  ip6_frag_hdr_t * frag_hdr)
381 {
382  vlib_buffer_t *fb = vlib_get_buffer (vm, bi0);
383  vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
384  fvnb->ip.reass.ip6_frag_hdr_offset =
385  (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb);
387  if (fb->current_length < sizeof (*fip) ||
388  fvnb->ip.reass.ip6_frag_hdr_offset == 0 ||
389  fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length)
390  {
392  }
393 
394  u32 fragment_first = fvnb->ip.reass.fragment_first =
395  ip6_frag_hdr_offset_bytes (frag_hdr);
396  u32 fragment_length =
397  vlib_buffer_length_in_chain (vm, fb) -
398  (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
399  u32 fragment_last = fvnb->ip.reass.fragment_last =
400  fragment_first + fragment_length - 1;
401  fvnb->ip.reass.range_first = fragment_first;
402  fvnb->ip.reass.range_last = fragment_last;
403  fvnb->ip.reass.next_range_bi = ~0;
404  if (0 == fragment_first)
405  {
406  if (!ip6_get_port
407  (vm, fb, fip, fb->current_length, &reass->ip_proto,
408  &reass->l4_src_port, &reass->l4_dst_port,
409  &reass->icmp_type_or_tcp_flags, &reass->tcp_ack_number,
410  &reass->tcp_seq_number))
412 
413  reass->is_complete = true;
414  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
415  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
416  {
417  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, REASS_FINISH,
418  reass->ip_proto, reass->l4_src_port,
419  reass->l4_dst_port);
420  }
421  }
422  vec_add1 (reass->cached_buffers, bi0);
423  if (!reass->is_complete)
424  {
425  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
426  {
427  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
429  reass->l4_src_port, reass->l4_dst_port);
430  }
431  if (vec_len (reass->cached_buffers) > rm->max_reass_len)
432  {
434  }
435  }
436  return IP6_SV_REASS_RC_OK;
437 }
438 
439 always_inline bool
441  vlib_buffer_t * b,
442  ip6_frag_hdr_t * frag_hdr)
443 {
444  ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
445  while (ip6_ext_hdr (tmp->next_hdr))
446  {
447  tmp = ip6_ext_next_header (tmp);
448  }
449  if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
450  {
451  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
452  ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
453  0);
454  b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
455 
456  return false;
457  }
458  return true;
459 }
460 
461 always_inline bool
463  vlib_node_runtime_t * node,
464  vlib_buffer_t * b,
465  ip6_frag_hdr_t * frag_hdr)
466 {
469  int more_fragments = ip6_frag_hdr_more (frag_hdr);
470  u32 fragment_length =
472  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
473  if (more_fragments && 0 != fragment_length % 8)
474  {
475  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
476  ICMP6_parameter_problem_erroneous_header_field,
477  (u8 *) & ip->payload_length - (u8 *) ip);
478  return false;
479  }
480  return true;
481 }
482 
483 always_inline bool
485  vlib_node_runtime_t * node,
486  vlib_buffer_t * b,
487  ip6_frag_hdr_t * frag_hdr)
488 {
490  u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
491  u32 fragment_length =
493  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
494  if (fragment_first + fragment_length > 65535)
495  {
497  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
498  ICMP6_parameter_problem_erroneous_header_field,
499  (u8 *) & frag_hdr->fragment_offset_and_more
500  - (u8 *) ip0);
501  return false;
502  }
503  return true;
504 }
505 
508  vlib_node_runtime_t * node,
509  vlib_frame_t * frame, bool is_feature)
510 {
511  u32 *from = vlib_frame_vector_args (frame);
512  u32 n_left_from, n_left_to_next, *to_next, next_index;
515  clib_spinlock_lock (&rt->lock);
516 
517  n_left_from = frame->n_vectors;
518  next_index = node->cached_next_index;
519 
520  while (n_left_from > 0)
521  {
522  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
523 
524  while (n_left_from > 0 && n_left_to_next > 0)
525  {
526  u32 bi0;
527  vlib_buffer_t *b0;
529  u32 error0 = IP6_ERROR_NONE;
530  u32 icmp_bi = ~0;
531 
532  bi0 = from[0];
533  b0 = vlib_get_buffer (vm, bi0);
534 
536  ip6_frag_hdr_t *frag_hdr = NULL;
537  ip6_ext_header_t *prev_hdr;
538  if (ip6_ext_hdr (ip0->protocol))
539  {
540  frag_hdr =
541  ip6_ext_header_find (vm, b0, ip0,
542  IP_PROTOCOL_IPV6_FRAGMENTATION,
543  &prev_hdr);
544  }
545  if (!frag_hdr)
546  {
547  // this is a regular packet - no fragmentation
548  if (!ip6_get_port
549  (vm, b0, ip0, b0->current_length,
550  &(vnet_buffer (b0)->ip.reass.ip_proto),
551  &(vnet_buffer (b0)->ip.reass.l4_src_port),
552  &(vnet_buffer (b0)->ip.reass.l4_dst_port),
553  &(vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags),
554  &(vnet_buffer (b0)->ip.reass.tcp_ack_number),
555  &(vnet_buffer (b0)->ip.reass.tcp_seq_number)))
556  {
557  error0 = IP6_ERROR_REASS_UNSUPP_IP_PROTO;
558  b0->error = node->errors[error0];
560  goto packet_enqueue;
561  }
562  vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
564  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
565  {
566  ip6_sv_reass_add_trace (vm, node, rm, NULL, bi0,
568  vnet_buffer (b0)->ip.reass.ip_proto,
569  vnet_buffer (b0)->ip.
570  reass.l4_src_port,
571  vnet_buffer (b0)->ip.
572  reass.l4_dst_port);
573  }
574  goto packet_enqueue;
575  }
576  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
577  (u8 *) frag_hdr - (u8 *) ip0;
578  if (0 == ip6_frag_hdr_offset (frag_hdr))
579  {
580  // first fragment - verify upper-layer is present
582  (node, b0, frag_hdr))
583  {
585  goto packet_enqueue;
586  }
587  }
589  (vm, node, b0, frag_hdr)
590  || !ip6_sv_reass_verify_packet_size_lt_64k (vm, node, b0,
591  frag_hdr))
592  {
594  goto packet_enqueue;
595  }
596 
598  u8 do_handoff = 0;
599 
600  kv.k.as_u64[0] = ip0->src_address.as_u64[0];
601  kv.k.as_u64[1] = ip0->src_address.as_u64[1];
602  kv.k.as_u64[2] = ip0->dst_address.as_u64[0];
603  kv.k.as_u64[3] = ip0->dst_address.as_u64[1];
604  kv.k.as_u64[4] =
606  vnet_buffer (b0)->sw_if_index[VLIB_RX])) << 32 |
607  (u64) frag_hdr->identification;
608  kv.k.as_u64[5] = ip0->protocol;
609 
610  ip6_sv_reass_t *reass =
611  ip6_sv_reass_find_or_create (vm, node, rm, rt, &kv, &icmp_bi,
612  &do_handoff);
613 
614  if (PREDICT_FALSE (do_handoff))
615  {
617  vnet_buffer (b0)->ip.reass.owner_thread_index =
618  kv.v.thread_index;
619  goto packet_enqueue;
620  }
621 
622  if (!reass)
623  {
625  error0 = IP6_ERROR_REASS_LIMIT_REACHED;
626  b0->error = node->errors[error0];
627  goto packet_enqueue;
628  }
629 
630  if (reass->is_complete)
631  {
632  vnet_buffer (b0)->ip.reass.is_non_first_fragment =
633  ! !ip6_frag_hdr_offset (frag_hdr);
634  vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
635  vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
636  reass->icmp_type_or_tcp_flags;
637  vnet_buffer (b0)->ip.reass.tcp_ack_number =
638  reass->tcp_ack_number;
639  vnet_buffer (b0)->ip.reass.tcp_seq_number =
640  reass->tcp_seq_number;
641  vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
642  vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
644  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
645  {
646  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
648  reass->ip_proto,
649  reass->l4_src_port,
650  reass->l4_dst_port);
651  }
652  goto packet_enqueue;
653  }
654 
655  switch (ip6_sv_reass_update
656  (vm, node, rm, rt, reass, bi0, frag_hdr))
657  {
658  case IP6_SV_REASS_RC_OK:
659  /* nothing to do here */
660  break;
663  IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
664  1);
665  ip6_sv_reass_free (vm, rm, rt, reass);
666  goto next_packet;
667  break;
670  IP6_ERROR_REASS_UNSUPP_IP_PROTO,
671  1);
672  ip6_sv_reass_free (vm, rm, rt, reass);
673  goto next_packet;
674  break;
677  IP6_ERROR_REASS_INTERNAL_ERROR, 1);
678  ip6_sv_reass_free (vm, rm, rt, reass);
679  goto next_packet;
680  break;
681  }
682 
683  if (reass->is_complete)
684  {
685  u32 idx;
686  vec_foreach_index (idx, reass->cached_buffers)
687  {
688  u32 bi0 = vec_elt (reass->cached_buffers, idx);
689  if (0 == n_left_to_next)
690  {
691  vlib_put_next_frame (vm, node, next_index,
692  n_left_to_next);
693  vlib_get_next_frame (vm, node, next_index, to_next,
694  n_left_to_next);
695  }
696  to_next[0] = bi0;
697  to_next += 1;
698  n_left_to_next -= 1;
699  b0 = vlib_get_buffer (vm, bi0);
700  if (is_feature)
701  {
702  vnet_feature_next (&next0, b0);
703  }
704  frag_hdr =
706  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset;
707  vnet_buffer (b0)->ip.reass.is_non_first_fragment =
708  ! !ip6_frag_hdr_offset (frag_hdr);
709  vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
710  vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
711  reass->icmp_type_or_tcp_flags;
712  vnet_buffer (b0)->ip.reass.tcp_ack_number =
713  reass->tcp_ack_number;
714  vnet_buffer (b0)->ip.reass.tcp_seq_number =
715  reass->tcp_seq_number;
716  vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
717  vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
718  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
719  {
720  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
722  reass->ip_proto,
723  reass->l4_src_port,
724  reass->l4_dst_port);
725  }
726  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
727  to_next, n_left_to_next, bi0,
728  next0);
729  }
730  _vec_len (reass->cached_buffers) = 0; // buffers are owned by frame now
731  }
732  goto next_packet;
733 
734  packet_enqueue:
735  to_next[0] = bi0;
736  to_next += 1;
737  n_left_to_next -= 1;
738  if (is_feature && IP6_ERROR_NONE == error0)
739  {
740  b0 = vlib_get_buffer (vm, bi0);
741  vnet_feature_next (&next0, b0);
742  }
743  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
744  n_left_to_next, bi0, next0);
745 
746  if (~0 != icmp_bi)
747  {
749  to_next[0] = icmp_bi;
750  to_next += 1;
751  n_left_to_next -= 1;
752  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
753  n_left_to_next, icmp_bi,
754  next0);
755  }
756 
757  next_packet:
758  from += 1;
759  n_left_from -= 1;
760  }
761 
762  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
763  }
764 
765  clib_spinlock_unlock (&rt->lock);
766  return frame->n_vectors;
767 }
768 
770 #define _(sym, string) string,
772 #undef _
773 };
774 
778 {
779  return ip6_sv_reassembly_inline (vm, node, frame, false /* is_feature */ );
780 }
781 
782 /* *INDENT-OFF* */
784  .name = "ip6-sv-reassembly",
785  .vector_size = sizeof (u32),
786  .format_trace = format_ip6_sv_reass_trace,
787  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
788  .error_strings = ip6_sv_reassembly_error_strings,
789  .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
790  .next_nodes =
791  {
792  [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
793  [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
794  [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
795  [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reassembly-handoff",
796  },
797 };
798 /* *INDENT-ON* */
799 
803 {
804  return ip6_sv_reassembly_inline (vm, node, frame, true /* is_feature */ );
805 }
806 
807 /* *INDENT-OFF* */
809  .name = "ip6-sv-reassembly-feature",
810  .vector_size = sizeof (u32),
811  .format_trace = format_ip6_sv_reass_trace,
812  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
813  .error_strings = ip6_sv_reassembly_error_strings,
814  .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
815  .next_nodes =
816  {
817  [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
818  [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
819  [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
820  [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reass-feature-hoff",
821  },
822 };
823 /* *INDENT-ON* */
824 
825 /* *INDENT-OFF* */
826 VNET_FEATURE_INIT (ip6_sv_reassembly_feature) = {
827  .arc_name = "ip6-unicast",
828  .node_name = "ip6-sv-reassembly-feature",
829  .runs_before = VNET_FEATURES ("ip6-lookup"),
830  .runs_after = 0,
831 };
832 /* *INDENT-ON* */
833 
834 #ifndef CLIB_MARCH_VARIANT
835 static u32
837 {
839  u32 nbuckets;
840  u8 i;
841 
842  nbuckets = (u32) (rm->max_reass_n / IP6_SV_REASS_HT_LOAD_FACTOR);
843 
844  for (i = 0; i < 31; i++)
845  if ((1 << i) >= nbuckets)
846  break;
847  nbuckets = 1 << i;
848 
849  return nbuckets;
850 }
851 #endif /* CLIB_MARCH_VARIANT */
852 
853 typedef enum
854 {
857 
858 #ifndef CLIB_MARCH_VARIANT
859 typedef struct
860 {
861  int failure;
862  clib_bihash_48_8_t *new_hash;
864 
865 static int
867 {
868  ip6_rehash_cb_ctx *ctx = _ctx;
869  if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1))
870  {
871  ctx->failure = 1;
872  }
873  return (BIHASH_WALK_CONTINUE);
874 }
875 
876 static void
877 ip6_sv_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
878  u32 max_reassembly_length,
879  u32 expire_walk_interval_ms)
880 {
881  ip6_sv_reass_main.timeout_ms = timeout_ms;
882  ip6_sv_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
883  ip6_sv_reass_main.max_reass_n = max_reassemblies;
884  ip6_sv_reass_main.max_reass_len = max_reassembly_length;
885  ip6_sv_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
886 }
887 
889 ip6_sv_reass_set (u32 timeout_ms, u32 max_reassemblies,
890  u32 max_reassembly_length, u32 expire_walk_interval_ms)
891 {
892  u32 old_nbuckets = ip6_sv_reass_get_nbuckets ();
893  ip6_sv_reass_set_params (timeout_ms, max_reassemblies,
894  max_reassembly_length, expire_walk_interval_ms);
895  vlib_process_signal_event (ip6_sv_reass_main.vlib_main,
896  ip6_sv_reass_main.ip6_sv_reass_expire_node_idx,
898  u32 new_nbuckets = ip6_sv_reass_get_nbuckets ();
899  if (ip6_sv_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
900  {
901  clib_bihash_48_8_t new_hash;
902  clib_memset (&new_hash, 0, sizeof (new_hash));
904  ctx.failure = 0;
905  ctx.new_hash = &new_hash;
906  clib_bihash_init_48_8 (&new_hash, "ip6-sv-reass", new_nbuckets,
907  new_nbuckets * 1024);
908  clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.hash,
909  ip6_rehash_cb, &ctx);
910  if (ctx.failure)
911  {
912  clib_bihash_free_48_8 (&new_hash);
913  return -1;
914  }
915  else
916  {
917  clib_bihash_free_48_8 (&ip6_sv_reass_main.hash);
918  clib_memcpy_fast (&ip6_sv_reass_main.hash, &new_hash,
919  sizeof (ip6_sv_reass_main.hash));
920  clib_bihash_copied (&ip6_sv_reass_main.hash, &new_hash);
921  }
922  }
923  return 0;
924 }
925 
927 ip6_sv_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
928  u32 * max_reassembly_length, u32 * expire_walk_interval_ms)
929 {
930  *timeout_ms = ip6_sv_reass_main.timeout_ms;
931  *max_reassemblies = ip6_sv_reass_main.max_reass_n;
932  *max_reassembly_length = ip6_sv_reass_main.max_reass_len;
933  *expire_walk_interval_ms = ip6_sv_reass_main.expire_walk_interval_ms;
934  return 0;
935 }
936 
937 static clib_error_t *
939 {
941  clib_error_t *error = 0;
942  u32 nbuckets;
943  vlib_node_t *node;
944 
945  rm->vlib_main = vm;
946  rm->vnet_main = vnet_get_main ();
947 
950  vec_foreach (rt, rm->per_thread_data)
951  {
952  clib_spinlock_init (&rt->lock);
953  pool_alloc (rt->pool, rm->max_reass_n);
954  rt->lru_first = rt->lru_last = ~0;
955  }
956 
957  node = vlib_get_node_by_name (vm, (u8 *) "ip6-sv-reassembly-expire-walk");
958  ASSERT (node);
960 
965 
966  nbuckets = ip6_sv_reass_get_nbuckets ();
967  clib_bihash_init_48_8 (&rm->hash, "ip6-sv-reass", nbuckets,
968  nbuckets * 1024);
969 
970  node = vlib_get_node_by_name (vm, (u8 *) "ip6-drop");
971  ASSERT (node);
972  rm->ip6_drop_idx = node->index;
973  node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error");
974  ASSERT (node);
975  rm->ip6_icmp_error_idx = node->index;
976 
977  if ((error = vlib_call_init_function (vm, ip_main_init)))
978  return error;
979  ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
980  ip6_sv_reass_node.index);
981 
983  rm->fq_feature_index =
985 
987 
988  return error;
989 }
990 
992 #endif /* CLIB_MARCH_VARIANT */
993 
994 static uword
996  vlib_node_runtime_t * node, vlib_frame_t * f)
997 {
999  uword event_type, *event_data = 0;
1000 
1001  while (true)
1002  {
1005  / (f64) MSEC_PER_SEC);
1006  event_type = vlib_process_get_events (vm, &event_data);
1007 
1008  switch (event_type)
1009  {
1010  case ~0: /* no events => timeout */
1011  /* nothing to do here */
1012  break;
1014  break;
1015  default:
1016  clib_warning ("BUG: event type 0x%wx", event_type);
1017  break;
1018  }
1019  f64 now = vlib_time_now (vm);
1020 
1021  ip6_sv_reass_t *reass;
1022  int *pool_indexes_to_free = NULL;
1023 
1024  uword thread_index = 0;
1025  int index;
1026  const uword nthreads = vlib_num_workers () + 1;
1027  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1028  {
1029  ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1030  clib_spinlock_lock (&rt->lock);
1031 
1032  vec_reset_length (pool_indexes_to_free);
1033  /* *INDENT-OFF* */
1034  pool_foreach_index (index, rt->pool, ({
1035  reass = pool_elt_at_index (rt->pool, index);
1036  if (now > reass->last_heard + rm->timeout)
1037  {
1038  vec_add1 (pool_indexes_to_free, index);
1039  }
1040  }));
1041  /* *INDENT-ON* */
1042  int *i;
1043  /* *INDENT-OFF* */
1044  vec_foreach (i, pool_indexes_to_free)
1045  {
1046  ip6_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1047  ip6_sv_reass_free (vm, rm, rt, reass);
1048  }
1049  /* *INDENT-ON* */
1050 
1051  clib_spinlock_unlock (&rt->lock);
1052  }
1053 
1054  vec_free (pool_indexes_to_free);
1055  if (event_data)
1056  {
1057  _vec_len (event_data) = 0;
1058  }
1059  }
1060 
1061  return 0;
1062 }
1063 
1064 /* *INDENT-OFF* */
1066  .function = ip6_sv_reass_walk_expired,
1067  .format_trace = format_ip6_sv_reass_trace,
1068  .type = VLIB_NODE_TYPE_PROCESS,
1069  .name = "ip6-sv-reassembly-expire-walk",
1070 
1072  .error_strings = ip6_sv_reassembly_error_strings,
1073 
1074 };
1075 /* *INDENT-ON* */
1076 
1077 static u8 *
1078 format_ip6_sv_reass_key (u8 * s, va_list * args)
1079 {
1080  ip6_sv_reass_key_t *key = va_arg (*args, ip6_sv_reass_key_t *);
1081  s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1083  &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1084  return s;
1085 }
1086 
1087 static u8 *
1088 format_ip6_sv_reass (u8 * s, va_list * args)
1089 {
1090  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1091  ip6_sv_reass_t *reass = va_arg (*args, ip6_sv_reass_t *);
1092 
1093  s = format (s, "ID: %lu, key: %U, trace_op_counter: %u\n",
1094  reass->id, format_ip6_sv_reass_key, &reass->key,
1095  reass->trace_op_counter);
1096  vlib_buffer_t *b;
1097  u32 *bip;
1098  u32 counter = 0;
1099  vec_foreach (bip, reass->cached_buffers)
1100  {
1101  u32 bi = *bip;
1102  do
1103  {
1104  b = vlib_get_buffer (vm, bi);
1105  s = format (s, " #%03u: bi: %u\n", counter, bi);
1106  ++counter;
1107  bi = b->next_buffer;
1108  }
1109  while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
1110  }
1111  return s;
1112 }
1113 
1114 static clib_error_t *
1117 {
1119 
1120  vlib_cli_output (vm, "---------------------");
1121  vlib_cli_output (vm, "IP6 reassembly status");
1122  vlib_cli_output (vm, "---------------------");
1123  bool details = false;
1124  if (unformat (input, "details"))
1125  {
1126  details = true;
1127  }
1128 
1129  u32 sum_reass_n = 0;
1130  u64 sum_buffers_n = 0;
1131  ip6_sv_reass_t *reass;
1132  uword thread_index;
1133  const uword nthreads = vlib_num_workers () + 1;
1134  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1135  {
1136  ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1137  clib_spinlock_lock (&rt->lock);
1138  if (details)
1139  {
1140  /* *INDENT-OFF* */
1141  pool_foreach (reass, rt->pool, {
1142  vlib_cli_output (vm, "%U", format_ip6_sv_reass, vm, reass);
1143  });
1144  /* *INDENT-ON* */
1145  }
1146  sum_reass_n += rt->reass_n;
1147  clib_spinlock_unlock (&rt->lock);
1148  }
1149  vlib_cli_output (vm, "---------------------");
1150  vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1151  (long unsigned) sum_reass_n);
1152  vlib_cli_output (vm,
1153  "Maximum configured concurrent shallow virtual IP6 reassemblies per worker-thread: %lu\n",
1154  (long unsigned) rm->max_reass_n);
1155  vlib_cli_output (vm,
1156  "Maximum configured shallow virtual IP6 reassembly timeout: %lums\n",
1157  (long unsigned) rm->timeout_ms);
1158  vlib_cli_output (vm,
1159  "Maximum configured shallow virtual IP6 reassembly expire walk interval: %lums\n",
1160  (long unsigned) rm->expire_walk_interval_ms);
1161  vlib_cli_output (vm, "Buffers in use: %lu\n",
1162  (long unsigned) sum_buffers_n);
1163  return 0;
1164 }
1165 
1166 /* *INDENT-OFF* */
1168  .path = "show ip6-sv-reassembly",
1169  .short_help = "show ip6-sv-reassembly [details]",
1170  .function = show_ip6_sv_reass,
1171 };
1172 /* *INDENT-ON* */
1173 
1174 #ifndef CLIB_MARCH_VARIANT
1177 {
1178  return ip6_sv_reass_enable_disable_with_refcnt (sw_if_index,
1179  enable_disable);
1180 }
1181 #endif /* CLIB_MARCH_VARIANT */
1182 
1183 #define foreach_ip6_sv_reassembly_handoff_error \
1184 _(CONGESTION_DROP, "congestion drop")
1185 
1186 
1187 typedef enum
1188 {
1189 #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym,
1191 #undef _
1194 
1196 #define _(sym,string) string,
1198 #undef _
1199 };
1200 
1201 typedef struct
1202 {
1205 
1206 static u8 *
1208 {
1209  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1210  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1212  va_arg (*args, ip6_sv_reassembly_handoff_trace_t *);
1213 
1214  s =
1215  format (s, "ip6-sv-reassembly-handoff: next-worker %d",
1216  t->next_worker_index);
1217 
1218  return s;
1219 }
1220 
1224  vlib_frame_t * frame, bool is_feature)
1225 {
1227 
1228  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1229  u32 n_enq, n_left_from, *from;
1230  u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1231  u32 fq_index;
1232 
1233  from = vlib_frame_vector_args (frame);
1234  n_left_from = frame->n_vectors;
1235  vlib_get_buffers (vm, from, bufs, n_left_from);
1236 
1237  b = bufs;
1238  ti = thread_indices;
1239 
1240  fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1241 
1242  while (n_left_from > 0)
1243  {
1244  ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1245 
1246  if (PREDICT_FALSE
1247  ((node->flags & VLIB_NODE_FLAG_TRACE)
1248  && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1249  {
1251  vlib_add_trace (vm, node, b[0], sizeof (*t));
1252  t->next_worker_index = ti[0];
1253  }
1254 
1255  n_left_from -= 1;
1256  ti += 1;
1257  b += 1;
1258  }
1259  n_enq =
1260  vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices,
1261  frame->n_vectors, 1);
1262 
1263  if (n_enq < frame->n_vectors)
1265  IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1266  frame->n_vectors - n_enq);
1267  return frame->n_vectors;
1268 }
1269 
1272  vlib_frame_t * frame)
1273 {
1274  return ip6_sv_reassembly_handoff_inline (vm, node, frame,
1275  false /* is_feature */ );
1276 }
1277 
1278 /* *INDENT-OFF* */
1280  .name = "ip6-sv-reassembly-handoff",
1281  .vector_size = sizeof (u32),
1282  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1283  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1285 
1286  .n_next_nodes = 1,
1287 
1288  .next_nodes = {
1289  [0] = "error-drop",
1290  },
1291 };
1292 
1293 
1296 {
1297  return ip6_sv_reassembly_handoff_inline (vm, node, frame, true /* is_feature */ );
1298 }
1299 
1300 
1301 /* *INDENT-OFF* */
1303  .name = "ip6-sv-reass-feature-hoff",
1304  .vector_size = sizeof (u32),
1305  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1306  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1308 
1309  .n_next_nodes = 1,
1310 
1311  .next_nodes = {
1312  [0] = "error-drop",
1313  },
1314 };
1315 /* *INDENT-ON* */
1316 
1317 #ifndef CLIB_MARCH_VARIANT
1318 int
1320 {
1322  vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
1323  if (is_enable)
1324  {
1325  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1326  {
1328  return vnet_feature_enable_disable ("ip6-unicast",
1329  "ip6-sv-reassembly-feature",
1330  sw_if_index, 1, 0, 0);
1331  }
1333  }
1334  else
1335  {
1337  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1338  return vnet_feature_enable_disable ("ip6-unicast",
1339  "ip6-sv-reassembly-feature",
1340  sw_if_index, 0, 0, 0);
1341  }
1342  return 0;
1343 }
1344 #endif
1345 
1346 /*
1347  * fd.io coding-style-patch-verification: ON
1348  *
1349  * Local Variables:
1350  * eval: (c-set-style "gnu")
1351  * End:
1352  */
#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:484
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:119
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:80
#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:1664
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
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define pool_alloc(P, N)
Allocate N more free elements to pool (unspecified alignment).
Definition: pool.h:361
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)
Definition: ip6_sv_reass.c:995
#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:64
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:279
static vlib_cli_command_t show_ip6_sv_reassembly_cmd
(constructor) VLIB_CLI_COMMAND (show_ip6_sv_reassembly_cmd)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:333
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1873
u32 thread_index
Definition: main.h:249
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:377
#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:877
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
Definition: ip6_packet.h:513
u32 * feature_use_refcount_per_intf
Definition: ip6_sv_reass.c:153
vlib_main_t * vm
Definition: in2out_ed.c:1582
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#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:469
static clib_error_t * ip6_sv_reass_init_function(vlib_main_t *vm)
Definition: ip6_sv_reass.c:938
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:252
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:252
double f64
Definition: types.h:142
clib_bihash_48_8_t hash
Definition: ip6_sv_reass.c:134
vlib_node_registration_t ip6_sv_reassembly_feature_handoff_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reassembly_feature_handoff_node)
ip6_address_t dst
Definition: ip6_sv_reass.c:52
ip6_sv_reass_rc_t
Definition: ip6_sv_reass.c:37
ip6_sv_reass_event_t
Definition: ip6_sv_reass.c:853
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
vlib_node_registration_t ip6_sv_reassembly_handoff_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reassembly_handoff_node)
#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
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:866
vlib_node_registration_t ip6_sv_reass_expire_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_expire_node)
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:507
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:462
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:377
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:539
#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:63
#define ip6_frag_hdr_more(hdr)
Definition: ip6_packet.h:670
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
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
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:229
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:302
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:120
#define always_inline
Definition: ipsec.h:28
ip6_main_t ip6_main
Definition: ip6_forward.c:2781
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:487
#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:169
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
u16 n_vectors
Definition: node.h:396
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
static u32 ip6_sv_reass_get_nbuckets()
Definition: ip6_sv_reass.c:836
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:889
#define ip6_frag_hdr_offset_bytes(hdr)
Definition: ip6_packet.h:667
#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:769
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:488
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1582
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
#define ip6_frag_hdr_offset(hdr)
Definition: ip6_packet.h:664
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:510
#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:927
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:440
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.
void clib_bihash_copied(void *dst, void *src)
typedef key
Definition: ipsec_types.api:85
u16 payload_length
Definition: ip6_packet.h:301
struct vnet_buffer_opaque_t::@162::@164 ip
static void ip6_sv_reass_init(ip6_sv_reass_t *reass)
Definition: ip6_sv_reass.c:292
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:783
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:1583
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:299
#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:500
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:577
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:558
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:301
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:196
vlib_node_registration_t ip6_sv_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_node_feature)
Definition: ip6_sv_reass.c:808
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:33
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