summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlberto Compagno <acompagn+fdio@cisco.com>2019-03-28 18:25:10 +0100
committerAlberto Compagno <acompagn+fdio@cisco.com>2019-03-29 13:27:47 +0100
commit680a127fa92d8ee6e2dfb786f4dabc0519648b29 (patch)
tree5e827f8023b0be4477184a596b26b98456c286c1
parent092e4903066f66f51c60ca8a0cef4cabbe7bafaa (diff)
[HICN-151] The source address in the IP face is optional. If not provided it will be used one of the ip addresses available in the interface
Change-Id: If800a07c0a61cde9152efdee01dd6ae9b12615dc Signed-off-by: Alberto Compagno <acompagn+fdio@cisco.com>
-rw-r--r--hicn-plugin/src/faces/ip/face_ip_cli.c61
-rw-r--r--hicn-plugin/src/hicn_api.c61
-rw-r--r--hicn-plugin/src/hicn_api_test.c10
-rw-r--r--hicn-plugin/src/route.c2
4 files changed, 119 insertions, 15 deletions
diff --git a/hicn-plugin/src/faces/ip/face_ip_cli.c b/hicn-plugin/src/faces/ip/face_ip_cli.c
index 534ae7f63..ba7765541 100644
--- a/hicn-plugin/src/faces/ip/face_ip_cli.c
+++ b/hicn-plugin/src/faces/ip/face_ip_cli.c
@@ -60,10 +60,12 @@ hicn_face_ip_cli_set_command_fn (vlib_main_t * vm,
else if (unformat (line_input, "add"))
{
face_op = HICN_FACE_ADD;
- if (unformat (line_input, "local %U remote %U intfc %U",
- unformat_ip46_address, &local_addr, IP46_TYPE_ANY,
- unformat_ip46_address, &remote_addr, IP46_TYPE_ANY,
- unformat_vnet_sw_interface, vnm, &sw_if));
+ if (unformat (line_input, "local %U ",
+ unformat_ip46_address, &local_addr, IP46_TYPE_ANY));
+ else if (unformat (line_input, "remote %U intfc %U",
+ unformat_ip46_address, &remote_addr,
+ IP46_TYPE_ANY, unformat_vnet_sw_interface, vnm,
+ &sw_if));
else
{
return clib_error_return (0, "%s '%U'",
@@ -90,6 +92,57 @@ hicn_face_ip_cli_set_command_fn (vlib_main_t * vm,
}
}
+ if (ip46_address_is_zero (&local_addr))
+ {
+ if (!vnet_sw_interface_is_valid (vnm, sw_if))
+ return clib_error_return (0, "interface not valid");
+
+ if (ip46_address_is_ip4 (&remote_addr))
+ {
+ ip_interface_address_t *interface_address;
+ ip4_address_t *addr =
+ ip4_interface_address_matching_destination (&ip4_main,
+ &remote_addr.ip4,
+ sw_if,
+ &interface_address);
+
+ if (addr == NULL)
+ addr = ip4_interface_first_address (&ip4_main,
+ sw_if, &interface_address);
+
+ if (addr == NULL)
+ return clib_error_return (0,
+ "no valid ip address on interface %d",
+ sw_if);
+
+ ip46_address_set_ip4 (&local_addr, addr);
+ }
+ else
+ {
+ ip_interface_address_t *interface_address;
+ ip6_interface_address_matching_destination (&ip6_main,
+ &remote_addr.ip6, sw_if,
+ &interface_address);
+
+ ip6_address_t *addr = NULL;
+ if (interface_address != NULL)
+ addr =
+ (ip6_address_t *)
+ ip_interface_address_get_address (&ip6_main.lookup_main,
+ interface_address);
+
+ if (addr == NULL)
+ addr = ip6_interface_first_address (&ip6_main, sw_if);
+
+ if (addr == NULL)
+ return clib_error_return (0,
+ "no valid ip address on interface %d",
+ sw_if);
+
+ ip46_address_set_ip6 (&local_addr, addr);
+ }
+ }
+
int rv;
switch (face_op)
{
diff --git a/hicn-plugin/src/hicn_api.c b/hicn-plugin/src/hicn_api.c
index 8f47ea799..b4d518774 100644
--- a/hicn-plugin/src/hicn_api.c
+++ b/hicn-plugin/src/hicn_api.c
@@ -208,15 +208,68 @@ vl_api_hicn_api_face_ip_add_t_handler (vl_api_hicn_api_face_ip_add_t * mp)
remote_addr.as_u64[1] =
clib_net_to_host_u64 (((u64 *) (&mp->remote_addr))[1]);
- u32 swif = clib_net_to_host_u32 (mp->swif);
+ u32 sw_if = clib_net_to_host_u32 (mp->swif);
+
+ if (ip46_address_is_zero (&local_addr))
+ {
+ if (vnet_sw_interface_is_valid (vnm, sw_if))
+ {
+ rv = HICN_ERROR_NONE;
+ }
+
+ if (rv == HICN_ERROR_NONE && ip46_address_is_ip4 (&remote_addr))
+ {
+ ip_interface_address_t *interface_address;
+ ip4_address_t *addr =
+ ip4_interface_address_matching_destination (&ip4_main,
+ &remote_addr.ip4,
+ sw_if,
+ &interface_address);
+ if (addr == NULL)
+ addr = ip4_interface_first_address (&ip4_main,
+ sw_if, &interface_address);
+
+ if (addr == NULL)
+ rv = HICN_ERROR_UNSPECIFIED;
+ else
+ ip46_address_set_ip4 (&local_addr, addr);
+ }
+ else
+ {
+ ip_interface_address_t *interface_address;
+ ip6_interface_address_matching_destination (&ip6_main,
+ &remote_addr.ip6, sw_if,
+ &interface_address);
+ ip6_address_t *addr = NULL;
+ if (rv == HICN_ERROR_NONE && interface_address != NULL)
+ {
+ addr =
+ (ip6_address_t *)
+ ip_interface_address_get_address (&ip6_main.lookup_main,
+ interface_address);
+ }
+ else
+ {
+ addr = ip6_interface_first_address (&ip6_main, sw_if);
+ }
- if (vnet_get_sw_interface_safe (vnm, swif) != NULL)
- rv = hicn_face_ip_add (&local_addr, &remote_addr, swif, &faceid);
+ if (addr == NULL)
+ rv = HICN_ERROR_UNSPECIFIED;
+ else
+ ip46_address_set_ip6 (&local_addr, addr);
+ }
+ }
+
+ if (rv == HICN_ERROR_NONE)
+ rv = hicn_face_ip_add (&local_addr, &remote_addr, sw_if, &faceid);
+ else
+ faceid = HICN_FACE_NULL;
/* *INDENT-OFF* */
REPLY_MACRO2 (VL_API_HICN_API_FACE_IP_ADD_REPLY /* , rmp, mp, rv */ ,(
{
- rmp->faceid = clib_host_to_net_u16 ((u16) faceid);
+ rmp->faceid = clib_host_to_net_u16 ((u32) faceid);
+ rmp->retval = rv;
}));
/* *INDENT-ON* */
}
diff --git a/hicn-plugin/src/hicn_api_test.c b/hicn-plugin/src/hicn_api_test.c
index 909bc540f..4225f0078 100644
--- a/hicn-plugin/src/hicn_api_test.c
+++ b/hicn-plugin/src/hicn_api_test.c
@@ -362,11 +362,9 @@ api_hicn_api_face_ip_add (vat_main_t * vam)
}
/* Check for presence of both addresses */
- if ((!ip46_address_is_zero (&local_addr)
- && ! !ip46_address_is_zero (&remote_addr)))
+ if (ip46_address_is_zero (&remote_addr))
{
- clib_warning
- ("Incomplete IP face. Please specify local and remote address");
+ clib_warning ("Incomplete IP face. Please specify remote address");
return (1);
}
/* Construct the API message */
@@ -558,7 +556,7 @@ api_hicn_api_face_stats_dump (vat_main_t * vam)
/* memif-details message handler */
static void
-vl_api_hicn_api_face_stats_details_t_handler
+ vl_api_hicn_api_face_stats_details_t_handler
(vl_api_hicn_api_face_stats_details_t * mp)
{
vat_main_t *vam = hicn_test_main.vat_main;
@@ -1071,7 +1069,7 @@ _(hicn_api_node_params_set, "PIT size <sz> CS size <sz>" \
_(hicn_api_node_params_get, "") \
_(hicn_api_node_stats_get, "") \
_(hicn_api_face_ip_del, "face <faceID>") \
-_(hicn_api_face_ip_add, "add <swif> <address>") \
+_(hicn_api_face_ip_add, "local <address> remote <address> intfc <swif>")\
_(hicn_api_face_stats_dump, "") \
_(hicn_api_route_nhops_add, "add prefix <IP4/IP6>/<subnet> face <faceID> weight <weight>") \
_(hicn_api_face_ip_params_get, "face <faceID>") \
diff --git a/hicn-plugin/src/route.c b/hicn-plugin/src/route.c
index 9202efbd4..11302aba4 100644
--- a/hicn-plugin/src/route.c
+++ b/hicn-plugin/src/route.c
@@ -108,7 +108,7 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len,
vlib_main_t *vm = vlib_get_main ();
hicn_face_vft_t *face_vft = NULL;
- if (face_id == NULL)
+ if (face_id == NULL || !hicn_dpoi_idx_is_valid (*face_id))
{
return HICN_ERROR_ROUTE_INVAL;
}