summaryrefslogtreecommitdiffstats
path: root/src/plugins/linux-cp/lcp_api.c
diff options
context:
space:
mode:
authorNeale Ranns <neale@graphiant.com>2021-05-21 09:47:08 +0000
committerMatthew Smith <mgsmith@netgate.com>2021-05-25 14:34:57 +0000
commit6bb77dec7074e6b7b27d6bc94238bcddda375a66 (patch)
tree44316c04ad5870fa64acd595a074ed02de539613 /src/plugins/linux-cp/lcp_api.c
parent01930f568a2472a3352ab80ea1d3b4cccf4ae0c7 (diff)
linux-cp: A V2 variant of pair create API that returns the host
interface created Type: improvement Signed-off-by: Neale Ranns <neale@graphiant.com> Change-Id: I31a83cd50513078895078bae3ae11372d351ddcd
Diffstat (limited to 'src/plugins/linux-cp/lcp_api.c')
-rw-r--r--src/plugins/linux-cp/lcp_api.c81
1 files changed, 63 insertions, 18 deletions
diff --git a/src/plugins/linux-cp/lcp_api.c b/src/plugins/linux-cp/lcp_api.c
index a6e14a7cac7..c9aa01566c6 100644
--- a/src/plugins/linux-cp/lcp_api.c
+++ b/src/plugins/linux-cp/lcp_api.c
@@ -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