ethernet_interface: Validate IP addresses
We don't want multicast or link local addresses to be assignable as IPs.
Right now they won't do what the user expects and it causes undefined
problems with the configuration.
Change-Id: Idefac159b7ce8b53988ddb4501a1c9321b2e6588
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 3374c6f..a577c2a 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -237,6 +237,10 @@
default:
throw std::logic_error("Exhausted protocols");
}
+ if (!std::visit([](auto ip) { return validIntfIP(ip); }, *addr))
+ {
+ throw std::invalid_argument("not unicast");
+ }
}
catch (const std::exception& e)
{
@@ -248,6 +252,10 @@
std::optional<stdplus::SubnetAny> ifaddr;
try
{
+ if (prefixLength == 0)
+ {
+ throw std::invalid_argument("default route");
+ }
ifaddr.emplace(*addr, prefixLength);
}
catch (const std::exception& e)