docs: Use newer Ubuntu LTS in tutorial
[vpp.git] / src / vnet / mpls / mpls_output.c
1 /*
2  * mpls_output.c: MPLS Adj rewrite
3  *
4  * Copyright (c) 2012-2014 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <vlib/vlib.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/mpls/mpls.h>
21 #include <vnet/ip/ip_frag.h>
22 #include <vnet/adj/adj_dp.h>
23 #include <vnet/mpls/mpls.api_enum.h>
24
25 typedef struct {
26   /* Adjacency taken. */
27   u32 adj_index;
28   u32 flow_hash;
29 } mpls_output_trace_t;
30
31 typedef enum {
32   MPLS_OUTPUT_MODE,
33   MPLS_OUTPUT_MIDCHAIN_MODE
34 }mpls_output_mode_t;
35
36 #define foreach_mpls_output_next                \
37 _(DROP, "error-drop")                           \
38 _(FRAG, "mpls-frag")
39
40 typedef enum {
41 #define _(s,n) MPLS_OUTPUT_NEXT_##s,
42   foreach_mpls_output_next
43 #undef _
44   MPLS_OUTPUT_N_NEXT,
45 } mpls_output_next_t;
46
47 static u8 *
48 format_mpls_output_trace (u8 * s, va_list * args)
49 {
50   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
51   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
52   mpls_output_trace_t * t = va_arg (*args, mpls_output_trace_t *);
53
54   s = format (s, "adj-idx %d : %U flow hash: 0x%08x",
55               t->adj_index,
56               format_ip_adjacency, t->adj_index, FORMAT_IP_ADJACENCY_NONE,
57               t->flow_hash);
58   return s;
59 }
60
61 static inline uword
62 mpls_output_inline (vlib_main_t * vm,
63                     vlib_node_runtime_t * node,
64                     vlib_frame_t * from_frame,
65                     mpls_output_mode_t mode)
66 {
67   u32 n_left_from, next_index, * from, * to_next, thread_index;
68   vlib_node_runtime_t * error_node;
69   u32 n_left_to_next;
70   mpls_main_t *mm;
71
72   thread_index = vlib_get_thread_index();
73   error_node = vlib_node_get_runtime (vm, mpls_output_node.index);
74   from = vlib_frame_vector_args (from_frame);
75   n_left_from = from_frame->n_vectors;
76   next_index = node->cached_next_index;
77   mm = &mpls_main;
78
79   while (n_left_from > 0)
80     {
81       vlib_get_next_frame (vm, node, next_index,
82                            to_next, n_left_to_next);
83
84       while (n_left_from >= 4 && n_left_to_next >= 2)
85         {
86           ip_adjacency_t * adj0;
87           mpls_unicast_header_t *hdr0;
88           vlib_buffer_t * p0;
89           u32 pi0, adj_index0, next0, error0;
90           word rw_len0;
91
92           ip_adjacency_t * adj1;
93           mpls_unicast_header_t *hdr1;
94           vlib_buffer_t * p1;
95           u32 pi1, adj_index1, next1, error1;
96           word rw_len1;
97
98           /* Prefetch next iteration. */
99           {
100             vlib_buffer_t * p2, * p3;
101
102             p2 = vlib_get_buffer (vm, from[2]);
103             p3 = vlib_get_buffer (vm, from[3]);
104
105             vlib_prefetch_buffer_header (p2, STORE);
106             vlib_prefetch_buffer_header (p3, STORE);
107
108             CLIB_PREFETCH (p2->data, sizeof (hdr0[0]), STORE);
109             CLIB_PREFETCH (p3->data, sizeof (hdr1[0]), STORE);
110           }
111
112           pi0 = to_next[0] = from[0];
113           pi1 = to_next[1] = from[1];
114
115           from += 2;
116           n_left_from -= 2;
117           to_next += 2;
118           n_left_to_next -= 2;
119
120           p0 = vlib_get_buffer (vm, pi0);
121           p1 = vlib_get_buffer (vm, pi1);
122
123           adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
124           adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
125
126           adj0 = adj_get(adj_index0);
127           adj1 = adj_get(adj_index1);
128           hdr0 = vlib_buffer_get_current (p0);
129           hdr1 = vlib_buffer_get_current (p1);
130
131           /* Guess we are only writing on simple Ethernet header. */
132           vnet_rewrite_two_headers (adj0[0], adj1[0], hdr0, hdr1,
133                                    sizeof (ethernet_header_t));
134
135           /* Update packet buffer attributes/set output interface. */
136           rw_len0 = adj0[0].rewrite_header.data_bytes;
137           rw_len1 = adj1[0].rewrite_header.data_bytes;
138           vnet_buffer (p0)->mpls.save_rewrite_length = rw_len0;
139           vnet_buffer (p1)->mpls.save_rewrite_length = rw_len1;
140
141           /* Bump the adj counters for packet and bytes */
142           vlib_increment_combined_counter
143               (&adjacency_counters,
144                thread_index,
145                adj_index0,
146                1,
147                vlib_buffer_length_in_chain (vm, p0) + rw_len0);
148           vlib_increment_combined_counter
149               (&adjacency_counters,
150                thread_index,
151                adj_index1,
152                1,
153                vlib_buffer_length_in_chain (vm, p1) + rw_len1);
154
155           /* Check MTU of outgoing interface. */
156           if (PREDICT_TRUE(vlib_buffer_length_in_chain (vm, p0) <=
157                            adj0[0].rewrite_header.max_l3_packet_bytes))
158             {
159               vlib_buffer_advance(p0, -rw_len0);
160
161               vnet_buffer (p0)->sw_if_index[VLIB_TX] =
162                   adj0[0].rewrite_header.sw_if_index;
163               next0 = adj0[0].rewrite_header.next_index;
164               error0 = IP4_ERROR_NONE;
165
166               if (PREDICT_FALSE(adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
167                 vnet_feature_arc_start (mm->output_feature_arc_index,
168                                         adj0[0].rewrite_header.sw_if_index,
169                                         &next0, p0);
170             }
171           else
172             {
173               error0 = IP4_ERROR_MTU_EXCEEDED;
174               next0 = MPLS_OUTPUT_NEXT_FRAG;
175               vlib_node_increment_counter (vm, mpls_output_node.index,
176                                            MPLS_ERROR_PKTS_NEED_FRAG,
177                                            1);
178             }
179           if (PREDICT_TRUE(vlib_buffer_length_in_chain (vm, p1) <=
180                            adj1[0].rewrite_header.max_l3_packet_bytes))
181             {
182               vlib_buffer_advance(p1, -rw_len1);
183
184               vnet_buffer (p1)->sw_if_index[VLIB_TX] =
185                   adj1[0].rewrite_header.sw_if_index;
186               next1 = adj1[0].rewrite_header.next_index;
187               error1 = IP4_ERROR_NONE;
188
189               if (PREDICT_FALSE(adj1[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
190                 vnet_feature_arc_start (mm->output_feature_arc_index,
191                                         adj1[0].rewrite_header.sw_if_index,
192                                         &next1, p1);
193             }
194           else
195             {
196               error1 = IP4_ERROR_MTU_EXCEEDED;
197               next1 = MPLS_OUTPUT_NEXT_FRAG;
198               vlib_node_increment_counter (vm, mpls_output_node.index,
199                                            MPLS_ERROR_PKTS_NEED_FRAG,
200                                            1);
201             }
202           if (mode == MPLS_OUTPUT_MIDCHAIN_MODE)
203           {
204             adj_midchain_fixup (vm, adj0, p0, VNET_LINK_MPLS);
205             adj_midchain_fixup (vm, adj1, p1, VNET_LINK_MPLS);
206           }
207
208           p0->error = error_node->errors[error0];
209           p1->error = error_node->errors[error1];
210
211           if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
212             {
213               mpls_output_trace_t *tr =
214                 vlib_add_trace (vm, node, p0, sizeof (*tr));
215               tr->adj_index = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
216               tr->flow_hash = vnet_buffer (p0)->ip.flow_hash;
217             }
218           if (PREDICT_FALSE (p1->flags & VLIB_BUFFER_IS_TRACED))
219             {
220               mpls_output_trace_t *tr =
221                 vlib_add_trace (vm, node, p1, sizeof (*tr));
222               tr->adj_index = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
223               tr->flow_hash = vnet_buffer (p1)->ip.flow_hash;
224             }
225
226           vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
227                                            n_left_to_next, pi0, pi1, next0,
228                                            next1);
229         }
230
231       while (n_left_from > 0 && n_left_to_next > 0)
232         {
233           ip_adjacency_t * adj0;
234           mpls_unicast_header_t *hdr0;
235           vlib_buffer_t * p0;
236           u32 pi0, adj_index0, next0, error0;
237           word rw_len0;
238
239           pi0 = to_next[0] = from[0];
240
241           p0 = vlib_get_buffer (vm, pi0);
242
243           adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
244
245           adj0 = adj_get(adj_index0);
246           hdr0 = vlib_buffer_get_current (p0);
247
248           /* Guess we are only writing on simple Ethernet header. */
249           vnet_rewrite_one_header (adj0[0], hdr0,
250                                    sizeof (ethernet_header_t));
251
252           /* Update packet buffer attributes/set output interface. */
253           rw_len0 = adj0[0].rewrite_header.data_bytes;
254           vnet_buffer (p0)->mpls.save_rewrite_length = rw_len0;
255
256           vlib_increment_combined_counter
257               (&adjacency_counters,
258                thread_index,
259                adj_index0,
260                1,
261                vlib_buffer_length_in_chain (vm, p0) + rw_len0);
262
263           /* Check MTU of outgoing interface. */
264           if (PREDICT_TRUE(vlib_buffer_length_in_chain (vm, p0) <=
265                            adj0[0].rewrite_header.max_l3_packet_bytes))
266             {
267               vlib_buffer_advance(p0, -rw_len0);
268
269               vnet_buffer (p0)->sw_if_index[VLIB_TX] =
270                   adj0[0].rewrite_header.sw_if_index;
271               next0 = adj0[0].rewrite_header.next_index;
272               error0 = IP4_ERROR_NONE;
273
274               if (PREDICT_FALSE(adj0[0].rewrite_header.flags & VNET_REWRITE_HAS_FEATURES))
275                 vnet_feature_arc_start (mm->output_feature_arc_index,
276                                         adj0[0].rewrite_header.sw_if_index,
277                                         &next0, p0);
278             }
279           else
280             {
281               error0 = IP4_ERROR_MTU_EXCEEDED;
282               next0 = MPLS_OUTPUT_NEXT_FRAG;
283               vlib_node_increment_counter (vm, mpls_output_node.index,
284                                            MPLS_ERROR_PKTS_NEED_FRAG,
285                                            1);
286             }
287           if (mode == MPLS_OUTPUT_MIDCHAIN_MODE)
288           {
289             adj_midchain_fixup (vm, adj0, p0, VNET_LINK_MPLS);
290           }
291
292           p0->error = error_node->errors[error0];
293
294           from += 1;
295           n_left_from -= 1;
296           to_next += 1;
297           n_left_to_next -= 1;
298
299           if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED))
300             {
301               mpls_output_trace_t *tr = vlib_add_trace (vm, node,
302                                                         p0, sizeof (*tr));
303               tr->adj_index = vnet_buffer(p0)->ip.adj_index[VLIB_TX];
304               tr->flow_hash = vnet_buffer(p0)->ip.flow_hash;
305             }
306
307           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
308                                            to_next, n_left_to_next,
309                                            pi0, next0);
310         }
311
312       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
313     }
314   vlib_node_increment_counter (vm, mpls_output_node.index,
315                                MPLS_ERROR_PKTS_ENCAP,
316                                from_frame->n_vectors);
317
318   return from_frame->n_vectors;
319 }
320
321 VLIB_NODE_FN (mpls_output_node) (vlib_main_t * vm,
322              vlib_node_runtime_t * node,
323              vlib_frame_t * from_frame)
324 {
325     return (mpls_output_inline(vm, node, from_frame, MPLS_OUTPUT_MODE));
326 }
327
328 VLIB_REGISTER_NODE (mpls_output_node) = {
329   .name = "mpls-output",
330   /* Takes a vector of packets. */
331   .vector_size = sizeof (u32),
332   .n_errors = MPLS_N_ERROR,
333   .error_counters = mpls_error_counters,
334
335   .n_next_nodes = MPLS_OUTPUT_N_NEXT,
336   .next_nodes = {
337         [MPLS_OUTPUT_NEXT_DROP] = "mpls-drop",
338         [MPLS_OUTPUT_NEXT_FRAG] = "mpls-frag",
339     },
340   .format_trace = format_mpls_output_trace,
341 };
342
343 VLIB_NODE_FN (mpls_midchain_node) (vlib_main_t * vm,
344                vlib_node_runtime_t * node,
345                vlib_frame_t * from_frame)
346 {
347     return (mpls_output_inline(vm, node, from_frame, MPLS_OUTPUT_MIDCHAIN_MODE));
348 }
349
350 VLIB_REGISTER_NODE (mpls_midchain_node) = {
351   .name = "mpls-midchain",
352   .vector_size = sizeof (u32),
353
354   .n_errors = MPLS_N_ERROR,
355   .error_counters = mpls_error_counters,
356
357   .sibling_of = "mpls-output",
358   .format_trace = format_mpls_output_trace,
359 };
360
361 typedef struct mpls_frag_trace_t_
362 {
363     u16 pkt_size;
364     u16 mtu;
365 } mpls_frag_trace_t;
366
367 typedef enum
368 {
369   MPLS_FRAG_NEXT_REWRITE,
370   MPLS_FRAG_NEXT_REWRITE_MIDCHAIN,
371   MPLS_FRAG_NEXT_ICMP4_ERROR,
372   MPLS_FRAG_NEXT_ICMP6_ERROR,
373   MPLS_FRAG_NEXT_DROP,
374   MPLS_FRAG_N_NEXT,
375 } mpls_frag_next_t;
376
377 static uword
378 mpls_frag (vlib_main_t * vm,
379            vlib_node_runtime_t * node,
380            vlib_frame_t * frame)
381 {
382     u32 n_left_from, next_index, * from, * to_next, n_left_to_next, *frags;
383
384     from = vlib_frame_vector_args (frame);
385     n_left_from = frame->n_vectors;
386     next_index = node->cached_next_index;
387     frags = NULL;
388
389     while (n_left_from > 0)
390     {
391         vlib_get_next_frame (vm, node, next_index,
392                              to_next, n_left_to_next);
393
394         while (n_left_from > 0 && n_left_to_next > 0)
395         {
396             ip_adjacency_t * adj0;
397             vlib_buffer_t * p0;
398             mpls_frag_next_t next0;
399             u32 pi0, adj_index0;
400             ip_frag_error_t error0 = IP_FRAG_ERROR_NONE;
401             i16 encap_size, mtu;
402             u8 is_ip4;
403
404             pi0 = to_next[0] = from[0];
405             p0 = vlib_get_buffer (vm, pi0);
406             from += 1;
407             n_left_from -= 1;
408             is_ip4 = vnet_buffer (p0)->mpls.pyld_proto == DPO_PROTO_IP4;
409
410             adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
411             adj0 = adj_get (adj_index0);
412
413             /* the size of the MPLS stack */
414             encap_size = vnet_buffer (p0)->l3_hdr_offset - p0->current_data;
415             mtu = adj0->rewrite_header.max_l3_packet_bytes - encap_size;
416
417             /* IP fragmentation */
418             if (is_ip4)
419               error0 = ip4_frag_do_fragment (vm, pi0, mtu, encap_size, &frags);
420             else
421               {
422                 if (!(p0->flags & VNET_BUFFER_F_LOCALLY_ORIGINATED))
423                   {
424                     /* only fragment locally generated IPv6 */
425                     error0 = IP_FRAG_ERROR_DONT_FRAGMENT_SET;
426                   }
427                 else
428                   {
429                     error0 =
430                       ip6_frag_do_fragment (vm, pi0, mtu, encap_size, &frags);
431                   }
432               }
433
434             if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
435               {
436                 mpls_frag_trace_t *tr =
437                   vlib_add_trace (vm, node, p0, sizeof (*tr));
438                 tr->mtu = mtu;
439                 tr->pkt_size = vlib_buffer_length_in_chain (vm, p0);
440               }
441
442             if (PREDICT_TRUE (error0 == IP_FRAG_ERROR_NONE))
443               {
444                 /* Free original buffer chain */
445                 vlib_buffer_free_one (vm, pi0);
446                 next0 = (IP_LOOKUP_NEXT_MIDCHAIN == adj0->lookup_next_index ?
447                            MPLS_FRAG_NEXT_REWRITE_MIDCHAIN :
448                            MPLS_FRAG_NEXT_REWRITE);
449               }
450             else
451               {
452                 vlib_error_count (vm, node->node_index, error0, 1);
453
454                 if (error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
455                   {
456                     vlib_buffer_advance (p0, encap_size);
457                     if (is_ip4)
458                       {
459                         icmp4_error_set_vnet_buffer (
460                           p0, ICMP4_destination_unreachable,
461                           ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
462                           mtu);
463                         next0 = MPLS_FRAG_NEXT_ICMP4_ERROR;
464                       }
465                     else
466                       {
467                         icmp6_error_set_vnet_buffer (p0, ICMP6_packet_too_big,
468                                                      0, mtu);
469                         next0 = MPLS_FRAG_NEXT_ICMP6_ERROR;
470                       }
471                   }
472                 else
473                   {
474                     next0 = MPLS_FRAG_NEXT_DROP;
475                   }
476
477                 /* Get rid of the original buffer */
478                 vec_add1 (frags, pi0);
479               }
480
481             /* Send fragments that were added in the frame */
482             u32 *frag_from, frag_left;
483
484             frag_from = frags;
485             frag_left = vec_len (frags);
486
487             while (frag_left > 0)
488               {
489                 while (frag_left > 0 && n_left_to_next > 0)
490                   {
491                     u32 i;
492                     i = to_next[0] = frag_from[0];
493                     frag_from += 1;
494                     frag_left -= 1;
495                     to_next += 1;
496                     n_left_to_next -= 1;
497
498                     vlib_validate_buffer_enqueue_x1 (
499                       vm, node, next_index, to_next, n_left_to_next, i, next0);
500                   }
501                 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
502                 vlib_get_next_frame (vm, node, next_index, to_next,
503                                      n_left_to_next);
504               }
505             vec_reset_length (frags);
506         }
507         vlib_put_next_frame (vm, node, next_index, n_left_to_next);
508     }
509     vec_free (frags);
510
511     return frame->n_vectors;
512 }
513
514 static u8 *
515 format_mpls_frag_trace (u8 * s, va_list * args)
516 {
517     CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
518     CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
519     mpls_frag_trace_t *t = va_arg (*args, mpls_frag_trace_t *);
520
521     s = format (s, "mtu:%d pkt-size:%d", t->mtu, t->pkt_size);
522   return s;
523 }
524
525 VLIB_REGISTER_NODE (mpls_frag_node) = {
526   .function = mpls_frag,
527   .name = "mpls-frag",
528   .vector_size = sizeof (u32),
529   .format_trace = format_mpls_frag_trace,
530   .type = VLIB_NODE_TYPE_INTERNAL,
531
532   .n_errors = IP_FRAG_N_ERROR,
533   .error_counters = ip_frag_error_counters,
534
535   .n_next_nodes = MPLS_FRAG_N_NEXT,
536   .next_nodes = { [MPLS_FRAG_NEXT_REWRITE] = "mpls-output",
537                   [MPLS_FRAG_NEXT_REWRITE_MIDCHAIN] = "mpls-midchain",
538                   [MPLS_FRAG_NEXT_ICMP4_ERROR] = "ip4-icmp-error",
539                   [MPLS_FRAG_NEXT_ICMP6_ERROR] = "ip6-icmp-error",
540                   [MPLS_FRAG_NEXT_DROP] = "mpls-drop" },
541 };
542
543 /*
544  * @brief Next index values from the MPLS incomplete adj node
545  */
546 #define foreach_mpls_adj_incomplete_next        \
547 _(DROP, "error-drop")                   \
548 _(IP4,  "ip4-arp")                      \
549 _(IP6,  "ip6-discover-neighbor")
550
551 typedef enum {
552 #define _(s,n) MPLS_ADJ_INCOMPLETE_NEXT_##s,
553   foreach_mpls_adj_incomplete_next
554 #undef _
555   MPLS_ADJ_INCOMPLETE_N_NEXT,
556 } mpls_adj_incomplete_next_t;
557
558 /**
559  * @brief A struct to hold tracing information for the MPLS label imposition
560  * node.
561  */
562 typedef struct mpls_adj_incomplete_trace_t_
563 {
564     u32 next;
565 } mpls_adj_incomplete_trace_t;
566
567
568 /**
569  * @brief Graph node for incomplete MPLS adjacency.
570  * This node will push traffic to either the v4-arp or v6-nd node
571  * based on the next-hop proto of the adj.
572  * We pay a cost for this 'routing' node, but an incomplete adj is the
573  * exception case.
574  */
575 VLIB_NODE_FN (mpls_adj_incomplete_node) (vlib_main_t * vm,
576                      vlib_node_runtime_t * node,
577                      vlib_frame_t * from_frame)
578 {
579     u32 n_left_from, next_index, * from, * to_next;
580
581   from = vlib_frame_vector_args (from_frame);
582   n_left_from = from_frame->n_vectors;
583   next_index = node->cached_next_index;
584
585   while (n_left_from > 0)
586     {
587       u32 n_left_to_next;
588
589       vlib_get_next_frame (vm, node, next_index,
590                            to_next, n_left_to_next);
591
592       while (n_left_from > 0 && n_left_to_next > 0)
593         {
594           u32 pi0, next0, adj_index0;
595           ip_adjacency_t * adj0;
596           vlib_buffer_t * p0;
597
598           pi0 = to_next[0] = from[0];
599           p0 = vlib_get_buffer (vm, pi0);
600           from += 1;
601           n_left_from -= 1;
602           to_next += 1;
603           n_left_to_next -= 1;
604
605           adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
606
607           adj0 = adj_get(adj_index0);
608
609           if (PREDICT_TRUE(FIB_PROTOCOL_IP4 == adj0->ia_nh_proto))
610           {
611               next0 = MPLS_ADJ_INCOMPLETE_NEXT_IP4;
612           }
613           else
614           {
615               next0 = MPLS_ADJ_INCOMPLETE_NEXT_IP6;
616           }
617
618           if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED))
619           {
620               mpls_adj_incomplete_trace_t *tr =
621                   vlib_add_trace (vm, node, p0, sizeof (*tr));
622               tr->next = next0;
623           }
624
625           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
626                                            to_next, n_left_to_next,
627                                            pi0, next0);
628         }
629
630       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
631     }
632
633   return from_frame->n_vectors;
634 }
635
636 static u8 *
637 format_mpls_adj_incomplete_trace (u8 * s, va_list * args)
638 {
639     CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
640     CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
641     mpls_adj_incomplete_trace_t * t;
642     u32 indent;
643
644     t = va_arg (*args, mpls_adj_incomplete_trace_t *);
645     indent = format_get_indent (s);
646
647     s = format (s, "%Unext:%d",
648                 format_white_space, indent,
649                 t->next);
650     return (s);
651 }
652
653 VLIB_REGISTER_NODE (mpls_adj_incomplete_node) = {
654   .name = "mpls-adj-incomplete",
655   .format_trace = format_mpls_adj_incomplete_trace,
656   /* Takes a vector of packets. */
657   .vector_size = sizeof (u32),
658   .n_errors = MPLS_N_ERROR,
659   .error_counters = mpls_error_counters,
660
661   .n_next_nodes = MPLS_ADJ_INCOMPLETE_N_NEXT,
662   .next_nodes = {
663 #define _(s,n) [MPLS_ADJ_INCOMPLETE_NEXT_##s] = n,
664     foreach_mpls_adj_incomplete_next
665 #undef _
666   },
667 };