Allow unset default gateway
Default gateway addresses cannot be unset in current implementation as
it requires a valid IP address and writes it to systemd.network files
every time. This patch supports setting empty string on DefaultGateway
and DefaultGateway6 DBus properties to unset the value as empty strings
will not be written to config file.
Tested:
Disable DHCP and set default gateway for both IPv4 and IPv6, then set
empty string on DefaultGateway and/or DefaultGateway6, verified the
corresponding [Route] section is removed in config file.
Change-Id: I3be81f9c7c605b12cb225beeefec02f9841b0dcd
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index a7e7302..913b6e1 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -217,6 +217,8 @@
std::string gateway = "10.3.3.3";
interface.defaultGateway(gateway);
EXPECT_EQ(interface.defaultGateway(), gateway);
+ interface.defaultGateway("");
+ EXPECT_EQ(interface.defaultGateway(), "");
}
TEST_F(TestEthernetInterface, addGateway6)
@@ -224,6 +226,8 @@
std::string gateway6 = "ffff:ffff:ffff:fe80::1";
interface.defaultGateway6(gateway6);
EXPECT_EQ(interface.defaultGateway6(), gateway6);
+ interface.defaultGateway6("");
+ EXPECT_EQ(interface.defaultGateway6(), "");
}
} // namespace network