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 /ethernet_interface.cpp | |
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>
Diffstat (limited to 'ethernet_interface.cpp')
-rw-r--r-- | ethernet_interface.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
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) { |