Fix NTPServers are hard-coded for eth0
Since bmcweb is getting and patching NTPServers only from
'/xyz/openbmc_project/network/eth0' object, and this is hard-coded, if
we use eth1, it will broken the NTP configuration and fail to route to
the correct NTPServer.
All NTPServers of xyz.openbmc_project.Network.EthernetInterface
interface should be updated.
Tested:
1. When NTPServer is set through the webUI, all NTPs of the
Ethernet will be updated synchronously.
2. If eth1 is ethernet.
doPatch:
curl -k -H "X-Auth-Token: $token" -X PATCH -d '{ "NTP":{"NTPServers": ["192.168.1.2", "192.168.1.1"], "ProtocolEnabled": true}}' https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol
doGet:
curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Managers/bmc/NetworkProtocol
{
"@odata.id": "/redfish/v1/Managers/bmc/NetworkProtocol",
"@odata.type": "#ManagerNetworkProtocol.v1_5_0.ManagerNetworkProtocol",
"Description": "Manager Network Service",
"NTP": {
"NTPServers": [
"192.168.1.2",
"192.168.1.1"
],
"ProtocolEnabled": true
},
...
}
3. cat 00-bmc-eth0.network
[Match]
Name=eth0
[Link]
MACAddress=52:54:00:12:34:56
[Network]
LinkLocalAddressing=yes
IPv6AcceptRA=true
NTP=192.168.1.1
NTP=192.168.1.2
DHCP=true
[DHCP]
ClientIdentifier=mac
UseDNS=true
UseNTP=true
UseHostname=true
SendHostname=true
4. cat 00-bmc-eth1.network
[Match]
Name=eth1
[Link]
MACAddress=52:54:00:12:34:57
[Network]
LinkLocalAddressing=yes
IPv6AcceptRA=true
NTP=192.168.1.1
NTP=192.168.1.2
DHCP=true
[DHCP]
ClientIdentifier=mac
UseDNS=true
UseNTP=true
UseHostname=true
SendHostname=true
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I624afa4154464524792d072966bf1ee9db594661
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 0d93102..3a769af 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -44,33 +44,32 @@
{
for (const auto& ifacePair : obj.second)
{
- if (obj.first == "/xyz/openbmc_project/network/eth0")
+ if (ifacePair.first !=
+ "xyz.openbmc_project.Network.EthernetInterface")
{
- if (ifacePair.first ==
- "xyz.openbmc_project.Network.EthernetInterface")
+ continue;
+ }
+
+ for (const auto& propertyPair : ifacePair.second)
+ {
+ if (propertyPair.first == "NTPServers")
{
- for (const auto& propertyPair : ifacePair.second)
+ const std::vector<std::string>* ntpServers =
+ std::get_if<std::vector<std::string>>(
+ &propertyPair.second);
+ if (ntpServers != nullptr)
{
- if (propertyPair.first == "NTPServers")
- {
- const std::vector<std::string>* ntpServers =
- std::get_if<std::vector<std::string>>(
- &propertyPair.second);
- if (ntpServers != nullptr)
- {
- ntpData = *ntpServers;
- }
- }
- else if (propertyPair.first == "DomainName")
- {
- const std::vector<std::string>* domainNames =
- std::get_if<std::vector<std::string>>(
- &propertyPair.second);
- if (domainNames != nullptr)
- {
- dnData = *domainNames;
- }
- }
+ ntpData = *ntpServers;
+ }
+ }
+ else if (propertyPair.first == "DomainName")
+ {
+ const std::vector<std::string>* domainNames =
+ std::get_if<std::vector<std::string>>(
+ &propertyPair.second);
+ if (domainNames != nullptr)
+ {
+ dnData = *domainNames;
}
}
}
@@ -130,30 +129,28 @@
getNTPProtocolEnabled(asyncResp);
- // TODO Get eth0 interface data, and call the below callback for JSON
- // preparation
- getEthernetIfaceData(
- [hostName, asyncResp](const bool& success,
- const std::vector<std::string>& ntpServers,
- const std::vector<std::string>& domainNames) {
- if (!success)
+ getEthernetIfaceData([hostName, asyncResp](
+ const bool& success,
+ const std::vector<std::string>& ntpServers,
+ const std::vector<std::string>& domainNames) {
+ if (!success)
+ {
+ messages::resourceNotFound(asyncResp->res, "ManagerNetworkProtocol",
+ "NetworkProtocol");
+ return;
+ }
+ asyncResp->res.jsonValue["NTP"]["NTPServers"] = ntpServers;
+ if (hostName.empty() == false)
+ {
+ std::string fqdn = hostName;
+ if (domainNames.empty() == false)
{
- messages::resourceNotFound(asyncResp->res, "EthernetInterface",
- "eth0");
- return;
+ fqdn += ".";
+ fqdn += domainNames[0];
}
- asyncResp->res.jsonValue["NTP"]["NTPServers"] = ntpServers;
- if (hostName.empty() == false)
- {
- std::string fqdn = hostName;
- if (domainNames.empty() == false)
- {
- fqdn += ".";
- fqdn += domainNames[0];
- }
- asyncResp->res.jsonValue["FQDN"] = std::move(fqdn);
- }
- });
+ asyncResp->res.jsonValue["FQDN"] = std::move(fqdn);
+ }
+ });
Privileges effectiveUserPrivileges =
redfish::getUserPrivileges(req.userRole);
@@ -252,17 +249,51 @@
}
crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code ec) {
+ [asyncResp,
+ ntpServers](boost::system::error_code ec,
+ const crow::openbmc_mapper::GetSubTreeType& subtree) {
if (ec)
{
+ BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", "
+ << ec.message();
messages::internalError(asyncResp->res);
return;
}
+
+ for (const auto& [objectPath, serviceMap] : subtree)
+ {
+ for (const auto& [service, interfaces] : serviceMap)
+ {
+ for (const auto& interface : interfaces)
+ {
+ if (interface !=
+ "xyz.openbmc_project.Network.EthernetInterface")
+ {
+ continue;
+ }
+
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ },
+ service, objectPath,
+ "org.freedesktop.DBus.Properties", "Set", interface,
+ "NTPServers",
+ std::variant<std::vector<std::string>>{ntpServers});
+ }
+ }
+ }
},
- "xyz.openbmc_project.Network", "/xyz/openbmc_project/network/eth0",
- "org.freedesktop.DBus.Properties", "Set",
- "xyz.openbmc_project.Network.EthernetInterface", "NTPServers",
- std::variant<std::vector<std::string>>{ntpServers});
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project", 0,
+ std::array<const char*, 1>{
+ "xyz.openbmc_project.Network.EthernetInterface"});
}
inline void