A Protocol Independent Hierarchical FIB (VPP-352)
[vpp.git] / vnet / vnet / sr / sr.c
index 0ae462a..086cbe9 100644 (file)
  * limitations under the License.
  */
 
+/**
+ * @file
+ * @brief Segment Routing main functions
+ *
+ */
 #include <vnet/vnet.h>
 #include <vnet/sr/sr.h>
+#include <vnet/fib/ip6_fib.h>
+#include <vnet/dpo/dpo.h>
 
 #include <openssl/hmac.h>
 
 ip6_sr_main_t sr_main;
 static vlib_node_registration_t sr_local_node;
 
+/**
+ * @brief Dynamically added SR DPO type
+ */
+static dpo_type_t sr_dpo_type;
+
+/**
+ * @brief Use passed HMAC key in ip6_sr_header_t in OpenSSL HMAC routines
+ *
+ * @param sm ip6_sr_main_t *
+ * @param ip ip6_header_t *
+ * @param sr ip6_sr_header_t *
+ */
 void
 sr_fix_hmac (ip6_sr_main_t * sm, ip6_header_t * ip, ip6_sr_header_t * sr)
 {
@@ -92,6 +111,14 @@ sr_fix_hmac (ip6_sr_main_t * sm, ip6_header_t * ip, ip6_sr_header_t * sr)
   HMAC_CTX_cleanup (sm->hmac_ctx);
 }
 
+/**
+ * @brief Format function for decoding various SR flags
+ *
+ * @param s u8 * - formatted string
+ * @param args va_list * - u16 flags
+ *
+ * @return formatted output string u8 *
+ */
 u8 *
 format_ip6_sr_header_flags (u8 * s, va_list * args)
 {
@@ -135,6 +162,14 @@ format_ip6_sr_header_flags (u8 * s, va_list * args)
   return s;
 }
 
+/**
+ * @brief Format function for decoding ip6_sr_header_t
+ *
+ * @param s u8 * - formatted string
+ * @param args va_list * - ip6_sr_header_t
+ *
+ * @return formatted output string u8 *
+ */
 u8 *
 format_ip6_sr_header (u8 * s, va_list * args)
 {
@@ -195,6 +230,14 @@ format_ip6_sr_header (u8 * s, va_list * args)
   return s;
 }
 
+/**
+ * @brief Format function for decoding ip6_sr_header_t with length
+ *
+ * @param s u8 * - formatted string
+ * @param args va_list * - ip6_header_t + ip6_sr_header_t
+ *
+ * @return formatted output string u8 *
+ */
 u8 *
 format_ip6_sr_header_with_length (u8 * s, va_list * args)
 {
@@ -213,7 +256,11 @@ format_ip6_sr_header_with_length (u8 * s, va_list * args)
   return s;
 }
 
-#if DPDK > 0                   /* Cannot call replicate yet without DPDK */
+/**
+ * @brief Defined valid next nodes
+ * @note Cannot call replicate yet without DPDK
+*/
+#if DPDK > 0
 #define foreach_sr_rewrite_next                 \
 _(ERROR, "error-drop")                          \
 _(IP6_LOOKUP, "ip6-lookup")                     \
@@ -226,6 +273,9 @@ _(IP6_LOOKUP, "ip6-lookup")                     \
 _(SR_LOCAL, "sr-local")
 #endif /* DPDK */
 
+/**
+ * @brief Struct for defined valid next nodes
+*/
 typedef enum
 {
 #define _(s,n) SR_REWRITE_NEXT_##s,
@@ -234,6 +284,9 @@ typedef enum
     SR_REWRITE_N_NEXT,
 } sr_rewrite_next_t;
 
+/**
+ * @brief Struct for data for SR rewrite packet trace
+ */
 typedef struct
 {
   ip6_address_t src, dst;
@@ -243,12 +296,18 @@ typedef struct
   u8 sr[256];
 } sr_rewrite_trace_t;
 
