summaryrefslogtreecommitdiff
path: root/redfish-core/lib/network_protocol.hpp
diff options
context:
space:
mode:
authorAppaRao Puli <apparao.puli@linux.intel.com>2019-11-05 14:36:20 +0300
committerAppaRao Puli <apparao.puli@linux.intel.com>2019-11-07 22:05:03 +0300
commitec4974dd6a419b7f5556d4dcf4b8b836b5efbbd9 (patch)
treef5661f2b49459c52e46d2b049af673dedf4b7ee8 /redfish-core/lib/network_protocol.hpp
parent0c838cf6c0765ee793d3942faf35562806df946b (diff)
downloadbmcweb-ec4974dd6a419b7f5556d4dcf4b8b836b5efbbd9.tar.xz
Update NetworkProtocol services
Updated the NetworkProtocol GET method code to lookup the service names and socket paths directly fetched from System control ListenSockets. Tested: - Performed GET on NetworkProtocol URI and validated all responses. - Stopped services(ssh) and validated Enabled status. - Successfully ran Redfish validator without any issues. URI: /redfish/v1/Managers/bmc/NetworkProtocol Response: ............ "IPMI": { "Port": 623, "ProtocolEnabled": true }, "HTTPS": { ..... "Port": 443, "ProtocolEnabled": true }, "SSH": { "Port": 22, "ProtocolEnabled": true }, .......... Change-Id: I047910d3e6430a2779b3803a0f1e836104e2bda3 Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
Diffstat (limited to 'redfish-core/lib/network_protocol.hpp')
-rw-r--r--redfish-core/lib/network_protocol.hpp78
1 files changed, 39 insertions, 39 deletions
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 0db1aa2d1b..2850683631 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -52,24 +52,10 @@ using UnitStruct =
std::string, sdbusplus::message::object_path, uint32_t,
std::string, sdbusplus::message::object_path>;
-struct ServiceConfiguration
-{
- const char* serviceName;
- const char* socketPath;
-};
-
-const static boost::container::flat_map<const char*, ServiceConfiguration>
- protocolToDBus{
- {"SSH",
- {"dropbear.socket",
- "/org/freedesktop/systemd1/unit/dropbear_2esocket"}},
- {"HTTPS",
- {"bmcweb.service",
- "/org/freedesktop/systemd1/unit/"
- "bmcweb_2esocket"}}, //"/org/freedesktop/systemd1/unit/phosphor_2dgevent_2esocket"}},
- {"IPMI",
- {"phosphor-ipmi-net.socket", "/org/freedesktop/systemd1/unit/"
- "phosphor_2dipmi_2dnet_2esocket"}}};
+const static boost::container::flat_map<const char*, std::string>
+ protocolToDBus{{"SSH", "dropbear"},
+ {"HTTPS", "bmcweb"},
+ {"IPMI", "phosphor-ipmi-net"}};
inline void
extractNTPServersAndDomainNamesData(const GetManagedObjects& dbus_data,
@@ -267,23 +253,35 @@ class NetworkProtocol : public Node
for (auto& unit : r)
{
+ /* Only traverse through <xyz>.socket units */
+ std::string unitName = std::get<NET_PROTO_UNIT_NAME>(unit);
+ if (!boost::ends_with(unitName, ".socket"))
+ {
+ continue;
+ }
+
for (auto& kv : protocolToDBus)
{
- if (kv.second.serviceName !=
- std::get<NET_PROTO_UNIT_NAME>(unit))
+ // We are interested in services, which starts with
+ // mapped service name
+ if (!boost::starts_with(unitName, kv.second))
{
continue;
}
- const char* service = kv.first;
- const char* socketPath = kv.second.socketPath;
-
- asyncResp->res.jsonValue[service]["ProtocolEnabled"] =
- (std::get<NET_PROTO_UNIT_SUB_STATE>(unit) ==
- "running") ||
- (std::get<NET_PROTO_UNIT_SUB_STATE>(unit) ==
- "listening");
+ const char* rfServiceKey = kv.first;
+ std::string socketPath =
+ std::get<NET_PROTO_UNIT_OBJ_PATH>(unit);
+ std::string unitState =
+ std::get<NET_PROTO_UNIT_SUB_STATE>(unit);
+
+ asyncResp->res
+ .jsonValue[rfServiceKey]["ProtocolEnabled"] =
+ (unitState == "running") ||
+ (unitState == "listening");
+
crow::connections::systemBus->async_method_call(
- [asyncResp, service{std::string(service)}](
+ [asyncResp,
+ rfServiceKey{std::string(rfServiceKey)}](
const boost::system::error_code ec,
const std::variant<std::vector<std::tuple<
std::string, std::string>>>& resp) {
@@ -315,27 +313,29 @@ class NetworkProtocol : public Node
}
std::string portStr =
listenStream.substr(lastColonPos + 1);
+ if (portStr.empty())
+ {
+ return;
+ }
char* endPtr = nullptr;
+ errno = 0;
// Use strtol instead of stroi to avoid
// exceptions
long port =
std::strtol(portStr.c_str(), &endPtr, 10);
- if (*endPtr != '\0' || portStr.empty())
+ if ((errno == 0) && (*endPtr == '\0'))
{
- // Invalid value
- asyncResp->res.jsonValue[service]["Port"] =
- nullptr;
- }
- else
- {
- // Everything OK
- asyncResp->res.jsonValue[service]["Port"] =
- port;
+ asyncResp->res
+ .jsonValue[rfServiceKey]["Port"] = port;
}
+ return;
},
"org.freedesktop.systemd1", socketPath,
"org.freedesktop.DBus.Properties", "Get",
"org.freedesktop.systemd1.Socket", "Listen");
+
+ // We found service, break the inner loop.
+ break;
}
}
},