FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
mpls_label_dpo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 
16 #include <vnet/ip/ip.h>
18 #include <vnet/mpls/mpls.h>
19 #include <vnet/dpo/drop_dpo.h>
20 
21 /*
22  * pool of all MPLS Label DPOs
23  */
25 
26 /**
27  * Strings for the flags
28  */
30 
31 /**
32  * registered DPO types for each of the label sub-types. And there's a
33  * subtype for each of the flag combinations.
34  */
36 
37 static mpls_label_dpo_t *
39 {
40  mpls_label_dpo_t *mld;
41 
42  pool_get_aligned(mpls_label_dpo_pool, mld, CLIB_CACHE_LINE_BYTES);
43  memset(mld, 0, sizeof(*mld));
44 
45  dpo_reset(&mld->mld_dpo);
46 
47  return (mld);
48 }
49 
50 static index_t
52 {
53  return (mld - mpls_label_dpo_pool);
54 }
55 
56 void
58  mpls_eos_bit_t eos,
59  dpo_proto_t payload_proto,
61  const dpo_id_t *parent,
62  dpo_id_t *dpo)
63 {
64  mpls_label_dpo_t *mld;
65  dpo_type_t dtype;
66  u32 ii;
67 
68  if ((DPO_PROTO_IP4 != payload_proto) &&
69  (DPO_PROTO_IP6 != payload_proto))
70  {
71  /*
72  * remove unsupported configuration
73  */
75  }
76 
77  mld = mpls_label_dpo_alloc();
78  mld->mld_flags = flags;
79  dtype = mpls_label_dpo_types[flags];
80 
81  if (MPLS_LABEL_DPO_MAX_N_LABELS < vec_len(label_stack))
82  {
83  clib_warning("Label stack size exceeded");
84  dpo_stack(dtype,
85  mld->mld_payload_proto,
86  &mld->mld_dpo,
88  }
89  else
90  {
91  mld->mld_n_labels = vec_len(label_stack);
92  mld->mld_n_hdr_bytes = mld->mld_n_labels * sizeof(mld->mld_hdr[0]);
93  mld->mld_payload_proto = payload_proto;
94 
95  /*
96  * construct label rewrite headers for each value passed.
97  * get the header in network byte order since we will paint it
98  * on a packet in the data-plane
99  */
100  for (ii = 0; ii < mld->mld_n_labels-1; ii++)
101  {
103  label_stack[ii].fml_value);
105  label_stack[ii].fml_exp);
107  MPLS_NON_EOS);
108  if (0 != label_stack[ii].fml_ttl)
109  {
111  label_stack[ii].fml_ttl);
112  }
113  else
114  {
117  }
118  mld->mld_hdr[ii].label_exp_s_ttl =
119  clib_host_to_net_u32(mld->mld_hdr[ii].label_exp_s_ttl);
120  }
121 
122  /*
123  * the inner most label
124  */
125  ii = mld->mld_n_labels-1;
126 
128  label_stack[ii].fml_value);
130  label_stack[ii].fml_exp);
132  if (0 != label_stack[ii].fml_ttl)
133  {
135  label_stack[ii].fml_ttl);
136  }
137  else
138  {
141  }
142  mld->mld_hdr[ii].label_exp_s_ttl =
143  clib_host_to_net_u32(mld->mld_hdr[ii].label_exp_s_ttl);
144 
145  /*
146  * pipe/uniform mode is only supported for the bottom of stack label
147  */
148  if (FIB_MPLS_LSP_MODE_UNIFORM == label_stack[ii].fml_mode)
149  {
151  }
152  else
153  {
155  }
156  dtype = mpls_label_dpo_types[mld->mld_flags];
157 
158  /*
159  * stack this label object on its parent.
160  */
161  dpo_stack(dtype,
162  mld->mld_payload_proto,
163  &mld->mld_dpo,
164  parent);
165  }
166 
167  dpo_set(dpo,
168  dtype,
169  mld->mld_payload_proto,
171 }
172 
173 u8*
174 format_mpls_label_dpo_flags (u8 *s, va_list *args)
175 {
176  mpls_label_dpo_flags_t flags = va_arg (*args, int);
178 
180  {
181  if ((1 << attr) & flags)
182  {
183  s = format(s, "%s,", mpls_label_dpo_attr_names[attr]);
184  }
185  }
186 
187  return (s);
188 }
189 
190 u8*
191 format_mpls_label_dpo (u8 *s, va_list *args)
192 {
193  index_t index = va_arg (*args, index_t);
194  u32 indent = va_arg (*args, u32);
196  mpls_label_dpo_t *mld;
197  u32 ii;
198 
199  if (pool_is_free_index(mpls_label_dpo_pool, index))
200  {
201  /*
202  * the packet trace can be printed after the DPO has been deleted
203  */
204  return (format(s, "mpls-label[???,%d]:", index));
205  }
206 
207  mld = mpls_label_dpo_get(index);
208  s = format(s, "mpls-label[%U%d]:",
210  (int) mld->mld_flags, index);
211 
212  for (ii = 0; ii < mld->mld_n_labels; ii++)
213  {
214  hdr.label_exp_s_ttl =
215  clib_net_to_host_u32(mld->mld_hdr[ii].label_exp_s_ttl);
216  s = format(s, "%U", format_mpls_header, hdr);
217  }
218 
219  s = format(s, "\n%U", format_white_space, indent);
220  s = format(s, "%U", format_dpo_id, &mld->mld_dpo, indent+2);
221 
222  return (s);
223 }
224 
225 static void
227 {
228  mpls_label_dpo_t *mld;
229 
230  mld = mpls_label_dpo_get(dpo->dpoi_index);
231 
232  mld->mld_locks++;
233 }
234 
235 static void
237 {
238  mpls_label_dpo_t *mld;
239 
240  mld = mpls_label_dpo_get(dpo->dpoi_index);
241 
242  mld->mld_locks--;
243 
244  if (0 == mld->mld_locks)
245  {
246  dpo_reset(&mld->mld_dpo);
247  pool_put(mpls_label_dpo_pool, mld);
248  }
249 }
250 
251 /**
252  * @brief A struct to hold tracing information for the MPLS label imposition
253  * node.
254  */
256 {
257  /**
258  * The MPLS header imposed
259  */
261 
262  /**
263  * TTL imposed - only valid for uniform LSPs
264  */
266 
267  /**
268  * TTL imposed - only valid for uniform LSPs
269  */
272 
275  mpls_label_dpo_t *mld0)
276 {
277  mpls_unicast_header_t *hdr0;
278 
279  vlib_buffer_advance(b0, -(mld0->mld_n_hdr_bytes));
280 
281  hdr0 = vlib_buffer_get_current(b0);
282 
283  if (1 == mld0->mld_n_labels)
284  {
285  /* optimise for the common case of one label */
286  *hdr0 = mld0->mld_hdr[0];
287  }
288  else
289  {
290  clib_memcpy(hdr0, mld0->mld_hdr, mld0->mld_n_hdr_bytes);
291  hdr0 = hdr0 + (mld0->mld_n_labels - 1);
292  }
293 
294  return (hdr0);
295 }
296 
297 /**
298  * Paint on an MPLS label and fixup the TTL
299  */
302  mpls_label_dpo_t *mld0,
303  u8 ttl0)
304 {
305  mpls_unicast_header_t *hdr0;
306 
307  hdr0 = mpls_label_paint(b0, mld0);
308 
309  /* fixup the TTL for the inner most label */
310  ((char*)hdr0)[3] = ttl0;
311 
312  return (hdr0);
313 }
314 
315 /**
316  * Paint on an MPLS label and fixup the TTL and EXP bits.
317  */
320  mpls_label_dpo_t *mld0,
321  u8 ttl0,
322  u8 exp0)
323 {
324  mpls_unicast_header_t *hdr0;
325 
326  hdr0 = mpls_label_paint_w_ttl(b0, mld0, ttl0);
327 
328  /* fixup the EXP for the inner most label */
329  ((char*)hdr0)[2] |= (exp0 << 1);
330 
331  return (hdr0);
332 }
333 
334 /**
335  * Paint on an MPLS label and fixup the TTL and EXP bits
336  * When the EXP bits are *already* bit shift to the correct place in
337  * in the 2nd byte (i.e. they were read from another label)
338  */
341  mpls_label_dpo_t *mld0,
342  u8 ttl0,
343  u8 exp0)
344 {
345  mpls_unicast_header_t *hdr0;
346 
347  hdr0 = mpls_label_paint_w_ttl(b0, mld0, ttl0);
348 
349  /* fixup the EXP for the inner most label */
350  ((char*)hdr0)[2] |= exp0;
351 
352  return (hdr0);
353 }
354 
357  vlib_node_runtime_t * node,
358  vlib_frame_t * from_frame,
359  const dpo_proto_t dproto,
361 {
362  u32 n_left_from, next_index, * from, * to_next;
363 
364  from = vlib_frame_vector_args (from_frame);
365  n_left_from = from_frame->n_vectors;
366 
367  next_index = node->cached_next_index;
368 
369  while (n_left_from > 0)
370  {
371  u32 n_left_to_next;
372 
373  vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
374 
375  while (n_left_from >= 8 && n_left_to_next >= 4)
376  {
377  u32 bi0, mldi0, bi1, mldi1, bi2, mldi2, bi3, mldi3;
378  mpls_unicast_header_t *hdr0, *hdr1, *hdr2, *hdr3;
379  mpls_label_dpo_t *mld0, *mld1, *mld2, *mld3;
380  vlib_buffer_t * b0, *b1, * b2, *b3;
381  u32 next0, next1, next2, next3;
382  u8 ttl0, ttl1, ttl2, ttl3;
383  u8 exp0, exp1, exp2, exp3;
384 
385  bi0 = to_next[0] = from[0];
386  bi1 = to_next[1] = from[1];
387  bi2 = to_next[2] = from[2];
388  bi3 = to_next[3] = from[3];
389 
390  /* Prefetch next iteration. */
391  {
392  vlib_buffer_t * p2, * p3, *p4, *p5;
393 
394  p2 = vlib_get_buffer (vm, from[2]);
395  p3 = vlib_get_buffer (vm, from[3]);
396  p4 = vlib_get_buffer (vm, from[4]);
397  p5 = vlib_get_buffer (vm, from[5]);
398 
399  vlib_prefetch_buffer_header (p2, STORE);
400  vlib_prefetch_buffer_header (p3, STORE);
401  vlib_prefetch_buffer_header (p4, STORE);
402  vlib_prefetch_buffer_header (p5, STORE);
403 
404  CLIB_PREFETCH (p2->data, sizeof (hdr0[0]), STORE);
405  CLIB_PREFETCH (p3->data, sizeof (hdr0[0]), STORE);
406  CLIB_PREFETCH (p4->data, sizeof (hdr0[0]), STORE);
407  CLIB_PREFETCH (p5->data, sizeof (hdr0[0]), STORE);
408  }
409 
410  from += 4;
411  to_next += 4;
412  n_left_from -= 4;
413  n_left_to_next -= 4;
414 
415  b0 = vlib_get_buffer (vm, bi0);
416  b1 = vlib_get_buffer (vm, bi1);
417  b2 = vlib_get_buffer (vm, bi2);
418  b3 = vlib_get_buffer (vm, bi3);
419 
420  /* dst lookup was done by ip4 lookup */
421  mldi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
422  mldi1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX];
423  mldi2 = vnet_buffer(b2)->ip.adj_index[VLIB_TX];
424  mldi3 = vnet_buffer(b3)->ip.adj_index[VLIB_TX];
425  mld0 = mpls_label_dpo_get(mldi0);
426  mld1 = mpls_label_dpo_get(mldi1);
427  mld2 = mpls_label_dpo_get(mldi2);
428  mld3 = mpls_label_dpo_get(mldi3);
429 
430  if (DPO_PROTO_MPLS != dproto)
431  {
432  /*
433  * These are the non-MPLS payload imposition cases
434  */
435  if (DPO_PROTO_IP4 == dproto)
436  {
441 
442  if (!(MPLS_LABEL_DPO_FLAG_NO_IP_TTL_DECR & flags))
443  {
444  /*
445  * decrement the TTL on ingress to the LSP
446  */
447  u32 checksum0;
448  u32 checksum1;
449  u32 checksum2;
450  u32 checksum3;
451 
452  checksum0 = ip0->checksum + clib_host_to_net_u16 (0x0100);
453  checksum1 = ip1->checksum + clib_host_to_net_u16 (0x0100);
454  checksum2 = ip2->checksum + clib_host_to_net_u16 (0x0100);
455  checksum3 = ip3->checksum + clib_host_to_net_u16 (0x0100);
456 
457  checksum0 += checksum0 >= 0xffff;
458  checksum1 += checksum1 >= 0xffff;
459  checksum2 += checksum2 >= 0xffff;
460  checksum3 += checksum3 >= 0xffff;
461 
462  ip0->checksum = checksum0;
463  ip1->checksum = checksum1;
464  ip2->checksum = checksum2;
465  ip3->checksum = checksum3;
466 
467  ip0->ttl -= 1;
468  ip1->ttl -= 1;
469  ip2->ttl -= 1;
470  ip3->ttl -= 1;
471  }
472 
474  {
475  ttl1 = ip1->ttl;
476  ttl0 = ip0->ttl;
477  ttl3 = ip3->ttl;
478  ttl2 = ip2->ttl;
479  /* by default copy the 3 most significant bits */
480  exp0 = ip_dscp_to_mpls_exp(ip0->tos);
481  exp1 = ip_dscp_to_mpls_exp(ip1->tos);
482  exp2 = ip_dscp_to_mpls_exp(ip2->tos);
483  exp3 = ip_dscp_to_mpls_exp(ip3->tos);
484  }
485  }
486  else if (DPO_PROTO_IP6 == dproto)
487  {
488  /*
489  * decrement the TTL on ingress to the LSP
490  */
495 
496  if (!(MPLS_LABEL_DPO_FLAG_NO_IP_TTL_DECR & flags))
497  {
498  ip0->hop_limit -= 1;
499  ip1->hop_limit -= 1;
500  ip2->hop_limit -= 1;
501  ip3->hop_limit -= 1;
502  }
504  {
505  ttl0 = ip0->hop_limit;
506  ttl1 = ip1->hop_limit;
507  ttl2 = ip2->hop_limit;
508  ttl3 = ip3->hop_limit;
509  /* by default copy the 3 most significant bits */
510  exp0 = ip_dscp_to_mpls_exp(
512  exp1 = ip_dscp_to_mpls_exp(
514  exp2 = ip_dscp_to_mpls_exp(
516  exp3 = ip_dscp_to_mpls_exp(
518  }
519  }
520  else
521  {
522  /*
523  * nothing to change in the ethernet header
524  */
525  ttl0 = ttl1 = ttl2 = ttl3 = MPLS_LABEL_DEFAULT_TTL;
526  exp0 = exp1 = exp2 = exp3 = MPLS_LABEL_DEFAULT_EXP;
527  }
528  /*
529  * These are the non-MPLS payload imposition cases.
530  * Based on the LSP mode either, for uniform, copy down the TTL
531  * and EXP from the payload or, for pipe mode, slap on the value
532  * requested from config
533  */
535  {
536  hdr0 = mpls_label_paint_w_ttl_exp(b0, mld0, ttl0, exp0);
537  hdr1 = mpls_label_paint_w_ttl_exp(b1, mld1, ttl1, exp1);
538  hdr2 = mpls_label_paint_w_ttl_exp(b2, mld2, ttl2, exp2);
539  hdr3 = mpls_label_paint_w_ttl_exp(b3, mld3, ttl3, exp3);
540  }
541  else
542  {
543  hdr0 = mpls_label_paint(b0, mld0);
544  hdr1 = mpls_label_paint(b1, mld1);
545  hdr2 = mpls_label_paint(b2, mld2);
546  hdr3 = mpls_label_paint(b3, mld3);
547  }
548  }
549  else
550  {
551  /*
552  * else, the packet to be encapped is an MPLS packet
553  * there are two cases to consider:
554  * 1 - this is an MPLS label swap at an LSP midpoint.
555  * recognisable because mpls.first = 1. In this case the
556  * TTL must be set to the current value -1.
557  * 2 - The MPLS packet is recursing (or being injected into)
558  * this LSP, in which case the pipe/uniform rules apply
559  *
560  */
561  if (PREDICT_TRUE(vnet_buffer(b0)->mpls.first))
562  {
563  /*
564  * The first label to be imposed on the packet. this is a
565  * label swap.in which case we stashed the TTL and EXP bits
566  * in the packet in the lookup node
567  */
568  ASSERT(0 != vnet_buffer (b0)->mpls.ttl);
569 
570  ttl0 = vnet_buffer(b0)->mpls.ttl - 1;
571  exp0 = vnet_buffer(b0)->mpls.exp;
572  hdr0 = mpls_label_paint_w_ttl_exp(b0, mld0, ttl0, exp0);
573  }
574  else
575  {
576  /*
577  * not the first label. implying we are recusring down a
578  * chain of output labels. Each layer is considered a new
579  * LSP - hence the TTL/EXP are pipe/uniform handled
580  */
582  {
583  hdr0 = vlib_buffer_get_current(b0);
584  ttl0 = ((u8*)hdr0)[3];
585  exp0 = ((u8*)hdr0)[2] & 0xe;
586  hdr0 = mpls_label_paint_w_ttl_mpls_exp(b0, mld0, ttl0, exp0);
587  }
588  else
589  {
590  hdr0 = mpls_label_paint(b0, mld0);
591  }
592  }
593  if (PREDICT_TRUE(vnet_buffer(b1)->mpls.first))
594  {
595  ASSERT(0 != vnet_buffer (b1)->mpls.ttl);
596 
597  ttl1 = vnet_buffer(b1)->mpls.ttl - 1;
598  exp1 = vnet_buffer(b1)->mpls.exp;
599  hdr1 = mpls_label_paint_w_ttl_exp(b1, mld1, ttl1, exp1);
600  }
601  else
602  {
604  {
605  hdr1 = vlib_buffer_get_current(b1);
606  ttl1 = ((u8*)hdr1)[3];
607  exp1 = ((u8*)hdr1)[2] & 0xe;
608  hdr1 = mpls_label_paint_w_ttl_mpls_exp(b1, mld1, ttl1, exp1);
609  }
610  else
611  {
612  hdr1 = mpls_label_paint(b1, mld1);
613  }
614  }
615  if (PREDICT_TRUE(vnet_buffer(b2)->mpls.first))
616  {
617  ASSERT(0 != vnet_buffer (b2)->mpls.ttl);
618 
619  ttl2 = vnet_buffer(b2)->mpls.ttl - 1;
620  exp2 = vnet_buffer(b2)->mpls.exp;
621  hdr2 = mpls_label_paint_w_ttl_exp(b2, mld2, ttl2, exp2);
622  }
623  else
624  {
626  {
627  hdr2 = vlib_buffer_get_current(b2);
628  ttl2 = ((u8*)hdr2)[3];
629  exp2 = ((u8*)hdr2)[2] & 0xe;
630  hdr2 = mpls_label_paint_w_ttl_mpls_exp(b2, mld2, ttl2, exp2);
631  }
632  else
633  {
634  hdr2 = mpls_label_paint(b2, mld2);
635  }
636  }
637  if (PREDICT_TRUE(vnet_buffer(b3)->mpls.first))
638  {
639  ASSERT(0 != vnet_buffer (b3)->mpls.ttl);
640 
641  ttl3 = vnet_buffer(b3)->mpls.ttl - 1;
642  exp3 = vnet_buffer(b3)->mpls.exp;
643  hdr3 = mpls_label_paint_w_ttl_exp(b3, mld3, ttl3, exp3);
644  }
645  else
646  {
648  {
649  hdr3 = vlib_buffer_get_current(b3);
650  ttl3 = ((u8*)hdr3)[3];
651  exp3 = ((u8*)hdr3)[2] & 0xe;
652  hdr3 = mpls_label_paint_w_ttl_mpls_exp(b3, mld3, ttl3, exp3);
653  }
654  else
655  {
656  hdr3 = mpls_label_paint(b3, mld3);
657  }
658  }
659 
660  vnet_buffer(b0)->mpls.first = 0;
661  vnet_buffer(b1)->mpls.first = 0;
662  vnet_buffer(b2)->mpls.first = 0;
663  vnet_buffer(b3)->mpls.first = 0;
664  }
665 
666  next0 = mld0->mld_dpo.dpoi_next_node;
667  next1 = mld1->mld_dpo.dpoi_next_node;
668  next2 = mld2->mld_dpo.dpoi_next_node;
669  next3 = mld3->mld_dpo.dpoi_next_node;
670 
671  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = mld0->mld_dpo.dpoi_index;
672  vnet_buffer(b1)->ip.adj_index[VLIB_TX] = mld1->mld_dpo.dpoi_index;
673  vnet_buffer(b2)->ip.adj_index[VLIB_TX] = mld2->mld_dpo.dpoi_index;
674  vnet_buffer(b3)->ip.adj_index[VLIB_TX] = mld3->mld_dpo.dpoi_index;
675 
676  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
677  {
679  vlib_add_trace (vm, node, b0, sizeof (*tr));
680  tr->hdr = *hdr0;
682  {
683  tr->ttl = ttl0;
684  tr->exp = exp0;
685  }
686  else
687  {
688  tr->ttl = tr->exp = 0;
689  }
690  }
691  if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
692  {
694  vlib_add_trace (vm, node, b1, sizeof (*tr));
695  tr->hdr = *hdr1;
697  {
698  tr->ttl = ttl1;
699  tr->exp = exp1;
700  }
701  else
702  {
703  tr->ttl = tr->exp = 0;
704  }
705  }
706  if (PREDICT_FALSE(b2->flags & VLIB_BUFFER_IS_TRACED))
707  {
709  vlib_add_trace (vm, node, b2, sizeof (*tr));
710  tr->hdr = *hdr2;
712  {
713  tr->ttl = ttl2;
714  tr->exp = exp2;
715  }
716  else
717  {
718  tr->ttl = tr->exp = 0;
719  }
720  }
721  if (PREDICT_FALSE(b3->flags & VLIB_BUFFER_IS_TRACED))
722  {
724  vlib_add_trace (vm, node, b3, sizeof (*tr));
725  tr->hdr = *hdr3;
727  {
728  tr->ttl = ttl3;
729  tr->exp = exp3;
730  }
731  else
732  {
733  tr->ttl = tr->exp = 0;
734  }
735  }
736 
737  vlib_validate_buffer_enqueue_x4(vm, node, next_index, to_next,
738  n_left_to_next,
739  bi0, bi1, bi2, bi3,
740  next0, next1, next2, next3);
741  }
742 
743  while (n_left_from > 0 && n_left_to_next > 0)
744  {
745  mpls_unicast_header_t *hdr0;
746  mpls_label_dpo_t *mld0;
747  vlib_buffer_t * b0;
748  u32 bi0, mldi0;
749  u8 ttl0, exp0;
750  u32 next0;
751 
752  bi0 = from[0];
753  to_next[0] = bi0;
754  from += 1;
755  to_next += 1;
756  n_left_from -= 1;
757  n_left_to_next -= 1;
758 
759  b0 = vlib_get_buffer (vm, bi0);
760 
761  /* dst lookup was done by ip4 lookup */
762  mldi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
763  mld0 = mpls_label_dpo_get(mldi0);
764 
765  if (DPO_PROTO_MPLS != dproto)
766  {
767  if (DPO_PROTO_IP4 == dproto)
768  {
769  /*
770  * decrement the TTL on ingress to the LSP
771  */
773  if (!(MPLS_LABEL_DPO_FLAG_NO_IP_TTL_DECR & flags))
774  {
775  u32 checksum0;
776 
777  checksum0 = ip0->checksum + clib_host_to_net_u16 (0x0100);
778  checksum0 += checksum0 >= 0xffff;
779 
780  ip0->checksum = checksum0;
781  ip0->ttl -= 1;
782  }
784  {
785  ttl0 = ip0->ttl;
786  exp0 = ip_dscp_to_mpls_exp(ip0->tos);
787  }
788  }
789  else if (DPO_PROTO_IP6 == dproto)
790  {
791  /*
792  * decrement the TTL on ingress to the LSP
793  */
795 
796  if (!(MPLS_LABEL_DPO_FLAG_NO_IP_TTL_DECR & flags))
797  {
798  ip0->hop_limit -= 1;
799  }
801  {
802  ttl0 = ip0->hop_limit;
803  exp0 = ip_dscp_to_mpls_exp(
805  }
806  }
807  else
808  {
809  /*
810  * nothing to change in the ethernet header
811  */
812  ttl0 = MPLS_LABEL_DEFAULT_TTL;
813  exp0 = MPLS_LABEL_DEFAULT_EXP;
814  }
815 
816  /*
817  * These are the non-MPLS payload imposition cases.
818  * Based on the LSP mode either, for uniform, copy down the TTL
819  * from the payload or, for pipe mode, slap on the value
820  * requested from config
821  */
823  {
824  hdr0 = mpls_label_paint_w_ttl_exp(b0, mld0, ttl0, exp0);
825  }
826  else
827  {
828  hdr0 = mpls_label_paint(b0, mld0);
829  }
830  }
831  else
832  {
833  if (PREDICT_TRUE(vnet_buffer(b0)->mpls.first))
834  {
835  ASSERT(0 != vnet_buffer (b0)->mpls.ttl);
836 
837  ttl0 = vnet_buffer(b0)->mpls.ttl - 1;
838  exp0 = vnet_buffer(b0)->mpls.exp;
839  hdr0 = mpls_label_paint_w_ttl_exp(b0, mld0, ttl0, exp0);
840  }
841  else
842  {
844  {
845  hdr0 = vlib_buffer_get_current(b0);
846  ttl0 = ((u8*)hdr0)[3];
847  exp0 = ((u8*)hdr0)[2] & 0xe;
848  hdr0 = mpls_label_paint_w_ttl_mpls_exp(b0, mld0, ttl0, exp0);
849  }
850  else
851  {
852  hdr0 = mpls_label_paint(b0, mld0);
853  }
854  }
855 
856  vnet_buffer(b0)->mpls.first = 0;
857  }
858 
859  next0 = mld0->mld_dpo.dpoi_next_node;
860  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = mld0->mld_dpo.dpoi_index;
861 
862  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
863  {
865  vlib_add_trace (vm, node, b0, sizeof (*tr));
866  tr->hdr = *hdr0;
868  {
869  tr->ttl = ttl0;
870  tr->exp = exp0;
871  }
872  else
873  {
874  tr->ttl = tr->exp = 0;
875  }
876  }
877 
878  vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
879  n_left_to_next, bi0, next0);
880  }
881  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
882  }
883  return from_frame->n_vectors;
884 }
885 
886 static u8 *
888 {
889  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
890  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
893  u32 indent;
894 
895  t = va_arg (*args, mpls_label_imposition_trace_t *);
896  indent = format_get_indent (s);
897  hdr.label_exp_s_ttl = clib_net_to_host_u32(t->hdr.label_exp_s_ttl);
898 
899  s = format (s, "%Umpls-header:%U",
900  format_white_space, indent,
901  format_mpls_header, hdr);
902  return (s);
903 }
904 
905 static uword
907  vlib_node_runtime_t * node,
908  vlib_frame_t * frame)
909 {
910  return (mpls_label_imposition_inline(vm, node, frame,
913 }
914 
917  .name = "mpls-label-imposition-pipe",
918  .vector_size = sizeof (u32),
919 
920  .format_trace = format_mpls_label_imposition_trace,
921  .n_next_nodes = 1,
922  .next_nodes = {
923  [0] = "mpls-drop",
924  }
925 };
928 
929 static uword
930 ip4_mpls_label_imposition_pipe (vlib_main_t * vm,
931  vlib_node_runtime_t * node,
932  vlib_frame_t * frame)
933 {
934  return (mpls_label_imposition_inline(vm, node, frame,
937 }
938 
940  .function = ip4_mpls_label_imposition_pipe,
941  .name = "ip4-mpls-label-imposition-pipe",
942  .vector_size = sizeof (u32),
943 
944  .format_trace = format_mpls_label_imposition_trace,
945  .n_next_nodes = 1,
946  .next_nodes = {
947  [0] = "ip4-drop",
948  }
949 };
951  ip4_mpls_label_imposition_pipe)
952 
953 static uword
954 ip6_mpls_label_imposition_pipe (vlib_main_t * vm,
955  vlib_node_runtime_t * node,
956  vlib_frame_t * frame)
957 {
958  return (mpls_label_imposition_inline(vm, node, frame,
961 }
962 
964  .function = ip6_mpls_label_imposition_pipe,
965  .name = "ip6-mpls-label-imposition-pipe",
966  .vector_size = sizeof (u32),
967 
968  .format_trace = format_mpls_label_imposition_trace,
969  .n_next_nodes = 1,
970  .next_nodes = {
971  [0] = "ip6-drop",
972  }
973 };
975  ip6_mpls_label_imposition_pipe)
976 
977 static uword
978 ethernet_mpls_label_imposition_pipe (vlib_main_t * vm,
979  vlib_node_runtime_t * node,
980  vlib_frame_t * frame)
981 {
982  return (mpls_label_imposition_inline(vm, node, frame,
985 }
986 
988  .function = ethernet_mpls_label_imposition_pipe,
989  .name = "ethernet-mpls-label-imposition-pipe",
990  .vector_size = sizeof (u32),
991 
992  .format_trace = format_mpls_label_imposition_trace,
993  .n_next_nodes = 1,
994  .next_nodes = {
995  [0] = "error-drop",
996  }
997 };
998 
1000  ethernet_mpls_label_imposition_pipe)
1001 
1002 static uword
1003 mpls_mpls_label_imposition_uniform (vlib_main_t * vm,
1004  vlib_node_runtime_t * node,
1005  vlib_frame_t * frame)
1006 {
1007  return (mpls_label_imposition_inline(vm, node, frame,
1010 }
1011 
1013  .function = mpls_mpls_label_imposition_uniform,
1014  .name = "mpls-label-imposition-uniform",
1015  .vector_size = sizeof (u32),
1016 
1017  .format_trace = format_mpls_label_imposition_trace,
1018  .n_next_nodes = 1,
1019  .next_nodes = {
1020  [0] = "mpls-drop",
1021  }
1022 };
1024  mpls_mpls_label_imposition_uniform)
1025 
1026 static uword
1027 ip4_mpls_label_imposition_uniform (vlib_main_t * vm,
1028  vlib_node_runtime_t * node,
1029  vlib_frame_t * frame)
1030 {
1031  return (mpls_label_imposition_inline(vm, node, frame,
1032  DPO_PROTO_IP4,
1034 }
1035 
1037  .function = ip4_mpls_label_imposition_uniform,
1038  .name = "ip4-mpls-label-imposition-uniform",
1039  .vector_size = sizeof (u32),
1040 
1041  .format_trace = format_mpls_label_imposition_trace,
1042  .n_next_nodes = 1,
1043  .next_nodes = {
1044  [0] = "ip4-drop",
1045  }
1046 };
1048  ip4_mpls_label_imposition_uniform)
1049 
1050 static uword
1051 ip6_mpls_label_imposition_uniform (vlib_main_t * vm,
1052  vlib_node_runtime_t * node,
1053  vlib_frame_t * frame)
1054 {
1055  return (mpls_label_imposition_inline(vm, node, frame,
1056  DPO_PROTO_IP6,
1058 }
1059 
1061  .function = ip6_mpls_label_imposition_uniform,
1062  .name = "ip6-mpls-label-imposition-uniform",
1063  .vector_size = sizeof (u32),
1064 
1065  .format_trace = format_mpls_label_imposition_trace,
1066  .n_next_nodes = 1,
1067  .next_nodes = {
1068  [0] = "ip6-drop",
1069  }
1070 };
1072  ip6_mpls_label_imposition_uniform)
1073 
1074 static uword
1075 ethernet_mpls_label_imposition_uniform (vlib_main_t * vm,
1076  vlib_node_runtime_t * node,
1077  vlib_frame_t * frame)
1078 {
1079  return (mpls_label_imposition_inline(vm, node, frame,
1082 }
1083 
1085  .function = ethernet_mpls_label_imposition_uniform,
1086  .name = "ethernet-mpls-label-imposition-uniform",
1087  .vector_size = sizeof (u32),
1088 
1089  .format_trace = format_mpls_label_imposition_trace,
1090  .n_next_nodes = 1,
1091  .next_nodes = {
1092  [0] = "error-drop",
1093  }
1094 };
1095 
1097  ethernet_mpls_label_imposition_uniform)
1098 
1099 static uword
1100 ip4_mpls_label_imposition_pipe_no_ip_ttl_decr (vlib_main_t * vm,
1101  vlib_node_runtime_t * node,
1102  vlib_frame_t * frame)
1103 {
1104  return (mpls_label_imposition_inline(vm, node, frame,
1105  DPO_PROTO_IP4,
1107 }
1108 
1110  .function = ip4_mpls_label_imposition_pipe_no_ip_ttl_decr,
1111  .name = "ip4-mpls-label-imposition-pipe-no-ip-ttl-decr",
1112  .vector_size = sizeof (u32),
1113 
1114  .format_trace = format_mpls_label_imposition_trace,
1115  .n_next_nodes = 1,
1116  .next_nodes = {
1117  [0] = "ip4-drop",
1118  }
1119 };
1121  ip4_mpls_label_imposition_pipe_no_ip_ttl_decr)
1122 
1123 static uword
1124 ip6_mpls_label_imposition_pipe_no_ip_ttl_decr (vlib_main_t * vm,
1125  vlib_node_runtime_t * node,
1126  vlib_frame_t * frame)
1127 {
1128  return (mpls_label_imposition_inline(vm, node, frame,
1129  DPO_PROTO_IP6,
1131 }
1132 
1134  .function = ip6_mpls_label_imposition_pipe_no_ip_ttl_decr,
1135  .name = "ip6-mpls-label-imposition-pipe-no-ip-ttl-decr",
1136  .vector_size = sizeof (u32),
1137 
1138  .format_trace = format_mpls_label_imposition_trace,
1139  .n_next_nodes = 1,
1140  .next_nodes = {
1141  [0] = "ip6-drop",
1142  }
1143 };
1145  ip6_mpls_label_imposition_pipe_no_ip_ttl_decr)
1146 
1147 static uword
1148 ip4_mpls_label_imposition_uniform_no_ip_ttl_decr (vlib_main_t * vm,
1149  vlib_node_runtime_t * node,
1150  vlib_frame_t * frame)
1151 {
1152  return (mpls_label_imposition_inline(vm, node, frame,
1153  DPO_PROTO_IP4,
1156 }
1157 
1159  .function = ip4_mpls_label_imposition_uniform_no_ip_ttl_decr,
1160  .name = "ip4-mpls-label-imposition-uniform-no-ip-ttl-decr",
1161  .vector_size = sizeof (u32),
1162 
1163  .format_trace = format_mpls_label_imposition_trace,
1164  .n_next_nodes = 1,
1165  .next_nodes = {
1166  [0] = "ip4-drop",
1167  }
1168 };
1170  ip4_mpls_label_imposition_uniform_no_ip_ttl_decr)
1171 
1172 static uword
1173 ip6_mpls_label_imposition_uniform_no_ip_ttl_decr (vlib_main_t * vm,
1174  vlib_node_runtime_t * node,
1175  vlib_frame_t * frame)
1176 {
1177  return (mpls_label_imposition_inline(vm, node, frame,
1178  DPO_PROTO_IP6,
1181 }
1182 
1184  .function = ip6_mpls_label_imposition_uniform_no_ip_ttl_decr,
1185  .name = "ip6-mpls-label-imposition-uniform-no-ip-ttl-decr",
1186  .vector_size = sizeof (u32),
1187 
1188  .format_trace = format_mpls_label_imposition_trace,
1189  .n_next_nodes = 1,
1190  .next_nodes = {
1191  [0] = "ip6-drop",
1192  }
1193 };
1195  ip6_mpls_label_imposition_uniform_no_ip_ttl_decr)
1196 
1197 
1198 static void
1199 mpls_label_dpo_mem_show (void)
1200 {
1201  fib_show_memory_usage("MPLS label",
1202  pool_elts(mpls_label_dpo_pool),
1203  pool_len(mpls_label_dpo_pool),
1204  sizeof(mpls_label_dpo_t));
1205 }
1206 
1207 /**
1208  * Interpose a label DPO. used in the FIB unit tests
1209  */
1210 static void
1212  const dpo_id_t *parent,
1213  dpo_id_t *clone)
1214 {
1215  mpls_label_dpo_t *mld, *mld_clone;
1216 
1217  mld_clone = mpls_label_dpo_alloc();
1218  mld = mpls_label_dpo_get(original->dpoi_index);
1219 
1220  mld_clone->mld_locks = 0;
1221  clib_memcpy(&mld_clone->mld_hdr,
1222  &mld->mld_hdr,
1223  sizeof(mld_clone->mld_hdr));
1224  mld_clone->mld_payload_proto = mld->mld_payload_proto;
1225  mld_clone->mld_n_labels = mld->mld_n_labels;
1226  mld_clone->mld_n_hdr_bytes = mld->mld_n_hdr_bytes;
1227 
1229  mld_clone->mld_payload_proto,
1230  &mld_clone->mld_dpo,
1231  parent);
1232 
1233  dpo_set(clone,
1234  mpls_label_dpo_types[MPLS_LABEL_DPO_FLAG_NONE],
1235  mld_clone->mld_payload_proto,
1236  mpls_label_dpo_get_index(mld_clone));
1237 }
1238 
1239 const static dpo_vft_t mld_vft = {
1241  .dv_unlock = mpls_label_dpo_unlock,
1242  .dv_format = format_mpls_label_dpo,
1243  .dv_mem_show = mpls_label_dpo_mem_show,
1244  .dv_mk_interpose = mpls_label_interpose,
1245 };
1246 
1247 const static char* const mpls_label_imp_pipe_ip4_nodes[] =
1248 {
1249  "ip4-mpls-label-imposition-pipe",
1250  NULL,
1251 };
1252 const static char* const mpls_label_imp_pipe_ip6_nodes[] =
1253 {
1254  "ip6-mpls-label-imposition-pipe",
1255  NULL,
1256 };
1257 const static char* const mpls_label_imp_pipe_mpls_nodes[] =
1258 {
1259  "mpls-label-imposition-pipe",
1260  NULL,
1261 };
1262 const static char* const mpls_label_imp_pipe_ethernet_nodes[] =
1263 {
1264  "ethernet-mpls-label-imposition-pipe",
1265  NULL,
1266 };
1267 
1268 const static char* const * const mpls_label_imp_pipe_nodes[DPO_PROTO_NUM] =
1269 {
1274 };
1275 
1276 const static char* const mpls_label_imp_uniform_ip4_nodes[] =
1277 {
1278  "ip4-mpls-label-imposition-uniform",
1279  NULL,
1280 };
1281 const static char* const mpls_label_imp_uniform_ip6_nodes[] =
1282 {
1283  "ip6-mpls-label-imposition-uniform",
1284  NULL,
1285 };
1286 const static char* const mpls_label_imp_uniform_mpls_nodes[] =
1287 {
1288  "mpls-label-imposition-uniform",
1289  NULL,
1290 };
1291 const static char* const mpls_label_imp_uniform_ethernet_nodes[] =
1292 {
1293  "ethernet-mpls-label-imposition-uniform",
1294  NULL,
1295 };
1296 
1297 const static char* const * const mpls_label_imp_uniform_nodes[DPO_PROTO_NUM] =
1298 {
1303 };
1304 
1306 {
1307  "ip4-mpls-label-imposition-pipe-no-ip-ttl-decr",
1308  NULL,
1309 };
1311 {
1312  "ip6-mpls-label-imposition-pipe-no-ip-ttl-decr",
1313  NULL,
1314 };
1315 
1316 const static char* const * const mpls_label_imp_pipe_no_ip_tll_decr_nodes[DPO_PROTO_NUM] =
1317 {
1320 };
1321 
1323 {
1324  "ip4-mpls-label-imposition-uniform-no-ip-ttl-decr",
1325  NULL,
1326 };
1328 {
1329  "ip6-mpls-label-imposition-uniform-no-ip-ttl-decr",
1330  NULL,
1331 };
1332 
1334 {
1337 };
1338 
1339 void
1341 {
1343  dpo_register_new_type(&mld_vft,
1346  dpo_register_new_type(&mld_vft,
1349  dpo_register_new_type(&mld_vft,
1353  dpo_register_new_type(&mld_vft,
1355 }
1356 
1357 dpo_type_t
1359 {
1360  return (mpls_label_dpo_types[flags]);
1361 }
static const char *const mpls_label_imp_pipe_ip6_nodes[]
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:404
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:399
format_function_t format_mpls_header
Definition: mpls.h:70
static const char *const mpls_label_imp_pipe_no_ip_tll_decr_ip6_nodes[]
mpls_unicast_header_t hdr
The MPLS header imposed.
#define PREDICT_TRUE(x)
Definition: clib.h:106
static const char *const mpls_label_imp_pipe_no_ip_tll_decr_ip4_nodes[]
#define NULL
Definition: clib.h:55
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define vlib_validate_buffer_enqueue_x4(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, bi2, bi3, next0, next1, next2, next3)
Finish enqueueing four buffers forward in the graph.
Definition: buffer_node.h:138
static u32 format_get_indent(u8 *s)
Definition: format.h:72
static const char *const mpls_label_imp_pipe_ethernet_nodes[]
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u8 * format_mpls_label_dpo(u8 *s, va_list *args)
vlib_node_registration_t ip4_mpls_label_imposition_uniform_no_ip_ttl_decr_node
(constructor) VLIB_REGISTER_NODE (ip4_mpls_label_imposition_uniform_no_ip_ttl_decr_node) ...
static uword mpls_label_imposition_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, const dpo_proto_t dproto, const mpls_label_dpo_flags_t flags)
unsigned char u8
Definition: types.h:56
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
vlib_node_registration_t ip4_mpls_label_imposition_pipe_no_ip_ttl_decr_node
(constructor) VLIB_REGISTER_NODE (ip4_mpls_label_imposition_pipe_no_ip_ttl_decr_node) ...
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
static index_t mpls_label_dpo_get_index(mpls_label_dpo_t *mld)
vlib_node_registration_t ip6_mpls_label_imposition_uniform_node
(constructor) VLIB_REGISTER_NODE (ip6_mpls_label_imposition_uniform_node)
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
static const char *const mpls_label_imp_uniform_no_ip_tll_decr_ip6_nodes[]
vlib_node_registration_t ip6_mpls_label_imposition_pipe_node
(constructor) VLIB_REGISTER_NODE (ip6_mpls_label_imposition_pipe_node)
#define MPLS_LABEL_DPO_MAX_N_LABELS
Maximum number of labels in one DPO.
#define always_inline
Definition: clib.h:92
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:184
static_always_inline u8 ip6_traffic_class_network_order(const ip6_header_t *ip6)
Definition: ip6_packet.h:357
#define MPLS_LABEL_DEFAULT_EXP
The Default EXP added to MPLS label headers when no other value is available.
Definition: packet.h:53
static const char *const mpls_label_imp_uniform_mpls_nodes[]
void fib_show_memory_usage(const char *name, u32 in_use_elts, u32 allocd_elts, size_t size_elt)
Show the memory usage for a type.
Definition: fib_node.c:220
unsigned int u32
Definition: types.h:88
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u8 exp
TTL imposed - only valid for uniform LSPs.
static void vnet_mpls_uc_set_label(mpls_label_t *label_exp_s_ttl, u32 value)
Definition: packet.h:123
static const char *const mpls_label_imp_pipe_mpls_nodes[]
enum mpls_label_dpo_flags_t_ mpls_label_dpo_flags_t
dpo_proto_t mld_payload_proto
The protocol of the payload/packets that are being encapped.
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:341
#define FOR_EACH_MPLS_LABEL_DPO_ATTR(_item)
static void vnet_mpls_uc_set_exp(mpls_label_t *label_exp_s_ttl, u32 exp)
Definition: packet.h:130
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:168
VLIB_NODE_FUNCTION_MULTIARCH(mpls_mpls_label_imposition_pipe_node, mpls_mpls_label_imposition_pipe)
static const char *const *const mpls_label_imp_uniform_nodes[DPO_PROTO_NUM]
void mpls_label_dpo_create(fib_mpls_label_t *label_stack, mpls_eos_bit_t eos, dpo_proto_t payload_proto, mpls_label_dpo_flags_t flags, const dpo_id_t *parent, dpo_id_t *dpo)
Create an MPLS label object.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:202
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:273
#define PREDICT_FALSE(x)
Definition: clib.h:105
Configuration for each label value in the output-stack.
Definition: fib_types.h:410
vlib_node_registration_t ip4_mpls_label_imposition_pipe_node
(constructor) VLIB_REGISTER_NODE (ip4_mpls_label_imposition_pipe_node)
static uword mpls_mpls_label_imposition_pipe(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define MPLS_LABEL_DPO_ATTR_NAMES
static const char *const *const mpls_label_imp_pipe_nodes[DPO_PROTO_NUM]
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:364
const char * mpls_label_dpo_attr_names[]
Strings for the flags.
vlib_node_registration_t ip6_mpls_label_imposition_uniform_no_ip_ttl_decr_node
(constructor) VLIB_REGISTER_NODE (ip6_mpls_label_imposition_uniform_no_ip_ttl_decr_node) ...
static const char *const mpls_label_imp_uniform_no_ip_tll_decr_ip4_nodes[]
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
#define MPLS_LABEL_DPO_ATTR_MAX
vlib_node_registration_t ip6_mpls_label_imposition_pipe_no_ip_ttl_decr_node
(constructor) VLIB_REGISTER_NODE (ip6_mpls_label_imposition_pipe_no_ip_ttl_decr_node) ...
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:153
u16 n_vectors
Definition: node.h:380
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:77
static const char *const mpls_label_imp_uniform_ethernet_nodes[]
vlib_main_t * vm
Definition: buffer.c:294
u16 mld_n_hdr_bytes
Cached amount of header bytes to paint.
vlib_node_registration_t mpls_mpls_label_imposition_pipe_node
(constructor) VLIB_REGISTER_NODE (mpls_mpls_label_imposition_pipe_node)
vlib_node_registration_t mpls_mpls_label_imposition_uniform_node
(constructor) VLIB_REGISTER_NODE (mpls_mpls_label_imposition_uniform_node)
#define clib_warning(format, args...)
Definition: error.h:59
static mpls_label_dpo_t * mpls_label_dpo_get(index_t index)
static const char *const mpls_label_imp_uniform_ip6_nodes[]
#define clib_memcpy(a, b, c)
Definition: string.h:75
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:270
mpls_label_t fml_value
The label value.
Definition: fib_types.h:415
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:454
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:185
static u8 ip_dscp_to_mpls_exp(u8 tos)
When in uniform mode convert an IPv[46] DSCP value to an MPLS EXP value.
Definition: packet.h:58
void mpls_label_dpo_module_init(void)
static const char *const mpls_label_imp_uniform_ip4_nodes[]
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:492
u8 mld_n_labels
Size of the label stack.
static void mpls_label_dpo_lock(dpo_id_t *dpo)
#define ASSERT(truth)
static mpls_unicast_header_t * mpls_label_paint_w_ttl(vlib_buffer_t *b0, mpls_label_dpo_t *mld0, u8 ttl0)
Paint on an MPLS label and fixup the TTL.
dpo_id_t mld_dpo
Next DPO in the graph.
u8 ttl
TTL imposed - only valid for uniform LSPs.
struct mpls_label_imposition_trace_t_ mpls_label_imposition_trace_t
A struct to hold tracing information for the MPLS label imposition node.
static mpls_unicast_header_t * mpls_label_paint_w_ttl_mpls_exp(vlib_buffer_t *b0, mpls_label_dpo_t *mld0, u8 ttl0, u8 exp0)
Paint on an MPLS label and fixup the TTL and EXP bits When the EXP bits are already bit shift to the ...
mpls_label_t label_exp_s_ttl
Definition: packet.h:31
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:215
static const char *const *const mpls_label_imp_uniform_no_ip_tll_decr_nodes[DPO_PROTO_NUM]
static void vnet_mpls_uc_set_s(mpls_label_t *label_exp_s_ttl, u32 eos)
Definition: packet.h:137
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:147
mpls_unicast_header_t mld_hdr[MPLS_LABEL_DPO_MAX_N_LABELS]
The MPLS label header to impose.
vlib_node_registration_t ethernet_mpls_label_imposition_uniform_node
(constructor) VLIB_REGISTER_NODE (ethernet_mpls_label_imposition_uniform_node)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
vlib_node_registration_t ethernet_mpls_label_imposition_pipe_node
(constructor) VLIB_REGISTER_NODE (ethernet_mpls_label_imposition_pipe_node)
Definition: defs.h:47
#define DPO_PROTO_NUM
Definition: dpo.h:70
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_node_registration_t ip4_mpls_label_imposition_uniform_node
(constructor) VLIB_REGISTER_NODE (ip4_mpls_label_imposition_uniform_node)
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
static mpls_unicast_header_t * mpls_label_paint_w_ttl_exp(vlib_buffer_t *b0, mpls_label_dpo_t *mld0, u8 ttl0, u8 exp0)
Paint on an MPLS label and fixup the TTL and EXP bits.
static void vnet_mpls_uc_set_ttl(mpls_label_t *label_exp_s_ttl, u32 ttl)
Definition: packet.h:144
mpls_label_dpo_flags_t mld_flags
Flags.
#define vnet_buffer(b)
Definition: buffer.h:360
static u8 * format_mpls_label_imposition_trace(u8 *s, va_list *args)
u8 data[0]
Packet data.
Definition: buffer.h:172
mpls_label_dpo_t * mpls_label_dpo_pool
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:231
u16 mld_locks
Number of locks/users of the label.
u8 fml_exp
EXP bits; valid only at imposition.
Definition: fib_types.h:430
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:180
static const char *const *const mpls_label_imp_pipe_no_ip_tll_decr_nodes[DPO_PROTO_NUM]
u32 flags
Definition: vhost-user.h:77
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:62
dpo_type_t mpls_label_dpo_get_type(mpls_label_dpo_flags_t flags)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:111
enum mpls_label_dpo_attr_t_ mpls_label_dpo_attr_t
Flags present on an MPLS label sourced path-extension.
static mpls_unicast_header_t * mpls_label_paint(vlib_buffer_t *b0, mpls_label_dpo_t *mld0)
static mpls_label_dpo_t * mpls_label_dpo_alloc(void)
u8 * format_mpls_label_dpo_flags(u8 *s, va_list *args)
Format the flags variable.
#define MPLS_LABEL_DEFAULT_TTL
The Default TTL added to MPLS label headers when no other value is available.
Definition: packet.h:48
static void mpls_label_interpose(const dpo_id_t *original, const dpo_id_t *parent, dpo_id_t *clone)
Interpose a label DPO.
A struct to hold tracing information for the MPLS label imposition node.
static void mpls_label_dpo_unlock(dpo_id_t *dpo)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
static const char *const mpls_label_imp_pipe_ip4_nodes[]
A representation of an MPLS label for imposition in the data-path.
static dpo_type_t mpls_label_dpo_types[1<< MPLS_LABEL_DPO_ATTR_MAX]
registered DPO types for each of the label sub-types.
void dpo_stack(dpo_type_t child_type, dpo_proto_t child_proto, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child-parent relationship.
Definition: dpo.c:515
enum mpls_eos_bit_t_ mpls_eos_bit_t
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128