From 63509dd54c3290750961899125d588ea5f339023 Mon Sep 17 00:00:00 2001 From: Ravi Teja Date: Tue, 17 Oct 2023 10:59:33 -0500 Subject: Fix SNMP invalid Destination error This commit handles invalid SNMP destination error Tested by: Configure SNMP with invalid destination IP address '{"Destination": "snmp://10.6.6.256:162", "SubscriptionType": "SNMPTrap", "Protocol": "SNMPv2c"}' Change-Id: I88f81a79a6665a7adc654e138b4f07ce321898a4 Signed-off-by: Ravi Teja --- redfish-core/include/snmp_trap_event_clients.hpp | 38 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'redfish-core') diff --git a/redfish-core/include/snmp_trap_event_clients.hpp b/redfish-core/include/snmp_trap_event_clients.hpp index 5660fbc50c..6cc96a62b5 100644 --- a/redfish-core/include/snmp_trap_event_clients.hpp +++ b/redfish-core/include/snmp_trap_event_clients.hpp @@ -129,24 +129,35 @@ inline void "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); } -inline void - afterSnmpClientCreate(const std::shared_ptr& asyncResp, - const boost::system::error_code& ec, - const std::string& dbusSNMPid) +inline void afterSnmpClientCreate( + const std::shared_ptr& asyncResp, + const boost::system::error_code& ec, const sdbusplus::message_t& msg, + const std::string& host, const std::string& dbusSNMPid) { if (ec) { - if (ec.value() != EBADR) + const sd_bus_error* dbusError = msg.get_error(); + if (dbusError != nullptr) { - // SNMP not installed - messages::propertyValueOutOfRange(asyncResp->res, "SNMPv2c", - "Protocol"); - return; + if (std::string_view( + "xyz.openbmc_project.Common.Error.InvalidArgument") == + dbusError->name) + { + messages::propertyValueIncorrect(asyncResp->res, "Destination", + host); + return; + } + if (ec.value() != EBADR) + { + // SNMP not installed + messages::propertyValueOutOfRange(asyncResp->res, "SNMPv2c", + "Protocol"); + return; + } } messages::internalError(asyncResp->res); return; } - sdbusplus::message::object_path path(dbusSNMPid); const std::string snmpId = path.filename(); if (snmpId.empty()) @@ -168,9 +179,10 @@ inline void const std::string& host, uint16_t snmpTrapPort) { crow::connections::systemBus->async_method_call( - [asyncResp](const boost::system::error_code& ec, - const std::string& dbusSNMPid) { - afterSnmpClientCreate(asyncResp, ec, dbusSNMPid); + [asyncResp, host](const boost::system::error_code& ec, + const sdbusplus::message_t& msg, + const std::string& dbusSNMPid) { + afterSnmpClientCreate(asyncResp, ec, msg, host, dbusSNMPid); }, "xyz.openbmc_project.Network.SNMP", "/xyz/openbmc_project/network/snmp/manager", -- cgit v1.2.3