types: Add a type for interface addresses
This will be used to uniquely identify them.
Change-Id: Iabd43520ae5060e4f5dfe18e549f96f6b910b3c1
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/types.cpp b/src/types.cpp
index 55c6d10..37eb69e 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -1,8 +1,18 @@
#include "types.hpp"
+#include <fmt/format.h>
+
#include <charconv>
-namespace phosphor::network::detail
+namespace phosphor::network
+{
+
+void IfAddr::invalidPfx(uint8_t pfx)
+{
+ throw std::invalid_argument(fmt::format("Invalid prefix {}", pfx));
+}
+
+namespace detail
{
std::string_view AddrBufMaker<ether_addr>::operator()(ether_addr val) noexcept
@@ -91,7 +101,8 @@
return {buf.data(), ptr};
}
-} // namespace phosphor::network::detail
+} // namespace detail
+} // namespace phosphor::network
std::size_t std::hash<in_addr>::operator()(in_addr addr) const noexcept
{
@@ -104,6 +115,12 @@
addr.s6_addr32[2], addr.s6_addr32[3]);
}
+std::size_t std::hash<phosphor::network::IfAddr>::operator()(
+ phosphor::network::IfAddr addr) const noexcept
+{
+ return phosphor::network::hash_multi(addr.getAddr(), addr.getPfx());
+}
+
std::string std::to_string(ether_addr value)
{
return string(phosphor::network::detail::AddrBufMaker<ether_addr>{}(value));
@@ -120,3 +137,8 @@
{
return std::visit([](auto v) { return std::to_string(v); }, value);
}
+
+std::string std::to_string(phosphor::network::IfAddr value)
+{
+ return fmt::to_string(value);
+}