FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
ip6_map_t.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 #include "map.h"
16 
17 #include <vnet/ip/ip4_to_ip6.h>
18 #include <vnet/ip/ip6_to_ip4.h>
19 #include <vnet/ip/ip_frag.h>
20 
21 typedef enum
22 {
29 
30 typedef enum
31 {
37 
38 typedef enum
39 {
45 
46 typedef enum
47 {
53 
55 ip6_map_fragment_cache (ip6_header_t * ip6, ip6_frag_hdr_t * frag,
56  map_domain_t * d, u16 port)
57 {
58  u32 *ignore = NULL;
60  map_ip4_reass_t *r =
63  frag_id_6to4 (frag->identification),
64  (ip6->protocol ==
65  IP_PROTOCOL_ICMP6) ? IP_PROTOCOL_ICMP : ip6->protocol,
66  &ignore);
67  if (r)
68  r->port = port;
69 
71  return !r;
72 }
73 
74 /* Returns the associated port or -1 */
76 ip6_map_fragment_get (ip6_header_t * ip6, ip6_frag_hdr_t * frag,
77  map_domain_t * d)
78 {
79  u32 *ignore = NULL;
81  map_ip4_reass_t *r =
84  frag_id_6to4 (frag->identification),
85  (ip6->protocol ==
86  IP_PROTOCOL_ICMP6) ? IP_PROTOCOL_ICMP : ip6->protocol,
87  &ignore);
88  i32 ret = r ? r->port : -1;
90  return ret;
91 }
92 
93 typedef struct
94 {
98 
99 static int
101 {
102  icmp6_to_icmp_ctx_t *ctx = arg;
103  u32 ip4_sadr;
104 
105  // Security check
106  // Note that this prevents an intermediate IPv6 router from answering
107  // the request.
108  ip4_sadr = map_get_ip4 (&ip6->src_address, ctx->d->flags);
109  if (ip6->src_address.as_u64[0] !=
110  map_get_pfx_net (ctx->d, ip4_sadr, ctx->sender_port)
111  || ip6->src_address.as_u64[1] != map_get_sfx_net (ctx->d, ip4_sadr,
112  ctx->sender_port))
113  return -1;
114 
115  ip4->dst_address.as_u32 =
117  ip4->src_address.as_u32 = ip4_sadr;
118 
119  return 0;
120 }
121 
122 static int
124  void *arg)
125 {
126  icmp6_to_icmp_ctx_t *ctx = arg;
127  u32 inner_ip4_dadr;
128 
129  //Security check of inner packet
130  inner_ip4_dadr = map_get_ip4 (&ip6->dst_address, ctx->d->flags);
131  if (ip6->dst_address.as_u64[0] !=
132  map_get_pfx_net (ctx->d, inner_ip4_dadr, ctx->sender_port)
133  || ip6->dst_address.as_u64[1] != map_get_sfx_net (ctx->d,
134  inner_ip4_dadr,
135  ctx->sender_port))
136  return -1;
137 
138  ip4->dst_address.as_u32 = inner_ip4_dadr;
139  ip4->src_address.as_u32 =
141 
142  return 0;
143 }
144 
145 static uword
147  vlib_node_runtime_t * node, vlib_frame_t * frame)
148 {
149  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
150  vlib_node_runtime_t *error_node =
152  from = vlib_frame_vector_args (frame);
153  n_left_from = frame->n_vectors;
154  next_index = node->cached_next_index;
156  u32 thread_index = vm->thread_index;
157 
158  while (n_left_from > 0)
159  {
160  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
161 
162  while (n_left_from > 0 && n_left_to_next > 0)
163  {
164  u32 pi0;
165  vlib_buffer_t *p0;
166  u8 error0;
167  ip6_mapt_icmp_next_t next0;
168  map_domain_t *d0;
169  u16 len0;
170  icmp6_to_icmp_ctx_t ctx0;
171  ip6_header_t *ip60;
172 
173  pi0 = to_next[0] = from[0];
174  from += 1;
175  n_left_from -= 1;
176  to_next += 1;
177  n_left_to_next -= 1;
178  error0 = MAP_ERROR_NONE;
180 
181  p0 = vlib_get_buffer (vm, pi0);
182  ip60 = vlib_buffer_get_current (p0);
183  len0 = clib_net_to_host_u16 (ip60->payload_length);
184  d0 =
186  vnet_buffer (p0)->map_t.map_domain_index);
187  ctx0.sender_port = ip6_get_port (ip60, 0, p0->current_length);
188  ctx0.d = d0;
189  if (ctx0.sender_port == 0)
190  {
191  // In case of 1:1 mapping, we don't care about the port
192  if (!(d0->ea_bits_len == 0 && d0->rules))
193  {
194  error0 = MAP_ERROR_ICMP;
195  goto err0;
196  }
197  }
198 
199  if (icmp6_to_icmp
200  (p0, ip6_to_ip4_set_icmp_cb, &ctx0,
202  {
203  error0 = MAP_ERROR_ICMP;
204  goto err0;
205  }
206 
207  if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
208  {
209  // Send to fragmentation node if necessary
210  vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
211  vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
213  }
214  err0:
215  if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
216  {
218  thread_index,
219  vnet_buffer (p0)->
220  map_t.map_domain_index, 1,
221  len0);
222  }
223  else
224  {
225  next0 = IP6_MAPT_ICMP_NEXT_DROP;
226  }
227 
228  p0->error = error_node->errors[error0];
229  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
230  to_next, n_left_to_next, pi0,
231  next0);
232  }
233  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
234  }
235  return frame->n_vectors;
236 }
237 
238 /*
239  * Translate IPv6 fragmented packet to IPv4.
240  */
241 always_inline int
243 {
244  ip6_header_t *ip6;
245  ip6_frag_hdr_t *frag;
246  ip4_header_t *ip4;
247  u16 frag_id;
248  u8 frag_more;
249  u16 frag_offset;
250  u8 l4_protocol;
251  u16 l4_offset;
252 
253  ip6 = vlib_buffer_get_current (p);
254 
255  if (ip6_parse
256  (ip6, p->current_length, &l4_protocol, &l4_offset, &frag_offset))
257  return -1;
258 
259  frag = (ip6_frag_hdr_t *) u8_ptr_add (ip6, frag_offset);
260  ip4 = (ip4_header_t *) u8_ptr_add (ip6, l4_offset - sizeof (*ip4));
261  vlib_buffer_advance (p, l4_offset - sizeof (*ip4));
262 
263  frag_id = frag_id_6to4 (frag->identification);
264  frag_more = ip6_frag_hdr_more (frag);
265  frag_offset = ip6_frag_hdr_offset (frag);
266 
267  ip4->dst_address.as_u32 = vnet_buffer (p)->map_t.v6.daddr;
268  ip4->src_address.as_u32 = vnet_buffer (p)->map_t.v6.saddr;
269 
272  ip4->tos = ip6_translate_tos (ip6);
273  ip4->length =
275  sizeof (*ip4) - l4_offset + sizeof (*ip6));
276  ip4->fragment_id = frag_id;
278  clib_host_to_net_u16 (frag_offset |
279  (frag_more ? IP4_HEADER_FLAG_MORE_FRAGMENTS : 0));
280  ip4->ttl = ip6->hop_limit;
281  ip4->protocol =
282  (l4_protocol == IP_PROTOCOL_ICMP6) ? IP_PROTOCOL_ICMP : l4_protocol;
283  ip4->checksum = ip4_header_checksum (ip4);
284 
285  return 0;
286 }
287 
288 static uword
290  vlib_node_runtime_t * node, vlib_frame_t * frame)
291 {
292  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
293  from = vlib_frame_vector_args (frame);
294  n_left_from = frame->n_vectors;
295  next_index = node->cached_next_index;
296  vlib_node_runtime_t *error_node =
298 
299  while (n_left_from > 0)
300  {
301  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
302 
303  while (n_left_from > 0 && n_left_to_next > 0)
304  {
305  u32 pi0;
306  vlib_buffer_t *p0;
307  u32 next0;
308 
309  pi0 = to_next[0] = from[0];
310  from += 1;
311  n_left_from -= 1;
312  to_next += 1;
313  n_left_to_next -= 1;
314 
316  p0 = vlib_get_buffer (vm, pi0);
317 
318  if (map_ip6_to_ip4_fragmented (p0))
319  {
320  p0->error = error_node->errors[MAP_ERROR_FRAGMENT_DROPPED];
322  }
323  else
324  {
325  if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
326  {
327  // Send to fragmentation node if necessary
328  vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
329  vnet_buffer (p0)->ip_frag.next_index =
332  }
333  }
334 
335  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
336  to_next, n_left_to_next, pi0,
337  next0);
338  }
339  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
340  }
341  return frame->n_vectors;
342 }
343 
344 /*
345  * Translate IPv6 UDP/TCP packet to IPv4.
346  */
347 always_inline int
349 {
350  map_main_t *mm = &map_main;
351  ip6_header_t *ip6;
352  u16 *checksum;
353  ip_csum_t csum = 0;
354  ip4_header_t *ip4;
355  u16 fragment_id;
356  u16 flags;
357  u16 frag_offset;
358  u8 l4_protocol;
359  u16 l4_offset;
360  ip6_address_t old_src, old_dst;
361 
362  ip6 = vlib_buffer_get_current (p);
363 
364  if (ip6_parse
365  (ip6, p->current_length, &l4_protocol, &l4_offset, &frag_offset))
366  return -1;
367 
368  if (l4_protocol == IP_PROTOCOL_TCP)
369  {
370  tcp_header_t *tcp = ip6_next_header (ip6);
371  if (mm->tcp_mss > 0)
372  {
373  csum = tcp->checksum;
374  map_mss_clamping (tcp, &csum, mm->tcp_mss);
375  tcp->checksum = ip_csum_fold (csum);
376  }
377  checksum = &tcp->checksum;
378  }
379  else
380  {
381  udp_header_t *udp = ip6_next_header (ip6);
382  checksum = &udp->checksum;
383  }
384 
385  old_src.as_u64[0] = ip6->src_address.as_u64[0];
386  old_src.as_u64[1] = ip6->src_address.as_u64[1];
387  old_dst.as_u64[0] = ip6->dst_address.as_u64[0];
388  old_dst.as_u64[1] = ip6->dst_address.as_u64[1];
389 
390  ip4 = (ip4_header_t *) u8_ptr_add (ip6, l4_offset - sizeof (*ip4));
391 
392  vlib_buffer_advance (p, l4_offset - sizeof (*ip4));
393 
394  if (PREDICT_FALSE (frag_offset))
395  {
396  // Only the first fragment
397  ip6_frag_hdr_t *hdr = (ip6_frag_hdr_t *) u8_ptr_add (ip6, frag_offset);
398  fragment_id = frag_id_6to4 (hdr->identification);
399  flags = clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
400  }
401  else
402  {
403  fragment_id = 0;
404  flags = 0;
405  }
406 
407  ip4->dst_address.as_u32 = vnet_buffer (p)->map_t.v6.daddr;
408  ip4->src_address.as_u32 = vnet_buffer (p)->map_t.v6.saddr;
409 
412  ip4->tos = ip6_translate_tos (ip6);
413  ip4->length =
415  sizeof (*ip4) + sizeof (*ip6) - l4_offset);
416  ip4->fragment_id = fragment_id;
418  ip4->ttl = ip6->hop_limit;
419  ip4->protocol = l4_protocol;
420  ip4->checksum = ip4_header_checksum (ip4);
421 
422  // UDP checksum is optional over IPv4
423  if (!udp_checksum && l4_protocol == IP_PROTOCOL_UDP)
424  {
425  *checksum = 0;
426  }
427  else
428  {
429  csum = ip_csum_sub_even (*checksum, old_src.as_u64[0]);
430  csum = ip_csum_sub_even (csum, old_src.as_u64[1]);
431  csum = ip_csum_sub_even (csum, old_dst.as_u64[0]);
432  csum = ip_csum_sub_even (csum, old_dst.as_u64[1]);
433  csum = ip_csum_add_even (csum, ip4->dst_address.as_u32);
434  csum = ip_csum_add_even (csum, ip4->src_address.as_u32);
435  *checksum = ip_csum_fold (csum);
436  }
437 
438  return 0;
439 }
440 
441 static uword
443  vlib_node_runtime_t * node, vlib_frame_t * frame)
444 {
445  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
446  vlib_node_runtime_t *error_node =
448 
449  from = vlib_frame_vector_args (frame);
450  n_left_from = frame->n_vectors;
451  next_index = node->cached_next_index;
452  while (n_left_from > 0)
453  {
454  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
455 
456  while (n_left_from > 0 && n_left_to_next > 0)
457  {
458  u32 pi0;
459  vlib_buffer_t *p0;
461 
462  pi0 = to_next[0] = from[0];
463  from += 1;
464  n_left_from -= 1;
465  to_next += 1;
466  n_left_to_next -= 1;
468 
469  p0 = vlib_get_buffer (vm, pi0);
470 
471  if (map_ip6_to_ip4_tcp_udp (p0, true))
472  {
473  p0->error = error_node->errors[MAP_ERROR_UNKNOWN];
475  }
476  else
477  {
478  if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
479  {
480  // Send to fragmentation node if necessary
481  vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
482  vnet_buffer (p0)->ip_frag.next_index =
485  }
486  }
487 
488  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
489  to_next, n_left_to_next, pi0,
490  next0);
491  }
492  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
493  }
494  return frame->n_vectors;
495 }
496 
497 static uword
499 {
500  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
501  vlib_node_runtime_t *error_node =
504  u32 thread_index = vm->thread_index;
505 
506  from = vlib_frame_vector_args (frame);
507  n_left_from = frame->n_vectors;
508  next_index = node->cached_next_index;
509  while (n_left_from > 0)
510  {
511  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
512 
513  while (n_left_from > 0 && n_left_to_next > 0)
514  {
515  u32 pi0;
516  vlib_buffer_t *p0;
517  ip6_header_t *ip60;
518  u8 error0;
519  u32 l4_len0;
520  i32 map_port0;
521  map_domain_t *d0;
522  ip6_frag_hdr_t *frag0;
523  ip6_mapt_next_t next0 = 0;
524  u32 saddr;
525 
526  pi0 = to_next[0] = from[0];
527  from += 1;
528  n_left_from -= 1;
529  to_next += 1;
530  n_left_to_next -= 1;
531  error0 = MAP_ERROR_NONE;
532 
533  p0 = vlib_get_buffer (vm, pi0);
534  ip60 = vlib_buffer_get_current (p0);
535 
536  d0 =
538  &vnet_buffer (p0)->map_t.map_domain_index,
539  &error0);
540  if (!d0)
541  { /* Guess it wasn't for us */
542  vnet_feature_next (&next0, p0);
543  goto exit;
544  }
545 
546  saddr = map_get_ip4 (&ip60->src_address, d0->ip6_src_len);
547  vnet_buffer (p0)->map_t.v6.saddr = saddr;
548  vnet_buffer (p0)->map_t.v6.daddr =
550  vnet_buffer (p0)->map_t.mtu = d0->mtu ? d0->mtu : ~0;
551 
552  if (PREDICT_FALSE
553  (ip6_parse (ip60, p0->current_length,
554  &(vnet_buffer (p0)->map_t.v6.l4_protocol),
555  &(vnet_buffer (p0)->map_t.v6.l4_offset),
556  &(vnet_buffer (p0)->map_t.v6.frag_offset))))
557  {
558  error0 =
559  error0 == MAP_ERROR_NONE ? MAP_ERROR_MALFORMED : error0;
560  }
561 
562  map_port0 = -1;
563  l4_len0 =
564  (u32) clib_net_to_host_u16 (ip60->payload_length) +
565  sizeof (*ip60) - vnet_buffer (p0)->map_t.v6.l4_offset;
566  frag0 =
567  (ip6_frag_hdr_t *) u8_ptr_add (ip60,
568  vnet_buffer (p0)->map_t.v6.
569  frag_offset);
570 
571  if (PREDICT_FALSE
572  (vnet_buffer (p0)->map_t.v6.frag_offset
573  && ip6_frag_hdr_offset (frag0)))
574  {
575  map_port0 = ip6_map_fragment_get (ip60, frag0, d0);
576  if (map_port0 == -1)
577  error0 =
578  error0 ==
579  MAP_ERROR_NONE ? MAP_ERROR_FRAGMENT_MEMORY : error0;
580  else
582  }
583  else
584  if (PREDICT_TRUE
585  (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_TCP))
586  {
587  error0 =
588  l4_len0 <
589  sizeof (tcp_header_t) ? MAP_ERROR_MALFORMED : error0;
590  vnet_buffer (p0)->map_t.checksum_offset =
591  vnet_buffer (p0)->map_t.v6.l4_offset + 16;
593  map_port0 =
594  (i32) *
595  ((u16 *)
596  u8_ptr_add (ip60, vnet_buffer (p0)->map_t.v6.l4_offset));
597  }
598  else
599  if (PREDICT_TRUE
600  (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_UDP))
601  {
602  error0 =
603  l4_len0 <
604  sizeof (udp_header_t) ? MAP_ERROR_MALFORMED : error0;
605  vnet_buffer (p0)->map_t.checksum_offset =
606  vnet_buffer (p0)->map_t.v6.l4_offset + 6;
608  map_port0 =
609  (i32) *
610  ((u16 *)
611  u8_ptr_add (ip60, vnet_buffer (p0)->map_t.v6.l4_offset));
612  }
613  else if (vnet_buffer (p0)->map_t.v6.l4_protocol ==
614  IP_PROTOCOL_ICMP6)
615  {
616  error0 =
617  l4_len0 <
618  sizeof (icmp46_header_t) ? MAP_ERROR_MALFORMED : error0;
619  next0 = IP6_MAPT_NEXT_MAPT_ICMP;
620  if (((icmp46_header_t *)
621  u8_ptr_add (ip60,
622  vnet_buffer (p0)->map_t.v6.l4_offset))->code ==
623  ICMP6_echo_reply
624  || ((icmp46_header_t *)
625  u8_ptr_add (ip60,
626  vnet_buffer (p0)->map_t.v6.l4_offset))->
627  code == ICMP6_echo_request)
628  map_port0 =
629  (i32) *
630  ((u16 *)
631  u8_ptr_add (ip60,
632  vnet_buffer (p0)->map_t.v6.l4_offset + 6));
633  }
634  else
635  {
636  // TODO: In case of 1:1 mapping, it might be possible to
637  // do something with those packets.
638  error0 = MAP_ERROR_BAD_PROTOCOL;
639  }
640 
641  if (PREDICT_FALSE (map_port0 != -1) &&
642  (ip60->src_address.as_u64[0] !=
643  map_get_pfx_net (d0, vnet_buffer (p0)->map_t.v6.saddr,
644  map_port0)
645  || ip60->src_address.as_u64[1] != map_get_sfx_net (d0,
647  (p0)->map_t.
648  v6.saddr,
649  map_port0)))
650  {
651  // Security check when map_port0 is not zero (non-first
652  // fragment, UDP or TCP)
653  error0 =
654  error0 == MAP_ERROR_NONE ? MAP_ERROR_SEC_CHECK : error0;
655  }
656 
657  // Fragmented first packet needs to be cached for following packets
658  if (PREDICT_FALSE
659  (vnet_buffer (p0)->map_t.v6.frag_offset
660  && !ip6_frag_hdr_offset ((ip6_frag_hdr_t *)
661  u8_ptr_add (ip60,
662  vnet_buffer (p0)->map_t.
663  v6.frag_offset)))
664  && (map_port0 != -1) && (d0->ea_bits_len != 0 || !d0->rules)
665  && (error0 == MAP_ERROR_NONE))
666  {
668  (ip6_frag_hdr_t *) u8_ptr_add (ip60,
670  (p0)->
671  map_t.v6.
672  frag_offset),
673  d0, map_port0);
674  }
675 
676  if (PREDICT_TRUE
677  (error0 == MAP_ERROR_NONE && next0 != IP6_MAPT_NEXT_MAPT_ICMP))
678  {
680  thread_index,
681  vnet_buffer (p0)->map_t.
682  map_domain_index, 1,
683  clib_net_to_host_u16 (ip60->
684  payload_length));
685  }
686 
687  next0 = (error0 != MAP_ERROR_NONE) ? IP6_MAPT_NEXT_DROP : next0;
688  p0->error = error_node->errors[error0];
689  exit:
690  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
691  to_next, n_left_to_next, pi0,
692  next0);
693  }
694  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
695  }
696  return frame->n_vectors;
697 }
698 
699 static char *map_t_error_strings[] = {
700 #define _(sym, string) string,
702 #undef _
703 };
704 
705 /* *INDENT-OFF* */
707  .function = ip6_map_t_fragmented,
708  .name = "ip6-map-t-fragmented",
709  .vector_size = sizeof (u32),
710  .format_trace = format_map_trace,
711  .type = VLIB_NODE_TYPE_INTERNAL,
712 
713  .n_errors = MAP_N_ERROR,
714  .error_strings = map_t_error_strings,
715 
716  .n_next_nodes = IP6_MAPT_FRAGMENTED_N_NEXT,
717  .next_nodes =
718  {
719  [IP6_MAPT_FRAGMENTED_NEXT_IP4_LOOKUP] = "ip4-lookup",
721  [IP6_MAPT_FRAGMENTED_NEXT_DROP] = "error-drop",
722  },
723 };
724 /* *INDENT-ON* */
725 
726 /* *INDENT-OFF* */
728  .function = ip6_map_t_icmp,
729  .name = "ip6-map-t-icmp",
730  .vector_size = sizeof (u32),
731  .format_trace = format_map_trace,
732  .type = VLIB_NODE_TYPE_INTERNAL,
733 
734  .n_errors = MAP_N_ERROR,
735  .error_strings = map_t_error_strings,
736 
737  .n_next_nodes = IP6_MAPT_ICMP_N_NEXT,
738  .next_nodes =
739  {
740  [IP6_MAPT_ICMP_NEXT_IP4_LOOKUP] = "ip4-lookup",
742  [IP6_MAPT_ICMP_NEXT_DROP] = "error-drop",
743  },
744 };
745 /* *INDENT-ON* */
746 
747 /* *INDENT-OFF* */
749  .function = ip6_map_t_tcp_udp,
750  .name = "ip6-map-t-tcp-udp",
751  .vector_size = sizeof (u32),
752  .format_trace = format_map_trace,
753  .type = VLIB_NODE_TYPE_INTERNAL,
754 
755  .n_errors = MAP_N_ERROR,
756  .error_strings = map_t_error_strings,
757 
758  .n_next_nodes = IP6_MAPT_TCP_UDP_N_NEXT,
759  .next_nodes =
760  {
761  [IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP] = "ip4-lookup",
763  [IP6_MAPT_TCP_UDP_NEXT_DROP] = "error-drop",
764  },
765 };
766 /* *INDENT-ON* */
767 
768 /* *INDENT-OFF* */
769 VNET_FEATURE_INIT(ip4_map_t_feature, static) = {
770  .arc_name = "ip6-unicast",
771  .node_name = "ip6-map-t",
772  .runs_before = VNET_FEATURES("ip6-flow-classify"),
773 };
774 
776  .function = ip6_map_t,
777  .name = "ip6-map-t",
778  .vector_size = sizeof(u32),
779  .format_trace = format_map_trace,
780  .type = VLIB_NODE_TYPE_INTERNAL,
781 
782  .n_errors = MAP_N_ERROR,
783  .error_strings = map_t_error_strings,
784 
785  .n_next_nodes = IP6_MAPT_N_NEXT,
786  .next_nodes =
787  {
788  [IP6_MAPT_NEXT_MAPT_TCP_UDP] = "ip6-map-t-tcp-udp",
789  [IP6_MAPT_NEXT_MAPT_ICMP] = "ip6-map-t-icmp",
790  [IP6_MAPT_NEXT_MAPT_FRAGMENTED] = "ip6-map-t-fragmented",
791  [IP6_MAPT_NEXT_DROP] = "error-drop",
792  },
793 };
794 /* *INDENT-ON* */
795 
796 /*
797  * fd.io coding-style-patch-verification: ON
798  *
799  * Local Variables:
800  * eval: (c-set-style "gnu")
801  * End:
802  */
#define map_ip4_reass_lock()
Definition: map.h:492
map_domain_t * d
Definition: ip6_map_t.c:95
static_always_inline u8 ip6_translate_tos(const ip6_header_t *ip6)
Translate TOS value from IPv6 to IPv4.
Definition: ip6_to_ip4.h:231
u32 flags
Definition: vhost_user.h:115
static uword ip6_map_t_tcp_udp(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_map_t.c:442
static u16 ip6_get_port(ip6_header_t *ip6, u8 sender, u16 buffer_len)
Get TCP/UDP port number or ICMP id from IPv6 packet.
Definition: ip6_to_ip4.h:90
map_domain_flags_e flags
Definition: map.h:113
map_main_t map_main
Definition: map.c:26
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
u16 udp_checksum(udp_header_t *uh, u32 udp_len, void *ih, u8 version)
Definition: packets.c:114
ip6_mapt_next_t
Definition: ip6_map_t.c:21
ip4_address_t src_address
Definition: ip4_packet.h:170
static int icmp6_to_icmp(vlib_buffer_t *p, ip6_to_ip4_set_fn_t fn, void *ctx, ip6_to_ip4_set_fn_t inner_fn, void *inner_ctx)
Translate ICMP6 packet to ICMP4.
Definition: ip6_to_ip4.h:249
#define PREDICT_TRUE(x)
Definition: clib.h:112
u64 as_u64[2]
Definition: ip6_packet.h:51
#define NULL
Definition: clib.h:58
static_always_inline map_domain_t * ip6_map_get_domain(ip6_address_t *addr, u32 *map_domain_index, u8 *error)
Definition: map.h:471
u32 thread_index
Definition: main.h:179
static uword ip6_map_t(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_map_t.c:498
uword ip_csum_t
Definition: ip_packet.h:181
static int ip6_to_ip4_set_icmp_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
Definition: ip6_map_t.c:100
u16 flags_and_fragment_offset
Definition: ip4_packet.h:151
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:493
struct _tcp_header tcp_header_t
ip6_address_t src_address
Definition: ip6_packet.h:378
unsigned char u8
Definition: types.h:56
IPv4 to IPv6 translation.
static_always_inline u32 ip6_map_t_embedded_address(map_domain_t *d, ip6_address_t *addr)
Definition: map.h:563
#define static_always_inline
Definition: clib.h:99
static_always_inline u32 map_get_ip4(ip6_address_t *addr, u16 prefix_len)
Definition: map.h:442
#define always_inline
Definition: clib.h:98
ip4_address_t dst_address
Definition: ip4_packet.h:170
vlib_combined_counter_main_t * domain_counters
Definition: map.h:257
static int map_ip6_to_ip4_tcp_udp(vlib_buffer_t *p, bool udp_checksum)
Definition: ip6_map_t.c:348
ip6_address_t * rules
Definition: map.h:108
static_always_inline int ip6_parse(const ip6_header_t *ip6, u32 buff_len, u8 *l4_protocol, u16 *l4_offset, u16 *frag_hdr_offset)
Parse some useful information from IPv6 header.
Definition: ip6_to_ip4.h:59
u8 ea_bits_len
Definition: map.h:116
unsigned int u32
Definition: types.h:88
static_always_inline i32 ip6_map_fragment_get(ip6_header_t *ip6, ip6_frag_hdr_t *frag, map_domain_t *d)
Definition: ip6_map_t.c:76
#define frag_id_6to4(id)
Definition: ip6_to_ip4.h:45
#define ip6_frag_hdr_more(hdr)
Definition: ip6_packet.h:579
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:114
#define IP4_FRAG_NODE_NAME
Definition: ip_frag.h:43
long ctx[MAX_CONNS]
Definition: main.c:144
static_always_inline u64 map_get_pfx_net(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:403
unsigned short u16
Definition: types.h:57
map_domain_t * domains
Definition: map.h:253
vlib_node_registration_t ip6_map_t_tcp_udp_node
(constructor) VLIB_REGISTER_NODE (ip6_map_t_tcp_udp_node)
Definition: ip6_map_t.c:748
static_always_inline int ip6_map_fragment_cache(ip6_header_t *ip6, ip6_frag_hdr_t *frag, map_domain_t *d, u16 port)
Definition: ip6_map_t.c:55
static_always_inline u64 map_get_sfx_net(map_domain_t *d, u32 addr, u16 port)
Definition: map.h:435
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:214
map_ip4_reass_t * map_ip4_reass_get(u32 src, u32 dst, u16 fragment_id, u8 protocol, u32 **pi_to_drop)
Definition: map.c:1383
#define PREDICT_FALSE(x)
Definition: clib.h:111
#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
u8 ip6_src_len
Definition: map.h:115
#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_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:139
vlib_node_registration_t ip6_map_t_fragmented_node
(constructor) VLIB_REGISTER_NODE (ip6_map_t_fragmented_node)
Definition: ip6_map_t.c:706
#define IP4_HEADER_FLAG_MORE_FRAGMENTS
Definition: ip4_packet.h:152
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
ip6_mapt_tcp_udp_next_t
Definition: ip6_map_t.c:38
u16 n_vectors
Definition: node.h:420
static uword ip6_map_t_icmp(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_map_t.c:146
vlib_main_t * vm
Definition: buffer.c:301
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:295
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
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:452
#define foreach_map_error
Definition: map.h:337
ip6_mapt_icmp_next_t
Definition: ip6_map_t.c:30
static void * ip6_next_header(ip6_header_t *i)
Definition: ip6_packet.h:405
vlib_node_registration_t ip6_map_t_icmp_node
(constructor) VLIB_REGISTER_NODE (ip6_map_t_icmp_node)
Definition: ip6_map_t.c:727
static int ip6_to_ip4_set_inner_icmp_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
Definition: ip6_map_t.c:123
signed int i32
Definition: types.h:77
#define ip6_frag_hdr_offset(hdr)
Definition: ip6_packet.h:573
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:537
static ip_csum_t ip_csum_sub_even(ip_csum_t c, ip_csum_t x)
Definition: ip_packet.h:209
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:233
#define map_ip4_reass_unlock()
Definition: map.h:493
u8 * format_map_trace(u8 *s, va_list *args)
Definition: map.c:1303
IPv6 to IPv4 translation.
#define u8_ptr_add(ptr, index)
Definition: ip.h:68
#define VNET_FEATURES(...)
Definition: feature.h:435
static_always_inline void map_mss_clamping(tcp_header_t *tcp, ip_csum_t *sum, u16 mss_clamping)
Definition: map.h:614
u16 mtu
Definition: map.h:112
static uword ip6_map_t_fragmented(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_map_t.c:289
u16 payload_length
Definition: ip6_packet.h:369
static int map_ip6_to_ip4_fragmented(vlib_buffer_t *p)
Definition: ip6_map_t.c:242
i32 port
Definition: map.h:158
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
u16 tcp_mss
Definition: map.h:271
A collection of combined counters.
Definition: counter.h:188
static char * map_t_error_strings[]
Definition: ip6_map_t.c:699
vlib_node_registration_t ip6_map_t_node
(constructor) VLIB_REGISTER_NODE (ip6_map_t_node)
Definition: ip6_map_t.c:775
#define vnet_buffer(b)
Definition: buffer.h:368
#define u16_net_add(u, val)
Definition: ip.h:69
VNET_FEATURE_INIT(ip4_map_t_feature, static)
#define IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS
Definition: ip4_packet.h:194
u8 ip_version_and_header_length
Definition: ip4_packet.h:138
ip6_mapt_fragmented_next_t
Definition: ip6_map_t.c:46
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:237
static ip_csum_t ip_csum_add_even(ip_csum_t c, ip_csum_t x)
Definition: ip_packet.h:192
ip6_address_t dst_address
Definition: ip6_packet.h:378