7999507618acb3507f93b5fff95e6437ad7d9443
[vpp.git] / src / plugins / map / ip6_map_t.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/ip4_to_ip6.h>
18 #include <vnet/ip/ip6_to_ip4.h>
19 #include <vnet/ip/ip_frag.h>
20
21 typedef enum
22 {
23   IP6_MAPT_NEXT_MAPT_TCP_UDP,
24   IP6_MAPT_NEXT_MAPT_ICMP,
25   IP6_MAPT_NEXT_MAPT_FRAGMENTED,
26   IP6_MAPT_NEXT_DROP,
27   IP6_MAPT_N_NEXT
28 } ip6_mapt_next_t;
29
30 typedef enum
31 {
32   IP6_MAPT_ICMP_NEXT_IP4_LOOKUP,
33   IP6_MAPT_ICMP_NEXT_IP4_FRAG,
34   IP6_MAPT_ICMP_NEXT_DROP,
35   IP6_MAPT_ICMP_N_NEXT
36 } ip6_mapt_icmp_next_t;
37
38 typedef enum
39 {
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;
45
46 typedef enum
47 {
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;
53
54 typedef struct
55 {
56   map_domain_t *d;
57   u16 sender_port;
58 } icmp6_to_icmp_ctx_t;
59
60 static int
61 ip6_to_ip4_set_icmp_cb (ip6_header_t * ip6, ip4_header_t * ip4, void *arg)
62 {
63   icmp6_to_icmp_ctx_t *ctx = arg;
64   u32 ip4_sadr;
65
66   // Security check
67   // Note that this prevents an intermediate IPv6 router from answering
68   // the request.
69   ip4_sadr = map_get_ip4 (&ip6->src_address, ctx->d->flags);
70   if (ip6->src_address.as_u64[0] !=
71       map_get_pfx_net (ctx->d, ip4_sadr, ctx->sender_port)
72       || ip6->src_address.as_u64[1] != map_get_sfx_net (ctx->d, ip4_sadr,
73                                                         ctx->sender_port))
74     return -1;
75
76   ip4->dst_address.as_u32 =
77     ip6_map_t_embedded_address (ctx->d, &ip6->dst_address);
78   ip4->src_address.as_u32 = ip4_sadr;
79
80   return 0;
81 }
82
83 static int
84 ip6_to_ip4_set_inner_icmp_cb (ip6_header_t * ip6, ip4_header_t * ip4,
85                               void *arg)
86 {
87   icmp6_to_icmp_ctx_t *ctx = arg;
88   u32 inner_ip4_dadr;
89
90   //Security check of inner packet
91   inner_ip4_dadr = map_get_ip4 (&ip6->dst_address, ctx->d->flags);
92   if (ip6->dst_address.as_u64[0] !=
93       map_get_pfx_net (ctx->d, inner_ip4_dadr, ctx->sender_port)
94       || ip6->dst_address.as_u64[1] != map_get_sfx_net (ctx->d,
95                                                         inner_ip4_dadr,
96                                                         ctx->sender_port))
97     return -1;
98
99   ip4->dst_address.as_u32 = inner_ip4_dadr;
100   ip4->src_address.as_u32 =
101     ip6_map_t_embedded_address (ctx->d, &ip6->src_address);
102
103   return 0;
104 }
105
106 static uword
107 ip6_map_t_icmp (vlib_main_t * vm,
108                 vlib_node_runtime_t * node, vlib_frame_t * frame)
109 {
110   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
111   vlib_node_runtime_t *error_node =
112     vlib_node_get_runtime (vm, ip6_map_t_icmp_node.index);
113   from = vlib_frame_vector_args (frame);
114   n_left_from = frame->n_vectors;
115   next_index = node->cached_next_index;
116   vlib_combined_counter_main_t *cm = map_main.domain_counters;
117   u32 thread_index = vm->thread_index;
118
119   while (n_left_from > 0)
120     {
121       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
122
123       while (n_left_from > 0 && n_left_to_next > 0)
124         {
125           u32 pi0;
126           vlib_buffer_t *p0;
127           u8 error0;
128           ip6_mapt_icmp_next_t next0;
129           map_domain_t *d0;
130           u16 len0;
131           icmp6_to_icmp_ctx_t ctx0;
132           ip6_header_t *ip60;
133
134           pi0 = to_next[0] = from[0];
135           from += 1;
136           n_left_from -= 1;
137           to_next += 1;
138           n_left_to_next -= 1;
139           error0 = MAP_ERROR_NONE;
140           next0 = IP6_MAPT_ICMP_NEXT_IP4_LOOKUP;
141
142           p0 = vlib_get_buffer (vm, pi0);
143           ip60 = vlib_buffer_get_current (p0);
144           len0 = clib_net_to_host_u16 (ip60->payload_length);
145           d0 =
146             pool_elt_at_index (map_main.domains,
147                                vnet_buffer (p0)->map_t.map_domain_index);
148           ctx0.sender_port = ip6_get_port (ip60, 0, p0->current_length);
149           ctx0.d = d0;
150           if (ctx0.sender_port == 0)
151             {
152               // In case of 1:1 mapping, we don't care about the port
153               if (!(d0->ea_bits_len == 0 && d0->rules))
154                 {
155                   error0 = MAP_ERROR_ICMP;
156                   goto err0;
157                 }
158             }
159
160           if (icmp6_to_icmp
161               (p0, ip6_to_ip4_set_icmp_cb, &ctx0,
162                ip6_to_ip4_set_inner_icmp_cb, &ctx0))
163             {
164               error0 = MAP_ERROR_ICMP;
165               goto err0;
166             }
167
168           if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
169             {
170               // Send to fragmentation node if necessary
171               vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
172               vnet_buffer (p0)->ip_frag.next_index = IP_FRAG_NEXT_IP4_LOOKUP;
173               next0 = IP6_MAPT_ICMP_NEXT_IP4_FRAG;
174             }
175         err0:
176           if (PREDICT_TRUE (error0 == MAP_ERROR_NONE))
177             {
178               vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
179                                                thread_index,
180                                                vnet_buffer (p0)->
181                                                map_t.map_domain_index, 1,
182                                                len0);
183             }
184           else
185             {
186               next0 = IP6_MAPT_ICMP_NEXT_DROP;
187             }
188
189           p0->error = error_node->errors[error0];
190           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
191                                            to_next, n_left_to_next, pi0,
192                                            next0);
193         }
194       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
195     }
196   return frame->n_vectors;
197 }
198
199 /*
200  * Translate IPv6 fragmented packet to IPv4.
201  */
202 always_inline int
203 map_ip6_to_ip4_fragmented (vlib_buffer_t * p)
204 {
205   ip6_header_t *ip6;
206   ip6_frag_hdr_t *frag;
207   ip4_header_t *ip4;
208   u16 frag_id;
209   u8 frag_more;
210   u16 frag_offset;
211   u8 l4_protocol;
212   u16 l4_offset;
213
214   ip6 = vlib_buffer_get_current (p);
215
216   if (ip6_parse
217       (ip6, p->current_length, &l4_protocol, &l4_offset, &frag_offset))
218     return -1;
219
220   frag = (ip6_frag_hdr_t *) u8_ptr_add (ip6, frag_offset);
221   ip4 = (ip4_header_t *) u8_ptr_add (ip6, l4_offset - sizeof (*ip4));
222   vlib_buffer_advance (p, l4_offset - sizeof (*ip4));
223
224   frag_id = frag_id_6to4 (frag->identification);
225   frag_more = ip6_frag_hdr_more (frag);
226   frag_offset = ip6_frag_hdr_offset (frag);
227
228   ip4->dst_address.as_u32 = vnet_buffer (p)->map_t.v6.daddr;
229   ip4->src_address.as_u32 = vnet_buffer (p)->map_t.v6.saddr;
230
231   ip4->ip_version_and_header_length =
232     IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
233   ip4->tos = ip6_translate_tos (ip6);
234   ip4->length =
235     u16_net_add (ip6->payload_length,
236                  sizeof (*ip4) - l4_offset + sizeof (*ip6));
237   ip4->fragment_id = frag_id;
238   ip4->flags_and_fragment_offset =
239     clib_host_to_net_u16 (frag_offset |
240                           (frag_more ? IP4_HEADER_FLAG_MORE_FRAGMENTS : 0));
241   ip4->ttl = ip6->hop_limit;
242   ip4->protocol =
243     (l4_protocol == IP_PROTOCOL_ICMP6) ? IP_PROTOCOL_ICMP : l4_protocol;
244   ip4->checksum = ip4_header_checksum (ip4);
245
246   return 0;
247 }
248
249 static uword
250 ip6_map_t_fragmented (vlib_main_t * vm,
251                       vlib_node_runtime_t * node, vlib_frame_t * frame)
252 {
253   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
254   from = vlib_frame_vector_args (frame);
255   n_left_from = frame->n_vectors;
256   next_index = node->cached_next_index;
257   vlib_node_runtime_t *error_node =
258     vlib_node_get_runtime (vm, ip6_map_t_fragmented_node.index);
259
260   while (n_left_from > 0)
261     {
262       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
263
264       while (n_left_from > 0 && n_left_to_next > 0)
265         {
266           u32 pi0;
267           vlib_buffer_t *p0;
268           u32 next0;
269
270           pi0 = to_next[0] = from[0];
271           from += 1;
272           n_left_from -= 1;
273           to_next += 1;
274           n_left_to_next -= 1;
275
276           next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
277           p0 = vlib_get_buffer (vm, pi0);
278
279           if (map_ip6_to_ip4_fragmented (p0))
280             {
281               p0->error = error_node->errors[MAP_ERROR_FRAGMENT_DROPPED];
282               next0 = IP6_MAPT_FRAGMENTED_NEXT_DROP;
283             }
284           else
285             {
286               if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
287                 {
288                   // Send to fragmentation node if necessary
289                   vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
290                   vnet_buffer (p0)->ip_frag.next_index =
291                     IP_FRAG_NEXT_IP4_LOOKUP;
292                   next0 = IP6_MAPT_FRAGMENTED_NEXT_IP4_FRAG;
293                 }
294             }
295
296           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
297                                            to_next, n_left_to_next, pi0,
298                                            next0);
299         }
300       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
301     }
302   return frame->n_vectors;
303 }
304
305 /*
306  * Translate IPv6 UDP/TCP packet to IPv4.
307  */
308 always_inline int
309 map_ip6_to_ip4_tcp_udp (vlib_buffer_t * p, bool udp_checksum)
310 {
311   map_main_t *mm = &map_main;
312   ip6_header_t *ip6;
313   u16 *checksum;
314   ip_csum_t csum = 0;
315   ip4_header_t *ip4;
316   u16 fragment_id;
317   u16 flags;
318   u16 frag_offset;
319   u8 l4_protocol;
320   u16 l4_offset;
321   ip6_address_t old_src, old_dst;
322
323   ip6 = vlib_buffer_get_current (p);
324
325   if (ip6_parse
326       (ip6, p->current_length, &l4_protocol, &l4_offset, &frag_offset))
327     return -1;
328
329   if (l4_protocol == IP_PROTOCOL_TCP)
330     {
331       tcp_header_t *tcp = ip6_next_header (ip6);
332       if (mm->tcp_mss > 0)
333         {
334           csum = tcp->checksum;
335           map_mss_clamping (tcp, &csum, mm->tcp_mss);
336           tcp->checksum = ip_csum_fold (csum);
337         }
338       checksum = &tcp->checksum;
339     }
340   else
341     {
342       udp_header_t *udp = ip6_next_header (ip6);
343       checksum = &udp->checksum;
344     }
345
346   old_src.as_u64[0] = ip6->src_address.as_u64[0];
347   old_src.as_u64[1] = ip6->src_address.as_u64[1];
348   old_dst.as_u64[0] = ip6->dst_address.as_u64[0];
349   old_dst.as_u64[1] = ip6->dst_address.as_u64[1];
350
351   ip4 = (ip4_header_t *) u8_ptr_add (ip6, l4_offset - sizeof (*ip4));
352
353   vlib_buffer_advance (p, l4_offset - sizeof (*ip4));
354
355   if (PREDICT_FALSE (frag_offset))
356     {
357       // Only the first fragment
358       ip6_frag_hdr_t *hdr = (ip6_frag_hdr_t *) u8_ptr_add (ip6, frag_offset);
359       fragment_id = frag_id_6to4 (hdr->identification);
360       flags = clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS);
361     }
362   else
363     {
364       fragment_id = 0;
365       flags = 0;
366     }
367
368   ip4->dst_address.as_u32 = vnet_buffer (p)->map_t.v6.daddr;
369   ip4->src_address.as_u32 = vnet_buffer (p)->map_t.v6.saddr;
370
371   ip4->ip_version_and_header_length =
372     IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS;
373   ip4->tos = ip6_translate_tos (ip6);
374   ip4->length =
375     u16_net_add (ip6->payload_length,
376                  sizeof (*ip4) + sizeof (*ip6) - l4_offset);
377   ip4->fragment_id = fragment_id;
378   ip4->flags_and_fragment_offset = flags;
379   ip4->ttl = ip6->hop_limit;
380   ip4->protocol = l4_protocol;
381   ip4->checksum = ip4_header_checksum (ip4);
382
383   // UDP checksum is optional over IPv4
384   if (!udp_checksum && l4_protocol == IP_PROTOCOL_UDP)
385     {
386       *checksum = 0;
387     }
388   else
389     {
390       csum = ip_csum_sub_even (*checksum, old_src.as_u64[0]);
391       csum = ip_csum_sub_even (csum, old_src.as_u64[1]);
392       csum = ip_csum_sub_even (csum, old_dst.as_u64[0]);
393       csum = ip_csum_sub_even (csum, old_dst.as_u64[1]);
394       csum = ip_csum_add_even (csum, ip4->dst_address.as_u32);
395       csum = ip_csum_add_even (csum, ip4->src_address.as_u32);
396       *checksum = ip_csum_fold (csum);
397     }
398
399   return 0;
400 }
401
402 static uword
403 ip6_map_t_tcp_udp (vlib_main_t * vm,
404                    vlib_node_runtime_t * node, vlib_frame_t * frame)
405 {
406   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
407   vlib_node_runtime_t *error_node =
408     vlib_node_get_runtime (vm, ip6_map_t_tcp_udp_node.index);
409
410   from = vlib_frame_vector_args (frame);
411   n_left_from = frame->n_vectors;
412   next_index = node->cached_next_index;
413   while (n_left_from > 0)
414     {
415       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
416
417       while (n_left_from > 0 && n_left_to_next > 0)
418         {
419           u32 pi0;
420           vlib_buffer_t *p0;
421           ip6_mapt_tcp_udp_next_t next0;
422
423           pi0 = to_next[0] = from[0];
424           from += 1;
425           n_left_from -= 1;
426           to_next += 1;
427           n_left_to_next -= 1;
428           next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP;
429
430           p0 = vlib_get_buffer (vm, pi0);
431
432           if (map_ip6_to_ip4_tcp_udp (p0, true))
433             {
434               p0->error = error_node->errors[MAP_ERROR_UNKNOWN];
435               next0 = IP6_MAPT_TCP_UDP_NEXT_DROP;
436             }
437           else
438             {
439               if (vnet_buffer (p0)->map_t.mtu < p0->current_length)
440                 {
441                   // Send to fragmentation node if necessary
442                   vnet_buffer (p0)->ip_frag.mtu = vnet_buffer (p0)->map_t.mtu;
443                   vnet_buffer (p0)->ip_frag.next_index =
444                     IP_FRAG_NEXT_IP4_LOOKUP;
445                   next0 = IP6_MAPT_TCP_UDP_NEXT_IP4_FRAG;
446                 }
447             }
448
449           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
450                                            to_next, n_left_to_next, pi0,
451                                            next0);
452         }
453       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
454     }
455   return frame->n_vectors;
456 }
457
458 static uword
459 ip6_map_t (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
460 {
461   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
462   vlib_node_runtime_t *error_node =
463     vlib_node_get_runtime (vm, ip6_map_t_node.index);
464   vlib_combined_counter_main_t *cm = map_main.domain_counters;
465   u32 thread_index = vm->thread_index;
466
467   from = vlib_frame_vector_args (frame);
468   n_left_from = frame->n_vectors;
469   next_index = node->cached_next_index;
470   while (n_left_from > 0)
471     {
472       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
473
474       while (n_left_from > 0 && n_left_to_next > 0)
475         {
476           u32 pi0;
477           vlib_buffer_t *p0;
478           ip6_header_t *ip60;
479           u8 error0;
480           u32 l4_len0;
481           i32 map_port0;
482           map_domain_t *d0;
483           ip6_frag_hdr_t *frag0;
484           ip6_mapt_next_t next0 = 0;
485           u32 saddr;
486
487           pi0 = to_next[0] = from[0];
488           from += 1;
489           n_left_from -= 1;
490           to_next += 1;
491           n_left_to_next -= 1;
492           error0 = MAP_ERROR_NONE;
493           p0 = vlib_get_buffer (vm, pi0);
494           u16 l4_src_port = vnet_buffer (p0)->ip.reass.l4_src_port;
495
496           ip60 = vlib_buffer_get_current (p0);
497
498           d0 =
499             ip6_map_get_domain (&ip60->dst_address,
500                                 &vnet_buffer (p0)->map_t.map_domain_index,
501                                 &error0);
502           if (!d0)
503             {                   /* Guess it wasn't for us */
504               vnet_feature_next (&next0, p0);
505               goto exit;
506             }
507
508           saddr = map_get_ip4 (&ip60->src_address, d0->ip6_src_len);
509           vnet_buffer (p0)->map_t.v6.saddr = saddr;
510           vnet_buffer (p0)->map_t.v6.daddr =
511             ip6_map_t_embedded_address (d0, &ip60->dst_address);
512           vnet_buffer (p0)->map_t.mtu = d0->mtu ? d0->mtu : ~0;
513
514           if (PREDICT_FALSE
515               (ip6_parse (ip60, p0->current_length,
516                           &(vnet_buffer (p0)->map_t.v6.l4_protocol),
517                           &(vnet_buffer (p0)->map_t.v6.l4_offset),
518                           &(vnet_buffer (p0)->map_t.v6.frag_offset))))
519             {
520               error0 =
521                 error0 == MAP_ERROR_NONE ? MAP_ERROR_MALFORMED : error0;
522             }
523
524           map_port0 = -1;
525           l4_len0 =
526             (u32) clib_net_to_host_u16 (ip60->payload_length) +
527             sizeof (*ip60) - vnet_buffer (p0)->map_t.v6.l4_offset;
528           frag0 =
529             (ip6_frag_hdr_t *) u8_ptr_add (ip60,
530                                            vnet_buffer (p0)->map_t.v6.
531                                            frag_offset);
532
533           if (PREDICT_FALSE
534               (vnet_buffer (p0)->map_t.v6.frag_offset
535                && ip6_frag_hdr_offset (frag0)))
536             {
537               map_port0 = l4_src_port;
538               next0 = IP6_MAPT_NEXT_MAPT_FRAGMENTED;
539             }
540           else
541             if (PREDICT_TRUE
542                 (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_TCP))
543             {
544               error0 =
545                 l4_len0 <
546                 sizeof (tcp_header_t) ? MAP_ERROR_MALFORMED : error0;
547               vnet_buffer (p0)->map_t.checksum_offset =
548                 vnet_buffer (p0)->map_t.v6.l4_offset + 16;
549               next0 = IP6_MAPT_NEXT_MAPT_TCP_UDP;
550               map_port0 = l4_src_port;
551             }
552           else
553             if (PREDICT_TRUE
554                 (vnet_buffer (p0)->map_t.v6.l4_protocol == IP_PROTOCOL_UDP))
555             {
556               error0 =
557                 l4_len0 <
558                 sizeof (udp_header_t) ? MAP_ERROR_MALFORMED : error0;
559               vnet_buffer (p0)->map_t.checksum_offset =
560                 vnet_buffer (p0)->map_t.v6.l4_offset + 6;
561               next0 = IP6_MAPT_NEXT_MAPT_TCP_UDP;
562               map_port0 = l4_src_port;
563             }
564           else if (vnet_buffer (p0)->map_t.v6.l4_protocol ==
565                    IP_PROTOCOL_ICMP6)
566             {
567               error0 =
568                 l4_len0 <
569                 sizeof (icmp46_header_t) ? MAP_ERROR_MALFORMED : error0;
570               next0 = IP6_MAPT_NEXT_MAPT_ICMP;
571               if (((icmp46_header_t *)
572                    u8_ptr_add (ip60,
573                                vnet_buffer (p0)->map_t.v6.l4_offset))->code ==
574                   ICMP6_echo_reply
575                   || ((icmp46_header_t *)
576                       u8_ptr_add (ip60,
577                                   vnet_buffer (p0)->map_t.v6.l4_offset))->
578                   code == ICMP6_echo_request)
579                 map_port0 = l4_src_port;
580             }
581           else
582             {
583               // TODO: In case of 1:1 mapping, it might be possible to
584               // do something with those packets.
585               error0 = MAP_ERROR_BAD_PROTOCOL;
586             }
587
588           if (PREDICT_FALSE (map_port0 != -1) &&
589               (ip60->src_address.as_u64[0] !=
590                map_get_pfx_net (d0, vnet_buffer (p0)->map_t.v6.saddr,
591                                 map_port0)
592                || ip60->src_address.as_u64[1] != map_get_sfx_net (d0,
593                                                                   vnet_buffer
594                                                                   (p0)->map_t.
595                                                                   v6.saddr,
596                                                                   map_port0)))
597             {
598               // Security check when map_port0 is not zero (non-first
599               // fragment, UDP or TCP)
600               error0 =
601                 error0 == MAP_ERROR_NONE ? MAP_ERROR_SEC_CHECK : error0;
602             }
603
604           if (PREDICT_TRUE
605               (error0 == MAP_ERROR_NONE && next0 != IP6_MAPT_NEXT_MAPT_ICMP))
606             {
607               vlib_increment_combined_counter (cm + MAP_DOMAIN_COUNTER_RX,
608                                                thread_index,
609                                                vnet_buffer (p0)->map_t.
610                                                map_domain_index, 1,
611                                                clib_net_to_host_u16 (ip60->
612                                                                      payload_length));
613             }
614
615           next0 = (error0 != MAP_ERROR_NONE) ? IP6_MAPT_NEXT_DROP : next0;
616           p0->error = error_node->errors[error0];
617           if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
618             {
619               map_add_trace (vm, node, p0,
620                              vnet_buffer (p0)->map_t.map_domain_index,
621                              map_port0);
622             }
623         exit:
624           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
625                                            to_next, n_left_to_next, pi0,
626                                            next0);
627         }
628       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
629     }
630   return frame->n_vectors;
631 }
632
633 static char *map_t_error_strings[] = {
634 #define _(sym, string) string,
635   foreach_map_error
636 #undef _
637 };
638
639 /* *INDENT-OFF* */
640 VLIB_REGISTER_NODE(ip6_map_t_fragmented_node) = {
641   .function = ip6_map_t_fragmented,
642   .name = "ip6-map-t-fragmented",
643   .vector_size = sizeof (u32),
644   .format_trace = format_map_trace,
645   .type = VLIB_NODE_TYPE_INTERNAL,
646
647   .n_errors = MAP_N_ERROR,
648   .error_strings = map_t_error_strings,
649
650   .n_next_nodes = IP6_MAPT_FRAGMENTED_N_NEXT,
651   .next_nodes =
652   {
653     [IP6_MAPT_FRAGMENTED_NEXT_IP4_LOOKUP] = "ip4-lookup",
654     [IP6_MAPT_FRAGMENTED_NEXT_IP4_FRAG] = IP4_FRAG_NODE_NAME,
655     [IP6_MAPT_FRAGMENTED_NEXT_DROP] = "error-drop",
656   },
657 };
658 /* *INDENT-ON* */
659
660 /* *INDENT-OFF* */
661 VLIB_REGISTER_NODE(ip6_map_t_icmp_node) = {
662   .function = ip6_map_t_icmp,
663   .name = "ip6-map-t-icmp",
664   .vector_size = sizeof (u32),
665   .format_trace = format_map_trace,
666   .type = VLIB_NODE_TYPE_INTERNAL,
667
668   .n_errors = MAP_N_ERROR,
669   .error_strings = map_t_error_strings,
670
671   .n_next_nodes = IP6_MAPT_ICMP_N_NEXT,
672   .next_nodes =
673   {
674     [IP6_MAPT_ICMP_NEXT_IP4_LOOKUP] = "ip4-lookup",
675     [IP6_MAPT_ICMP_NEXT_IP4_FRAG] = IP4_FRAG_NODE_NAME,
676     [IP6_MAPT_ICMP_NEXT_DROP] = "error-drop",
677   },
678 };
679 /* *INDENT-ON* */
680
681 /* *INDENT-OFF* */
682 VLIB_REGISTER_NODE(ip6_map_t_tcp_udp_node) = {
683   .function = ip6_map_t_tcp_udp,
684   .name = "ip6-map-t-tcp-udp",
685   .vector_size = sizeof (u32),
686   .format_trace = format_map_trace,
687   .type = VLIB_NODE_TYPE_INTERNAL,
688
689   .n_errors = MAP_N_ERROR,
690   .error_strings = map_t_error_strings,
691
692   .n_next_nodes = IP6_MAPT_TCP_UDP_N_NEXT,
693   .next_nodes =
694   {
695     [IP6_MAPT_TCP_UDP_NEXT_IP4_LOOKUP] = "ip4-lookup",
696     [IP6_MAPT_TCP_UDP_NEXT_IP4_FRAG] = IP4_FRAG_NODE_NAME,
697     [IP6_MAPT_TCP_UDP_NEXT_DROP] = "error-drop",
698   },
699 };
700 /* *INDENT-ON* */
701
702 /* *INDENT-OFF* */
703 VNET_FEATURE_INIT (ip6_map_t_feature, static) = {
704     .arc_name = "ip6-unicast",
705     .node_name = "ip6-map-t",
706     .runs_before = VNET_FEATURES ("ip6-flow-classify"),
707     .runs_after = VNET_FEATURES ("ip6-sv-reassembly-feature"),
708 };
709
710 VLIB_REGISTER_NODE(ip6_map_t_node) = {
711   .function = ip6_map_t,
712   .name = "ip6-map-t",
713   .vector_size = sizeof(u32),
714   .format_trace = format_map_trace,
715   .type = VLIB_NODE_TYPE_INTERNAL,
716
717   .n_errors = MAP_N_ERROR,
718   .error_strings = map_t_error_strings,
719
720   .n_next_nodes = IP6_MAPT_N_NEXT,
721   .next_nodes =
722   {
723     [IP6_MAPT_NEXT_MAPT_TCP_UDP] = "ip6-map-t-tcp-udp",
724     [IP6_MAPT_NEXT_MAPT_ICMP] = "ip6-map-t-icmp",
725     [IP6_MAPT_NEXT_MAPT_FRAGMENTED] = "ip6-map-t-fragmented",
726     [IP6_MAPT_NEXT_DROP] = "error-drop",
727   },
728 };
729 /* *INDENT-ON* */
730
731 /*
732  * fd.io coding-style-patch-verification: ON
733  *
734  * Local Variables:
735  * eval: (c-set-style "gnu")
736  * End:
737  */