FD.io VPP  v17.04.2-2-ga8f93f8
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 #define MAP_ENCAP_DUAL 0
19 
20 #include "map.h"
21 #include "../ip/ip_frag.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 
65 /*
66  * ip4_map_get_port
67  */
68 u16
70 {
71  /* Find port information */
72  if (PREDICT_TRUE ((ip->protocol == IP_PROTOCOL_TCP) ||
73  (ip->protocol == IP_PROTOCOL_UDP)))
74  {
75  udp_header_t *udp = (void *) (ip + 1);
76  return (dir == MAP_SENDER ? udp->src_port : udp->dst_port);
77  }
78  else if (ip->protocol == IP_PROTOCOL_ICMP)
79  {
80  /*
81  * 1) ICMP Echo request or Echo reply
82  * 2) ICMP Error with inner packet being UDP or TCP
83  * 3) ICMP Error with inner packet being ICMP Echo request or Echo reply
84  */
85  icmp46_header_t *icmp = (void *) (ip + 1);
86  if (icmp->type == ICMP4_echo_request || icmp->type == ICMP4_echo_reply)
87  {
88  return *((u16 *) (icmp + 1));
89  }
90  else if (clib_net_to_host_u16 (ip->length) >= 56)
91  { // IP + ICMP + IP + L4 header
92  ip4_header_t *icmp_ip = (ip4_header_t *) (icmp + 2);
93  if (PREDICT_TRUE ((icmp_ip->protocol == IP_PROTOCOL_TCP) ||
94  (icmp_ip->protocol == IP_PROTOCOL_UDP)))
95  {
96  udp_header_t *udp = (void *) (icmp_ip + 1);
97  return (dir == MAP_SENDER ? udp->dst_port : udp->src_port);
98  }
99  else if (icmp_ip->protocol == IP_PROTOCOL_ICMP)
100  {
101  icmp46_header_t *inner_icmp = (void *) (icmp_ip + 1);
102  if (inner_icmp->type == ICMP4_echo_request
103  || inner_icmp->type == ICMP4_echo_reply)
104  return (*((u16 *) (inner_icmp + 1)));
105  }
106  }
107  }
108  return (0);
109 }
110 
113  u32 * next, u8 * error)
114 {
115  u16 port = 0;
116 
117  if (d->psid_length > 0)
118  {
119  if (ip4_get_fragment_offset (ip) == 0)
120  {
121  if (PREDICT_FALSE
122  ((ip->ip_version_and_header_length != 0x45)
123  || clib_host_to_net_u16 (ip->length) < 28))
124  {
125  return 0;
126  }
127  port = ip4_map_get_port (ip, MAP_RECEIVER);
128  if (port)
129  {
130  /* Verify that port is not among the well-known ports */
131  if ((d->psid_offset > 0)
132  && (clib_net_to_host_u16 (port) <
133  (0x1 << (16 - d->psid_offset))))
134  {
135  *error = MAP_ERROR_ENCAP_SEC_CHECK;
136  }
137  else
138  {
139  if (ip4_get_fragment_more (ip))
140  *next = IP4_MAP_NEXT_REASS;
141  return (port);
142  }
143  }
144  else
145  {
146  *error = MAP_ERROR_BAD_PROTOCOL;
147  }
148  }
149  else
150  {
151  *next = IP4_MAP_NEXT_REASS;
152  }
153  }
154  return (0);
155 }
156 
157 /*
158  * ip4_map_vtcfl
159  */
162 {
163  map_main_t *mm = &map_main;
164  u8 tc = mm->tc_copy ? ip4->tos : mm->tc;
165  u32 vtcfl = 0x6 << 28;
166  vtcfl |= tc << 20;
167  vtcfl |= vnet_buffer (p)->ip.flow_hash & 0x000fffff;
168 
169  return (clib_host_to_net_u32 (vtcfl));
170 }
171 
174 {
175 #ifdef MAP_SKIP_IP6_LOOKUP
177  {
178  vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
180  return (true);
181  }
182 #endif
183  return (false);
184 }
185 
186 /*
187  * ip4_map_ttl
188  */
189 static inline void
191 {
192  i32 ttl = ip->ttl;
193 
194  /* Input node should have reject packets with ttl 0. */
195  ASSERT (ip->ttl > 0);
196 
197  u32 checksum = ip->checksum + clib_host_to_net_u16 (0x0100);
198  checksum += checksum >= 0xffff;
199  ip->checksum = checksum;
200  ttl -= 1;
201  ip->ttl = ttl;
202  *error = ttl <= 0 ? IP4_ERROR_TIME_EXPIRED : *error;
203 
204  /* Verify checksum. */
205  ASSERT (ip->checksum == ip4_header_checksum (ip));
206 }
207 
208 static u32
209 ip4_map_fragment (vlib_buffer_t * b, u16 mtu, bool df, u8 * error)
210 {
211  map_main_t *mm = &map_main;
212 
213  if (mm->frag_inner)
214  {
215  ip_frag_set_vnet_buffer (b, sizeof (ip6_header_t), mtu,
218  return (IP4_MAP_NEXT_IP4_FRAGMENT);
219  }
220  else
221  {
222  if (df && !mm->frag_ignore_df)
223  {
224  icmp4_error_set_vnet_buffer (b, ICMP4_destination_unreachable,
225  ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
226  mtu);
227  vlib_buffer_advance (b, sizeof (ip6_header_t));
228  *error = MAP_ERROR_DF_SET;
229  return (IP4_MAP_NEXT_ICMP_ERROR);
230  }
233  return (IP4_MAP_NEXT_IP6_FRAGMENT);
234  }
235 }
236 
237 /*
238  * ip4_map
239  */
240 static uword
242 {
243  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
244  vlib_node_runtime_t *error_node =
246  from = vlib_frame_vector_args (frame);
247  n_left_from = frame->n_vectors;
248  next_index = node->cached_next_index;
249  map_main_t *mm = &map_main;
251  u32 cpu_index = os_get_cpu_number ();
252 
253  while (n_left_from > 0)
254  {
255  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
256 
257  /* Dual loop */
258  while (n_left_from >= 4 && n_left_to_next >= 2)
259  {
260  u32 pi0, pi1;
261  vlib_buffer_t *p0, *p1;
262  map_domain_t *d0, *d1;
263  u8 error0 = MAP_ERROR_NONE, error1 = MAP_ERROR_NONE;
264  ip4_header_t *ip40, *ip41;
265  u16 port0 = 0, port1 = 0;
266  ip6_header_t *ip6h0, *ip6h1;
267  u32 map_domain_index0 = ~0, map_domain_index1 = ~0;
268  u32 next0 = IP4_MAP_NEXT_IP6_LOOKUP, next1 =
270 
271  /* Prefetch next iteration. */
272  {
273  vlib_buffer_t *p2, *p3;
274 
275  p2 = vlib_get_buffer (vm, from[2]);
276  p3 = vlib_get_buffer (vm, from[3]);
277 
278  vlib_prefetch_buffer_header (p2, STORE);
279  vlib_prefetch_buffer_header (p3, STORE);
280  /* IPv4 + 8 = 28. possibly plus -40 */
281  CLIB_PREFETCH (p2->data - 40, 68, STORE);
282  CLIB_PREFETCH (p3->data - 40, 68, STORE);
283  }
284 
285  pi0 = to_next[0] = from[0];
286  pi1 = to_next[1] = from[1];
287  from += 2;
288  n_left_from -= 2;
289  to_next += 2;
290  n_left_to_next -= 2;
291 
292  p0 = vlib_get_buffer (vm, pi0);
293  p1 = vlib_get_buffer (vm, pi1);
294  ip40 = vlib_buffer_get_current (p0);
295  ip41 = vlib_buffer_get_current (p1);
296  d0 =
297  ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
298  &map_domain_index0);
299  d1 =
300  ip4_map_get_domain (vnet_buffer (p1)->ip.adj_index[VLIB_TX],
301  &map_domain_index1);
302  ASSERT (d0);
303  ASSERT (d1);
304 
305  /*
306  * Shared IPv4 address
307  */
308  port0 = ip4_map_port_and_security_check (d0, ip40, &next0, &error0);
309  port1 = ip4_map_port_and_security_check (d1, ip41, &next1, &error1);
310 
311  /* Decrement IPv4 TTL */
312  ip4_map_decrement_ttl (ip40, &error0);
313  ip4_map_decrement_ttl (ip41, &error1);
314  bool df0 =
316  clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
317  bool df1 =
319  clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
320 
321  /* MAP calc */
322  u32 da40 = clib_net_to_host_u32 (ip40->dst_address.as_u32);
323  u32 da41 = clib_net_to_host_u32 (ip41->dst_address.as_u32);
324  u16 dp40 = clib_net_to_host_u16 (port0);
325  u16 dp41 = clib_net_to_host_u16 (port1);
326  u64 dal60 = map_get_pfx (d0, da40, dp40);
327  u64 dal61 = map_get_pfx (d1, da41, dp41);
328  u64 dar60 = map_get_sfx (d0, da40, dp40);
329  u64 dar61 = map_get_sfx (d1, da41, dp41);
330  if (dal60 == 0 && dar60 == 0 && error0 == MAP_ERROR_NONE
331  && next0 != IP4_MAP_NEXT_REASS)
332  error0 = MAP_ERROR_NO_BINDING;
333  if (dal61 == 0 && dar61 == 0 && error1 == MAP_ERROR_NONE
334  && next1 != IP4_MAP_NEXT_REASS)
335  error1 = MAP_ERROR_NO_BINDING;
336 
337  /* construct ipv6 header */
338  vlib_buffer_advance (p0, -sizeof (ip6_header_t));
339  vlib_buffer_advance (p1, -sizeof (ip6_header_t));
340  ip6h0 = vlib_buffer_get_current (p0);
341  ip6h1 = vlib_buffer_get_current (p1);
342  vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
343  vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
344 
346  ip4_map_vtcfl (ip40, p0);
348  ip4_map_vtcfl (ip41, p1);
349  ip6h0->payload_length = ip40->length;
350  ip6h1->payload_length = ip41->length;
351  ip6h0->protocol = IP_PROTOCOL_IP_IN_IP;
352  ip6h1->protocol = IP_PROTOCOL_IP_IN_IP;
353  ip6h0->hop_limit = 0x40;
354  ip6h1->hop_limit = 0x40;
355  ip6h0->src_address = d0->ip6_src;
356  ip6h1->src_address = d1->ip6_src;
357  ip6h0->dst_address.as_u64[0] = clib_host_to_net_u64 (dal60);
358  ip6h0->dst_address.as_u64[1] = clib_host_to_net_u64 (dar60);
359  ip6h1->dst_address.as_u64[0] = clib_host_to_net_u64 (dal61);
360  ip6h1->dst_address.as_u64[1] = clib_host_to_net_u64 (dar61);
361 
362  /*
363  * Determine next node. Can be one of:
364  * ip6-lookup, ip6-rewrite, ip4-fragment, ip4-virtreass, error-drop
365  */
366  if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
367  {
368  if (PREDICT_FALSE
369  (d0->mtu
370  && (clib_net_to_host_u16 (ip6h0->payload_length) +
371  sizeof (*ip6h0) > d0->mtu)))
372  {
373  next0 = ip4_map_fragment (p0, d0->mtu, df0, &error0);
374  }
375  else
376  {
377  next0 =
379  ip40) ?
380  IP4_MAP_NEXT_IP6_REWRITE : next0;
382  cpu_index,
383  map_domain_index0, 1,
384  clib_net_to_host_u16
385  (ip6h0->payload_length) +
386  40);
387  }
388  }
389  else
390  {
391  next0 = IP4_MAP_NEXT_DROP;
392  }
393 
394  /*
395  * Determine next node. Can be one of:
396  * ip6-lookup, ip6-rewrite, ip4-fragment, ip4-virtreass, error-drop
397  */
398  if (PREDICT_TRUE (error1 == MAP_ERROR_NONE))
399  {
400  if (PREDICT_FALSE
401  (d1->mtu
402  && (clib_net_to_host_u16 (ip6h1->payload_length) +
403  sizeof (*ip6h1) > d1->mtu)))
404  {
405  next1 = ip4_map_fragment (p1, d1->mtu, df1, &error1);
406  }
407  else
408  {
409  next1 =
411  ip41) ?
412  IP4_MAP_NEXT_IP6_REWRITE : next1;
414  cpu_index,
415  map_domain_index1, 1,
416  clib_net_to_host_u16
417  (ip6h1->payload_length) +
418  40);
419  }
420  }
421  else
422  {
423  next1 = IP4_MAP_NEXT_DROP;
424  }
425 
427  {
428  map_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
429  tr->map_domain_index = map_domain_index0;
430  tr->port = port0;
431  }
433  {
434  map_trace_t *tr = vlib_add_trace (vm, node, p1, sizeof (*tr));
435  tr->map_domain_index = map_domain_index1;
436  tr->port = port1;
437  }
438 
439  p0->error = error_node->errors[error0];
440  p1->error = error_node->errors[error1];
441 
442  vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
443  n_left_to_next, pi0, pi1, next0,
444  next1);
445  }
446 
447  while (n_left_from > 0 && n_left_to_next > 0)
448  {
449  u32 pi0;
450  vlib_buffer_t *p0;
451  map_domain_t *d0;
452  u8 error0 = MAP_ERROR_NONE;
453  ip4_header_t *ip40;
454  u16 port0 = 0;
455  ip6_header_t *ip6h0;
457  u32 map_domain_index0 = ~0;
458 
459  pi0 = to_next[0] = from[0];
460  from += 1;
461  n_left_from -= 1;
462  to_next += 1;
463  n_left_to_next -= 1;
464 
465  p0 = vlib_get_buffer (vm, pi0);
466  ip40 = vlib_buffer_get_current (p0);
467  d0 =
468  ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
469  &map_domain_index0);
470  ASSERT (d0);
471 
472  /*
473  * Shared IPv4 address
474  */
475  port0 = ip4_map_port_and_security_check (d0, ip40, &next0, &error0);
476 
477  /* Decrement IPv4 TTL */
478  ip4_map_decrement_ttl (ip40, &error0);
479  bool df0 =
481  clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
482 
483  /* MAP calc */
484  u32 da40 = clib_net_to_host_u32 (ip40->dst_address.as_u32);
485  u16 dp40 = clib_net_to_host_u16 (port0);
486  u64 dal60 = map_get_pfx (d0, da40, dp40);
487  u64 dar60 = map_get_sfx (d0, da40, dp40);
488  if (dal60 == 0 && dar60 == 0 && error0 == MAP_ERROR_NONE
489  && next0 != IP4_MAP_NEXT_REASS)
490  error0 = MAP_ERROR_NO_BINDING;
491 
492  /* construct ipv6 header */
493  vlib_buffer_advance (p0, -(sizeof (ip6_header_t)));
494  ip6h0 = vlib_buffer_get_current (p0);
495  vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
496 
498  ip4_map_vtcfl (ip40, p0);
499  ip6h0->payload_length = ip40->length;
500  ip6h0->protocol = IP_PROTOCOL_IP_IN_IP;
501  ip6h0->hop_limit = 0x40;
502  ip6h0->src_address = d0->ip6_src;
503  ip6h0->dst_address.as_u64[0] = clib_host_to_net_u64 (dal60);
504  ip6h0->dst_address.as_u64[1] = clib_host_to_net_u64 (dar60);
505 
506  /*
507  * Determine next node. Can be one of:
508  * ip6-lookup, ip6-rewrite, ip4-fragment, ip4-virtreass, error-drop
509  */
510  if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
511  {
512  if (PREDICT_FALSE
513  (d0->mtu
514  && (clib_net_to_host_u16 (ip6h0->payload_length) +
515  sizeof (*ip6h0) > d0->mtu)))
516  {
517  next0 = ip4_map_fragment (p0, d0->mtu, df0, &error0);
518  }
519  else
520  {
521  next0 =
523  ip40) ?
524  IP4_MAP_NEXT_IP6_REWRITE : next0;
526  cpu_index,
527  map_domain_index0, 1,
528  clib_net_to_host_u16
529  (ip6h0->payload_length) +
530  40);
531  }
532  }
533  else
534  {
535  next0 = IP4_MAP_NEXT_DROP;
536  }
537 
539  {
540  map_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
541  tr->map_domain_index = map_domain_index0;
542  tr->port = port0;
543  }
544 
545  p0->error = error_node->errors[error0];
546  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
547  n_left_to_next, pi0, next0);
548  }
549  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
550  }
551 
552  return frame->n_vectors;
553 }
554 
555 /*
556  * ip4_map_reass
557  */
558 static uword
560  vlib_node_runtime_t * node, vlib_frame_t * frame)
561 {
562  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
563  vlib_node_runtime_t *error_node =
565  from = vlib_frame_vector_args (frame);
566  n_left_from = frame->n_vectors;
567  next_index = node->cached_next_index;
568  map_main_t *mm = &map_main;
570  u32 cpu_index = os_get_cpu_number ();
571  u32 *fragments_to_drop = NULL;
572  u32 *fragments_to_loopback = NULL;
573 
574  while (n_left_from > 0)
575  {
576  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
577 
578  while (n_left_from > 0 && n_left_to_next > 0)
579  {
580  u32 pi0;
581  vlib_buffer_t *p0;
582  map_domain_t *d0;
583  u8 error0 = MAP_ERROR_NONE;
584  ip4_header_t *ip40;
585  i32 port0 = 0;
586  ip6_header_t *ip60;
588  u32 map_domain_index0;
589  u8 cached = 0;
590 
591  pi0 = to_next[0] = from[0];
592  from += 1;
593  n_left_from -= 1;
594  to_next += 1;
595  n_left_to_next -= 1;
596 
597  p0 = vlib_get_buffer (vm, pi0);
598  ip60 = vlib_buffer_get_current (p0);
599  ip40 = (ip4_header_t *) (ip60 + 1);
600  d0 =
601  ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
602  &map_domain_index0);
603 
606  ip40->dst_address.as_u32,
607  ip40->fragment_id,
608  ip40->protocol,
609  &fragments_to_drop);
610  if (PREDICT_FALSE (!r))
611  {
612  // Could not create a caching entry
613  error0 = MAP_ERROR_FRAGMENT_MEMORY;
614  }
615  else if (PREDICT_TRUE (ip4_get_fragment_offset (ip40)))
616  {
617  if (r->port >= 0)
618  {
619  // We know the port already
620  port0 = r->port;
621  }
622  else if (map_ip4_reass_add_fragment (r, pi0))
623  {
624  // Not enough space for caching
625  error0 = MAP_ERROR_FRAGMENT_MEMORY;
626  map_ip4_reass_free (r, &fragments_to_drop);
627  }
628  else
629  {
630  cached = 1;
631  }
632  }
633  else
634  if ((port0 =
635  ip4_get_port (ip40, MAP_RECEIVER, p0->current_length)) < 0)
636  {
637  // Could not find port. We'll free the reassembly.
638  error0 = MAP_ERROR_BAD_PROTOCOL;
639  port0 = 0;
640  map_ip4_reass_free (r, &fragments_to_drop);
641  }
642  else
643  {
644  r->port = port0;
645  map_ip4_reass_get_fragments (r, &fragments_to_loopback);
646  }
647 
648 #ifdef MAP_IP4_REASS_COUNT_BYTES
649  if (!cached && r)
650  {
651  r->forwarded += clib_host_to_net_u16 (ip40->length) - 20;
652  if (!ip4_get_fragment_more (ip40))
653  r->expected_total =
654  ip4_get_fragment_offset (ip40) * 8 +
655  clib_host_to_net_u16 (ip40->length) - 20;
656  if (r->forwarded >= r->expected_total)
657  map_ip4_reass_free (r, &fragments_to_drop);
658  }
659 #endif
660 
662 
663  // NOTE: Most operations have already been performed by ip4_map
664  // All we need is the right destination address
665  ip60->dst_address.as_u64[0] =
666  map_get_pfx_net (d0, ip40->dst_address.as_u32, port0);
667  ip60->dst_address.as_u64[1] =
668  map_get_sfx_net (d0, ip40->dst_address.as_u32, port0);
669 
670  if (PREDICT_FALSE
671  (d0->mtu
672  && (clib_net_to_host_u16 (ip60->payload_length) +
673  sizeof (*ip60) > d0->mtu)))
674  {
675  vnet_buffer (p0)->ip_frag.header_offset = sizeof (*ip60);
676  vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP6_LOOKUP;
677  vnet_buffer (p0)->ip_frag.mtu = d0->mtu;
678  vnet_buffer (p0)->ip_frag.flags = IP_FRAG_FLAG_IP6_HEADER;
680  }
681 
683  {
685  vlib_add_trace (vm, node, p0, sizeof (*tr));
686  tr->map_domain_index = map_domain_index0;
687  tr->port = port0;
688  tr->cached = cached;
689  }
690 
691  if (cached)
692  {
693  //Dequeue the packet
694  n_left_to_next++;
695  to_next--;
696  }
697  else
698  {
699  if (error0 == MAP_ERROR_NONE)
701  cpu_index, map_domain_index0,
702  1,
703  clib_net_to_host_u16
704  (ip60->payload_length) + 40);
705  next0 =
706  (error0 == MAP_ERROR_NONE) ? next0 : IP4_MAP_REASS_NEXT_DROP;
707  p0->error = error_node->errors[error0];
708  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
709  n_left_to_next, pi0, next0);
710  }
711 
712  //Loopback when we reach the end of the inpu vector
713  if (n_left_from == 0 && vec_len (fragments_to_loopback))
714  {
715  from = vlib_frame_vector_args (frame);
716  u32 len = vec_len (fragments_to_loopback);
717  if (len <= VLIB_FRAME_SIZE)
718  {
719  clib_memcpy (from, fragments_to_loopback,
720  sizeof (u32) * len);
721  n_left_from = len;
722  vec_reset_length (fragments_to_loopback);
723  }
724  else
725  {
726  clib_memcpy (from,
727  fragments_to_loopback + (len -
729  sizeof (u32) * VLIB_FRAME_SIZE);
730  n_left_from = VLIB_FRAME_SIZE;
731  _vec_len (fragments_to_loopback) = len - VLIB_FRAME_SIZE;
732  }
733  }
734  }
735  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
736  }
737 
738  map_send_all_to_node (vm, fragments_to_drop, node,
739  &error_node->errors[MAP_ERROR_FRAGMENT_DROPPED],
741 
742  vec_free (fragments_to_drop);
743  vec_free (fragments_to_loopback);
744  return frame->n_vectors;
745 }
746 
747 static char *map_error_strings[] = {
748 #define _(sym,string) string,
750 #undef _
751 };
752 
753 /* *INDENT-OFF* */
755  .function = ip4_map,
756  .name = "ip4-map",
757  .vector_size = sizeof(u32),
758  .format_trace = format_map_trace,
759  .type = VLIB_NODE_TYPE_INTERNAL,
760 
761  .n_errors = MAP_N_ERROR,
762  .error_strings = map_error_strings,
763 
764  .n_next_nodes = IP4_MAP_N_NEXT,
765  .next_nodes = {
766  [IP4_MAP_NEXT_IP6_LOOKUP] = "ip6-lookup",
767 #ifdef MAP_SKIP_IP6_LOOKUP
768  [IP4_MAP_NEXT_IP6_REWRITE] = "ip6-load-balance",
769 #endif
770  [IP4_MAP_NEXT_IP4_FRAGMENT] = "ip4-frag",
771  [IP4_MAP_NEXT_IP6_FRAGMENT] = "ip6-frag",
772  [IP4_MAP_NEXT_REASS] = "ip4-map-reass",
773  [IP4_MAP_NEXT_ICMP_ERROR] = "ip4-icmp-error",
774  [IP4_MAP_NEXT_DROP] = "error-drop",
775  },
776 };
777 /* *INDENT-ON* */
778 
779 /* *INDENT-OFF* */
781  .function = ip4_map_reass,
782  .name = "ip4-map-reass",
783  .vector_size = sizeof(u32),
784  .format_trace = format_ip4_map_reass_trace,
785  .type = VLIB_NODE_TYPE_INTERNAL,
786 
787  .n_errors = MAP_N_ERROR,
788  .error_strings = map_error_strings,
789 
790  .n_next_nodes = IP4_MAP_REASS_N_NEXT,
791  .next_nodes = {
792  [IP4_MAP_REASS_NEXT_IP6_LOOKUP] = "ip6-lookup",
793  [IP4_MAP_REASS_NEXT_IP4_FRAGMENT] = "ip4-frag",
794  [IP4_MAP_REASS_NEXT_DROP] = "error-drop",
795  },
796 };
797 /* *INDENT-ON* */
798 
799 /*
800  * fd.io coding-style-patch-verification: ON
801  *
802  * Local Variables:
803  * eval: (c-set-style "gnu")
804  * End:
805  */
#define map_ip4_reass_lock()
Definition: map.h:476
u8 psid_length
Definition: map.h:102
#define CLIB_UNUSED(x)
Definition: clib.h:79
u8 * format_ip4_map_reass_trace(u8 *s, va_list *args)
Definition: ip4_map.c:55
static_always_inline u64 map_get_pfx(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:360
ip4_address_t src_address
Definition: ip4_packet.h:163
void ip_frag_set_vnet_buffer(vlib_buffer_t *b, u16 offset, u16 mtu, u8 next_index, u8 flags)
Definition: ip_frag.c:178
#define PREDICT_TRUE(x)
Definition: clib.h:98
u64 as_u64[2]
Definition: ip6_packet.h:51
dpo_id_t dpo
The Load-balance object index to use to forward.
Definition: map.h:225
#define NULL
Definition: clib.h:55
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:459
u8 tc
Definition: map.h:245
struct _vlib_node_registration vlib_node_registration_t
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
vlib_node_registration_t ip4_map_node
(constructor) VLIB_REGISTER_NODE (ip4_map_node)
Definition: ip4_map.c:754
u16 flags_and_fragment_offset
Definition: ip4_packet.h:144
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:418
ip6_address_t src_address
Definition: ip6_packet.h:341
u16 port
Definition: map.h:338
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
bool tc_copy
Definition: map.h:246
#define static_always_inline
Definition: clib.h:85
ip4_address_t dst_address
Definition: ip4_packet.h:163
vlib_combined_counter_main_t * domain_counters
Definition: map.h:241
static int ip4_get_fragment_offset(ip4_header_t *i)
Definition: ip4_packet.h:191
int i32
Definition: types.h:81
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:164
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:587
int map_ip4_reass_add_fragment(map_ip4_reass_t *r, u32 pi)
Definition: map.c:1673
unsigned long u64
Definition: types.h:89
static u32 ip4_map_fragment(vlib_buffer_t *b, u16 mtu, bool df, u8 *error)
Definition: ip4_map.c:209
static uword ip4_map_reass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip4_map.c:559
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:71
bool frag_ignore_df
Definition: map.h:281
static_always_inline u64 map_get_pfx_net(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:374
ip4_map_reass_next_t
Definition: ip4_map.c:39
ip4_map_next_e
Definition: ip4_map.c:25
uword os_get_cpu_number(void)
Definition: unix-misc.c:224
static_always_inline u64 map_get_sfx_net(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:403
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:188
map_ip4_reass_t * map_ip4_reass_get(u32 src, u32 dst, u16 fragment_id, u8 protocol, u32 **pi_to_drop)
Definition: map.c:1594
#define PREDICT_FALSE(x)
Definition: clib.h:97
static_always_inline u32 ip4_map_vtcfl(ip4_header_t *ip4, vlib_buffer_t *p)
Definition: ip4_map.c:161
#define VLIB_FRAME_SIZE
Definition: node.h:328
map_main_t map_main
Definition: map.h:341
i32 ip4_get_port(ip4_header_t *ip, map_dir_e dir, u16 buffer_len)
Definition: map.c:80
#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:216
#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:350
u16 expected_total
Definition: map.h:139
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:113
vlib_node_registration_t ip4_map_reass_node
(constructor) VLIB_REGISTER_NODE (ip4_map_reass_node)
Definition: ip4_map.c:23
u16 ip4_map_get_port(ip4_header_t *ip, map_dir_e dir)
Definition: ip4_map.c:69
map_main_pre_resolved_t pre_resolved[FIB_PROTOCOL_MAX]
Pre-resolvd per-protocol global next-hops.
Definition: map.c:444
void map_ip4_reass_free(map_ip4_reass_t *r, u32 **pi_to_drop)
Definition: map.c:1551
static uword ip4_map(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip4_map.c:241
static_always_inline bool ip4_map_ip6_lookup_bypass(vlib_buffer_t *p0, ip4_header_t *ip)
Definition: ip4_map.c:173
map_dir_e
Definition: map.h:28
u16 n_vectors
Definition: node.h:344
static_always_inline void map_ip4_reass_get_fragments(map_ip4_reass_t *r, u32 **pi)
Definition: map.h:480
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
vlib_main_t * vm
Definition: buffer.c:276
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:340
void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
Definition: icmp4.c:431
u8 psid_offset
Definition: map.h:101
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:85
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:88
u16 forwarded
Definition: map.h:140
#define clib_memcpy(a, b, c)
Definition: string.h:69
static void ip4_map_decrement_ttl(ip4_header_t *ip, u8 *error)
Definition: ip4_map.c:190
#define foreach_map_error
Definition: map.h:308
ip6_address_t ip6_src
Definition: map.h:90
static char * map_error_strings[]
Definition: ip4_map.c:747
#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:455
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:211
bool frag_inner
Definition: map.h:280
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:201
#define map_ip4_reass_unlock()
Definition: map.h:477
u8 * format_map_trace(u8 *s, va_list *args)
Definition: map.c:1514
static int ip4_get_fragment_more(ip4_header_t *i)
Definition: ip4_packet.h:197
u64 uword
Definition: types.h:112
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
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:328
Definition: defs.h:47
unsigned short u16
Definition: types.h:57
u16 mtu
Definition: map.h:96
u16 payload_length
Definition: ip6_packet.h:332
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:162
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
i32 port
Definition: map.h:142
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:253
A collection of combined counters.
Definition: counter.h:180
static_always_inline map_domain_t * ip4_map_get_domain(u32 mdi, u32 *map_domain_index)
Definition: map.h:419
#define vnet_buffer(b)
Definition: buffer.h:294
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u8 data[0]
Packet data.
Definition: buffer.h:152
#define IP4_HEADER_FLAG_DONT_FRAGMENT
Definition: ip4_packet.h:146
static_always_inline u64 map_get_sfx(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:384
u32 map_domain_index
Definition: map.h:337
u8 ip_version_and_header_length
Definition: ip4_packet.h:131
Definition: map.h:30
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:74
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:238
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:112
ip6_address_t dst_address
Definition: ip6_packet.h:341