aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--src/plugins/linux-cp/lcp.api16
-rw-r--r--src/plugins/linux-cp/lcp_api.c81
-rw-r--r--src/plugins/linux-cp/lcp_cli.c2
-rw-r--r--src/plugins/linux-cp/lcp_interface.c8
-rw-r--r--src/plugins/linux-cp/lcp_interface.h3
5 files changed, 88 insertions, 22 deletions
diff --git a/src/plugins/linux-cp/lcp.api b/src/plugins/linux-cp/lcp.api
index 5bde88082df..319dd3e6483 100644
--- a/src/plugins/linux-cp/lcp.api
+++ b/src/plugins/linux-cp/lcp.api
@@ -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
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
diff --git a/src/plugins/linux-cp/lcp_cli.c b/src/plugins/linux-cp/lcp_cli.c
index 0231f67f835..cb874b1c023 100644
--- a/src/plugins/linux-cp/lcp_cli.c
+++ b/src/plugins/linux-cp/lcp_cli.c
@@ -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);
diff --git a/src/plugins/linux-cp/lcp_interface.c b/src/plugins/linux-cp/lcp_interface.c
index 0dcac4857cf..e33c34b5f6a 100644
--- a/src/plugins/linux-cp/lcp_interface.c
+++ b/src/plugins/linux-cp/lcp_interface.c
@@ -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);
diff --git a/src/plugins/linux-cp/lcp_interface.h b/src/plugins/linux-cp/lcp_interface.h
index d2f19e8481b..be566a07cb6 100644
--- a/src/plugins/linux-cp/lcp_interface.h
+++ b/src/plugins/linux-cp/lcp_interface.h
@@ -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