FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
ip4_map.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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  * Defines used for testing various optimisation schemes
17  */
18 
19 #include "map.h"
20 #include <vnet/ip/ip_frag.h>
21 #include <vnet/ip/ip4_to_ip6.h>
22 
24 
26 {
28 #ifdef MAP_SKIP_IP6_LOOKUP
30 #endif
37 };
38 
40 {
45 };
46 
47 typedef struct
48 {
53 
54 u8 *
55 format_ip4_map_reass_trace (u8 * s, va_list * args)
56 {
57  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
58  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
60  return format (s, "MAP domain index: %d L4 port: %u Status: %s",
61  t->map_domain_index, t->port,
62  t->cached ? "cached" : "forwarded");
63 }
64 
67  u32 * next, u8 * error)
68 {
69  u16 port = 0;
70 
71  if (d->psid_length > 0)
72  {
73  if (ip4_get_fragment_offset (ip) == 0)
74  {
75  if (PREDICT_FALSE
76  ((ip->ip_version_and_header_length != 0x45)
77  || clib_host_to_net_u16 (ip->length) < 28))
78  {
79  return 0;
80  }
81  port = ip4_get_port (ip, 0);
82  if (port)
83  {
84  /* Verify that port is not among the well-known ports */
85  if ((d->psid_offset > 0)
86  && (clib_net_to_host_u16 (port) <
87  (0x1 << (16 - d->psid_offset))))
88  {
89  *error = MAP_ERROR_ENCAP_SEC_CHECK;
90  }
91  else
92  {
93  if (ip4_get_fragment_more (ip))
94  *next = IP4_MAP_NEXT_REASS;
95  return (port);
96  }
97  }
98  else
99  {
100  *error = MAP_ERROR_BAD_PROTOCOL;
101  }
102  }
103  else
104  {
105  *next = IP4_MAP_NEXT_REASS;
106  }
107  }
108  return (0);
109 }
110 
111 /*
112  * ip4_map_vtcfl
113  */
116 {
117  map_main_t *mm = &map_main;
118  u8 tc = mm->tc_copy ? ip4->tos : mm->tc;
119  u32 vtcfl = 0x6 << 28;
120  vtcfl |= tc << 20;
121  vtcfl |= vnet_buffer (p)->ip.flow_hash & 0x000fffff;
122 
123  return (clib_host_to_net_u32 (vtcfl));
124 }
125 
126 /*
127  * ip4_map_ttl
128  */
129 static inline void
131 {
132  i32 ttl = ip->ttl;
133 
134  /* Input node should have reject packets with ttl 0. */
135  ASSERT (ip->ttl > 0);
136 
137  u32 checksum = ip->checksum + clib_host_to_net_u16 (0x0100);
138  checksum += checksum >= 0xffff;
139  ip->checksum = checksum;
140  ttl -= 1;
141  ip->ttl = ttl;
142  *error = ttl <= 0 ? IP4_ERROR_TIME_EXPIRED : *error;
143 
144  /* Verify checksum. */
145  ASSERT (ip->checksum == ip4_header_checksum (ip));
146 }
147 
148 static u32
149 ip4_map_fragment (vlib_buffer_t * b, u16 mtu, bool df, u8 * error)
150 {
151  map_main_t *mm = &map_main;
152 
153  if (mm->frag_inner)
154  {
155  // TODO: Fix inner fragmentation after removed inner support from ip-frag.
156  ip_frag_set_vnet_buffer (b, /*sizeof (ip6_header_t), */ mtu,
159  return (IP4_MAP_NEXT_IP4_FRAGMENT);
160  }
161  else
162  {
163  if (df && !mm->frag_ignore_df)
164  {
165  icmp4_error_set_vnet_buffer (b, ICMP4_destination_unreachable,
166  ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
167  mtu);
168  vlib_buffer_advance (b, sizeof (ip6_header_t));
169  *error = MAP_ERROR_DF_SET;
170  return (IP4_MAP_NEXT_ICMP_ERROR);
171  }
174  return (IP4_MAP_NEXT_IP6_FRAGMENT);
175  }
176 }
177 
178 /*
179  * ip4_map
180  */
181 static uword
183 {
184  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
185  vlib_node_runtime_t *error_node =
187  from = vlib_frame_vector_args (frame);
188  n_left_from = frame->n_vectors;
189  next_index = node->cached_next_index;
190  map_main_t *mm = &map_main;
192  u32 thread_index = vm->thread_index;
193 
194  while (n_left_from > 0)
195  {
196  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
197 
198  /* Dual loop */
199  while (n_left_from >= 4 && n_left_to_next >= 2)
200  {
201  u32 pi0, pi1;
202  vlib_buffer_t *p0, *p1;
203  map_domain_t *d0, *d1;
204  u8 error0 = MAP_ERROR_NONE, error1 = MAP_ERROR_NONE;
205  ip4_header_t *ip40, *ip41;
206  u16 port0 = 0, port1 = 0;
207  ip6_header_t *ip6h0, *ip6h1;
208  u32 map_domain_index0 = ~0, map_domain_index1 = ~0;
209  u32 next0 = IP4_MAP_NEXT_IP6_LOOKUP, next1 =
211 
212  /* Prefetch next iteration. */
213  {
214  vlib_buffer_t *p2, *p3;
215 
216  p2 = vlib_get_buffer (vm, from[2]);
217  p3 = vlib_get_buffer (vm, from[3]);
218 
219  vlib_prefetch_buffer_header (p2, STORE);
220  vlib_prefetch_buffer_header (p3, STORE);
221  /* IPv4 + 8 = 28. possibly plus -40 */
222  CLIB_PREFETCH (p2->data - 40, 68, STORE);
223  CLIB_PREFETCH (p3->data - 40, 68, STORE);
224  }
225 
226  pi0 = to_next[0] = from[0];
227  pi1 = to_next[1] = from[1];
228  from += 2;
229  n_left_from -= 2;
230  to_next += 2;
231  n_left_to_next -= 2;
232 
233  p0 = vlib_get_buffer (vm, pi0);
234  p1 = vlib_get_buffer (vm, pi1);
235  ip40 = vlib_buffer_get_current (p0);
236  ip41 = vlib_buffer_get_current (p1);
237  d0 =
238  ip4_map_get_domain (&ip40->dst_address, &map_domain_index0,
239  &error0);
240  d1 =
241  ip4_map_get_domain (&ip41->dst_address, &map_domain_index1,
242  &error1);
243 
244  /*
245  * Shared IPv4 address
246  */
247  port0 = ip4_map_port_and_security_check (d0, ip40, &next0, &error0);
248  port1 = ip4_map_port_and_security_check (d1, ip41, &next1, &error1);
249 
250  /* Decrement IPv4 TTL */
251  ip4_map_decrement_ttl (ip40, &error0);
252  ip4_map_decrement_ttl (ip41, &error1);
253  bool df0 =
255  clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
256  bool df1 =
258  clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
259 
260  /* MAP calc */
261  u32 da40 = clib_net_to_host_u32 (ip40->dst_address.as_u32);
262  u32 da41 = clib_net_to_host_u32 (ip41->dst_address.as_u32);
263  u16 dp40 = clib_net_to_host_u16 (port0);
264  u16 dp41 = clib_net_to_host_u16 (port1);
265  u64 dal60 = map_get_pfx (d0, da40, dp40);
266  u64 dal61 = map_get_pfx (d1, da41, dp41);
267  u64 dar60 = map_get_sfx (d0, da40, dp40);
268  u64 dar61 = map_get_sfx (d1, da41, dp41);
269  if (dal60 == 0 && dar60 == 0 && error0 == MAP_ERROR_NONE
270  && next0 != IP4_MAP_NEXT_REASS)
271  error0 = MAP_ERROR_NO_BINDING;
272  if (dal61 == 0 && dar61 == 0 && error1 == MAP_ERROR_NONE
273  && next1 != IP4_MAP_NEXT_REASS)
274  error1 = MAP_ERROR_NO_BINDING;
275 
276  /* construct ipv6 header */
277  vlib_buffer_advance (p0, -sizeof (ip6_header_t));
278  vlib_buffer_advance (p1, -sizeof (ip6_header_t));
279  ip6h0 = vlib_buffer_get_current (p0);
280  ip6h1 = vlib_buffer_get_current (p1);
281  vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
282  vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
283 
285  ip4_map_vtcfl (ip40, p0);
287  ip4_map_vtcfl (ip41, p1);
288  ip6h0->payload_length = ip40->length;
289  ip6h1->payload_length = ip41->length;
290  ip6h0->protocol = IP_PROTOCOL_IP_IN_IP;
291  ip6h1->protocol = IP_PROTOCOL_IP_IN_IP;
292  ip6h0->hop_limit = 0x40;
293  ip6h1->hop_limit = 0x40;
294  ip6h0->src_address = d0->ip6_src;
295  ip6h1->src_address = d1->ip6_src;
296  ip6h0->dst_address.as_u64[0] = clib_host_to_net_u64 (dal60);
297  ip6h0->dst_address.as_u64[1] = clib_host_to_net_u64 (dar60);
298  ip6h1->dst_address.as_u64[0] = clib_host_to_net_u64 (dal61);
299  ip6h1->dst_address.as_u64[1] = clib_host_to_net_u64 (dar61);
300 
301  /*
302  * Determine next node. Can be one of:
303  * ip6-lookup, ip6-rewrite, ip4-fragment, ip4-virtreass, error-drop
304  */
305  if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
306  {
307  if (PREDICT_FALSE
308  (d0->mtu
309  && (clib_net_to_host_u16 (ip6h0->payload_length) +
310  sizeof (*ip6h0) > d0->mtu)))
311  {
312  next0 = ip4_map_fragment (p0, d0->mtu, df0, &error0);
313  }
314  else
315  {
316  next0 =
318  ip40) ?
319  IP4_MAP_NEXT_IP6_REWRITE : next0;
321  thread_index,
322  map_domain_index0, 1,
323  clib_net_to_host_u16
324  (ip6h0->payload_length) +
325  40);
326  }
327  }
328  else
329  {
330  next0 = IP4_MAP_NEXT_DROP;
331  }
332 
333  /*
334  * Determine next node. Can be one of:
335  * ip6-lookup, ip6-rewrite, ip4-fragment, ip4-virtreass, error-drop
336  */
337  if (PREDICT_TRUE (error1 == MAP_ERROR_NONE))
338  {
339  if (PREDICT_FALSE
340  (d1->mtu
341  && (clib_net_to_host_u16 (ip6h1->payload_length) +
342  sizeof (*ip6h1) > d1->mtu)))
343  {
344  next1 = ip4_map_fragment (p1, d1->mtu, df1, &error1);
345  }
346  else
347  {
348  next1 =
350  ip41) ?
351  IP4_MAP_NEXT_IP6_REWRITE : next1;
353  thread_index,
354  map_domain_index1, 1,
355  clib_net_to_host_u16
356  (ip6h1->payload_length) +
357  40);
358  }
359  }
360  else
361  {
362  next1 = IP4_MAP_NEXT_DROP;
363  }
364 
365  if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
366  {
367  map_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
368  tr->map_domain_index = map_domain_index0;
369  tr->port = port0;
370  }
371  if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
372  {
373  map_trace_t *tr = vlib_add_trace (vm, node, p1, sizeof (*tr));
374  tr->map_domain_index = map_domain_index1;
375  tr->port = port1;
376  }
377 
378  p0->error = error_node->errors[error0];
379  p1->error = error_node->errors[error1];
380 
381  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
382  n_left_to_next, pi0, pi1, next0,
383  next1);
384  }
385 
386  while (n_left_from > 0 && n_left_to_next > 0)
387  {
388  u32 pi0;
389  vlib_buffer_t *p0;
390  map_domain_t *d0;
391  u8 error0 = MAP_ERROR_NONE;
392  ip4_header_t *ip40;
393  u16 port0 = 0;
394  ip6_header_t *ip6h0;
396  u32 map_domain_index0 = ~0;
397 
398  pi0 = to_next[0] = from[0];
399  from += 1;
400  n_left_from -= 1;
401  to_next += 1;
402  n_left_to_next -= 1;
403 
404  p0 = vlib_get_buffer (vm, pi0);
405  ip40 = vlib_buffer_get_current (p0);
406 
407  d0 =
408  ip4_map_get_domain (&ip40->dst_address, &map_domain_index0,
409  &error0);
410  if (!d0)
411  { /* Guess it wasn't for us */
412  vnet_feature_next (&next0, p0);
413  goto exit;
414  }
415 
416  /*
417  * Shared IPv4 address
418  */
419  port0 = ip4_map_port_and_security_check (d0, ip40, &next0, &error0);
420 
421  /* Decrement IPv4 TTL */
422  ip4_map_decrement_ttl (ip40, &error0);
423  bool df0 =
425  clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
426 
427  /* MAP calc */
428  u32 da40 = clib_net_to_host_u32 (ip40->dst_address.as_u32);
429  u16 dp40 = clib_net_to_host_u16 (port0);
430  u64 dal60 = map_get_pfx (d0, da40, dp40);
431  u64 dar60 = map_get_sfx (d0, da40, dp40);
432  if (dal60 == 0 && dar60 == 0 && error0 == MAP_ERROR_NONE
433  && next0 != IP4_MAP_NEXT_REASS)
434  error0 = MAP_ERROR_NO_BINDING;
435 
436  /* construct ipv6 header */
437  vlib_buffer_advance (p0, -(sizeof (ip6_header_t)));
438  ip6h0 = vlib_buffer_get_current (p0);
439  vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
440 
442  ip4_map_vtcfl (ip40, p0);
443  ip6h0->payload_length = ip40->length;
444  ip6h0->protocol = IP_PROTOCOL_IP_IN_IP;
445  ip6h0->hop_limit = 0x40;
446  ip6h0->src_address = d0->ip6_src;
447  ip6h0->dst_address.as_u64[0] = clib_host_to_net_u64 (dal60);
448  ip6h0->dst_address.as_u64[1] = clib_host_to_net_u64 (dar60);
449 
450  /*
451  * Determine next node. Can be one of:
452  * ip6-lookup, ip6-rewrite, ip4-fragment, ip4-virtreass, error-drop
453  */
454  if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
455  {
456  if (PREDICT_FALSE
457  (d0->mtu
458  && (clib_net_to_host_u16 (ip6h0->payload_length) +
459  sizeof (*ip6h0) > d0->mtu)))
460  {
461  next0 = ip4_map_fragment (p0, d0->mtu, df0, &error0);
462  }
463  else
464  {
465  next0 =
467  ip40) ?
468  IP4_MAP_NEXT_IP6_REWRITE : next0;
470  thread_index,
471  map_domain_index0, 1,
472  clib_net_to_host_u16
473  (ip6h0->payload_length) +
474  40);
475  }
476  }
477  else
478  {
479  next0 = IP4_MAP_NEXT_DROP;
480  }
481 
482  if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
483  {
484  map_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
485  tr->map_domain_index = map_domain_index0;
486  tr->port = port0;
487  }
488 
489  p0->error = error_node->errors[error0];
490  exit:
491  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
492  n_left_to_next, pi0, next0);
493  }
494  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
495  }
496 
497  return frame->n_vectors;
498 }
499 
500 /*
501  * ip4_map_reass
502  */
503 static uword
505  vlib_node_runtime_t * node, vlib_frame_t * frame)
506 {
507  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
508  vlib_node_runtime_t *error_node =
510  from = vlib_frame_vector_args (frame);
511  n_left_from = frame->n_vectors;
512  next_index = node->cached_next_index;
513  map_main_t *mm = &map_main;
515  u32 thread_index = vm->thread_index;
516  u32 *fragments_to_drop = NULL;
517  u32 *fragments_to_loopback = NULL;
518 
519  while (n_left_from > 0)
520  {
521  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
522 
523  while (n_left_from > 0 && n_left_to_next > 0)
524  {
525  u32 pi0;
526  vlib_buffer_t *p0;
527  map_domain_t *d0;
528  u8 error0 = MAP_ERROR_NONE;
529  ip4_header_t *ip40;
530  i32 port0 = 0;
531  ip6_header_t *ip60;
533  u32 map_domain_index0 = ~0;
534  u8 cached = 0;
535 
536  pi0 = to_next[0] = from[0];
537  from += 1;
538  n_left_from -= 1;
539  to_next += 1;
540  n_left_to_next -= 1;
541 
542  p0 = vlib_get_buffer (vm, pi0);
543  ip60 = vlib_buffer_get_current (p0);
544  ip40 = (ip4_header_t *) (ip60 + 1);
545  d0 =
546  ip4_map_get_domain (&ip40->dst_address, &map_domain_index0,
547  &error0);
548 
551  ip40->dst_address.as_u32,
552  ip40->fragment_id,
553  ip40->protocol,
554  &fragments_to_drop);
555  if (PREDICT_FALSE (!r))
556  {
557  // Could not create a caching entry
558  error0 = MAP_ERROR_FRAGMENT_MEMORY;
559  }
560  else if (PREDICT_TRUE (ip4_get_fragment_offset (ip40)))
561  {
562  if (r->port >= 0)
563  {
564  // We know the port already
565  port0 = r->port;
566  }
567  else if (map_ip4_reass_add_fragment (r, pi0))
568  {
569  // Not enough space for caching
570  error0 = MAP_ERROR_FRAGMENT_MEMORY;
571  map_ip4_reass_free (r, &fragments_to_drop);
572  }
573  else
574  {
575  cached = 1;
576  }
577  }
578  else if ((port0 = ip4_get_port (ip40, 0)) == 0)
579  {
580  // Could not find port. We'll free the reassembly.
581  error0 = MAP_ERROR_BAD_PROTOCOL;
582  port0 = 0;
583  map_ip4_reass_free (r, &fragments_to_drop);
584  }
585  else
586  {
587  r->port = port0;
588  map_ip4_reass_get_fragments (r, &fragments_to_loopback);
589  }
590 
591 #ifdef MAP_IP4_REASS_COUNT_BYTES
592  if (!cached && r)
593  {
594  r->forwarded += clib_host_to_net_u16 (ip40->length) - 20;
595  if (!ip4_get_fragment_more (ip40))
596  r->expected_total =
597  ip4_get_fragment_offset (ip40) * 8 +
598  clib_host_to_net_u16 (ip40->length) - 20;
599  if (r->forwarded >= r->expected_total)
600  map_ip4_reass_free (r, &fragments_to_drop);
601  }
602 #endif
603 
605 
606  // NOTE: Most operations have already been performed by ip4_map
607  // All we need is the right destination address
608  ip60->dst_address.as_u64[0] =
609  map_get_pfx_net (d0, ip40->dst_address.as_u32, port0);
610  ip60->dst_address.as_u64[1] =
611  map_get_sfx_net (d0, ip40->dst_address.as_u32, port0);
612 
613  if (PREDICT_FALSE
614  (d0->mtu
615  && (clib_net_to_host_u16 (ip60->payload_length) +
616  sizeof (*ip60) > d0->mtu)))
617  {
618  // TODO: vnet_buffer (p0)->ip_frag.header_offset = sizeof (*ip60);
619  vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP6_LOOKUP;
620  vnet_buffer (p0)->ip_frag.mtu = d0->mtu;
621  vnet_buffer (p0)->ip_frag.flags = IP_FRAG_FLAG_IP6_HEADER;
623  }
624 
625  if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
626  {
628  vlib_add_trace (vm, node, p0, sizeof (*tr));
629  tr->map_domain_index = map_domain_index0;
630  tr->port = port0;
631  tr->cached = cached;
632  }
633 
634  if (cached)
635  {
636  //Dequeue the packet
637  n_left_to_next++;
638  to_next--;
639  }
640  else
641  {
642  if (error0 == MAP_ERROR_NONE)
644  thread_index,
645  map_domain_index0, 1,
646  clib_net_to_host_u16
647  (ip60->payload_length) + 40);
648  next0 =
649  (error0 == MAP_ERROR_NONE) ? next0 : IP4_MAP_REASS_NEXT_DROP;
650  p0->error = error_node->errors[error0];
651  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
652  n_left_to_next, pi0, next0);
653  }
654 
655  //Loopback when we reach the end of the inpu vector
656  if (n_left_from == 0 && vec_len (fragments_to_loopback))
657  {
658  from = vlib_frame_vector_args (frame);
659  u32 len = vec_len (fragments_to_loopback);
660  if (len <= VLIB_FRAME_SIZE)
661  {
662  clib_memcpy_fast (from, fragments_to_loopback,
663  sizeof (u32) * len);
664  n_left_from = len;
665  vec_reset_length (fragments_to_loopback);
666  }
667  else
668  {
669  clib_memcpy_fast (from, fragments_to_loopback +
670  (len - VLIB_FRAME_SIZE),
671  sizeof (u32) * VLIB_FRAME_SIZE);
672  n_left_from = VLIB_FRAME_SIZE;
673  _vec_len (fragments_to_loopback) = len - VLIB_FRAME_SIZE;
674  }
675  }
676  }
677  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
678  }
679 
680  map_send_all_to_node (vm, fragments_to_drop, node,
681  &error_node->errors[MAP_ERROR_FRAGMENT_DROPPED],
683 
684  vec_free (fragments_to_drop);
685  vec_free (fragments_to_loopback);
686  return frame->n_vectors;
687 }
688 
689 static char *map_error_strings[] = {
690 #define _(sym,string) string,
692 #undef _
693 };
694 
695 
696 /* *INDENT-OFF* */
697 VNET_FEATURE_INIT (ip4_map_feature, static) =
698 {
699  .arc_name = "ip4-unicast",
700  .node_name = "ip4-map",
701  .runs_before =
702  VNET_FEATURES ("ip4-flow-classify"),
703 };
704 
706  .function = ip4_map,
707  .name = "ip4-map",
708  .vector_size = sizeof(u32),
709  .format_trace = format_map_trace,
711 
712  .n_errors = MAP_N_ERROR,
713  .error_strings = map_error_strings,
714 
715  .n_next_nodes = IP4_MAP_N_NEXT,
716  .next_nodes = {
717  [IP4_MAP_NEXT_IP6_LOOKUP] = "ip6-lookup",
718 #ifdef MAP_SKIP_IP6_LOOKUP
719  [IP4_MAP_NEXT_IP6_REWRITE] = "ip6-load-balance",
720 #endif
721  [IP4_MAP_NEXT_IP4_FRAGMENT] = "ip4-frag",
722  [IP4_MAP_NEXT_IP6_FRAGMENT] = "ip6-frag",
723  [IP4_MAP_NEXT_REASS] = "ip4-map-reass",
724  [IP4_MAP_NEXT_ICMP_ERROR] = "ip4-icmp-error",
725  [IP4_MAP_NEXT_DROP] = "error-drop",
726  },
727 };
728 /* *INDENT-ON* */
729 
730 /* *INDENT-OFF* */
732  .function = ip4_map_reass,
733  .name = "ip4-map-reass",
734  .vector_size = sizeof(u32),
735  .format_trace = format_ip4_map_reass_trace,
737 
738  .n_errors = MAP_N_ERROR,
739  .error_strings = map_error_strings,
740 
741  .n_next_nodes = IP4_MAP_REASS_N_NEXT,
742  .next_nodes = {
743  [IP4_MAP_REASS_NEXT_IP6_LOOKUP] = "ip6-lookup",
744  [IP4_MAP_REASS_NEXT_IP4_FRAGMENT] = "ip4-frag",
745  [IP4_MAP_REASS_NEXT_DROP] = "error-drop",
746  },
747 };
748 /* *INDENT-ON* */
749 
750 /*
751  * fd.io coding-style-patch-verification: ON
752  *
753  * Local Variables:
754  * eval: (c-set-style "gnu")
755  * End:
756  */
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 map_ip4_reass_lock()
Definition: map.h:505
u8 psid_length
Definition: map.h:120
#define CLIB_UNUSED(x)
Definition: clib.h:83
u8 * format_ip4_map_reass_trace(u8 *s, va_list *args)
Definition: ip4_map.c:55
map_main_t map_main
Definition: map.c:27
void ip_frag_set_vnet_buffer(vlib_buffer_t *b, u16 mtu, u8 next_index, u8 flags)
Definition: ip_frag.c:272
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:220
static_always_inline u64 map_get_pfx(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:402
ip4_address_t src_address
Definition: ip4_packet.h:170
#define PREDICT_TRUE(x)
Definition: clib.h:113
u64 as_u64[2]
Definition: ip6_packet.h:51
unsigned long u64
Definition: types.h:89
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
u8 tc
Definition: map.h:277
u32 thread_index
Definition: main.h:218
static_always_inline map_domain_t * ip4_map_get_domain(ip4_address_t *addr, u32 *map_domain_index, u8 *error)
Definition: map.h:465
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
vlib_node_registration_t ip4_map_node
(constructor) VLIB_REGISTER_NODE (ip4_map_node)
Definition: ip4_map.c:705
u16 flags_and_fragment_offset
Definition: ip4_packet.h:151
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:470
ip6_address_t src_address
Definition: ip6_packet.h:383
unsigned char u8
Definition: types.h:56
IPv4 to IPv6 translation.
u16 port
Definition: map.h:380
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
bool tc_copy
Definition: map.h:278
#define static_always_inline
Definition: clib.h:100
ip4_address_t dst_address
Definition: ip4_packet.h:170
vlib_combined_counter_main_t * domain_counters
Definition: map.h:270
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:203
static_always_inline void map_send_all_to_node(vlib_main_t *vm, u32 *pi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
Definition: map.h:602
int map_ip4_reass_add_fragment(map_ip4_reass_t *r, u32 pi)
Definition: map.c:1524
unsigned int u32
Definition: types.h:88
#define VLIB_FRAME_SIZE
Definition: node.h:378
static u16 ip4_get_port(ip4_header_t *ip, u8 sender)
Get TCP/UDP port number or ICMP id from IPv4 packet.
Definition: ip4_to_ip6.h:51
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
static u32 ip4_map_fragment(vlib_buffer_t *b, u16 mtu, bool df, u8 *error)
Definition: ip4_map.c:149
static uword ip4_map_reass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip4_map.c:504
vnet_crypto_main_t * cm
Definition: quic_crypto.c:41
bool frag_ignore_df
Definition: map.h:315
static_always_inline u64 map_get_pfx_net(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:416
unsigned short u16
Definition: types.h:57
ip4_map_reass_next_t
Definition: ip4_map.c:39
ip4_map_next_e
Definition: ip4_map.c:25
static int ip4_get_fragment_offset(const ip4_header_t *i)
Definition: ip4_packet.h:200
static_always_inline u64 map_get_sfx_net(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:448
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
map_ip4_reass_t * map_ip4_reass_get(u32 src, u32 dst, u16 fragment_id, u8 protocol, u32 **pi_to_drop)
Definition: map.c:1443
#define PREDICT_FALSE(x)
Definition: clib.h:112
static_always_inline u32 ip4_map_vtcfl(ip4_header_t *ip4, vlib_buffer_t *p)
Definition: ip4_map.c:115
u16 port
Definition: punt.api:40
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
#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
u16 expected_total
Definition: map.h:167
vlib_node_registration_t ip4_map_reass_node
(constructor) VLIB_REGISTER_NODE (ip4_map_reass_node)
Definition: ip4_map.c:23
u8 len
Definition: ip_types.api:90
void map_ip4_reass_free(map_ip4_reass_t *r, u32 **pi_to_drop)
Definition: map.c:1400
static uword ip4_map(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip4_map.c:182
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:397
static_always_inline void map_ip4_reass_get_fragments(map_ip4_reass_t *r, u32 **pi)
Definition: map.h:509
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:323
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:302
u8 psid_offset
Definition: map.h:119
u8 ttl
Definition: fib_types.api:26
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
Definition: node_funcs.h:89
u8 data[]
Packet data.
Definition: buffer.h:181
u16 forwarded
Definition: map.h:168
static void ip4_map_decrement_ttl(ip4_header_t *ip, u8 *error)
Definition: ip4_map.c:130
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
#define foreach_map_error
Definition: map.h:350
ip6_address_t ip6_src
Definition: map.h:108
static int ip4_get_fragment_more(const ip4_header_t *i)
Definition: ip4_packet.h:206
static char * map_error_strings[]
Definition: ip4_map.c:689
signed int i32
Definition: types.h:77
#define IP_FRAG_FLAG_IP6_HEADER
Definition: ip_frag.h:41
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)
ip_dscp_t tos
Definition: ip4_packet.h:141
bool frag_inner
Definition: map.h:314
static_always_inline bool ip4_map_ip6_lookup_bypass(vlib_buffer_t *p0, ip4_header_t *ip)
Definition: map.h:677
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
#define map_ip4_reass_unlock()
Definition: map.h:506
u8 * format_map_trace(u8 *s, va_list *args)
Definition: map.c:1363
VNET_FEATURE_INIT(ip4_map_feature, static)
#define VNET_FEATURES(...)
Definition: feature.h:442
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
struct _vlib_node_registration vlib_node_registration_t
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:370
Definition: defs.h:47
u16 mtu
Definition: map.h:114
u16 payload_length
Definition: ip6_packet.h:374
vl_api_address_t ip
Definition: l2.api:489
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
i32 port
Definition: map.h:170
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
A collection of combined counters.
Definition: counter.h:188
#define vnet_buffer(b)
Definition: buffer.h:365
#define IP4_HEADER_FLAG_DONT_FRAGMENT
Definition: ip4_packet.h:153
static_always_inline u64 map_get_sfx(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:426
u32 map_domain_index
Definition: map.h:379
u8 ip_version_and_header_length
Definition: ip4_packet.h:138
static_always_inline void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
Definition: icmp4.h:51
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 u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
static_always_inline u16 ip4_map_port_and_security_check(map_domain_t *d, ip4_header_t *ip, u32 *next, u8 *error)
Definition: ip4_map.c:66
ip6_address_t dst_address
Definition: ip6_packet.h:383