sr: SRv6 uN behavior
[vpp.git] / src / vnet / srv6 / sr_api.c
index 17d4821..cd81824 100644 (file)
@@ -24,6 +24,7 @@
 #include <vnet/interface.h>
 #include <vnet/api_errno.h>
 #include <vnet/feature/feature.h>
+#include <vnet/fib/fib_table.h>
 
 #include <vnet/vnet_msg_enum.h>
 
@@ -50,6 +51,7 @@ _(SR_POLICY_MOD, sr_policy_mod)                         \
 _(SR_POLICY_DEL, sr_policy_del)                         \
 _(SR_STEERING_ADD_DEL, sr_steering_add_del)             \
 _(SR_SET_ENCAP_SOURCE, sr_set_encap_source)             \
+_(SR_SET_ENCAP_HOP_LIMIT, sr_set_encap_hop_limit)       \
 _(SR_LOCALSIDS_DUMP, sr_localsids_dump)                 \
 _(SR_POLICIES_DUMP, sr_policies_dump)                   \
 _(SR_STEERING_POL_DUMP, sr_steering_pol_dump)
@@ -71,7 +73,7 @@ static void vl_api_sr_localsid_add_del_t_handler
 
   ip46_address_t prefix;
 
-  memset (&prefix, 0, sizeof (ip46_address_t));
+  clib_memset (&prefix, 0, sizeof (ip46_address_t));
   if ((mp->nh_addr4[0] | mp->nh_addr4[1] | mp->
        nh_addr4[2] | mp->nh_addr4[3]) != 0)
     memcpy (&prefix.ip4, mp->nh_addr4, sizeof (prefix.ip4));
@@ -79,7 +81,7 @@ static void vl_api_sr_localsid_add_del_t_handler
     memcpy (&prefix.ip6, mp->nh_addr6, sizeof (prefix.ip6));
 
   rv = sr_cli_localsid (mp->is_del,
-                       (ip6_address_t *) & mp->localsid,
+                       (ip6_address_t *) & mp->localsid, 128,
                        mp->end_psp,
                        mp->behavior,
                        ntohl (mp->sw_if_index),
@@ -107,13 +109,15 @@ vl_api_sr_policy_add_t_handler (vl_api_sr_policy_add_t * mp)
 
 /*
  * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
- *                u32 weight, u8 behavior, u32 fib_table, u8 is_encap)
+ *                u32 weight, u8 behavior, u32 fib_table, u8 is_encap,
+ *                u16 behavior, void *plugin_mem)
  */
   int rv = 0;
   rv = sr_policy_add ((ip6_address_t *) & mp->bsid_addr,
                      segments,
                      ntohl (mp->sids.weight),
-                     mp->type, ntohl (mp->fib_table), mp->is_encap);
+                     mp->type, ntohl (mp->fib_table), mp->is_encap, 0, NULL);
+  vec_free (segments);
 
   REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY);
 }
@@ -147,6 +151,7 @@ vl_api_sr_policy_mod_t_handler (vl_api_sr_policy_mod_t * mp)
                      mp->operation,
                      segments, ntohl (mp->sl_index),
                      ntohl (mp->sids.weight));
+  vec_free (segments);
 
   REPLY_MACRO (VL_API_SR_POLICY_MOD_REPLY);
 }
@@ -173,7 +178,21 @@ vl_api_sr_set_encap_source_t_handler (vl_api_sr_set_encap_source_t * mp)
   int rv = 0;
   sr_set_source ((ip6_address_t *) & mp->encaps_source);
 
-  REPLY_MACRO (VL_API_SR_POLICY_DEL_REPLY);
+  REPLY_MACRO (VL_API_SR_SET_ENCAP_SOURCE_REPLY);
+}
+
+static void
+vl_api_sr_set_encap_hop_limit_t_handler (vl_api_sr_set_encap_hop_limit_t * mp)
+{
+  vl_api_sr_set_encap_hop_limit_reply_t *rmp;
+  int rv = 0;
+
+  if (mp->hop_limit == 0)
+    rv = VNET_API_ERROR_INVALID_VALUE;
+  else
+    sr_set_hop_limit (mp->hop_limit);
+
+  REPLY_MACRO (VL_API_SR_SET_ENCAP_HOP_LIMIT_REPLY);
 }
 
 static void vl_api_sr_steering_add_del_t_handler
@@ -208,7 +227,7 @@ static void send_sr_localsid_details
   vl_api_sr_localsids_details_t *rmp;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_SR_LOCALSIDS_DETAILS);
   clib_memcpy (rmp->addr.addr, &t->localsid, sizeof (ip6_address_t));
   rmp->end_psp = t->end_psp;
@@ -221,7 +240,16 @@ static void send_sr_localsid_details
   else
     clib_memcpy (rmp->xconnect_nh_addr6, &t->next_hop.ip6,
                 sizeof (ip6_address_t));
-  rmp->xconnect_iface_or_vrf_table = htonl (t->sw_if_index);
+
+  if (t->behavior == SR_BEHAVIOR_T || t->behavior == SR_BEHAVIOR_DT6)
+    rmp->xconnect_iface_or_vrf_table =
+      htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP6));
+  else if (t->behavior == SR_BEHAVIOR_DT4)
+    rmp->xconnect_iface_or_vrf_table =
+      htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP4));
+  else
+    rmp->xconnect_iface_or_vrf_table = htonl (t->sw_if_index);
+
   rmp->context = context;
 
   vl_api_send_msg (reg, (u8 *) rmp);
@@ -259,9 +287,10 @@ static void send_sr_policies_details
   rmp = vl_msg_api_alloc (sizeof (*rmp) +
                          vec_len (t->segments_lists) *
                          sizeof (vl_api_srv6_sid_list_t));
-  memset (rmp, 0,
-         (sizeof (*rmp) +
-          vec_len (t->segments_lists) * sizeof (vl_api_srv6_sid_list_t)));
+  clib_memset (rmp, 0,
+              (sizeof (*rmp) +
+               vec_len (t->segments_lists) *
+               sizeof (vl_api_srv6_sid_list_t)));
 
   rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_DETAILS);
   clib_memcpy (rmp->bsid.addr, &t->bsid, sizeof (ip6_address_t));
@@ -311,7 +340,7 @@ static void send_sr_steering_pol_details
   ip6_sr_main_t *sm = &sr_main;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
-  memset (rmp, 0, sizeof (*rmp));
+  clib_memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_SR_STEERING_POL_DETAILS);
 
   //Get the SR policy BSID
@@ -358,7 +387,7 @@ static void vl_api_sr_steering_pol_dump_t_handler
 /*
  * sr_api_hookup
  * Add vpe's API message handlers to the table.
- * vlib has alread mapped shared memory and
+ * vlib has already mapped shared memory and
  * added the client registration handlers.
  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
  */
@@ -377,7 +406,7 @@ setup_message_id_table (api_main_t * am)
 static clib_error_t *
 sr_api_hookup (vlib_main_t * vm)
 {
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
 #define _(N,n)                                                  \
     vl_msg_api_set_handlers(VL_API_##N, #n,                     \