Patrick Venture | 690a234 | 2020-05-17 11:51:31 -0700 | [diff] [blame] | 1 | #include "transporthandler.hpp" |
| 2 | |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 3 | #include <stdplus/net/addr/subnet.hpp> |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 4 | #include <stdplus/raw.hpp> |
| 5 | |
| 6 | #include <array> |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 7 | #include <fstream> |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 8 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 9 | using phosphor::logging::commit; |
| 10 | using phosphor::logging::elog; |
| 11 | using phosphor::logging::entry; |
| 12 | using phosphor::logging::level; |
| 13 | using phosphor::logging::log; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 14 | using sdbusplus::error::xyz::openbmc_project::common::InternalFailure; |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 15 | using sdbusplus::error::xyz::openbmc_project::common::InvalidArgument; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 16 | using sdbusplus::server::xyz::openbmc_project::network::EthernetInterface; |
| 17 | using sdbusplus::server::xyz::openbmc_project::network::IP; |
| 18 | using sdbusplus::server::xyz::openbmc_project::network::Neighbor; |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 19 | |
Johnathan Mantey | affadb5 | 2019-10-07 10:13:53 -0700 | [diff] [blame] | 20 | namespace cipher |
| 21 | { |
| 22 | |
| 23 | std::vector<uint8_t> getCipherList() |
| 24 | { |
| 25 | std::vector<uint8_t> cipherList; |
| 26 | |
| 27 | std::ifstream jsonFile(cipher::configFile); |
| 28 | if (!jsonFile.is_open()) |
| 29 | { |
| 30 | log<level::ERR>("Channel Cipher suites file not found"); |
| 31 | elog<InternalFailure>(); |
| 32 | } |
| 33 | |
| 34 | auto data = Json::parse(jsonFile, nullptr, false); |
| 35 | if (data.is_discarded()) |
| 36 | { |
| 37 | log<level::ERR>("Parsing channel cipher suites JSON failed"); |
| 38 | elog<InternalFailure>(); |
| 39 | } |
| 40 | |
| 41 | // Byte 1 is reserved |
| 42 | cipherList.push_back(0x00); |
| 43 | |
| 44 | for (const auto& record : data) |
| 45 | { |
| 46 | cipherList.push_back(record.value(cipher, 0)); |
| 47 | } |
| 48 | |
| 49 | return cipherList; |
| 50 | } |
| 51 | } // namespace cipher |
| 52 | |
| 53 | namespace ipmi |
| 54 | { |
| 55 | namespace transport |
| 56 | { |
| 57 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 58 | /** @brief Valid address origins for IPv4 */ |
| 59 | const std::unordered_set<IP::AddressOrigin> originsV4 = { |
| 60 | IP::AddressOrigin::Static, |
| 61 | IP::AddressOrigin::DHCP, |
| 62 | }; |
| 63 | |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 64 | static constexpr uint8_t oemCmdStart = 192; |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 65 | |
William A. Kennington III | c72f360 | 2023-10-19 03:51:37 -0700 | [diff] [blame] | 66 | // Checks if the ifname is part of the networkd path |
| 67 | // This assumes the path came from the network subtree PATH_ROOT |
| 68 | bool ifnameInPath(std::string_view ifname, std::string_view path) |
| 69 | { |
| 70 | constexpr auto rs = PATH_ROOT.size() + 1; // ROOT + separator |
| 71 | const auto is = rs + ifname.size(); // ROOT + sep + ifname |
| 72 | return path.size() > rs && path.substr(rs).starts_with(ifname) && |
| 73 | (path.size() == is || path[is] == '/'); |
| 74 | } |
| 75 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 76 | std::optional<ChannelParams> maybeGetChannelParams(sdbusplus::bus_t& bus, |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 77 | uint8_t channel) |
| 78 | { |
| 79 | auto ifname = getChannelName(channel); |
| 80 | if (ifname.empty()) |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 81 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 82 | return std::nullopt; |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 83 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 84 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 85 | // Enumerate all VLAN + ETHERNET interfaces |
| 86 | auto req = bus.new_method_call(MAPPER_BUS_NAME, MAPPER_OBJ, MAPPER_INTF, |
| 87 | "GetSubTree"); |
William A. Kennington III | c72f360 | 2023-10-19 03:51:37 -0700 | [diff] [blame] | 88 | req.append(std::string_view(PATH_ROOT), 0, |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 89 | std::vector<std::string>{INTF_VLAN, INTF_ETHERNET}); |
| 90 | auto reply = bus.call(req); |
| 91 | ObjectTree objs; |
| 92 | reply.read(objs); |
| 93 | |
| 94 | ChannelParams params; |
| 95 | for (const auto& [path, impls] : objs) |
| 96 | { |
William A. Kennington III | c72f360 | 2023-10-19 03:51:37 -0700 | [diff] [blame] | 97 | if (!ifnameInPath(ifname, path)) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 98 | { |
| 99 | continue; |
| 100 | } |
| 101 | for (const auto& [service, intfs] : impls) |
| 102 | { |
| 103 | bool vlan = false; |
| 104 | bool ethernet = false; |
| 105 | for (const auto& intf : intfs) |
| 106 | { |
| 107 | if (intf == INTF_VLAN) |
| 108 | { |
| 109 | vlan = true; |
| 110 | } |
| 111 | else if (intf == INTF_ETHERNET) |
| 112 | { |
| 113 | ethernet = true; |
| 114 | } |
| 115 | } |
| 116 | if (params.service.empty() && (vlan || ethernet)) |
| 117 | { |
| 118 | params.service = service; |
| 119 | } |
| 120 | if (params.ifPath.empty() && !vlan && ethernet) |
| 121 | { |
| 122 | params.ifPath = path; |
| 123 | } |
| 124 | if (params.logicalPath.empty() && vlan) |
| 125 | { |
| 126 | params.logicalPath = path; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // We must have a path for the underlying interface |
| 132 | if (params.ifPath.empty()) |
| 133 | { |
| 134 | return std::nullopt; |
| 135 | } |
| 136 | // We don't have a VLAN so the logical path is the same |
| 137 | if (params.logicalPath.empty()) |
| 138 | { |
| 139 | params.logicalPath = params.ifPath; |
| 140 | } |
| 141 | |
| 142 | params.id = channel; |
| 143 | params.ifname = std::move(ifname); |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 144 | return params; |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 147 | ChannelParams getChannelParams(sdbusplus::bus_t& bus, uint8_t channel) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 148 | { |
| 149 | auto params = maybeGetChannelParams(bus, channel); |
| 150 | if (!params) |
| 151 | { |
| 152 | log<level::ERR>("Failed to get channel params", |
| 153 | entry("CHANNEL=%" PRIu8, channel)); |
| 154 | elog<InternalFailure>(); |
| 155 | } |
| 156 | return std::move(*params); |
| 157 | } |
| 158 | |
| 159 | /** @brief Wraps the phosphor logging method to insert some additional metadata |
| 160 | * |
| 161 | * @param[in] params - The parameters for the channel |
| 162 | * ... |
| 163 | */ |
| 164 | template <auto level, typename... Args> |
| 165 | auto logWithChannel(const ChannelParams& params, Args&&... args) |
| 166 | { |
| 167 | return log<level>(std::forward<Args>(args)..., |
| 168 | entry("CHANNEL=%d", params.id), |
| 169 | entry("IFNAME=%s", params.ifname.c_str())); |
| 170 | } |
| 171 | template <auto level, typename... Args> |
| 172 | auto logWithChannel(const std::optional<ChannelParams>& params, Args&&... args) |
| 173 | { |
| 174 | if (params) |
| 175 | { |
| 176 | return logWithChannel<level>(*params, std::forward<Args>(args)...); |
| 177 | } |
| 178 | return log<level>(std::forward<Args>(args)...); |
| 179 | } |
| 180 | |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 181 | /** @brief Get / Set the Property value from phosphor-networkd EthernetInterface |
| 182 | */ |
| 183 | template <typename T> |
| 184 | static T getEthProp(sdbusplus::bus_t& bus, const ChannelParams& params, |
| 185 | const std::string& prop) |
| 186 | { |
| 187 | return std::get<T>(getDbusProperty(bus, params.service, params.logicalPath, |
| 188 | INTF_ETHERNET, prop)); |
| 189 | } |
| 190 | template <typename T> |
| 191 | static void setEthProp(sdbusplus::bus_t& bus, const ChannelParams& params, |
| 192 | const std::string& prop, const T& t) |
| 193 | { |
| 194 | return setDbusProperty(bus, params.service, params.logicalPath, |
| 195 | INTF_ETHERNET, prop, t); |
| 196 | } |
| 197 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 198 | /** @brief Determines the MAC of the ethernet interface |
| 199 | * |
| 200 | * @param[in] bus - The bus object used for lookups |
| 201 | * @param[in] params - The parameters for the channel |
| 202 | * @return The configured mac address |
| 203 | */ |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 204 | stdplus::EtherAddr getMACProperty(sdbusplus::bus_t& bus, |
| 205 | const ChannelParams& params) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 206 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 207 | auto prop = getDbusProperty(bus, params.service, params.ifPath, INTF_MAC, |
| 208 | "MACAddress"); |
| 209 | return stdplus::fromStr<stdplus::EtherAddr>(std::get<std::string>(prop)); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** @brief Sets the system value for MAC address on the given interface |
| 213 | * |
| 214 | * @param[in] bus - The bus object used for lookups |
| 215 | * @param[in] params - The parameters for the channel |
| 216 | * @param[in] mac - MAC address to apply |
| 217 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 218 | void setMACProperty(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 219 | stdplus::EtherAddr mac) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 220 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 221 | setDbusProperty(bus, params.service, params.ifPath, INTF_MAC, "MACAddress", |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 222 | stdplus::toStr(mac)); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 225 | void deleteObjectIfExists(sdbusplus::bus_t& bus, const std::string& service, |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 226 | const std::string& path) |
| 227 | { |
| 228 | if (path.empty()) |
| 229 | { |
| 230 | return; |
| 231 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 232 | try |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 233 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 234 | auto req = bus.new_method_call(service.c_str(), path.c_str(), |
| 235 | ipmi::DELETE_INTERFACE, "Delete"); |
| 236 | bus.call_noreply(req); |
| 237 | } |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 238 | catch (const sdbusplus::exception_t& e) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 239 | { |
jayaprakash Mutyala | 84c49dc | 2020-05-18 23:12:13 +0000 | [diff] [blame] | 240 | if (strcmp(e.name(), |
| 241 | "xyz.openbmc_project.Common.Error.InternalFailure") != 0 && |
| 242 | strcmp(e.name(), "org.freedesktop.DBus.Error.UnknownObject") != 0) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 243 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 244 | // We want to rethrow real errors |
| 245 | throw; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 246 | } |
| 247 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 248 | } |
| 249 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 250 | /** @brief Sets the address info configured for the interface |
| 251 | * If a previous address path exists then it will be removed |
| 252 | * before the new address is added. |
| 253 | * |
| 254 | * @param[in] bus - The bus object used for lookups |
| 255 | * @param[in] params - The parameters for the channel |
| 256 | * @param[in] address - The address of the new IP |
| 257 | * @param[in] prefix - The prefix of the new IP |
| 258 | */ |
| 259 | template <int family> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 260 | void createIfAddr(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 261 | typename AddrFamily<family>::addr address, uint8_t prefix) |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 262 | { |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 263 | auto newreq = bus.new_method_call(params.service.c_str(), |
| 264 | params.logicalPath.c_str(), |
| 265 | INTF_IP_CREATE, "IP"); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 266 | std::string protocol = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 267 | sdbusplus::common::xyz::openbmc_project::network::convertForMessage( |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 268 | AddrFamily<family>::protocol); |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 269 | stdplus::ToStrHandle<stdplus::ToStr<typename AddrFamily<family>::addr>> tsh; |
| 270 | newreq.append(protocol, tsh(address), prefix, ""); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 271 | bus.call_noreply(newreq); |
| 272 | } |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 273 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 274 | /** @brief Trivial helper for getting the IPv4 address from getIfAddrs() |
| 275 | * |
| 276 | * @param[in] bus - The bus object used for lookups |
| 277 | * @param[in] params - The parameters for the channel |
| 278 | * @return The address and prefix if found |
| 279 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 280 | auto getIfAddr4(sdbusplus::bus_t& bus, const ChannelParams& params) |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 281 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 282 | return getIfAddr<AF_INET>(bus, params, 0, originsV4); |
| 283 | } |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 284 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 285 | /** @brief Reconfigures the IPv4 address info configured for the interface |
| 286 | * |
| 287 | * @param[in] bus - The bus object used for lookups |
| 288 | * @param[in] params - The parameters for the channel |
| 289 | * @param[in] address - The new address if specified |
| 290 | * @param[in] prefix - The new address prefix if specified |
| 291 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 292 | void reconfigureIfAddr4(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 293 | std::optional<stdplus::In4Addr> address, |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 294 | std::optional<uint8_t> prefix) |
| 295 | { |
| 296 | auto ifaddr = getIfAddr4(bus, params); |
| 297 | if (!ifaddr && !address) |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 298 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 299 | log<level::ERR>("Missing address for IPv4 assignment"); |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 300 | elog<InternalFailure>(); |
| 301 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 302 | uint8_t fallbackPrefix = AddrFamily<AF_INET>::defaultPrefix; |
| 303 | if (ifaddr) |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 304 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 305 | fallbackPrefix = ifaddr->prefix; |
| 306 | deleteObjectIfExists(bus, params.service, ifaddr->path); |
| 307 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 308 | auto addr = address.value_or(ifaddr->address); |
| 309 | if (addr != stdplus::In4Addr{}) |
Johnathan Mantey | cbfa6e1 | 2023-06-01 06:57:25 -0700 | [diff] [blame] | 310 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 311 | createIfAddr<AF_INET>(bus, params, addr, |
Johnathan Mantey | cbfa6e1 | 2023-06-01 06:57:25 -0700 | [diff] [blame] | 312 | prefix.value_or(fallbackPrefix)); |
| 313 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 314 | } |
| 315 | |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 316 | template <int family> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 317 | std::optional<IfNeigh<family>> findGatewayNeighbor(sdbusplus::bus_t& bus, |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 318 | const ChannelParams& params, |
| 319 | ObjectLookupCache& neighbors) |
| 320 | { |
| 321 | auto gateway = getGatewayProperty<family>(bus, params); |
| 322 | if (!gateway) |
| 323 | { |
| 324 | return std::nullopt; |
| 325 | } |
| 326 | |
| 327 | return findStaticNeighbor<family>(bus, params, *gateway, neighbors); |
| 328 | } |
| 329 | |
| 330 | template <int family> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 331 | std::optional<IfNeigh<family>> getGatewayNeighbor(sdbusplus::bus_t& bus, |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 332 | const ChannelParams& params) |
| 333 | { |
| 334 | ObjectLookupCache neighbors(bus, params, INTF_NEIGHBOR); |
| 335 | return findGatewayNeighbor<family>(bus, params, neighbors); |
| 336 | } |
| 337 | |
| 338 | template <int family> |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 339 | void reconfigureGatewayMAC(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 340 | stdplus::EtherAddr mac) |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 341 | { |
| 342 | auto gateway = getGatewayProperty<family>(bus, params); |
| 343 | if (!gateway) |
| 344 | { |
| 345 | log<level::ERR>("Tried to set Gateway MAC without Gateway"); |
| 346 | elog<InternalFailure>(); |
| 347 | } |
| 348 | |
| 349 | ObjectLookupCache neighbors(bus, params, INTF_NEIGHBOR); |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 350 | auto neighbor = findStaticNeighbor<family>(bus, params, *gateway, |
| 351 | neighbors); |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 352 | if (neighbor) |
| 353 | { |
| 354 | deleteObjectIfExists(bus, params.service, neighbor->path); |
| 355 | } |
| 356 | |
| 357 | createNeighbor<family>(bus, params, *gateway, mac); |
| 358 | } |
| 359 | |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 360 | /** @brief Deconfigures the IPv6 address info configured for the interface |
| 361 | * |
| 362 | * @param[in] bus - The bus object used for lookups |
| 363 | * @param[in] params - The parameters for the channel |
| 364 | * @param[in] idx - The address index to operate on |
| 365 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 366 | void deconfigureIfAddr6(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 367 | uint8_t idx) |
| 368 | { |
| 369 | auto ifaddr = getIfAddr<AF_INET6>(bus, params, idx, originsV6Static); |
| 370 | if (ifaddr) |
| 371 | { |
| 372 | deleteObjectIfExists(bus, params.service, ifaddr->path); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /** @brief Reconfigures the IPv6 address info configured for the interface |
| 377 | * |
| 378 | * @param[in] bus - The bus object used for lookups |
| 379 | * @param[in] params - The parameters for the channel |
| 380 | * @param[in] idx - The address index to operate on |
| 381 | * @param[in] address - The new address |
| 382 | * @param[in] prefix - The new address prefix |
| 383 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 384 | void reconfigureIfAddr6(sdbusplus::bus_t& bus, const ChannelParams& params, |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 385 | uint8_t idx, stdplus::In6Addr address, uint8_t prefix) |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 386 | { |
| 387 | deconfigureIfAddr6(bus, params, idx); |
| 388 | createIfAddr<AF_INET6>(bus, params, address, prefix); |
| 389 | } |
| 390 | |
| 391 | /** @brief Converts the AddressOrigin into an IPv6Source |
| 392 | * |
| 393 | * @param[in] origin - The DBus Address Origin to convert |
| 394 | * @return The IPv6Source version of the origin |
| 395 | */ |
| 396 | IPv6Source originToSourceType(IP::AddressOrigin origin) |
| 397 | { |
| 398 | switch (origin) |
| 399 | { |
| 400 | case IP::AddressOrigin::Static: |
| 401 | return IPv6Source::Static; |
| 402 | case IP::AddressOrigin::DHCP: |
| 403 | return IPv6Source::DHCP; |
| 404 | case IP::AddressOrigin::SLAAC: |
| 405 | return IPv6Source::SLAAC; |
| 406 | default: |
| 407 | { |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 408 | auto originStr = sdbusplus::common::xyz::openbmc_project::network:: |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 409 | convertForMessage(origin); |
| 410 | log<level::ERR>( |
| 411 | "Invalid IP::AddressOrigin conversion to IPv6Source", |
| 412 | entry("ORIGIN=%s", originStr.c_str())); |
| 413 | elog<InternalFailure>(); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /** @brief Packs the IPMI message response with IPv6 address data |
| 419 | * |
| 420 | * @param[out] ret - The IPMI response payload to be packed |
| 421 | * @param[in] channel - The channel id corresponding to an ethernet interface |
| 422 | * @param[in] set - The set selector for determining address index |
| 423 | * @param[in] origins - Set of valid origins for address filtering |
| 424 | */ |
| 425 | void getLanIPv6Address(message::Payload& ret, uint8_t channel, uint8_t set, |
| 426 | const std::unordered_set<IP::AddressOrigin>& origins) |
| 427 | { |
| 428 | auto source = IPv6Source::Static; |
| 429 | bool enabled = false; |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 430 | stdplus::In6Addr addr{}; |
Johnathan Mantey | 5aae092 | 2021-10-21 13:05:36 -0700 | [diff] [blame] | 431 | uint8_t prefix{}; |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 432 | auto status = IPv6AddressStatus::Disabled; |
| 433 | |
| 434 | auto ifaddr = channelCall<getIfAddr<AF_INET6>>(channel, set, origins); |
| 435 | if (ifaddr) |
| 436 | { |
| 437 | source = originToSourceType(ifaddr->origin); |
Johnathan Mantey | 846af86 | 2021-10-21 12:48:54 -0700 | [diff] [blame] | 438 | enabled = (origins == originsV6Static); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 439 | addr = ifaddr->address; |
| 440 | prefix = ifaddr->prefix; |
| 441 | status = IPv6AddressStatus::Active; |
| 442 | } |
| 443 | |
| 444 | ret.pack(set); |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 445 | ret.pack(types::enum_cast<uint4_t>(source), uint3_t{}, enabled); |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 446 | ret.pack(stdplus::raw::asView<char>(addr)); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 447 | ret.pack(prefix); |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 448 | ret.pack(types::enum_cast<uint8_t>(status)); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 449 | } |
| 450 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 451 | /** @brief Gets the vlan ID configured on the interface |
| 452 | * |
| 453 | * @param[in] bus - The bus object used for lookups |
| 454 | * @param[in] params - The parameters for the channel |
| 455 | * @return VLAN id or the standard 0 for no VLAN |
| 456 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 457 | uint16_t getVLANProperty(sdbusplus::bus_t& bus, const ChannelParams& params) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 458 | { |
| 459 | // VLAN devices will always have a separate logical object |
| 460 | if (params.ifPath == params.logicalPath) |
| 461 | { |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | auto vlan = std::get<uint32_t>(getDbusProperty( |
| 466 | bus, params.service, params.logicalPath, INTF_VLAN, "Id")); |
| 467 | if ((vlan & VLAN_VALUE_MASK) != vlan) |
| 468 | { |
| 469 | logWithChannel<level::ERR>(params, "networkd returned an invalid vlan", |
| 470 | entry("VLAN=%" PRIu32, vlan)); |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 471 | elog<InternalFailure>(); |
| 472 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 473 | return vlan; |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 474 | } |
| 475 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 476 | /** @brief Deletes all of the possible configuration parameters for a channel |
| 477 | * |
| 478 | * @param[in] bus - The bus object used for lookups |
| 479 | * @param[in] params - The parameters for the channel |
| 480 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 481 | void deconfigureChannel(sdbusplus::bus_t& bus, ChannelParams& params) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 482 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 483 | // Delete all objects associated with the interface |
| 484 | auto objreq = bus.new_method_call(MAPPER_BUS_NAME, MAPPER_OBJ, MAPPER_INTF, |
| 485 | "GetSubTree"); |
William A. Kennington III | c72f360 | 2023-10-19 03:51:37 -0700 | [diff] [blame] | 486 | objreq.append(std::string_view(PATH_ROOT), 0, |
| 487 | std::vector<std::string>{DELETE_INTERFACE}); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 488 | auto objreply = bus.call(objreq); |
| 489 | ObjectTree objs; |
| 490 | objreply.read(objs); |
| 491 | for (const auto& [path, impls] : objs) |
| 492 | { |
William A. Kennington III | c72f360 | 2023-10-19 03:51:37 -0700 | [diff] [blame] | 493 | if (!ifnameInPath(params.ifname, path)) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 494 | { |
| 495 | continue; |
| 496 | } |
| 497 | for (const auto& [service, intfs] : impls) |
| 498 | { |
| 499 | deleteObjectIfExists(bus, service, path); |
| 500 | } |
| 501 | // Update params to reflect the deletion of vlan |
| 502 | if (path == params.logicalPath) |
| 503 | { |
| 504 | params.logicalPath = params.ifPath; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | // Clear out any settings on the lower physical interface |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 509 | setEthProp(bus, params, "DHCP4", false); |
| 510 | setEthProp(bus, params, "DHCP6", false); |
| 511 | setEthProp(bus, params, "IPv6AcceptRA", false); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 512 | } |
| 513 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 514 | /** @brief Creates a new VLAN on the specified interface |
| 515 | * |
| 516 | * @param[in] bus - The bus object used for lookups |
| 517 | * @param[in] params - The parameters for the channel |
| 518 | * @param[in] vlan - The id of the new vlan |
| 519 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 520 | void createVLAN(sdbusplus::bus_t& bus, ChannelParams& params, uint16_t vlan) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 521 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 522 | if (vlan == 0) |
Richard Marian Thomaiyar | 75b480b | 2019-01-22 00:20:15 +0530 | [diff] [blame] | 523 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 524 | return; |
Richard Marian Thomaiyar | 75b480b | 2019-01-22 00:20:15 +0530 | [diff] [blame] | 525 | } |
| 526 | |
William A. Kennington III | c72f360 | 2023-10-19 03:51:37 -0700 | [diff] [blame] | 527 | auto req = bus.new_method_call(params.service.c_str(), PATH_ROOT.c_str(), |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 528 | INTF_VLAN_CREATE, "VLAN"); |
| 529 | req.append(params.ifname, static_cast<uint32_t>(vlan)); |
| 530 | auto reply = bus.call(req); |
| 531 | sdbusplus::message::object_path newPath; |
| 532 | reply.read(newPath); |
| 533 | params.logicalPath = std::move(newPath); |
Richard Marian Thomaiyar | 75b480b | 2019-01-22 00:20:15 +0530 | [diff] [blame] | 534 | } |
| 535 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 536 | /** @brief Performs the necessary reconfiguration to change the VLAN |
| 537 | * |
| 538 | * @param[in] bus - The bus object used for lookups |
| 539 | * @param[in] params - The parameters for the channel |
| 540 | * @param[in] vlan - The new vlan id to use |
| 541 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 542 | void reconfigureVLAN(sdbusplus::bus_t& bus, ChannelParams& params, |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 543 | uint16_t vlan) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 544 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 545 | // Unfortunatetly we don't have built-in functions to migrate our interface |
| 546 | // customizations to new VLAN interfaces, or have some kind of decoupling. |
| 547 | // We therefore must retain all of our old information, setup the new VLAN |
| 548 | // configuration, then restore the old info. |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 549 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 550 | // Save info from the old logical interface |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 551 | bool dhcp4 = getEthProp<bool>(bus, params, "DHCP4"); |
| 552 | bool dhcp6 = getEthProp<bool>(bus, params, "DHCP6"); |
| 553 | bool ra = getEthProp<bool>(bus, params, "IPv6AcceptRA"); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 554 | ObjectLookupCache ips(bus, params, INTF_IP); |
| 555 | auto ifaddr4 = findIfAddr<AF_INET>(bus, params, 0, originsV4, ips); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 556 | std::vector<IfAddr<AF_INET6>> ifaddrs6; |
| 557 | for (uint8_t i = 0; i < MAX_IPV6_STATIC_ADDRESSES; ++i) |
| 558 | { |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 559 | auto ifaddr6 = findIfAddr<AF_INET6>(bus, params, i, originsV6Static, |
| 560 | ips); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 561 | if (!ifaddr6) |
| 562 | { |
| 563 | break; |
| 564 | } |
| 565 | ifaddrs6.push_back(std::move(*ifaddr6)); |
| 566 | } |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 567 | ObjectLookupCache neighbors(bus, params, INTF_NEIGHBOR); |
| 568 | auto neighbor4 = findGatewayNeighbor<AF_INET>(bus, params, neighbors); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 569 | auto neighbor6 = findGatewayNeighbor<AF_INET6>(bus, params, neighbors); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 570 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 571 | deconfigureChannel(bus, params); |
| 572 | createVLAN(bus, params, vlan); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 573 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 574 | // Re-establish the saved settings |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 575 | setEthProp(bus, params, "DHCP4", dhcp4); |
| 576 | setEthProp(bus, params, "DHCP6", dhcp6); |
| 577 | setEthProp(bus, params, "IPv6AcceptRA", ra); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 578 | if (ifaddr4) |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 579 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 580 | createIfAddr<AF_INET>(bus, params, ifaddr4->address, ifaddr4->prefix); |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 581 | } |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 582 | for (const auto& ifaddr6 : ifaddrs6) |
| 583 | { |
| 584 | createIfAddr<AF_INET6>(bus, params, ifaddr6.address, ifaddr6.prefix); |
| 585 | } |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 586 | if (neighbor4) |
| 587 | { |
| 588 | createNeighbor<AF_INET>(bus, params, neighbor4->ip, neighbor4->mac); |
| 589 | } |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 590 | if (neighbor6) |
| 591 | { |
| 592 | createNeighbor<AF_INET6>(bus, params, neighbor6->ip, neighbor6->mac); |
| 593 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 594 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 595 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 596 | // We need to store this value so it can be returned to the client |
| 597 | // It is volatile so safe to store in daemon memory. |
| 598 | static std::unordered_map<uint8_t, SetStatus> setStatus; |
| 599 | |
| 600 | // Until we have good support for fixed versions of IPMI tool |
| 601 | // we need to return the VLAN id for disabled VLANs. The value is only |
| 602 | // used for verification that a disable operation succeeded and will only |
| 603 | // be sent if our system indicates that vlans are disabled. |
| 604 | static std::unordered_map<uint8_t, uint16_t> lastDisabledVlan; |
| 605 | |
| 606 | /** @brief Gets the set status for the channel if it exists |
| 607 | * Otherise populates and returns the default value. |
| 608 | * |
| 609 | * @param[in] channel - The channel id corresponding to an ethernet interface |
| 610 | * @return A reference to the SetStatus for the channel |
| 611 | */ |
| 612 | SetStatus& getSetStatus(uint8_t channel) |
| 613 | { |
| 614 | auto it = setStatus.find(channel); |
| 615 | if (it != setStatus.end()) |
| 616 | { |
| 617 | return it->second; |
| 618 | } |
| 619 | return setStatus[channel] = SetStatus::Complete; |
| 620 | } |
| 621 | |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 622 | /** @brief Unpacks the trivially copyable type from the message */ |
| 623 | template <typename T> |
| 624 | static T unpackT(message::Payload& req) |
| 625 | { |
| 626 | std::array<uint8_t, sizeof(T)> bytes; |
| 627 | if (req.unpack(bytes) != 0) |
| 628 | { |
| 629 | throw ccReqDataLenInvalid; |
| 630 | } |
| 631 | return stdplus::raw::copyFrom<T>(bytes); |
| 632 | } |
| 633 | |
| 634 | /** @brief Ensure the message is fully unpacked */ |
| 635 | static void unpackFinal(message::Payload& req) |
| 636 | { |
| 637 | if (!req.fullyUnpacked()) |
| 638 | { |
| 639 | throw ccReqDataTruncated; |
| 640 | } |
| 641 | } |
| 642 | |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 643 | /** |
| 644 | * Define placeholder command handlers for the OEM Extension bytes for the Set |
| 645 | * LAN Configuration Parameters and Get LAN Configuration Parameters |
| 646 | * commands. Using "weak" linking allows the placeholder setLanOem/getLanOem |
| 647 | * functions below to be overridden. |
| 648 | * To create handlers for your own proprietary command set: |
| 649 | * Create/modify a phosphor-ipmi-host Bitbake append file within your Yocto |
| 650 | * recipe |
| 651 | * Create C++ file(s) that define IPMI handler functions matching the |
| 652 | * function names below (i.e. setLanOem). The default name for the |
| 653 | * transport IPMI commands is transporthandler_oem.cpp. |
| 654 | * Add: |
Johnathan Mantey | efe2668 | 2022-08-11 14:30:45 -0700 | [diff] [blame] | 655 | * EXTRA_OEMESON:append = "-Dtransport-oem=enabled" |
| 656 | * Create a do_configure:prepend()/do_install:append() method in your |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 657 | * bbappend file to copy the file to the build directory. |
| 658 | * Add: |
| 659 | * PROJECT_SRC_DIR := "${THISDIR}/${PN}" |
| 660 | * # Copy the "strong" functions into the working directory, overriding the |
| 661 | * # placeholder functions. |
Johnathan Mantey | efe2668 | 2022-08-11 14:30:45 -0700 | [diff] [blame] | 662 | * do_configure:prepend(){ |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 663 | * cp -f ${PROJECT_SRC_DIR}/transporthandler_oem.cpp ${S} |
| 664 | * } |
| 665 | * |
| 666 | * # Clean up after complilation has completed |
Johnathan Mantey | efe2668 | 2022-08-11 14:30:45 -0700 | [diff] [blame] | 667 | * do_install:append(){ |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 668 | * rm -f ${S}/transporthandler_oem.cpp |
| 669 | * } |
| 670 | * |
| 671 | */ |
| 672 | |
| 673 | /** |
| 674 | * Define the placeholder OEM commands as having weak linkage. Create |
| 675 | * setLanOem, and getLanOem functions in the transporthandler_oem.cpp |
| 676 | * file. The functions defined there must not have the "weak" attribute |
| 677 | * applied to them. |
| 678 | */ |
| 679 | RspType<> setLanOem(uint8_t channel, uint8_t parameter, message::Payload& req) |
| 680 | __attribute__((weak)); |
| 681 | RspType<message::Payload> getLanOem(uint8_t channel, uint8_t parameter, |
| 682 | uint8_t set, uint8_t block) |
| 683 | __attribute__((weak)); |
| 684 | |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 685 | RspType<> setLanOem(uint8_t, uint8_t, message::Payload& req) |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 686 | { |
| 687 | req.trailingOk = true; |
| 688 | return response(ccParamNotSupported); |
| 689 | } |
| 690 | |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 691 | RspType<message::Payload> getLanOem(uint8_t, uint8_t, uint8_t, uint8_t) |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 692 | { |
| 693 | return response(ccParamNotSupported); |
| 694 | } |
| 695 | |
Jian Zhang | cf19d14 | 2023-07-31 10:22:53 +0800 | [diff] [blame] | 696 | /** |
| 697 | * @brief is a valid LAN channel. |
| 698 | * |
| 699 | * This function checks whether the input channel is a valid LAN channel or not. |
| 700 | * |
| 701 | * @param[in] channel: the channel number. |
| 702 | * @return nullopt if the channel is invalid, false if the channel is not a LAN |
| 703 | * channel, true if the channel is a LAN channel. |
| 704 | **/ |
| 705 | std::optional<bool> isLanChannel(uint8_t channel) |
| 706 | { |
| 707 | ChannelInfo chInfo; |
| 708 | auto cc = getChannelInfo(channel, chInfo); |
| 709 | if (cc != ccSuccess) |
| 710 | { |
| 711 | return std::nullopt; |
| 712 | } |
| 713 | |
| 714 | return chInfo.mediumType == |
| 715 | static_cast<uint8_t>(EChannelMediumType::lan8032); |
| 716 | } |
| 717 | |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 718 | RspType<> setLanInt(Context::ptr ctx, uint4_t channelBits, uint4_t reserved1, |
| 719 | uint8_t parameter, message::Payload& req) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 720 | { |
vijayabharathix shetty | cc76925 | 2020-02-27 17:52:20 +0000 | [diff] [blame] | 721 | const uint8_t channel = convertCurrentChannelNum( |
| 722 | static_cast<uint8_t>(channelBits), ctx->channel); |
| 723 | if (reserved1 || !isValidChannel(channel)) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 724 | { |
vijayabharathix shetty | cc76925 | 2020-02-27 17:52:20 +0000 | [diff] [blame] | 725 | log<level::ERR>("Set Lan - Invalid field in request"); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 726 | req.trailingOk = true; |
| 727 | return responseInvalidFieldRequest(); |
| 728 | } |
| 729 | |
Jian Zhang | cf19d14 | 2023-07-31 10:22:53 +0800 | [diff] [blame] | 730 | if (!isLanChannel(channel).value_or(false)) |
| 731 | { |
| 732 | log<level::ERR>("Set Lan - Not a LAN channel"); |
| 733 | return responseInvalidFieldRequest(); |
| 734 | } |
| 735 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 736 | switch (static_cast<LanParam>(parameter)) |
| 737 | { |
| 738 | case LanParam::SetStatus: |
| 739 | { |
| 740 | uint2_t flag; |
| 741 | uint6_t rsvd; |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 742 | if (req.unpack(flag, rsvd) != 0) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 743 | { |
| 744 | return responseReqDataLenInvalid(); |
| 745 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 746 | unpackFinal(req); |
Johnathan Mantey | 4a15685 | 2019-12-11 13:47:43 -0800 | [diff] [blame] | 747 | if (rsvd) |
| 748 | { |
| 749 | return responseInvalidFieldRequest(); |
| 750 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 751 | auto status = static_cast<SetStatus>(static_cast<uint8_t>(flag)); |
| 752 | switch (status) |
| 753 | { |
| 754 | case SetStatus::Complete: |
| 755 | { |
| 756 | getSetStatus(channel) = status; |
| 757 | return responseSuccess(); |
| 758 | } |
| 759 | case SetStatus::InProgress: |
| 760 | { |
| 761 | auto& storedStatus = getSetStatus(channel); |
| 762 | if (storedStatus == SetStatus::InProgress) |
| 763 | { |
| 764 | return response(ccParamSetLocked); |
| 765 | } |
| 766 | storedStatus = status; |
| 767 | return responseSuccess(); |
| 768 | } |
| 769 | case SetStatus::Commit: |
| 770 | if (getSetStatus(channel) != SetStatus::InProgress) |
| 771 | { |
| 772 | return responseInvalidFieldRequest(); |
| 773 | } |
| 774 | return responseSuccess(); |
| 775 | } |
| 776 | return response(ccParamNotSupported); |
| 777 | } |
| 778 | case LanParam::AuthSupport: |
| 779 | { |
| 780 | req.trailingOk = true; |
| 781 | return response(ccParamReadOnly); |
| 782 | } |
| 783 | case LanParam::AuthEnables: |
| 784 | { |
| 785 | req.trailingOk = true; |
Johnathan Mantey | 76ce9c7 | 2019-11-14 14:41:46 -0800 | [diff] [blame] | 786 | return response(ccParamReadOnly); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 787 | } |
William A. Kennington III | aab2023 | 2018-11-19 18:20:39 -0800 | [diff] [blame] | 788 | case LanParam::IP: |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 789 | { |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 790 | if (channelCall<getEthProp<bool>>(channel, "DHCP4")) |
Johnathan Mantey | 930104a | 2019-12-17 09:18:34 -0800 | [diff] [blame] | 791 | { |
| 792 | return responseCommandNotAvailable(); |
| 793 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 794 | auto ip = unpackT<stdplus::In4Addr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 795 | unpackFinal(req); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 796 | channelCall<reconfigureIfAddr4>(channel, ip, std::nullopt); |
| 797 | return responseSuccess(); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 798 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 799 | case LanParam::IPSrc: |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 800 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 801 | uint4_t flag; |
| 802 | uint4_t rsvd; |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 803 | if (req.unpack(flag, rsvd) != 0) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 804 | { |
| 805 | return responseReqDataLenInvalid(); |
| 806 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 807 | unpackFinal(req); |
Johnathan Mantey | 4a15685 | 2019-12-11 13:47:43 -0800 | [diff] [blame] | 808 | if (rsvd) |
| 809 | { |
| 810 | return responseInvalidFieldRequest(); |
| 811 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 812 | switch (static_cast<IPSrc>(static_cast<uint8_t>(flag))) |
| 813 | { |
| 814 | case IPSrc::DHCP: |
Johnathan Mantey | 6526536 | 2019-11-14 11:24:19 -0800 | [diff] [blame] | 815 | // The IPSrc IPMI command is only for IPv4 |
| 816 | // management. Modifying IPv6 state is done using |
| 817 | // a completely different Set LAN Configuration |
| 818 | // subcommand. |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 819 | channelCall<setEthProp<bool>>(channel, "DHCP4", true); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 820 | return responseSuccess(); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 821 | case IPSrc::Unspecified: |
| 822 | case IPSrc::Static: |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 823 | channelCall<setEthProp<bool>>(channel, "DHCP4", false); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 824 | return responseSuccess(); |
Rajashekar Gade Reddy | 8a860ea | 2019-12-24 11:31:19 +0530 | [diff] [blame] | 825 | case IPSrc::BIOS: |
| 826 | case IPSrc::BMC: |
Rajashekar Gade Reddy | 8a860ea | 2019-12-24 11:31:19 +0530 | [diff] [blame] | 827 | return responseInvalidFieldRequest(); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 828 | } |
| 829 | return response(ccParamNotSupported); |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 830 | } |
William A. Kennington III | aab2023 | 2018-11-19 18:20:39 -0800 | [diff] [blame] | 831 | case LanParam::MAC: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 832 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 833 | auto mac = unpackT<stdplus::EtherAddr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 834 | unpackFinal(req); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 835 | channelCall<setMACProperty>(channel, mac); |
| 836 | return responseSuccess(); |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 837 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 838 | case LanParam::SubnetMask: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 839 | { |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 840 | if (channelCall<getEthProp<bool>>(channel, "DHCP4")) |
Johnathan Mantey | 930104a | 2019-12-17 09:18:34 -0800 | [diff] [blame] | 841 | { |
| 842 | return responseCommandNotAvailable(); |
| 843 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 844 | auto pfx = stdplus::maskToPfx(unpackT<stdplus::In4Addr>(req)); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 845 | unpackFinal(req); |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 846 | channelCall<reconfigureIfAddr4>(channel, std::nullopt, pfx); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 847 | return responseSuccess(); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 848 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 849 | case LanParam::Gateway1: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 850 | { |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 851 | if (channelCall<getEthProp<bool>>(channel, "DHCP4")) |
Johnathan Mantey | 930104a | 2019-12-17 09:18:34 -0800 | [diff] [blame] | 852 | { |
| 853 | return responseCommandNotAvailable(); |
| 854 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 855 | auto gateway = unpackT<stdplus::In4Addr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 856 | unpackFinal(req); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 857 | channelCall<setGatewayProperty<AF_INET>>(channel, gateway); |
| 858 | return responseSuccess(); |
| 859 | } |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 860 | case LanParam::Gateway1MAC: |
| 861 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 862 | auto gatewayMAC = unpackT<stdplus::EtherAddr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 863 | unpackFinal(req); |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 864 | channelCall<reconfigureGatewayMAC<AF_INET>>(channel, gatewayMAC); |
| 865 | return responseSuccess(); |
| 866 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 867 | case LanParam::VLANId: |
| 868 | { |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 869 | uint12_t vlanData; |
| 870 | uint3_t rsvd; |
| 871 | bool vlanEnable; |
Suryakanth Sekar | 8e8c8e2 | 2019-08-30 11:54:20 +0530 | [diff] [blame] | 872 | |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 873 | if (req.unpack(vlanData, rsvd, vlanEnable) != 0) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 874 | { |
| 875 | return responseReqDataLenInvalid(); |
| 876 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 877 | unpackFinal(req); |
Suryakanth Sekar | 8e8c8e2 | 2019-08-30 11:54:20 +0530 | [diff] [blame] | 878 | |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 879 | if (rsvd) |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 880 | { |
Suryakanth Sekar | 8e8c8e2 | 2019-08-30 11:54:20 +0530 | [diff] [blame] | 881 | return responseInvalidFieldRequest(); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 882 | } |
Suryakanth Sekar | 8e8c8e2 | 2019-08-30 11:54:20 +0530 | [diff] [blame] | 883 | |
| 884 | uint16_t vlan = static_cast<uint16_t>(vlanData); |
| 885 | |
| 886 | if (!vlanEnable) |
| 887 | { |
| 888 | lastDisabledVlan[channel] = vlan; |
| 889 | vlan = 0; |
| 890 | } |
Suryakanth Sekar | 8e8c8e2 | 2019-08-30 11:54:20 +0530 | [diff] [blame] | 891 | |
jayaprakash Mutyala | 84c49dc | 2020-05-18 23:12:13 +0000 | [diff] [blame] | 892 | channelCall<reconfigureVLAN>(channel, vlan); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 893 | return responseSuccess(); |
| 894 | } |
| 895 | case LanParam::CiphersuiteSupport: |
| 896 | case LanParam::CiphersuiteEntries: |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 897 | case LanParam::IPFamilySupport: |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 898 | { |
| 899 | req.trailingOk = true; |
| 900 | return response(ccParamReadOnly); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 901 | } |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 902 | case LanParam::IPFamilyEnables: |
| 903 | { |
| 904 | uint8_t enables; |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 905 | if (req.unpack(enables) != 0) |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 906 | { |
| 907 | return responseReqDataLenInvalid(); |
| 908 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 909 | unpackFinal(req); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 910 | switch (static_cast<IPFamilyEnables>(enables)) |
| 911 | { |
| 912 | case IPFamilyEnables::DualStack: |
| 913 | return responseSuccess(); |
| 914 | case IPFamilyEnables::IPv4Only: |
| 915 | case IPFamilyEnables::IPv6Only: |
| 916 | return response(ccParamNotSupported); |
| 917 | } |
| 918 | return response(ccParamNotSupported); |
| 919 | } |
| 920 | case LanParam::IPv6Status: |
| 921 | { |
| 922 | req.trailingOk = true; |
| 923 | return response(ccParamReadOnly); |
| 924 | } |
| 925 | case LanParam::IPv6StaticAddresses: |
| 926 | { |
| 927 | uint8_t set; |
| 928 | uint7_t rsvd; |
| 929 | bool enabled; |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 930 | uint8_t prefix; |
| 931 | uint8_t status; |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 932 | if (req.unpack(set, rsvd, enabled) != 0) |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 933 | { |
| 934 | return responseReqDataLenInvalid(); |
| 935 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 936 | auto ip = unpackT<stdplus::In6Addr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 937 | if (req.unpack(prefix, status) != 0) |
| 938 | { |
| 939 | return responseReqDataLenInvalid(); |
| 940 | } |
| 941 | unpackFinal(req); |
Johnathan Mantey | 4a15685 | 2019-12-11 13:47:43 -0800 | [diff] [blame] | 942 | if (rsvd) |
| 943 | { |
| 944 | return responseInvalidFieldRequest(); |
| 945 | } |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 946 | if (enabled) |
| 947 | { |
Jiaqing Zhao | 6d4a44e | 2022-01-24 15:04:00 +0800 | [diff] [blame] | 948 | if (prefix < MIN_IPV6_PREFIX_LENGTH || |
| 949 | prefix > MAX_IPV6_PREFIX_LENGTH) |
| 950 | { |
| 951 | return responseParmOutOfRange(); |
| 952 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 953 | channelCall<reconfigureIfAddr6>(channel, set, ip, prefix); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 954 | } |
| 955 | else |
| 956 | { |
| 957 | channelCall<deconfigureIfAddr6>(channel, set); |
| 958 | } |
| 959 | return responseSuccess(); |
| 960 | } |
| 961 | case LanParam::IPv6DynamicAddresses: |
| 962 | { |
| 963 | req.trailingOk = true; |
| 964 | return response(ccParamReadOnly); |
| 965 | } |
| 966 | case LanParam::IPv6RouterControl: |
| 967 | { |
| 968 | std::bitset<8> control; |
Johnathan Mantey | 3b7a407 | 2021-01-26 14:24:53 -0800 | [diff] [blame] | 969 | constexpr uint8_t reservedRACCBits = 0xfc; |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 970 | if (req.unpack(control) != 0) |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 971 | { |
| 972 | return responseReqDataLenInvalid(); |
| 973 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 974 | unpackFinal(req); |
Johnathan Mantey | 3b7a407 | 2021-01-26 14:24:53 -0800 | [diff] [blame] | 975 | if (std::bitset<8> expected(control & |
| 976 | std::bitset<8>(reservedRACCBits)); |
| 977 | expected.any()) |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 978 | { |
Johnathan Mantey | 3b7a407 | 2021-01-26 14:24:53 -0800 | [diff] [blame] | 979 | return response(ccParamNotSupported); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 980 | } |
Johnathan Mantey | 3b7a407 | 2021-01-26 14:24:53 -0800 | [diff] [blame] | 981 | |
| 982 | bool enableRA = control[IPv6RouterControlFlag::Dynamic]; |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 983 | channelCall<setEthProp<bool>>(channel, "IPv6AcceptRA", enableRA); |
| 984 | channelCall<setEthProp<bool>>(channel, "DHCP6", enableRA); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 985 | return responseSuccess(); |
| 986 | } |
| 987 | case LanParam::IPv6StaticRouter1IP: |
| 988 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 989 | auto gateway = unpackT<stdplus::In6Addr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 990 | unpackFinal(req); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 991 | channelCall<setGatewayProperty<AF_INET6>>(channel, gateway); |
| 992 | return responseSuccess(); |
| 993 | } |
| 994 | case LanParam::IPv6StaticRouter1MAC: |
| 995 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 996 | auto mac = unpackT<stdplus::EtherAddr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 997 | unpackFinal(req); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 998 | channelCall<reconfigureGatewayMAC<AF_INET6>>(channel, mac); |
| 999 | return responseSuccess(); |
| 1000 | } |
| 1001 | case LanParam::IPv6StaticRouter1PrefixLength: |
| 1002 | { |
| 1003 | uint8_t prefix; |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1004 | if (req.unpack(prefix) != 0) |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1005 | { |
| 1006 | return responseReqDataLenInvalid(); |
| 1007 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1008 | unpackFinal(req); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1009 | if (prefix != 0) |
| 1010 | { |
| 1011 | return responseInvalidFieldRequest(); |
| 1012 | } |
| 1013 | return responseSuccess(); |
| 1014 | } |
| 1015 | case LanParam::IPv6StaticRouter1PrefixValue: |
| 1016 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1017 | unpackT<stdplus::In6Addr>(req); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1018 | unpackFinal(req); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1019 | // Accept any prefix value since our prefix length has to be 0 |
| 1020 | return responseSuccess(); |
| 1021 | } |
jayaprakash Mutyala | b741b99 | 2019-12-02 17:29:09 +0000 | [diff] [blame] | 1022 | case LanParam::cipherSuitePrivilegeLevels: |
| 1023 | { |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1024 | uint8_t rsvd; |
jayaprakash Mutyala | b741b99 | 2019-12-02 17:29:09 +0000 | [diff] [blame] | 1025 | std::array<uint4_t, ipmi::maxCSRecords> cipherSuitePrivs; |
| 1026 | |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1027 | if (req.unpack(rsvd, cipherSuitePrivs)) |
jayaprakash Mutyala | b741b99 | 2019-12-02 17:29:09 +0000 | [diff] [blame] | 1028 | { |
| 1029 | return responseReqDataLenInvalid(); |
| 1030 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1031 | unpackFinal(req); |
jayaprakash Mutyala | b741b99 | 2019-12-02 17:29:09 +0000 | [diff] [blame] | 1032 | |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1033 | if (rsvd) |
jayaprakash Mutyala | b741b99 | 2019-12-02 17:29:09 +0000 | [diff] [blame] | 1034 | { |
| 1035 | return responseInvalidFieldRequest(); |
| 1036 | } |
| 1037 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1038 | uint8_t resp = getCipherConfigObject(csPrivFileName, |
| 1039 | csPrivDefaultFileName) |
| 1040 | .setCSPrivilegeLevels(channel, cipherSuitePrivs); |
jayaprakash Mutyala | b741b99 | 2019-12-02 17:29:09 +0000 | [diff] [blame] | 1041 | if (!resp) |
| 1042 | { |
| 1043 | return responseSuccess(); |
| 1044 | } |
| 1045 | else |
| 1046 | { |
| 1047 | req.trailingOk = true; |
| 1048 | return response(resp); |
| 1049 | } |
| 1050 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 1051 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 1052 | |
PavanKumarIntel | 3771f5f | 2023-11-02 06:26:42 +0000 | [diff] [blame] | 1053 | if (parameter >= oemCmdStart) |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 1054 | { |
| 1055 | return setLanOem(channel, parameter, req); |
| 1056 | } |
| 1057 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1058 | req.trailingOk = true; |
| 1059 | return response(ccParamNotSupported); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1060 | } |
| 1061 | |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1062 | RspType<> setLan(Context::ptr ctx, uint4_t channelBits, uint4_t reserved1, |
| 1063 | uint8_t parameter, message::Payload& req) |
| 1064 | { |
| 1065 | try |
| 1066 | { |
| 1067 | return setLanInt(ctx, channelBits, reserved1, parameter, req); |
| 1068 | } |
| 1069 | catch (ipmi::Cc cc) |
| 1070 | { |
| 1071 | return response(cc); |
| 1072 | } |
| 1073 | catch (const sdbusplus::exception_t& e) |
| 1074 | { |
| 1075 | if (std::string_view{InvalidArgument::errName} == e.name()) |
| 1076 | { |
| 1077 | return responseInvalidFieldRequest(); |
| 1078 | } |
| 1079 | throw; |
| 1080 | } |
| 1081 | } |
| 1082 | |
vijayabharathix shetty | cc76925 | 2020-02-27 17:52:20 +0000 | [diff] [blame] | 1083 | RspType<message::Payload> getLan(Context::ptr ctx, uint4_t channelBits, |
| 1084 | uint3_t reserved, bool revOnly, |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1085 | uint8_t parameter, uint8_t set, uint8_t block) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 1086 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1087 | message::Payload ret; |
| 1088 | constexpr uint8_t current_revision = 0x11; |
| 1089 | ret.pack(current_revision); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1090 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1091 | if (revOnly) |
Suryakanth Sekar | e405440 | 2019-08-08 15:16:52 +0530 | [diff] [blame] | 1092 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1093 | return responseSuccess(std::move(ret)); |
Suryakanth Sekar | e405440 | 2019-08-08 15:16:52 +0530 | [diff] [blame] | 1094 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1095 | |
vijayabharathix shetty | cc76925 | 2020-02-27 17:52:20 +0000 | [diff] [blame] | 1096 | const uint8_t channel = convertCurrentChannelNum( |
| 1097 | static_cast<uint8_t>(channelBits), ctx->channel); |
| 1098 | if (reserved || !isValidChannel(channel)) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1099 | { |
vijayabharathix shetty | cc76925 | 2020-02-27 17:52:20 +0000 | [diff] [blame] | 1100 | log<level::ERR>("Get Lan - Invalid field in request"); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1101 | return responseInvalidFieldRequest(); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1102 | } |
| 1103 | |
Jian Zhang | cf19d14 | 2023-07-31 10:22:53 +0800 | [diff] [blame] | 1104 | if (!isLanChannel(channel).value_or(false)) |
| 1105 | { |
| 1106 | log<level::ERR>("Set Lan - Not a LAN channel"); |
| 1107 | return responseInvalidFieldRequest(); |
| 1108 | } |
| 1109 | |
Johnathan Mantey | affadb5 | 2019-10-07 10:13:53 -0700 | [diff] [blame] | 1110 | static std::vector<uint8_t> cipherList; |
| 1111 | static bool listInit = false; |
| 1112 | if (!listInit) |
| 1113 | { |
| 1114 | try |
| 1115 | { |
| 1116 | cipherList = cipher::getCipherList(); |
| 1117 | listInit = true; |
| 1118 | } |
| 1119 | catch (const std::exception& e) |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1120 | {} |
Johnathan Mantey | affadb5 | 2019-10-07 10:13:53 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1123 | switch (static_cast<LanParam>(parameter)) |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 1124 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1125 | case LanParam::SetStatus: |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 1126 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1127 | SetStatus status; |
| 1128 | try |
| 1129 | { |
| 1130 | status = setStatus.at(channel); |
| 1131 | } |
| 1132 | catch (const std::out_of_range&) |
| 1133 | { |
| 1134 | status = SetStatus::Complete; |
| 1135 | } |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1136 | ret.pack(types::enum_cast<uint2_t>(status), uint6_t{}); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1137 | return responseSuccess(std::move(ret)); |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 1138 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1139 | case LanParam::AuthSupport: |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 1140 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1141 | std::bitset<6> support; |
| 1142 | ret.pack(support, uint2_t{}); |
| 1143 | return responseSuccess(std::move(ret)); |
Tom Joseph | a30c8d3 | 2018-03-22 02:15:03 +0530 | [diff] [blame] | 1144 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1145 | case LanParam::AuthEnables: |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 1146 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1147 | std::bitset<6> enables; |
| 1148 | ret.pack(enables, uint2_t{}); // Callback |
| 1149 | ret.pack(enables, uint2_t{}); // User |
| 1150 | ret.pack(enables, uint2_t{}); // Operator |
| 1151 | ret.pack(enables, uint2_t{}); // Admin |
| 1152 | ret.pack(enables, uint2_t{}); // OEM |
| 1153 | return responseSuccess(std::move(ret)); |
William A. Kennington III | 39f94ef | 2018-11-19 22:36:16 -0800 | [diff] [blame] | 1154 | } |
William A. Kennington III | aab2023 | 2018-11-19 18:20:39 -0800 | [diff] [blame] | 1155 | case LanParam::IP: |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1156 | { |
| 1157 | auto ifaddr = channelCall<getIfAddr4>(channel); |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1158 | stdplus::In4Addr addr{}; |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1159 | if (ifaddr) |
| 1160 | { |
| 1161 | addr = ifaddr->address; |
| 1162 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1163 | ret.pack(stdplus::raw::asView<char>(addr)); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1164 | return responseSuccess(std::move(ret)); |
| 1165 | } |
| 1166 | case LanParam::IPSrc: |
| 1167 | { |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 1168 | auto src = channelCall<getEthProp<bool>>(channel, "DHCP4") |
| 1169 | ? IPSrc::DHCP |
| 1170 | : IPSrc::Static; |
William A. Kennington III | 7a0e5df | 2021-05-19 13:31:29 -0700 | [diff] [blame] | 1171 | ret.pack(types::enum_cast<uint4_t>(src), uint4_t{}); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1172 | return responseSuccess(std::move(ret)); |
| 1173 | } |
William A. Kennington III | aab2023 | 2018-11-19 18:20:39 -0800 | [diff] [blame] | 1174 | case LanParam::MAC: |
William A. Kennington III | 39f94ef | 2018-11-19 22:36:16 -0800 | [diff] [blame] | 1175 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1176 | auto mac = channelCall<getMACProperty>(channel); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1177 | ret.pack(stdplus::raw::asView<char>(mac)); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1178 | return responseSuccess(std::move(ret)); |
| 1179 | } |
| 1180 | case LanParam::SubnetMask: |
| 1181 | { |
| 1182 | auto ifaddr = channelCall<getIfAddr4>(channel); |
| 1183 | uint8_t prefix = AddrFamily<AF_INET>::defaultPrefix; |
| 1184 | if (ifaddr) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 1185 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1186 | prefix = ifaddr->prefix; |
| 1187 | } |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1188 | auto netmask = stdplus::pfxToMask<stdplus::In4Addr>(prefix); |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1189 | ret.pack(stdplus::raw::asView<char>(netmask)); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1190 | return responseSuccess(std::move(ret)); |
| 1191 | } |
| 1192 | case LanParam::Gateway1: |
| 1193 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1194 | auto gateway = channelCall<getGatewayProperty<AF_INET>>(channel); |
| 1195 | ret.pack(stdplus::raw::asView<char>( |
| 1196 | gateway.value_or(stdplus::In4Addr{}))); |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1197 | return responseSuccess(std::move(ret)); |
| 1198 | } |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 1199 | case LanParam::Gateway1MAC: |
| 1200 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1201 | stdplus::EtherAddr mac{}; |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 1202 | auto neighbor = channelCall<getGatewayNeighbor<AF_INET>>(channel); |
| 1203 | if (neighbor) |
| 1204 | { |
| 1205 | mac = neighbor->mac; |
| 1206 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1207 | ret.pack(stdplus::raw::asView<char>(mac)); |
William A. Kennington III | 4bbc3db | 2019-04-15 00:02:10 -0700 | [diff] [blame] | 1208 | return responseSuccess(std::move(ret)); |
| 1209 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1210 | case LanParam::VLANId: |
| 1211 | { |
| 1212 | uint16_t vlan = channelCall<getVLANProperty>(channel); |
| 1213 | if (vlan != 0) |
| 1214 | { |
| 1215 | vlan |= VLAN_ENABLE_FLAG; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 1216 | } |
| 1217 | else |
| 1218 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1219 | vlan = lastDisabledVlan[channel]; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 1220 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1221 | ret.pack(vlan); |
| 1222 | return responseSuccess(std::move(ret)); |
Adriana Kobylak | 342df10 | 2016-02-10 13:48:16 -0600 | [diff] [blame] | 1223 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1224 | case LanParam::CiphersuiteSupport: |
Johnathan Mantey | affadb5 | 2019-10-07 10:13:53 -0700 | [diff] [blame] | 1225 | { |
srikanta mondal | 1d8579c | 2020-04-15 17:13:25 +0000 | [diff] [blame] | 1226 | if (getChannelSessionSupport(channel) == |
| 1227 | EChannelSessSupported::none) |
| 1228 | { |
| 1229 | return responseInvalidFieldRequest(); |
| 1230 | } |
Johnathan Mantey | affadb5 | 2019-10-07 10:13:53 -0700 | [diff] [blame] | 1231 | if (!listInit) |
| 1232 | { |
| 1233 | return responseUnspecifiedError(); |
| 1234 | } |
| 1235 | ret.pack(static_cast<uint8_t>(cipherList.size() - 1)); |
| 1236 | return responseSuccess(std::move(ret)); |
| 1237 | } |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1238 | case LanParam::CiphersuiteEntries: |
Johnathan Mantey | affadb5 | 2019-10-07 10:13:53 -0700 | [diff] [blame] | 1239 | { |
srikanta mondal | 1d8579c | 2020-04-15 17:13:25 +0000 | [diff] [blame] | 1240 | if (getChannelSessionSupport(channel) == |
| 1241 | EChannelSessSupported::none) |
| 1242 | { |
| 1243 | return responseInvalidFieldRequest(); |
| 1244 | } |
Johnathan Mantey | affadb5 | 2019-10-07 10:13:53 -0700 | [diff] [blame] | 1245 | if (!listInit) |
| 1246 | { |
| 1247 | return responseUnspecifiedError(); |
| 1248 | } |
| 1249 | ret.pack(cipherList); |
| 1250 | return responseSuccess(std::move(ret)); |
| 1251 | } |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1252 | case LanParam::IPFamilySupport: |
| 1253 | { |
| 1254 | std::bitset<8> support; |
| 1255 | support[IPFamilySupportFlag::IPv6Only] = 0; |
| 1256 | support[IPFamilySupportFlag::DualStack] = 1; |
| 1257 | support[IPFamilySupportFlag::IPv6Alerts] = 1; |
| 1258 | ret.pack(support); |
| 1259 | return responseSuccess(std::move(ret)); |
| 1260 | } |
| 1261 | case LanParam::IPFamilyEnables: |
| 1262 | { |
| 1263 | ret.pack(static_cast<uint8_t>(IPFamilyEnables::DualStack)); |
| 1264 | return responseSuccess(std::move(ret)); |
| 1265 | } |
| 1266 | case LanParam::IPv6Status: |
| 1267 | { |
| 1268 | ret.pack(MAX_IPV6_STATIC_ADDRESSES); |
| 1269 | ret.pack(MAX_IPV6_DYNAMIC_ADDRESSES); |
| 1270 | std::bitset<8> support; |
| 1271 | support[IPv6StatusFlag::DHCP] = 1; |
| 1272 | support[IPv6StatusFlag::SLAAC] = 1; |
| 1273 | ret.pack(support); |
| 1274 | return responseSuccess(std::move(ret)); |
| 1275 | } |
| 1276 | case LanParam::IPv6StaticAddresses: |
| 1277 | { |
| 1278 | if (set >= MAX_IPV6_STATIC_ADDRESSES) |
| 1279 | { |
| 1280 | return responseParmOutOfRange(); |
| 1281 | } |
| 1282 | getLanIPv6Address(ret, channel, set, originsV6Static); |
| 1283 | return responseSuccess(std::move(ret)); |
| 1284 | } |
| 1285 | case LanParam::IPv6DynamicAddresses: |
| 1286 | { |
| 1287 | if (set >= MAX_IPV6_DYNAMIC_ADDRESSES) |
| 1288 | { |
| 1289 | return responseParmOutOfRange(); |
| 1290 | } |
| 1291 | getLanIPv6Address(ret, channel, set, originsV6Dynamic); |
| 1292 | return responseSuccess(std::move(ret)); |
| 1293 | } |
| 1294 | case LanParam::IPv6RouterControl: |
| 1295 | { |
| 1296 | std::bitset<8> control; |
Johnathan Mantey | 3b7a407 | 2021-01-26 14:24:53 -0800 | [diff] [blame] | 1297 | control[IPv6RouterControlFlag::Dynamic] = |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 1298 | channelCall<getEthProp<bool>>(channel, "IPv6AcceptRA"); |
Johnathan Mantey | 3b7a407 | 2021-01-26 14:24:53 -0800 | [diff] [blame] | 1299 | control[IPv6RouterControlFlag::Static] = 1; |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1300 | ret.pack(control); |
| 1301 | return responseSuccess(std::move(ret)); |
| 1302 | } |
| 1303 | case LanParam::IPv6StaticRouter1IP: |
| 1304 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1305 | stdplus::In6Addr gateway{}; |
William A. Kennington III | a8a2e5f | 2023-06-21 17:50:01 -0700 | [diff] [blame] | 1306 | if (!channelCall<getEthProp<bool>>(channel, "IPv6AcceptRA")) |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1307 | { |
| 1308 | gateway = |
| 1309 | channelCall<getGatewayProperty<AF_INET6>>(channel).value_or( |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1310 | stdplus::In6Addr{}); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1311 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1312 | ret.pack(stdplus::raw::asView<char>(gateway)); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1313 | return responseSuccess(std::move(ret)); |
| 1314 | } |
| 1315 | case LanParam::IPv6StaticRouter1MAC: |
| 1316 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1317 | stdplus::EtherAddr mac{}; |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1318 | auto neighbor = channelCall<getGatewayNeighbor<AF_INET6>>(channel); |
| 1319 | if (neighbor) |
| 1320 | { |
| 1321 | mac = neighbor->mac; |
| 1322 | } |
William A. Kennington III | 7a3831b | 2023-06-21 01:10:49 -0700 | [diff] [blame] | 1323 | ret.pack(stdplus::raw::asView<char>(mac)); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1324 | return responseSuccess(std::move(ret)); |
| 1325 | } |
| 1326 | case LanParam::IPv6StaticRouter1PrefixLength: |
| 1327 | { |
| 1328 | ret.pack(UINT8_C(0)); |
| 1329 | return responseSuccess(std::move(ret)); |
| 1330 | } |
| 1331 | case LanParam::IPv6StaticRouter1PrefixValue: |
| 1332 | { |
William A. Kennington III | 726f2bd | 2023-06-21 01:11:40 -0700 | [diff] [blame] | 1333 | ret.pack(stdplus::raw::asView<char>(stdplus::In6Addr{})); |
William A. Kennington III | 16064aa | 2019-04-13 17:44:53 -0700 | [diff] [blame] | 1334 | return responseSuccess(std::move(ret)); |
| 1335 | } |
jayaprakash Mutyala | b741b99 | 2019-12-02 17:29:09 +0000 | [diff] [blame] | 1336 | case LanParam::cipherSuitePrivilegeLevels: |
| 1337 | { |
| 1338 | std::array<uint4_t, ipmi::maxCSRecords> csPrivilegeLevels; |
| 1339 | |
| 1340 | uint8_t resp = |
| 1341 | getCipherConfigObject(csPrivFileName, csPrivDefaultFileName) |
| 1342 | .getCSPrivilegeLevels(channel, csPrivilegeLevels); |
| 1343 | if (!resp) |
| 1344 | { |
| 1345 | constexpr uint8_t reserved1 = 0x00; |
| 1346 | ret.pack(reserved1, csPrivilegeLevels); |
| 1347 | return responseSuccess(std::move(ret)); |
| 1348 | } |
| 1349 | else |
| 1350 | { |
| 1351 | return response(resp); |
| 1352 | } |
| 1353 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1354 | } |
| 1355 | |
PavanKumarIntel | 3771f5f | 2023-11-02 06:26:42 +0000 | [diff] [blame] | 1356 | if (parameter >= oemCmdStart) |
Johnathan Mantey | b87034e | 2019-09-16 10:50:50 -0700 | [diff] [blame] | 1357 | { |
| 1358 | return getLanOem(channel, parameter, set, block); |
| 1359 | } |
| 1360 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1361 | return response(ccParamNotSupported); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1362 | } |
| 1363 | |
Jian Zhang | 23f4465 | 2022-03-17 17:13:10 +0800 | [diff] [blame] | 1364 | constexpr const char* solInterface = "xyz.openbmc_project.Ipmi.SOL"; |
| 1365 | constexpr const char* solPath = "/xyz/openbmc_project/ipmi/sol/"; |
| 1366 | constexpr const uint16_t solDefaultPort = 623; |
| 1367 | |
| 1368 | RspType<> setSolConfParams(Context::ptr ctx, uint4_t channelBits, |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 1369 | uint4_t /*reserved*/, uint8_t parameter, |
Jian Zhang | 23f4465 | 2022-03-17 17:13:10 +0800 | [diff] [blame] | 1370 | message::Payload& req) |
| 1371 | { |
| 1372 | const uint8_t channel = convertCurrentChannelNum( |
| 1373 | static_cast<uint8_t>(channelBits), ctx->channel); |
| 1374 | |
| 1375 | if (!isValidChannel(channel)) |
| 1376 | { |
| 1377 | log<level::ERR>("Set Sol Config - Invalid channel in request"); |
| 1378 | return responseInvalidFieldRequest(); |
| 1379 | } |
| 1380 | |
| 1381 | std::string solService{}; |
| 1382 | std::string solPathWitheEthName = solPath + ipmi::getChannelName(channel); |
| 1383 | |
| 1384 | if (ipmi::getService(ctx, solInterface, solPathWitheEthName, solService)) |
| 1385 | { |
| 1386 | log<level::ERR>("Set Sol Config - Invalid solInterface", |
| 1387 | entry("SERVICE=%s", solService.c_str()), |
| 1388 | entry("OBJPATH=%s", solPathWitheEthName.c_str()), |
| 1389 | entry("INTERFACE=%s", solInterface)); |
| 1390 | return responseInvalidFieldRequest(); |
| 1391 | } |
| 1392 | |
| 1393 | switch (static_cast<SolConfParam>(parameter)) |
| 1394 | { |
| 1395 | case SolConfParam::Progress: |
| 1396 | { |
| 1397 | uint8_t progress; |
| 1398 | if (req.unpack(progress) != 0 || !req.fullyUnpacked()) |
| 1399 | { |
| 1400 | return responseReqDataLenInvalid(); |
| 1401 | } |
| 1402 | |
| 1403 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1404 | solInterface, "Progress", progress)) |
| 1405 | { |
| 1406 | return responseUnspecifiedError(); |
| 1407 | } |
| 1408 | break; |
| 1409 | } |
| 1410 | case SolConfParam::Enable: |
| 1411 | { |
| 1412 | bool enable; |
| 1413 | uint7_t reserved2; |
| 1414 | |
| 1415 | if (req.unpack(enable, reserved2) != 0 || !req.fullyUnpacked()) |
| 1416 | { |
| 1417 | return responseReqDataLenInvalid(); |
| 1418 | } |
| 1419 | |
| 1420 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1421 | solInterface, "Enable", enable)) |
| 1422 | { |
| 1423 | return responseUnspecifiedError(); |
| 1424 | } |
| 1425 | break; |
| 1426 | } |
| 1427 | case SolConfParam::Authentication: |
| 1428 | { |
| 1429 | uint4_t privilegeBits{}; |
| 1430 | uint2_t reserved2{}; |
| 1431 | bool forceAuth = false; |
| 1432 | bool forceEncrypt = false; |
| 1433 | |
| 1434 | if (req.unpack(privilegeBits, reserved2, forceAuth, forceEncrypt) != |
| 1435 | 0 || |
| 1436 | !req.fullyUnpacked()) |
| 1437 | { |
| 1438 | return responseReqDataLenInvalid(); |
| 1439 | } |
| 1440 | |
| 1441 | uint8_t privilege = static_cast<uint8_t>(privilegeBits); |
Jonathan Doman | a48bf77 | 2023-05-26 17:54:57 -0700 | [diff] [blame] | 1442 | if (privilege < static_cast<uint8_t>(Privilege::User) || |
Jian Zhang | 23f4465 | 2022-03-17 17:13:10 +0800 | [diff] [blame] | 1443 | privilege > static_cast<uint8_t>(Privilege::Oem)) |
| 1444 | { |
| 1445 | return ipmi::responseInvalidFieldRequest(); |
| 1446 | } |
| 1447 | |
| 1448 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1449 | solInterface, "Privilege", privilege)) |
| 1450 | { |
| 1451 | return responseUnspecifiedError(); |
| 1452 | } |
| 1453 | |
| 1454 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1455 | solInterface, "ForceEncryption", |
| 1456 | forceEncrypt)) |
| 1457 | { |
| 1458 | return responseUnspecifiedError(); |
| 1459 | } |
| 1460 | |
| 1461 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1462 | solInterface, "ForceAuthentication", |
| 1463 | forceAuth)) |
| 1464 | { |
| 1465 | return responseUnspecifiedError(); |
| 1466 | } |
| 1467 | break; |
| 1468 | } |
| 1469 | case SolConfParam::Accumulate: |
| 1470 | { |
| 1471 | uint8_t interval; |
| 1472 | uint8_t threshold; |
| 1473 | if (req.unpack(interval, threshold) != 0 || !req.fullyUnpacked()) |
| 1474 | { |
| 1475 | return responseReqDataLenInvalid(); |
| 1476 | } |
| 1477 | |
| 1478 | if (threshold == 0) |
| 1479 | { |
| 1480 | return responseInvalidFieldRequest(); |
| 1481 | } |
| 1482 | |
| 1483 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1484 | solInterface, "AccumulateIntervalMS", |
| 1485 | interval)) |
| 1486 | { |
| 1487 | return responseUnspecifiedError(); |
| 1488 | } |
| 1489 | |
| 1490 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1491 | solInterface, "Threshold", threshold)) |
| 1492 | { |
| 1493 | return responseUnspecifiedError(); |
| 1494 | } |
| 1495 | break; |
| 1496 | } |
| 1497 | case SolConfParam::Retry: |
| 1498 | { |
| 1499 | uint3_t countBits; |
| 1500 | uint5_t reserved2; |
| 1501 | uint8_t interval; |
| 1502 | |
| 1503 | if (req.unpack(countBits, reserved2, interval) != 0 || |
| 1504 | !req.fullyUnpacked()) |
| 1505 | { |
| 1506 | return responseReqDataLenInvalid(); |
| 1507 | } |
| 1508 | |
| 1509 | uint8_t count = static_cast<uint8_t>(countBits); |
| 1510 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1511 | solInterface, "RetryCount", count)) |
| 1512 | { |
| 1513 | return responseUnspecifiedError(); |
| 1514 | } |
| 1515 | |
| 1516 | if (ipmi::setDbusProperty(ctx, solService, solPathWitheEthName, |
| 1517 | solInterface, "RetryIntervalMS", |
| 1518 | interval)) |
| 1519 | { |
| 1520 | return responseUnspecifiedError(); |
| 1521 | } |
| 1522 | break; |
| 1523 | } |
| 1524 | case SolConfParam::Port: |
| 1525 | { |
| 1526 | return response(ipmiCCWriteReadParameter); |
| 1527 | } |
| 1528 | case SolConfParam::NonVbitrate: |
| 1529 | case SolConfParam::Vbitrate: |
| 1530 | case SolConfParam::Channel: |
| 1531 | default: |
| 1532 | return response(ipmiCCParamNotSupported); |
| 1533 | } |
| 1534 | return responseSuccess(); |
| 1535 | } |
| 1536 | |
| 1537 | RspType<message::Payload> getSolConfParams(Context::ptr ctx, |
| 1538 | uint4_t channelBits, |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 1539 | uint3_t /*reserved*/, bool revOnly, |
| 1540 | uint8_t parameter, uint8_t /*set*/, |
| 1541 | uint8_t /*block*/) |
Jian Zhang | 23f4465 | 2022-03-17 17:13:10 +0800 | [diff] [blame] | 1542 | { |
| 1543 | message::Payload ret; |
| 1544 | constexpr uint8_t current_revision = 0x11; |
| 1545 | ret.pack(current_revision); |
| 1546 | if (revOnly) |
| 1547 | { |
| 1548 | return responseSuccess(std::move(ret)); |
| 1549 | } |
| 1550 | |
| 1551 | const uint8_t channel = convertCurrentChannelNum( |
| 1552 | static_cast<uint8_t>(channelBits), ctx->channel); |
| 1553 | |
| 1554 | if (!isValidChannel(channel)) |
| 1555 | { |
| 1556 | log<level::ERR>("Get Sol Config - Invalid channel in request"); |
| 1557 | return responseInvalidFieldRequest(); |
| 1558 | } |
| 1559 | |
| 1560 | std::string solService{}; |
| 1561 | std::string solPathWitheEthName = solPath + ipmi::getChannelName(channel); |
| 1562 | |
| 1563 | if (ipmi::getService(ctx, solInterface, solPathWitheEthName, solService)) |
| 1564 | { |
| 1565 | log<level::ERR>("Set Sol Config - Invalid solInterface", |
| 1566 | entry("SERVICE=%s", solService.c_str()), |
| 1567 | entry("OBJPATH=%s", solPathWitheEthName.c_str()), |
| 1568 | entry("INTERFACE=%s", solInterface)); |
| 1569 | return responseInvalidFieldRequest(); |
| 1570 | } |
| 1571 | |
| 1572 | switch (static_cast<SolConfParam>(parameter)) |
| 1573 | { |
| 1574 | case SolConfParam::Progress: |
| 1575 | { |
| 1576 | uint8_t progress; |
| 1577 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1578 | solInterface, "Progress", progress)) |
| 1579 | { |
| 1580 | return responseUnspecifiedError(); |
| 1581 | } |
| 1582 | ret.pack(progress); |
| 1583 | return responseSuccess(std::move(ret)); |
| 1584 | } |
| 1585 | case SolConfParam::Enable: |
| 1586 | { |
| 1587 | bool enable{}; |
| 1588 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1589 | solInterface, "Enable", enable)) |
| 1590 | { |
| 1591 | return responseUnspecifiedError(); |
| 1592 | } |
| 1593 | ret.pack(enable, uint7_t{}); |
| 1594 | return responseSuccess(std::move(ret)); |
| 1595 | } |
| 1596 | case SolConfParam::Authentication: |
| 1597 | { |
| 1598 | // 4bits, cast when pack |
| 1599 | uint8_t privilege; |
| 1600 | bool forceAuth = false; |
| 1601 | bool forceEncrypt = false; |
| 1602 | |
| 1603 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1604 | solInterface, "Privilege", privilege)) |
| 1605 | { |
| 1606 | return responseUnspecifiedError(); |
| 1607 | } |
| 1608 | |
| 1609 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1610 | solInterface, "ForceAuthentication", |
| 1611 | forceAuth)) |
| 1612 | { |
| 1613 | return responseUnspecifiedError(); |
| 1614 | } |
| 1615 | |
| 1616 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1617 | solInterface, "ForceEncryption", |
| 1618 | forceEncrypt)) |
| 1619 | { |
| 1620 | return responseUnspecifiedError(); |
| 1621 | } |
| 1622 | ret.pack(uint4_t{privilege}, uint2_t{}, forceAuth, forceEncrypt); |
| 1623 | return responseSuccess(std::move(ret)); |
| 1624 | } |
| 1625 | case SolConfParam::Accumulate: |
| 1626 | { |
| 1627 | uint8_t interval{}, threshold{}; |
| 1628 | |
| 1629 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1630 | solInterface, "AccumulateIntervalMS", |
| 1631 | interval)) |
| 1632 | { |
| 1633 | return responseUnspecifiedError(); |
| 1634 | } |
| 1635 | |
| 1636 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1637 | solInterface, "Threshold", threshold)) |
| 1638 | { |
| 1639 | return responseUnspecifiedError(); |
| 1640 | } |
| 1641 | ret.pack(interval, threshold); |
| 1642 | return responseSuccess(std::move(ret)); |
| 1643 | } |
| 1644 | case SolConfParam::Retry: |
| 1645 | { |
| 1646 | // 3bits, cast when cast |
| 1647 | uint8_t count{}; |
| 1648 | uint8_t interval{}; |
| 1649 | |
| 1650 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1651 | solInterface, "RetryCount", count)) |
| 1652 | { |
| 1653 | return responseUnspecifiedError(); |
| 1654 | } |
| 1655 | |
| 1656 | if (ipmi::getDbusProperty(ctx, solService, solPathWitheEthName, |
| 1657 | solInterface, "RetryIntervalMS", |
| 1658 | interval)) |
| 1659 | { |
| 1660 | return responseUnspecifiedError(); |
| 1661 | } |
| 1662 | ret.pack(uint3_t{count}, uint5_t{}, interval); |
| 1663 | return responseSuccess(std::move(ret)); |
| 1664 | } |
| 1665 | case SolConfParam::Port: |
| 1666 | { |
| 1667 | auto port = solDefaultPort; |
| 1668 | ret.pack(static_cast<uint16_t>(port)); |
| 1669 | return responseSuccess(std::move(ret)); |
| 1670 | } |
| 1671 | case SolConfParam::Channel: |
| 1672 | { |
| 1673 | ret.pack(channel); |
| 1674 | return responseSuccess(std::move(ret)); |
| 1675 | } |
| 1676 | case SolConfParam::NonVbitrate: |
Jonathan Doman | a48bf77 | 2023-05-26 17:54:57 -0700 | [diff] [blame] | 1677 | { |
| 1678 | uint64_t baudRate; |
| 1679 | uint8_t encodedBitRate = 0; |
| 1680 | if (ipmi::getDbusProperty( |
| 1681 | ctx, "xyz.openbmc_project.Console.default", |
| 1682 | "/xyz/openbmc_project/console/default", |
| 1683 | "xyz.openbmc_project.Console.UART", "Baud", baudRate)) |
| 1684 | { |
| 1685 | return ipmi::responseUnspecifiedError(); |
| 1686 | } |
| 1687 | switch (baudRate) |
| 1688 | { |
| 1689 | case 9600: |
| 1690 | encodedBitRate = 0x06; |
| 1691 | break; |
| 1692 | case 19200: |
| 1693 | encodedBitRate = 0x07; |
| 1694 | break; |
| 1695 | case 38400: |
| 1696 | encodedBitRate = 0x08; |
| 1697 | break; |
| 1698 | case 57600: |
| 1699 | encodedBitRate = 0x09; |
| 1700 | break; |
| 1701 | case 115200: |
| 1702 | encodedBitRate = 0x0a; |
| 1703 | break; |
| 1704 | default: |
| 1705 | break; |
| 1706 | } |
| 1707 | ret.pack(encodedBitRate); |
| 1708 | return responseSuccess(std::move(ret)); |
| 1709 | } |
Jian Zhang | 23f4465 | 2022-03-17 17:13:10 +0800 | [diff] [blame] | 1710 | case SolConfParam::Vbitrate: |
| 1711 | default: |
| 1712 | return response(ipmiCCParamNotSupported); |
| 1713 | } |
| 1714 | |
| 1715 | return response(ccParamNotSupported); |
| 1716 | } |
| 1717 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1718 | } // namespace transport |
| 1719 | } // namespace ipmi |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 1720 | |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1721 | void register_netfn_transport_functions() __attribute__((constructor)); |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 1722 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1723 | void register_netfn_transport_functions() |
| 1724 | { |
William A. Kennington III | c514d87 | 2019-04-06 18:19:38 -0700 | [diff] [blame] | 1725 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport, |
| 1726 | ipmi::transport::cmdSetLanConfigParameters, |
| 1727 | ipmi::Privilege::Admin, ipmi::transport::setLan); |
| 1728 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport, |
| 1729 | ipmi::transport::cmdGetLanConfigParameters, |
Johnathan Mantey | 34698d5 | 2019-11-19 14:47:30 -0800 | [diff] [blame] | 1730 | ipmi::Privilege::Operator, ipmi::transport::getLan); |
Jian Zhang | 23f4465 | 2022-03-17 17:13:10 +0800 | [diff] [blame] | 1731 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport, |
| 1732 | ipmi::transport::cmdSetSolConfigParameters, |
| 1733 | ipmi::Privilege::Admin, |
| 1734 | ipmi::transport::setSolConfParams); |
| 1735 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnTransport, |
| 1736 | ipmi::transport::cmdGetSolConfigParameters, |
| 1737 | ipmi::Privilege::User, |
| 1738 | ipmi::transport::getSolConfParams); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 1739 | } |