FD.io VPP  v17.04-9-g99c0734
Vector Packet Processing
sr_localsid.c
Go to the documentation of this file.
1 /*
2  * sr_localsid.c: ipv6 segment routing Endpoint behaviors
3  *
4  * Copyright (c) 2016 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 /**
19  * @file
20  * @brief Processing of packets with a SRH
21  *
22  * CLI to define new Segment Routing End processing functions.
23  * Graph node to support such functions.
24  *
25  * Each function associates an SRv6 segment (IPv6 address) with an specific
26  * Segment Routing function.
27  *
28  */
29 
30 #include <vlib/vlib.h>
31 #include <vnet/vnet.h>
32 #include <vnet/sr/sr.h>
33 #include <vnet/ip/ip.h>
34 #include <vnet/sr/sr_packet.h>
35 #include <vnet/ip/ip6_packet.h>
36 #include <vnet/fib/ip6_fib.h>
37 #include <vnet/dpo/dpo.h>
38 #include <vnet/adj/adj.h>
39 
40 #include <vppinfra/error.h>
41 #include <vppinfra/elog.h>
42 
43 /**
44  * @brief Dynamically added SR localsid DPO type
45  */
48 
49 /**
50  * @brief SR localsid add/del
51  *
52  * Function to add or delete SR LocalSIDs.
53  *
54  * @param is_del Boolean of whether its a delete instruction
55  * @param localsid_addr IPv6 address of the localsid
56  * @param is_decap Boolean of whether decapsulation is allowed in this function
57  * @param behavior Type of behavior (function) for this localsid
58  * @param sw_if_index Only for L2/L3 xconnect. OIF. In VRF variant the fib_table.
59  * @param vlan_index Only for L2 xconnect. Outgoing VLAN tag.
60  * @param fib_table FIB table in which we should install the localsid entry
61  * @param nh_addr Next Hop IPv4/IPv6 address. Only for L2/L3 xconnect.
62  *
63  * @return 0 on success, error otherwise.
64  */
65 int
66 sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
67  char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index,
68  u32 fib_table, ip46_address_t * nh_addr, void *ls_plugin_mem)
69 {
70  ip6_sr_main_t *sm = &sr_main;
71  uword *p;
72  int rv;
73 
74  ip6_sr_localsid_t *ls = 0;
75 
76  dpo_id_t dpo = DPO_INVALID;
77 
78  /* Search for the item */
79  p = mhash_get (&sm->sr_localsids_index_hash, localsid_addr);
80 
81  if (p)
82  {
83  if (is_del)
84  {
85  /* Retrieve localsid */
86  ls = pool_elt_at_index (sm->localsids, p[0]);
87  /* Delete FIB entry */
88  fib_prefix_t pfx = {
90  .fp_len = 128,
91  .fp_addr = {
92  .ip6 = *localsid_addr,
93  }
94  };
95 
97  (FIB_PROTOCOL_IP6, fib_table), &pfx,
99 
100  /* In case it is a Xconnect iface remove the (OIF, NHOP) adj */
101  if (ls->behavior == SR_BEHAVIOR_X || ls->behavior == SR_BEHAVIOR_DX6
102  || ls->behavior == SR_BEHAVIOR_DX4)
103  adj_unlock (ls->nh_adj);
104 
105  if (ls->behavior >= SR_BEHAVIOR_LAST)
106  {
107  sr_localsid_fn_registration_t *plugin = 0;
108  plugin = pool_elt_at_index (sm->plugin_functions,
109  ls->behavior - SR_BEHAVIOR_LAST);
110 
111  /* Callback plugin removal function */
112  rv = plugin->removal (ls);
113  }
114 
115  /* Delete localsid registry */
116  pool_put (sm->localsids, ls);
117  mhash_unset (&sm->sr_localsids_index_hash, localsid_addr, NULL);
118  return 1;
119  }
120  else /* create with function already existing; complain */
121  return -1;
122  }
123  else
124  /* delete; localsid does not exist; complain */
125  if (is_del)
126  return -2;
127 
128  /* Check whether there exists a FIB entry with such address */
129  fib_prefix_t pfx = {
131  .fp_len = 128,
132  };
133 
134  pfx.fp_addr.as_u64[0] = localsid_addr->as_u64[0];
135  pfx.fp_addr.as_u64[1] = localsid_addr->as_u64[1];
136 
137  /* Lookup the FIB index associated to the table id provided */
138  u32 fib_index = fib_table_id_find_fib_index (FIB_PROTOCOL_IP6, fib_table);
139  if (fib_index == ~0)
140  return -3;
141 
142  /* Lookup the localsid in such FIB table */
143  fib_node_index_t fei = fib_table_lookup_exact_match (fib_index, &pfx);
144  if (FIB_NODE_INDEX_INVALID != fei)
145  return -4; //There is an entry for such address (the localsid addr)
146 
147  /* Create a new localsid registry */
148  pool_get (sm->localsids, ls);
149  memset (ls, 0, sizeof (*ls));
150 
151  clib_memcpy (&ls->localsid, localsid_addr, sizeof (ip6_address_t));
152  ls->end_psp = end_psp;
153  ls->behavior = behavior;
154  ls->nh_adj = (u32) ~ 0;
155  ls->fib_table = fib_table;
156  switch (behavior)
157  {
158  case SR_BEHAVIOR_END:
159  break;
160  case SR_BEHAVIOR_X:
161  ls->sw_if_index = sw_if_index;
162  clib_memcpy (&ls->next_hop.ip6, &nh_addr->ip6, sizeof (ip6_address_t));
163  break;
164  case SR_BEHAVIOR_DX4:
165  ls->sw_if_index = sw_if_index;
166  clib_memcpy (&ls->next_hop.ip4, &nh_addr->ip4, sizeof (ip4_address_t));
167  break;
168  case SR_BEHAVIOR_DX6:
169  ls->sw_if_index = sw_if_index;
170  clib_memcpy (&ls->next_hop.ip6, &nh_addr->ip6, sizeof (ip6_address_t));
171  break;
172  case SR_BEHAVIOR_DT6:
173  ls->vrf_index = sw_if_index;
174  break;
175  case SR_BEHAVIOR_DX2:
176  ls->sw_if_index = sw_if_index;
177  ls->vlan_index = vlan_index;
178  break;
179  }
180 
181  /* Figure out the adjacency magic for Xconnect variants */
182  if (ls->behavior == SR_BEHAVIOR_X || ls->behavior == SR_BEHAVIOR_DX4
183  || ls->behavior == SR_BEHAVIOR_DX6)
184  {
185  adj_index_t nh_adj_index = ADJ_INDEX_INVALID;
186 
187  /* Retrieve the adjacency corresponding to the (OIF, next_hop) */
188  if (ls->behavior == SR_BEHAVIOR_DX6 || ls->behavior == SR_BEHAVIOR_X)
190  nh_addr, sw_if_index);
191 
192  else if (ls->behavior == SR_BEHAVIOR_DX4)
194  nh_addr, sw_if_index);
195 
196  /* Check for ADJ creation error. If so panic */
197  if (nh_adj_index == ADJ_INDEX_INVALID)
198  {
199  pool_put (sm->localsids, ls);
200  return -5;
201  }
202 
203  ls->nh_adj = nh_adj_index;
204  }
205 
206  /* Set DPO */
207  if (ls->behavior == SR_BEHAVIOR_END || ls->behavior == SR_BEHAVIOR_X)
209  else if (ls->behavior > SR_BEHAVIOR_D_FIRST
210  && ls->behavior < SR_BEHAVIOR_LAST)
212  else if (ls->behavior >= SR_BEHAVIOR_LAST)
213  {
214  sr_localsid_fn_registration_t *plugin = 0;
215  plugin = pool_elt_at_index (sm->plugin_functions,
216  ls->behavior - SR_BEHAVIOR_LAST);
217  /* Copy the unformat memory result */
218  ls->plugin_mem = ls_plugin_mem;
219  /* Callback plugin creation function */
220  rv = plugin->creation (ls);
221  if (rv)
222  {
223  pool_put (sm->localsids, ls);
224  return -6;
225  }
226  dpo_set (&dpo, plugin->dpo, DPO_PROTO_IP6, ls - sm->localsids);
227  }
228 
229  /* Set hash key for searching localsid by address */
230  mhash_set (&sm->sr_localsids_index_hash, localsid_addr, ls - sm->localsids,
231  NULL);
232 
235  dpo_reset (&dpo);
236 
237  /* Set counter to zero */
239  ls - sm->localsids);
241  ls - sm->localsids);
242 
244  ls - sm->localsids);
246  ls - sm->localsids);
247 
248  return 0;
249 }
250 
251 /**
252  * @brief SR LocalSID CLI function.
253  *
254  * @see sr_cli_localsid
255  */
256 static clib_error_t *
258  vlib_cli_command_t * cmd)
259 {
260  vnet_main_t *vnm = vnet_get_main ();
261  ip6_sr_main_t *sm = &sr_main;
262  u32 sw_if_index = (u32) ~ 0, vlan_index = (u32) ~ 0, fib_index = 0;
263  int is_del = 0;
264  int end_psp = 0;
265  ip6_address_t resulting_address;
266  ip46_address_t next_hop;
267  char address_set = 0;
268  char behavior = 0;
269  void *ls_plugin_mem = 0;
270 
271  int rv;
272 
273  memset (&resulting_address, 0, sizeof (ip6_address_t));
274  ip46_address_reset (&next_hop);
275 
277  {
278  if (unformat (input, "del"))
279  is_del = 1;
280  else if (!address_set
281  && unformat (input, "address %U", unformat_ip6_address,
282  &resulting_address))
283  address_set = 1;
284  else if (!address_set
285  && unformat (input, "addr %U", unformat_ip6_address,
286  &resulting_address))
287  address_set = 1;
288  else if (unformat (input, "fib-table %u", &fib_index));
289  else if (vlan_index == (u32) ~ 0
290  && unformat (input, "vlan %u", &vlan_index));
291  else if (!behavior && unformat (input, "behavior"))
292  {
293  if (unformat (input, "end.x %U %U",
294  unformat_vnet_sw_interface, vnm, &sw_if_index,
295  unformat_ip6_address, &next_hop.ip6))
296  behavior = SR_BEHAVIOR_X;
297  else if (unformat (input, "end.dx6 %U %U",
298  unformat_vnet_sw_interface, vnm, &sw_if_index,
299  unformat_ip6_address, &next_hop.ip6))
300  behavior = SR_BEHAVIOR_DX6;
301  else if (unformat (input, "end.dx4 %U %U",
302  unformat_vnet_sw_interface, vnm, &sw_if_index,
303  unformat_ip4_address, &next_hop.ip4))
304  behavior = SR_BEHAVIOR_DX4;
305  else if (unformat (input, "end.dx2 %U",
306  unformat_vnet_sw_interface, vnm, &sw_if_index))
307  behavior = SR_BEHAVIOR_DX2;
308  else if (unformat (input, "end.dt6 %u", &sw_if_index))
309  behavior = SR_BEHAVIOR_DT6;
310  else if (unformat (input, "end.dt4 %u", &sw_if_index))
311  behavior = SR_BEHAVIOR_DT4;
312  else
313  {
314  /* Loop over all the plugin behavior format functions */
315  sr_localsid_fn_registration_t *plugin = 0, **vec_plugins = 0;
316  sr_localsid_fn_registration_t **plugin_it = 0;
317 
318  /* Create a vector out of the plugin pool as recommended */
319  /* *INDENT-OFF* */
320  pool_foreach (plugin, sm->plugin_functions,
321  {
322  vec_add1 (vec_plugins, plugin);
323  });
324  /* *INDENT-ON* */
325 
326  vec_foreach (plugin_it, vec_plugins)
327  {
328  if (unformat
329  (input, "%U", (*plugin_it)->ls_unformat, &ls_plugin_mem))
330  {
331  behavior = (*plugin_it)->sr_localsid_function_number;
332  break;
333  }
334  }
335  }
336 
337  if (!behavior)
338  {
339  if (unformat (input, "end"))
340  behavior = SR_BEHAVIOR_END;
341  else
342  break;
343  }
344  }
345  else if (!end_psp && unformat (input, "psp"))
346  end_psp = 1;
347  else
348  break;
349  }
350 
351  if (!behavior && end_psp)
352  behavior = SR_BEHAVIOR_END;
353 
354  if (!address_set)
355  return clib_error_return (0,
356  "Error: SRv6 LocalSID address is mandatory.");
357  if (!is_del && !behavior)
358  return clib_error_return (0,
359  "Error: SRv6 LocalSID behavior is mandatory.");
360  if (vlan_index != (u32) ~ 0)
361  return clib_error_return (0,
362  "Error: SRv6 End.DX2 with rewrite VLAN tag not supported by now.");
363  if (end_psp && !(behavior == SR_BEHAVIOR_END || behavior == SR_BEHAVIOR_X))
364  return clib_error_return (0,
365  "Error: SRv6 PSP only compatible with End and End.X");
366 
367  rv = sr_cli_localsid (is_del, &resulting_address, end_psp, behavior,
368  sw_if_index, vlan_index, fib_index, &next_hop,
369  ls_plugin_mem);
370 
371  switch (rv)
372  {
373  case 0:
374  break;
375  case 1:
376  return 0;
377  case -1:
378  return clib_error_return (0,
379  "Identical localsid already exists. Requested localsid not created.");
380  case -2:
381  return clib_error_return (0,
382  "The requested localsid could not be deleted. SR localsid not found");
383  case -3:
384  return clib_error_return (0, "FIB table %u does not exist", fib_index);
385  case -4:
386  return clib_error_return (0, "There is already one FIB entry for the"
387  "requested localsid non segment routing related");
388  case -5:
389  return clib_error_return (0,
390  "Could not create ARP/ND entry for such next_hop. Internal error.");
391  case -6:
392  return clib_error_return (0,
393  "Error on the plugin based localsid creation.");
394  default:
395  return clib_error_return (0, "BUG: sr localsid returns %d", rv);
396  }
397  return 0;
398 }
399 
400 /* *INDENT-OFF* */
401 VLIB_CLI_COMMAND (sr_localsid_command, static) = {
402  .path = "sr localsid",
403  .short_help = "sr localsid (del) address XX:XX::YY:YY"
404  "(fib-table 8) behavior STRING",
405  .long_help =
406  "Create SR LocalSID and binds it to a particular behavior\n"
407  "Arguments:\n"
408  "\tlocalSID IPv6_addr(128b) LocalSID IPv6 address\n"
409  "\t(fib-table X) Optional. VRF where to install SRv6 localsid\n"
410  "\tbehavior STRING Specifies the behavior\n"
411  "\n\tBehaviors:\n"
412  "\tEnd\t-> Endpoint.\n"
413  "\tEnd.X\t-> Endpoint with decapsulation and Layer-3 cross-connect.\n"
414  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
415  "\tEnd.DX2\t-> Endpoint with decapsulation and Layer-2 cross-connect.\n"
416  "\t\tParameters: '<iface>'\n"
417  "\tEnd.DX6\t-> Endpoint with decapsulation and IPv6 cross-connect.\n"
418  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
419  "\tEnd.DX4\t-> Endpoint with decapsulation and IPv4 cross-connect.\n"
420  "\t\tParameters: '<iface> <ip4_next_hop>'\n"
421  "\tEnd.DT6\t-> Endpoint with decapsulation and specific IPv6 table lookup.\n"
422  "\t\tParameters: '<ip6_fib_table>'\n"
423  "\tEnd.DT4\t-> Endpoint with decapsulation and specific IPv4 table lookup.\n"
424  "\t\tParameters: '<ip4_fib_table>'\n",
425  .function = sr_cli_localsid_command_fn,
426 };
427 /* *INDENT-ON* */
428 
429 /**
430  * @brief CLI function to 'show' all SR LocalSIDs on console.
431  */
432 static clib_error_t *
434  vlib_cli_command_t * cmd)
435 {
436  vnet_main_t *vnm = vnet_get_main ();
437  ip6_sr_main_t *sm = &sr_main;
438  ip6_sr_localsid_t **localsid_list = 0;
439  ip6_sr_localsid_t *ls;
440  int i;
441 
442  vlib_cli_output (vm, "SRv6 - My LocalSID Table:");
443  vlib_cli_output (vm, "=========================");
444  /* *INDENT-OFF* */
445  pool_foreach (ls, sm->localsids, ({ vec_add1 (localsid_list, ls); }));
446  /* *INDENT-ON* */
447  for (i = 0; i < vec_len (localsid_list); i++)
448  {
449  ls = localsid_list[i];
450  switch (ls->behavior)
451  {
452  case SR_BEHAVIOR_END:
453  vlib_cli_output (vm, "\tAddress: \t%U\n\tBehavior: \tEnd",
455  break;
456  case SR_BEHAVIOR_X:
457  vlib_cli_output (vm,
458  "\tAddress: \t%U\n\tBehavior: \tX (Endpoint with Layer-3 cross-connect)"
459  "\n\tIface: \t%U\n\tNext hop: \t%U",
462  format_ip6_address, &ls->next_hop.ip6);
463  break;
464  case SR_BEHAVIOR_DX4:
465  vlib_cli_output (vm,
466  "\tAddress: \t%U\n\tBehavior: \tDX4 (Endpoint with decapsulation and IPv4 cross-connect)"
467  "\n\tIface: \t%U\n\tNext hop: \t%U",
470  format_ip4_address, &ls->next_hop.ip4);
471  break;
472  case SR_BEHAVIOR_DX6:
473  vlib_cli_output (vm,
474  "\tAddress: \t%U\n\tBehavior: \tDX6 (Endpoint with decapsulation and IPv6 cross-connect)"
475  "\n\tIface: \t%U\n\tNext hop: \t%U",
478  format_ip6_address, &ls->next_hop.ip6);
479  break;
480  case SR_BEHAVIOR_DX2:
481  if (ls->vlan_index == (u32) ~ 0)
482  vlib_cli_output (vm,
483  "\tAddress: \t%U\n\tBehavior: \tDX2 (Endpoint with decapulation and Layer-2 cross-connect)"
484  "\n\tIface: \t%U", format_ip6_address,
486  ls->sw_if_index);
487  else
488  vlib_cli_output (vm,
489  "Unsupported yet. (DX2 with egress VLAN rewrite)");
490  break;
491  case SR_BEHAVIOR_DT6:
492  vlib_cli_output (vm,
493  "\tAddress: \t%U\n\tBehavior: \tDT6 (Endpoint with decapsulation and specific IPv6 table lookup)"
494  "\n\tTable: %u", format_ip6_address, &ls->localsid,
495  ls->fib_table);
496  break;
497  case SR_BEHAVIOR_DT4:
498  vlib_cli_output (vm,
499  "\tAddress: \t%U\n\tBehavior: \tDT4 (Endpoint with decapsulation and specific IPv4 table lookup)"
500  "\n\tTable: \t%u", format_ip6_address,
501  &ls->localsid, ls->fib_table);
502  break;
503  default:
504  if (ls->behavior >= SR_BEHAVIOR_LAST)
505  {
508  ls->behavior - SR_BEHAVIOR_LAST);
509 
510  vlib_cli_output (vm, "\tAddress: \t%U\n"
511  "\tBehavior: \t%s (%s)\n\t%U",
513  plugin->keyword_str, plugin->def_str,
514  plugin->ls_format, ls->plugin_mem);
515  }
516  else
517  //Should never get here...
518  vlib_cli_output (vm, "Internal error");
519  break;
520  }
521  if (ls->end_psp)
522  vlib_cli_output (vm, "\tPSP: \tTrue\n");
523 
524  /* Print counters */
525  vlib_counter_t valid, invalid;
528  vlib_cli_output (vm, "\tGood traffic: \t[%Ld packets : %Ld bytes]\n",
529  valid.packets, valid.bytes);
530  vlib_cli_output (vm, "\tBad traffic: \t[%Ld packets : %Ld bytes]\n",
531  invalid.packets, invalid.bytes);
532  vlib_cli_output (vm, "--------------------");
533  }
534  return 0;
535 }
536 
537 /* *INDENT-OFF* */
538 VLIB_CLI_COMMAND (show_sr_localsid_command, static) = {
539  .path = "show sr localsids",
540  .short_help = "show sr localsids",
541  .function = show_sr_localsid_command_fn,
542 };
543 /* *INDENT-ON* */
544 
545 /**
546  * @brief Function to 'clear' ALL SR localsid counters
547  */
548 static clib_error_t *
550  unformat_input_t * input,
551  vlib_cli_command_t * cmd)
552 {
553  ip6_sr_main_t *sm = &sr_main;
554 
557 
558  return 0;
559 }
560 
561 /* *INDENT-OFF* */
562 VLIB_CLI_COMMAND (clear_sr_localsid_counters_command, static) = {
563  .path = "clear sr localsid counters",
564  .short_help = "clear sr localsid counters",
566 };
567 /* *INDENT-ON* */
568 
569 /************************ SR LocalSID graphs node ****************************/
570 /**
571  * @brief SR localsid node trace
572  */
573 typedef struct
574 {
576  ip6_address_t src, out_dst;
577  u8 sr[256];
580  //With SRv6 header update include flags here.
582 
583 #define foreach_sr_localsid_error \
584 _(NO_INNER_HEADER, "(SR-Error) No inner IP header") \
585 _(NO_MORE_SEGMENTS, "(SR-Error) No more segments") \
586 _(NO_SRH, "(SR-Error) No SR header") \
587 _(NO_PSP, "(SR-Error) PSP Not available (segments left > 0)") \
588 _(NOT_LS, "(SR-Error) Decaps not available (segments left > 0)") \
589 _(L2, "(SR-Error) SRv6 decapsulated a L2 frame without dest")
590 
591 typedef enum
592 {
593 #define _(sym,str) SR_LOCALSID_ERROR_##sym,
595 #undef _
598 
599 static char *sr_localsid_error_strings[] = {
600 #define _(sym,string) string,
602 #undef _
603 };
604 
605 #define foreach_sr_localsid_next \
606 _(ERROR, "error-drop") \
607 _(IP6_LOOKUP, "ip6-lookup") \
608 _(IP4_LOOKUP, "ip4-lookup") \
609 _(IP6_REWRITE, "ip6-rewrite") \
610 _(IP4_REWRITE, "ip4-rewrite") \
611 _(INTERFACE_OUTPUT, "interface-output")
612 
613 typedef enum
614 {
615 #define _(s,n) SR_LOCALSID_NEXT_##s,
617 #undef _
620 
621 /**
622  * @brief SR LocalSID graph node trace function
623  *
624  * @see sr_localsid
625  */
626 u8 *
627 format_sr_localsid_trace (u8 * s, va_list * args)
628 {
629  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
630  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
631  ip6_sr_main_t *sm = &sr_main;
632  sr_localsid_trace_t *t = va_arg (*args, sr_localsid_trace_t *);
633 
634  ip6_sr_localsid_t *ls =
636 
637  s =
638  format (s, "SR-LOCALSID:\n\tLocalsid: %U\n", format_ip6_address,
639  &ls->localsid);
640  switch (ls->behavior)
641  {
642  case SR_BEHAVIOR_END:
643  s = format (s, "\tBehavior: End\n");
644  break;
645  case SR_BEHAVIOR_DX6:
646  s = format (s, "\tBehavior: Decapsulation with IPv6 L3 xconnect\n");
647  break;
648  case SR_BEHAVIOR_DX4:
649  s = format (s, "\tBehavior: Decapsulation with IPv4 L3 xconnect\n");
650  break;
651  case SR_BEHAVIOR_X:
652  s = format (s, "\tBehavior: IPv6 L3 xconnect\n");
653  break;
654  case SR_BEHAVIOR_DT6:
655  s = format (s, "\tBehavior: Decapsulation with IPv6 Table lookup\n");
656  break;
657  case SR_BEHAVIOR_DT4:
658  s = format (s, "\tBehavior: Decapsulation with IPv4 Table lookup\n");
659  break;
660  case SR_BEHAVIOR_DX2:
661  s = format (s, "\tBehavior: Decapsulation with L2 xconnect\n");
662  break;
663  default:
664  s = format (s, "\tBehavior: defined in plugin\n"); //TODO
665  break;
666  }
667  if (t->num_segments != 0xFF)
668  {
669  if (t->num_segments > 0)
670  {
671  s = format (s, "\tSegments left: %d\n", t->num_segments);
672  s = format (s, "\tSID list: [in ietf order]");
673  int i = 0;
674  for (i = 0; i < t->num_segments; i++)
675  {
676  s = format (s, "\n\t-> %U", format_ip6_address,
677  (ip6_address_t *) & t->sr[i *
678  sizeof (ip6_address_t)]);
679  }
680  }
681  }
682  return s;
683 }
684 
685 /**
686  * @brief Function doing End processing.
687  */
690  vlib_buffer_t * b0,
691  ip6_header_t * ip0,
692  ip6_sr_header_t * sr0,
693  ip6_sr_localsid_t * ls0, u32 * next0)
694 {
695  ip6_address_t *new_dst0;
696 
698  {
699  if (PREDICT_TRUE (sr0->segments_left != 0))
700  {
701  sr0->segments_left -= 1;
702  new_dst0 = (ip6_address_t *) (sr0->segments);
703  new_dst0 += sr0->segments_left;
704  ip0->dst_address.as_u64[0] = new_dst0->as_u64[0];
705  ip0->dst_address.as_u64[1] = new_dst0->as_u64[1];
706 
707  if (ls0->behavior == SR_BEHAVIOR_X)
708  {
709  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
710  *next0 = SR_LOCALSID_NEXT_IP6_REWRITE;
711  }
712  }
713  else
714  {
715  *next0 = SR_LOCALSID_NEXT_ERROR;
716  b0->error = node->errors[SR_LOCALSID_ERROR_NO_MORE_SEGMENTS];
717  }
718  }
719  else
720  {
721  /* Error. Routing header of type != SR */
722  *next0 = SR_LOCALSID_NEXT_ERROR;
723  b0->error = node->errors[SR_LOCALSID_ERROR_NO_SRH];
724  }
725 }
726 
727 /*
728  * @brief Function doing SRH processing for D* variants
729  */
730 //FixME. I must crosscheck that next_proto matches the localsid
733  vlib_buffer_t * b0,
734  ip6_header_t * ip0,
735  ip6_sr_header_t * sr0,
736  ip6_sr_localsid_t * ls0, u32 * next0)
737 {
738  /* Compute the size of the IPv6 header with all Ext. headers */
739  u8 next_proto;
740  ip6_ext_header_t *next_ext_header;
741  u16 total_size = 0;
742 
743  next_proto = ip0->protocol;
744  next_ext_header = (void *) (ip0 + 1);
745  total_size = sizeof (ip6_header_t);
746  while (ip6_ext_hdr (next_proto))
747  {
748  total_size += ip6_ext_header_len (next_ext_header);
749  next_proto = next_ext_header->next_hdr;
750  next_ext_header = ip6_ext_next_header (next_ext_header);
751  }
752 
753  /* Ensure this is the last segment. Otherwise drop. */
754  if (sr0 && sr0->segments_left != 0)
755  {
756  *next0 = SR_LOCALSID_NEXT_ERROR;
757  b0->error = node->errors[SR_LOCALSID_ERROR_NOT_LS];
758  return;
759  }
760 
761  switch (next_proto)
762  {
763  case IP_PROTOCOL_IPV6:
764  /* Encap-End IPv6. Pop outer IPv6 header. */
765  if (ls0->behavior == SR_BEHAVIOR_DX6)
766  {
767  vlib_buffer_advance (b0, total_size);
768  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
769  *next0 = SR_LOCALSID_NEXT_IP6_REWRITE;
770  return;
771  }
772  else if (ls0->behavior == SR_BEHAVIOR_DT6)
773  {
774  vlib_buffer_advance (b0, total_size);
775  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->fib_table;
776  return;
777  }
778  break;
779  case IP_PROTOCOL_IP_IN_IP:
780  /* Encap-End IPv4. Pop outer IPv6 header */
781  if (ls0->behavior == SR_BEHAVIOR_DX4)
782  {
783  vlib_buffer_advance (b0, total_size);
784  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
785  *next0 = SR_LOCALSID_NEXT_IP4_REWRITE;
786  return;
787  }
788  else if (ls0->behavior == SR_BEHAVIOR_DT4)
789  {
790  vlib_buffer_advance (b0, total_size);
791  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->fib_table;
792  *next0 = SR_LOCALSID_NEXT_IP4_LOOKUP;
793  return;
794  }
795  break;
796  case IP_PROTOCOL_IP6_NONXT:
797  /* L2 encaps */
798  if (ls0->behavior == SR_BEHAVIOR_DX2)
799  {
800  vlib_buffer_advance (b0, total_size);
801  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->sw_if_index;
802  *next0 = SR_LOCALSID_NEXT_INTERFACE_OUTPUT;
803  return;
804  }
805  break;
806  }
807  *next0 = SR_LOCALSID_NEXT_ERROR;
808  b0->error = node->errors[SR_LOCALSID_ERROR_NO_INNER_HEADER];
809  return;
810 }
811 
812 /**
813  * @brief Function doing End processing with PSP
814  */
817  vlib_buffer_t * b0,
818  ip6_header_t * ip0,
819  ip6_ext_header_t * prev0,
820  ip6_sr_header_t * sr0,
821  ip6_sr_localsid_t * ls0, u32 * next0)
822 {
823  u32 new_l0, sr_len;
824  u64 *copy_dst0, *copy_src0;
825  u32 copy_len_u64s0 = 0;
826  int i;
827 
829  {
830  if (PREDICT_TRUE (sr0->segments_left == 1))
831  {
832  ip0->dst_address.as_u64[0] = sr0->segments->as_u64[0];
833  ip0->dst_address.as_u64[1] = sr0->segments->as_u64[1];
834 
835  /* Remove the SRH taking care of the rest of IPv6 ext header */
836  if (prev0)
837  prev0->next_hdr = sr0->protocol;
838  else
839  ip0->protocol = sr0->protocol;
840 
841  sr_len = ip6_ext_header_len (sr0);
842  vlib_buffer_advance (b0, sr_len);
843  new_l0 = clib_net_to_host_u16 (ip0->payload_length) - sr_len;
844  ip0->payload_length = clib_host_to_net_u16 (new_l0);
845  copy_src0 = (u64 *) ip0;
846  copy_dst0 = copy_src0 + (sr0->length + 1);
847  /* number of 8 octet units to copy
848  * By default in absence of extension headers it is equal to length of ip6 header
849  * With extension headers it number of 8 octet units of ext headers preceding
850  * SR header
851  */
852  copy_len_u64s0 =
853  (((u8 *) sr0 - (u8 *) ip0) - sizeof (ip6_header_t)) >> 3;
854  copy_dst0[4 + copy_len_u64s0] = copy_src0[4 + copy_len_u64s0];
855  copy_dst0[3 + copy_len_u64s0] = copy_src0[3 + copy_len_u64s0];
856  copy_dst0[2 + copy_len_u64s0] = copy_src0[2 + copy_len_u64s0];
857  copy_dst0[1 + copy_len_u64s0] = copy_src0[1 + copy_len_u64s0];
858  copy_dst0[0 + copy_len_u64s0] = copy_src0[0 + copy_len_u64s0];
859 
860  for (i = copy_len_u64s0 - 1; i >= 0; i--)
861  {
862  copy_dst0[i] = copy_src0[i];
863  }
864 
865  if (ls0->behavior == SR_BEHAVIOR_X)
866  {
867  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
868  *next0 = SR_LOCALSID_NEXT_IP6_REWRITE;
869  }
870  return;
871  }
872  }
873  /* Error. Routing header of type != SR */
874  *next0 = SR_LOCALSID_NEXT_ERROR;
875  b0->error = node->errors[SR_LOCALSID_ERROR_NO_PSP];
876 }
877 
878 /**
879  * @brief SR LocalSID graph node. Supports all default SR Endpoint variants
880  */
881 static uword
883  vlib_frame_t * from_frame)
884 {
885  u32 n_left_from, next_index, *from, *to_next;
886  ip6_sr_main_t *sm = &sr_main;
887  from = vlib_frame_vector_args (from_frame);
888  n_left_from = from_frame->n_vectors;
889  next_index = node->cached_next_index;
890  u32 cpu_index = os_get_cpu_number ();
891 
892  while (n_left_from > 0)
893  {
894  u32 n_left_to_next;
895  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
896 
897  /* Quad - Loop */
898  while (n_left_from >= 8 && n_left_to_next >= 4)
899  {
900  u32 bi0, bi1, bi2, bi3;
901  vlib_buffer_t *b0, *b1, *b2, *b3;
902  ip6_header_t *ip0, *ip1, *ip2, *ip3;
903  ip6_ext_header_t *prev0, *prev1, *prev2, *prev3;
904  ip6_sr_header_t *sr0, *sr1, *sr2, *sr3;
905  u32 next0, next1, next2, next3;
906  next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP;
907  ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3;
908 
909  /* Prefetch next iteration. */
910  {
911  vlib_buffer_t *p4, *p5, *p6, *p7;
912 
913  p4 = vlib_get_buffer (vm, from[4]);
914  p5 = vlib_get_buffer (vm, from[5]);
915  p6 = vlib_get_buffer (vm, from[6]);
916  p7 = vlib_get_buffer (vm, from[7]);
917 
918  /* Prefetch the buffer header and packet for the N+4 loop iteration */
919  vlib_prefetch_buffer_header (p4, LOAD);
920  vlib_prefetch_buffer_header (p5, LOAD);
921  vlib_prefetch_buffer_header (p6, LOAD);
922  vlib_prefetch_buffer_header (p7, LOAD);
923 
928  }
929 
930  to_next[0] = bi0 = from[0];
931  to_next[1] = bi1 = from[1];
932  to_next[2] = bi2 = from[2];
933  to_next[3] = bi3 = from[3];
934  from += 4;
935  to_next += 4;
936  n_left_from -= 4;
937  n_left_to_next -= 4;
938 
939  b0 = vlib_get_buffer (vm, bi0);
940  b1 = vlib_get_buffer (vm, bi1);
941  b2 = vlib_get_buffer (vm, bi2);
942  b3 = vlib_get_buffer (vm, bi3);
943 
944  ls0 =
946  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
947  ls1 =
949  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
950  ls2 =
952  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
953  ls3 =
955  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
956 
957  ip0 = vlib_buffer_get_current (b0);
958  ip1 = vlib_buffer_get_current (b1);
959  ip2 = vlib_buffer_get_current (b2);
960  ip3 = vlib_buffer_get_current (b3);
961 
962  ip6_ext_header_find_t (ip0, prev0, sr0, IP_PROTOCOL_IPV6_ROUTE);
963  ip6_ext_header_find_t (ip1, prev1, sr1, IP_PROTOCOL_IPV6_ROUTE);
964  ip6_ext_header_find_t (ip2, prev2, sr2, IP_PROTOCOL_IPV6_ROUTE);
965  ip6_ext_header_find_t (ip3, prev3, sr3, IP_PROTOCOL_IPV6_ROUTE);
966 
967  end_decaps_srh_processing (node, b0, ip0, sr0, ls0, &next0);
968  end_decaps_srh_processing (node, b1, ip1, sr1, ls1, &next1);
969  end_decaps_srh_processing (node, b2, ip2, sr2, ls2, &next2);
970  end_decaps_srh_processing (node, b3, ip3, sr3, ls3, &next3);
971 
972  //TODO: trace.
973 
975  (((next0 ==
976  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
977  &(sm->sr_ls_valid_counters)), cpu_index, ls0 - sm->localsids, 1,
978  vlib_buffer_length_in_chain (vm, b0));
979 
981  (((next1 ==
982  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
983  &(sm->sr_ls_valid_counters)), cpu_index, ls1 - sm->localsids, 1,
984  vlib_buffer_length_in_chain (vm, b1));
985 
987  (((next2 ==
988  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
989  &(sm->sr_ls_valid_counters)), cpu_index, ls2 - sm->localsids, 1,
990  vlib_buffer_length_in_chain (vm, b2));
991 
993  (((next3 ==
994  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
995  &(sm->sr_ls_valid_counters)), cpu_index, ls3 - sm->localsids, 1,
996  vlib_buffer_length_in_chain (vm, b3));
997 
998  vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
999  n_left_to_next, bi0, bi1, bi2, bi3,
1000  next0, next1, next2, next3);
1001  }
1002 
1003  /* Single loop for potentially the last three packets */
1004  while (n_left_from > 0 && n_left_to_next > 0)
1005  {
1006  u32 bi0;
1007  vlib_buffer_t *b0;
1008  ip6_header_t *ip0;
1009  ip6_ext_header_t *prev0;
1010  ip6_sr_header_t *sr0;
1011  u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP;
1012  ip6_sr_localsid_t *ls0;
1013 
1014  bi0 = from[0];
1015  to_next[0] = bi0;
1016  from += 1;
1017  to_next += 1;
1018  n_left_from -= 1;
1019  n_left_to_next -= 1;
1020 
1021  b0 = vlib_get_buffer (vm, bi0);
1022  ip0 = vlib_buffer_get_current (b0);
1023 
1024  /* Lookup the SR End behavior based on IP DA (adj) */
1025  ls0 =
1027  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1028 
1029  /* Find SRH as well as previous header */
1030  ip6_ext_header_find_t (ip0, prev0, sr0, IP_PROTOCOL_IPV6_ROUTE);
1031 
1032  /* SRH processing and End variants */
1033  end_decaps_srh_processing (node, b0, ip0, sr0, ls0, &next0);
1034 
1036  {
1037  sr_localsid_trace_t *tr =
1038  vlib_add_trace (vm, node, b0, sizeof (*tr));
1039  tr->num_segments = 0;
1040  tr->localsid_index = ls0 - sm->localsids;
1041 
1042  if (ip0 == vlib_buffer_get_current (b0))
1043  {
1044  clib_memcpy (tr->src.as_u8, ip0->src_address.as_u8,
1045  sizeof (tr->src.as_u8));
1047  sizeof (tr->out_dst.as_u8));
1048  if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
1049  && sr0->type == ROUTING_HEADER_TYPE_SR)
1050  {
1051  clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
1052  tr->num_segments =
1053  sr0->length * 8 / sizeof (ip6_address_t);
1054  tr->segments_left = sr0->segments_left;
1055  }
1056  }
1057  else
1058  tr->num_segments = 0xFF;
1059  }
1060 
1061  /* Increase the counters */
1063  (((next0 ==
1064  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1065  &(sm->sr_ls_valid_counters)), cpu_index, ls0 - sm->localsids, 1,
1066  vlib_buffer_length_in_chain (vm, b0));
1067 
1068  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1069  n_left_to_next, bi0, next0);
1070  }
1071  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1072  }
1073  return from_frame->n_vectors;
1074 }
1075 
1076 /* *INDENT-OFF* */
1078  .function = sr_localsid_d_fn,
1079  .name = "sr-localsid-d",
1080  .vector_size = sizeof (u32),
1081  .format_trace = format_sr_localsid_trace,
1082  .type = VLIB_NODE_TYPE_INTERNAL,
1083  .n_errors = SR_LOCALSID_N_ERROR,
1084  .error_strings = sr_localsid_error_strings,
1085  .n_next_nodes = SR_LOCALSID_N_NEXT,
1086  .next_nodes = {
1087 #define _(s,n) [SR_LOCALSID_NEXT_##s] = n,
1089 #undef _
1090  },
1091 };
1092 /* *INDENT-ON* */
1093 
1094 /**
1095  * @brief SR LocalSID graph node. Supports all default SR Endpoint variants
1096  */
1097 static uword
1099  vlib_frame_t * from_frame)
1100 {
1101  u32 n_left_from, next_index, *from, *to_next;
1102  ip6_sr_main_t *sm = &sr_main;
1103  from = vlib_frame_vector_args (from_frame);
1104  n_left_from = from_frame->n_vectors;
1105  next_index = node->cached_next_index;
1106  u32 cpu_index = os_get_cpu_number ();
1107 
1108  while (n_left_from > 0)
1109  {
1110  u32 n_left_to_next;
1111  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1112 
1113  /* Quad - Loop */
1114  while (n_left_from >= 8 && n_left_to_next >= 4)
1115  {
1116  u32 bi0, bi1, bi2, bi3;
1117  vlib_buffer_t *b0, *b1, *b2, *b3;
1118  ip6_header_t *ip0, *ip1, *ip2, *ip3;
1119  ip6_sr_header_t *sr0, *sr1, *sr2, *sr3;
1120  ip6_ext_header_t *prev0, *prev1, *prev2, *prev3;
1121  u32 next0, next1, next2, next3;
1122  next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP;
1123  ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3;
1124 
1125  /* Prefetch next iteration. */
1126  {
1127  vlib_buffer_t *p4, *p5, *p6, *p7;
1128 
1129  p4 = vlib_get_buffer (vm, from[4]);
1130  p5 = vlib_get_buffer (vm, from[5]);
1131  p6 = vlib_get_buffer (vm, from[6]);
1132  p7 = vlib_get_buffer (vm, from[7]);
1133 
1134  /* Prefetch the buffer header and packet for the N+2 loop iteration */
1135  vlib_prefetch_buffer_header (p4, LOAD);
1136  vlib_prefetch_buffer_header (p5, LOAD);
1137  vlib_prefetch_buffer_header (p6, LOAD);
1138  vlib_prefetch_buffer_header (p7, LOAD);
1139 
1144  }
1145 
1146  to_next[0] = bi0 = from[0];
1147  to_next[1] = bi1 = from[1];
1148  to_next[2] = bi2 = from[2];
1149  to_next[3] = bi3 = from[3];
1150  from += 4;
1151  to_next += 4;
1152  n_left_from -= 4;
1153  n_left_to_next -= 4;
1154 
1155  b0 = vlib_get_buffer (vm, bi0);
1156  b1 = vlib_get_buffer (vm, bi1);
1157  b2 = vlib_get_buffer (vm, bi2);
1158  b3 = vlib_get_buffer (vm, bi3);
1159 
1160  ip0 = vlib_buffer_get_current (b0);
1161  ip1 = vlib_buffer_get_current (b1);
1162  ip2 = vlib_buffer_get_current (b2);
1163  ip3 = vlib_buffer_get_current (b3);
1164 
1165  ip6_ext_header_find_t (ip0, prev0, sr0, IP_PROTOCOL_IPV6_ROUTE);
1166  ip6_ext_header_find_t (ip1, prev1, sr1, IP_PROTOCOL_IPV6_ROUTE);
1167  ip6_ext_header_find_t (ip2, prev2, sr2, IP_PROTOCOL_IPV6_ROUTE);
1168  ip6_ext_header_find_t (ip3, prev3, sr3, IP_PROTOCOL_IPV6_ROUTE);
1169 
1170  ls0 =
1172  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1173  ls1 =
1175  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1176  ls2 =
1178  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1179  ls3 =
1181  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1182 
1183  if (ls0->end_psp)
1184  end_psp_srh_processing (node, b0, ip0, prev0, sr0, ls0, &next0);
1185  else
1186  end_srh_processing (node, b0, ip0, sr0, ls0, &next0);
1187 
1188  if (ls1->end_psp)
1189  end_psp_srh_processing (node, b1, ip1, prev1, sr1, ls1, &next1);
1190  else
1191  end_srh_processing (node, b1, ip1, sr1, ls1, &next1);
1192 
1193  if (ls2->end_psp)
1194  end_psp_srh_processing (node, b2, ip2, prev2, sr2, ls2, &next2);
1195  else
1196  end_srh_processing (node, b2, ip2, sr2, ls2, &next2);
1197 
1198  if (ls3->end_psp)
1199  end_psp_srh_processing (node, b3, ip3, prev3, sr3, ls3, &next3);
1200  else
1201  end_srh_processing (node, b3, ip3, sr3, ls3, &next3);
1202 
1203  //TODO: proper trace.
1204 
1206  (((next0 ==
1207  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1208  &(sm->sr_ls_valid_counters)), cpu_index, ls0 - sm->localsids, 1,
1209  vlib_buffer_length_in_chain (vm, b0));
1210 
1212  (((next1 ==
1213  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1214  &(sm->sr_ls_valid_counters)), cpu_index, ls1 - sm->localsids, 1,
1215  vlib_buffer_length_in_chain (vm, b1));
1216 
1218  (((next2 ==
1219  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1220  &(sm->sr_ls_valid_counters)), cpu_index, ls2 - sm->localsids, 1,
1221  vlib_buffer_length_in_chain (vm, b2));
1222 
1224  (((next3 ==
1225  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1226  &(sm->sr_ls_valid_counters)), cpu_index, ls3 - sm->localsids, 1,
1227  vlib_buffer_length_in_chain (vm, b3));
1228 
1229  vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
1230  n_left_to_next, bi0, bi1, bi2, bi3,
1231  next0, next1, next2, next3);
1232  }
1233 
1234  /* Single loop for potentially the last three packets */
1235  while (n_left_from > 0 && n_left_to_next > 0)
1236  {
1237  u32 bi0;
1238  vlib_buffer_t *b0;
1239  ip6_header_t *ip0 = 0;
1240  ip6_ext_header_t *prev0;
1241  ip6_sr_header_t *sr0;
1242  u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP;
1243  ip6_sr_localsid_t *ls0;
1244 
1245  bi0 = from[0];
1246  to_next[0] = bi0;
1247  from += 1;
1248  to_next += 1;
1249  n_left_from -= 1;
1250  n_left_to_next -= 1;
1251 
1252  b0 = vlib_get_buffer (vm, bi0);
1253  ip0 = vlib_buffer_get_current (b0);
1254  ip6_ext_header_find_t (ip0, prev0, sr0, IP_PROTOCOL_IPV6_ROUTE);
1255 
1256  /* Lookup the SR End behavior based on IP DA (adj) */
1257  ls0 =
1259  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1260 
1261  /* SRH processing */
1262  if (ls0->end_psp)
1263  end_psp_srh_processing (node, b0, ip0, prev0, sr0, ls0, &next0);
1264  else
1265  end_srh_processing (node, b0, ip0, sr0, ls0, &next0);
1266 
1268  {
1269  sr_localsid_trace_t *tr =
1270  vlib_add_trace (vm, node, b0, sizeof (*tr));
1271  tr->num_segments = 0;
1272  tr->localsid_index = ls0 - sm->localsids;
1273 
1274  if (ip0 == vlib_buffer_get_current (b0))
1275  {
1276  clib_memcpy (tr->src.as_u8, ip0->src_address.as_u8,
1277  sizeof (tr->src.as_u8));
1279  sizeof (tr->out_dst.as_u8));
1280  if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
1281  && sr0->type == ROUTING_HEADER_TYPE_SR)
1282  {
1283  clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
1284  tr->num_segments =
1285  sr0->length * 8 / sizeof (ip6_address_t);
1286  tr->segments_left = sr0->segments_left;
1287  }
1288  }
1289  else
1290  {
1291  tr->num_segments = 0xFF;
1292  }
1293  }
1294 
1296  (((next0 ==
1297  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1298  &(sm->sr_ls_valid_counters)), cpu_index, ls0 - sm->localsids, 1,
1299  vlib_buffer_length_in_chain (vm, b0));
1300 
1301  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1302  n_left_to_next, bi0, next0);
1303  }
1304  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1305  }
1306  return from_frame->n_vectors;
1307 }
1308 
1309 /* *INDENT-OFF* */
1311  .function = sr_localsid_fn,
1312  .name = "sr-localsid",
1313  .vector_size = sizeof (u32),
1314  .format_trace = format_sr_localsid_trace,
1315  .type = VLIB_NODE_TYPE_INTERNAL,
1316  .n_errors = SR_LOCALSID_N_ERROR,
1317  .error_strings = sr_localsid_error_strings,
1318  .n_next_nodes = SR_LOCALSID_N_NEXT,
1319  .next_nodes = {
1320 #define _(s,n) [SR_LOCALSID_NEXT_##s] = n,
1322 #undef _
1323  },
1324 };
1325 /* *INDENT-ON* */
1326 
1327 static u8 *
1328 format_sr_dpo (u8 * s, va_list * args)
1329 {
1330  index_t index = va_arg (*args, index_t);
1331  CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
1332 
1333  return (format (s, "SR: localsid_index:[%d]", index));
1334 }
1335 
1336 const static dpo_vft_t sr_loc_vft = {
1337  .dv_lock = sr_dpo_lock,
1338  .dv_unlock = sr_dpo_unlock,
1339  .dv_format = format_sr_dpo,
1340 };
1341 
1342 const static char *const sr_loc_ip6_nodes[] = {
1343  "sr-localsid",
1344  NULL,
1345 };
1346 
1347 const static char *const *const sr_loc_nodes[DPO_PROTO_NUM] = {
1349 };
1350 
1351 const static char *const sr_loc_d_ip6_nodes[] = {
1352  "sr-localsid-d",
1353  NULL,
1354 };
1355 
1356 const static char *const *const sr_loc_d_nodes[DPO_PROTO_NUM] = {
1358 };
1359 
1360 
1361 /*************************** SR LocalSID plugins ******************************/
1362 /**
1363  * @brief SR LocalSID plugin registry
1364  */
1365 int
1367  u8 * keyword_str, u8 * def_str,
1368  u8 * params_str, dpo_type_t * dpo,
1369  format_function_t * ls_format,
1370  unformat_function_t * ls_unformat,
1371  sr_plugin_callback_t * creation_fn,
1372  sr_plugin_callback_t * removal_fn)
1373 {
1374  ip6_sr_main_t *sm = &sr_main;
1375  uword *p;
1376 
1378 
1379  /* Did this function exist? If so update it */
1380  p = hash_get_mem (sm->plugin_functions_by_key, fn_name);
1381  if (p)
1382  {
1383  plugin = pool_elt_at_index (sm->plugin_functions, p[0]);
1384  }
1385  /* Else create a new one and set hash key */
1386  else
1387  {
1388  pool_get (sm->plugin_functions, plugin);
1389  hash_set_mem (sm->plugin_functions_by_key, fn_name,
1390  plugin - sm->plugin_functions);
1391  }
1392 
1393  memset (plugin, 0, sizeof (*plugin));
1394 
1395  plugin->sr_localsid_function_number = (plugin - sm->plugin_functions);
1397  plugin->ls_format = ls_format;
1398  plugin->ls_unformat = ls_unformat;
1399  plugin->creation = creation_fn;
1400  plugin->removal = removal_fn;
1401  clib_memcpy (&plugin->dpo, dpo, sizeof (dpo_type_t));
1402  plugin->function_name = format (0, "%s%c", fn_name, 0);
1403  plugin->keyword_str = format (0, "%s%c", keyword_str, 0);
1404  plugin->def_str = format (0, "%s%c", def_str, 0);
1405  plugin->params_str = format (0, "%s%c", params_str, 0);
1406 
1407  return plugin->sr_localsid_function_number;
1408 }
1409 
1410 /**
1411  * @brief CLI function to 'show' all available SR LocalSID behaviors
1412  */
1413 static clib_error_t *
1415  unformat_input_t * input,
1416  vlib_cli_command_t * cmd)
1417 {
1418  ip6_sr_main_t *sm = &sr_main;
1420  sr_localsid_fn_registration_t **plugins_vec = 0;
1421  int i;
1422 
1423  vlib_cli_output (vm,
1424  "SR LocalSIDs behaviors:\n-----------------------\n\n");
1425 
1426  /* *INDENT-OFF* */
1427  pool_foreach (plugin, sm->plugin_functions,
1428  ({ vec_add1 (plugins_vec, plugin); }));
1429  /* *INDENT-ON* */
1430 
1431  /* Print static behaviors */
1432  vlib_cli_output (vm, "Default behaviors:\n"
1433  "\tEnd\t-> Endpoint.\n"
1434  "\tEnd.X\t-> Endpoint with decapsulation and Layer-3 cross-connect.\n"
1435  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
1436  "\tEnd.DX2\t-> Endpoint with decapsulation and Layer-2 cross-connect.\n"
1437  "\t\tParameters: '<iface>'\n"
1438  "\tEnd.DX6\t-> Endpoint with decapsulation and IPv6 cross-connect.\n"
1439  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
1440  "\tEnd.DX4\t-> Endpoint with decapsulation and IPv4 cross-connect.\n"
1441  "\t\tParameters: '<iface> <ip4_next_hop>'\n"
1442  "\tEnd.DT6\t-> Endpoint with decapsulation and specific IPv6 table lookup.\n"
1443  "\t\tParameters: '<ip6_fib_table>'\n"
1444  "\tEnd.DT4\t-> Endpoint with decapsulation and specific IPv4 table lookup.\n"
1445  "\t\tParameters: '<ip4_fib_table>'\n");
1446  vlib_cli_output (vm, "Plugin behaviors:\n");
1447  for (i = 0; i < vec_len (plugins_vec); i++)
1448  {
1449  plugin = plugins_vec[i];
1450  vlib_cli_output (vm, "\t%s\t-> %s.\n", plugin->keyword_str,
1451  plugin->def_str);
1452  vlib_cli_output (vm, "\t\tParameters: '%s'\n", plugin->params_str);
1453  }
1454  return 0;
1455 }
1456 
1457 /* *INDENT-OFF* */
1458 VLIB_CLI_COMMAND (show_sr_localsid_behaviors_command, static) = {
1459  .path = "show sr localsids behaviors",
1460  .short_help = "show sr localsids behaviors",
1462 };
1463 /* *INDENT-ON* */
1464 
1465 /**
1466  * @brief SR LocalSID initialization
1467  */
1468 clib_error_t *
1470 {
1471  /* Init memory for function keys */
1472  ip6_sr_main_t *sm = &sr_main;
1473  mhash_init (&sm->sr_localsids_index_hash, sizeof (uword),
1474  sizeof (ip6_address_t));
1475  /* Init SR behaviors DPO type */
1477  /* Init SR behaviors DPO type */
1479  dpo_register_new_type (&sr_loc_vft, sr_loc_d_nodes);
1480  /* Init memory for localsid plugins */
1481  sm->plugin_functions_by_key = hash_create_string (0, sizeof (uword));
1482  return 0;
1483 }
1484 
1486 /*
1487 * fd.io coding-style-patch-verification: ON
1488 *
1489 * Local Variables:
1490 * eval: (c-set-style "gnu")
1491 * End:
1492 */
u8 * function_name
Function name.
Definition: sr.h:135
#define SR_BEHAVIOR_D_FIRST
Definition: sr.h:39
u32 fib_table_id_find_fib_index(fib_protocol_t proto, u32 table_id)
Definition: lookup.c:360
sr_localsid_error_t
Definition: sr_localsid.c:591
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:169
ip6_sr_main_t sr_main
Definition: sr.c:31
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:335
u32 vlan_index
VLAN tag (not an index)
Definition: sr.h:117
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:231
u32 nh_adj
Next_adj for xconnect usage only.
Definition: sr.h:121
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:330
static const char *const sr_loc_ip6_nodes[]
Definition: sr_localsid.c:1342
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:89
fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, const fib_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
Definition: fib_table.c:95
#define SR_BEHAVIOR_X
Definition: sr.h:38
SR LocalSID.
Definition: sr.h:101
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define PREDICT_TRUE(x)
Definition: clib.h:98
void sr_dpo_unlock(dpo_id_t *dpo)
no-op unlock function.
Definition: sr.c:47
int sr_cli_localsid(char is_del, ip6_address_t *localsid_addr, char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table, ip46_address_t *nh_addr, void *ls_plugin_mem)
SR localsid add/del.
Definition: sr_localsid.c:66
u8 as_u8[16]
Definition: ip6_packet.h:48
u64 as_u64[2]
Definition: ip6_packet.h:51
unsigned char params_str[32]
#define NULL
Definition: clib.h:55
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:353
format_function_t * ls_format
LocalSID format function.
Definition: sr.h:145
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:459
ip6_address_t out_dst
Definition: sr_localsid.c:576
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 SR_BEHAVIOR_DT6
Definition: sr.h:43
static_always_inline void end_decaps_srh_processing(vlib_node_runtime_t *node, vlib_buffer_t *b0, ip6_header_t *ip0, ip6_sr_header_t *sr0, ip6_sr_localsid_t *ls0, u32 *next0)
Definition: sr_localsid.c:732
#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
Combined counter to hold both packets and byte differences.
Definition: counter.h:139
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
Definition: ip6_packet.h:465
#define hash_set_mem(h, key, value)
Definition: hash.h:274
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
u16 behavior
Behavior associated to this localsid.
Definition: sr.h:107
unformat_function_t unformat_vnet_sw_interface
#define ROUTING_HEADER_TYPE_SR
Definition: sr_packet.h:116
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
unsigned char keyword_str[32]
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:418
static_always_inline void end_psp_srh_processing(vlib_node_runtime_t *node, vlib_buffer_t *b0, ip6_header_t *ip0, ip6_ext_header_t *prev0, ip6_sr_header_t *sr0, ip6_sr_localsid_t *ls0, u32 *next0)
Function doing End processing with PSP.
Definition: sr_localsid.c:816
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:100
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:200
vlib_combined_counter_main_t sr_ls_invalid_counters
Definition: sr.h:228
vlib_combined_counter_main_t sr_ls_valid_counters
Definition: sr.h:227
ip6_address_t src_address
Definition: ip6_packet.h:341
static char * sr_localsid_error_strings[]
Definition: sr_localsid.c:599
static clib_error_t * show_sr_localsid_behaviors_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI function to &#39;show&#39; all available SR LocalSID behaviors.
Definition: sr_localsid.c:1414
format_function_t format_vnet_sw_if_index_name
#define SR_BEHAVIOR_DT4
Definition: sr.h:44
static const char *const sr_loc_d_ip6_nodes[]
Definition: sr_localsid.c:1351
static const char *const *const sr_loc_nodes[DPO_PROTO_NUM]
Definition: sr_localsid.c:1347
format_function_t format_ip4_address
Definition: format.h:79
#define static_always_inline
Definition: clib.h:85
static clib_error_t * sr_cli_localsid_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
SR LocalSID CLI function.
Definition: sr_localsid.c:257
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
Definition: counter.c:60
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:376
unformat_function_t unformat_ip4_address
Definition: format.h:76
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
#define SR_BEHAVIOR_LAST
Definition: sr.h:45
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:164
Aggregrate type for a prefix.
Definition: fib_types.h:160
#define clib_error_return(e, args...)
Definition: error.h:111
unsigned long u64
Definition: types.h:89
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:215
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:261
ip6_address_t src
Definition: sr_localsid.c:576
#define hash_create_string(elts, value_bytes)
Definition: hash.h:652
int( sr_plugin_callback_t)(ip6_sr_localsid_t *localsid)
Definition: sr.h:126
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:146
Definition: fib_entry.h:231
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
Definition: counter.h:276
counter_t packets
packet counter
Definition: counter.h:141
vlib_node_registration_t sr_localsid_d_node
(constructor) VLIB_REGISTER_NODE (sr_localsid_d_node)
Definition: sr_localsid.c:1077
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:183
#define SR_BEHAVIOR_END
Definition: sr.h:37
u8 * format_sr_localsid_trace(u8 *s, va_list *args)
SR LocalSID graph node trace function.
Definition: sr_localsid.c:627
struct _unformat_input_t unformat_input_t
uword os_get_cpu_number(void)
Definition: unix-misc.c:224
SR LocalSID behavior registration.
Definition: sr.h:131
unsigned char def_str[64]
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:188
static_always_inline void end_srh_processing(vlib_node_runtime_t *node, vlib_buffer_t *b0, ip6_header_t *ip0, ip6_sr_header_t *sr0, ip6_sr_localsid_t *ls0, u32 *next0)
Function doing End processing.
Definition: sr_localsid.c:689
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:241
char end_psp
Combined with End.PSP?
Definition: sr.h:105
static dpo_type_t sr_localsid_d_dpo_type
Definition: sr_localsid.c:47
#define PREDICT_FALSE(x)
Definition: clib.h:97
void sr_dpo_lock(dpo_id_t *dpo)
no-op lock function.
Definition: sr.c:38
static u8 * format_sr_dpo(u8 *s, va_list *args)
Definition: sr_localsid.c:1328
#define SR_BEHAVIOR_DX4
Definition: sr.h:42
#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:216
static uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
Definition: mhash.h:117
#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:350
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:113
static uword sr_localsid_d_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
SR LocalSID graph node.
Definition: sr_localsid.c:882
#define ip6_ext_header_len(p)
Definition: ip6_packet.h:461
unformat_function_t unformat_ip6_address
Definition: format.h:94
ip6_sr_localsid_t * localsids
Definition: sr.h:203
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:168
static clib_error_t * show_sr_localsid_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI function to &#39;show&#39; all SR LocalSIDs on console.
Definition: sr_localsid.c:433
u16 n_vectors
Definition: node.h:344
format_function_t format_ip6_address
Definition: format.h:95
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:250
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
vlib_main_t * vm
Definition: buffer.c:276
static clib_error_t * clear_sr_localsid_counters_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Function to &#39;clear&#39; ALL SR localsid counters.
Definition: sr_localsid.c:549
void fib_table_entry_delete(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:798
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:85
#define clib_memcpy(a, b, c)
Definition: string.h:69
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
unformat_function_t * ls_unformat
LocalSID unformat function.
Definition: sr.h:147
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
int sr_localsid_register_function(vlib_main_t *vm, u8 *fn_name, u8 *keyword_str, u8 *def_str, u8 *params_str, dpo_type_t *dpo, format_function_t *ls_format, unformat_function_t *ls_unformat, sr_plugin_callback_t *creation_fn, sr_plugin_callback_t *removal_fn)
SR LocalSID plugin registry.
Definition: sr_localsid.c:1366
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:157
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:449
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a &#39;special&#39; entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
Definition: fib_table.c:288
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:455
unsigned int u32
Definition: types.h:88
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:211
dpo_type_t dpo
DPO type registration.
Definition: sr.h:143
u8 * def_str
Behavior definition (i.e.
Definition: sr.h:139
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
void * plugin_mem
Memory to be used by the plugin callback functions.
Definition: sr.h:123
static const char *const *const sr_loc_d_nodes[DPO_PROTO_NUM]
Definition: sr_localsid.c:1356
u32 vrf_index
vrf only
Definition: sr.h:112
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:201
u32 fib_table
FIB table where localsid is registered.
Definition: sr.h:115
#define SR_BEHAVIOR_DX2
Definition: sr.h:40
SR localsid node trace.
Definition: sr_localsid.c:573
u64 uword
Definition: types.h:112
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
u16 sr_localsid_function_number
SR LocalSID plugin function (>SR_BEHAVIOR_LAST)
Definition: sr.h:133
#define ip46_address_reset(ip46)
Definition: ip6_packet.h:79
counter_t bytes
byte counter
Definition: counter.h:142
Definition: defs.h:47
unsigned short u16
Definition: types.h:57
#define DPO_PROTO_NUM
Definition: dpo.h:73
SRv6.
Definition: fib_entry.h:70
u16 payload_length
Definition: ip6_packet.h:332
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
ip6_address_t segments[0]
Definition: sr_packet.h:148
sr_plugin_callback_t * creation
Function within plugin that will be called after localsid creation.
Definition: sr.h:149
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:253
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:173
clib_error_t * sr_localsids_init(vlib_main_t *vm)
SR LocalSID initialization.
Definition: sr_localsid.c:1469
#define hash_get_mem(h, key)
Definition: hash.h:268
#define vnet_buffer(b)
Definition: buffer.h:294
vlib_node_registration_t sr_localsid_node
(constructor) VLIB_REGISTER_NODE (sr_localsid_node)
Definition: sr_localsid.c:1310
Segment Routing data structures definitions.
Segment Routing main datastructure.
Definition: sr.h:188
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u8 data[0]
Packet data.
Definition: buffer.h:152
adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index)
Neighbour Adjacency sub-type.
Definition: adj_nbr.c:216
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:194
#define vec_foreach(var, vec)
Vector iterator.
static uword sr_localsid_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
SR LocalSID graph node.
Definition: sr_localsid.c:1098
#define ip6_ext_header_find_t(i, p, m, t)
Definition: ip6_packet.h:474
#define foreach_sr_localsid_next
Definition: sr_localsid.c:605
ip46_address_t next_hop
Next_hop for xconnect usage only.
Definition: sr.h:119
mhash_t sr_localsids_index_hash
Definition: sr.h:206
u8 * params_str
Behavior parameters (i.e.
Definition: sr.h:141
#define foreach_sr_localsid_error
Definition: sr_localsid.c:583
u32 sw_if_index
xconnect only
Definition: sr.h:111
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
sr_plugin_callback_t * removal
Function within plugin that will be called before localsid removal.
Definition: sr.h:151
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:74
ip6_address_t localsid
LocalSID IPv6 address.
Definition: sr.h:103
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:577
static dpo_type_t sr_localsid_dpo_type
Dynamically added SR localsid DPO type.
Definition: sr_localsid.c:46
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
u8 * keyword_str
Behavior keyword (i.e.
Definition: sr.h:137
sr_localsid_fn_registration_t * plugin_functions
Definition: sr.h:221
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:971
sr_localsid_next_t
Definition: sr_localsid.c:613
#define SR_BEHAVIOR_DX6
Definition: sr.h:41
ip6_address_t dst_address
Definition: ip6_packet.h:341
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
uword * plugin_functions_by_key
Definition: sr.h:224