IPv6 gateway support
This implements the dbus interface plumbing needed to properly get and
set the defaultGateway6 property.
Tested:
Made sure manual changes to the default route were discovered.
Changed the route via the dbus interface and saw it write the
correct entry to the .network file. Ensured that restarting the
daemon and the BMC preserved the defaultGateway6 field.
Change-Id: Ida6a168e0df0a42b4e0d3f6d569ec2fe1f9adaab
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 4825e5b..5416f74 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -573,6 +573,11 @@
{
stream << "Gateway=" << gateway << "\n";
}
+ const auto& gateway6 = manager.getSystemConf()->defaultGateway6();
+ if (!gateway6.empty())
+ {
+ stream << "Gateway=" << gateway6 << "\n";
+ }
}
// write the route section
diff --git a/routing_table.cpp b/routing_table.cpp
index 6aa237a..4391668 100644
--- a/routing_table.cpp
+++ b/routing_table.cpp
@@ -155,6 +155,10 @@
{
defaultGateway = gatewayStr;
}
+ else if (rtMsg->rtm_family == AF_INET6)
+ {
+ defaultGateway6 = gatewayStr;
+ }
}
Entry route(dstStr, gatewayStr, ifName);
diff --git a/routing_table.hpp b/routing_table.hpp
index 10198d8..4943a4a 100644
--- a/routing_table.hpp
+++ b/routing_table.hpp
@@ -60,9 +60,9 @@
Map getRoutes();
/**
- * @brief gets the default gateway.
+ * @brief gets the default v4 gateway.
*
- * @returns the default gateway.
+ * @returns the default v4 gateway.
*/
std::string getDefaultGateway() const
{
@@ -70,6 +70,16 @@
};
/**
+ * @brief gets the default v6 gateway.
+ *
+ * @returns the default v6 gateway.
+ */
+ std::string getDefaultGateway6() const
+ {
+ return defaultGateway6;
+ };
+
+ /**
* @brief get the gateway for the network.
* @param[in] addressFamily - ip address family(AF_INET/AF_INET6)
* @param[in] ipaddress - ip address.
@@ -94,8 +104,9 @@
*/
void parseRoutes(const struct nlmsghdr* nlHdr);
- std::string defaultGateway; // default gateway
- Map routeList; // List of routes
+ std::string defaultGateway; // default gateway
+ std::string defaultGateway6; // default gateway
+ Map routeList; // List of routes
};
} // namespace route
diff --git a/system_configuration.cpp b/system_configuration.cpp
index 603fa15..4c5700e 100644
--- a/system_configuration.cpp
+++ b/system_configuration.cpp
@@ -40,6 +40,7 @@
SystemConfigIntf::hostName(name);
SystemConfigIntf::defaultGateway(routingTable.getDefaultGateway());
+ SystemConfigIntf::defaultGateway6(routingTable.getDefaultGateway6());
this->emit_object_added();
}
@@ -98,7 +99,7 @@
if (!isValidIP(AF_INET, gateway))
{
- log<level::ERR>("Not a valid Gateway",
+ log<level::ERR>("Not a valid v4 Gateway",
entry("GATEWAY=%s", gateway.c_str()));
elog<InvalidArgument>(
InvalidArgumentMetadata::ARGUMENT_NAME("GATEWAY"),
@@ -109,5 +110,26 @@
return gw;
}
+std::string SystemConfiguration::defaultGateway6(std::string gateway)
+{
+ auto gw = SystemConfigIntf::defaultGateway6();
+ if (gw == gateway)
+ {
+ return gw;
+ }
+
+ if (!isValidIP(AF_INET6, gateway))
+ {
+ log<level::ERR>("Not a valid v6 Gateway",
+ entry("GATEWAY=%s", gateway.c_str()));
+ elog<InvalidArgument>(
+ InvalidArgumentMetadata::ARGUMENT_NAME("GATEWAY"),
+ InvalidArgumentMetadata::ARGUMENT_VALUE(gateway.c_str()));
+ }
+ gw = SystemConfigIntf::defaultGateway6(gateway);
+ manager.writeToConfigurationFile();
+ return gw;
+}
+
} // namespace network
} // namespace phosphor
diff --git a/system_configuration.hpp b/system_configuration.hpp
index 9e76dca..a29309c 100644
--- a/system_configuration.hpp
+++ b/system_configuration.hpp
@@ -45,13 +45,20 @@
*/
std::string hostName(std::string name) override;
- /** @brief set the default gateway of the system.
- * @param[in] gateway - default gateway of the system.
+ /** @brief set the default v4 gateway of the system.
+ * @param[in] gateway - default v4 gateway of the system.
*/
std::string defaultGateway(std::string gateway) override;
using SystemConfigIntf::defaultGateway;
+ /** @brief set the default v6 gateway of the system.
+ * @param[in] gateway - default v6 gateway of the system.
+ */
+ std::string defaultGateway6(std::string gateway) override;
+
+ using SystemConfigIntf::defaultGateway6;
+
private:
/** @brief get the hostname from the system by doing
* dbus call to hostnamed service.