linux-cp: A V2 variant of pair create API that returns the host 11/32411/2
authorNeale Ranns <neale@graphiant.com>
Fri, 21 May 2021 09:47:08 +0000 (09:47 +0000)
committerMatthew Smith <mgsmith@netgate.com>
Tue, 25 May 2021 14:34:57 +0000 (14:34 +0000)
interface created

Type: improvement

Signed-off-by: Neale Ranns <neale@graphiant.com>
Change-Id: I31a83cd50513078895078bae3ae11372d351ddcd

src/plugins/linux-cp/lcp.api
src/plugins/linux-cp/lcp_api.c
src/plugins/linux-cp/lcp_cli.c
src/plugins/linux-cp/lcp_interface.c
src/plugins/linux-cp/lcp_interface.h

index 5bde880..319dd3e 100644 (file)
@@ -79,6 +79,22 @@ autoreply autoendian define lcp_itf_pair_add_del
   vl_api_lcp_itf_host_type_t host_if_type;
   string namespace[32];                        /* LCP_NS_LEN */
 };
+autoendian define lcp_itf_pair_add_del_v2
+{
+  u32 client_index;
+  u32 context;
+  bool is_add;
+  vl_api_interface_index_t sw_if_index;
+  string host_if_name[16];             /* IFNAMSIZ */
+  vl_api_lcp_itf_host_type_t host_if_type;
+  string namespace[32];                        /* LCP_NS_LEN */
+};
+define lcp_itf_pair_add_del_v2_reply
+{
+  u32 context;
+  i32 retval;
+  vl_api_interface_index_t host_sw_if_index;
+};
 
 /** \brief Dump Linux Control Plane interface pair data
     @param client_index - opaque cookie to identify the sender
index a6e14a7..c9aa015 100644 (file)
@@ -57,6 +57,35 @@ lcp_auto_intf (void)
   return lcpm->auto_intf;
 }
 
+static int
+vl_api_lcp_itf_pair_add (u32 phy_sw_if_index, lip_host_type_t lip_host_type,
+                        u8 *mp_host_if_name, size_t sizeof_host_if_name,
+                        u8 *mp_namespace, size_t sizeof_mp_namespace,
+                        u32 *host_sw_if_index_p)
+{
+  u8 *host_if_name, *netns;
+  int host_len, netns_len, rv;
+
+  host_if_name = netns = 0;
+
+  /* lcp_itf_pair_create expects vec of u8 */
+  host_len = clib_strnlen ((char *) mp_host_if_name, sizeof_host_if_name - 1);
+  vec_add (host_if_name, mp_host_if_name, host_len);
+  vec_add1 (host_if_name, 0);
+
+  netns_len = clib_strnlen ((char *) mp_namespace, sizeof_mp_namespace - 1);
+  vec_add (netns, mp_namespace, netns_len);
+  vec_add1 (netns, 0);
+
+  rv = lcp_itf_pair_create (phy_sw_if_index, host_if_name, lip_host_type,
+                           netns, host_sw_if_index_p);
+
+  vec_free (host_if_name);
+  vec_free (netns);
+
+  return rv;
+}
+
 static void
 vl_api_lcp_itf_pair_add_del_t_handler (vl_api_lcp_itf_pair_add_del_t *mp)
 {
@@ -75,27 +104,42 @@ vl_api_lcp_itf_pair_add_del_t_handler (vl_api_lcp_itf_pair_add_del_t *mp)
   lip_host_type = api_decode_host_type (mp->host_if_type);
   if (mp->is_add)
     {
-      u8 *host_if_name, *netns;
-      int host_len, netns_len;
-
-      host_if_name = netns = 0;
+      rv =
+       vl_api_lcp_itf_pair_add (phy_sw_if_index, lip_host_type,
+                                mp->host_if_name, sizeof (mp->host_if_name),
+                                mp->namespace, sizeof (mp->namespace), NULL);
+    }
+  else
+    {
+      rv = lcp_itf_pair_delete (phy_sw_if_index);
+    }
 
-      /* lcp_itf_pair_create expects vec of u8 */
-      host_len = clib_strnlen ((char *) mp->host_if_name,
-                              sizeof (mp->host_if_name) - 1);
-      vec_add (host_if_name, mp->host_if_name, host_len);
-      vec_add1 (host_if_name, 0);
+  BAD_SW_IF_INDEX_LABEL;
+  REPLY_MACRO (VL_API_LCP_ITF_PAIR_ADD_DEL_REPLY);
+}
 
