Remove c-11 memcpy checks from perf-critical code
[vpp.git] / src / plugins / map / ip6_map.c
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/ip_frag.h>
18 #include <vnet/ip/ip4_to_ip6.h>
19 #include <vnet/ip/ip6_to_ip4.h>
20
21 enum ip6_map_next_e
22 {
23   IP6_MAP_NEXT_IP4_LOOKUP,
24 #ifdef MAP_SKIP_IP6_LOOKUP
25   IP6_MAP_NEXT_IP4_REWRITE,
26 #endif
27   IP6_MAP_NEXT_IP6_REASS,
28   IP6_MAP_NEXT_IP4_REASS,
29   IP6_MAP_NEXT_IP4_FRAGMENT,
30   IP6_MAP_NEXT_IP6_ICMP_RELAY,
31   IP6_MAP_NEXT_IP6_LOCAL,
32   IP6_MAP_NEXT_DROP,
33   IP6_MAP_NEXT_ICMP,
34   IP6_MAP_N_NEXT,
35 };
36
37 enum ip6_map_ip6_reass_next_e
38 {
39   IP6_MAP_IP6_REASS_NEXT_IP6_MAP,
40   IP6_MAP_IP6_REASS_NEXT_DROP,
41   IP6_MAP_IP6_REASS_N_NEXT,
42 };
43
44 enum ip6_map_ip4_reass_next_e
45 {
46   IP6_MAP_IP4_REASS_NEXT_IP4_LOOKUP,
47   IP6_MAP_IP4_REASS_NEXT_IP4_FRAGMENT,
48   IP6_MAP_IP4_REASS_NEXT_DROP,
49   IP6_MAP_IP4_REASS_N_NEXT,
50 };
51
52 enum ip6_icmp_relay_next_e
53 {
54   IP6_ICMP_RELAY_NEXT_IP4_LOOKUP,
55   IP6_ICMP_RELAY_NEXT_DROP,
56   IP6_ICMP_RELAY_N_NEXT,
57 };
58
59 vlib_node_registration_t ip6_map_ip4_reass_node;
60 vlib_node_registration_t ip6_map_ip6_reass_node;
61 static vlib_node_registration_t ip6_map_icmp_relay_node;
62
63 typedef struct
64 {
65   u32 map_domain_index;
66   u16 port;
67   u8 cached;
68 } map_ip6_map_ip4_reass_trace_t;
69
70 u8 *
71 format_ip6_map_ip4_reass_trace (u8 * s, va_list * args)
72 {
73   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
74   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
75   map_ip6_map_ip4_reass_trace_t *t =
76     va_arg (*args, map_ip6_map_ip4_reass_trace_t *);
77   return format (s, "MAP domain index: %d L4 port: %u Status: %s",
78                  t->map_domain_index, t->port,
79                  t->cached ? "cached" : "forwarded");
80 }
81
82 typedef struct
83 {
84   u16 offset;
85   u16 frag_len;
86   u8 out;
87 } map_ip6_map_ip6_reass_trace_t;
88
89 u8 *
90 format_ip6_map_ip6_reass_trace (u8 * s, va_list * args)
91 {
92   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
93   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
94   map_ip6_map_ip6_reass_trace_t *t =
95     va_arg (*args, map_ip6_map_ip6_reass_trace_t *);
96   return format (s, "Offset: %d Fragment length: %d Status: %s", t->offset,
97                  t->frag_len, t->out ? "out" : "in");
98 }
99
100 /*
101  * ip6_map_sec_check
102  */
103 static_always_inline bool
104 ip6_map_sec_check (map_domain_t * d, u16 port, ip4_header_t * ip4,
105                    ip6_header_t * ip6)
106 {
107   u16 sp4 = clib_net_to_host_u16 (port);
108   u32 sa4 = clib_net_to_host_u32 (ip4->src_address.as_u32);
109   u64 sal6 = map_get_pfx (d, sa4, sp4);
110   u64 sar6 = map_get_sfx (d, sa4, sp4);
111
112   if (PREDICT_FALSE
113       (sal6 != clib_net_to_host_u64 (ip6->src_address.as_u64[0])
114        || sar6 != clib_net_to_host_u64 (ip6->src_address.as_u64[1])))
115     return (false);
116   return (true);
117 }
118
119 static_always_inline void
120 ip6_map_security_check (map_domain_t * d, ip4_header_t * ip4,
121                         ip6_header_t * ip6, u32 * next, u8 * error)
122 {
123   map_main_t *mm = &map_main;
124   if (d->ea_bits_len || d->rules)
125     {
126       if (d->psid_length > 0)
127         {
128           if (!ip4_is_fragment (ip4))
129             {
130               u16 port = ip4_get_port (ip4, 1);
131               if (port)
132                 {
133                   if (mm->sec_check)
134                     *error =
135                       ip6_map_sec_check (d, port, ip4,
136                                          ip6) ? MAP_ERROR_NONE :
137                       MAP_ERROR_DECAP_SEC_CHECK;
138                 }
139               else
140                 {
141                   *error = MAP_ERROR_BAD_PROTOCOL;
142                 }
143             }
144           else
145             {
146               *next = mm->sec_check_frag ? IP6_MAP_NEXT_IP4_REASS : *next;
147             }
148         }
149     }
150 }
151
152 static_always_inline bool
153 ip6_map_ip4_lookup_bypass (vlib_buffer_t * p0, ip4_header_t * ip)
154 {
155 #ifdef MAP_SKIP_IP6_LOOKUP
156   if (FIB_NODE_INDEX_INVALID != pre_resolved[FIB_PROTOCOL_IP4].fei)
157     {
158       vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
159         pre_resolved[FIB_PROTOCOL_IP4].dpo.dpoi_index;
160       return (true);
161     }
162 #endif
163   return (false);
164 }
165
166 /*
167  * ip6_map
168  */
169 static uword
170 ip6_map (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
171 {
172   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
173   vlib_node_runtime_t *error_node =
174     vlib_node_get_runtime (vm, ip6_map_node.index);
175   map_main_t *mm = &map_main;
176   vlib_combined_counter_main_t *cm = mm->domain_counters;
177   u32 thread_index = vm->thread_index;
178
179   from = vlib_frame_vector_args (frame);
180   n_left_from = frame->n_vectors;
181   next_index = node->cached_next_index;
182   while (n_left_from > 0)
183     {
184       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
185
186       /* Dual loop */
187       while (n_left_from >= 4 && n_left_to_next >= 2)
188         {
189           u32 pi0, pi1;
190           vlib_buffer_t *p0, *p1;
191           u8 error0 = MAP_ERROR_NONE;
192           u8 error1 = MAP_ERROR_NONE;
193           map_domain_t *d0 = 0, *d1 = 0;
194           ip4_header_t *ip40, *ip41;
195           ip6_header_t *ip60, *ip61;
196           u16 port0 = 0, port1 = 0;
197           u32 map_domain_index0 = ~0, map_domain_index1 = ~0;
198           u32 next0 = IP6_MAP_NEXT_IP4_LOOKUP;
199           u32 next1 = IP6_MAP_NEXT_IP4_LOOKUP;
200
201           /* Prefetch next iteration. */
202           {
203             vlib_buffer_t *p2, *p3;
204
205             p2 = vlib_get_buffer (vm, from[2]);
206             p3 = vlib_get_buffer (vm, from[3]);
207
208             vlib_prefetch_buffer_header (p2, LOAD);
209             vlib_prefetch_buffer_header (p3, LOAD);
210
211             /* IPv6 + IPv4 header + 8 bytes of ULP */
212             CLIB_PREFETCH (p2->data, 68, LOAD);
213             CLIB_PREFETCH (p3->data, 68, LOAD);
214           }
215
216           pi0 = to_next[0] = from[0];
217           pi1 = to_next[1] = from[1];
218           from += 2;
219           n_left_from -= 2;
220           to_next += 2;
221           n_left_to_next -= 2;
222
223           p0 = vlib_get_buffer (vm, pi0);
224           p1 = vlib_get_buffer (vm, pi1);
225           ip60 = vlib_buffer_get_current (p0);
226           ip61 = vlib_buffer_get_current (p1);
227           vlib_buffer_advance (p0, sizeof (ip6_header_t));
228           vlib_buffer_advance (p1, sizeof (ip6_header_t));
229           ip40 = vlib_buffer_get_current (p0);
230           ip41 = vlib_buffer_get_current (p1);
231
232           /*
233            * Encapsulated IPv4 packet
234            *   - IPv4 fragmented -> Pass to virtual reassembly unless security check disabled
235            *   - Lookup/Rewrite or Fragment node in case of packet > MTU
236            * Fragmented IPv6 packet
237            * ICMP IPv6 packet
238            *   - Error -> Pass to ICMPv6/ICMPv4 relay
239            *   - Info -> Pass to IPv6 local
240            * Anything else -> drop
241            */
242           if (PREDICT_TRUE
243               (ip60->protocol == IP_PROTOCOL_IP_IN_IP
244                && clib_net_to_host_u16 (ip60->payload_length) > 20))
245             {
246               d0 =
247                 ip6_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
248                                     (ip4_address_t *) & ip40->
249                                     src_address.as_u32, &map_domain_index0,
250                                     &error0);
251             }
252           else if (ip60->protocol == IP_PROTOCOL_ICMP6 &&
253                    clib_net_to_host_u16 (ip60->payload_length) >
254                    sizeof (icmp46_header_t))
255             {
256               icmp46_header_t *icmp = (void *) (ip60 + 1);
257               next0 = (icmp->type == ICMP6_echo_request
258                        || icmp->type ==
259                        ICMP6_echo_reply) ? IP6_MAP_NEXT_IP6_LOCAL :
260                 IP6_MAP_NEXT_IP6_ICMP_RELAY;
261             }
262           else if (ip60->protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
263             {
264               next0 = IP6_MAP_NEXT_IP6_REASS;
265             }
266           else
267             {
268               error0 = MAP_ERROR_BAD_PROTOCOL;
269             }
270           if (PREDICT_TRUE
271               (ip61->protocol == IP_PROTOCOL_IP_IN_IP
272                && clib_net_to_host_u16 (ip61->payload_length) > 20))
273             {
274               d1 =
275                 ip6_map_get_domain (vnet_buffer (p1)->ip.adj_index[VLIB_TX],
276                                     (ip4_address_t *) & ip41->
277                                     src_address.as_u32, &map_domain_index1,
278                                     &error1);
279             }
280           else if (ip61->protocol == IP_PROTOCOL_ICMP6 &&
281                    clib_net_to_host_u16 (ip61->payload_length) >
282                    sizeof (icmp46_header_t))
283             {
284               icmp46_header_t *icmp = (void *) (ip61 + 1);
285               next1 = (icmp->type == ICMP6_echo_request
286                        || icmp->type ==
287                        ICMP6_echo_reply) ? IP6_MAP_NEXT_IP6_LOCAL :
288                 IP6_MAP_NEXT_IP6_ICMP_RELAY;
289             }
290           else if (ip61->protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
291             {
292               next1 = IP6_MAP_NEXT_IP6_REASS;
293             }
294           else
295             {
296               error1 = MAP_ERROR_BAD_PROTOCOL;
297             }
298
299           if (d0)
300             {
301               /* MAP inbound security check */
302               ip6_map_security_check (d0, ip40, ip60, &next0, &error0);
303
304               if (PREDICT_TRUE (error0 == MAP_ERROR_NONE &&
305                                 next0 == IP6_MAP_NEXT_IP4_LOOKUP))
306                 {
307                   if (PREDICT_FALSE
308                       (d0->mtu
309                        && (clib_host_to_net_u16 (ip40->length) > d0->mtu)))
310                     {
311                       vnet_buffer (p0)->ip_frag.flags = 0;
312                       vnet_buffer (p0)->ip_frag.next_index =
313                         IP4_FRAG_NEXT_IP4_LOOKUP;
314                       vnet_buffer (p0)->ip_frag.mtu = d0->mtu;
315                       next0 = IP6_MAP_NEXT_IP4_FRAGMENT;
316                     }
317                   else
318                     {
319                       next0 =
320                         ip6_map_ip4_lookup_bypass (p0,
321                                                    ip40) ?
322                         IP6_MAP_NEXT_IP4_REWRITE : next0;
323                     }
324                   vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
325                                                    thread_index,
326                                                    map_domain_index0, 1,
327                                                    clib_net_to_host_u16
328                                                    (ip40->length));
329                 }
330             }
331           if (d1)
332             {
333               /* MAP inbound security check */
334               ip6_map_security_check (d1, ip41, ip61, &next1, &error1);
335
336               if (PREDICT_TRUE (error1 == MAP_ERROR_NONE &&
337                                 next1 == IP6_MAP_NEXT_IP4_LOOKUP))
338                 {
339                   if (PREDICT_FALSE
340                       (d1->mtu
341                        && (clib_host_to_net_u16 (ip41->length) > d1->mtu)))
342                     {
343                       vnet_buffer (p1)->ip_frag.flags = 0;
344                       vnet_buffer (p1)->ip_frag.next_index =
345                         IP4_FRAG_NEXT_IP4_LOOKUP;
346                       vnet_buffer (p1)->ip_frag.mtu = d1->mtu;
347                       next1 = IP6_MAP_NEXT_IP4_FRAGMENT;
348                     }
349                   else
350                     {
351                       next1 =
352                         ip6_map_ip4_lookup_bypass (p1,
353                                                    ip41) ?
354                         IP6_MAP_NEXT_IP4_REWRITE : next1;
355                     }
356                   vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
357                                                    thread_index,
358                                                    map_domain_index1, 1,
359                                                    clib_net_to_host_u16
360                                                    (ip41->length));
361                 }
362             }
363
364           if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
365             {
366               map_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
367               tr->map_domain_index = map_domain_index0;
368               tr->port = port0;
369             }
370
371           if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
372             {
373               map_trace_t *tr = vlib_add_trace (vm, node, p1, sizeof (*tr));
374               tr->map_domain_index = map_domain_index1;
375               tr->port = port1;
376             }
377
378           if (error0 == MAP_ERROR_DECAP_SEC_CHECK && mm->icmp6_enabled)
379             {
380               /* Set ICMP parameters */
381               vlib_buffer_advance (p0, -sizeof (ip6_header_t));
382               icmp6_error_set_vnet_buffer (p0, ICMP6_destination_unreachable,
383                                            ICMP6_destination_unreachable_source_address_failed_policy,
384                                            0);
385               next0 = IP6_MAP_NEXT_ICMP;
386             }
387           else
388             {
389               next0 = (error0 == MAP_ERROR_NONE) ? next0 : IP6_MAP_NEXT_DROP;
390             }
391
392           if (error1 == MAP_ERROR_DECAP_SEC_CHECK && mm->icmp6_enabled)
393             {
394               /* Set ICMP parameters */
395               vlib_buffer_advance (p1, -sizeof (ip6_header_t));
396               icmp6_error_set_vnet_buffer (p1, ICMP6_destination_unreachable,
397                                            ICMP6_destination_unreachable_source_address_failed_policy,
398                                            0);
399               next1 = IP6_MAP_NEXT_ICMP;
400             }
401           else
402             {
403               next1 = (error1 == MAP_ERROR_NONE) ? next1 : IP6_MAP_NEXT_DROP;
404             }
405
406           /* Reset packet */
407           if (next0 == IP6_MAP_NEXT_IP6_LOCAL)
408             vlib_buffer_advance (p0, -sizeof (ip6_header_t));
409           if (next1 == IP6_MAP_NEXT_IP6_LOCAL)
410             vlib_buffer_advance (p1, -sizeof (ip6_header_t));
411
412           p0->error = error_node->errors[error0];
413           p1->error = error_node->errors[error1];
414           vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
415                                            n_left_to_next, pi0, pi1, next0,
416                                            next1);
417         }
418
419       /* Single loop */
420       while (n_left_from > 0 && n_left_to_next > 0)
421         {
422           u32 pi0;
423           vlib_buffer_t *p0;
424           u8 error0 = MAP_ERROR_NONE;
425           map_domain_t *d0 = 0;
426           ip4_header_t *ip40;
427           ip6_header_t *ip60;
428           i32 port0 = 0;
429           u32 map_domain_index0 = ~0;
430           u32 next0 = IP6_MAP_NEXT_IP4_LOOKUP;
431
432           pi0 = to_next[0] = from[0];
433           from += 1;
434           n_left_from -= 1;
435           to_next += 1;
436           n_left_to_next -= 1;
437
438           p0 = vlib_get_buffer (vm, pi0);
439           ip60 = vlib_buffer_get_current (p0);
440           vlib_buffer_advance (p0, sizeof (ip6_header_t));
441           ip40 = vlib_buffer_get_current (p0);
442
443           /*
444            * Encapsulated IPv4 packet
445            *   - IPv4 fragmented -> Pass to virtual reassembly unless security check disabled
446            *   - Lookup/Rewrite or Fragment node in case of packet > MTU
447            * Fragmented IPv6 packet
448            * ICMP IPv6 packet
449            *   - Error -> Pass to ICMPv6/ICMPv4 relay
450            *   - Info -> Pass to IPv6 local
451            * Anything else -> drop
452            */
453           if (PREDICT_TRUE
454               (ip60->protocol == IP_PROTOCOL_IP_IN_IP
455                && clib_net_to_host_u16 (ip60->payload_length) > 20))
456             {
457               d0 =
458                 ip6_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
459                                     (ip4_address_t *) & ip40->
460                                     src_address.as_u32, &map_domain_index0,
461                                     &error0);
462             }
463           else if (ip60->protocol == IP_PROTOCOL_ICMP6 &&
464                    clib_net_to_host_u16 (ip60->payload_length) >
465                    sizeof (icmp46_header_t))
466             {
467               icmp46_header_t *icmp = (void *) (ip60 + 1);
468               next0 = (icmp->type == ICMP6_echo_request
469                        || icmp->type ==
470                        ICMP6_echo_reply) ? IP6_MAP_NEXT_IP6_LOCAL :
471                 IP6_MAP_NEXT_IP6_ICMP_RELAY;
472             }
473           else if (ip60->protocol == IP_PROTOCOL_IPV6_FRAGMENTATION &&
474                    (((ip6_frag_hdr_t *) (ip60 + 1))->next_hdr ==
475                     IP_PROTOCOL_IP_IN_IP))
476             {
477               next0 = IP6_MAP_NEXT_IP6_REASS;
478             }
479           else
480             {
481               error0 = MAP_ERROR_BAD_PROTOCOL;
482             }
483
484           if (d0)
485             {
486               /* MAP inbound security check */
487               ip6_map_security_check (d0, ip40, ip60, &next0, &error0);
488
489               if (PREDICT_TRUE (error0 == MAP_ERROR_NONE &&
490                                 next0 == IP6_MAP_NEXT_IP4_LOOKUP))
491                 {
492                   if (PREDICT_FALSE
493                       (d0->mtu
494                        && (clib_host_to_net_u16 (ip40->length) > d0->mtu)))
495                     {
496                       vnet_buffer (p0)->ip_frag.flags = 0;
497                       vnet_buffer (p0)->ip_frag.next_index =
498                         IP4_FRAG_NEXT_IP4_LOOKUP;
499                       vnet_buffer (p0)->ip_frag.mtu = d0->mtu;
500                       next0 = IP6_MAP_NEXT_IP4_FRAGMENT;
501                     }
502                   else
503                     {
504                       next0 =
505                         ip6_map_ip4_lookup_bypass (p0,
506                                                    ip40) ?
507                         IP6_MAP_NEXT_IP4_REWRITE : next0;
508                     }
509                   vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
510                                                    thread_index,
511                                                    map_domain_index0, 1,
512                                                    clib_net_to_host_u16
513                                                    (ip40->length));
514                 }
515             }
516
517           if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
518             {
519               map_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
520               tr->map_domain_index = map_domain_index0;
521               tr->port = (u16) port0;
522             }
523
524           if (mm->icmp6_enabled &&
525               (error0 == MAP_ERROR_DECAP_SEC_CHECK
526                || error0 == MAP_ERROR_NO_DOMAIN))
527             {
528               /* Set ICMP parameters */
529               vlib_buffer_advance (p0, -sizeof (ip6_header_t));
530               icmp6_error_set_vnet_buffer (p0, ICMP6_destination_unreachable,
531                                            ICMP6_destination_unreachable_source_address_failed_policy,
532                                            0);
533               next0 = IP6_MAP_NEXT_ICMP;
534             }
535           else
536             {
537               next0 = (error0 == MAP_ERROR_NONE) ? next0 : IP6_MAP_NEXT_DROP;
538             }
539
540           /* Reset packet */
541           if (next0 == IP6_MAP_NEXT_IP6_LOCAL)
542             vlib_buffer_advance (p0, -sizeof (ip6_header_t));
543
544           p0->error = error_node->errors[error0];
545           vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
546                                            n_left_to_next, pi0, next0);
547         }
548       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
549     }
550
551   return frame->n_vectors;
552 }
553
554
555 static_always_inline void
556 ip6_map_ip6_reass_prepare (vlib_main_t * vm, vlib_node_runtime_t * node,
557                            map_ip6_reass_t * r, u32 ** fragments_ready,
558                            u32 ** fragments_to_drop)
559 {
560   ip4_header_t *ip40;
561   ip6_header_t *ip60;
562   ip6_frag_hdr_t *frag0;
563   vlib_buffer_t *p0;
564
565   if (!r->ip4_header.ip_version_and_header_length)
566     return;
567
568   //The IP header is here, we need to check for packets
569   //that can be forwarded
570   int i;
571   for (i = 0; i < MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++)
572     {
573       if (r->fragments[i].pi == ~0 ||
574           ((!r->fragments[i].next_data_len)
575            && (r->fragments[i].next_data_offset != (0xffff))))
576         continue;
577
578       p0 = vlib_get_buffer (vm, r->fragments[i].pi);
579       ip60 = vlib_buffer_get_current (p0);
580       frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
581       ip40 = (ip4_header_t *) (frag0 + 1);
582
583       if (ip6_frag_hdr_offset (frag0))
584         {
585           //Not first fragment, add the IPv4 header
586           clib_memcpy_fast (ip40, &r->ip4_header, 20);
587         }
588
589 #ifdef MAP_IP6_REASS_COUNT_BYTES
590       r->forwarded +=
591         clib_net_to_host_u16 (ip60->payload_length) - sizeof (*frag0);
592 #endif
593
594       if (ip6_frag_hdr_more (frag0))
595         {
596           //Not last fragment, we copy end of next
597           clib_memcpy_fast (u8_ptr_add (ip60, p0->current_length),
598                             r->fragments[i].next_data, 20);
599           p0->current_length += 20;
600           ip60->payload_length = u16_net_add (ip60->payload_length, 20);
601         }
602
603       if (!ip4_is_fragment (ip40))
604         {
605           ip40->fragment_id = frag_id_6to4 (frag0->identification);
606           ip40->flags_and_fragment_offset =
607             clib_host_to_net_u16 (ip6_frag_hdr_offset (frag0));
608         }
609       else
610         {
611           ip40->flags_and_fragment_offset =
612             clib_host_to_net_u16 (ip4_get_fragment_offset (ip40) +
613                                   ip6_frag_hdr_offset (frag0));
614         }
615
616       if (ip6_frag_hdr_more (frag0))
617         ip40->flags_and_fragment_offset |=
618           clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
619
620       ip40->length =
621         clib_host_to_net_u16 (p0->current_length - sizeof (*ip60) -
622                               sizeof (*frag0));
623       ip40->checksum = ip4_header_checksum (ip40);
624
625       if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
626         {
627           map_ip6_map_ip6_reass_trace_t *tr =
628             vlib_add_trace (vm, node, p0, sizeof (*tr));
629           tr->offset = ip4_get_fragment_offset (ip40);
630           tr->frag_len = clib_net_to_host_u16 (ip40->length) - sizeof (*ip40);
631           tr->out = 1;
632         }
633
634       vec_add1 (*fragments_ready, r->fragments[i].pi);
635       r->fragments[i].pi = ~0;
636       r->fragments[i].next_data_len = 0;
637       r->fragments[i].next_data_offset = 0;
638       map_main.ip6_reass_buffered_counter--;
639
640       //TODO: Best solution would be that ip6_map handles extension headers
641       // and ignores atomic fragment. But in the meantime, let's just copy the header.
642
643       u8 protocol = frag0->next_hdr;
644       memmove (u8_ptr_add (ip40, -sizeof (*ip60)), ip60, sizeof (*ip60));
645       ((ip6_header_t *) u8_ptr_add (ip40, -sizeof (*ip60)))->protocol =
646         protocol;
647       vlib_buffer_advance (p0, sizeof (*frag0));
648     }
649 }
650
651 void
652 map_ip6_drop_pi (u32 pi)
653 {
654   vlib_main_t *vm = vlib_get_main ();
655   vlib_node_runtime_t *n =
656     vlib_node_get_runtime (vm, ip6_map_ip6_reass_node.index);
657   vlib_set_next_frame_buffer (vm, n, IP6_MAP_IP6_REASS_NEXT_DROP, pi);
658 }
659
660 void
661 map_ip4_drop_pi (u32 pi)
662 {
663   vlib_main_t *vm = vlib_get_main ();
664   vlib_node_runtime_t *n =
665     vlib_node_get_runtime (vm, ip6_map_ip4_reass_node.index);
666   vlib_set_next_frame_buffer (vm, n, IP6_MAP_IP4_REASS_NEXT_DROP, pi);
667 }
668
669 /*
670  * ip6_reass
671  * TODO: We should count the number of successfully
672  * transmitted fragment bytes and compare that to the last fragment
673  * offset such that we can free the reassembly structure when all fragments
674  * have been forwarded.
675  */
676 static uword
677 ip6_map_ip6_reass (vlib_main_t * vm,
678                    vlib_node_runtime_t * node, vlib_frame_t * frame)
679 {
680   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
681   vlib_node_runtime_t *error_node =
682     vlib_node_get_runtime (vm, ip6_map_ip6_reass_node.index);
683   u32 *fragments_to_drop = NULL;
684   u32 *fragments_ready = NULL;
685
686   from = vlib_frame_vector_args (frame);
687   n_left_from = frame->n_vectors;
688   next_index = node->cached_next_index;
689   while (n_left_from > 0)
690     {
691       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
692
693       /* Single loop */
694       while (n_left_from > 0 && n_left_to_next > 0)
695         {
696           u32 pi0;
697           vlib_buffer_t *p0;
698           u8 error0 = MAP_ERROR_NONE;
699           ip6_header_t *ip60;
700           ip6_frag_hdr_t *frag0;
701           u16 offset;
702           u16 next_offset;
703           u16 frag_len;
704
705           pi0 = to_next[0] = from[0];
706           from += 1;
707           n_left_from -= 1;
708           to_next += 1;
709           n_left_to_next -= 1;
710
711           p0 = vlib_get_buffer (vm, pi0);
712           ip60 = vlib_buffer_get_current (p0);
713           frag0 = (ip6_frag_hdr_t *) (ip60 + 1);
714           offset =
715             clib_host_to_net_u16 (frag0->fragment_offset_and_more) & (~7);
716           frag_len =
717             clib_net_to_host_u16 (ip60->payload_length) - sizeof (*frag0);
718           next_offset =
719             ip6_frag_hdr_more (frag0) ? (offset + frag_len) : (0xffff);
720
721           //FIXME: Support other extension headers, maybe
722
723           if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
724             {
725               map_ip6_map_ip6_reass_trace_t *tr =
726                 vlib_add_trace (vm, node, p0, sizeof (*tr));
727               tr->offset = offset;
728               tr->frag_len = frag_len;
729               tr->out = 0;
730             }
731
732           map_ip6_reass_lock ();
733           map_ip6_reass_t *r =
734             map_ip6_reass_get (&ip60->src_address, &ip60->dst_address,
735                                frag0->identification, frag0->next_hdr,
736                                &fragments_to_drop);
737           //FIXME: Use better error codes
738           if (PREDICT_FALSE (!r))
739             {
740               // Could not create a caching entry
741               error0 = MAP_ERROR_FRAGMENT_MEMORY;
742             }
743           else if (PREDICT_FALSE ((frag_len <= 20 &&
744                                    (ip6_frag_hdr_more (frag0) || (!offset)))))
745             {
746               //Very small fragment are restricted to the last one and
747               //can't be the first one
748               error0 = MAP_ERROR_FRAGMENT_MALFORMED;
749             }
750           else
751             if (map_ip6_reass_add_fragment
752                 (r, pi0, offset, next_offset, (u8 *) (frag0 + 1), frag_len))
753             {
754               map_ip6_reass_free (r, &fragments_to_drop);
755               error0 = MAP_ERROR_FRAGMENT_MEMORY;
756             }
757           else
758             {
759 #ifdef MAP_IP6_REASS_COUNT_BYTES
760               if (!ip6_frag_hdr_more (frag0))
761                 r->expected_total = offset + frag_len;
762 #endif
763               ip6_map_ip6_reass_prepare (vm, node, r, &fragments_ready,
764                                          &fragments_to_drop);
765 #ifdef MAP_IP6_REASS_COUNT_BYTES
766               if (r->forwarded >= r->expected_total)
767                 map_ip6_reass_free (r, &fragments_to_drop);
768 #endif
769             }
770           map_ip6_reass_unlock ();
771
772           if (error0 == MAP_ERROR_NONE)
773             {
774               if (frag_len > 20)
775                 {
776                   //Dequeue the packet
777                   n_left_to_next++;
778                   to_next--;
779                 }
780               else
781                 {
782                   //All data from that packet was copied no need to keep it, but this is not an error
783                   p0->error = error_node->errors[MAP_ERROR_NONE];
784                   vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
785                                                    to_next, n_left_to_next,
786                                                    pi0,
787                                                    IP6_MAP_IP6_REASS_NEXT_DROP);
788                 }
789             }
790           else
791             {
792               p0->error = error_node->errors[error0];
793               vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
794                                                n_left_to_next, pi0,
795                                                IP6_MAP_IP6_REASS_NEXT_DROP);
796             }
797         }
798       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
799     }
800
801   map_send_all_to_node (vm, fragments_ready, node,
802                         &error_node->errors[MAP_ERROR_NONE],
803                         IP6_MAP_IP6_REASS_NEXT_IP6_MAP);
804   map_send_all_to_node (vm, fragments_to_drop, node,
805                         &error_node->errors[MAP_ERROR_FRAGMENT_DROPPED],
806                         IP6_MAP_IP6_REASS_NEXT_DROP);
807
808   vec_free (fragments_to_drop);
809   vec_free (fragments_ready);
810   return frame->n_vectors;
811 }
812
813 /*
814  * ip6_ip4_virt_reass
815  */
816 static uword
817 ip6_map_ip4_reass (vlib_main_t * vm,
818                    vlib_node_runtime_t * node, vlib_frame_t * frame)
819 {
820   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
821   vlib_node_runtime_t *error_node =
822     vlib_node_get_runtime (vm, ip6_map_ip4_reass_node.index);
823   map_main_t *mm = &map_main;
824   vlib_combined_counter_main_t *cm = mm->domain_counters;
825   u32 thread_index = vm->thread_index;
826   u32 *fragments_to_drop = NULL;
827   u32 *fragments_to_loopback = NULL;
828
829   from = vlib_frame_vector_args (frame);
830   n_left_from = frame->n_vectors;
831   next_index = node->cached_next_index;
832   while (n_left_from > 0)
833     {
834       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
835
836       /* Single loop */
837       while (n_left_from > 0 && n_left_to_next > 0)
838         {
839           u32 pi0;
840           vlib_buffer_t *p0;
841           u8 error0 = MAP_ERROR_NONE;
842           map_domain_t *d0;
843           ip4_header_t *ip40;
844           ip6_header_t *ip60;
845           i32 port0 = 0;
846           u32 map_domain_index0 = ~0;
847           u32 next0 = IP6_MAP_IP4_REASS_NEXT_IP4_LOOKUP;
848           u8 cached = 0;
849
850           pi0 = to_next[0] = from[0];
851           from += 1;
852           n_left_from -= 1;
853           to_next += 1;
854           n_left_to_next -= 1;
855
856           p0 = vlib_get_buffer (vm, pi0);
857           ip40 = vlib_buffer_get_current (p0);
858           ip60 = ((ip6_header_t *) ip40) - 1;
859
860           d0 =
861             ip6_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
862                                 (ip4_address_t *) & ip40->src_address.as_u32,
863                                 &map_domain_index0, &error0);
864
865           map_ip4_reass_lock ();
866           //This node only deals with fragmented ip4
867           map_ip4_reass_t *r = map_ip4_reass_get (ip40->src_address.as_u32,
868                                                   ip40->dst_address.as_u32,
869                                                   ip40->fragment_id,
870                                                   ip40->protocol,
871                                                   &fragments_to_drop);
872           if (PREDICT_FALSE (!r))
873             {
874               // Could not create a caching entry
875               error0 = MAP_ERROR_FRAGMENT_MEMORY;
876             }
877           else if (PREDICT_TRUE (ip4_get_fragment_offset (ip40)))
878             {
879               // This is a fragment
880               if (r->port >= 0)
881                 {
882                   // We know the port already
883                   port0 = r->port;
884                 }
885               else if (map_ip4_reass_add_fragment (r, pi0))
886                 {
887                   // Not enough space for caching
888                   error0 = MAP_ERROR_FRAGMENT_MEMORY;
889                   map_ip4_reass_free (r, &fragments_to_drop);
890                 }
891               else
892                 {
893                   cached = 1;
894                 }
895             }
896           else if ((port0 = ip4_get_port (ip40, 1)) == 0)
897             {
898               // Could not find port from first fragment. Stop reassembling.
899               error0 = MAP_ERROR_BAD_PROTOCOL;
900               port0 = 0;
901               map_ip4_reass_free (r, &fragments_to_drop);
902             }
903           else
904             {
905               // Found port. Remember it and loopback saved fragments
906               r->port = port0;
907               map_ip4_reass_get_fragments (r, &fragments_to_loopback);
908             }
909
910 #ifdef MAP_IP4_REASS_COUNT_BYTES
911           if (!cached && r)
912             {
913               r->forwarded += clib_host_to_net_u16 (ip40->length) - 20;
914               if (!ip4_get_fragment_more (ip40))
915                 r->expected_total =
916                   ip4_get_fragment_offset (ip40) * 8 +
917                   clib_host_to_net_u16 (ip40->length) - 20;
918               if (r->forwarded >= r->expected_total)
919                 map_ip4_reass_free (r, &fragments_to_drop);
920             }
921 #endif
922
923           map_ip4_reass_unlock ();
924
925           if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
926             error0 =
927               ip6_map_sec_check (d0, port0, ip40,
928                                  ip60) ? MAP_ERROR_NONE :
929               MAP_ERROR_DECAP_SEC_CHECK;
930
931           if (PREDICT_FALSE
932               (d0->mtu && (clib_host_to_net_u16 (ip40->length) > d0->mtu)
933                && error0 == MAP_ERROR_NONE && !cached))
934             {
935               vnet_buffer (p0)->ip_frag.flags = 0;
936               vnet_buffer (p0)->ip_frag.next_index = IP4_FRAG_NEXT_IP4_LOOKUP;
937               vnet_buffer (p0)->ip_frag.mtu = d0->mtu;
938               next0 = IP6_MAP_IP4_REASS_NEXT_IP4_FRAGMENT;
939             }
940
941           if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
942             {
943               map_ip6_map_ip4_reass_trace_t *tr =
944                 vlib_add_trace (vm, node, p0, sizeof (*tr));
945               tr->map_domain_index = map_domain_index0;
946               tr->port = port0;
947               tr->cached = cached;
948             }
949
950           if (cached)
951             {
952               //Dequeue the packet
953               n_left_to_next++;
954               to_next--;
955             }
956           else
957             {
958               if (error0 == MAP_ERROR_NONE)
959                 vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
960                                                  thread_index,
961                                                  map_domain_index0, 1,
962                                                  clib_net_to_host_u16
963                                                  (ip40->length));
964               next0 =
965                 (error0 ==
966                  MAP_ERROR_NONE) ? next0 : IP6_MAP_IP4_REASS_NEXT_DROP;
967               p0->error = error_node->errors[error0];
968               vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
969                                                n_left_to_next, pi0, next0);
970             }
971
972           //Loopback when we reach the end of the inpu vector
973           if (n_left_from == 0 && vec_len (fragments_to_loopback))
974             {
975               from = vlib_frame_vector_args (frame);
976               u32 len = vec_len (fragments_to_loopback);
977               if (len <= VLIB_FRAME_SIZE)
978                 {
979                   clib_memcpy_fast (from, fragments_to_loopback,
980                                     sizeof (u32) * len);
981                   n_left_from = len;
982                   vec_reset_length (fragments_to_loopback);
983                 }
984               else
985                 {
986                   clib_memcpy_fast (from, fragments_to_loopback +
987                                     (len - VLIB_FRAME_SIZE),
988                                     sizeof (u32) * VLIB_FRAME_SIZE);
989                   n_left_from = VLIB_FRAME_SIZE;
990                   _vec_len (fragments_to_loopback) = len - VLIB_FRAME_SIZE;
991                 }
992             }
993         }
994       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
995     }
996   map_send_all_to_node (vm, fragments_to_drop, node,
997                         &error_node->errors[MAP_ERROR_FRAGMENT_DROPPED],
998                         IP6_MAP_IP4_REASS_NEXT_DROP);
999
1000   vec_free (fragments_to_drop);
1001   vec_free (fragments_to_loopback);
1002   return frame->n_vectors;
1003 }
1004
1005 /*
1006  * ip6_icmp_relay
1007  */
1008 static uword
1009 ip6_map_icmp_relay (vlib_main_t * vm,
1010                     vlib_node_runtime_t * node, vlib_frame_t * frame)
1011 {
1012   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
1013   vlib_node_runtime_t *error_node =
1014     vlib_node_get_runtime (vm, ip6_map_icmp_relay_node.index);
1015   map_main_t *mm = &map_main;
1016   u32 thread_index = vm->thread_index;
1017   u16 *fragment_ids, *fid;
1018
1019   from = vlib_frame_vector_args (frame);
1020   n_left_from = frame->n_vectors;
1021   next_index = node->cached_next_index;
1022
1023   /* Get random fragment IDs for replies. */
1024   fid = fragment_ids =
1025     clib_random_buffer_get_data (&vm->random_buffer,
1026                                  n_left_from * sizeof (fragment_ids[0]));
1027
1028   while (n_left_from > 0)
1029     {
1030       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1031
1032       /* Single loop */
1033       while (n_left_from > 0 && n_left_to_next > 0)
1034         {
1035           u32 pi0;
1036           vlib_buffer_t *p0;
1037           u8 error0 = MAP_ERROR_NONE;
1038           ip6_header_t *ip60;
1039           u32 next0 = IP6_ICMP_RELAY_NEXT_IP4_LOOKUP;
1040           u32 mtu;
1041
1042           pi0 = to_next[0] = from[0];
1043           from += 1;
1044           n_left_from -= 1;
1045           to_next += 1;
1046           n_left_to_next -= 1;
1047
1048           p0 = vlib_get_buffer (vm, pi0);
1049           ip60 = vlib_buffer_get_current (p0);
1050           u16 tlen = clib_net_to_host_u16 (ip60->payload_length);
1051
1052           /*
1053            * In:
1054            *  IPv6 header           (40)
1055            *  ICMPv6 header          (8)
1056            *  IPv6 header           (40)
1057            *  Original IPv4 header / packet
1058            * Out:
1059            *  New IPv4 header
1060            *  New ICMP header
1061            *  Original IPv4 header / packet
1062            */
1063
1064           /* Need at least ICMP(8) + IPv6(40) + IPv4(20) + L4 header(8) */
1065           if (tlen < 76)
1066             {
1067               error0 = MAP_ERROR_ICMP_RELAY;
1068               goto error;
1069             }
1070
1071           icmp46_header_t *icmp60 = (icmp46_header_t *) (ip60 + 1);
1072           ip6_header_t *inner_ip60 = (ip6_header_t *) (icmp60 + 2);
1073
1074           if (inner_ip60->protocol != IP_PROTOCOL_IP_IN_IP)
1075             {
1076               error0 = MAP_ERROR_ICMP_RELAY;
1077               goto error;
1078             }
1079
1080           ip4_header_t *inner_ip40 = (ip4_header_t *) (inner_ip60 + 1);
1081           vlib_buffer_advance (p0, 60); /* sizeof ( IPv6 + ICMP + IPv6 - IPv4 - ICMP ) */
1082           ip4_header_t *new_ip40 = vlib_buffer_get_current (p0);
1083           icmp46_header_t *new_icmp40 = (icmp46_header_t *) (new_ip40 + 1);
1084
1085           /*
1086            * Relay according to RFC2473, section 8.3
1087            */
1088           switch (icmp60->type)
1089             {
1090             case ICMP6_destination_unreachable:
1091             case ICMP6_time_exceeded:
1092             case ICMP6_parameter_problem:
1093               /* Type 3 - destination unreachable, Code 1 - host unreachable */
1094               new_icmp40->type = ICMP4_destination_unreachable;
1095               new_icmp40->code =
1096                 ICMP4_destination_unreachable_destination_unreachable_host;
1097               break;
1098
1099             case ICMP6_packet_too_big:
1100               /* Type 3 - destination unreachable, Code 4 - packet too big */
1101               /* Potential TODO: Adjust domain tunnel MTU based on the value received here */
1102               mtu = clib_net_to_host_u32 (*((u32 *) (icmp60 + 1)));
1103
1104               /* Check DF flag */
1105               if (!
1106                   (inner_ip40->flags_and_fragment_offset &
1107                    clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT)))
1108                 {
1109                   error0 = MAP_ERROR_ICMP_RELAY;
1110                   goto error;
1111                 }
1112
1113               new_icmp40->type = ICMP4_destination_unreachable;
1114               new_icmp40->code =
1115                 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set;
1116               *((u32 *) (new_icmp40 + 1)) =
1117                 clib_host_to_net_u32 (mtu < 1280 ? 1280 : mtu);
1118               break;
1119
1120             default:
1121               error0 = MAP_ERROR_ICMP_RELAY;
1122               break;
1123             }
1124
1125           /*
1126            * Ensure the total ICMP packet is no longer than 576 bytes (RFC1812)
1127            */
1128           new_ip40->ip_version_and_header_length = 0x45;
1129           new_ip40->tos = 0;
1130           u16 nlen = (tlen - 20) > 576 ? 576 : tlen - 20;
1131           new_ip40->length = clib_host_to_net_u16 (nlen);
1132           new_ip40->fragment_id = fid[0];
1133           fid++;
1134           new_ip40->ttl = 64;
1135           new_ip40->protocol = IP_PROTOCOL_ICMP;
1136           new_ip40->src_address = mm->icmp4_src_address;
1137           new_ip40->dst_address = inner_ip40->src_address;
1138           new_ip40->checksum = ip4_header_checksum (new_ip40);
1139
1140           new_icmp40->checksum = 0;
1141           ip_csum_t sum = ip_incremental_checksum (0, new_icmp40, nlen - 20);
1142           new_icmp40->checksum = ~ip_csum_fold (sum);
1143
1144           vlib_increment_simple_counter (&mm->icmp_relayed, thread_index, 0,
1145                                          1);
1146
1147         error:
1148           if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
1149             {
1150               map_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
1151               tr->map_domain_index = 0;
1152               tr->port = 0;
1153             }
1154
1155           next0 =
1156             (error0 == MAP_ERROR_NONE) ? next0 : IP6_ICMP_RELAY_NEXT_DROP;
1157           p0->error = error_node->errors[error0];
1158           vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1159                                            n_left_to_next, pi0, next0);
1160         }
1161       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1162     }
1163
1164   return frame->n_vectors;
1165
1166 }
1167
1168 static char *map_error_strings[] = {
1169 #define _(sym,string) string,
1170   foreach_map_error
1171 #undef _
1172 };
1173
1174 /* *INDENT-OFF* */
1175 VLIB_REGISTER_NODE(ip6_map_node) = {
1176   .function = ip6_map,
1177   .name = "ip6-map",
1178   .vector_size = sizeof(u32),
1179   .format_trace = format_map_trace,
1180   .type = VLIB_NODE_TYPE_INTERNAL,
1181
1182   .n_errors = MAP_N_ERROR,
1183   .error_strings = map_error_strings,
1184
1185   .n_next_nodes = IP6_MAP_N_NEXT,
1186   .next_nodes = {
1187     [IP6_MAP_NEXT_IP4_LOOKUP] = "ip4-lookup",
1188 #ifdef MAP_SKIP_IP6_LOOKUP
1189     [IP6_MAP_NEXT_IP4_REWRITE] = "ip4-load-balance",
1190 #endif
1191     [IP6_MAP_NEXT_IP6_REASS] = "ip6-map-ip6-reass",
1192     [IP6_MAP_NEXT_IP4_REASS] = "ip6-map-ip4-reass",
1193     [IP6_MAP_NEXT_IP4_FRAGMENT] = "ip4-frag",
1194     [IP6_MAP_NEXT_IP6_ICMP_RELAY] = "ip6-map-icmp-relay",
1195     [IP6_MAP_NEXT_IP6_LOCAL] = "ip6-local",
1196     [IP6_MAP_NEXT_DROP] = "error-drop",
1197     [IP6_MAP_NEXT_ICMP] = "ip6-icmp-error",
1198   },
1199 };
1200 /* *INDENT-ON* */
1201
1202 /* *INDENT-OFF* */
1203 VLIB_REGISTER_NODE(ip6_map_ip6_reass_node) = {
1204   .function = ip6_map_ip6_reass,
1205   .name = "ip6-map-ip6-reass",
1206   .vector_size = sizeof(u32),
1207   .format_trace = format_ip6_map_ip6_reass_trace,
1208   .type = VLIB_NODE_TYPE_INTERNAL,
1209   .n_errors = MAP_N_ERROR,
1210   .error_strings = map_error_strings,
1211   .n_next_nodes = IP6_MAP_IP6_REASS_N_NEXT,
1212   .next_nodes = {
1213     [IP6_MAP_IP6_REASS_NEXT_IP6_MAP] = "ip6-map",
1214     [IP6_MAP_IP6_REASS_NEXT_DROP] = "error-drop",
1215   },
1216 };
1217 /* *INDENT-ON* */
1218
1219 /* *INDENT-OFF* */
1220 VLIB_REGISTER_NODE(ip6_map_ip4_reass_node) = {
1221   .function = ip6_map_ip4_reass,
1222   .name = "ip6-map-ip4-reass",
1223   .vector_size = sizeof(u32),
1224   .format_trace = format_ip6_map_ip4_reass_trace,
1225   .type = VLIB_NODE_TYPE_INTERNAL,
1226   .n_errors = MAP_N_ERROR,
1227   .error_strings = map_error_strings,
1228   .n_next_nodes = IP6_MAP_IP4_REASS_N_NEXT,
1229   .next_nodes = {
1230     [IP6_MAP_IP4_REASS_NEXT_IP4_LOOKUP] = "ip4-lookup",
1231     [IP6_MAP_IP4_REASS_NEXT_IP4_FRAGMENT] = "ip4-frag",
1232     [IP6_MAP_IP4_REASS_NEXT_DROP] = "error-drop",
1233   },
1234 };
1235 /* *INDENT-ON* */
1236
1237 /* *INDENT-OFF* */
1238 VLIB_REGISTER_NODE(ip6_map_icmp_relay_node, static) = {
1239   .function = ip6_map_icmp_relay,
1240   .name = "ip6-map-icmp-relay",
1241   .vector_size = sizeof(u32),
1242   .format_trace = format_map_trace, //FIXME
1243   .type = VLIB_NODE_TYPE_INTERNAL,
1244   .n_errors = MAP_N_ERROR,
1245   .error_strings = map_error_strings,
1246   .n_next_nodes = IP6_ICMP_RELAY_N_NEXT,
1247   .next_nodes = {
1248     [IP6_ICMP_RELAY_NEXT_IP4_LOOKUP] = "ip4-lookup",
1249     [IP6_ICMP_RELAY_NEXT_DROP] = "error-drop",
1250   },
1251 };
1252 /* *INDENT-ON* */
1253
1254 /*
1255  * fd.io coding-style-patch-verification: ON
1256  *
1257  * Local Variables:
1258  * eval: (c-set-style "gnu")
1259  * End:
1260  */