From 8c8acc027871f97370ee549306876690030c3bbb Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 27 Nov 2018 10:05:23 +0100 Subject: API: Change ip4_address and ip6_address to use type alias. Change-Id: Id8669bbadd1d6b2054865a310a654e9b38d1667d Signed-off-by: Ole Troan --- extras/vom/vom/api_types.cpp | 59 +++++-------------------- extras/vom/vom/api_types.hpp | 2 +- extras/vom/vom/bridge_domain_arp_entry_cmds.cpp | 4 +- extras/vom/vom/gbp_contract_cmds.cpp | 2 +- extras/vom/vom/gbp_endpoint_cmds.cpp | 2 +- extras/vom/vom/ip_punt_redirect_cmds.cpp | 4 +- 6 files changed, 19 insertions(+), 54 deletions(-) (limited to 'extras') diff --git a/extras/vom/vom/api_types.cpp b/extras/vom/vom/api_types.cpp index 1b9ff2913a1..1bde8be9dcc 100644 --- a/extras/vom/vom/api_types.cpp +++ b/extras/vom/vom/api_types.cpp @@ -17,47 +17,15 @@ namespace VOM { -static vapi_type_ip4_address -to_api(const boost::asio::ip::address_v4& a) -{ - vapi_type_ip4_address v; - - std::copy_n(a.to_bytes().data(), 4, v.address); - - return v; -} - -static vapi_type_ip6_address -to_api(const boost::asio::ip::address_v6& a) -{ - vapi_type_ip6_address v; - - std::copy_n(a.to_bytes().data(), 16, v.address); - - return v; -} - -vapi_type_address -to_api(const ip_address_t& a) +void +to_api(const ip_address_t& a, vapi_type_address& v) { if (a.is_v4()) { - vapi_type_address v = { - .af = ADDRESS_IP4, - .un = - { - .ip4 = to_api(a.to_v4()), - }, - }; - return (v); + v.af = ADDRESS_IP4; + memcpy(v.un.ip4, a.to_v4().to_bytes().data(), 4); } else { - vapi_type_address v = { - .af = ADDRESS_IP6, - .un = - { - .ip6 = to_api(a.to_v6()), - }, - }; - return (v); + v.af = ADDRESS_IP6; + memcpy(v.un.ip6, a.to_v6().to_bytes().data(), 16); } } @@ -68,12 +36,12 @@ from_api(const vapi_type_address& v) if (ADDRESS_IP6 == v.af) { std::array a; - std::copy(v.un.ip6.address, v.un.ip6.address + 16, std::begin(a)); + std::copy(v.un.ip6, v.un.ip6 + 16, std::begin(a)); boost::asio::ip::address_v6 v6(a); addr = v6; } else { std::array a; - std::copy(v.un.ip6.address, v.un.ip6.address + 4, std::begin(a)); + std::copy(v.un.ip6, v.un.ip6 + 4, std::begin(a)); boost::asio::ip::address_v4 v4(a); addr = v4; } @@ -103,14 +71,11 @@ from_api(const vapi_type_prefix& v) return route::prefix_t(from_api(v.address), v.address_length); } -vapi_type_prefix -to_api(const route::prefix_t& p) +void +to_api(const route::prefix_t& p, vapi_type_prefix& v) { - vapi_type_prefix v = { - .address = to_api(p.address()), .address_length = p.mask_width(), - }; - - return v; + to_api(p.address(), v.address); + v.address_length = p.mask_width(); } }; diff --git a/extras/vom/vom/api_types.hpp b/extras/vom/vom/api_types.hpp index b555fc3c752..96e2c47f558 100644 --- a/extras/vom/vom/api_types.hpp +++ b/extras/vom/vom/api_types.hpp @@ -23,7 +23,7 @@ namespace VOM { typedef boost::asio::ip::address ip_address_t; -vapi_type_address to_api(const ip_address_t& a); +void to_api(const ip_address_t& a, vapi_type_address& v); ip_address_t from_api(const vapi_type_address& v); diff --git a/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp b/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp index 4e5dfb0f2f4..da5c547bb3b 100644 --- a/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp +++ b/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp @@ -46,7 +46,7 @@ create_cmd::issue(connection& con) payload.bd_id = m_bd; payload.is_add = 1; payload.mac = to_api(m_mac); - payload.ip = to_api(m_ip_addr); + to_api(m_ip_addr, payload.ip); VAPI_CALL(req.execute()); @@ -91,7 +91,7 @@ delete_cmd::issue(connection& con) payload.bd_id = m_bd; payload.is_add = 0; payload.mac = to_api(m_mac); - payload.ip = to_api(m_ip_addr); + to_api(m_ip_addr, payload.ip); VAPI_CALL(req.execute()); diff --git a/extras/vom/vom/gbp_contract_cmds.cpp b/extras/vom/vom/gbp_contract_cmds.cpp index db49f9751f1..1a3975b832a 100644 --- a/extras/vom/vom/gbp_contract_cmds.cpp +++ b/extras/vom/vom/gbp_contract_cmds.cpp @@ -77,7 +77,7 @@ create_cmd::issue(connection& con) payload.contract.rules[ii].nh_set.n_nhs = nh_size; while (jj < nh_size) { - payload.contract.rules[ii].nh_set.nhs[jj].ip = to_api(nh_it->getIp()); + to_api(nh_it->getIp(), payload.contract.rules[ii].nh_set.nhs[jj].ip); payload.contract.rules[ii].nh_set.nhs[jj].mac = to_api(nh_it->getMac()); payload.contract.rules[ii].nh_set.nhs[jj].bd_id = nh_it->getBdId(); payload.contract.rules[ii].nh_set.nhs[jj].rd_id = nh_it->getRdId(); diff --git a/extras/vom/vom/gbp_endpoint_cmds.cpp b/extras/vom/vom/gbp_endpoint_cmds.cpp index 8d44c91ec61..b15b941b125 100644 --- a/extras/vom/vom/gbp_endpoint_cmds.cpp +++ b/extras/vom/vom/gbp_endpoint_cmds.cpp @@ -54,7 +54,7 @@ create_cmd::issue(connection& con) payload.endpoint.n_ips = m_ip_addrs.size(); for (n = 0; n < payload.endpoint.n_ips; n++) { - payload.endpoint.ips[n] = to_api(m_ip_addrs[n]); + to_api(m_ip_addrs[n], payload.endpoint.ips[n]); } payload.endpoint.mac = to_api(m_mac); diff --git a/extras/vom/vom/ip_punt_redirect_cmds.cpp b/extras/vom/vom/ip_punt_redirect_cmds.cpp index 135ef6a4e64..419e3f17fba 100644 --- a/extras/vom/vom/ip_punt_redirect_cmds.cpp +++ b/extras/vom/vom/ip_punt_redirect_cmds.cpp @@ -47,7 +47,7 @@ config_cmd::issue(connection& con) payload.is_add = 1; payload.punt.rx_sw_if_index = m_rx_itf.value(); payload.punt.tx_sw_if_index = m_tx_itf.value(); - payload.punt.nh = to_api(m_addr); + to_api(m_addr, payload.punt.nh); VAPI_CALL(req.execute()); @@ -93,7 +93,7 @@ unconfig_cmd::issue(connection& con) payload.is_add = 0; payload.punt.rx_sw_if_index = m_rx_itf.value(); payload.punt.tx_sw_if_index = m_tx_itf.value(); - payload.punt.nh = to_api(m_addr); + to_api(m_addr, payload.punt.nh); VAPI_CALL(req.execute()); -- cgit 1.2.3-korg