diff options
| author | William A. Kennington III <wak@google.com> | 2019-02-01 21:12:02 -0800 |
|---|---|---|
| committer | William A. Kennington III <wak@google.com> | 2019-02-21 12:34:29 -0800 |
| commit | d3c249ce77b4973d5809a0e1dc0ec3fffb3da222 (patch) | |
| tree | 0da5ee55f937e643c8c2a42ac305cf6136f57984 | |
| parent | 00506d82189984ad4dc01c7c6b096a1c6281699d (diff) | |
| download | phosphor-networkd-d3c249ce77b4973d5809a0e1dc0ec3fffb3da222.tar.gz phosphor-networkd-d3c249ce77b4973d5809a0e1dc0ec3fffb3da222.zip | |
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>
| -rw-r--r-- | ethernet_interface.cpp | 5 | ||||
| -rw-r--r-- | routing_table.cpp | 4 | ||||
| -rw-r--r-- | routing_table.hpp | 19 | ||||
| -rw-r--r-- | system_configuration.cpp | 24 | ||||
| -rw-r--r-- | system_configuration.hpp | 11 |
5 files changed, 56 insertions, 7 deletions
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 @@ void EthernetInterface::writeConfigurationFile() { 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 @@ void Table::parseRoutes(const nlmsghdr* nlHdr) { 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 @@ class Table 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 @@ class Table }; /** + * @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 @@ class Table */ 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 @@ SystemConfiguration::SystemConfiguration(sdbusplus::bus::bus& bus, SystemConfigIntf::hostName(name); SystemConfigIntf::defaultGateway(routingTable.getDefaultGateway()); + SystemConfigIntf::defaultGateway6(routingTable.getDefaultGateway6()); this->emit_object_added(); } @@ -98,7 +99,7 @@ std::string SystemConfiguration::defaultGateway(std::string gateway) 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 @@ std::string SystemConfiguration::defaultGateway(std::string gateway) 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 @@ class SystemConfiguration : public Iface */ 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. |

