Patrick Venture | 690a234 | 2020-05-17 11:51:31 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 3 | #include "app/channel.hpp" |
| 4 | #include "user_channel/cipher_mgmt.hpp" |
| 5 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 6 | #include <ipmid/api-types.hpp> |
| 7 | #include <ipmid/api.hpp> |
| 8 | #include <ipmid/message.hpp> |
| 9 | #include <ipmid/message/types.hpp> |
| 10 | #include <ipmid/types.hpp> |
| 11 | #include <ipmid/utils.hpp> |
| 12 | #include <phosphor-logging/elog-errors.hpp> |
| 13 | #include <phosphor-logging/elog.hpp> |
| 14 | #include <phosphor-logging/log.hpp> |
| 15 | #include <sdbusplus/bus.hpp> |
| 16 | #include <sdbusplus/exception.hpp> |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 17 | #include <stdplus/net/addr/ether.hpp> |
| 18 | #include <stdplus/net/addr/ip.hpp> |
| 19 | #include <stdplus/str/conv.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 20 | #include <user_channel/channel_layer.hpp> |
| 21 | #include <xyz/openbmc_project/Common/error.hpp> |
| 22 | #include <xyz/openbmc_project/Network/EthernetInterface/server.hpp> |
| 23 | #include <xyz/openbmc_project/Network/IP/server.hpp> |
| 24 | #include <xyz/openbmc_project/Network/Neighbor/server.hpp> |
| 25 | |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 26 | #include <cinttypes> |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 27 | #include <functional> |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 28 | #include <optional> |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 29 | #include <string> |
| 30 | #include <string_view> |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 31 | #include <unordered_map> |
| 32 | #include <unordered_set> |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 33 | #include <utility> |
Patrick Venture | 690a234 | 2020-05-17 11:51:31 -0700 | [diff] [blame] | 34 | |
| 35 | namespace ipmi |
| 36 | { |
| 37 | namespace transport |
| 38 | { |
| 39 | |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 40 | // D-Bus Network Daemon definitions |
| 41 | constexpr auto PATH_ROOT = "/xyz/openbmc_project/network"; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 42 | constexpr auto INTF_ETHERNET = "xyz.openbmc_project.Network.EthernetInterface"; |
| 43 | constexpr auto INTF_IP = "xyz.openbmc_project.Network.IP"; |
| 44 | constexpr auto INTF_IP_CREATE = "xyz.openbmc_project.Network.IP.Create"; |
| 45 | constexpr auto INTF_MAC = "xyz.openbmc_project.Network.MACAddress"; |
| 46 | constexpr auto INTF_NEIGHBOR = "xyz.openbmc_project.Network.Neighbor"; |
| 47 | constexpr auto INTF_NEIGHBOR_CREATE_STATIC = |
| 48 | "xyz.openbmc_project.Network.Neighbor.CreateStatic"; |
| 49 | constexpr auto INTF_VLAN = "xyz.openbmc_project.Network.VLAN"; |
| 50 | constexpr auto INTF_VLAN_CREATE = "xyz.openbmc_project.Network.VLAN.Create"; |
| 51 | |
Patrick Venture | 690a234 | 2020-05-17 11:51:31 -0700 | [diff] [blame] | 52 | /** @brief IPMI LAN Parameters */ |
| 53 | enum class LanParam : uint8_t |
| 54 | { |
| 55 | SetStatus = 0, |
| 56 | AuthSupport = 1, |
| 57 | AuthEnables = 2, |
| 58 | IP = 3, |
| 59 | IPSrc = 4, |
| 60 | MAC = 5, |
| 61 | SubnetMask = 6, |
| 62 | Gateway1 = 12, |
| 63 | Gateway1MAC = 13, |
| 64 | VLANId = 20, |
| 65 | CiphersuiteSupport = 22, |
| 66 | CiphersuiteEntries = 23, |
| 67 | cipherSuitePrivilegeLevels = 24, |
| 68 | IPFamilySupport = 50, |
| 69 | IPFamilyEnables = 51, |
| 70 | IPv6Status = 55, |
| 71 | IPv6StaticAddresses = 56, |
| 72 | IPv6DynamicAddresses = 59, |
| 73 | IPv6RouterControl = 64, |
| 74 | IPv6StaticRouter1IP = 65, |
| 75 | IPv6StaticRouter1MAC = 66, |
| 76 | IPv6StaticRouter1PrefixLength = 67, |
| 77 | IPv6StaticRouter1PrefixValue = 68, |
| 78 | }; |
| 79 | |
| 80 | /** @brief IPMI IP Origin Types */ |
| 81 | enum class IPSrc : uint8_t |
| 82 | { |
| 83 | Unspecified = 0, |
| 84 | Static = 1, |
| 85 | DHCP = 2, |
| 86 | BIOS = 3, |
| 87 | BMC = 4, |
| 88 | }; |
| 89 | |
| 90 | /** @brief IPMI Set Status */ |
| 91 | enum class SetStatus : uint8_t |
| 92 | { |
| 93 | Complete = 0, |
| 94 | InProgress = 1, |
| 95 | Commit = 2, |
| 96 | }; |
| 97 | |
| 98 | /** @brief IPMI Family Suport Bits */ |
| 99 | namespace IPFamilySupportFlag |
| 100 | { |
| 101 | constexpr uint8_t IPv6Only = 0; |
| 102 | constexpr uint8_t DualStack = 1; |
| 103 | constexpr uint8_t IPv6Alerts = 2; |
| 104 | } // namespace IPFamilySupportFlag |
| 105 | |
| 106 | /** @brief IPMI IPFamily Enables Flag */ |
| 107 | enum class IPFamilyEnables : uint8_t |
| 108 | { |
| 109 | IPv4Only = 0, |
| 110 | IPv6Only = 1, |
| 111 | DualStack = 2, |
| 112 | }; |
| 113 | |
| 114 | /** @brief IPMI IPv6 Dyanmic Status Bits */ |
| 115 | namespace IPv6StatusFlag |
| 116 | { |
| 117 | constexpr uint8_t DHCP = 0; |
| 118 | constexpr uint8_t SLAAC = 1; |
| 119 | }; // namespace IPv6StatusFlag |
| 120 | |
| 121 | /** @brief IPMI IPv6 Source */ |
| 122 | enum class IPv6Source : uint8_t |
| 123 | { |
| 124 | Static = 0, |
| 125 | SLAAC = 1, |
| 126 | DHCP = 2, |
| 127 | }; |
| 128 | |
| 129 | /** @brief IPMI IPv6 Address Status */ |
| 130 | enum class IPv6AddressStatus : uint8_t |
| 131 | { |
| 132 | Active = 0, |
| 133 | Disabled = 1, |
| 134 | }; |
| 135 | |
| 136 | namespace IPv6RouterControlFlag |
| 137 | { |
| 138 | constexpr uint8_t Static = 0; |
| 139 | constexpr uint8_t Dynamic = 1; |
| 140 | }; // namespace IPv6RouterControlFlag |
| 141 | |
| 142 | // LAN Handler specific response codes |
| 143 | constexpr Cc ccParamNotSupported = 0x80; |
| 144 | constexpr Cc ccParamSetLocked = 0x81; |
| 145 | constexpr Cc ccParamReadOnly = 0x82; |
| 146 | |
| 147 | // VLANs are a 12-bit value |
| 148 | constexpr uint16_t VLAN_VALUE_MASK = 0x0fff; |
| 149 | constexpr uint16_t VLAN_ENABLE_FLAG = 0x8000; |
| 150 | |
| 151 | // Arbitrary v6 Address Limits to prevent too much output in ipmitool |
| 152 | constexpr uint8_t MAX_IPV6_STATIC_ADDRESSES = 15; |
| 153 | constexpr uint8_t MAX_IPV6_DYNAMIC_ADDRESSES = 15; |
| 154 | |
Jiaqing Zhao | 6d4a44e | 2022-01-24 15:04:00 +0800 | [diff] [blame] | 155 | // Prefix length limits of phosphor-networkd |
Jiaqing Zhao | 6d4a44e | 2022-01-24 15:04:00 +0800 | [diff] [blame] | 156 | constexpr uint8_t MIN_IPV6_PREFIX_LENGTH = 1; |
| 157 | constexpr uint8_t MAX_IPV6_PREFIX_LENGTH = 128; |
| 158 | |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 159 | /** @brief The dbus parameters for the interface corresponding to a channel |
| 160 | * This helps reduce the number of mapper lookups we need for each |
| 161 | * query and simplifies finding the VLAN interface if needed. |
| 162 | */ |
| 163 | struct ChannelParams |
| 164 | { |
| 165 | /** @brief The channel ID */ |
| 166 | int id; |
| 167 | /** @brief channel name for the interface */ |
| 168 | std::string ifname; |
| 169 | /** @brief Name of the service on the bus */ |
| 170 | std::string service; |
| 171 | /** @brief Lower level adapter path that is guaranteed to not be a VLAN */ |
| 172 | std::string ifPath; |
| 173 | /** @brief Logical adapter path used for address assignment */ |
| 174 | std::string logicalPath; |
| 175 | }; |
| 176 | |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 177 | /** @brief Determines the ethernet interface name corresponding to a channel |
| 178 | * Tries to map a VLAN object first so that the address information |
| 179 | * is accurate. Otherwise it gets the standard ethernet interface. |
| 180 | * |
| 181 | * @param[in] bus - The bus object used for lookups |
| 182 | * @param[in] channel - The channel id corresponding to an ethernet interface |
| 183 | * @return Ethernet interface service and object path if it exists |
| 184 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 185 | std::optional<ChannelParams> maybeGetChannelParams(sdbusplus::bus_t& bus, |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 186 | uint8_t channel); |
| 187 | |
| 188 | /** @brief A trivial helper around maybeGetChannelParams() that throws an |
| 189 | * exception when it is unable to acquire parameters for the channel. |
| 190 | * |
| 191 | * @param[in] bus - The bus object used for lookups |
| 192 | * @param[in] channel - The channel id corresponding to an ethernet interface |
| 193 | * @return Ethernet interface service and object path |
| 194 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 195 | ChannelParams getChannelParams(sdbusplus::bus_t& bus, uint8_t channel); |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 196 | |
| 197 | /** @brief Trivializes using parameter getter functions by providing a bus |
| 198 | * and channel parameters automatically. |
| 199 | * |
| 200 | * @param[in] channel - The channel id corresponding to an ethernet interface |
| 201 | * ... |
| 202 | */ |
| 203 | template <auto func, typename... Args> |
| 204 | auto channelCall(uint8_t channel, Args&&... args) |
| 205 | { |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 206 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 207 | auto params = getChannelParams(bus, channel); |
| 208 | return std::invoke(func, bus, params, std::forward<Args>(args)...); |
| 209 | } |
| 210 | |
| 211 | /** @brief Generic paramters for different address families */ |
| 212 | template <int family> |
| 213 | struct AddrFamily |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 214 | {}; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 215 | |
| 216 | /** @brief Parameter specialization for IPv4 */ |
| 217 | template <> |
| 218 | struct AddrFamily<AF_INET> |
| 219 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 220 | using addr = stdplus::In4Addr; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 221 | static constexpr auto protocol = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 222 | sdbusplus::server::xyz::openbmc_project::network::IP::Protocol::IPv4; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 223 | static constexpr size_t maxStrLen = INET6_ADDRSTRLEN; |
| 224 | static constexpr uint8_t defaultPrefix = 32; |
| 225 | static constexpr char propertyGateway[] = "DefaultGateway"; |
| 226 | }; |
| 227 | |
| 228 | /** @brief Parameter specialization for IPv6 */ |
| 229 | template <> |
| 230 | struct AddrFamily<AF_INET6> |
| 231 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 232 | using addr = stdplus::In6Addr; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 233 | static constexpr auto protocol = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 234 | sdbusplus::server::xyz::openbmc_project::network::IP::Protocol::IPv6; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 235 | static constexpr size_t maxStrLen = INET6_ADDRSTRLEN; |
| 236 | static constexpr uint8_t defaultPrefix = 128; |
| 237 | static constexpr char propertyGateway[] = "DefaultGateway6"; |
| 238 | }; |
| 239 | |
| 240 | /** @brief Interface Neighbor configuration parameters */ |
| 241 | template <int family> |
| 242 | struct IfNeigh |
| 243 | { |
| 244 | std::string path; |
| 245 | typename AddrFamily<family>::addr ip; |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 246 | stdplus::EtherAddr mac; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | /** @brief Interface IP Address configuration parameters */ |
| 250 | template <int family> |
| 251 | struct IfAddr |
| 252 | { |
| 253 | std::string path; |
| 254 | typename AddrFamily<family>::addr address; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 255 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin origin; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 256 | uint8_t prefix; |
| 257 | }; |
| 258 | |
| 259 | /** @brief Valid address origins for IPv6 */ |
| 260 | static inline const std::unordered_set< |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 261 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin> |
| 262 | originsV6Static = {sdbusplus::server::xyz::openbmc_project::network::IP:: |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 263 | AddressOrigin::Static}; |
| 264 | static inline const std::unordered_set< |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 265 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin> |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 266 | originsV6Dynamic = { |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 267 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin:: |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 268 | DHCP, |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 269 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin:: |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 270 | SLAAC, |
| 271 | }; |
| 272 | |
| 273 | /** @brief A lazy lookup mechanism for iterating over object properties stored |
| 274 | * in DBus. This will only perform the object lookup when needed, and |
| 275 | * retains a cache of previous lookups to speed up future iterations. |
| 276 | */ |
| 277 | class ObjectLookupCache |
| 278 | { |
| 279 | public: |
| 280 | using PropertiesCache = std::unordered_map<std::string, PropertyMap>; |
| 281 | |
| 282 | /** @brief Creates a new ObjectLookupCache for the interface on the bus |
| 283 | * NOTE: The inputs to this object must outlive the object since |
| 284 | * they are only referenced by it. |
| 285 | * |
| 286 | * @param[in] bus - The bus object used for lookups |
| 287 | * @param[in] params - The parameters for the channel |
| 288 | * @param[in] intf - The interface we are looking up |
| 289 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 290 | ObjectLookupCache(sdbusplus::bus_t& bus, const ChannelParams& params, |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 291 | const char* intf) : |
| 292 | bus(bus), |
| 293 | params(params), intf(intf), |
| 294 | objs(getAllDbusObjects(bus, params.logicalPath, intf, "")) |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 295 | {} |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 296 | |
| 297 | class iterator : public ObjectTree::const_iterator |
| 298 | { |
| 299 | public: |
| 300 | using value_type = PropertiesCache::value_type; |
| 301 | |
| 302 | iterator(ObjectTree::const_iterator it, ObjectLookupCache& container) : |
| 303 | ObjectTree::const_iterator(it), container(container), |
| 304 | ret(container.cache.end()) |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 305 | {} |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 306 | value_type& operator*() |
| 307 | { |
| 308 | ret = container.get(ObjectTree::const_iterator::operator*().first); |
| 309 | return *ret; |
| 310 | } |
| 311 | value_type* operator->() |
| 312 | { |
| 313 | return &operator*(); |
| 314 | } |
| 315 | |
| 316 | private: |
| 317 | ObjectLookupCache& container; |
| 318 | PropertiesCache::iterator ret; |
| 319 | }; |
| 320 | |
| 321 | iterator begin() noexcept |
| 322 | { |
| 323 | return iterator(objs.begin(), *this); |
| 324 | } |
| 325 | |
| 326 | iterator end() noexcept |
| 327 | { |
| 328 | return iterator(objs.end(), *this); |
| 329 | } |
| 330 | |
| 331 | private: |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 332 | sdbusplus::bus_t& bus; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 333 | const ChannelParams& params; |
| 334 | const char* const intf; |
| 335 | const ObjectTree objs; |
| 336 | PropertiesCache cache; |
| 337 | |
| 338 | /** @brief Gets a cached copy of the object properties if possible |
| 339 | * Otherwise performs a query on DBus to look them up |
| 340 | * |
| 341 | * @param[in] path - The object path to lookup |
| 342 | * @return An iterator for the specified object path + properties |
| 343 | */ |
| 344 | PropertiesCache::iterator get(const std::string& path) |
| 345 | { |
| 346 | auto it = cache.find(path); |
| 347 | if (it != cache.end()) |
| 348 | { |
| 349 | return it; |
| 350 | } |
| 351 | auto properties = getAllDbusProperties(bus, params.service, path, intf); |
| 352 | return cache.insert({path, std::move(properties)}).first; |
| 353 | } |
| 354 | }; |
| 355 | |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 356 | /** @brief Searches the ip object lookup cache for an address matching |
| 357 | * the input parameters. NOTE: The index lacks stability across address |
| 358 | * changes since the network daemon has no notion of stable indicies. |
| 359 | * |
| 360 | * @param[in] bus - The bus object used for lookups |
| 361 | * @param[in] params - The parameters for the channel |
| 362 | * @param[in] idx - The index of the desired address on the interface |
| 363 | * @param[in] origins - The allowed origins for the address objects |
| 364 | * @param[in] ips - The object lookup cache holding all of the address info |
| 365 | * @return The address and prefix if it was found |
| 366 | */ |
| 367 | template <int family> |
| 368 | std::optional<IfAddr<family>> findIfAddr( |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 369 | [[maybe_unused]] sdbusplus::bus_t& bus, |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 370 | [[maybe_unused]] const ChannelParams& params, uint8_t idx, |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 371 | const std::unordered_set< |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 372 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin>& |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 373 | origins, |
| 374 | ObjectLookupCache& ips) |
| 375 | { |
| 376 | for (const auto& [path, properties] : ips) |
| 377 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 378 | std::optional<typename AddrFamily<family>::addr> addr; |
| 379 | try |
| 380 | { |
| 381 | addr.emplace(stdplus::fromStr<typename AddrFamily<family>::addr>( |
| 382 | std::get<std::string>(properties.at("Address")))); |
| 383 | } |
| 384 | catch (...) |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 385 | { |
| 386 | continue; |
| 387 | } |
| 388 | |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 389 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin |
| 390 | origin = sdbusplus::server::xyz::openbmc_project::network::IP:: |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 391 | convertAddressOriginFromString( |
| 392 | std::get<std::string>(properties.at("Origin"))); |
| 393 | if (origins.find(origin) == origins.end()) |
| 394 | { |
| 395 | continue; |
| 396 | } |
| 397 | |
| 398 | if (idx > 0) |
| 399 | { |
| 400 | idx--; |
| 401 | continue; |
| 402 | } |
| 403 | |
| 404 | IfAddr<family> ifaddr; |
| 405 | ifaddr.path = path; |
| 406 | ifaddr.address = *addr; |
| 407 | ifaddr.prefix = std::get<uint8_t>(properties.at("PrefixLength")); |
| 408 | ifaddr.origin = origin; |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 409 | return ifaddr; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | return std::nullopt; |
| 413 | } |
| 414 | /** @brief Trivial helper around findIfAddr that simplifies calls |
| 415 | * for one off lookups. Don't use this if you intend to do multiple |
| 416 | * lookups at a time. |
| 417 | * |
| 418 | * @param[in] bus - The bus object used for lookups |
| 419 | * @param[in] params - The parameters for the channel |
| 420 | * @param[in] idx - The index of the desired address on the interface |
| 421 | * @param[in] origins - The allowed origins for the address objects |
| 422 | * @return The address and prefix if it was found |
| 423 | */ |
| 424 | template <int family> |
| 425 | auto getIfAddr( |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 426 | sdbusplus::bus_t& bus, const ChannelParams& params, uint8_t idx, |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 427 | const std::unordered_set< |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 428 | sdbusplus::server::xyz::openbmc_project::network::IP::AddressOrigin>& |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 429 | origins) |
| 430 | { |
| 431 | ObjectLookupCache ips(bus, params, INTF_IP); |
| 432 | return findIfAddr<family>(bus, params, idx, origins, ips); |
| 433 | } |
| 434 | |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 435 | /** @brief Reconfigures the IPv6 address info configured for the interface |
| 436 | * |
| 437 | * @param[in] bus - The bus object used for lookups |
| 438 | * @param[in] params - The parameters for the channel |
| 439 | * @param[in] idx - The address index to operate on |
| 440 | * @param[in] address - The new address |
| 441 | * @param[in] prefix - The new address prefix |
| 442 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 443 | void reconfigureIfAddr6(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 444 | uint8_t idx, stdplus::In6Addr address, uint8_t prefix); |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 445 | |
| 446 | /** @brief Retrieves the current gateway for the address family on the system |
Lei YU | d1bd8c4 | 2021-08-11 17:13:56 +0800 | [diff] [blame] | 447 | * NOTE: The gateway is per channel instead of the system wide one. |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 448 | * |
| 449 | * @param[in] bus - The bus object used for lookups |
| 450 | * @param[in] params - The parameters for the channel |
| 451 | * @return An address representing the gateway address if it exists |
| 452 | */ |
| 453 | template <int family> |
| 454 | std::optional<typename AddrFamily<family>::addr> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 455 | getGatewayProperty(sdbusplus::bus_t& bus, const ChannelParams& params) |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 456 | { |
Lei YU | d1bd8c4 | 2021-08-11 17:13:56 +0800 | [diff] [blame] | 457 | auto objPath = "/xyz/openbmc_project/network/" + params.ifname; |
| 458 | auto gatewayStr = std::get<std::string>( |
| 459 | getDbusProperty(bus, params.service, objPath, INTF_ETHERNET, |
| 460 | AddrFamily<family>::propertyGateway)); |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 461 | if (gatewayStr.empty()) |
| 462 | { |
| 463 | return std::nullopt; |
| 464 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 465 | return stdplus::fromStr<typename AddrFamily<family>::addr>(gatewayStr); |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | template <int family> |
| 469 | std::optional<IfNeigh<family>> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 470 | findStaticNeighbor(sdbusplus::bus_t&, const ChannelParams&, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 471 | typename AddrFamily<family>::addr ip, |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 472 | ObjectLookupCache& neighbors) |
| 473 | { |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 474 | using sdbusplus::server::xyz::openbmc_project::network::Neighbor; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 475 | const auto state = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 476 | sdbusplus::common::xyz::openbmc_project::network::convertForMessage( |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 477 | Neighbor::State::Permanent); |
| 478 | for (const auto& [path, neighbor] : neighbors) |
| 479 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 480 | std::optional<typename AddrFamily<family>::addr> neighIP; |
| 481 | try |
| 482 | { |
| 483 | neighIP.emplace(stdplus::fromStr<typename AddrFamily<family>::addr>( |
| 484 | std::get<std::string>(neighbor.at("IPAddress")))); |
| 485 | } |
| 486 | catch (...) |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 487 | { |
| 488 | continue; |
| 489 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 490 | if (*neighIP != ip) |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 491 | { |
| 492 | continue; |
| 493 | } |
| 494 | if (state != std::get<std::string>(neighbor.at("State"))) |
| 495 | { |
| 496 | continue; |
| 497 | } |
| 498 | |
| 499 | IfNeigh<family> ret; |
| 500 | ret.path = path; |
| 501 | ret.ip = ip; |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 502 | ret.mac = stdplus::fromStr<stdplus::EtherAddr>( |
| 503 | std::get<std::string>(neighbor.at("MACAddress"))); |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 504 | return ret; |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | return std::nullopt; |
| 508 | } |
| 509 | |
| 510 | template <int family> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 511 | void createNeighbor(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 512 | typename AddrFamily<family>::addr address, |
| 513 | stdplus::EtherAddr mac) |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 514 | { |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 515 | auto newreq = bus.new_method_call(params.service.c_str(), |
| 516 | params.logicalPath.c_str(), |
| 517 | INTF_NEIGHBOR_CREATE_STATIC, "Neighbor"); |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 518 | stdplus::ToStrHandle<stdplus::ToStr<stdplus::EtherAddr>> macToStr; |
| 519 | stdplus::ToStrHandle<stdplus::ToStr<typename AddrFamily<family>::addr>> |
| 520 | addrToStr; |
| 521 | newreq.append(addrToStr(address), macToStr(mac)); |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 522 | bus.call_noreply(newreq); |
| 523 | } |
| 524 | |
| 525 | /** @brief Deletes the dbus object. Ignores empty objects or objects that are |
| 526 | * missing from the bus. |
| 527 | * |
| 528 | * @param[in] bus - The bus object used for lookups |
| 529 | * @param[in] service - The name of the service |
| 530 | * @param[in] path - The path of the object to delete |
| 531 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 532 | void deleteObjectIfExists(sdbusplus::bus_t& bus, const std::string& service, |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 533 | const std::string& path); |
| 534 | |
Lei YU | d1bd8c4 | 2021-08-11 17:13:56 +0800 | [diff] [blame] | 535 | /** @brief Sets the value for the default gateway of the channel |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 536 | * |
| 537 | * @param[in] bus - The bus object used for lookups |
| 538 | * @param[in] params - The parameters for the channel |
| 539 | * @param[in] gateway - Gateway address to apply |
| 540 | */ |
| 541 | template <int family> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 542 | void setGatewayProperty(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 543 | typename AddrFamily<family>::addr address) |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 544 | { |
| 545 | // Save the old gateway MAC address if it exists so we can recreate it |
| 546 | auto gateway = getGatewayProperty<family>(bus, params); |
| 547 | std::optional<IfNeigh<family>> neighbor; |
| 548 | if (gateway) |
| 549 | { |
| 550 | ObjectLookupCache neighbors(bus, params, INTF_NEIGHBOR); |
| 551 | neighbor = findStaticNeighbor<family>(bus, params, *gateway, neighbors); |
| 552 | } |
| 553 | |
Lei YU | d1bd8c4 | 2021-08-11 17:13:56 +0800 | [diff] [blame] | 554 | auto objPath = "/xyz/openbmc_project/network/" + params.ifname; |
| 555 | setDbusProperty(bus, params.service, objPath, INTF_ETHERNET, |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 556 | AddrFamily<family>::propertyGateway, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame^] | 557 | stdplus::toStr(address)); |
John Wang | 8a7236a | 2021-01-04 15:31:44 +0800 | [diff] [blame] | 558 | |
| 559 | // Restore the gateway MAC if we had one |
| 560 | if (neighbor) |
| 561 | { |
| 562 | deleteObjectIfExists(bus, params.service, neighbor->path); |
| 563 | createNeighbor<family>(bus, params, address, neighbor->mac); |
| 564 | } |
| 565 | } |
| 566 | |
Jian Zhang | 23f4465 | 2022-03-17 17:13:10 +0800 | [diff] [blame] | 567 | /** @enum SolConfParam |
| 568 | * |
| 569 | * using for Set/Get SOL configuration parameters command. |
| 570 | */ |
| 571 | enum class SolConfParam : uint8_t |
| 572 | { |
| 573 | Progress, //!< Set In Progress. |
| 574 | Enable, //!< SOL Enable. |
| 575 | Authentication, //!< SOL Authentication. |
| 576 | Accumulate, //!< Character Accumulate Interval & Send Threshold. |
| 577 | Retry, //!< SOL Retry. |
| 578 | NonVbitrate, //!< SOL non-volatile bit rate. |
| 579 | Vbitrate, //!< SOL volatile bit rate. |
| 580 | Channel, //!< SOL payload channel. |
| 581 | Port, //!< SOL payload port. |
| 582 | }; |
| 583 | |
| 584 | constexpr uint8_t ipmiCCParamNotSupported = 0x80; |
| 585 | constexpr uint8_t ipmiCCWriteReadParameter = 0x82; |
| 586 | |
Patrick Venture | 690a234 | 2020-05-17 11:51:31 -0700 | [diff] [blame] | 587 | } // namespace transport |
| 588 | } // namespace ipmi |