sr: SRv6 uN behavior
[vpp.git] / src / vnet / srv6 / sr.h
index d0f4286..f804b19 100755 (executable)
 
 #define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1
 
+/* *INDENT-OFF* */
+typedef struct
+{
+  ip6_header_t ip;
+  ip6_sr_header_t sr;
+} __attribute__ ((packed)) ip6srv_combo_header_t;
+/* *INDENT-ON* */
+
 /**
  * @brief SR Segment List (SID list)
  */
@@ -69,6 +77,9 @@ typedef struct
   dpo_id_t bsid_dpo;                           /**< DPO for Encaps/Insert for BSID */
   dpo_id_t ip6_dpo;                            /**< DPO for Encaps/Insert IPv6 */
   dpo_id_t ip4_dpo;                            /**< DPO for Encaps IPv6 */
+
+  u16 plugin;
+  void *plugin_mem;
 } ip6_sr_sl_t;
 
 /* SR policy types */
@@ -94,8 +105,13 @@ typedef struct
   u32 fib_table;                       /**< FIB table */
 
   u8 is_encap;                         /**< Mode (0 is SRH insert, 1 Encaps) */
+
+  u16 plugin;
+  void *plugin_mem;
 } ip6_sr_policy_t;
 
+typedef int (sr_p_plugin_callback_t) (ip6_sr_policy_t * sr);
+
 /**
  * @brief SR LocalSID
  */
@@ -103,6 +119,8 @@ typedef struct
 {
   ip6_address_t localsid;              /**< LocalSID IPv6 address */
 
+  u16 localsid_prefix_len;
+
   char end_psp;                                        /**< Combined with End.PSP? */
 
   u16 behavior;                                        /**< Behavior associated to this localsid */
@@ -141,6 +159,8 @@ typedef struct
 
   u8 *params_str;                                                      /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
 
+  u8 prefix_length;
+
   dpo_type_t dpo;                                                      /**< DPO type registration */
 
   format_function_t *ls_format;                                /**< LocalSID format function */
@@ -152,6 +172,34 @@ typedef struct
   sr_plugin_callback_t *removal;                       /**< Function within plugin that will be called before localsid removal */
 } sr_localsid_fn_registration_t;
 
+/**
+ * @brief SR Policy behavior registration
+ */
+typedef struct
+{
+  u16 sr_policy_function_number;                       /**< SR Policy plugin function */
+
+  u8 *function_name;                                   /**< Function name. (key). */
+
+  u8 *keyword_str;                                     /**< Behavior keyword (i.e. End.X) */
+
+  u8 *def_str;                                         /**< Behavior definition (i.e. Endpoint with cross-connect) */
+
+  u8 *params_str;                                      /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
+
+  u8 prefix_length;
+
+  dpo_type_t dpo;                                      /**< DPO type registration */
+
+  format_function_t *ls_format;                                /**< LocalSID format function */
+
+  unformat_function_t *ls_unformat;                    /**< LocalSID unformat function */
+
+  sr_p_plugin_callback_t *creation;                    /**< Function within plugin that will be called after localsid creation*/
+
+  sr_p_plugin_callback_t *removal;                     /**< Function within plugin that will be called before localsid removal */
+} sr_policy_fn_registration_t;
+
 /**
  * @brief Steering db key
  *
@@ -224,6 +272,12 @@ typedef struct
   /* Find plugin function by name */
   uword *plugin_functions_by_key;
 
+  /* Plugin functions for Policy */
+  sr_policy_fn_registration_t *policy_plugin_functions;
+
+  /* Find plugin function by name */
+  uword *policy_plugin_functions_by_key;
+
   /* Counters */
   vlib_combined_counter_main_t sr_ls_valid_counters;
   vlib_combined_counter_main_t sr_ls_invalid_counters;
@@ -250,32 +304,48 @@ extern void sr_dpo_unlock (dpo_id_t * dpo);
 extern 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,
+                              u8 * params_str, u8 prefix_length,
+                              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);
 
 extern int
-sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
-              u32 weight, u8 behavior, u32 fib_table, u8 is_encap);
+sr_policy_register_function (vlib_main_t * vm, u8 * fn_name,
+                            u8 * keyword_str, u8 * def_str,
+                            u8 * params_str, u8 prefix_length,
+                            dpo_type_t * dpo,
+                            format_function_t * ls_format,
+                            unformat_function_t * ls_unformat,
+                            sr_p_plugin_callback_t * creation_fn,
+                            sr_p_plugin_callback_t * removal_fn);
+
 extern int
-sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table,
-              u8 operation, ip6_address_t * segments, u32 sl_index,
-              u32 weight);
+sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
+              u32 weight, u8 behavior, u32 fib_table, u8 is_encap,
+              u16 plugin, void *plugin_mem);
+extern int sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table,
+                         u8 operation, ip6_address_t * segments,
+                         u32 sl_index, u32 weight);
 extern int sr_policy_del (ip6_address_t * bsid, u32 index);
 
 extern 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);
+                u16 localsid_prefix_len, char end_psp, u8 behavior,
+                u32 sw_if_index, u32 vlan_index, u32 fib_table,
+                ip46_address_t * nh_addr, void *ls_plugin_mem);
 
 extern int
 sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
                    u32 table_id, ip46_address_t * prefix, u32 mask_width,
                    u32 sw_if_index, u8 traffic_type);
 
+extern void sr_set_source (ip6_address_t * address);
+
+extern void sr_set_hop_limit (u8 hop_limit);
+extern u8 sr_get_hop_limit (void);
+
 /**
  * @brief SR rewrite string computation for SRH insertion (inline)
  *
@@ -300,15 +370,16 @@ ip6_sr_compute_rewrite_string_insert (ip6_address_t * sl)
   srh = (ip6_sr_header_t *) rs;
   srh->type = ROUTING_HEADER_TYPE_SR;
   srh->segments_left = vec_len (sl);
-  srh->first_segment = vec_len (sl);
+  srh->last_entry = vec_len (sl);
   srh->length = ((sizeof (ip6_sr_header_t) +
                  ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1;
   srh->flags = 0x00;
-  srh->reserved = 0x0000;
+  srh->tag = 0x0000;
   addrp = srh->segments + vec_len (sl);
   vec_foreach (this_address, sl)
   {
-    clib_memcpy (addrp->as_u8, this_address->as_u8, sizeof (ip6_address_t));
+    clib_memcpy_fast (addrp->as_u8, this_address->as_u8,
+                     sizeof (ip6_address_t));
     addrp--;
   }
   return rs;