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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "../ip/ip_frag.h"
19 #define IP6_MAP_T_DUAL_LOOP
23 IP6_MAPT_NEXT_MAPT_TCP_UDP,
24 IP6_MAPT_NEXT_MAPT_ICMP,
25 IP6_MAPT_NEXT_MAPT_FRAGMENTED,
32 IP6_MAPT_ICMP_NEXT_IP4_LOOKUP,
33 IP6_MAPT_ICMP_NEXT_IP4_FRAG,
34 IP6_MAPT_ICMP_NEXT_DROP,
36 } ip6_mapt_icmp_next_t;
40 IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP,
41 IP6_MAPT_TCP_UDP_NEXT_IP4_FRAG,
42 IP6_MAPT_TCP_UDP_NEXT_DROP,
43 IP6_MAPT_TCP_UDP_N_NEXT
44 } ip6_mapt_tcp_udp_next_t;
48 IP6_MAPT_FRAGMENTED_NEXT_IP4_LOOKUP,
49 IP6_MAPT_FRAGMENTED_NEXT_IP4_FRAG,
50 IP6_MAPT_FRAGMENTED_NEXT_DROP,
51 IP6_MAPT_FRAGMENTED_N_NEXT
52 } ip6_mapt_fragmented_next_t;
54 static_always_inline int
55 ip6_map_fragment_cache (ip6_header_t * ip6, ip6_frag_hdr_t * frag,
56 map_domain_t * d, u16 port)
59 map_ip4_reass_lock ();
60 map_ip4_reass_t *r = map_ip4_reass_get (map_get_ip4 (&ip6->src_address),
61 ip6_map_t_embedded_address (d,
64 frag_id_6to4 (frag->identification),
67 IP_PROTOCOL_ICMP : ip6->protocol,
72 map_ip4_reass_unlock ();
76 /* Returns the associated port or -1 */
77 static_always_inline i32
78 ip6_map_fragment_get (ip6_header_t * ip6, ip6_frag_hdr_t * frag,
82 map_ip4_reass_lock ();
83 map_ip4_reass_t *r = map_ip4_reass_get (map_get_ip4 (&ip6->src_address),
84 ip6_map_t_embedded_address (d,
87 frag_id_6to4 (frag->identification),
90 IP_PROTOCOL_ICMP : ip6->protocol,
92 i32 ret = r ? r->port : -1;
93 map_ip4_reass_unlock ();
97 static_always_inline u8
98 ip6_translate_tos (const ip6_header_t * ip6)
100 #ifdef IP6_MAP_T_OVERRIDE_TOS
101 return IP6_MAP_T_OVERRIDE_TOS;
103 return (clib_net_to_host_u32 (ip6->ip_version_traffic_class_and_flow_label)
108 //TODO: Find right place in memory for that
110 static u8 icmp6_to_icmp_updater_pointer_table[] =
124 static_always_inline int
125 ip6_icmp_to_icmp6_in_place (icmp46_header_t * icmp, u32 icmp_len,
126 i32 * sender_port, ip6_header_t ** inner_ip6)
131 case ICMP6_echo_request:
132 *sender_port = ((u16 *) icmp)[2];
133 icmp->type = ICMP4_echo_request;
135 case ICMP6_echo_reply:
136 *sender_port = ((u16 *) icmp)[2];
137 icmp->type = ICMP4_echo_reply;
139 case ICMP6_destination_unreachable:
140 *inner_ip6 = (ip6_header_t *) u8_ptr_add (icmp, 8);
141 *sender_port = ip6_get_port (*inner_ip6, MAP_RECEIVER, icmp_len);
145 case ICMP6_destination_unreachable_no_route_to_destination: //0
146 case ICMP6_destination_unreachable_beyond_scope_of_source_address: //2
147 case ICMP6_destination_unreachable_address_unreachable: //3
148 icmp->type = ICMP4_destination_unreachable;
150 ICMP4_destination_unreachable_destination_unreachable_host;
152 case ICMP6_destination_unreachable_destination_administratively_prohibited: //1
154 ICMP4_destination_unreachable;
156 ICMP4_destination_unreachable_communication_administratively_prohibited;
158 case ICMP6_destination_unreachable_port_unreachable:
159 icmp->type = ICMP4_destination_unreachable;
160 icmp->code = ICMP4_destination_unreachable_port_unreachable;
166 case ICMP6_packet_too_big:
167 *inner_ip6 = (ip6_header_t *) u8_ptr_add (icmp, 8);
168 *sender_port = ip6_get_port (*inner_ip6, MAP_RECEIVER, icmp_len);
170 icmp->type = ICMP4_destination_unreachable;
173 u32 advertised_mtu = clib_net_to_host_u32 (*((u32 *) (icmp + 1)));
174 advertised_mtu -= 20;
175 //FIXME: = minimum(advertised MTU-20, MTU_of_IPv4_nexthop, (MTU_of_IPv6_nexthop)-20)
176 ((u16 *) (icmp))[3] = clib_host_to_net_u16 (advertised_mtu);
180 case ICMP6_time_exceeded:
181 *inner_ip6 = (ip6_header_t *) u8_ptr_add (icmp, 8);
182 *sender_port = ip6_get_port (*inner_ip6, MAP_RECEIVER, icmp_len);
184 icmp->type = ICMP4_time_exceeded;
187 case ICMP6_parameter_problem:
188 *inner_ip6 = (ip6_header_t *) u8_ptr_add (icmp, 8);
189 *sender_port = ip6_get_port (*inner_ip6, MAP_RECEIVER, icmp_len);
193 case ICMP6_parameter_problem_erroneous_header_field:
194 icmp->type = ICMP4_parameter_problem;
195 icmp->code = ICMP4_parameter_problem_pointer_indicates_error;
196 u32 pointer = clib_net_to_host_u32 (*((u32 *) (icmp + 1)));
200 ((u8 *) (icmp + 1))[0] =
201 icmp6_to_icmp_updater_pointer_table[pointer];
203 case ICMP6_parameter_problem_unrecognized_next_header:
204 icmp->type = ICMP4_destination_unreachable;
205 icmp->code = ICMP4_destination_unreachable_port_unreachable;
207 case ICMP6_parameter_problem_unrecognized_option:
219 static_always_inline void
220 _ip6_map_t_icmp (map_domain_t * d, vlib_buffer_t * p, u8 * error)
222 ip6_header_t *ip6, *inner_ip6;
223 ip4_header_t *ip4, *inner_ip4;
225 icmp46_header_t *icmp;
228 u32 ip4_sadr, inner_ip4_dadr;
230 ip6 = vlib_buffer_get_current (p);
231 ip6_pay_len = clib_net_to_host_u16 (ip6->payload_length);
232 icmp = (icmp46_header_t *) (ip6 + 1);
233 ASSERT (ip6_pay_len + sizeof (*ip6) <= p->current_length);
235 if (ip6->protocol != IP_PROTOCOL_ICMP6)
237 //No extensions headers allowed here
239 *error = MAP_ERROR_MALFORMED;
243 //There are no fragmented ICMP messages, so no extension header for now
245 if (ip6_icmp_to_icmp6_in_place
246 (icmp, ip6_pay_len, &sender_port, &inner_ip6))
248 //TODO: In case of 1:1 mapping it is not necessary to have the sender port
249 *error = MAP_ERROR_ICMP;
255 // In case of 1:1 mapping, we don't care about the port
256 if (d->ea_bits_len == 0 && d->rules)
262 *error = MAP_ERROR_ICMP;
268 //Note that this prevents an intermediate IPv6 router from answering the request
269 ip4_sadr = map_get_ip4 (&ip6->src_address);
270 if (ip6->src_address.as_u64[0] != map_get_pfx_net (d, ip4_sadr, sender_port)
271 || ip6->src_address.as_u64[1] != map_get_sfx_net (d, ip4_sadr,
274 *error = MAP_ERROR_SEC_CHECK;
280 u16 *inner_L4_checksum, inner_l4_offset, inner_frag_offset,
282 u8 *inner_l4, inner_protocol;
284 //We have two headers to translate
286 // [ IPv6 ]<- ext ->[IC][ IPv6 ]<- ext ->[L4 header ...
288 // [ IPv6 ][IC][ IPv6 ][L4 header ...
289 // [ IPv6 ][IC][ IPv6 ][Fr][L4 header ...
291 // [ IPv4][IC][ IPv4][L4 header ...
293 //TODO: This was already done deep in ip6_icmp_to_icmp6_in_place
294 //We shouldn't have to do it again
295 if (ip6_parse (inner_ip6, ip6_pay_len - 8,
296 &inner_protocol, &inner_l4_offset, &inner_frag_offset))
298 *error = MAP_ERROR_MALFORMED;
302 inner_l4 = u8_ptr_add (inner_ip6, inner_l4_offset);
304 (ip4_header_t *) u8_ptr_add (inner_l4, -sizeof (*inner_ip4));
305 if (inner_frag_offset)
307 ip6_frag_hdr_t *inner_frag =
308 (ip6_frag_hdr_t *) u8_ptr_add (inner_ip6, inner_frag_offset);
309 inner_frag_id = frag_id_6to4 (inner_frag->identification);
316 //Do the translation of the inner packet
317 if (inner_protocol == IP_PROTOCOL_TCP)
319 inner_L4_checksum = (u16 *) u8_ptr_add (inner_l4, 16);
321 else if (inner_protocol == IP_PROTOCOL_UDP)
323 inner_L4_checksum = (u16 *) u8_ptr_add (inner_l4, 6);
325 else if (inner_protocol == IP_PROTOCOL_ICMP6)
327 icmp46_header_t *inner_icmp = (icmp46_header_t *) inner_l4;
328 csum = inner_icmp->checksum;
329 csum = ip_csum_sub_even (csum, *((u16 *) inner_icmp));
330 //It cannot be of a different type as ip6_icmp_to_icmp6_in_place succeeded
331 inner_icmp->type = (inner_icmp->type == ICMP6_echo_request) ?
332 ICMP4_echo_request : ICMP4_echo_reply;
333 csum = ip_csum_add_even (csum, *((u16 *) inner_icmp));
334 inner_icmp->checksum = ip_csum_fold (csum);
335 inner_protocol = IP_PROTOCOL_ICMP; //Will be copied to ip6 later
336 inner_L4_checksum = &inner_icmp->checksum;
340 *error = MAP_ERROR_BAD_PROTOCOL;
344 csum = *inner_L4_checksum;
345 csum = ip_csum_sub_even (csum, inner_ip6->src_address.as_u64[0]);
346 csum = ip_csum_sub_even (csum, inner_ip6->src_address.as_u64[1]);
347 csum = ip_csum_sub_even (csum, inner_ip6->dst_address.as_u64[0]);
348 csum = ip_csum_sub_even (csum, inner_ip6->dst_address.as_u64[1]);
350 //Sanity check of the outer destination address
351 if (ip6->dst_address.as_u64[0] != inner_ip6->src_address.as_u64[0] &&
352 ip6->dst_address.as_u64[1] != inner_ip6->src_address.as_u64[1])
354 *error = MAP_ERROR_SEC_CHECK;
358 //Security check of inner packet
359 inner_ip4_dadr = map_get_ip4 (&inner_ip6->dst_address);
360 if (inner_ip6->dst_address.as_u64[0] !=
361 map_get_pfx_net (d, inner_ip4_dadr, sender_port)
362 || inner_ip6->dst_address.as_u64[1] != map_get_sfx_net (d,
366 *error = MAP_ERROR_SEC_CHECK;
370 inner_ip4->dst_address.as_u32 = inner_ip4_dadr;
371 inner_ip4->src_address.as_u32 =
372 ip6_map_t_embedded_address (d, &inner_ip6->src_address);
373 inner_ip4->ip_version_and_header_length =
374 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
375 inner_ip4->tos = ip6_translate_tos (inner_ip6);
377 u16_net_add (inner_ip6->payload_length,
378 sizeof (*ip4) + sizeof (*ip6) - inner_l4_offset);
379 inner_ip4->fragment_id = inner_frag_id;
380 inner_ip4->flags_and_fragment_offset =
381 clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
382 inner_ip4->ttl = inner_ip6->hop_limit;
383 inner_ip4->protocol = inner_protocol;
384 inner_ip4->checksum = ip4_header_checksum (inner_ip4);
386 if (inner_ip4->protocol == IP_PROTOCOL_ICMP)
388 //Remove remainings of the pseudo-header in the csum
390 ip_csum_sub_even (csum, clib_host_to_net_u16 (IP_PROTOCOL_ICMP6));
392 ip_csum_sub_even (csum, inner_ip4->length - sizeof (*inner_ip4));
396 //Update to new pseudo-header
397 csum = ip_csum_add_even (csum, inner_ip4->src_address.as_u32);
398 csum = ip_csum_add_even (csum, inner_ip4->dst_address.as_u32);
400 *inner_L4_checksum = ip_csum_fold (csum);
402 //Move up icmp header
403 ip4 = (ip4_header_t *) u8_ptr_add (inner_l4, -2 * sizeof (*ip4) - 8);
404 clib_memcpy (u8_ptr_add (inner_l4, -sizeof (*ip4) - 8), icmp, 8);
405 icmp = (icmp46_header_t *) u8_ptr_add (inner_l4, -sizeof (*ip4) - 8);
409 //Only one header to translate
410 ip4 = (ip4_header_t *) u8_ptr_add (ip6, sizeof (*ip6) - sizeof (*ip4));
412 vlib_buffer_advance (p, (u32) (((u8 *) ip4) - ((u8 *) ip6)));
414 ip4->dst_address.as_u32 = ip6_map_t_embedded_address (d, &ip6->dst_address);
415 ip4->src_address.as_u32 = ip4_sadr;
416 ip4->ip_version_and_header_length =
417 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
418 ip4->tos = ip6_translate_tos (ip6);
419 ip4->fragment_id = 0;
420 ip4->flags_and_fragment_offset = 0;
421 ip4->ttl = ip6->hop_limit;
422 ip4->protocol = IP_PROTOCOL_ICMP;
423 //TODO fix the length depending on offset length
424 ip4->length = u16_net_add (ip6->payload_length,
426 NULL) ? sizeof (*ip4) : (2 * sizeof (*ip4) -
428 ip4->checksum = ip4_header_checksum (ip4);
430 //TODO: We could do an easy diff-checksum for echo requests/replies
431 //Recompute ICMP checksum
434 ip_incremental_checksum (0, icmp,
435 clib_net_to_host_u16 (ip4->length) -
437 icmp->checksum = ~ip_csum_fold (csum);
441 ip6_map_t_icmp (vlib_main_t * vm,
442 vlib_node_runtime_t * node, vlib_frame_t * frame)
444 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
445 vlib_node_runtime_t *error_node =
446 vlib_node_get_runtime (vm, ip6_map_t_icmp_node.index);
447 from = vlib_frame_vector_args (frame);
448 n_left_from = frame->n_vectors;
449 next_index = node->cached_next_index;
450 vlib_combined_counter_main_t *cm = map_main.domain_counters;
451 u32 thread_index = vlib_get_thread_index ();
453 while (n_left_from > 0)
455 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
457 while (n_left_from > 0 && n_left_to_next > 0)
462 ip6_mapt_icmp_next_t next0;
466 pi0 = to_next[0] = from[0];
471 error0 = MAP_ERROR_NONE;
472 next0 = IP6_MAPT_ICMP_NEXT_IP4_LOOKUP;
474 p0 = vlib_get_buffer (vm, pi0);
476 clib_net_to_host_u16 (((ip6_header_t *)
477 vlib_buffer_get_current
478 (p0))->payload_length);
480 pool_elt_at_index (map_main.domains,
481 vnet_buffer (p0)->map_t.map_domain_index);
482 _ip6_map_t_icmp (d0, p0, &error0);
484 if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
486 //Send to fragmentation node if necessary
487 vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
488 vnet_buffer (p0)->ip_frag.header_offset = 0;
489 vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
490 next0 = IP6_MAPT_ICMP_NEXT_IP4_FRAG;
493 if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
495 vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
498 map_t.map_domain_index, 1,
503 next0 = IP6_MAPT_ICMP_NEXT_DROP;
506 p0->error = error_node->errors[error0];
507 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
508 to_next, n_left_to_next, pi0,
511 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
513 return frame->n_vectors;
517 ip6_map_t_fragmented (vlib_main_t * vm,
518 vlib_node_runtime_t * node, vlib_frame_t * frame)
520 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
521 from = vlib_frame_vector_args (frame);
522 n_left_from = frame->n_vectors;
523 next_index = node->cached_next_index;
525 while (n_left_from > 0)
527 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
529 #ifdef IP6_MAP_T_DUAL_LOOP
530 while (n_left_from >= 4 && n_left_to_next >= 2)
533 vlib_buffer_t *p0, *p1;
534 ip6_header_t *ip60, *ip61;
535 ip6_frag_hdr_t *frag0, *frag1;
536 ip4_header_t *ip40, *ip41;
537 u16 frag_id0, frag_offset0, frag_id1, frag_offset1;
538 u8 frag_more0, frag_more1;
541 pi0 = to_next[0] = from[0];
542 pi1 = to_next[1] = from[1];
548 next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
549 next1 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
550 p0 = vlib_get_buffer (vm, pi0);
551 p1 = vlib_get_buffer (vm, pi1);
552 ip60 = vlib_buffer_get_current (p0);
553 ip61 = vlib_buffer_get_current (p1);
555 (ip6_frag_hdr_t *) u8_ptr_add (ip60,
556 vnet_buffer (p0)->map_t.
559 (ip6_frag_hdr_t *) u8_ptr_add (ip61,
560 vnet_buffer (p1)->map_t.
563 (ip4_header_t *) u8_ptr_add (ip60,
564 vnet_buffer (p0)->map_t.
565 v6.l4_offset - sizeof (*ip40));
567 (ip4_header_t *) u8_ptr_add (ip61,
568 vnet_buffer (p1)->map_t.
569 v6.l4_offset - sizeof (*ip40));
570 vlib_buffer_advance (p0,
571 vnet_buffer (p0)->map_t.v6.l4_offset -
573 vlib_buffer_advance (p1,
574 vnet_buffer (p1)->map_t.v6.l4_offset -
577 frag_id0 = frag_id_6to4 (frag0->identification);
578 frag_id1 = frag_id_6to4 (frag1->identification);
579 frag_more0 = ip6_frag_hdr_more (frag0);
580 frag_more1 = ip6_frag_hdr_more (frag1);
581 frag_offset0 = ip6_frag_hdr_offset (frag0);
582 frag_offset1 = ip6_frag_hdr_offset (frag1);
584 ip40->dst_address.as_u32 = vnet_buffer (p0)->map_t.v6.daddr;
585 ip41->dst_address.as_u32 = vnet_buffer (p1)->map_t.v6.daddr;
586 ip40->src_address.as_u32 = vnet_buffer (p0)->map_t.v6.saddr;
587 ip41->src_address.as_u32 = vnet_buffer (p1)->map_t.v6.saddr;
588 ip40->ip_version_and_header_length =
589 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
590 ip41->ip_version_and_header_length =
591 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
592 ip40->tos = ip6_translate_tos (ip60);
593 ip41->tos = ip6_translate_tos (ip61);
594 ip40->length = u16_net_add (ip60->payload_length,
596 vnet_buffer (p0)->map_t.v6.l4_offset +
599 u16_net_add (ip61->payload_length,
601 vnet_buffer (p1)->map_t.v6.l4_offset +
603 ip40->fragment_id = frag_id0;
604 ip41->fragment_id = frag_id1;
605 ip40->flags_and_fragment_offset =
606 clib_host_to_net_u16 (frag_offset0 |
607 (frag_more0 ? IP4_HEADER_FLAG_MORE_FRAGMENTS
609 ip41->flags_and_fragment_offset =
610 clib_host_to_net_u16 (frag_offset1 |
611 (frag_more1 ? IP4_HEADER_FLAG_MORE_FRAGMENTS
613 ip40->ttl = ip60->hop_limit;
614 ip41->ttl = ip61->hop_limit;
616 (vnet_buffer (p0)->map_t.v6.l4_protocol ==
617 IP_PROTOCOL_ICMP6) ? IP_PROTOCOL_ICMP : vnet_buffer (p0)->
618 map_t.v6.l4_protocol;
620 (vnet_buffer (p1)->map_t.v6.l4_protocol ==
621 IP_PROTOCOL_ICMP6) ? IP_PROTOCOL_ICMP : vnet_buffer (p1)->
622 map_t.v6.l4_protocol;
623 ip40->checksum = ip4_header_checksum (ip40);
624 ip41->checksum = ip4_header_checksum (ip41);
626 if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
628 vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
629 vnet_buffer (p0)->ip_frag.header_offset = 0;
630 vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
631 next0 = IP6_MAPT_FRAGMENTED_NEXT_IP4_FRAG;
634 if (vnet_buffer (p1)->map_t.mtu < p1->current_length)
636 vnet_buffer (p1)->ip_frag.mtu = vnet_buffer (p1)->map_t.mtu;
637 vnet_buffer (p1)->ip_frag.header_offset = 0;
638 vnet_buffer (p1)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
639 next1 = IP6_MAPT_FRAGMENTED_NEXT_IP4_FRAG;
642 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
643 to_next, n_left_to_next, pi0, pi1,
648 while (n_left_from > 0 && n_left_to_next > 0)
653 ip6_frag_hdr_t *frag0;
660 pi0 = to_next[0] = from[0];
666 next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
667 p0 = vlib_get_buffer (vm, pi0);
668 ip60 = vlib_buffer_get_current (p0);
670 (ip6_frag_hdr_t *) u8_ptr_add (ip60,
671 vnet_buffer (p0)->map_t.
674 (ip4_header_t *) u8_ptr_add (ip60,
675 vnet_buffer (p0)->map_t.
676 v6.l4_offset - sizeof (*ip40));
677 vlib_buffer_advance (p0,
678 vnet_buffer (p0)->map_t.v6.l4_offset -
681 frag_id0 = frag_id_6to4 (frag0->identification);
682 frag_more0 = ip6_frag_hdr_more (frag0);
683 frag_offset0 = ip6_frag_hdr_offset (frag0);
685 ip40->dst_address.as_u32 = vnet_buffer (p0)->map_t.v6.daddr;
686 ip40->src_address.as_u32 = vnet_buffer (p0)->map_t.v6.saddr;
687 ip40->ip_version_and_header_length =
688 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
689 ip40->tos = ip6_translate_tos (ip60);
690 ip40->length = u16_net_add (ip60->payload_length,
692 vnet_buffer (p0)->map_t.v6.l4_offset +
694 ip40->fragment_id = frag_id0;
695 ip40->flags_and_fragment_offset =
696 clib_host_to_net_u16 (frag_offset0 |
697 (frag_more0 ? IP4_HEADER_FLAG_MORE_FRAGMENTS
699 ip40->ttl = ip60->hop_limit;
701 (vnet_buffer (p0)->map_t.v6.l4_protocol ==
702 IP_PROTOCOL_ICMP6) ? IP_PROTOCOL_ICMP : vnet_buffer (p0)->
703 map_t.v6.l4_protocol;
704 ip40->checksum = ip4_header_checksum (ip40);
706 if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
708 //Send to fragmentation node if necessary
709 vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
710 vnet_buffer (p0)->ip_frag.header_offset = 0;
711 vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
712 next0 = IP6_MAPT_FRAGMENTED_NEXT_IP4_FRAG;
715 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
716 to_next, n_left_to_next, pi0,
719 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
721 return frame->n_vectors;
725 ip6_map_t_tcp_udp (vlib_main_t * vm,
726 vlib_node_runtime_t * node, vlib_frame_t * frame)
728 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
729 from = vlib_frame_vector_args (frame);
730 n_left_from = frame->n_vectors;
731 next_index = node->cached_next_index;
732 while (n_left_from > 0)
734 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
736 #ifdef IP6_MAP_T_DUAL_LOOP
737 while (n_left_from >= 4 && n_left_to_next >= 2)
740 vlib_buffer_t *p0, *p1;
741 ip6_header_t *ip60, *ip61;
742 ip_csum_t csum0, csum1;
743 ip4_header_t *ip40, *ip41;
744 u16 fragment_id0, flags0, *checksum0,
745 fragment_id1, flags1, *checksum1;
746 ip6_mapt_tcp_udp_next_t next0, next1;
748 pi0 = to_next[0] = from[0];
749 pi1 = to_next[1] = from[1];
754 next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
755 next1 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
757 p0 = vlib_get_buffer (vm, pi0);
758 p1 = vlib_get_buffer (vm, pi1);
759 ip60 = vlib_buffer_get_current (p0);
760 ip61 = vlib_buffer_get_current (p1);
762 (ip4_header_t *) u8_ptr_add (ip60,
763 vnet_buffer (p0)->map_t.
764 v6.l4_offset - sizeof (*ip40));
766 (ip4_header_t *) u8_ptr_add (ip61,
767 vnet_buffer (p1)->map_t.
768 v6.l4_offset - sizeof (*ip40));
769 vlib_buffer_advance (p0,
770 vnet_buffer (p0)->map_t.v6.l4_offset -
772 vlib_buffer_advance (p1,
773 vnet_buffer (p1)->map_t.v6.l4_offset -
776 (u16 *) u8_ptr_add (ip60,
777 vnet_buffer (p0)->map_t.checksum_offset);
779 (u16 *) u8_ptr_add (ip61,
780 vnet_buffer (p1)->map_t.checksum_offset);
782 csum0 = ip_csum_sub_even (*checksum0, ip60->src_address.as_u64[0]);
783 csum1 = ip_csum_sub_even (*checksum1, ip61->src_address.as_u64[0]);
784 csum0 = ip_csum_sub_even (csum0, ip60->src_address.as_u64[1]);
785 csum1 = ip_csum_sub_even (csum1, ip61->src_address.as_u64[1]);
786 csum0 = ip_csum_sub_even (csum0, ip60->dst_address.as_u64[0]);
787 csum1 = ip_csum_sub_even (csum0, ip61->dst_address.as_u64[0]);
788 csum0 = ip_csum_sub_even (csum0, ip60->dst_address.as_u64[1]);
789 csum1 = ip_csum_sub_even (csum1, ip61->dst_address.as_u64[1]);
790 csum0 = ip_csum_add_even (csum0, vnet_buffer (p0)->map_t.v6.daddr);
791 csum1 = ip_csum_add_even (csum1, vnet_buffer (p1)->map_t.v6.daddr);
792 csum0 = ip_csum_add_even (csum0, vnet_buffer (p0)->map_t.v6.saddr);
793 csum1 = ip_csum_add_even (csum1, vnet_buffer (p1)->map_t.v6.saddr);
794 *checksum0 = ip_csum_fold (csum0);
795 *checksum1 = ip_csum_fold (csum1);
797 if (PREDICT_FALSE (vnet_buffer (p0)->map_t.v6.frag_offset))
799 ip6_frag_hdr_t *hdr = (ip6_frag_hdr_t *) u8_ptr_add (ip60,
804 fragment_id0 = frag_id_6to4 (hdr->identification);
805 flags0 = clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
813 if (PREDICT_FALSE (vnet_buffer (p1)->map_t.v6.frag_offset))
815 ip6_frag_hdr_t *hdr = (ip6_frag_hdr_t *) u8_ptr_add (ip61,
820 fragment_id1 = frag_id_6to4 (hdr->identification);
821 flags1 = clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
829 ip40->dst_address.as_u32 = vnet_buffer (p0)->map_t.v6.daddr;
830 ip41->dst_address.as_u32 = vnet_buffer (p1)->map_t.v6.daddr;
831 ip40->src_address.as_u32 = vnet_buffer (p0)->map_t.v6.saddr;
832 ip41->src_address.as_u32 = vnet_buffer (p1)->map_t.v6.saddr;
833 ip40->ip_version_and_header_length =
834 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
835 ip41->ip_version_and_header_length =
836 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
837 ip40->tos = ip6_translate_tos (ip60);
838 ip41->tos = ip6_translate_tos (ip61);
839 ip40->length = u16_net_add (ip60->payload_length,
840 sizeof (*ip40) + sizeof (*ip60) -
841 vnet_buffer (p0)->map_t.v6.l4_offset);
843 u16_net_add (ip61->payload_length,
844 sizeof (*ip40) + sizeof (*ip60) -
845 vnet_buffer (p1)->map_t.v6.l4_offset);
846 ip40->fragment_id = fragment_id0;
847 ip41->fragment_id = fragment_id1;
848 ip40->flags_and_fragment_offset = flags0;
849 ip41->flags_and_fragment_offset = flags1;
850 ip40->ttl = ip60->hop_limit;
851 ip41->ttl = ip61->hop_limit;
852 ip40->protocol = vnet_buffer (p0)->map_t.v6.l4_protocol;
853 ip41->protocol = vnet_buffer (p1)->map_t.v6.l4_protocol;
854 ip40->checksum = ip4_header_checksum (ip40);
855 ip41->checksum = ip4_header_checksum (ip41);
857 if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
859 vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
860 vnet_buffer (p0)->ip_frag.header_offset = 0;
861 vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
862 next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_FRAG;
865 if (vnet_buffer (p1)->map_t.mtu < p1->current_length)
867 vnet_buffer (p1)->ip_frag.mtu = vnet_buffer (p1)->map_t.mtu;
868 vnet_buffer (p1)->ip_frag.header_offset = 0;
869 vnet_buffer (p1)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
870 next1 = IP6_MAPT_TCP_UDP_NEXT_IP4_FRAG;
873 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
874 n_left_to_next, pi0, pi1, next0,
879 while (n_left_from > 0 && n_left_to_next > 0)
889 ip6_mapt_tcp_udp_next_t next0;
891 pi0 = to_next[0] = from[0];
896 next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
898 p0 = vlib_get_buffer (vm, pi0);
899 ip60 = vlib_buffer_get_current (p0);
901 (ip4_header_t *) u8_ptr_add (ip60,
902 vnet_buffer (p0)->map_t.
903 v6.l4_offset - sizeof (*ip40));
904 vlib_buffer_advance (p0,
905 vnet_buffer (p0)->map_t.v6.l4_offset -
908 (u16 *) u8_ptr_add (ip60,
909 vnet_buffer (p0)->map_t.checksum_offset);
911 //TODO: This can probably be optimized
912 csum0 = ip_csum_sub_even (*checksum0, ip60->src_address.as_u64[0]);
913 csum0 = ip_csum_sub_even (csum0, ip60->src_address.as_u64[1]);
914 csum0 = ip_csum_sub_even (csum0, ip60->dst_address.as_u64[0]);
915 csum0 = ip_csum_sub_even (csum0, ip60->dst_address.as_u64[1]);
916 csum0 = ip_csum_add_even (csum0, vnet_buffer (p0)->map_t.v6.daddr);
917 csum0 = ip_csum_add_even (csum0, vnet_buffer (p0)->map_t.v6.saddr);
918 *checksum0 = ip_csum_fold (csum0);
920 if (PREDICT_FALSE (vnet_buffer (p0)->map_t.v6.frag_offset))
922 //Only the first fragment
923 ip6_frag_hdr_t *hdr = (ip6_frag_hdr_t *) u8_ptr_add (ip60,
928 fragment_id0 = frag_id_6to4 (hdr->identification);
929 flags0 = clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
937 ip40->dst_address.as_u32 = vnet_buffer (p0)->map_t.v6.daddr;
938 ip40->src_address.as_u32 = vnet_buffer (p0)->map_t.v6.saddr;
939 ip40->ip_version_and_header_length =
940 IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
941 ip40->tos = ip6_translate_tos (ip60);
942 ip40->length = u16_net_add (ip60->payload_length,
943 sizeof (*ip40) + sizeof (*ip60) -
944 vnet_buffer (p0)->map_t.v6.l4_offset);
945 ip40->fragment_id = fragment_id0;
946 ip40->flags_and_fragment_offset = flags0;
947 ip40->ttl = ip60->hop_limit;
948 ip40->protocol = vnet_buffer (p0)->map_t.v6.l4_protocol;
949 ip40->checksum = ip4_header_checksum (ip40);
951 if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
953 //Send to fragmentation node if necessary
954 vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
955 vnet_buffer (p0)->ip_frag.header_offset = 0;
956 vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
957 next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_FRAG;
960 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
961 to_next, n_left_to_next, pi0,
964 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
966 return frame->n_vectors;
969 static_always_inline void
970 ip6_map_t_classify (vlib_buffer_t * p0, ip6_header_t * ip60,
971 map_domain_t * d0, i32 * src_port0,
972 u8 * error0, ip6_mapt_next_t * next0,
973 u32 l4_len0, ip6_frag_hdr_t * frag0)
975 if (PREDICT_FALSE (vnet_buffer (p0)->map_t.v6.frag_offset &&
976 ip6_frag_hdr_offset (frag0)))
978 *next0 = IP6_MAPT_NEXT_MAPT_FRAGMENTED;
979 if (d0->ea_bits_len == 0 && d0->rules)
985 *src_port0 = ip6_map_fragment_get (ip60, frag0, d0);
986 *error0 = (*src_port0 != -1) ? *error0 : MAP_ERROR_FRAGMENT_DROPPED;
991 (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_TCP))
994 l4_len0 < sizeof (tcp_header_t) ? MAP_ERROR_MALFORMED : *error0;
995 vnet_buffer (p0)->map_t.checksum_offset =
996 vnet_buffer (p0)->map_t.v6.l4_offset + 16;
997 *next0 = IP6_MAPT_NEXT_MAPT_TCP_UDP;
1000 ((u16 *) u8_ptr_add (ip60, vnet_buffer (p0)->map_t.v6.l4_offset));
1004 (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_UDP))
1007 l4_len0 < sizeof (udp_header_t) ? MAP_ERROR_MALFORMED : *error0;
1008 vnet_buffer (p0)->map_t.checksum_offset =
1009 vnet_buffer (p0)->map_t.v6.l4_offset + 6;
1010 *next0 = IP6_MAPT_NEXT_MAPT_TCP_UDP;
1013 ((u16 *) u8_ptr_add (ip60, vnet_buffer (p0)->map_t.v6.l4_offset));
1015 else if (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_ICMP6)
1018 l4_len0 < sizeof (icmp46_header_t) ? MAP_ERROR_MALFORMED : *error0;
1019 *next0 = IP6_MAPT_NEXT_MAPT_ICMP;
1020 if (d0->ea_bits_len == 0 && d0->rules)
1025 if (((icmp46_header_t *)
1027 vnet_buffer (p0)->map_t.v6.l4_offset))->code ==
1029 || ((icmp46_header_t *)
1031 vnet_buffer (p0)->map_t.v6.l4_offset))->code ==
1037 u8_ptr_add (ip60, vnet_buffer (p0)->map_t.v6.l4_offset + 6));
1042 //TODO: In case of 1:1 mapping, it might be possible to do something with those packets.
1043 *error0 = MAP_ERROR_BAD_PROTOCOL;
1048 ip6_map_t (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
1050 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
1051 vlib_node_runtime_t *error_node =
1052 vlib_node_get_runtime (vm, ip6_map_t_node.index);
1053 vlib_combined_counter_main_t *cm = map_main.domain_counters;
1054 u32 thread_index = vlib_get_thread_index ();
1056 from = vlib_frame_vector_args (frame);
1057 n_left_from = frame->n_vectors;
1058 next_index = node->cached_next_index;
1059 while (n_left_from > 0)
1061 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1063 #ifdef IP6_MAP_T_DUAL_LOOP
1064 while (n_left_from >= 4 && n_left_to_next >= 2)
1067 vlib_buffer_t *p0, *p1;
1068 ip6_header_t *ip60, *ip61;
1070 ip6_mapt_next_t next0, next1;
1071 u32 l4_len0, l4_len1;
1072 i32 src_port0, src_port1;
1073 map_domain_t *d0, *d1;
1074 ip6_frag_hdr_t *frag0, *frag1;
1076 next0 = next1 = 0; //Because compiler whines
1078 pi0 = to_next[0] = from[0];
1079 pi1 = to_next[1] = from[1];
1083 n_left_to_next -= 2;
1085 error0 = MAP_ERROR_NONE;
1086 error1 = MAP_ERROR_NONE;
1088 p0 = vlib_get_buffer (vm, pi0);
1089 p1 = vlib_get_buffer (vm, pi1);
1090 ip60 = vlib_buffer_get_current (p0);
1091 ip61 = vlib_buffer_get_current (p1);
1093 saddr0 = map_get_ip4 (&ip60->src_address);
1094 saddr1 = map_get_ip4 (&ip61->src_address);
1095 d0 = ip6_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
1096 (ip4_address_t *) & saddr0,
1097 &vnet_buffer (p0)->map_t.map_domain_index,
1100 ip6_map_get_domain (vnet_buffer (p1)->ip.adj_index[VLIB_TX],
1101 (ip4_address_t *) & saddr1,
1102 &vnet_buffer (p1)->map_t.map_domain_index,
1105 vnet_buffer (p0)->map_t.v6.saddr = saddr0;
1106 vnet_buffer (p1)->map_t.v6.saddr = saddr1;
1107 vnet_buffer (p0)->map_t.v6.daddr =
1108 ip6_map_t_embedded_address (d0, &ip60->dst_address);
1109 vnet_buffer (p1)->map_t.v6.daddr =
1110 ip6_map_t_embedded_address (d1, &ip61->dst_address);
1111 vnet_buffer (p0)->map_t.mtu = d0->mtu ? d0->mtu : ~0;
1112 vnet_buffer (p1)->map_t.mtu = d1->mtu ? d1->mtu : ~0;
1114 if (PREDICT_FALSE (ip6_parse (ip60, p0->current_length,
1115 &(vnet_buffer (p0)->map_t.
1117 &(vnet_buffer (p0)->map_t.
1119 &(vnet_buffer (p0)->map_t.
1122 error0 = MAP_ERROR_MALFORMED;
1123 next0 = IP6_MAPT_NEXT_DROP;
1126 if (PREDICT_FALSE (ip6_parse (ip61, p1->current_length,
1127 &(vnet_buffer (p1)->map_t.
1129 &(vnet_buffer (p1)->map_t.
1131 &(vnet_buffer (p1)->map_t.
1134 error1 = MAP_ERROR_MALFORMED;
1135 next1 = IP6_MAPT_NEXT_DROP;
1138 src_port0 = src_port1 = -1;
1139 l4_len0 = (u32) clib_net_to_host_u16 (ip60->payload_length) +
1140 sizeof (*ip60) - vnet_buffer (p0)->map_t.v6.l4_offset;
1141 l4_len1 = (u32) clib_net_to_host_u16 (ip61->payload_length) +
1142 sizeof (*ip60) - vnet_buffer (p1)->map_t.v6.l4_offset;
1144 (ip6_frag_hdr_t *) u8_ptr_add (ip60,
1145 vnet_buffer (p0)->map_t.
1148 (ip6_frag_hdr_t *) u8_ptr_add (ip61,
1149 vnet_buffer (p1)->map_t.
1152 ip6_map_t_classify (p0, ip60, d0, &src_port0, &error0, &next0,
1154 ip6_map_t_classify (p1, ip61, d1, &src_port1, &error1, &next1,
1159 && (ip60->src_address.as_u64[0] !=
1160 map_get_pfx_net (d0, vnet_buffer (p0)->map_t.v6.saddr,
1162 || ip60->src_address.as_u64[1] != map_get_sfx_net (d0,
1164 (p0)->map_t.v6.saddr,
1167 error0 = MAP_ERROR_SEC_CHECK;
1172 && (ip61->src_address.as_u64[0] !=
1173 map_get_pfx_net (d1, vnet_buffer (p1)->map_t.v6.saddr,
1175 || ip61->src_address.as_u64[1] != map_get_sfx_net (d1,
1177 (p1)->map_t.v6.saddr,
1180 error1 = MAP_ERROR_SEC_CHECK;
1183 if (PREDICT_FALSE (vnet_buffer (p0)->map_t.v6.frag_offset &&
1184 !ip6_frag_hdr_offset ((ip6_frag_hdr_t *)
1189 && (src_port0 != -1) && (d0->ea_bits_len != 0 || !d0->rules)
1190 && (error0 == MAP_ERROR_NONE))
1192 ip6_map_fragment_cache (ip60,
1193 (ip6_frag_hdr_t *) u8_ptr_add (ip60,
1200 if (PREDICT_FALSE (vnet_buffer (p1)->map_t.v6.frag_offset &&
1201 !ip6_frag_hdr_offset ((ip6_frag_hdr_t *)
1206 && (src_port1 != -1) && (d1->ea_bits_len != 0 || !d1->rules)
1207 && (error1 == MAP_ERROR_NONE))
1209 ip6_map_fragment_cache (ip61,
1210 (ip6_frag_hdr_t *) u8_ptr_add (ip61,
1218 (error0 == MAP_ERROR_NONE && next0 != IP6_MAPT_NEXT_MAPT_ICMP))
1220 vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
1223 map_t.map_domain_index, 1,
1224 clib_net_to_host_u16
1225 (ip60->payload_length));
1229 (error1 == MAP_ERROR_NONE && next1 != IP6_MAPT_NEXT_MAPT_ICMP))
1231 vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
1234 map_t.map_domain_index, 1,
1235 clib_net_to_host_u16
1236 (ip61->payload_length));
1239 next0 = (error0 != MAP_ERROR_NONE) ? IP6_MAPT_NEXT_DROP : next0;
1240 next1 = (error1 != MAP_ERROR_NONE) ? IP6_MAPT_NEXT_DROP : next1;
1241 p0->error = error_node->errors[error0];
1242 p1->error = error_node->errors[error1];
1243 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
1244 n_left_to_next, pi0, pi1, next0,
1249 while (n_left_from > 0 && n_left_to_next > 0)
1258 ip6_frag_hdr_t *frag0;
1259 ip6_mapt_next_t next0 = 0;
1262 pi0 = to_next[0] = from[0];
1266 n_left_to_next -= 1;
1267 error0 = MAP_ERROR_NONE;
1269 p0 = vlib_get_buffer (vm, pi0);
1270 ip60 = vlib_buffer_get_current (p0);
1271 //Save saddr in a different variable to not overwrite ip.adj_index
1272 saddr = map_get_ip4 (&ip60->src_address);
1273 d0 = ip6_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
1274 (ip4_address_t *) & saddr,
1275 &vnet_buffer (p0)->map_t.map_domain_index,
1278 //FIXME: What if d0 is null
1279 vnet_buffer (p0)->map_t.v6.saddr = saddr;
1280 vnet_buffer (p0)->map_t.v6.daddr =
1281 ip6_map_t_embedded_address (d0, &ip60->dst_address);
1282 vnet_buffer (p0)->map_t.mtu = d0->mtu ? d0->mtu : ~0;
1284 if (PREDICT_FALSE (ip6_parse (ip60, p0->current_length,
1285 &(vnet_buffer (p0)->map_t.
1287 &(vnet_buffer (p0)->map_t.
1289 &(vnet_buffer (p0)->map_t.
1292 error0 = MAP_ERROR_MALFORMED;
1293 next0 = IP6_MAPT_NEXT_DROP;
1297 l4_len0 = (u32) clib_net_to_host_u16 (ip60->payload_length) +
1298 sizeof (*ip60) - vnet_buffer (p0)->map_t.v6.l4_offset;
1300 (ip6_frag_hdr_t *) u8_ptr_add (ip60,
1301 vnet_buffer (p0)->map_t.
1305 if (PREDICT_FALSE (vnet_buffer (p0)->map_t.v6.frag_offset &&
1306 ip6_frag_hdr_offset (frag0)))
1308 src_port0 = ip6_map_fragment_get (ip60, frag0, d0);
1309 error0 = (src_port0 != -1) ? error0 : MAP_ERROR_FRAGMENT_MEMORY;
1310 next0 = IP6_MAPT_NEXT_MAPT_FRAGMENTED;
1314 (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_TCP))
1318 sizeof (tcp_header_t) ? MAP_ERROR_MALFORMED : error0;
1319 vnet_buffer (p0)->map_t.checksum_offset =
1320 vnet_buffer (p0)->map_t.v6.l4_offset + 16;
1321 next0 = IP6_MAPT_NEXT_MAPT_TCP_UDP;
1325 u8_ptr_add (ip60, vnet_buffer (p0)->map_t.v6.l4_offset));
1329 (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_UDP))
1333 sizeof (udp_header_t) ? MAP_ERROR_MALFORMED : error0;
1334 vnet_buffer (p0)->map_t.checksum_offset =
1335 vnet_buffer (p0)->map_t.v6.l4_offset + 6;
1336 next0 = IP6_MAPT_NEXT_MAPT_TCP_UDP;
1340 u8_ptr_add (ip60, vnet_buffer (p0)->map_t.v6.l4_offset));
1342 else if (vnet_buffer (p0)->map_t.v6.l4_protocol ==
1347 sizeof (icmp46_header_t) ? MAP_ERROR_MALFORMED : error0;
1348 next0 = IP6_MAPT_NEXT_MAPT_ICMP;
1349 if (((icmp46_header_t *)
1351 vnet_buffer (p0)->map_t.v6.l4_offset))->code ==
1353 || ((icmp46_header_t *)
1355 vnet_buffer (p0)->map_t.v6.
1356 l4_offset))->code == ICMP6_echo_request)
1361 vnet_buffer (p0)->map_t.v6.l4_offset + 6));
1365 //TODO: In case of 1:1 mapping, it might be possible to do something with those packets.
1366 error0 = MAP_ERROR_BAD_PROTOCOL;
1372 && (ip60->src_address.as_u64[0] !=
1373 map_get_pfx_net (d0, vnet_buffer (p0)->map_t.v6.saddr,
1375 || ip60->src_address.as_u64[1] != map_get_sfx_net (d0,
1377 (p0)->map_t.v6.saddr,
1380 //Security check when src_port0 is not zero (non-first fragment, UDP or TCP)
1381 error0 = MAP_ERROR_SEC_CHECK;
1384 //Fragmented first packet needs to be cached for following packets
1385 if (PREDICT_FALSE (vnet_buffer (p0)->map_t.v6.frag_offset &&
1386 !ip6_frag_hdr_offset ((ip6_frag_hdr_t *)
1391 && (src_port0 != -1) && (d0->ea_bits_len != 0 || !d0->rules)
1392 && (error0 == MAP_ERROR_NONE))
1394 ip6_map_fragment_cache (ip60,
1395 (ip6_frag_hdr_t *) u8_ptr_add (ip60,
1403 (error0 == MAP_ERROR_NONE && next0 != IP6_MAPT_NEXT_MAPT_ICMP))
1405 vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
1408 map_t.map_domain_index, 1,
1409 clib_net_to_host_u16
1410 (ip60->payload_length));
1413 next0 = (error0 != MAP_ERROR_NONE) ? IP6_MAPT_NEXT_DROP : next0;
1414 p0->error = error_node->errors[error0];
1415 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1416 to_next, n_left_to_next, pi0,
1419 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1421 return frame->n_vectors;
1424 static char *map_t_error_strings[] = {
1425 #define _(sym,string) string,
1431 VLIB_REGISTER_NODE(ip6_map_t_fragmented_node) = {
1432 .function = ip6_map_t_fragmented,
1433 .name = "ip6-map-t-fragmented",
1434 .vector_size = sizeof (u32),
1435 .format_trace = format_map_trace,
1436 .type = VLIB_NODE_TYPE_INTERNAL,
1438 .n_errors = MAP_N_ERROR,
1439 .error_strings = map_t_error_strings,
1441 .n_next_nodes = IP6_MAPT_FRAGMENTED_N_NEXT,
1443 [IP6_MAPT_FRAGMENTED_NEXT_IP4_LOOKUP] = "ip4-lookup",
1444 [IP6_MAPT_FRAGMENTED_NEXT_IP4_FRAG] = IP4_FRAG_NODE_NAME,
1445 [IP6_MAPT_FRAGMENTED_NEXT_DROP] = "error-drop",
1451 VLIB_REGISTER_NODE(ip6_map_t_icmp_node) = {
1452 .function = ip6_map_t_icmp,
1453 .name = "ip6-map-t-icmp",
1454 .vector_size = sizeof (u32),
1455 .format_trace = format_map_trace,
1456 .type = VLIB_NODE_TYPE_INTERNAL,
1458 .n_errors = MAP_N_ERROR,
1459 .error_strings = map_t_error_strings,
1461 .n_next_nodes = IP6_MAPT_ICMP_N_NEXT,
1463 [IP6_MAPT_ICMP_NEXT_IP4_LOOKUP] = "ip4-lookup",
1464 [IP6_MAPT_ICMP_NEXT_IP4_FRAG] = IP4_FRAG_NODE_NAME,
1465 [IP6_MAPT_ICMP_NEXT_DROP] = "error-drop",
1471 VLIB_REGISTER_NODE(ip6_map_t_tcp_udp_node) = {
1472 .function = ip6_map_t_tcp_udp,
1473 .name = "ip6-map-t-tcp-udp",
1474 .vector_size = sizeof (u32),
1475 .format_trace = format_map_trace,
1476 .type = VLIB_NODE_TYPE_INTERNAL,
1478 .n_errors = MAP_N_ERROR,
1479 .error_strings = map_t_error_strings,
1481 .n_next_nodes = IP6_MAPT_TCP_UDP_N_NEXT,
1483 [IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP] = "ip4-lookup",
1484 [IP6_MAPT_TCP_UDP_NEXT_IP4_FRAG] = IP4_FRAG_NODE_NAME,
1485 [IP6_MAPT_TCP_UDP_NEXT_DROP] = "error-drop",
1491 VLIB_REGISTER_NODE(ip6_map_t_node) = {
1492 .function = ip6_map_t,
1493 .name = "ip6-map-t",
1494 .vector_size = sizeof(u32),
1495 .format_trace = format_map_trace,
1496 .type = VLIB_NODE_TYPE_INTERNAL,
1498 .n_errors = MAP_N_ERROR,
1499 .error_strings = map_t_error_strings,
1501 .n_next_nodes = IP6_MAPT_N_NEXT,
1503 [IP6_MAPT_NEXT_MAPT_TCP_UDP] = "ip6-map-t-tcp-udp",
1504 [IP6_MAPT_NEXT_MAPT_ICMP] = "ip6-map-t-icmp",
1505 [IP6_MAPT_NEXT_MAPT_FRAGMENTED] = "ip6-map-t-fragmented",
1506 [IP6_MAPT_NEXT_DROP] = "error-drop",
1512 * fd.io coding-style-patch-verification: ON
1515 * eval: (c-set-style "gnu")