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