FD.io VPP  v20.01-48-g3e0dafb74
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  {
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 (rm->vlib_main);
307 
308  if (!clib_bihash_search_48_8
309  (&rm->hash, (clib_bihash_kv_48_8_t *) kv, (clib_bihash_kv_48_8_t *) kv))
310  {
311  if (vm->thread_index != kv->v.thread_index)
312  {
313  *do_handoff = 1;
314  return NULL;
315  }
316  reass = pool_elt_at_index (rt->pool, kv->v.reass_index);
317 
318  if (now > reass->last_heard + rm->timeout)
319  {
320  ip6_sv_reass_free (vm, rm, rt, reass);
321  reass = NULL;
322  }
323  }
324 
325  if (reass)
326  {
327  reass->last_heard = now;
328  return reass;
329  }
330 
331  if (rt->reass_n >= rm->max_reass_n)
332  {
333  reass = pool_elt_at_index (rt->pool, rt->lru_last);
334  ip6_sv_reass_free (vm, rm, rt, reass);
335  }
336 
337  pool_get (rt->pool, reass);
338  clib_memset (reass, 0, sizeof (*reass));
339  reass->id = ((u64) vm->thread_index * 1000000000) + rt->id_counter;
340  ++rt->id_counter;
341  ip6_sv_reass_init (reass);
342  ++rt->reass_n;
343 
344  reass->lru_prev = reass->lru_next = ~0;
345 
346  if (~0 != rt->lru_last)
347  {
348  ip6_sv_reass_t *lru_last = pool_elt_at_index (rt->pool, rt->lru_last);
349  reass->lru_prev = rt->lru_last;
350  lru_last->lru_next = rt->lru_last = reass - rt->pool;
351  }
352 
353  if (~0 == rt->lru_first)
354  {
355  rt->lru_first = rt->lru_last = reass - rt->pool;
356  }
357 
358  reass->key.as_u64[0] = ((clib_bihash_kv_48_8_t *) kv)->key[0];
359  reass->key.as_u64[1] = ((clib_bihash_kv_48_8_t *) kv)->key[1];
360  reass->key.as_u64[2] = ((clib_bihash_kv_48_8_t *) kv)->key[2];
361  reass->key.as_u64[3] = ((clib_bihash_kv_48_8_t *) kv)->key[3];
362  reass->key.as_u64[4] = ((clib_bihash_kv_48_8_t *) kv)->key[4];
363  reass->key.as_u64[5] = ((clib_bihash_kv_48_8_t *) kv)->key[5];
364  kv->v.reass_index = (reass - rt->pool);
365  kv->v.thread_index = vm->thread_index;
366  reass->last_heard = now;
367 
368  if (clib_bihash_add_del_48_8 (&rm->hash, (clib_bihash_kv_48_8_t *) kv, 1))
369  {
370  ip6_sv_reass_free (vm, rm, rt, reass);
371  reass = NULL;
372  }
373 
374  return reass;
375 }
376 
377 always_inline ip6_sv_reass_rc_t
380  ip6_sv_reass_t * reass, u32 bi0,
381  ip6_frag_hdr_t * frag_hdr)
382 {
383  vlib_buffer_t *fb = vlib_get_buffer (vm, bi0);
384  vnet_buffer_opaque_t *fvnb = vnet_buffer (fb);
385  fvnb->ip.reass.ip6_frag_hdr_offset =
386  (u8 *) frag_hdr - (u8 *) vlib_buffer_get_current (fb);
388  if (fb->current_length < sizeof (*fip) ||
389  fvnb->ip.reass.ip6_frag_hdr_offset == 0 ||
390  fvnb->ip.reass.ip6_frag_hdr_offset >= fb->current_length)
391  {
393  }
394 
395  u32 fragment_first = fvnb->ip.reass.fragment_first =
396  ip6_frag_hdr_offset_bytes (frag_hdr);
397  u32 fragment_length =
398  vlib_buffer_length_in_chain (vm, fb) -
399  (fvnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
400  u32 fragment_last = fvnb->ip.reass.fragment_last =
401  fragment_first + fragment_length - 1;
402  fvnb->ip.reass.range_first = fragment_first;
403  fvnb->ip.reass.range_last = fragment_last;
404  fvnb->ip.reass.next_range_bi = ~0;
405  if (0 == fragment_first)
406  {
407  if (!ip6_get_port
408  (vm, fb, fip, fb->current_length, &reass->ip_proto,
409  &reass->l4_src_port, &reass->l4_dst_port,
410  &reass->icmp_type_or_tcp_flags, &reass->tcp_ack_number,
411  &reass->tcp_seq_number))
413 
414  reass->is_complete = true;
415  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
416  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
417  {
418  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0, REASS_FINISH,
419  reass->ip_proto, reass->l4_src_port,
420  reass->l4_dst_port);
421  }
422  }
423  vec_add1 (reass->cached_buffers, bi0);
424  if (!reass->is_complete)
425  {
426  if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
427  {
428  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
430  reass->l4_src_port, reass->l4_dst_port);
431  }
432  if (vec_len (reass->cached_buffers) > rm->max_reass_len)
433  {
435  }
436  }
437  return IP6_SV_REASS_RC_OK;
438 }
439 
440 always_inline bool
442  vlib_buffer_t * b,
443  ip6_frag_hdr_t * frag_hdr)
444 {
445  ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
446  while (ip6_ext_hdr (tmp->next_hdr))
447  {
448  tmp = ip6_ext_next_header (tmp);
449  }
450  if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
451  {
452  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
453  ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
454  0);
455  b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
456 
457  return false;
458  }
459  return true;
460 }
461 
462 always_inline bool
464  vlib_node_runtime_t * node,
465  vlib_buffer_t * b,
466  ip6_frag_hdr_t * frag_hdr)
467 {
470  int more_fragments = ip6_frag_hdr_more (frag_hdr);
471  u32 fragment_length =
473  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
474  if (more_fragments && 0 != fragment_length % 8)
475  {
476  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
477  ICMP6_parameter_problem_erroneous_header_field,
478  (u8 *) & ip->payload_length - (u8 *) ip);
479  return false;
480  }
481  return true;
482 }
483 
484 always_inline bool
486  vlib_node_runtime_t * node,
487  vlib_buffer_t * b,
488  ip6_frag_hdr_t * frag_hdr)
489 {
491  u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
492  u32 fragment_length =
494  (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
495  if (fragment_first + fragment_length > 65535)
496  {
498  icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
499  ICMP6_parameter_problem_erroneous_header_field,
500  (u8 *) & frag_hdr->fragment_offset_and_more
501  - (u8 *) ip0);
502  return false;
503  }
504  return true;
505 }
506 
509  vlib_node_runtime_t * node,
510  vlib_frame_t * frame, bool is_feature)
511 {
512  u32 *from = vlib_frame_vector_args (frame);
513  u32 n_left_from, n_left_to_next, *to_next, next_index;
516  clib_spinlock_lock (&rt->lock);
517 
518  n_left_from = frame->n_vectors;
519  next_index = node->cached_next_index;
520 
521  while (n_left_from > 0)
522  {
523  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
524 
525  while (n_left_from > 0 && n_left_to_next > 0)
526  {
527  u32 bi0;
528  vlib_buffer_t *b0;
530  u32 error0 = IP6_ERROR_NONE;
531  u32 icmp_bi = ~0;
532 
533  bi0 = from[0];
534  b0 = vlib_get_buffer (vm, bi0);
535 
537  ip6_frag_hdr_t *frag_hdr = NULL;
538  ip6_ext_header_t *prev_hdr;
539  if (ip6_ext_hdr (ip0->protocol))
540  {
541  frag_hdr =
542  ip6_ext_header_find (vm, b0, ip0,
543  IP_PROTOCOL_IPV6_FRAGMENTATION,
544  &prev_hdr);
545  }
546  if (!frag_hdr)
547  {
548  // this is a regular packet - no fragmentation
549  if (!ip6_get_port
550  (vm, b0, ip0, b0->current_length,
551  &(vnet_buffer (b0)->ip.reass.ip_proto),
552  &(vnet_buffer (b0)->ip.reass.l4_src_port),
553  &(vnet_buffer (b0)->ip.reass.l4_dst_port),
554  &(vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags),
555  &(vnet_buffer (b0)->ip.reass.tcp_ack_number),
556  &(vnet_buffer (b0)->ip.reass.tcp_seq_number)))
557  {
558  error0 = IP6_ERROR_REASS_UNSUPP_IP_PROTO;
560  goto packet_enqueue;
561  }
562  ASSERT (vnet_buffer (b0)->ip.save_rewrite_length < (2 << 14));
563  vnet_buffer (b0)->ip.reass.save_rewrite_length =
564  vnet_buffer (b0)->ip.save_rewrite_length;
565  vnet_buffer (b0)->ip.reass.is_non_first_fragment = 0;
567  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
568  {
569  ip6_sv_reass_add_trace (vm, node, rm, NULL, bi0,
571  vnet_buffer (b0)->ip.reass.ip_proto,
572  vnet_buffer (b0)->ip.
573  reass.l4_src_port,
574  vnet_buffer (b0)->ip.
575  reass.l4_dst_port);
576  }
577  goto packet_enqueue;
578  }
579  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
580  (u8 *) frag_hdr - (u8 *) ip0;
581  if (0 == ip6_frag_hdr_offset (frag_hdr))
582  {
583  // first fragment - verify upper-layer is present
585  (node, b0, frag_hdr))
586  {
588  goto packet_enqueue;
589  }
590  }
592  (vm, node, b0, frag_hdr)
593  || !ip6_sv_reass_verify_packet_size_lt_64k (vm, node, b0,
594  frag_hdr))
595  {
597  goto packet_enqueue;
598  }
599 
601  u8 do_handoff = 0;
602 
603  kv.k.as_u64[0] = ip0->src_address.as_u64[0];
604  kv.k.as_u64[1] = ip0->src_address.as_u64[1];
605  kv.k.as_u64[2] = ip0->dst_address.as_u64[0];
606  kv.k.as_u64[3] = ip0->dst_address.as_u64[1];
607  kv.k.as_u64[4] =
609  vnet_buffer (b0)->sw_if_index[VLIB_RX])) << 32 |
610  (u64) frag_hdr->identification;
611  kv.k.as_u64[5] = ip0->protocol;
612 
613  ip6_sv_reass_t *reass =
614  ip6_sv_reass_find_or_create (vm, node, rm, rt, &kv, &icmp_bi,
615  &do_handoff);
616 
617  if (PREDICT_FALSE (do_handoff))
618  {
620  vnet_buffer (b0)->ip.reass.owner_thread_index =
621  kv.v.thread_index;
622  goto packet_enqueue;
623  }
624 
625  if (!reass)
626  {
628  error0 = IP6_ERROR_REASS_LIMIT_REACHED;
629  goto packet_enqueue;
630  }
631 
632  if (reass->is_complete)
633  {
634  ASSERT (vnet_buffer (b0)->ip.save_rewrite_length < (2 << 14));
635  vnet_buffer (b0)->ip.reass.save_rewrite_length =
636  vnet_buffer (b0)->ip.save_rewrite_length;
637  vnet_buffer (b0)->ip.reass.is_non_first_fragment =
638  ! !ip6_frag_hdr_offset (frag_hdr);
639  vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
640  vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
641  reass->icmp_type_or_tcp_flags;
642  vnet_buffer (b0)->ip.reass.tcp_ack_number =
643  reass->tcp_ack_number;
644  vnet_buffer (b0)->ip.reass.tcp_seq_number =
645  reass->tcp_seq_number;
646  vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
647  vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
649  error0 = IP6_ERROR_NONE;
650  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
651  {
652  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
654  reass->ip_proto,
655  reass->l4_src_port,
656  reass->l4_dst_port);
657  }
658  goto packet_enqueue;
659  }
660 
661  switch (ip6_sv_reass_update
662  (vm, node, rm, rt, reass, bi0, frag_hdr))
663  {
664  case IP6_SV_REASS_RC_OK:
665  /* nothing to do here */
666  break;
669  IP6_ERROR_REASS_FRAGMENT_CHAIN_TOO_LONG,
670  1);
671  ip6_sv_reass_free (vm, rm, rt, reass);
672  goto next_packet;
673  break;
676  IP6_ERROR_REASS_UNSUPP_IP_PROTO,
677  1);
678  ip6_sv_reass_free (vm, rm, rt, reass);
679  goto next_packet;
680  break;
683  IP6_ERROR_REASS_INTERNAL_ERROR, 1);
684  ip6_sv_reass_free (vm, rm, rt, reass);
685  goto next_packet;
686  break;
687  }
688 
689  b0->error = node->errors[error0];
690 
691  if (reass->is_complete)
692  {
693  u32 idx;
694  vec_foreach_index (idx, reass->cached_buffers)
695  {
696  u32 bi0 = vec_elt (reass->cached_buffers, idx);
697  if (0 == n_left_to_next)
698  {
699  vlib_put_next_frame (vm, node, next_index,
700  n_left_to_next);
701  vlib_get_next_frame (vm, node, next_index, to_next,
702  n_left_to_next);
703  }
704  to_next[0] = bi0;
705  to_next += 1;
706  n_left_to_next -= 1;
707  b0 = vlib_get_buffer (vm, bi0);
708  if (is_feature)
709  {
710  vnet_feature_next (&next0, b0);
711  }
712  frag_hdr =
714  vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset;
715  ASSERT (vnet_buffer (b0)->ip.save_rewrite_length < (2 << 14));
716  vnet_buffer (b0)->ip.reass.save_rewrite_length =
717  vnet_buffer (b0)->ip.save_rewrite_length;
718  vnet_buffer (b0)->ip.reass.is_non_first_fragment =
719  ! !ip6_frag_hdr_offset (frag_hdr);
720  vnet_buffer (b0)->ip.reass.ip_proto = reass->ip_proto;
721  vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags =
722  reass->icmp_type_or_tcp_flags;
723  vnet_buffer (b0)->ip.reass.tcp_ack_number =
724  reass->tcp_ack_number;
725  vnet_buffer (b0)->ip.reass.tcp_seq_number =
726  reass->tcp_seq_number;
727  vnet_buffer (b0)->ip.reass.l4_src_port = reass->l4_src_port;
728  vnet_buffer (b0)->ip.reass.l4_dst_port = reass->l4_dst_port;
729  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
730  {
731  ip6_sv_reass_add_trace (vm, node, rm, reass, bi0,
733  reass->ip_proto,
734  reass->l4_src_port,
735  reass->l4_dst_port);
736  }
737  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
738  to_next, n_left_to_next, bi0,
739  next0);
740  }
741  _vec_len (reass->cached_buffers) = 0; // buffers are owned by frame now
742  }
743  goto next_packet;
744 
745  packet_enqueue:
746  to_next[0] = bi0;
747  to_next += 1;
748  n_left_to_next -= 1;
749  if (is_feature && IP6_ERROR_NONE == error0)
750  {
751  b0 = vlib_get_buffer (vm, bi0);
752  vnet_feature_next (&next0, b0);
753  }
754  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
755  n_left_to_next, bi0, next0);
756 
757  if (~0 != icmp_bi)
758  {
760  to_next[0] = icmp_bi;
761  to_next += 1;
762  n_left_to_next -= 1;
763  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
764  n_left_to_next, icmp_bi,
765  next0);
766  }
767 
768  next_packet:
769  from += 1;
770  n_left_from -= 1;
771  }
772 
773  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
774  }
775 
776  clib_spinlock_unlock (&rt->lock);
777  return frame->n_vectors;
778 }
779 
781 #define _(sym, string) string,
783 #undef _
784 };
785 
789 {
790  return ip6_sv_reassembly_inline (vm, node, frame, false /* is_feature */ );
791 }
792 
793 /* *INDENT-OFF* */
795  .name = "ip6-sv-reassembly",
796  .vector_size = sizeof (u32),
797  .format_trace = format_ip6_sv_reass_trace,
798  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
799  .error_strings = ip6_sv_reassembly_error_strings,
800  .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
801  .next_nodes =
802  {
803  [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
804  [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
805  [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
806  [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reassembly-handoff",
807  },
808 };
809 /* *INDENT-ON* */
810 
814 {
815  return ip6_sv_reassembly_inline (vm, node, frame, true /* is_feature */ );
816 }
817 
818 /* *INDENT-OFF* */
820  .name = "ip6-sv-reassembly-feature",
821  .vector_size = sizeof (u32),
822  .format_trace = format_ip6_sv_reass_trace,
823  .n_errors = ARRAY_LEN (ip6_sv_reassembly_error_strings),
824  .error_strings = ip6_sv_reassembly_error_strings,
825  .n_next_nodes = IP6_SV_REASSEMBLY_N_NEXT,
826  .next_nodes =
827  {
828  [IP6_SV_REASSEMBLY_NEXT_INPUT] = "ip6-input",
829  [IP6_SV_REASSEMBLY_NEXT_DROP] = "ip6-drop",
830  [IP6_SV_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
831  [IP6_SV_REASSEMBLY_NEXT_HANDOFF] = "ip6-sv-reass-feature-hoff",
832  },
833 };
834 /* *INDENT-ON* */
835 
836 /* *INDENT-OFF* */
837 VNET_FEATURE_INIT (ip6_sv_reassembly_feature) = {
838  .arc_name = "ip6-unicast",
839  .node_name = "ip6-sv-reassembly-feature",
840  .runs_before = VNET_FEATURES ("ip6-lookup"),
841  .runs_after = 0,
842 };
843 /* *INDENT-ON* */
844 
845 #ifndef CLIB_MARCH_VARIANT
846 static u32
848 {
850  u32 nbuckets;
851  u8 i;
852 
853  nbuckets = (u32) (rm->max_reass_n / IP6_SV_REASS_HT_LOAD_FACTOR);
854 
855  for (i = 0; i < 31; i++)
856  if ((1 << i) >= nbuckets)
857  break;
858  nbuckets = 1 << i;
859 
860  return nbuckets;
861 }
862 #endif /* CLIB_MARCH_VARIANT */
863 
864 typedef enum
865 {
868 
869 #ifndef CLIB_MARCH_VARIANT
870 typedef struct
871 {
872  int failure;
873  clib_bihash_48_8_t *new_hash;
875 
876 static int
878 {
879  ip6_rehash_cb_ctx *ctx = _ctx;
880  if (clib_bihash_add_del_48_8 (ctx->new_hash, kv, 1))
881  {
882  ctx->failure = 1;
883  }
884  return (BIHASH_WALK_CONTINUE);
885 }
886 
887 static void
888 ip6_sv_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
889  u32 max_reassembly_length,
890  u32 expire_walk_interval_ms)
891 {
892  ip6_sv_reass_main.timeout_ms = timeout_ms;
893  ip6_sv_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
894  ip6_sv_reass_main.max_reass_n = max_reassemblies;
895  ip6_sv_reass_main.max_reass_len = max_reassembly_length;
896  ip6_sv_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
897 }
898 
900 ip6_sv_reass_set (u32 timeout_ms, u32 max_reassemblies,
901  u32 max_reassembly_length, u32 expire_walk_interval_ms)
902 {
903  u32 old_nbuckets = ip6_sv_reass_get_nbuckets ();
904  ip6_sv_reass_set_params (timeout_ms, max_reassemblies,
905  max_reassembly_length, expire_walk_interval_ms);
906  vlib_process_signal_event (ip6_sv_reass_main.vlib_main,
907  ip6_sv_reass_main.ip6_sv_reass_expire_node_idx,
909  u32 new_nbuckets = ip6_sv_reass_get_nbuckets ();
910  if (ip6_sv_reass_main.max_reass_n > 0 && new_nbuckets > old_nbuckets)
911  {
912  clib_bihash_48_8_t new_hash;
913  clib_memset (&new_hash, 0, sizeof (new_hash));
915  ctx.failure = 0;
916  ctx.new_hash = &new_hash;
917  clib_bihash_init_48_8 (&new_hash, "ip6-sv-reass", new_nbuckets,
918  new_nbuckets * 1024);
919  clib_bihash_foreach_key_value_pair_48_8 (&ip6_sv_reass_main.hash,
920  ip6_rehash_cb, &ctx);
921  if (ctx.failure)
922  {
923  clib_bihash_free_48_8 (&new_hash);
924  return -1;
925  }
926  else
927  {
928  clib_bihash_free_48_8 (&ip6_sv_reass_main.hash);
929  clib_memcpy_fast (&ip6_sv_reass_main.hash, &new_hash,
930  sizeof (ip6_sv_reass_main.hash));
931  clib_bihash_copied (&ip6_sv_reass_main.hash, &new_hash);
932  }
933  }
934  return 0;
935 }
936 
938 ip6_sv_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
939  u32 * max_reassembly_length, u32 * expire_walk_interval_ms)
940 {
941  *timeout_ms = ip6_sv_reass_main.timeout_ms;
942  *max_reassemblies = ip6_sv_reass_main.max_reass_n;
943  *max_reassembly_length = ip6_sv_reass_main.max_reass_len;
944  *expire_walk_interval_ms = ip6_sv_reass_main.expire_walk_interval_ms;
945  return 0;
946 }
947 
948 static clib_error_t *
950 {
952  clib_error_t *error = 0;
953  u32 nbuckets;
954  vlib_node_t *node;
955 
956  rm->vlib_main = vm;
957  rm->vnet_main = vnet_get_main ();
958 
961  vec_foreach (rt, rm->per_thread_data)
962  {
963  clib_spinlock_init (&rt->lock);
964  pool_alloc (rt->pool, rm->max_reass_n);
965  rt->lru_first = rt->lru_last = ~0;
966  }
967 
968  node = vlib_get_node_by_name (vm, (u8 *) "ip6-sv-reassembly-expire-walk");
969  ASSERT (node);
971 
976 
977  nbuckets = ip6_sv_reass_get_nbuckets ();
978  clib_bihash_init_48_8 (&rm->hash, "ip6-sv-reass", nbuckets,
979  nbuckets * 1024);
980 
981  node = vlib_get_node_by_name (vm, (u8 *) "ip6-drop");
982  ASSERT (node);
983  rm->ip6_drop_idx = node->index;
984  node = vlib_get_node_by_name (vm, (u8 *) "ip6-icmp-error");
985  ASSERT (node);
986  rm->ip6_icmp_error_idx = node->index;
987 
988  if ((error = vlib_call_init_function (vm, ip_main_init)))
989  return error;
990  ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
991  ip6_sv_reass_node.index);
992 
994  rm->fq_feature_index =
996 
998 
999  return error;
1000 }
1001 
1003 #endif /* CLIB_MARCH_VARIANT */
1004 
1005 static uword
1007  vlib_node_runtime_t * node, vlib_frame_t * f)
1008 {
1010  uword event_type, *event_data = 0;
1011 
1012  while (true)
1013  {
1016  / (f64) MSEC_PER_SEC);
1017  event_type = vlib_process_get_events (vm, &event_data);
1018 
1019  switch (event_type)
1020  {
1021  case ~0: /* no events => timeout */
1022  /* nothing to do here */
1023  break;
1025  break;
1026  default:
1027  clib_warning ("BUG: event type 0x%wx", event_type);
1028  break;
1029  }
1030  f64 now = vlib_time_now (vm);
1031 
1032  ip6_sv_reass_t *reass;
1033  int *pool_indexes_to_free = NULL;
1034 
1035  uword thread_index = 0;
1036  int index;
1037  const uword nthreads = vlib_num_workers () + 1;
1038  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1039  {
1040  ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1041  clib_spinlock_lock (&rt->lock);
1042 
1043  vec_reset_length (pool_indexes_to_free);
1044  /* *INDENT-OFF* */
1045  pool_foreach_index (index, rt->pool, ({
1046  reass = pool_elt_at_index (rt->pool, index);
1047  if (now > reass->last_heard + rm->timeout)
1048  {
1049  vec_add1 (pool_indexes_to_free, index);
1050  }
1051  }));
1052  /* *INDENT-ON* */
1053  int *i;
1054  /* *INDENT-OFF* */
1055  vec_foreach (i, pool_indexes_to_free)
1056  {
1057  ip6_sv_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
1058  ip6_sv_reass_free (vm, rm, rt, reass);
1059  }
1060  /* *INDENT-ON* */
1061 
1062  clib_spinlock_unlock (&rt->lock);
1063  }
1064 
1065  vec_free (pool_indexes_to_free);
1066  if (event_data)
1067  {
1068  _vec_len (event_data) = 0;
1069  }
1070  }
1071 
1072  return 0;
1073 }
1074 
1075 /* *INDENT-OFF* */
1077  .function = ip6_sv_reass_walk_expired,
1078  .format_trace = format_ip6_sv_reass_trace,
1079  .type = VLIB_NODE_TYPE_PROCESS,
1080  .name = "ip6-sv-reassembly-expire-walk",
1081 
1083  .error_strings = ip6_sv_reassembly_error_strings,
1084 
1085 };
1086 /* *INDENT-ON* */
1087 
1088 static u8 *
1089 format_ip6_sv_reass_key (u8 * s, va_list * args)
1090 {
1091  ip6_sv_reass_key_t *key = va_arg (*args, ip6_sv_reass_key_t *);
1092  s = format (s, "xx_id: %u, src: %U, dst: %U, frag_id: %u, proto: %u",
1094  &key->dst, clib_net_to_host_u16 (key->frag_id), key->proto);
1095  return s;
1096 }
1097 
1098 static u8 *
1099 format_ip6_sv_reass (u8 * s, va_list * args)
1100 {
1101  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
1102  ip6_sv_reass_t *reass = va_arg (*args, ip6_sv_reass_t *);
1103 
1104  s = format (s, "ID: %lu, key: %U, trace_op_counter: %u\n",
1105  reass->id, format_ip6_sv_reass_key, &reass->key,
1106  reass->trace_op_counter);
1107  vlib_buffer_t *b;
1108  u32 *bip;
1109  u32 counter = 0;
1110  vec_foreach (bip, reass->cached_buffers)
1111  {
1112  u32 bi = *bip;
1113  do
1114  {
1115  b = vlib_get_buffer (vm, bi);
1116  s = format (s, " #%03u: bi: %u\n", counter, bi);
1117  ++counter;
1118  bi = b->next_buffer;
1119  }
1120  while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
1121  }
1122  return s;
1123 }
1124 
1125 static clib_error_t *
1128 {
1130 
1131  vlib_cli_output (vm, "---------------------");
1132  vlib_cli_output (vm, "IP6 reassembly status");
1133  vlib_cli_output (vm, "---------------------");
1134  bool details = false;
1135  if (unformat (input, "details"))
1136  {
1137  details = true;
1138  }
1139 
1140  u32 sum_reass_n = 0;
1141  u64 sum_buffers_n = 0;
1142  ip6_sv_reass_t *reass;
1143  uword thread_index;
1144  const uword nthreads = vlib_num_workers () + 1;
1145  for (thread_index = 0; thread_index < nthreads; ++thread_index)
1146  {
1147  ip6_sv_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
1148  clib_spinlock_lock (&rt->lock);
1149  if (details)
1150  {
1151  /* *INDENT-OFF* */
1152  pool_foreach (reass, rt->pool, {
1153  vlib_cli_output (vm, "%U", format_ip6_sv_reass, vm, reass);
1154  });
1155  /* *INDENT-ON* */
1156  }
1157  sum_reass_n += rt->reass_n;
1158  clib_spinlock_unlock (&rt->lock);
1159  }
1160  vlib_cli_output (vm, "---------------------");
1161  vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
1162  (long unsigned) sum_reass_n);
1163  vlib_cli_output (vm, "Maximum configured concurrent IP6 reassemblies per "
1164  "worker-thread: %lu\n", (long unsigned) rm->max_reass_n);
1165  vlib_cli_output (vm, "Buffers in use: %lu\n",
1166  (long unsigned) sum_buffers_n);
1167  return 0;
1168 }
1169 
1170 /* *INDENT-OFF* */
1172  .path = "show ip6-sv-reassembly",
1173  .short_help = "show ip6-sv-reassembly [details]",
1174  .function = show_ip6_sv_reass,
1175 };
1176 /* *INDENT-ON* */
1177 
1178 #ifndef CLIB_MARCH_VARIANT
1181 {
1182  return ip6_sv_reass_enable_disable_with_refcnt (sw_if_index,
1183  enable_disable);
1184 }
1185 #endif /* CLIB_MARCH_VARIANT */
1186 
1187 #define foreach_ip6_sv_reassembly_handoff_error \
1188 _(CONGESTION_DROP, "congestion drop")
1189 
1190 
1191 typedef enum
1192 {
1193 #define _(sym,str) IP6_SV_REASSEMBLY_HANDOFF_ERROR_##sym,
1195 #undef _
1198 
1200 #define _(sym,string) string,
1202 #undef _
1203 };
1204 
1205 typedef struct
1206 {
1209 
1210 static u8 *
1212 {
1213  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1214  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1216  va_arg (*args, ip6_sv_reassembly_handoff_trace_t *);
1217 
1218  s =
1219  format (s, "ip6-sv-reassembly-handoff: next-worker %d",
1220  t->next_worker_index);
1221 
1222  return s;
1223 }
1224 
1228  vlib_frame_t * frame, bool is_feature)
1229 {
1231 
1232  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1233  u32 n_enq, n_left_from, *from;
1234  u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1235  u32 fq_index;
1236 
1237  from = vlib_frame_vector_args (frame);
1238  n_left_from = frame->n_vectors;
1239  vlib_get_buffers (vm, from, bufs, n_left_from);
1240 
1241  b = bufs;
1242  ti = thread_indices;
1243 
1244  fq_index = (is_feature) ? rm->fq_feature_index : rm->fq_index;
1245 
1246  while (n_left_from > 0)
1247  {
1248  ti[0] = vnet_buffer (b[0])->ip.reass.owner_thread_index;
1249 
1250  if (PREDICT_FALSE
1251  ((node->flags & VLIB_NODE_FLAG_TRACE)
1252  && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1253  {
1255  vlib_add_trace (vm, node, b[0], sizeof (*t));
1256  t->next_worker_index = ti[0];
1257  }
1258 
1259  n_left_from -= 1;
1260  ti += 1;
1261  b += 1;
1262  }
1263  n_enq =
1264  vlib_buffer_enqueue_to_thread (vm, fq_index, from, thread_indices,
1265  frame->n_vectors, 1);
1266 
1267  if (n_enq < frame->n_vectors)
1269  IP6_SV_REASSEMBLY_HANDOFF_ERROR_CONGESTION_DROP,
1270  frame->n_vectors - n_enq);
1271  return frame->n_vectors;
1272 }
1273 
1276  vlib_frame_t * frame)
1277 {
1278  return ip6_sv_reassembly_handoff_inline (vm, node, frame,
1279  false /* is_feature */ );
1280 }
1281 
1282 /* *INDENT-OFF* */
1284  .name = "ip6-sv-reassembly-handoff",
1285  .vector_size = sizeof (u32),
1286  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1287  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1289 
1290  .n_next_nodes = 1,
1291 
1292  .next_nodes = {
1293  [0] = "error-drop",
1294  },
1295 };
1296 
1297 
1300 {
1301  return ip6_sv_reassembly_handoff_inline (vm, node, frame, true /* is_feature */ );
1302 }
1303 
1304 
1305 /* *INDENT-OFF* */
1307  .name = "ip6-sv-reass-feature-hoff",
1308  .vector_size = sizeof (u32),
1309  .n_errors = ARRAY_LEN(ip6_sv_reassembly_handoff_error_strings),
1310  .error_strings = ip6_sv_reassembly_handoff_error_strings,
1312 
1313  .n_next_nodes = 1,
1314 
1315  .next_nodes = {
1316  [0] = "error-drop",
1317  },
1318 };
1319 /* *INDENT-ON* */
1320 
1321 #ifndef CLIB_MARCH_VARIANT
1322 int
1324 {
1326  vec_validate (rm->feature_use_refcount_per_intf, sw_if_index);
1327  if (is_enable)
1328  {
1329  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1330  {
1332  return vnet_feature_enable_disable ("ip6-unicast",
1333  "ip6-sv-reassembly-feature",
1334  sw_if_index, 1, 0, 0);
1335  }
1337  }
1338  else
1339  {
1341  if (!rm->feature_use_refcount_per_intf[sw_if_index])
1342  return vnet_feature_enable_disable ("ip6-unicast",
1343  "ip6-sv-reassembly-feature",
1344  sw_if_index, 0, 0, 0);
1345  }
1346  return 0;
1347 }
1348 #endif
1349 
1350 /*
1351  * fd.io coding-style-patch-verification: ON
1352  *
1353  * Local Variables:
1354  * eval: (c-set-style "gnu")
1355  * End:
1356  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:440
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:158
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:485
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:102
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:80
#define CLIB_UNUSED(x)
Definition: clib.h:82
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:673
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1590
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:890
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:346
u64 as_u64
Definition: bihash_doc.h:63
u64 as_u64[2]
Definition: ip6_packet.h:51
unsigned long u64
Definition: types.h:89
static uword ip6_sv_reass_walk_expired(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
#define IP6_SV_REASS_MAX_REASSEMBLY_LENGTH_DEFAULT
Definition: ip6_sv_reass.c:34
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
clib_bihash_48_8_t * new_hash
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:280
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:279
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1810
u32 thread_index
Definition: main.h:218
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:523
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:378
#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:888
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
Definition: ip6_packet.h:510
int i
u32 * feature_use_refcount_per_intf
Definition: ip6_sv_reass.c:153
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:470
static clib_error_t * ip6_sv_reass_init_function(vlib_main_t *vm)
Definition: ip6_sv_reass.c:949
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:366
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:237
ip6_address_t src_address
Definition: ip6_packet.h:307
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:864
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:498
vlib_node_registration_t ip6_sv_reassembly_handoff_node
(constructor) VLIB_REGISTER_NODE (ip6_sv_reassembly_handoff_node)
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
#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:516
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:877
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:508
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:463
unsigned int u32
Definition: types.h:88
#define vlib_call_init_function(vm, x)
Definition: init.h:270
#define VLIB_FRAME_SIZE
Definition: node.h:378
static void * ip6_ext_header_find(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6_header, u8 header_type, ip6_ext_header_t **prev_ext_header)
Definition: ip6_packet.h:536
#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:667
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:519
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:934
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:287
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:111
#define always_inline
Definition: ipsec.h:28
ip6_main_t ip6_main
Definition: ip6_forward.c:2703
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:496
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:338
vlib_main_t * vm
Definition: in2out_ed.c:1810
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:1150
#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:397
format_function_t format_ip6_address
Definition: format.h:91
u32 fq_index
Worker handoff.
Definition: ip6_sv_reass.c:149
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:342
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:302
#define clib_warning(format, args...)
Definition: error.h:59
static u32 ip6_sv_reass_get_nbuckets()
Definition: ip6_sv_reass.c:847
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:900
#define ip6_frag_hdr_offset_bytes(hdr)
Definition: ip6_packet.h:664
#define ARRAY_LEN(x)
Definition: clib.h:62
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:456
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
static char * ip6_sv_reassembly_error_strings[]
Definition: ip6_sv_reass.c:780
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1810
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:485
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
ip_proto
Definition: ip_types.api:64
#define ip6_frag_hdr_offset(hdr)
Definition: ip6_packet.h:661
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:515
#define ASSERT(truth)
#define IP6_SV_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS
Definition: ip6_sv_reass.c:32
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:938
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:441
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:442
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
struct vnet_buffer_opaque_t::@132::@134 ip
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
#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:83
u16 payload_length
Definition: ip6_packet.h:298
u8 action
Definition: l2.api:173
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:490
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)
#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:794
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 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:244
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:487
#define vnet_buffer(b)
Definition: buffer.h:408
static u32 vlib_num_workers()
Definition: threads.h:372
#define vec_foreach(var, vec)
Vector iterator.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: in2out_ed.c:1811
u16 flags
Copy of main node flags.
Definition: node.h:509
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:543
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:244
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:302
static u8 * format_ip6_sv_reassembly_handoff_trace(u8 *s, va_list *args)
u32 * cached_buffers
Definition: ip6_sv_reass.c:94
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
u32 * fib_index_by_sw_if_index
Definition: ip6.h:195
vlib_node_registration_t ip6_sv_reass_node_feature
(constructor) VLIB_REGISTER_NODE (ip6_sv_reass_node_feature)
Definition: ip6_sv_reass.c:819
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
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:304
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
ip6_address_t dst_address
Definition: ip6_packet.h:307
#define IP6_SV_REASS_TIMEOUT_DEFAULT_MS
Definition: ip6_sv_reass.c:31