+/**
+ * @brief Error strings for SR rewrite
+ */
 static char *sr_rewrite_error_strings[] = {
 #define sr_error(n,s) s,
 #include "sr_error.def"
 #undef sr_error
 };
 
+/**
+ * @brief Struct for SR rewrite error strings
+ */
 typedef enum
 {
 #define sr_error(n,s) SR_REWRITE_ERROR_##n,
@@ -258,22 +317,21 @@ typedef enum
 } sr_rewrite_error_t;
 
 
+/**
+ * @brief Format function for SR rewrite trace.
+ */
 u8 *
 format_sr_rewrite_trace (u8 * s, va_list * args)
 {
   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
   sr_rewrite_trace_t *t = va_arg (*args, sr_rewrite_trace_t *);
-  ip6_main_t *im = &ip6_main;
   ip6_sr_main_t *sm = &sr_main;
   ip6_sr_tunnel_t *tun = pool_elt_at_index (sm->tunnels, t->tunnel_index);
   ip6_fib_t *rx_fib, *tx_fib;
 
-  rx_fib = find_ip6_fib_by_table_index_or_id (im, tun->rx_fib_index,
-                                             IP6_ROUTE_FLAG_FIB_INDEX);
-
-  tx_fib = find_ip6_fib_by_table_index_or_id (im, tun->tx_fib_index,
-                                             IP6_ROUTE_FLAG_FIB_INDEX);
+  rx_fib = ip6_fib_get (tun->rx_fib_index);
+  tx_fib = ip6_fib_get (tun->tx_fib_index);
 
   s = format
     (s, "SR-REWRITE: next %s ip6 src %U dst %U len %u\n"
@@ -287,6 +345,16 @@ format_sr_rewrite_trace (u8 * s, va_list * args)
   return s;
 }
 
+/**
+ * @brief Main processing dual-loop for Segment Routing Rewrite
+ * @node sr-rewrite
+ *
+ * @param vm vlib_main_t *
+ * @param node vlib_node_runtime_t *
+ * @param from_frame vlib_frame_t *
+ *
+ * @return from_frame->n_vectors uword
+ */
 static uword
 sr_rewrite (vlib_main_t * vm,
            vlib_node_runtime_t * node, vlib_frame_t * from_frame)
@@ -668,41 +736,30 @@ VLIB_NODE_FUNCTION_MULTIARCH (sr_rewrite_node, sr_rewrite)
                                              u32 dst_address_length,
                                              u32 rx_table_id)
 {
-  ip6_add_del_route_args_t a;
-  ip6_address_t dst_address;
-  ip6_fib_t *fib;
-  ip6_main_t *im6 = &ip6_main;
-  BVT (clib_bihash_kv) kv, value;
-
-  fib = find_ip6_fib_by_table_index_or_id (im6, rx_table_id,
-                                          IP6_ROUTE_FLAG_TABLE_ID);
-  memset (&a, 0, sizeof (a));
-  a.flags |= IP4_ROUTE_FLAG_DEL;
-  a.dst_address_length = dst_address_length;
-
-  dst_address = *dst_address_arg;
-
-  ip6_address_mask (&dst_address, &im6->fib_masks[dst_address_length]);
-
-  kv.key[0] = dst_address.as_u64[0];
-  kv.key[1] = dst_address.as_u64[1];
-  kv.key[2] = ((u64) ((fib - im6->fibs)) << 32) | dst_address_length;
-
-  if (BV (clib_bihash_search) (&im6->ip6_lookup_table, &kv, &value) < 0)
-    {
-      clib_warning ("%U/%d not in FIB",
-                   format_ip6_address, &a.dst_address, a.dst_address_length);
-      return -10;
-    }
+  fib_prefix_t pfx = {
+    .fp_len = dst_address_length,
+    .fp_proto = FIB_PROTOCOL_IP6,
+    .fp_addr = {
+               .ip6 = *dst_address_arg,
+               }
+  };
 
-  a.adj_index = value.value;
-  a.dst_address = dst_address;
+  fib_table_entry_delete (fib_table_id_find_fib_index (FIB_PROTOCOL_IP6,
+                                                      rx_table_id),
+                         &pfx, FIB_SOURCE_SR);
 
-  ip6_add_del_route (im6, &a);
-  ip6_maybe_remap_adjacencies (im6, rx_table_id, IP6_ROUTE_FLAG_TABLE_ID);
   return 0;
 }
 
