diff options
author | 2019-03-29 13:27:22 +0000 | |
---|---|---|
committer | 2019-03-29 13:27:22 +0000 | |
commit | 65317f78ac16a40d0ce189ec90eca45cbd064006 (patch) | |
tree | cb126f20a74524e32a466c9b62a699023e831c84 /hicn-plugin/src/hicn_api.c | |
parent | 1eec68585d60ef29bead48c0a1c5950d50b0260f (diff) | |
parent | 680a127fa92d8ee6e2dfb786f4dabc0519648b29 (diff) |
Merge "[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"
Diffstat (limited to 'hicn-plugin/src/hicn_api.c')
-rw-r--r-- | hicn-plugin/src/hicn_api.c | 61 |
1 files changed, 57 insertions, 4 deletions
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* */ } |