From ccf813e13eba7b5c71cc3090582f50f25ba7b721 Mon Sep 17 00:00:00 2001 From: Alberto Compagno Date: Thu, 22 Aug 2019 09:48:32 +0200 Subject: [HICN-262] Fix binary api to prevent byteswapping of ip addresses in vapi Change-Id: If3f9a7db1e1310fdc08d1003b28e5e1d4006b61e Signed-off-by: Alberto Compagno --- .../hicn/transport/core/vpp_forwarder_interface.cc | 33 +++++++++------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc') diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc index c8a4f9c88..598b692c9 100644 --- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc +++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc @@ -87,8 +87,8 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() { void VPPForwarderInterface::consumerConnection() { hicn_consumer_input_params input = {0}; hicn_consumer_output_params output = {0}; - ip_prefix_t ip4_address; - ip_prefix_t ip6_address; + ip_address_t ip4_address; + ip_address_t ip6_address; output.src4 = &ip4_address; output.src6 = &ip6_address; @@ -102,13 +102,9 @@ void VPPForwarderInterface::consumerConnection() { throw errors::RuntimeException(hicn_binary_api_get_error_string(ret)); } - inet_address_.family = AF_INET; - inet_address_.len = output.src4->len; - std::memcpy(inet_address_.address.buffer, output.src4->address.buffer, IPV6_ADDR_LEN); + std::memcpy(inet_address_.v4.as_u8, output.src4->as_u8, IPV4_ADDR_LEN); - inet6_address_.family = AF_INET6; - inet6_address_.len = output.src6->len; - std::memcpy(inet6_address_.address.buffer, output.src6->address.buffer, IPV6_ADDR_LEN); + std::memcpy(inet6_address_.v6.as_u8, output.src6->as_u8, IPV6_ADDR_LEN); } void VPPForwarderInterface::producerConnection() { @@ -141,10 +137,10 @@ void VPPForwarderInterface::connect(bool is_consumer) { } void VPPForwarderInterface::registerRoute(Prefix &prefix) { - auto &addr = prefix.toIpAddressStruct(); + ip_prefix_t &addr = prefix.toIpPrefixStruct(); - // Same ip address for input and outurt params - ip_prefix_t ip_address; + ip_prefix_t producer_prefix; + ip_address_t producer_locator; if (face_id_ == uint32_t(~0)) { hicn_producer_input_params input; @@ -153,8 +149,8 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) { hicn_producer_output_params output; std::memset(&output, 0, sizeof(output)); - input.prefix = &ip_address; - output.prod_addr = &ip_address; + input.prefix = &producer_prefix; + output.prod_addr = &producer_locator; // Here we have to ask to the actual connector what is the // memif_id, since this function should be called after the @@ -174,21 +170,18 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) { } if (addr.family == AF_INET6) { - inet6_address_.len = output.prod_addr->len; - inet6_address_.address.as_u64[0] = output.prod_addr->address.as_u64[0]; - inet6_address_.address.as_u64[1] = output.prod_addr->address.as_u64[1]; + inet6_address_.v6.as_u64[0] = output.prod_addr->v6.as_u64[0]; + inet6_address_.v6.as_u64[1] = output.prod_addr->v6.as_u64[1]; } else { - inet_address_.len = output.prod_addr->len; // The ipv4 is written in the last 4 bytes of the ipv6 address, so we need // to copy from the byte 12 - inet_address_.address.as_u64[0] = output.prod_addr->address.as_u64[0]; - inet_address_.address.as_u64[1] = output.prod_addr->address.as_u64[1]; + inet_address_.v4.as_u32 = output.prod_addr->v4.as_u32; } face_id_ = output.face_id; } else { hicn_producer_set_route_params params; - params.prefix = &ip_address; + params.prefix = &producer_prefix; params.prefix->address.as_u64[0] = addr.address.as_u64[0]; params.prefix->address.as_u64[1] = addr.address.as_u64[1]; params.prefix->family = addr.family == AF_INET6 ? AF_INET6 : AF_INET; -- cgit 1.2.3-korg