+/**
+ * @brief Find or add if not found - HMAC shared secret
+ *
+ * @param sm ip6_sr_main_t *
+ * @param secret u8 *
+ * @param indexp u32 *
+ *
+ * @return ip6_sr_hmac_key_t *
+ */
 static ip6_sr_hmac_key_t *
 find_or_add_shared_secret (ip6_sr_main_t * sm, u8 * secret, u32 * indexp)
 {
@@ -752,28 +809,31 @@ find_or_add_shared_secret (ip6_sr_main_t * sm, u8 * secret, u32 * indexp)
   return (key);
 }
 
-
+/**
+ * @brief Add or Delete a Segment Routing tunnel.
+ *
+ * @param a ip6_sr_add_del_tunnel_args_t *
+ *
+ * @return retval int
+ */
 int
 ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a)
 {
   ip6_main_t *im = &ip6_main;
-  ip_lookup_main_t *lm = &im->lookup_main;
   ip6_sr_tunnel_key_t key;
   ip6_sr_tunnel_t *t;
   uword *p, *n;
   ip6_sr_header_t *h = 0;
   u32 header_length;
   ip6_address_t *addrp, *this_address;
-  ip_adjacency_t adj, *ap, *add_adj = 0;
-  u32 adj_index;
   ip6_sr_main_t *sm = &sr_main;
   u8 *key_copy;
   u32 rx_fib_index, tx_fib_index;
-  ip6_add_del_route_args_t aa;
   u32 hmac_key_index_u32;
   u8 hmac_key_index = 0;
   ip6_sr_policy_t *pt;
   int i;
+  dpo_id_t dpo = DPO_NULL;
 
   /* Make sure that the rx FIB exists */
   p = hash_get (im->fib_index_by_table_id, a->rx_table_id);
@@ -977,15 +1037,6 @@ ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a)
   clib_memcpy (key_copy, &key, sizeof (ip6_sr_tunnel_key_t));
   hash_set_mem (sm->tunnel_index_by_key, key_copy, t - sm->tunnels);
 
-  memset (&adj, 0, sizeof (adj));
-
-  /* Create an adjacency and add to v6 fib */
-  adj.lookup_next_index = sm->ip6_lookup_sr_next_index;
-  adj.explicit_fib_index = ~0;
-
-  ap = ip_add_adjacency (lm, &adj, 1 /* one adj */ ,
-                        &adj_index);
-
   /*
    * Stick the tunnel index into the rewrite header.
    *
@@ -997,22 +1048,20 @@ ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a)
    * We don't handle ugly RFC-related cases yet, but I'm sure PL will complain
    * at some point...
    */
-  ap->rewrite_header.sw_if_index = t - sm->tunnels;
-
-  vec_add1 (add_adj, ap[0]);
-
-  clib_memcpy (aa.dst_address.as_u8, a->dst_address,
-              sizeof (aa.dst_address.as_u8));
-  aa.dst_address_length = a->dst_mask_width;
+  dpo_set (&dpo, sr_dpo_type, DPO_PROTO_IP6, t - sm->tunnels);
 
