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/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index 21062f4..74768c1 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -96,6 +96,19 @@
TEST_F(TestEthernetInterface, AddIPAddress)
{
+ EXPECT_THROW(createIPObject(IP::Protocol::IPv4, "127.0.0.1", 16),
+ InvalidArgument);
+ EXPECT_THROW(createIPObject(IP::Protocol::IPv4, "127.0.0.1", 32),
+ InvalidArgument);
+ EXPECT_THROW(createIPObject(IP::Protocol::IPv4, "192.168.1.1", 0),
+ InvalidArgument);
+ EXPECT_THROW(createIPObject(IP::Protocol::IPv6, "::1", 64),
+ InvalidArgument);
+ EXPECT_THROW(createIPObject(IP::Protocol::IPv6, "::", 128),
+ InvalidArgument);
+ EXPECT_THROW(createIPObject(IP::Protocol::IPv6, "fe80::1", 0),
+ InvalidArgument);
+
createIPObject(IP::Protocol::IPv4, "10.10.10.10", 16);
EXPECT_THAT(interface.addrs, UnorderedElementsAre(Key(stdplus::SubnetAny(
stdplus::In4Addr{10, 10, 10, 10}, 16))));