From c514d874e4ce3ed1f747cfcb4bab5990393c55e8 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Sat, 6 Apr 2019 18:19:38 -0700 Subject: transporthandler: Rewrite + New Handler This rewrites the old transport handler to use the new ipmi handler registration functions. It attempts to clean up the old code, by refactoring any business logic out of the code that parses the IPMI messages. This makes the code paths easier to understand and allows for better code re-use. This also gets rid of the concept of the settings change timer. Clients expect to see their settings take effect as soon as they are set, regardless of the "Set In Progress" flag. This means we no longer need a cache for our network settings that are about to be set by the daemon, and a client can hold the BMC in "Set In Progress" while it verifies settings like other BMC implementations. Change-Id: I5406a674f087600afdfc2c0b3adeacde10986abc Signed-off-by: William A. Kennington III --- libipmid/utils.cpp | 148 ----------------------------------------------------- 1 file changed, 148 deletions(-) (limited to 'libipmid/utils.cpp') diff --git a/libipmid/utils.cpp b/libipmid/utils.cpp index cc4b763..ed493d6 100644 --- a/libipmid/utils.cpp +++ b/libipmid/utils.cpp @@ -98,43 +98,6 @@ DbusObjectInfo getDbusObject(sdbusplus::bus::bus& bus, return make_pair(found->first, std::move(found->second.begin()->first)); } -DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus, - const std::string& interface, - const std::string& serviceRoot, - const std::string& match) -{ - auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, match); - - if (objectTree.empty()) - { - log("No Object has implemented the IP interface", - entry("INTERFACE=%s", interface.c_str())); - elog(); - } - - DbusObjectInfo objectInfo; - - for (auto& object : objectTree) - { - auto variant = ipmi::getDbusProperty( - bus, object.second.begin()->first, object.first, - ipmi::network::IP_INTERFACE, "Address"); - - objectInfo = std::make_pair(object.first, object.second.begin()->first); - - // if LinkLocalIP found look for Non-LinkLocalIP - if (ipmi::network::isLinkLocalIP(std::get(variant))) - { - continue; - } - else - { - break; - } - } - return objectInfo; -} - Value getDbusProperty(sdbusplus::bus::bus& bus, const std::string& service, const std::string& objPath, const std::string& interface, const std::string& property, @@ -437,117 +400,6 @@ void callDbusMethod(sdbusplus::bus::bus& bus, const std::string& service, } } // namespace method_no_args - -namespace network -{ - -bool isLinkLocalIP(const std::string& address) -{ - return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0; -} - -void createIP(sdbusplus::bus::bus& bus, const std::string& service, - const std::string& objPath, const std::string& protocolType, - const std::string& ipaddress, uint8_t prefix) -{ - std::string gateway = ""; - - auto busMethod = bus.new_method_call(service.c_str(), objPath.c_str(), - IP_CREATE_INTERFACE, "IP"); - - busMethod.append(protocolType, ipaddress, prefix, gateway); - - auto reply = bus.call(busMethod); - - if (reply.is_method_error()) - { - log("Failed to execute method", entry("METHOD=%s", "IP"), - entry("PATH=%s", objPath.c_str())); - elog(); - } -} - -void createVLAN(sdbusplus::bus::bus& bus, const std::string& service, - const std::string& objPath, const std::string& interfaceName, - uint32_t vlanID) -{ - auto busMethod = bus.new_method_call(service.c_str(), objPath.c_str(), - VLAN_CREATE_INTERFACE, "VLAN"); - - busMethod.append(interfaceName, vlanID); - - auto reply = bus.call(busMethod); - - if (reply.is_method_error()) - { - log("Failed to execute method", entry("METHOD=%s", "VLAN"), - entry("PATH=%s", objPath.c_str())); - elog(); - } -} - -uint8_t toPrefix(int addressFamily, const std::string& subnetMask) -{ - if (addressFamily == AF_INET6) - { - return 0; - } - - uint32_t buff{}; - - auto rc = inet_pton(addressFamily, subnetMask.c_str(), &buff); - if (rc <= 0) - { - log("inet_pton failed:", - entry("SUBNETMASK=%s", subnetMask.c_str())); - return 0; - } - - buff = be32toh(buff); - // total no of bits - total no of leading zero == total no of ones - if (((sizeof(buff) * 8) - (__builtin_ctz(buff))) == - __builtin_popcount(buff)) - { - return __builtin_popcount(buff); - } - else - { - log("Invalid Mask", - entry("SUBNETMASK=%s", subnetMask.c_str())); - return 0; - } -} - -uint32_t getVLAN(const std::string& path) -{ - // Path would be look like - // /xyz/openbmc_project/network/eth0_443/ipv4 - - uint32_t vlanID = 0; - try - { - auto intfObjectPath = path.substr(0, path.find(IP_TYPE) - 1); - - auto intfName = intfObjectPath.substr(intfObjectPath.rfind("/") + 1); - - auto index = intfName.find("_"); - if (index != std::string::npos) - { - auto str = intfName.substr(index + 1); - vlanID = std::stoul(str); - } - } - catch (std::exception& e) - { - log("Exception occurred during getVLAN", - entry("PATH=%s", path.c_str()), - entry("EXCEPTION=%s", e.what())); - } - return vlanID; -} - -} // namespace network - ipmi::Cc i2cWriteRead(std::string i2cBus, const uint8_t slaveAddr, std::vector writeData, std::vector& readBuf) -- cgit v1.2.1