diff options
author | William A. Kennington III <wak@google.com> | 2019-04-06 18:19:38 -0700 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2019-09-27 17:18:29 +0000 |
commit | c514d874e4ce3ed1f747cfcb4bab5990393c55e8 (patch) | |
tree | 3f53b6aee184df63fed0e12be530fb0ab1e7184d /libipmid/utils.cpp | |
parent | e7023926675030a5976dffda0825445ca0b5ef84 (diff) | |
download | phosphor-host-ipmid-c514d874e4ce3ed1f747cfcb4bab5990393c55e8.tar.gz phosphor-host-ipmid-c514d874e4ce3ed1f747cfcb4bab5990393c55e8.zip |
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 <wak@google.com>
Diffstat (limited to 'libipmid/utils.cpp')
-rw-r--r-- | libipmid/utils.cpp | 148 |
1 files changed, 0 insertions, 148 deletions
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<level::ERR>("No Object has implemented the IP interface", - entry("INTERFACE=%s", interface.c_str())); - elog<InternalFailure>(); - } - - 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<std::string>(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<level::ERR>("Failed to execute method", entry("METHOD=%s", "IP"), - entry("PATH=%s", objPath.c_str())); - elog<InternalFailure>(); - } -} - -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<level::ERR>("Failed to execute method", entry("METHOD=%s", "VLAN"), - entry("PATH=%s", objPath.c_str())); - elog<InternalFailure>(); - } -} - -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<level::ERR>("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<level::ERR>("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<level::ERR>("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<uint8_t> writeData, std::vector<uint8_t>& readBuf) |