-      netns_len =
-       clib_strnlen ((char *) mp->namespace, sizeof (mp->namespace) - 1);
-      vec_add (netns, mp->namespace, netns_len);
-      vec_add1 (netns, 0);
+static void
+vl_api_lcp_itf_pair_add_del_v2_t_handler (vl_api_lcp_itf_pair_add_del_v2_t *mp)
+{
+  u32 phy_sw_if_index, host_sw_if_index = ~0;
+  vl_api_lcp_itf_pair_add_del_v2_reply_t *rmp;
+  lip_host_type_t lip_host_type;
+  int rv;
 
-      rv = lcp_itf_pair_create (phy_sw_if_index, host_if_name, lip_host_type,
-                               netns);
+  if (!vnet_sw_if_index_is_api_valid (mp->sw_if_index))
+    {
+      rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
+      goto bad_sw_if_index;
+    }
 
-      vec_free (host_if_name);
-      vec_free (netns);
+  phy_sw_if_index = mp->sw_if_index;
+  lip_host_type = api_decode_host_type (mp->host_if_type);
+  if (mp->is_add)
+    {
+      rv = vl_api_lcp_itf_pair_add (phy_sw_if_index, lip_host_type,
+                                   mp->host_if_name,
+                                   sizeof (mp->host_if_name), mp->namespace,
+                                   sizeof (mp->namespace), &host_sw_if_index);
     }
   else
     {
@@ -103,7 +147,8 @@ vl_api_lcp_itf_pair_add_del_t_handler (vl_api_lcp_itf_pair_add_del_t *mp)
     }
 
   BAD_SW_IF_INDEX_LABEL;
-  REPLY_MACRO (VL_API_LCP_ITF_PAIR_ADD_DEL_REPLY);
+  REPLY_MACRO2 (VL_API_LCP_ITF_PAIR_ADD_DEL_V2_REPLY,
+               { rmp->host_sw_if_index = ntohl (host_sw_if_index); });
 }
 
 static void
index 0231f67..cb874b1 100644 (file)
@@ -93,7 +93,7 @@ lcp_itf_pair_create_command_fn (vlib_main_t *vm, unformat_input_t *input,
        0, "Namespace name should be fewer than %d characters", LCP_NS_LEN);
     }
 
-  r = lcp_itf_pair_create (sw_if_index, host_if_name, host_if_type, ns);
+  r = lcp_itf_pair_create (sw_if_index, host_if_name, host_if_type, ns, NULL);
 
   vec_free (host_if_name);
   vec_free (ns);
index 0dcac48..e33c34b 100644 (file)
@@ -640,7 +640,8 @@ lcp_itf_set_vif_link_state (u32 vif_index, u8 up, u8 *ns)
 
 int
 lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
-                    lip_host_type_t host_if_type, u8 *ns)
+                    lip_host_type_t host_if_type, u8 *ns,
+                    u32 *host_sw_if_indexp)
 {
   vlib_main_t *vm;
   vnet_main_t *vnm;
@@ -823,6 +824,9 @@ lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
                     format_vnet_sw_if_index_name, vnet_get_main (),
                     host_sw_if_index, host_if_name);
 
+  if (host_sw_if_indexp)
+    *host_sw_if_indexp = host_sw_if_index;
+
   return 0;
 }
 
@@ -902,7 +906,7 @@ lcp_itf_pair_process (vlib_main_t *vm, vlib_node_runtime_t *rt,
          lipn = &lipn_names[*lipn_index];
          lcp_itf_pair_create (lipn->lipn_phy_sw_if_index,
                               lipn->lipn_host_name, LCP_ITF_HOST_TAP,
-                              lipn->lipn_namespace);
+                              lipn->lipn_namespace, NULL);
        }
 
       vec_reset_length (event_data);
index d2f19e8..be566a0 100644 (file)
@@ -98,7 +98,8 @@ extern int lcp_itf_pair_del (u32 phy_sw_if_index);
  * @return error code
  */
 extern int lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
-                               lip_host_type_t host_if_type, u8 *ns);
+                               lip_host_type_t host_if_type, u8 *ns,
+                               u32 *host_sw_if_indexp);
 
 /**
  * Delete a LCP_ITF_PAIR