2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vom/api_types.hpp>
20 vapi_enum_ip_neighbor_flags
21 to_api(const neighbour::flags_t& f)
23 vapi_enum_ip_neighbor_flags out = IP_API_NEIGHBOR_FLAG_NONE;
25 if (f & neighbour::flags_t::STATIC)
26 out = static_cast<vapi_enum_ip_neighbor_flags>(out |
27 IP_API_NEIGHBOR_FLAG_STATIC);
28 if (f & neighbour::flags_t::NO_FIB_ENTRY)
29 out = static_cast<vapi_enum_ip_neighbor_flags>(
30 out | IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY);
35 const neighbour::flags_t
36 from_api(vapi_enum_ip_neighbor_flags f)
38 neighbour::flags_t out = neighbour::flags_t::NONE;
40 if (f & IP_API_NEIGHBOR_FLAG_STATIC)
41 out |= neighbour::flags_t::STATIC;
42 if (f & IP_API_NEIGHBOR_FLAG_NO_FIB_ENTRY)
43 out |= neighbour::flags_t::NO_FIB_ENTRY;
49 to_api(const boost::asio::ip::address_v4& a, vapi_type_ip4_address& v)
51 std::copy_n(std::begin(a.to_bytes()), a.to_bytes().size(), v);
54 to_api(const boost::asio::ip::address_v6& a, vapi_type_ip6_address& v)
56 std::copy_n(std::begin(a.to_bytes()), a.to_bytes().size(), v);
60 to_api(const ip_address_t& a, vapi_type_address& v)
64 memcpy(v.un.ip4, a.to_v4().to_bytes().data(), 4);
67 memcpy(v.un.ip6, a.to_v6().to_bytes().data(), 16);
72 to_api(const ip_address_t& a,
73 vapi_union_address_union& u,
74 vapi_enum_address_family& af)
78 memcpy(u.ip4, a.to_v4().to_bytes().data(), 4);
81 memcpy(u.ip6, a.to_v6().to_bytes().data(), 16);
85 boost::asio::ip::address_v6
86 from_api(const vapi_type_ip6_address& v)
88 std::array<uint8_t, 16> a;
89 std::copy(v, v + 16, std::begin(a));
90 boost::asio::ip::address_v6 v6(a);
95 boost::asio::ip::address_v4
96 from_api(const vapi_type_ip4_address& v)
98 std::array<uint8_t, 4> a;
99 std::copy(v, v + 4, std::begin(a));
100 boost::asio::ip::address_v4 v4(a);
106 from_api(const vapi_type_address& v)
108 boost::asio::ip::address addr;
110 if (ADDRESS_IP6 == v.af) {
111 std::array<uint8_t, 16> a;
112 std::copy(v.un.ip6, v.un.ip6 + 16, std::begin(a));
113 boost::asio::ip::address_v6 v6(a);
116 std::array<uint8_t, 4> a;
117 std::copy(v.un.ip6, v.un.ip6 + 4, std::begin(a));
118 boost::asio::ip::address_v4 v4(a);
126 from_api(const vapi_union_address_union& u, vapi_enum_address_family af)
128 boost::asio::ip::address addr;
130 if (ADDRESS_IP6 == af) {
131 std::array<uint8_t, 16> a;
132 std::copy(u.ip6, u.ip6 + 16, std::begin(a));
133 boost::asio::ip::address_v6 v6(a);
136 std::array<uint8_t, 4> a;
137 std::copy(u.ip6, u.ip6 + 4, std::begin(a));
138 boost::asio::ip::address_v4 v4(a);
146 to_api(const mac_address_t& a, vapi_type_mac_address& v)
148 std::copy(std::begin(a.bytes), std::end(a.bytes), v);
152 from_api(const vapi_type_mac_address& v)
154 return mac_address_t(v);
158 from_api(const vapi_type_prefix& v)
160 return route::prefix_t(from_api(v.address), v.address_length);
164 to_api(const route::prefix_t& p)
167 to_api(p.address(), v.address);
168 v.address_length = p.mask_width();
173 from_api(const vapi_type_mprefix& v)
175 return route::mprefix_t(from_api(v.src_address, v.af),
176 from_api(v.grp_address, v.af), v.grp_address_length);
180 to_api(const route::mprefix_t& p)
182 vapi_enum_address_family af;
184 to_api(p.grp_address(), v.grp_address, af);
185 to_api(p.src_address(), v.src_address, af);
186 v.grp_address_length = p.mask_width();
193 * fd.io coding-style-patch-verification: ON
196 * eval: (c-set-style "mozilla")