Filter static ntp servers from ntpservers
EthernetInterface::ntpServers contains both static and dynamic
ntpservers. EthernetInterface::ntpServers is returned as network
provided ntp servers in redfish response.
In bmcweb,
NTPServers = ntpServers = StaticNTPServers of networkd
NetworkSuppliedServers = dynamicNtpServers = NTPServers of networkd
This commit filter out static ntp servers from the ntpServers to have it
contain only network provided ntp servers.
Tested by:
1. Enable DHCP to fetch NTP servers list from the DHCP server. Do a
GET on NetworkProtocol and verify the NetworkSuppliedServers contains
NTP servers from DHCP only.
2. Verified it has not altered the behavior of static NTPServers list
"Id": "NetworkProtocol",
"NTP": {
"NTPServers": [<Static NTP Servers>],
"NetworkSuppliedServers": [<NTP servers from DHCP>],
"ProtocolEnabled": false
},
Change-Id: I0cf186cae9159bd56a3166d5921d32d51216cf47
Signed-off-by: Jishnu CM <jishnunambiarcm@duck.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index ae539b9..46967f5 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -560,9 +560,22 @@
void EthernetInterface::loadNTPServers(const config::Parser& config)
{
- EthernetInterfaceIntf::ntpServers(getNTPServerFromTimeSyncd());
- EthernetInterfaceIntf::staticNTPServers(
- config.map.getValueStrings("Network", "NTP"));
+ ServerList ntpServerList = getNTPServerFromTimeSyncd();
+ ServerList staticNTPServers = config.map.getValueStrings("Network", "NTP");
+
+ std::unordered_set<std::string> staticNTPServersSet(
+ staticNTPServers.begin(), staticNTPServers.end());
+ ServerList networkSuppliedServers;
+
+ std::copy_if(ntpServerList.begin(), ntpServerList.end(),
+ std::back_inserter(networkSuppliedServers),
+ [&staticNTPServersSet](const std::string& server) {
+ return staticNTPServersSet.find(server) ==
+ staticNTPServersSet.end();
+ });
+
+ EthernetInterfaceIntf::ntpServers(networkSuppliedServers);
+ EthernetInterfaceIntf::staticNTPServers(staticNTPServers);
}
void EthernetInterface::loadNameServers(const config::Parser& config)