-  aa.flags = (a->is_del ? IP6_ROUTE_FLAG_DEL : IP6_ROUTE_FLAG_ADD);
-  aa.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
-  aa.table_index_or_table_id = rx_fib_index;
-  aa.add_adj = add_adj;
-  aa.adj_index = adj_index;
-  aa.n_add_adj = 1;
-  ip6_add_del_route (im, &aa);
-  vec_free (add_adj);
+  fib_prefix_t pfx = {
+    .fp_proto = FIB_PROTOCOL_IP6,
+    .fp_len = a->dst_mask_width,
+    .fp_addr = {
+               .ip6 = *a->dst_address,
+               }
+  };
+  fib_table_entry_special_dpo_add (rx_fib_index,
+                                  &pfx,
+                                  FIB_SOURCE_SR,
+                                  FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
+  dpo_reset (&dpo);
 
   if (a->policy_name)
     {
@@ -1045,6 +1094,57 @@ ip6_sr_add_del_tunnel (ip6_sr_add_del_tunnel_args_t * a)
   return 0;
 }
 
+/**
+ * @brief no-op lock function.
+ * The lifetime of the SR entry is managed by the control plane
+ */
+static void
+sr_dpo_lock (dpo_id_t * dpo)
+{
+}
+
+/**
+ * @brief no-op unlock function.
+ * The lifetime of the SR entry is managed by the control plane
+ */
+static void
+sr_dpo_unlock (dpo_id_t * dpo)
+{
+}
+
+u8 *
+format_sr_dpo (u8 * s, va_list * args)
+{
+  index_t index = va_arg (*args, index_t);
+  CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
+
+  return (format (s, "SR: tunnel:[%d]", index));
+}
+
+const static dpo_vft_t sr_vft = {
+  .dv_lock = sr_dpo_lock,
+  .dv_unlock = sr_dpo_unlock,
+  .dv_format = format_sr_dpo,
+};
+
+const static char *const sr_ip6_nodes[] = {
+  "sr-rewrite",
+  NULL,
+};
+
+const static char *const *const sr_nodes[DPO_PROTO_NUM] = {
+  [DPO_PROTO_IP6] = sr_ip6_nodes,
+};
+
+/**
+ * @brief CLI parser for Add or Delete a Segment Routing tunnel.
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 sr_add_del_tunnel_command_fn (vlib_main_t * vm,
                              unformat_input_t * input,
@@ -1216,19 +1316,22 @@ VLIB_CLI_COMMAND (sr_tunnel_command, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief Display Segment Routing tunnel
+ *
+ * @param vm vlib_main_t *
+ * @param t ip6_sr_tunnel_t *
+ *
+ */
 void
 ip6_sr_tunnel_display (vlib_main_t * vm, ip6_sr_tunnel_t * t)
 {
-  ip6_main_t *im = &ip6_main;
   ip6_sr_main_t *sm = &sr_main;
   ip6_fib_t *rx_fib, *tx_fib;
   ip6_sr_policy_t *pt;
 
-  rx_fib = find_ip6_fib_by_table_index_or_id (im, t->rx_fib_index,
-                                             IP6_ROUTE_FLAG_FIB_INDEX);
-
-  tx_fib = find_ip6_fib_by_table_index_or_id (im, t->tx_fib_index,
-                                             IP6_ROUTE_FLAG_FIB_INDEX);
+  rx_fib = ip6_fib_get (t->rx_fib_index);
+  tx_fib = ip6_fib_get (t->tx_fib_index);
 
   if (t->name)
     vlib_cli_output (vm, "sr tunnel name: %s", (char *) t->name);
@@ -1252,6 +1355,15 @@ ip6_sr_tunnel_display (vlib_main_t * vm, ip6_sr_tunnel_t * t)
   return;
 }
 
+/**
+ * @brief CLI Parser for Display Segment Routing tunnel
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 show_sr_tunnel_fn (vlib_main_t * vm,
                   unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -1310,6 +1422,13 @@ VLIB_CLI_COMMAND (show_sr_tunnel_command, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief Add or Delete a Segment Routing policy
+ *
+ * @param a ip6_sr_add_del_policy_args_t *
+ *
+ * @return retval int
+ */
 int
 ip6_sr_add_del_policy (ip6_sr_add_del_policy_args_t * a)
 {
@@ -1383,7 +1502,15 @@ ip6_sr_add_del_policy (ip6_sr_add_del_policy_args_t * a)
   return 0;
 }
 
-
+/**
+ * @brief CLI Parser for Add or Delete a Segment Routing policy
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 sr_add_del_policy_command_fn (vlib_main_t * vm,
                              unformat_input_t * input,
@@ -1466,6 +1593,15 @@ VLIB_CLI_COMMAND (sr_policy_command, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief CLI Parser for Displaying Segment Routing policy
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 show_sr_policy_fn (vlib_main_t * vm,
                   unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -1537,17 +1673,20 @@ VLIB_CLI_COMMAND (show_sr_policy_command, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief Add or Delete a mapping of IP6 multicast address
+ * to Segment Routing policy.
+ *
+ * @param a ip6_sr_add_del_multicastmap_args_t *
+ *
+ * @return retval int
+ */
 int
 ip6_sr_add_del_multicastmap (ip6_sr_add_del_multicastmap_args_t * a)
 {
   uword *p;
-  ip6_main_t *im = &ip6_main;
-  ip_lookup_main_t *lm = &im->lookup_main;
   ip6_sr_tunnel_t *t;
-  ip_adjacency_t adj, *ap, *add_adj = 0;
-  u32 adj_index;
   ip6_sr_main_t *sm = &sr_main;
-  ip6_add_del_route_args_t aa;
   ip6_sr_policy_t *pt;
 
   if (a->is_del)
@@ -1577,16 +1716,6 @@ ip6_sr_add_del_multicastmap (ip6_sr_add_del_multicastmap_args_t * a)
 
   t = pool_elt_at_index (sm->tunnels, pt->tunnel_indices[0]);
 
-  /* Construct a FIB entry for multicast using the rx/tx fib from the first tunnel */
-  memset (&adj, 0, sizeof (adj));
-
-  /* Create an adjacency and add to v6 fib */
-  adj.lookup_next_index = sm->ip6_lookup_sr_replicate_index;
-  adj.explicit_fib_index = ~0;
-
-  ap = ip_add_adjacency (lm, &adj, 1 /* one adj */ ,
-                        &adj_index);
-
   /*
    * Stick the tunnel index into the rewrite header.
    *
@@ -1598,22 +1727,23 @@ ip6_sr_add_del_multicastmap (ip6_sr_add_del_multicastmap_args_t * a)
    * We don't handle ugly RFC-related cases yet, but I'm sure PL will complain
    * at some point...
    */
-  ap->rewrite_header.sw_if_index = t - sm->tunnels;
+  dpo_id_t dpo = DPO_NULL;
 
-  vec_add1 (add_adj, ap[0]);
+  dpo_set (&dpo, sr_dpo_type, DPO_PROTO_IP6, t - sm->tunnels);
 
-  memcpy (aa.dst_address.as_u8, a->multicast_address,
-         sizeof (aa.dst_address.as_u8));
-  aa.dst_address_length = 128;
-
-  aa.flags = (a->is_del ? IP6_ROUTE_FLAG_DEL : IP6_ROUTE_FLAG_ADD);
-  aa.flags |= IP6_ROUTE_FLAG_FIB_INDEX;
-  aa.table_index_or_table_id = t->rx_fib_index;
-  aa.add_adj = add_adj;
-  aa.adj_index = adj_index;
-  aa.n_add_adj = 1;
-  ip6_add_del_route (im, &aa);
-  vec_free (add_adj);
+  /* Construct a FIB entry for multicast using the rx/tx fib from the first tunnel */
+  fib_prefix_t pfx = {
+    .fp_proto = FIB_PROTOCOL_IP6,
+    .fp_len = 128,
+    .fp_addr = {
+               .ip6 = *a->multicast_address,
+               }
+  };
+  fib_table_entry_special_dpo_add (t->rx_fib_index,
+                                  &pfx,
+                                  FIB_SOURCE_SR,
+                                  FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
+  dpo_reset (&dpo);
 
   u8 *mcast_copy = 0;
   mcast_copy = vec_new (ip6_address_t, 1);
@@ -1634,6 +1764,16 @@ ip6_sr_add_del_multicastmap (ip6_sr_add_del_multicastmap_args_t * a)
   return 0;
 }
 
+/**
+ * @brief CLI Parser for Adding or Delete a mapping of IP6 multicast address
+ * to Segment Routing policy.
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 sr_add_del_multicast_map_command_fn (vlib_main_t * vm,
                                     unformat_input_t * input,
@@ -1716,6 +1856,16 @@ VLIB_CLI_COMMAND (sr_multicast_map_command, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief CLI Parser for Displaying a mapping of IP6 multicast address
+ * to Segment Routing policy.
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 show_sr_multicast_map_fn (vlib_main_t * vm,
                          unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -1768,6 +1918,9 @@ VLIB_CLI_COMMAND (show_sr_multicast_map_command, static) = {
 #define foreach_sr_fix_dst_addr_next            \
 _(DROP, "error-drop")
 
+/**
+ * @brief Struct for valid next-nodes for SR fix destination address node
+ */
 typedef enum
 {
 #define _(s,n) SR_FIX_DST_ADDR_NEXT_##s,
@@ -1776,12 +1929,18 @@ typedef enum
     SR_FIX_DST_ADDR_N_NEXT,
 } sr_fix_dst_addr_next_t;
 
+/**
+ * @brief Error strings for SR Fix Destination rewrite
+ */
 static char *sr_fix_dst_error_strings[] = {
 #define sr_fix_dst_error(n,s) s,
 #include "sr_fix_dst_error.def"
 #undef sr_fix_dst_error
 };
 
+/**
+ * @brief Struct for errors for SR Fix Destination rewrite
+ */
 typedef enum
 {
 #define sr_fix_dst_error(n,s) SR_FIX_DST_ERROR_##n,
@@ -1790,6 +1949,9 @@ typedef enum
   SR_FIX_DST_N_ERROR,
 } sr_fix_dst_error_t;
 
+/**
+ * @brief Information for fix address trace
+ */
 typedef struct
 {
   ip6_address_t src, dst;
@@ -1798,6 +1960,9 @@ typedef struct
   u8 sr[256];
 } sr_fix_addr_trace_t;
 
+/**
+ * @brief Formatter for fix address trace
+ */
 u8 *
 format_sr_fix_addr_trace (u8 * s, va_list * args)
 {
@@ -1831,6 +1996,16 @@ format_sr_fix_addr_trace (u8 * s, va_list * args)
   return s;
 }
 
+/**
+ * @brief Fix SR destination address - dual-loop
+ *
+ * @node sr-fix-dst-addr
+ * @param vm vlib_main_t *
+ * @param node vlib_node_runtime_t *
+ * @param from_frame vlib_frame_t *
+ *
+ * @return from_frame->n_vectors uword
+ */
 static uword
 sr_fix_dst_addr (vlib_main_t * vm,
                 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
@@ -2042,10 +2217,6 @@ VLIB_NODE_FUNCTION_MULTIARCH (sr_fix_dst_addr_node, sr_fix_dst_addr)
   ip6_rewrite_node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite");
   ASSERT (ip6_rewrite_node);
 
-  /* Add a disposition to ip6_lookup for the sr rewrite node */
-  sm->ip6_lookup_sr_next_index =
-    vlib_node_add_next (vm, ip6_lookup_node->index, sr_rewrite_node.index);
-
 #if DPDK > 0                   /* Cannot run replicate without DPDK */
   /* Add a disposition to sr_replicate for the sr multicast replicate node */
   sm->ip6_lookup_sr_replicate_index =
@@ -2062,15 +2233,23 @@ VLIB_NODE_FUNCTION_MULTIARCH (sr_fix_dst_addr_node, sr_fix_dst_addr)
   sm->md = (void *) EVP_get_digestbyname ("sha1");
   sm->hmac_ctx = clib_mem_alloc (sizeof (HMAC_CTX));
 
+  sr_dpo_type = dpo_register_new_type (&sr_vft, sr_nodes);
+
   return error;
 }
 
 VLIB_INIT_FUNCTION (sr_init);
 
+/**
+ * @brief Definition of next-nodes for SR local
+ */
 #define foreach_sr_local_next                   \
   _ (ERROR, "error-drop")                       \
   _ (IP6_LOOKUP, "ip6-lookup")
 
+/**
+ * @brief Struct for definition of next-nodes for SR local
+ */
 typedef enum
 {
 #define _(s,n) SR_LOCAL_NEXT_##s,
@@ -2079,6 +2258,9 @@ typedef enum
     SR_LOCAL_N_NEXT,
 } sr_local_next_t;
 
+/**
+ * @brief Struct for packet trace of SR local
+ */
 typedef struct
 {
   u8 next_index;
@@ -2088,12 +2270,18 @@ typedef struct
   u8 sr[256];
 } sr_local_trace_t;
 
+/**
+ * @brief Definition of SR local error-strings
+ */
 static char *sr_local_error_strings[] = {
 #define sr_error(n,s) s,
 #include "sr_error.def"
 #undef sr_error
 };
 
+/**
+ * @brief Struct for definition of SR local error-strings
+ */
 typedef enum
 {
 #define sr_error(n,s) SR_LOCAL_ERROR_##n,
@@ -2102,6 +2290,14 @@ typedef enum
   SR_LOCAL_N_ERROR,
 } sr_local_error_t;
 
+/**
+ * @brief Format SR local trace
+ *
+ * @param s u8 *
+ * @param args va_list *
+ *
+ * @return s u8 *
+ */
 u8 *
 format_sr_local_trace (u8 * s, va_list * args)
 {
@@ -2123,7 +2319,15 @@ format_sr_local_trace (u8 * s, va_list * args)
 
 
 /* $$$$ fixme: smp, don't copy data, cache input, output (maybe) */
-
+/**
+ * @brief Validate the SR HMAC
+ *
+ * @param sm ip6_sr_main_t *
+ * @param ip ip6_header_t *
+ * @param sr ip6_sr_header_t *
+ *
+ * @return retval int
+ */
 static int
 sr_validate_hmac (ip6_sr_main_t * sm, ip6_header_t * ip, ip6_sr_header_t * sr)
 {
@@ -2215,6 +2419,16 @@ sr_validate_hmac (ip6_sr_main_t * sm, ip6_header_t * ip, ip6_sr_header_t * sr)
   return memcmp (signature, addrp, SHA256_DIGEST_LENGTH);
 }
 
+/**
+ * @brief SR local node
+ * @node sr-local
+ *
+ * @param vm vlib_main_t *
+ * @param node vlib_node_runtime_t *
+ * @param from_frame vlib_frame_t *
+ *
+ * @return from_frame->n_vectors uword
+ */
 static uword
 sr_local (vlib_main_t * vm,
          vlib_node_runtime_t * node, vlib_frame_t * from_frame)
@@ -2648,46 +2862,61 @@ VLIB_NODE_FUNCTION_MULTIARCH (sr_local_node, sr_local)
   return &sr_main;
 }
 
-
+/**
+ * @brief CLI parser for SR fix destination rewrite node
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 set_ip6_sr_rewrite_fn (vlib_main_t * vm,
                       unformat_input_t * input, vlib_cli_command_t * cmd)
 {
-  ip6_address_t a;
-  ip6_main_t *im = &ip6_main;
-  ip_lookup_main_t *lm = &im->lookup_main;
+  fib_prefix_t pfx = {
+    .fp_proto = FIB_PROTOCOL_IP6,
+    .fp_len = 128,
+  };
   u32 fib_index = 0;
   u32 fib_id = 0;
   u32 adj_index;
-  uword *p;
   ip_adjacency_t *adj;
   vnet_hw_interface_t *hi;
   u32 sw_if_index;
   ip6_sr_main_t *sm = &sr_main;
   vnet_main_t *vnm = vnet_get_main ();
+  fib_node_index_t fei;
 
-  if (!unformat (input, "%U", unformat_ip6_address, &a))
+  if (!unformat (input, "%U", unformat_ip6_address, &pfx.fp_addr.ip6))
     return clib_error_return (0, "ip6 address missing in '%U'",
                              format_unformat_error, input);
 
   if (unformat (input, "rx-table-id %d", &fib_id))
     {
-      p = hash_get (im->fib_index_by_table_id, fib_id);
-      if (p == 0)
-       return clib_error_return (0, "fib-id %d not found");
-      fib_index = p[0];
+      fib_index = fib_table_id_find_fib_index (FIB_PROTOCOL_IP6, fib_id);
+      if (fib_index == ~0)
+       return clib_error_return (0, "fib-id %d not found", fib_id);
     }
 
-  adj_index = ip6_fib_lookup_with_table (im, fib_index, &a);
+  fei = fib_table_lookup_exact_match (fib_index, &pfx);
+
+  if (FIB_NODE_INDEX_INVALID == fei)
+    return clib_error_return (0, "no match for %U",
+                             format_ip6_address, &pfx.fp_addr.ip6);
 
-  if (adj_index == lm->miss_adj_index)
-    return clib_error_return (0, "no match for %U", format_ip6_address, &a);
+  adj_index = fib_entry_get_adj_for_source (fei, FIB_SOURCE_SR);
 
-  adj = ip_get_adjacency (lm, adj_index);
+  if (ADJ_INDEX_INVALID == adj_index)
+    return clib_error_return (0, "%U not SR sourced",
+                             format_ip6_address, &pfx.fp_addr.ip6);
+
+  adj = adj_get (adj_index);
 
   if (adj->lookup_next_index != IP_LOOKUP_NEXT_REWRITE)
     return clib_error_return (0, "%U unresolved (not a rewrite adj)",
-                             format_ip6_address, &a);
+                             format_ip6_address, &pfx.fp_addr.ip6);
 
   adj->rewrite_header.next_index = sm->ip6_rewrite_sr_next_index;
 
@@ -2711,6 +2940,11 @@ VLIB_CLI_COMMAND (set_ip6_sr_rewrite, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief Register a callback routine to set next0 in sr_local
+ *
+ * @param cb void *
+ */
 void
 vnet_register_sr_app_callback (void *cb)
 {
@@ -2719,6 +2953,9 @@ vnet_register_sr_app_callback (void *cb)
   sm->sr_local_cb = cb;
 }
 
+/**
+ * @brief Test routine for validation of HMAC
+ */
 static clib_error_t *
 test_sr_hmac_validate_fn (vlib_main_t * vm,
                          unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -2746,6 +2983,17 @@ VLIB_CLI_COMMAND (test_sr_hmac_validate, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief Add or Delete HMAC key
+ *
+ * @param sm ip6_sr_main_t *
+ * @param key_id u32
+ * @param shared_secret u8 *
+ * @param is_del u8
+ *
+ * @return retval i32
+ */
+// $$$ fixme shouldn't return i32
 i32
 sr_hmac_add_del_key (ip6_sr_main_t * sm, u32 key_id, u8 * shared_secret,
                     u8 is_del)
@@ -2844,7 +3092,15 @@ VLIB_CLI_COMMAND (sr_hmac, static) = {
 };
 /* *INDENT-ON* */
 
-
+/**
+ * @brief CLI parser for show HMAC key shared secrets
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 show_sr_hmac_fn (vlib_main_t * vm,
                 unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -2869,6 +3125,15 @@ VLIB_CLI_COMMAND (show_sr_hmac, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief Test for SR debug flag
+ *
+ * @param vm vlib_main_t *
+ * @param input unformat_input_t *
+ * @param cmd vlib_cli_command_t *
+ *
+ * @return error clib_error_t *
+ */
 static clib_error_t *
 test_sr_debug_fn (vlib_main_t * vm,
                  unformat_input_t * input, vlib_cli_command_t * cmd)