diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-08-22 19:15:59 +0530 |
---|---|---|
committer | Ratan Gupta <ratagupt@in.ibm.com> | 2017-10-11 18:17:17 +0530 |
commit | 497c0c9f28b33b48a485a0ab319896ac758994d4 (patch) | |
tree | eca51529ecf6a24b62ca71506460313b34b754ac | |
parent | 16f12886cc31a81e48ef9ed8cdcef4a1599bdeac (diff) | |
download | phosphor-networkd-497c0c9f28b33b48a485a0ab319896ac758994d4.tar.gz phosphor-networkd-497c0c9f28b33b48a485a0ab319896ac758994d4.zip |
Implement configuration of NTP server support
Change-Id: I8d471dbc6ea7ec62cbcc157565a7b39cd5031caa
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
-rw-r--r-- | dhcp_configuration.hpp | 3 | ||||
-rw-r--r-- | ethernet_interface.cpp | 39 | ||||
-rw-r--r-- | ethernet_interface.hpp | 12 | ||||
-rw-r--r-- | util.hpp | 3 |
4 files changed, 53 insertions, 4 deletions
diff --git a/dhcp_configuration.hpp b/dhcp_configuration.hpp index f486f22..e952073 100644 --- a/dhcp_configuration.hpp +++ b/dhcp_configuration.hpp @@ -11,9 +11,6 @@ namespace phosphor namespace network { -constexpr auto networkdService = "systemd-networkd.service"; -constexpr auto timeSynchdService = "systemd-timesyncd.service"; - class Manager; // forward declaration of network manager. namespace dhcp diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp index c3bac59..ffaac74 100644 --- a/ethernet_interface.cpp +++ b/ethernet_interface.cpp @@ -1,4 +1,5 @@ #include "config.h" +#include "config_parser.hpp" #include "ethernet_interface.hpp" #include "ipaddress.hpp" #include "network_manager.hpp" @@ -48,7 +49,7 @@ EthernetInterface::EthernetInterface(sdbusplus::bus::bus& bus, interfaceName(intfName); EthernetInterfaceIntf::dHCPEnabled(dhcpEnabled); MacAddressIntf::mACAddress(getMACAddress(intfName)); - + EthernetInterfaceIntf::nTPServers(getNTPServersFromConf()); // Emit deferred signal. if (emitSignal) { @@ -381,6 +382,36 @@ void EthernetInterface::createVLAN(VlanId id) manager.writeToConfigurationFile(); } +ServerList EthernetInterface::getNTPServersFromConf() +{ + fs::path confPath = manager.getConfDir(); + + std::string fileName = systemd::config::networkFilePrefix + interfaceName() + + systemd::config::networkFileSuffix; + confPath /= fileName; + ServerList servers; + try + { + config::Parser parser(confPath.string()); + servers = parser.getValues("Network", "NTP"); + } + catch (InternalFailure& e) + { + log<level::INFO>("Unable to find the NTP server configuration."); + } + return servers; +} + +ServerList EthernetInterface::nTPServers(ServerList servers) +{ + auto ntpServers = EthernetInterfaceIntf::nTPServers(servers); + + writeConfigurationFile(); + // timesynchd reads the NTP server configuration from the + // network file. + restartSystemdUnit(timeSynchdService); + return ntpServers; +} // Need to merge the below function with the code which writes the // config file during factory reset. // TODO openbmc/openbmc#1751 @@ -443,6 +474,12 @@ void EthernetInterface::writeConfigurationFile() return; } + //Add the NTP server + for(const auto& ntp: EthernetInterfaceIntf::nTPServers()) + { + stream << "NTP=" << ntp << "\n"; + } + // Static for (const auto& addr : addrs) { diff --git a/ethernet_interface.hpp b/ethernet_interface.hpp index 06a2e5f..8ef1795 100644 --- a/ethernet_interface.hpp +++ b/ethernet_interface.hpp @@ -32,6 +32,8 @@ using EthernetInterfaceIntf = using MacAddressIntf = sdbusplus::xyz::openbmc_project::Network::server::MACAddress; +using ServerList = std::vector<std::string>; + namespace fs = std::experimental::filesystem; class Manager; // forward declaration of network manager. @@ -123,6 +125,11 @@ class EthernetInterface : public Ifaces */ std::string mACAddress(std::string value) override; + /** @brief sets the NTP servers. + * @param[in] value - vector of NTP servers. + */ + ServerList nTPServers(ServerList value) override; + /** @brief create Vlan interface. * @param[in] id- VLAN identifier. */ @@ -193,6 +200,11 @@ class EthernetInterface : public Ifaces /** @brief write the dhcp section **/ void writeDHCPSection(std::fstream& stream);; + /** @brief get the NTP server list from the network conf + * + */ + ServerList getNTPServersFromConf(); + /** @brief Persistent sdbusplus DBus bus connection. */ sdbusplus::bus::bus& bus; @@ -60,6 +60,9 @@ inline uint64_t convertToInt(const std::string& value) }//namespace internal }//namespace mac_address +constexpr auto networkdService = "systemd-networkd.service"; +constexpr auto timeSynchdService = "systemd-timesyncd.service"; + /* @brief converts the given subnet into prefix notation. * @param[in] addressFamily - IP address family(AF_INET/AF_INET6). * @param[in] mask - Subnet Mask. |