summaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/faces
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 /hicn-plugin/src/faces
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>
Diffstat (limited to 'hicn-plugin/src/faces')
-rw-r--r--hicn-plugin/src/faces/ip/face_ip_cli.c61
1 files changed, 57 insertions, 4 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)
{