Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "app.hpp" |
| 19 | #include "dbus_singleton.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 20 | #include "dbus_utility.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "error_messages.hpp" |
| 22 | #include "health.hpp" |
| 23 | #include "query.hpp" |
| 24 | #include "registries/privilege_registry.hpp" |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 25 | #include "utils/ip_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 26 | #include "utils/json_utils.hpp" |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 27 | |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 28 | #include <boost/algorithm/string/classification.hpp> |
| 29 | #include <boost/algorithm/string/split.hpp> |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 30 | #include <boost/container/flat_set.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 31 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 32 | #include <array> |
Ed Tanous | a24526d | 2018-12-10 15:17:59 -0800 | [diff] [blame] | 33 | #include <optional> |
Joshi-Mansi | ab6554f | 2020-03-10 18:33:36 +0530 | [diff] [blame] | 34 | #include <regex> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 35 | #include <string_view> |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 36 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 37 | namespace redfish |
| 38 | { |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 39 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 40 | enum class LinkType |
| 41 | { |
| 42 | Local, |
| 43 | Global |
| 44 | }; |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Structure for keeping IPv4 data required by Redfish |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 48 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 49 | struct IPv4AddressData |
| 50 | { |
| 51 | std::string id; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 52 | std::string address; |
| 53 | std::string domain; |
| 54 | std::string gateway; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 55 | std::string netmask; |
| 56 | std::string origin; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 57 | LinkType linktype; |
Sunitha Harish | 01c6e85 | 2020-03-20 05:04:09 -0500 | [diff] [blame] | 58 | bool isActive; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 59 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 60 | bool operator<(const IPv4AddressData& obj) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 61 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 62 | return id < obj.id; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 63 | } |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /** |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 67 | * Structure for keeping IPv6 data required by Redfish |
| 68 | */ |
| 69 | struct IPv6AddressData |
| 70 | { |
| 71 | std::string id; |
| 72 | std::string address; |
| 73 | std::string origin; |
| 74 | uint8_t prefixLength; |
| 75 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 76 | bool operator<(const IPv6AddressData& obj) const |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 77 | { |
| 78 | return id < obj.id; |
| 79 | } |
| 80 | }; |
| 81 | /** |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 82 | * Structure for keeping basic single Ethernet Interface information |
| 83 | * available from DBus |
| 84 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 85 | struct EthernetInterfaceData |
| 86 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 87 | uint32_t speed; |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 88 | size_t mtuSize; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 89 | bool autoNeg; |
| 90 | bool dnsEnabled; |
| 91 | bool ntpEnabled; |
| 92 | bool hostNameEnabled; |
Johnathan Mantey | aa05fb2 | 2020-01-08 12:08:44 -0800 | [diff] [blame] | 93 | bool linkUp; |
Johnathan Mantey | eeedda2 | 2019-10-29 16:09:52 -0700 | [diff] [blame] | 94 | bool nicEnabled; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 95 | std::string dhcpEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 96 | std::string operatingMode; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 97 | std::string hostName; |
| 98 | std::string defaultGateway; |
| 99 | std::string ipv6DefaultGateway; |
| 100 | std::string macAddress; |
Jiaqing Zhao | 17e2202 | 2022-04-14 18:58:06 +0800 | [diff] [blame] | 101 | std::optional<uint32_t> vlanId; |
manojkiran.eda@gmail.com | 0f6efdc | 2019-10-03 04:53:44 -0500 | [diff] [blame] | 102 | std::vector<std::string> nameServers; |
| 103 | std::vector<std::string> staticNameServers; |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 104 | std::vector<std::string> domainnames; |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 107 | struct DHCPParameters |
| 108 | { |
| 109 | std::optional<bool> dhcpv4Enabled; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 110 | std::optional<bool> useDnsServers; |
| 111 | std::optional<bool> useNtpServers; |
| 112 | std::optional<bool> useDomainName; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 113 | std::optional<std::string> dhcpv6OperatingMode; |
| 114 | }; |
| 115 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 116 | // Helper function that changes bits netmask notation (i.e. /24) |
| 117 | // into full dot notation |
| 118 | inline std::string getNetmask(unsigned int bits) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 119 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 120 | uint32_t value = 0xffffffff << (32 - bits); |
| 121 | std::string netmask = std::to_string((value >> 24) & 0xff) + "." + |
| 122 | std::to_string((value >> 16) & 0xff) + "." + |
| 123 | std::to_string((value >> 8) & 0xff) + "." + |
| 124 | std::to_string(value & 0xff); |
| 125 | return netmask; |
| 126 | } |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 127 | |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 128 | inline bool translateDhcpEnabledToBool(const std::string& inputDHCP, |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 129 | bool isIPv4) |
| 130 | { |
| 131 | if (isIPv4) |
| 132 | { |
| 133 | return ( |
| 134 | (inputDHCP == |
| 135 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4") || |
| 136 | (inputDHCP == |
| 137 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both")); |
| 138 | } |
| 139 | return ((inputDHCP == |
| 140 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") || |
| 141 | (inputDHCP == |
| 142 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both")); |
| 143 | } |
| 144 | |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 145 | inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 146 | { |
| 147 | if (isIPv4 && isIPv6) |
| 148 | { |
| 149 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"; |
| 150 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 151 | if (isIPv4) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 152 | { |
| 153 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4"; |
| 154 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 155 | if (isIPv6) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 156 | { |
| 157 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6"; |
| 158 | } |
| 159 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none"; |
| 160 | } |
| 161 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 162 | inline std::string |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 163 | translateAddressOriginDbusToRedfish(const std::string& inputOrigin, |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 164 | bool isIPv4) |
| 165 | { |
| 166 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 167 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 168 | return "Static"; |
| 169 | } |
| 170 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal") |
| 171 | { |
| 172 | if (isIPv4) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 173 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 174 | return "IPv4LinkLocal"; |
| 175 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 176 | return "LinkLocal"; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 177 | } |
| 178 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP") |
| 179 | { |
| 180 | if (isIPv4) |
| 181 | { |
| 182 | return "DHCP"; |
| 183 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 184 | return "DHCPv6"; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 185 | } |
| 186 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC") |
| 187 | { |
| 188 | return "SLAAC"; |
| 189 | } |
| 190 | return ""; |
| 191 | } |
| 192 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 193 | inline bool extractEthernetInterfaceData( |
| 194 | const std::string& ethifaceId, |
| 195 | const dbus::utility::ManagedObjectType& dbusData, |
| 196 | EthernetInterfaceData& ethData) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 197 | { |
Ed Tanous | 4c9afe4 | 2019-05-03 16:59:57 -0700 | [diff] [blame] | 198 | bool idFound = false; |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 199 | for (const auto& objpath : dbusData) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 200 | { |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 201 | for (const auto& ifacePair : objpath.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 202 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 203 | if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 204 | { |
Ed Tanous | 4c9afe4 | 2019-05-03 16:59:57 -0700 | [diff] [blame] | 205 | idFound = true; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 206 | if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 207 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 208 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 209 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 210 | if (propertyPair.first == "MACAddress") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 211 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 212 | const std::string* mac = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 213 | std::get_if<std::string>(&propertyPair.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 214 | if (mac != nullptr) |
| 215 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 216 | ethData.macAddress = *mac; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 217 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 218 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN") |
| 222 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 223 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 224 | { |
| 225 | if (propertyPair.first == "Id") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 226 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 227 | const uint32_t* id = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 228 | std::get_if<uint32_t>(&propertyPair.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 229 | if (id != nullptr) |
| 230 | { |
Jiaqing Zhao | 17e2202 | 2022-04-14 18:58:06 +0800 | [diff] [blame] | 231 | ethData.vlanId = *id; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 232 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 233 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | else if (ifacePair.first == |
| 237 | "xyz.openbmc_project.Network.EthernetInterface") |
| 238 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 239 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 240 | { |
| 241 | if (propertyPair.first == "AutoNeg") |
| 242 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 243 | const bool* autoNeg = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 244 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 245 | if (autoNeg != nullptr) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 246 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 247 | ethData.autoNeg = *autoNeg; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | else if (propertyPair.first == "Speed") |
| 251 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 252 | const uint32_t* speed = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 253 | std::get_if<uint32_t>(&propertyPair.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 254 | if (speed != nullptr) |
| 255 | { |
| 256 | ethData.speed = *speed; |
| 257 | } |
| 258 | } |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 259 | else if (propertyPair.first == "MTU") |
| 260 | { |
| 261 | const uint32_t* mtuSize = |
| 262 | std::get_if<uint32_t>(&propertyPair.second); |
| 263 | if (mtuSize != nullptr) |
| 264 | { |
| 265 | ethData.mtuSize = *mtuSize; |
| 266 | } |
| 267 | } |
Johnathan Mantey | aa05fb2 | 2020-01-08 12:08:44 -0800 | [diff] [blame] | 268 | else if (propertyPair.first == "LinkUp") |
| 269 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 270 | const bool* linkUp = |
Johnathan Mantey | aa05fb2 | 2020-01-08 12:08:44 -0800 | [diff] [blame] | 271 | std::get_if<bool>(&propertyPair.second); |
| 272 | if (linkUp != nullptr) |
| 273 | { |
| 274 | ethData.linkUp = *linkUp; |
| 275 | } |
| 276 | } |
Johnathan Mantey | eeedda2 | 2019-10-29 16:09:52 -0700 | [diff] [blame] | 277 | else if (propertyPair.first == "NICEnabled") |
| 278 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 279 | const bool* nicEnabled = |
Johnathan Mantey | eeedda2 | 2019-10-29 16:09:52 -0700 | [diff] [blame] | 280 | std::get_if<bool>(&propertyPair.second); |
| 281 | if (nicEnabled != nullptr) |
| 282 | { |
| 283 | ethData.nicEnabled = *nicEnabled; |
| 284 | } |
| 285 | } |
RAJESWARAN THILLAIGOVINDAN | f85837b | 2019-04-04 05:18:53 -0500 | [diff] [blame] | 286 | else if (propertyPair.first == "Nameservers") |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 287 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 288 | const std::vector<std::string>* nameservers = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 289 | std::get_if<std::vector<std::string>>( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 290 | &propertyPair.second); |
| 291 | if (nameservers != nullptr) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 292 | { |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 293 | ethData.nameServers = *nameservers; |
manojkiran.eda@gmail.com | 0f6efdc | 2019-10-03 04:53:44 -0500 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | else if (propertyPair.first == "StaticNameServers") |
| 297 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 298 | const std::vector<std::string>* staticNameServers = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 299 | std::get_if<std::vector<std::string>>( |
manojkiran.eda@gmail.com | 0f6efdc | 2019-10-03 04:53:44 -0500 | [diff] [blame] | 300 | &propertyPair.second); |
| 301 | if (staticNameServers != nullptr) |
| 302 | { |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 303 | ethData.staticNameServers = *staticNameServers; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
manojkiraneda | 2a13328 | 2019-02-19 13:09:43 +0530 | [diff] [blame] | 306 | else if (propertyPair.first == "DHCPEnabled") |
| 307 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 308 | const std::string* dhcpEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 309 | std::get_if<std::string>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 310 | if (dhcpEnabled != nullptr) |
manojkiraneda | 2a13328 | 2019-02-19 13:09:43 +0530 | [diff] [blame] | 311 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 312 | ethData.dhcpEnabled = *dhcpEnabled; |
manojkiraneda | 2a13328 | 2019-02-19 13:09:43 +0530 | [diff] [blame] | 313 | } |
| 314 | } |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 315 | else if (propertyPair.first == "DomainName") |
| 316 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 317 | const std::vector<std::string>* domainNames = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 318 | std::get_if<std::vector<std::string>>( |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 319 | &propertyPair.second); |
| 320 | if (domainNames != nullptr) |
| 321 | { |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 322 | ethData.domainnames = *domainNames; |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 323 | } |
| 324 | } |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 325 | else if (propertyPair.first == "DefaultGateway") |
| 326 | { |
| 327 | const std::string* defaultGateway = |
| 328 | std::get_if<std::string>(&propertyPair.second); |
| 329 | if (defaultGateway != nullptr) |
| 330 | { |
| 331 | std::string defaultGatewayStr = *defaultGateway; |
| 332 | if (defaultGatewayStr.empty()) |
| 333 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 334 | ethData.defaultGateway = "0.0.0.0"; |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 335 | } |
| 336 | else |
| 337 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 338 | ethData.defaultGateway = defaultGatewayStr; |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | else if (propertyPair.first == "DefaultGateway6") |
| 343 | { |
| 344 | const std::string* defaultGateway6 = |
| 345 | std::get_if<std::string>(&propertyPair.second); |
| 346 | if (defaultGateway6 != nullptr) |
| 347 | { |
| 348 | std::string defaultGateway6Str = |
| 349 | *defaultGateway6; |
| 350 | if (defaultGateway6Str.empty()) |
| 351 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 352 | ethData.ipv6DefaultGateway = |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 353 | "0:0:0:0:0:0:0:0"; |
| 354 | } |
| 355 | else |
| 356 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 357 | ethData.ipv6DefaultGateway = |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 358 | defaultGateway6Str; |
| 359 | } |
| 360 | } |
| 361 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | } |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 365 | |
Jian Zhang | 1e3f85e | 2022-12-13 13:50:35 +0800 | [diff] [blame] | 366 | if (objpath.first == "/xyz/openbmc_project/network/dhcp") |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 367 | { |
| 368 | if (ifacePair.first == |
| 369 | "xyz.openbmc_project.Network.DHCPConfiguration") |
| 370 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 371 | for (const auto& propertyPair : ifacePair.second) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 372 | { |
| 373 | if (propertyPair.first == "DNSEnabled") |
| 374 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 375 | const bool* dnsEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 376 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 377 | if (dnsEnabled != nullptr) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 378 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 379 | ethData.dnsEnabled = *dnsEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | else if (propertyPair.first == "NTPEnabled") |
| 383 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 384 | const bool* ntpEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 385 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 386 | if (ntpEnabled != nullptr) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 387 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 388 | ethData.ntpEnabled = *ntpEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | else if (propertyPair.first == "HostNameEnabled") |
| 392 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 393 | const bool* hostNameEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 394 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 395 | if (hostNameEnabled != nullptr) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 396 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 397 | ethData.hostNameEnabled = *hostNameEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 398 | } |
| 399 | } |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 403 | // System configuration shows up in the global namespace, so no need |
| 404 | // to check eth number |
| 405 | if (ifacePair.first == |
| 406 | "xyz.openbmc_project.Network.SystemConfiguration") |
| 407 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 408 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 409 | { |
| 410 | if (propertyPair.first == "HostName") |
| 411 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 412 | const std::string* hostname = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 413 | std::get_if<std::string>(&propertyPair.second); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 414 | if (hostname != nullptr) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 415 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 416 | ethData.hostName = *hostname; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 417 | } |
| 418 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 422 | } |
Ed Tanous | 4c9afe4 | 2019-05-03 16:59:57 -0700 | [diff] [blame] | 423 | return idFound; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 426 | // Helper function that extracts data for single ethernet ipv6 address |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 427 | inline void |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 428 | extractIPV6Data(const std::string& ethifaceId, |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 429 | const dbus::utility::ManagedObjectType& dbusData, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 430 | boost::container::flat_set<IPv6AddressData>& ipv6Config) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 431 | { |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 432 | const std::string ipPathStart = |
| 433 | "/xyz/openbmc_project/network/" + ethifaceId; |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 434 | |
| 435 | // Since there might be several IPv6 configurations aligned with |
| 436 | // single ethernet interface, loop over all of them |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 437 | for (const auto& objpath : dbusData) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 438 | { |
| 439 | // Check if proper pattern for object path appears |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 440 | if (objpath.first.str.starts_with(ipPathStart + "/")) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 441 | { |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 442 | for (const auto& interface : objpath.second) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 443 | { |
| 444 | if (interface.first == "xyz.openbmc_project.Network.IP") |
| 445 | { |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 446 | auto type = std::find_if(interface.second.begin(), |
| 447 | interface.second.end(), |
| 448 | [](const auto& property) { |
| 449 | return property.first == "Type"; |
| 450 | }); |
| 451 | if (type == interface.second.end()) |
| 452 | { |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | const std::string* typeStr = |
| 457 | std::get_if<std::string>(&type->second); |
| 458 | |
| 459 | if (typeStr == nullptr || |
| 460 | (*typeStr != |
| 461 | "xyz.openbmc_project.Network.IP.Protocol.IPv6")) |
| 462 | { |
| 463 | continue; |
| 464 | } |
| 465 | |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 466 | // Instance IPv6AddressData structure, and set as |
| 467 | // appropriate |
| 468 | std::pair< |
| 469 | boost::container::flat_set<IPv6AddressData>::iterator, |
| 470 | bool> |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 471 | it = ipv6Config.insert(IPv6AddressData{}); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 472 | IPv6AddressData& ipv6Address = *it.first; |
| 473 | ipv6Address.id = |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 474 | objpath.first.str.substr(ipPathStart.size()); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 475 | for (const auto& property : interface.second) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 476 | { |
| 477 | if (property.first == "Address") |
| 478 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 479 | const std::string* address = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 480 | std::get_if<std::string>(&property.second); |
| 481 | if (address != nullptr) |
| 482 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 483 | ipv6Address.address = *address; |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | else if (property.first == "Origin") |
| 487 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 488 | const std::string* origin = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 489 | std::get_if<std::string>(&property.second); |
| 490 | if (origin != nullptr) |
| 491 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 492 | ipv6Address.origin = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 493 | translateAddressOriginDbusToRedfish(*origin, |
| 494 | false); |
| 495 | } |
| 496 | } |
| 497 | else if (property.first == "PrefixLength") |
| 498 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 499 | const uint8_t* prefix = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 500 | std::get_if<uint8_t>(&property.second); |
| 501 | if (prefix != nullptr) |
| 502 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 503 | ipv6Address.prefixLength = *prefix; |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 504 | } |
| 505 | } |
Asmitha Karunanithi | 889ff69 | 2021-11-29 08:43:30 -0600 | [diff] [blame] | 506 | else if (property.first == "Type" || |
| 507 | property.first == "Gateway") |
| 508 | { |
| 509 | // Type & Gateway is not used |
| 510 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 511 | else |
| 512 | { |
| 513 | BMCWEB_LOG_ERROR |
| 514 | << "Got extra property: " << property.first |
| 515 | << " on the " << objpath.first.str << " object"; |
| 516 | } |
| 517 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 524 | // Helper function that extracts data for single ethernet ipv4 address |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 525 | inline void |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 526 | extractIPData(const std::string& ethifaceId, |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 527 | const dbus::utility::ManagedObjectType& dbusData, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 528 | boost::container::flat_set<IPv4AddressData>& ipv4Config) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 529 | { |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 530 | const std::string ipPathStart = |
| 531 | "/xyz/openbmc_project/network/" + ethifaceId; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 532 | |
| 533 | // Since there might be several IPv4 configurations aligned with |
| 534 | // single ethernet interface, loop over all of them |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 535 | for (const auto& objpath : dbusData) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 536 | { |
| 537 | // Check if proper pattern for object path appears |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 538 | if (objpath.first.str.starts_with(ipPathStart + "/")) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 539 | { |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 540 | for (const auto& interface : objpath.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 541 | { |
| 542 | if (interface.first == "xyz.openbmc_project.Network.IP") |
| 543 | { |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 544 | auto type = std::find_if(interface.second.begin(), |
| 545 | interface.second.end(), |
| 546 | [](const auto& property) { |
| 547 | return property.first == "Type"; |
| 548 | }); |
| 549 | if (type == interface.second.end()) |
| 550 | { |
| 551 | continue; |
| 552 | } |
| 553 | |
| 554 | const std::string* typeStr = |
| 555 | std::get_if<std::string>(&type->second); |
| 556 | |
| 557 | if (typeStr == nullptr || |
| 558 | (*typeStr != |
| 559 | "xyz.openbmc_project.Network.IP.Protocol.IPv4")) |
| 560 | { |
| 561 | continue; |
| 562 | } |
| 563 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 564 | // Instance IPv4AddressData structure, and set as |
| 565 | // appropriate |
| 566 | std::pair< |
| 567 | boost::container::flat_set<IPv4AddressData>::iterator, |
| 568 | bool> |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 569 | it = ipv4Config.insert(IPv4AddressData{}); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 570 | IPv4AddressData& ipv4Address = *it.first; |
| 571 | ipv4Address.id = |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 572 | objpath.first.str.substr(ipPathStart.size()); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 573 | for (const auto& property : interface.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 574 | { |
| 575 | if (property.first == "Address") |
| 576 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 577 | const std::string* address = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 578 | std::get_if<std::string>(&property.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 579 | if (address != nullptr) |
| 580 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 581 | ipv4Address.address = *address; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 582 | } |
| 583 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 584 | else if (property.first == "Origin") |
| 585 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 586 | const std::string* origin = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 587 | std::get_if<std::string>(&property.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 588 | if (origin != nullptr) |
| 589 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 590 | ipv4Address.origin = |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 591 | translateAddressOriginDbusToRedfish(*origin, |
| 592 | true); |
| 593 | } |
| 594 | } |
| 595 | else if (property.first == "PrefixLength") |
| 596 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 597 | const uint8_t* mask = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 598 | std::get_if<uint8_t>(&property.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 599 | if (mask != nullptr) |
| 600 | { |
| 601 | // convert it to the string |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 602 | ipv4Address.netmask = getNetmask(*mask); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 603 | } |
| 604 | } |
Asmitha Karunanithi | 889ff69 | 2021-11-29 08:43:30 -0600 | [diff] [blame] | 605 | else if (property.first == "Type" || |
| 606 | property.first == "Gateway") |
| 607 | { |
| 608 | // Type & Gateway is not used |
| 609 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 610 | else |
| 611 | { |
| 612 | BMCWEB_LOG_ERROR |
| 613 | << "Got extra property: " << property.first |
| 614 | << " on the " << objpath.first.str << " object"; |
| 615 | } |
| 616 | } |
| 617 | // Check if given address is local, or global |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 618 | ipv4Address.linktype = |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 619 | ipv4Address.address.starts_with("169.254.") |
Johnathan Mantey | 18659d1 | 2019-06-07 10:26:29 -0700 | [diff] [blame] | 620 | ? LinkType::Local |
| 621 | : LinkType::Global; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | /** |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 629 | * @brief Deletes given IPv4 interface |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 630 | * |
| 631 | * @param[in] ifaceId Id of interface whose IP should be deleted |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 632 | * @param[in] ipHash DBus Hash id of IP that should be deleted |
| 633 | * @param[io] asyncResp Response object that will be returned to client |
| 634 | * |
| 635 | * @return None |
| 636 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 637 | inline void deleteIPv4(const std::string& ifaceId, const std::string& ipHash, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 638 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 639 | { |
| 640 | crow::connections::systemBus->async_method_call( |
Johnathan Mantey | 286b911 | 2019-06-10 13:38:04 -0700 | [diff] [blame] | 641 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 642 | if (ec) |
| 643 | { |
| 644 | messages::internalError(asyncResp->res); |
| 645 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 646 | }, |
| 647 | "xyz.openbmc_project.Network", |
| 648 | "/xyz/openbmc_project/network/" + ifaceId + "/ipv4/" + ipHash, |
| 649 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 650 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 651 | |
Gunnar Mills | 244b6d5 | 2021-04-12 15:44:23 -0500 | [diff] [blame] | 652 | inline void updateIPv4DefaultGateway( |
| 653 | const std::string& ifaceId, const std::string& gateway, |
| 654 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 655 | { |
| 656 | crow::connections::systemBus->async_method_call( |
| 657 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 658 | if (ec) |
| 659 | { |
| 660 | messages::internalError(asyncResp->res); |
| 661 | return; |
| 662 | } |
| 663 | asyncResp->res.result(boost::beast::http::status::no_content); |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 664 | }, |
| 665 | "xyz.openbmc_project.Network", |
| 666 | "/xyz/openbmc_project/network/" + ifaceId, |
| 667 | "org.freedesktop.DBus.Properties", "Set", |
| 668 | "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 669 | dbus::utility::DbusVariantType(gateway)); |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 670 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 671 | /** |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 672 | * @brief Creates a static IPv4 entry |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 673 | * |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 674 | * @param[in] ifaceId Id of interface upon which to create the IPv4 entry |
| 675 | * @param[in] prefixLength IPv4 prefix syntax for the subnet mask |
| 676 | * @param[in] gateway IPv4 address of this interfaces gateway |
| 677 | * @param[in] address IPv4 address to assign to this interface |
| 678 | * @param[io] asyncResp Response object that will be returned to client |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 679 | * |
| 680 | * @return None |
| 681 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 682 | inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength, |
| 683 | const std::string& gateway, const std::string& address, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 684 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 685 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 686 | auto createIpHandler = |
| 687 | [asyncResp, ifaceId, gateway](const boost::system::error_code ec) { |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 688 | if (ec) |
| 689 | { |
| 690 | messages::internalError(asyncResp->res); |
| 691 | return; |
| 692 | } |
| 693 | updateIPv4DefaultGateway(ifaceId, gateway, asyncResp); |
| 694 | }; |
| 695 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 696 | crow::connections::systemBus->async_method_call( |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 697 | std::move(createIpHandler), "xyz.openbmc_project.Network", |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 698 | "/xyz/openbmc_project/network/" + ifaceId, |
| 699 | "xyz.openbmc_project.Network.IP.Create", "IP", |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 700 | "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength, |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 701 | gateway); |
| 702 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 703 | |
| 704 | /** |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 705 | * @brief Deletes the IPv4 entry for this interface and creates a replacement |
| 706 | * static IPv4 entry |
| 707 | * |
| 708 | * @param[in] ifaceId Id of interface upon which to create the IPv4 entry |
| 709 | * @param[in] id The unique hash entry identifying the DBus entry |
| 710 | * @param[in] prefixLength IPv4 prefix syntax for the subnet mask |
| 711 | * @param[in] gateway IPv4 address of this interfaces gateway |
| 712 | * @param[in] address IPv4 address to assign to this interface |
| 713 | * @param[io] asyncResp Response object that will be returned to client |
| 714 | * |
| 715 | * @return None |
| 716 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 717 | inline void |
| 718 | deleteAndCreateIPv4(const std::string& ifaceId, const std::string& id, |
| 719 | uint8_t prefixLength, const std::string& gateway, |
| 720 | const std::string& address, |
| 721 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 722 | { |
| 723 | crow::connections::systemBus->async_method_call( |
| 724 | [asyncResp, ifaceId, address, prefixLength, |
| 725 | gateway](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 726 | if (ec) |
| 727 | { |
| 728 | messages::internalError(asyncResp->res); |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | crow::connections::systemBus->async_method_call( |
| 733 | [asyncResp, ifaceId, gateway](const boost::system::error_code ec2) { |
| 734 | if (ec2) |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 735 | { |
| 736 | messages::internalError(asyncResp->res); |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 737 | return; |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 738 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 739 | updateIPv4DefaultGateway(ifaceId, gateway, asyncResp); |
| 740 | }, |
| 741 | "xyz.openbmc_project.Network", |
| 742 | "/xyz/openbmc_project/network/" + ifaceId, |
| 743 | "xyz.openbmc_project.Network.IP.Create", "IP", |
| 744 | "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, |
| 745 | prefixLength, gateway); |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 746 | }, |
| 747 | "xyz.openbmc_project.Network", |
| 748 | +"/xyz/openbmc_project/network/" + ifaceId + "/ipv4/" + id, |
| 749 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 750 | } |
| 751 | |
| 752 | /** |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 753 | * @brief Deletes given IPv6 |
| 754 | * |
| 755 | * @param[in] ifaceId Id of interface whose IP should be deleted |
| 756 | * @param[in] ipHash DBus Hash id of IP that should be deleted |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 757 | * @param[io] asyncResp Response object that will be returned to client |
| 758 | * |
| 759 | * @return None |
| 760 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 761 | inline void deleteIPv6(const std::string& ifaceId, const std::string& ipHash, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 762 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 763 | { |
| 764 | crow::connections::systemBus->async_method_call( |
Johnathan Mantey | 286b911 | 2019-06-10 13:38:04 -0700 | [diff] [blame] | 765 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 766 | if (ec) |
| 767 | { |
| 768 | messages::internalError(asyncResp->res); |
| 769 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 770 | }, |
| 771 | "xyz.openbmc_project.Network", |
| 772 | "/xyz/openbmc_project/network/" + ifaceId + "/ipv6/" + ipHash, |
| 773 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 774 | } |
| 775 | |
| 776 | /** |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 777 | * @brief Deletes the IPv6 entry for this interface and creates a replacement |
| 778 | * static IPv6 entry |
| 779 | * |
| 780 | * @param[in] ifaceId Id of interface upon which to create the IPv6 entry |
| 781 | * @param[in] id The unique hash entry identifying the DBus entry |
| 782 | * @param[in] prefixLength IPv6 prefix syntax for the subnet mask |
| 783 | * @param[in] address IPv6 address to assign to this interface |
| 784 | * @param[io] asyncResp Response object that will be returned to client |
| 785 | * |
| 786 | * @return None |
| 787 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 788 | inline void |
| 789 | deleteAndCreateIPv6(const std::string& ifaceId, const std::string& id, |
| 790 | uint8_t prefixLength, const std::string& address, |
| 791 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 792 | { |
| 793 | crow::connections::systemBus->async_method_call( |
| 794 | [asyncResp, ifaceId, address, |
| 795 | prefixLength](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 796 | if (ec) |
| 797 | { |
| 798 | messages::internalError(asyncResp->res); |
| 799 | } |
| 800 | crow::connections::systemBus->async_method_call( |
| 801 | [asyncResp](const boost::system::error_code ec2) { |
| 802 | if (ec2) |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 803 | { |
| 804 | messages::internalError(asyncResp->res); |
| 805 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 806 | }, |
| 807 | "xyz.openbmc_project.Network", |
| 808 | "/xyz/openbmc_project/network/" + ifaceId, |
| 809 | "xyz.openbmc_project.Network.IP.Create", "IP", |
| 810 | "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, |
| 811 | prefixLength, ""); |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 812 | }, |
| 813 | "xyz.openbmc_project.Network", |
| 814 | +"/xyz/openbmc_project/network/" + ifaceId + "/ipv6/" + id, |
| 815 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 816 | } |
| 817 | |
| 818 | /** |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 819 | * @brief Creates IPv6 with given data |
| 820 | * |
| 821 | * @param[in] ifaceId Id of interface whose IP should be added |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 822 | * @param[in] prefixLength Prefix length that needs to be added |
| 823 | * @param[in] address IP address that needs to be added |
| 824 | * @param[io] asyncResp Response object that will be returned to client |
| 825 | * |
| 826 | * @return None |
| 827 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 828 | inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength, |
| 829 | const std::string& address, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 830 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 831 | { |
| 832 | auto createIpHandler = [asyncResp](const boost::system::error_code ec) { |
| 833 | if (ec) |
| 834 | { |
| 835 | messages::internalError(asyncResp->res); |
| 836 | } |
| 837 | }; |
| 838 | // Passing null for gateway, as per redfish spec IPv6StaticAddresses object |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 839 | // does not have associated gateway property |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 840 | crow::connections::systemBus->async_method_call( |
| 841 | std::move(createIpHandler), "xyz.openbmc_project.Network", |
| 842 | "/xyz/openbmc_project/network/" + ifaceId, |
| 843 | "xyz.openbmc_project.Network.IP.Create", "IP", |
| 844 | "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength, |
| 845 | ""); |
| 846 | } |
| 847 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 848 | /** |
| 849 | * Function that retrieves all properties for given Ethernet Interface |
| 850 | * Object |
| 851 | * from EntityManager Network Manager |
| 852 | * @param ethiface_id a eth interface id to query on DBus |
| 853 | * @param callback a function that shall be called to convert Dbus output |
| 854 | * into JSON |
| 855 | */ |
| 856 | template <typename CallbackFunc> |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 857 | void getEthernetIfaceData(const std::string& ethifaceId, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 858 | CallbackFunc&& callback) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 859 | { |
| 860 | crow::connections::systemBus->async_method_call( |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 861 | [ethifaceId{std::string{ethifaceId}}, |
| 862 | callback{std::forward<CallbackFunc>(callback)}]( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 863 | const boost::system::error_code errorCode, |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 864 | const dbus::utility::ManagedObjectType& resp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 865 | EthernetInterfaceData ethData{}; |
| 866 | boost::container::flat_set<IPv4AddressData> ipv4Data; |
| 867 | boost::container::flat_set<IPv6AddressData> ipv6Data; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 868 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 869 | if (errorCode) |
| 870 | { |
| 871 | callback(false, ethData, ipv4Data, ipv6Data); |
| 872 | return; |
| 873 | } |
| 874 | |
| 875 | bool found = extractEthernetInterfaceData(ethifaceId, resp, ethData); |
| 876 | if (!found) |
| 877 | { |
| 878 | callback(false, ethData, ipv4Data, ipv6Data); |
| 879 | return; |
| 880 | } |
| 881 | |
| 882 | extractIPData(ethifaceId, resp, ipv4Data); |
| 883 | // Fix global GW |
| 884 | for (IPv4AddressData& ipv4 : ipv4Data) |
| 885 | { |
| 886 | if (((ipv4.linktype == LinkType::Global) && |
| 887 | (ipv4.gateway == "0.0.0.0")) || |
| 888 | (ipv4.origin == "DHCP") || (ipv4.origin == "Static")) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 889 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 890 | ipv4.gateway = ethData.defaultGateway; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 891 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 892 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 893 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 894 | extractIPV6Data(ethifaceId, resp, ipv6Data); |
| 895 | // Finally make a callback with useful data |
| 896 | callback(true, ethData, ipv4Data, ipv6Data); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 897 | }, |
| 898 | "xyz.openbmc_project.Network", "/xyz/openbmc_project/network", |
| 899 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 900 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 901 | |
| 902 | /** |
| 903 | * Function that retrieves all Ethernet Interfaces available through Network |
| 904 | * Manager |
| 905 | * @param callback a function that shall be called to convert Dbus output |
| 906 | * into JSON. |
| 907 | */ |
| 908 | template <typename CallbackFunc> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 909 | void getEthernetIfaceList(CallbackFunc&& callback) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 910 | { |
| 911 | crow::connections::systemBus->async_method_call( |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 912 | [callback{std::forward<CallbackFunc>(callback)}]( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 913 | const boost::system::error_code errorCode, |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 914 | dbus::utility::ManagedObjectType& resp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 915 | // Callback requires vector<string> to retrieve all available |
| 916 | // ethernet interfaces |
| 917 | boost::container::flat_set<std::string> ifaceList; |
| 918 | ifaceList.reserve(resp.size()); |
| 919 | if (errorCode) |
| 920 | { |
| 921 | callback(false, ifaceList); |
| 922 | return; |
| 923 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 924 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 925 | // Iterate over all retrieved ObjectPaths. |
| 926 | for (const auto& objpath : resp) |
| 927 | { |
| 928 | // And all interfaces available for certain ObjectPath. |
| 929 | for (const auto& interface : objpath.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 930 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 931 | // If interface is |
| 932 | // xyz.openbmc_project.Network.EthernetInterface, this is |
| 933 | // what we're looking for. |
| 934 | if (interface.first == |
| 935 | "xyz.openbmc_project.Network.EthernetInterface") |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 936 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 937 | std::string ifaceId = objpath.first.filename(); |
| 938 | if (ifaceId.empty()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 939 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 940 | continue; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 941 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 942 | // and put it into output vector. |
| 943 | ifaceList.emplace(ifaceId); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 944 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 945 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 946 | } |
| 947 | // Finally make a callback with useful data |
| 948 | callback(true, ifaceList); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 949 | }, |
| 950 | "xyz.openbmc_project.Network", "/xyz/openbmc_project/network", |
| 951 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 952 | } |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 953 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 954 | inline void |
| 955 | handleHostnamePatch(const std::string& hostname, |
| 956 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 957 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 958 | // SHOULD handle host names of up to 255 characters(RFC 1123) |
| 959 | if (hostname.length() > 255) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 960 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 961 | messages::propertyValueFormatError(asyncResp->res, hostname, |
| 962 | "HostName"); |
| 963 | return; |
| 964 | } |
| 965 | crow::connections::systemBus->async_method_call( |
| 966 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 967 | if (ec) |
| 968 | { |
| 969 | messages::internalError(asyncResp->res); |
| 970 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 971 | }, |
| 972 | "xyz.openbmc_project.Network", "/xyz/openbmc_project/network/config", |
| 973 | "org.freedesktop.DBus.Properties", "Set", |
| 974 | "xyz.openbmc_project.Network.SystemConfiguration", "HostName", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 975 | dbus::utility::DbusVariantType(hostname)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 978 | inline void |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 979 | handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize, |
| 980 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 981 | { |
| 982 | sdbusplus::message::object_path objPath = |
| 983 | "/xyz/openbmc_project/network/" + ifaceId; |
| 984 | crow::connections::systemBus->async_method_call( |
| 985 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 986 | if (ec) |
| 987 | { |
| 988 | messages::internalError(asyncResp->res); |
| 989 | } |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 990 | }, |
| 991 | "xyz.openbmc_project.Network", objPath, |
| 992 | "org.freedesktop.DBus.Properties", "Set", |
| 993 | "xyz.openbmc_project.Network.EthernetInterface", "MTU", |
| 994 | std::variant<size_t>(mtuSize)); |
| 995 | } |
| 996 | |
| 997 | inline void |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 998 | handleDomainnamePatch(const std::string& ifaceId, |
| 999 | const std::string& domainname, |
| 1000 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1001 | { |
| 1002 | std::vector<std::string> vectorDomainname = {domainname}; |
| 1003 | crow::connections::systemBus->async_method_call( |
| 1004 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1005 | if (ec) |
| 1006 | { |
| 1007 | messages::internalError(asyncResp->res); |
| 1008 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1009 | }, |
| 1010 | "xyz.openbmc_project.Network", |
| 1011 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1012 | "org.freedesktop.DBus.Properties", "Set", |
| 1013 | "xyz.openbmc_project.Network.EthernetInterface", "DomainName", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1014 | dbus::utility::DbusVariantType(vectorDomainname)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1017 | inline bool isHostnameValid(const std::string& hostname) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1018 | { |
| 1019 | // A valid host name can never have the dotted-decimal form (RFC 1123) |
| 1020 | if (std::all_of(hostname.begin(), hostname.end(), ::isdigit)) |
| 1021 | { |
| 1022 | return false; |
| 1023 | } |
| 1024 | // Each label(hostname/subdomains) within a valid FQDN |
| 1025 | // MUST handle host names of up to 63 characters (RFC 1123) |
| 1026 | // labels cannot start or end with hyphens (RFC 952) |
| 1027 | // labels can start with numbers (RFC 1123) |
| 1028 | const std::regex pattern( |
| 1029 | "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$"); |
| 1030 | |
| 1031 | return std::regex_match(hostname, pattern); |
| 1032 | } |
| 1033 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1034 | inline bool isDomainnameValid(const std::string& domainname) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1035 | { |
| 1036 | // Can have multiple subdomains |
| 1037 | // Top Level Domain's min length is 2 character |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1038 | const std::regex pattern( |
| 1039 | "^([A-Za-z0-9][a-zA-Z0-9\\-]{1,61}|[a-zA-Z0-9]{1,30}\\.)*[a-zA-Z]{2,}$"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1040 | |
| 1041 | return std::regex_match(domainname, pattern); |
| 1042 | } |
| 1043 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1044 | inline void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn, |
| 1045 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1046 | { |
| 1047 | // Total length of FQDN must not exceed 255 characters(RFC 1035) |
| 1048 | if (fqdn.length() > 255) |
| 1049 | { |
| 1050 | messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN"); |
| 1051 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1054 | size_t pos = fqdn.find('.'); |
| 1055 | if (pos == std::string::npos) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1056 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1057 | messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN"); |
| 1058 | return; |
| 1059 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1060 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1061 | std::string hostname; |
| 1062 | std::string domainname; |
| 1063 | domainname = (fqdn).substr(pos + 1); |
| 1064 | hostname = (fqdn).substr(0, pos); |
| 1065 | |
| 1066 | if (!isHostnameValid(hostname) || !isDomainnameValid(domainname)) |
| 1067 | { |
| 1068 | messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN"); |
| 1069 | return; |
| 1070 | } |
| 1071 | |
| 1072 | handleHostnamePatch(hostname, asyncResp); |
| 1073 | handleDomainnamePatch(ifaceId, domainname, asyncResp); |
| 1074 | } |
| 1075 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1076 | inline void |
| 1077 | handleMACAddressPatch(const std::string& ifaceId, |
| 1078 | const std::string& macAddress, |
| 1079 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1080 | { |
Johnathan Mantey | 58283f4 | 2022-08-15 14:38:36 -0700 | [diff] [blame] | 1081 | static constexpr std::string_view dbusNotAllowedError = |
| 1082 | "xyz.openbmc_project.Common.Error.NotAllowed"; |
| 1083 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1084 | crow::connections::systemBus->async_method_call( |
Johnathan Mantey | 58283f4 | 2022-08-15 14:38:36 -0700 | [diff] [blame] | 1085 | [asyncResp, macAddress](const boost::system::error_code ec, |
Patrick Williams | 5b37854 | 2022-11-26 09:41:59 -0600 | [diff] [blame] | 1086 | const sdbusplus::message_t& msg) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1087 | if (ec) |
| 1088 | { |
Johnathan Mantey | 58283f4 | 2022-08-15 14:38:36 -0700 | [diff] [blame] | 1089 | const sd_bus_error* err = msg.get_error(); |
| 1090 | if (err == nullptr) |
| 1091 | { |
| 1092 | messages::internalError(asyncResp->res); |
| 1093 | return; |
| 1094 | } |
| 1095 | if (err->name == dbusNotAllowedError) |
| 1096 | { |
| 1097 | messages::propertyNotWritable(asyncResp->res, "MACAddress"); |
| 1098 | return; |
| 1099 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1100 | messages::internalError(asyncResp->res); |
| 1101 | return; |
| 1102 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1103 | }, |
| 1104 | "xyz.openbmc_project.Network", |
| 1105 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1106 | "org.freedesktop.DBus.Properties", "Set", |
| 1107 | "xyz.openbmc_project.Network.MACAddress", "MACAddress", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1108 | dbus::utility::DbusVariantType(macAddress)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1111 | inline void setDHCPEnabled(const std::string& ifaceId, |
| 1112 | const std::string& propertyName, const bool v4Value, |
| 1113 | const bool v6Value, |
| 1114 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1115 | { |
| 1116 | const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value); |
| 1117 | crow::connections::systemBus->async_method_call( |
| 1118 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1119 | if (ec) |
| 1120 | { |
| 1121 | BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; |
| 1122 | messages::internalError(asyncResp->res); |
| 1123 | return; |
| 1124 | } |
| 1125 | messages::success(asyncResp->res); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1126 | }, |
| 1127 | "xyz.openbmc_project.Network", |
| 1128 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1129 | "org.freedesktop.DBus.Properties", "Set", |
| 1130 | "xyz.openbmc_project.Network.EthernetInterface", propertyName, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1131 | dbus::utility::DbusVariantType{dhcp}); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1134 | inline void setEthernetInterfaceBoolProperty( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1135 | const std::string& ifaceId, const std::string& propertyName, |
| 1136 | const bool& value, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1137 | { |
| 1138 | crow::connections::systemBus->async_method_call( |
| 1139 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1140 | if (ec) |
| 1141 | { |
| 1142 | BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; |
| 1143 | messages::internalError(asyncResp->res); |
| 1144 | return; |
| 1145 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1146 | }, |
| 1147 | "xyz.openbmc_project.Network", |
| 1148 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1149 | "org.freedesktop.DBus.Properties", "Set", |
| 1150 | "xyz.openbmc_project.Network.EthernetInterface", propertyName, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1151 | dbus::utility::DbusVariantType{value}); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1154 | inline void setDHCPv4Config(const std::string& propertyName, const bool& value, |
| 1155 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1156 | { |
| 1157 | BMCWEB_LOG_DEBUG << propertyName << " = " << value; |
| 1158 | crow::connections::systemBus->async_method_call( |
| 1159 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1160 | if (ec) |
| 1161 | { |
| 1162 | BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; |
| 1163 | messages::internalError(asyncResp->res); |
| 1164 | return; |
| 1165 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1166 | }, |
Jian Zhang | 1e3f85e | 2022-12-13 13:50:35 +0800 | [diff] [blame] | 1167 | "xyz.openbmc_project.Network", "/xyz/openbmc_project/network/dhcp", |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1168 | "org.freedesktop.DBus.Properties", "Set", |
| 1169 | "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1170 | dbus::utility::DbusVariantType{value}); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1173 | inline void handleDHCPPatch(const std::string& ifaceId, |
| 1174 | const EthernetInterfaceData& ethData, |
| 1175 | const DHCPParameters& v4dhcpParms, |
| 1176 | const DHCPParameters& v6dhcpParms, |
| 1177 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1178 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1179 | bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true); |
| 1180 | bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1181 | |
| 1182 | bool nextv4DHCPState = |
| 1183 | v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active; |
| 1184 | |
| 1185 | bool nextv6DHCPState{}; |
| 1186 | if (v6dhcpParms.dhcpv6OperatingMode) |
| 1187 | { |
| 1188 | if ((*v6dhcpParms.dhcpv6OperatingMode != "Stateful") && |
| 1189 | (*v6dhcpParms.dhcpv6OperatingMode != "Stateless") && |
| 1190 | (*v6dhcpParms.dhcpv6OperatingMode != "Disabled")) |
| 1191 | { |
| 1192 | messages::propertyValueFormatError(asyncResp->res, |
| 1193 | *v6dhcpParms.dhcpv6OperatingMode, |
| 1194 | "OperatingMode"); |
| 1195 | return; |
| 1196 | } |
| 1197 | nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Stateful"); |
| 1198 | } |
| 1199 | else |
| 1200 | { |
| 1201 | nextv6DHCPState = ipv6Active; |
| 1202 | } |
| 1203 | |
| 1204 | bool nextDNS{}; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1205 | if (v4dhcpParms.useDnsServers && v6dhcpParms.useDnsServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1206 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1207 | if (*v4dhcpParms.useDnsServers != *v6dhcpParms.useDnsServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1208 | { |
| 1209 | messages::generalError(asyncResp->res); |
| 1210 | return; |
| 1211 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1212 | nextDNS = *v4dhcpParms.useDnsServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1213 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1214 | else if (v4dhcpParms.useDnsServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1215 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1216 | nextDNS = *v4dhcpParms.useDnsServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1217 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1218 | else if (v6dhcpParms.useDnsServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1219 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1220 | nextDNS = *v6dhcpParms.useDnsServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1221 | } |
| 1222 | else |
| 1223 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1224 | nextDNS = ethData.dnsEnabled; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | bool nextNTP{}; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1228 | if (v4dhcpParms.useNtpServers && v6dhcpParms.useNtpServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1229 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1230 | if (*v4dhcpParms.useNtpServers != *v6dhcpParms.useNtpServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1231 | { |
| 1232 | messages::generalError(asyncResp->res); |
| 1233 | return; |
| 1234 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1235 | nextNTP = *v4dhcpParms.useNtpServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1236 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1237 | else if (v4dhcpParms.useNtpServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1238 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1239 | nextNTP = *v4dhcpParms.useNtpServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1240 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1241 | else if (v6dhcpParms.useNtpServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1242 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1243 | nextNTP = *v6dhcpParms.useNtpServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1244 | } |
| 1245 | else |
| 1246 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1247 | nextNTP = ethData.ntpEnabled; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | bool nextUseDomain{}; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1251 | if (v4dhcpParms.useDomainName && v6dhcpParms.useDomainName) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1252 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1253 | if (*v4dhcpParms.useDomainName != *v6dhcpParms.useDomainName) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1254 | { |
| 1255 | messages::generalError(asyncResp->res); |
| 1256 | return; |
| 1257 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1258 | nextUseDomain = *v4dhcpParms.useDomainName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1259 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1260 | else if (v4dhcpParms.useDomainName) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1261 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1262 | nextUseDomain = *v4dhcpParms.useDomainName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1263 | } |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1264 | else if (v6dhcpParms.useDomainName) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1265 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1266 | nextUseDomain = *v6dhcpParms.useDomainName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1267 | } |
| 1268 | else |
| 1269 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1270 | nextUseDomain = ethData.hostNameEnabled; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | BMCWEB_LOG_DEBUG << "set DHCPEnabled..."; |
| 1274 | setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState, |
| 1275 | asyncResp); |
| 1276 | BMCWEB_LOG_DEBUG << "set DNSEnabled..."; |
| 1277 | setDHCPv4Config("DNSEnabled", nextDNS, asyncResp); |
| 1278 | BMCWEB_LOG_DEBUG << "set NTPEnabled..."; |
| 1279 | setDHCPv4Config("NTPEnabled", nextNTP, asyncResp); |
| 1280 | BMCWEB_LOG_DEBUG << "set HostNameEnabled..."; |
| 1281 | setDHCPv4Config("HostNameEnabled", nextUseDomain, asyncResp); |
| 1282 | } |
| 1283 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1284 | inline boost::container::flat_set<IPv4AddressData>::const_iterator |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1285 | getNextStaticIpEntry( |
| 1286 | const boost::container::flat_set<IPv4AddressData>::const_iterator& head, |
| 1287 | const boost::container::flat_set<IPv4AddressData>::const_iterator& end) |
| 1288 | { |
| 1289 | return std::find_if(head, end, [](const IPv4AddressData& value) { |
| 1290 | return value.origin == "Static"; |
| 1291 | }); |
| 1292 | } |
| 1293 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1294 | inline boost::container::flat_set<IPv6AddressData>::const_iterator |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1295 | getNextStaticIpEntry( |
| 1296 | const boost::container::flat_set<IPv6AddressData>::const_iterator& head, |
| 1297 | const boost::container::flat_set<IPv6AddressData>::const_iterator& end) |
| 1298 | { |
| 1299 | return std::find_if(head, end, [](const IPv6AddressData& value) { |
| 1300 | return value.origin == "Static"; |
| 1301 | }); |
| 1302 | } |
| 1303 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1304 | inline void handleIPv4StaticPatch( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1305 | const std::string& ifaceId, nlohmann::json& input, |
| 1306 | const boost::container::flat_set<IPv4AddressData>& ipv4Data, |
| 1307 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1308 | { |
| 1309 | if ((!input.is_array()) || input.empty()) |
| 1310 | { |
| 1311 | messages::propertyValueTypeError( |
| 1312 | asyncResp->res, |
| 1313 | input.dump(2, ' ', true, nlohmann::json::error_handler_t::replace), |
| 1314 | "IPv4StaticAddresses"); |
| 1315 | return; |
| 1316 | } |
| 1317 | |
| 1318 | unsigned entryIdx = 1; |
| 1319 | // Find the first static IP address currently active on the NIC and |
| 1320 | // match it to the first JSON element in the IPv4StaticAddresses array. |
| 1321 | // Match each subsequent JSON element to the next static IP programmed |
| 1322 | // into the NIC. |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1323 | boost::container::flat_set<IPv4AddressData>::const_iterator nicIpEntry = |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1324 | getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend()); |
| 1325 | |
| 1326 | for (nlohmann::json& thisJson : input) |
| 1327 | { |
| 1328 | std::string pathString = |
| 1329 | "IPv4StaticAddresses/" + std::to_string(entryIdx); |
| 1330 | |
| 1331 | if (!thisJson.is_null() && !thisJson.empty()) |
| 1332 | { |
| 1333 | std::optional<std::string> address; |
| 1334 | std::optional<std::string> subnetMask; |
| 1335 | std::optional<std::string> gateway; |
| 1336 | |
| 1337 | if (!json_util::readJson(thisJson, asyncResp->res, "Address", |
| 1338 | address, "SubnetMask", subnetMask, |
| 1339 | "Gateway", gateway)) |
| 1340 | { |
| 1341 | messages::propertyValueFormatError( |
| 1342 | asyncResp->res, |
| 1343 | thisJson.dump(2, ' ', true, |
| 1344 | nlohmann::json::error_handler_t::replace), |
| 1345 | pathString); |
| 1346 | return; |
| 1347 | } |
| 1348 | |
| 1349 | // Find the address/subnet/gateway values. Any values that are |
| 1350 | // not explicitly provided are assumed to be unmodified from the |
| 1351 | // current state of the interface. Merge existing state into the |
| 1352 | // current request. |
| 1353 | const std::string* addr = nullptr; |
| 1354 | const std::string* gw = nullptr; |
| 1355 | uint8_t prefixLength = 0; |
| 1356 | bool errorInEntry = false; |
| 1357 | if (address) |
| 1358 | { |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 1359 | if (ip_util::ipv4VerifyIpAndGetBitcount(*address)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1360 | { |
| 1361 | addr = &(*address); |
| 1362 | } |
| 1363 | else |
| 1364 | { |
| 1365 | messages::propertyValueFormatError(asyncResp->res, *address, |
| 1366 | pathString + "/Address"); |
| 1367 | errorInEntry = true; |
| 1368 | } |
| 1369 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1370 | else if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1371 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1372 | addr = &(nicIpEntry->address); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1373 | } |
| 1374 | else |
| 1375 | { |
| 1376 | messages::propertyMissing(asyncResp->res, |
| 1377 | pathString + "/Address"); |
| 1378 | errorInEntry = true; |
| 1379 | } |
| 1380 | |
| 1381 | if (subnetMask) |
| 1382 | { |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 1383 | if (!ip_util::ipv4VerifyIpAndGetBitcount(*subnetMask, |
| 1384 | &prefixLength)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1385 | { |
| 1386 | messages::propertyValueFormatError( |
| 1387 | asyncResp->res, *subnetMask, |
| 1388 | pathString + "/SubnetMask"); |
| 1389 | errorInEntry = true; |
| 1390 | } |
| 1391 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1392 | else if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1393 | { |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 1394 | if (!ip_util::ipv4VerifyIpAndGetBitcount(nicIpEntry->netmask, |
| 1395 | &prefixLength)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1396 | { |
| 1397 | messages::propertyValueFormatError( |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1398 | asyncResp->res, nicIpEntry->netmask, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1399 | pathString + "/SubnetMask"); |
| 1400 | errorInEntry = true; |
| 1401 | } |
| 1402 | } |
| 1403 | else |
| 1404 | { |
| 1405 | messages::propertyMissing(asyncResp->res, |
| 1406 | pathString + "/SubnetMask"); |
| 1407 | errorInEntry = true; |
| 1408 | } |
| 1409 | |
| 1410 | if (gateway) |
| 1411 | { |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 1412 | if (ip_util::ipv4VerifyIpAndGetBitcount(*gateway)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1413 | { |
| 1414 | gw = &(*gateway); |
| 1415 | } |
| 1416 | else |
| 1417 | { |
| 1418 | messages::propertyValueFormatError(asyncResp->res, *gateway, |
| 1419 | pathString + "/Gateway"); |
| 1420 | errorInEntry = true; |
| 1421 | } |
| 1422 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1423 | else if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1424 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1425 | gw = &nicIpEntry->gateway; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1426 | } |
| 1427 | else |
| 1428 | { |
| 1429 | messages::propertyMissing(asyncResp->res, |
| 1430 | pathString + "/Gateway"); |
| 1431 | errorInEntry = true; |
| 1432 | } |
| 1433 | |
| 1434 | if (errorInEntry) |
| 1435 | { |
| 1436 | return; |
| 1437 | } |
| 1438 | |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1439 | if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1440 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1441 | deleteAndCreateIPv4(ifaceId, nicIpEntry->id, prefixLength, *gw, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1442 | *addr, asyncResp); |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1443 | nicIpEntry = |
| 1444 | getNextStaticIpEntry(++nicIpEntry, ipv4Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1445 | } |
| 1446 | else |
| 1447 | { |
| 1448 | createIPv4(ifaceId, prefixLength, *gateway, *address, |
| 1449 | asyncResp); |
| 1450 | } |
| 1451 | entryIdx++; |
| 1452 | } |
| 1453 | else |
| 1454 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1455 | if (nicIpEntry == ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1456 | { |
| 1457 | // Requesting a DELETE/DO NOT MODIFY action for an item |
| 1458 | // that isn't present on the eth(n) interface. Input JSON is |
| 1459 | // in error, so bail out. |
| 1460 | if (thisJson.is_null()) |
| 1461 | { |
| 1462 | messages::resourceCannotBeDeleted(asyncResp->res); |
| 1463 | return; |
| 1464 | } |
| 1465 | messages::propertyValueFormatError( |
| 1466 | asyncResp->res, |
| 1467 | thisJson.dump(2, ' ', true, |
| 1468 | nlohmann::json::error_handler_t::replace), |
| 1469 | pathString); |
| 1470 | return; |
| 1471 | } |
| 1472 | |
| 1473 | if (thisJson.is_null()) |
| 1474 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1475 | deleteIPv4(ifaceId, nicIpEntry->id, asyncResp); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1476 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1477 | if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1478 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1479 | nicIpEntry = |
| 1480 | getNextStaticIpEntry(++nicIpEntry, ipv4Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1481 | } |
| 1482 | entryIdx++; |
| 1483 | } |
| 1484 | } |
| 1485 | } |
| 1486 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1487 | inline void handleStaticNameServersPatch( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1488 | const std::string& ifaceId, |
| 1489 | const std::vector<std::string>& updatedStaticNameServers, |
| 1490 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1491 | { |
| 1492 | crow::connections::systemBus->async_method_call( |
| 1493 | [asyncResp](const boost::system::error_code ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1494 | if (ec) |
| 1495 | { |
| 1496 | messages::internalError(asyncResp->res); |
| 1497 | return; |
| 1498 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1499 | }, |
| 1500 | "xyz.openbmc_project.Network", |
| 1501 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1502 | "org.freedesktop.DBus.Properties", "Set", |
| 1503 | "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1504 | dbus::utility::DbusVariantType{updatedStaticNameServers}); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1507 | inline void handleIPv6StaticAddressesPatch( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1508 | const std::string& ifaceId, const nlohmann::json& input, |
| 1509 | const boost::container::flat_set<IPv6AddressData>& ipv6Data, |
| 1510 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1511 | { |
| 1512 | if (!input.is_array() || input.empty()) |
| 1513 | { |
| 1514 | messages::propertyValueTypeError( |
| 1515 | asyncResp->res, |
| 1516 | input.dump(2, ' ', true, nlohmann::json::error_handler_t::replace), |
| 1517 | "IPv6StaticAddresses"); |
| 1518 | return; |
| 1519 | } |
| 1520 | size_t entryIdx = 1; |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1521 | boost::container::flat_set<IPv6AddressData>::const_iterator nicIpEntry = |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1522 | getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend()); |
| 1523 | for (const nlohmann::json& thisJson : input) |
| 1524 | { |
| 1525 | std::string pathString = |
| 1526 | "IPv6StaticAddresses/" + std::to_string(entryIdx); |
| 1527 | |
| 1528 | if (!thisJson.is_null() && !thisJson.empty()) |
| 1529 | { |
| 1530 | std::optional<std::string> address; |
| 1531 | std::optional<uint8_t> prefixLength; |
| 1532 | nlohmann::json thisJsonCopy = thisJson; |
| 1533 | if (!json_util::readJson(thisJsonCopy, asyncResp->res, "Address", |
| 1534 | address, "PrefixLength", prefixLength)) |
| 1535 | { |
| 1536 | messages::propertyValueFormatError( |
| 1537 | asyncResp->res, |
| 1538 | thisJson.dump(2, ' ', true, |
| 1539 | nlohmann::json::error_handler_t::replace), |
| 1540 | pathString); |
| 1541 | return; |
| 1542 | } |
| 1543 | |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 1544 | const std::string* addr = nullptr; |
| 1545 | uint8_t prefix = 0; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1546 | |
| 1547 | // Find the address and prefixLength values. Any values that are |
| 1548 | // not explicitly provided are assumed to be unmodified from the |
| 1549 | // current state of the interface. Merge existing state into the |
| 1550 | // current request. |
| 1551 | if (address) |
| 1552 | { |
| 1553 | addr = &(*address); |
| 1554 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1555 | else if (nicIpEntry != ipv6Data.end()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1556 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1557 | addr = &(nicIpEntry->address); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1558 | } |
| 1559 | else |
| 1560 | { |
| 1561 | messages::propertyMissing(asyncResp->res, |
| 1562 | pathString + "/Address"); |
| 1563 | return; |
| 1564 | } |
| 1565 | |
| 1566 | if (prefixLength) |
| 1567 | { |
| 1568 | prefix = *prefixLength; |
| 1569 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1570 | else if (nicIpEntry != ipv6Data.end()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1571 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1572 | prefix = nicIpEntry->prefixLength; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1573 | } |
| 1574 | else |
| 1575 | { |
| 1576 | messages::propertyMissing(asyncResp->res, |
| 1577 | pathString + "/PrefixLength"); |
| 1578 | return; |
| 1579 | } |
| 1580 | |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1581 | if (nicIpEntry != ipv6Data.end()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1582 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1583 | deleteAndCreateIPv6(ifaceId, nicIpEntry->id, prefix, *addr, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1584 | asyncResp); |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1585 | nicIpEntry = |
| 1586 | getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1587 | } |
| 1588 | else |
| 1589 | { |
| 1590 | createIPv6(ifaceId, *prefixLength, *addr, asyncResp); |
| 1591 | } |
| 1592 | entryIdx++; |
| 1593 | } |
| 1594 | else |
| 1595 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1596 | if (nicIpEntry == ipv6Data.end()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1597 | { |
| 1598 | // Requesting a DELETE/DO NOT MODIFY action for an item |
| 1599 | // that isn't present on the eth(n) interface. Input JSON is |
| 1600 | // in error, so bail out. |
| 1601 | if (thisJson.is_null()) |
| 1602 | { |
| 1603 | messages::resourceCannotBeDeleted(asyncResp->res); |
| 1604 | return; |
| 1605 | } |
| 1606 | messages::propertyValueFormatError( |
| 1607 | asyncResp->res, |
| 1608 | thisJson.dump(2, ' ', true, |
| 1609 | nlohmann::json::error_handler_t::replace), |
| 1610 | pathString); |
| 1611 | return; |
| 1612 | } |
| 1613 | |
| 1614 | if (thisJson.is_null()) |
| 1615 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1616 | deleteIPv6(ifaceId, nicIpEntry->id, asyncResp); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1617 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1618 | if (nicIpEntry != ipv6Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1619 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1620 | nicIpEntry = |
| 1621 | getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1622 | } |
| 1623 | entryIdx++; |
| 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1628 | inline void parseInterfaceData( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1629 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1630 | const std::string& ifaceId, const EthernetInterfaceData& ethData, |
| 1631 | const boost::container::flat_set<IPv4AddressData>& ipv4Data, |
| 1632 | const boost::container::flat_set<IPv6AddressData>& ipv6Data) |
| 1633 | { |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1634 | constexpr std::array<std::string_view, 1> inventoryForEthernet = { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1635 | "xyz.openbmc_project.Inventory.Item.Ethernet"}; |
| 1636 | |
| 1637 | nlohmann::json& jsonResponse = asyncResp->res.jsonValue; |
| 1638 | jsonResponse["Id"] = ifaceId; |
| 1639 | jsonResponse["@odata.id"] = |
| 1640 | "/redfish/v1/Managers/bmc/EthernetInterfaces/" + ifaceId; |
| 1641 | jsonResponse["InterfaceEnabled"] = ethData.nicEnabled; |
| 1642 | |
| 1643 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 1644 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1645 | dbus::utility::getSubTreePaths( |
| 1646 | "/", 0, inventoryForEthernet, |
| 1647 | [health](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1648 | const dbus::utility::MapperGetSubTreePathsResponse& resp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1649 | if (ec) |
| 1650 | { |
| 1651 | return; |
| 1652 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1653 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1654 | health->inventory = resp; |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 1655 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1656 | |
| 1657 | health->populate(); |
| 1658 | |
| 1659 | if (ethData.nicEnabled) |
| 1660 | { |
Johnathan Mantey | 0ef0e28 | 2022-11-15 12:15:02 -0800 | [diff] [blame] | 1661 | jsonResponse["LinkStatus"] = ethData.linkUp ? "LinkUp" : "LinkDown"; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1662 | jsonResponse["Status"]["State"] = "Enabled"; |
| 1663 | } |
| 1664 | else |
| 1665 | { |
| 1666 | jsonResponse["LinkStatus"] = "NoLink"; |
| 1667 | jsonResponse["Status"]["State"] = "Disabled"; |
| 1668 | } |
| 1669 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1670 | jsonResponse["SpeedMbps"] = ethData.speed; |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 1671 | jsonResponse["MTUSize"] = ethData.mtuSize; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1672 | jsonResponse["MACAddress"] = ethData.macAddress; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1673 | jsonResponse["DHCPv4"]["DHCPEnabled"] = |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1674 | translateDhcpEnabledToBool(ethData.dhcpEnabled, true); |
| 1675 | jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpEnabled; |
| 1676 | jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsEnabled; |
| 1677 | jsonResponse["DHCPv4"]["UseDomainName"] = ethData.hostNameEnabled; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1678 | |
| 1679 | jsonResponse["DHCPv6"]["OperatingMode"] = |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1680 | translateDhcpEnabledToBool(ethData.dhcpEnabled, false) ? "Stateful" |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1681 | : "Disabled"; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1682 | jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpEnabled; |
| 1683 | jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsEnabled; |
| 1684 | jsonResponse["DHCPv6"]["UseDomainName"] = ethData.hostNameEnabled; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1685 | |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1686 | if (!ethData.hostName.empty()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1687 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1688 | jsonResponse["HostName"] = ethData.hostName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1689 | |
| 1690 | // When domain name is empty then it means, that it is a network |
| 1691 | // without domain names, and the host name itself must be treated as |
| 1692 | // FQDN |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1693 | std::string fqdn = ethData.hostName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1694 | if (!ethData.domainnames.empty()) |
| 1695 | { |
| 1696 | fqdn += "." + ethData.domainnames[0]; |
| 1697 | } |
| 1698 | jsonResponse["FQDN"] = fqdn; |
| 1699 | } |
| 1700 | |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 1701 | jsonResponse["VLANs"]["@odata.id"] = |
| 1702 | crow::utility::urlFromPieces("redfish", "v1", "Managers", "bmc", |
| 1703 | "EthernetInterfaces", ifaceId, "VLANs"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1704 | |
| 1705 | jsonResponse["NameServers"] = ethData.nameServers; |
| 1706 | jsonResponse["StaticNameServers"] = ethData.staticNameServers; |
| 1707 | |
| 1708 | nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"]; |
| 1709 | nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"]; |
| 1710 | ipv4Array = nlohmann::json::array(); |
| 1711 | ipv4StaticArray = nlohmann::json::array(); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 1712 | for (const auto& ipv4Config : ipv4Data) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1713 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1714 | std::string gatewayStr = ipv4Config.gateway; |
| 1715 | if (gatewayStr.empty()) |
| 1716 | { |
| 1717 | gatewayStr = "0.0.0.0"; |
| 1718 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1719 | nlohmann::json::object_t ipv4; |
| 1720 | ipv4["AddressOrigin"] = ipv4Config.origin; |
| 1721 | ipv4["SubnetMask"] = ipv4Config.netmask; |
| 1722 | ipv4["Address"] = ipv4Config.address; |
| 1723 | ipv4["Gateway"] = gatewayStr; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1724 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1725 | if (ipv4Config.origin == "Static") |
| 1726 | { |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1727 | ipv4StaticArray.push_back(ipv4); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1728 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1729 | |
| 1730 | ipv4Array.push_back(std::move(ipv4)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1733 | std::string ipv6GatewayStr = ethData.ipv6DefaultGateway; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1734 | if (ipv6GatewayStr.empty()) |
| 1735 | { |
| 1736 | ipv6GatewayStr = "0:0:0:0:0:0:0:0"; |
| 1737 | } |
| 1738 | |
| 1739 | jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr; |
| 1740 | |
| 1741 | nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"]; |
| 1742 | nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"]; |
| 1743 | ipv6Array = nlohmann::json::array(); |
| 1744 | ipv6StaticArray = nlohmann::json::array(); |
| 1745 | nlohmann::json& ipv6AddrPolicyTable = |
| 1746 | jsonResponse["IPv6AddressPolicyTable"]; |
| 1747 | ipv6AddrPolicyTable = nlohmann::json::array(); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 1748 | for (const auto& ipv6Config : ipv6Data) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1749 | { |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1750 | nlohmann::json::object_t ipv6; |
| 1751 | ipv6["Address"] = ipv6Config.address; |
| 1752 | ipv6["PrefixLength"] = ipv6Config.prefixLength; |
| 1753 | ipv6["AddressOrigin"] = ipv6Config.origin; |
| 1754 | ipv6["AddressState"] = nullptr; |
| 1755 | ipv6Array.push_back(std::move(ipv6)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1756 | if (ipv6Config.origin == "Static") |
| 1757 | { |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1758 | nlohmann::json::object_t ipv6Static; |
| 1759 | ipv6Static["Address"] = ipv6Config.address; |
| 1760 | ipv6Static["PrefixLength"] = ipv6Config.prefixLength; |
| 1761 | ipv6StaticArray.push_back(std::move(ipv6Static)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1762 | } |
| 1763 | } |
| 1764 | } |
| 1765 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1766 | inline bool verifyNames(const std::string& parent, const std::string& iface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1767 | { |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 1768 | return iface.starts_with(parent + "_"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | inline void requestEthernetInterfacesRoutes(App& app) |
| 1772 | { |
| 1773 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1774 | .privileges(redfish::privileges::getEthernetInterfaceCollection) |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1775 | .methods(boost::beast::http::verb::get)( |
| 1776 | [&app](const crow::Request& req, |
| 1777 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1778 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1779 | { |
| 1780 | return; |
| 1781 | } |
| 1782 | |
| 1783 | asyncResp->res.jsonValue["@odata.type"] = |
| 1784 | "#EthernetInterfaceCollection.EthernetInterfaceCollection"; |
| 1785 | asyncResp->res.jsonValue["@odata.id"] = |
| 1786 | "/redfish/v1/Managers/bmc/EthernetInterfaces"; |
| 1787 | asyncResp->res.jsonValue["Name"] = |
| 1788 | "Ethernet Network Interface Collection"; |
| 1789 | asyncResp->res.jsonValue["Description"] = |
| 1790 | "Collection of EthernetInterfaces for this Manager"; |
| 1791 | |
| 1792 | // Get eth interface list, and call the below callback for JSON |
| 1793 | // preparation |
| 1794 | getEthernetIfaceList( |
| 1795 | [asyncResp]( |
| 1796 | const bool& success, |
| 1797 | const boost::container::flat_set<std::string>& ifaceList) { |
| 1798 | if (!success) |
| 1799 | { |
| 1800 | messages::internalError(asyncResp->res); |
| 1801 | return; |
| 1802 | } |
| 1803 | |
| 1804 | nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"]; |
| 1805 | ifaceArray = nlohmann::json::array(); |
| 1806 | std::string tag = "_"; |
| 1807 | for (const std::string& ifaceItem : ifaceList) |
| 1808 | { |
| 1809 | std::size_t found = ifaceItem.find(tag); |
| 1810 | if (found == std::string::npos) |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1811 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1812 | nlohmann::json::object_t iface; |
| 1813 | iface["@odata.id"] = |
| 1814 | "/redfish/v1/Managers/bmc/EthernetInterfaces/" + |
| 1815 | ifaceItem; |
| 1816 | ifaceArray.push_back(std::move(iface)); |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1817 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1818 | } |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1819 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1820 | asyncResp->res.jsonValue["Members@odata.count"] = ifaceArray.size(); |
| 1821 | asyncResp->res.jsonValue["@odata.id"] = |
| 1822 | "/redfish/v1/Managers/bmc/EthernetInterfaces"; |
| 1823 | }); |
| 1824 | }); |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 1825 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1826 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1827 | .privileges(redfish::privileges::getEthernetInterface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1828 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1829 | [&app](const crow::Request& req, |
| 1830 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1831 | const std::string& ifaceId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1832 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1833 | { |
| 1834 | return; |
| 1835 | } |
| 1836 | getEthernetIfaceData( |
| 1837 | ifaceId, |
| 1838 | [asyncResp, ifaceId]( |
| 1839 | const bool& success, const EthernetInterfaceData& ethData, |
| 1840 | const boost::container::flat_set<IPv4AddressData>& ipv4Data, |
| 1841 | const boost::container::flat_set<IPv6AddressData>& ipv6Data) { |
| 1842 | if (!success) |
| 1843 | { |
| 1844 | // TODO(Pawel)consider distinguish between non |
| 1845 | // existing object, and other errors |
| 1846 | messages::resourceNotFound(asyncResp->res, "EthernetInterface", |
| 1847 | ifaceId); |
| 1848 | return; |
| 1849 | } |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 1850 | |
Jiaqing Zhao | 188cb62 | 2022-05-26 02:14:28 +0800 | [diff] [blame] | 1851 | // Keep using the v1.6.0 schema here as currently bmcweb have to use |
| 1852 | // "VLANs" property deprecated in v1.7.0 for VLAN creation/deletion. |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1853 | asyncResp->res.jsonValue["@odata.type"] = |
Jiaqing Zhao | 188cb62 | 2022-05-26 02:14:28 +0800 | [diff] [blame] | 1854 | "#EthernetInterface.v1_6_0.EthernetInterface"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1855 | asyncResp->res.jsonValue["Name"] = "Manager Ethernet Interface"; |
| 1856 | asyncResp->res.jsonValue["Description"] = |
| 1857 | "Management Network Interface"; |
Ratan Gupta | f476acb | 2019-03-02 16:46:57 +0530 | [diff] [blame] | 1858 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1859 | parseInterfaceData(asyncResp, ifaceId, ethData, ipv4Data, ipv6Data); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1860 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1861 | }); |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 1862 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1863 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1864 | .privileges(redfish::privileges::patchEthernetInterface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1865 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1866 | [&app](const crow::Request& req, |
| 1867 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1868 | const std::string& ifaceId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1869 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1870 | { |
| 1871 | return; |
| 1872 | } |
| 1873 | std::optional<std::string> hostname; |
| 1874 | std::optional<std::string> fqdn; |
| 1875 | std::optional<std::string> macAddress; |
| 1876 | std::optional<std::string> ipv6DefaultGateway; |
| 1877 | std::optional<nlohmann::json> ipv4StaticAddresses; |
| 1878 | std::optional<nlohmann::json> ipv6StaticAddresses; |
| 1879 | std::optional<std::vector<std::string>> staticNameServers; |
| 1880 | std::optional<nlohmann::json> dhcpv4; |
| 1881 | std::optional<nlohmann::json> dhcpv6; |
| 1882 | std::optional<bool> interfaceEnabled; |
| 1883 | std::optional<size_t> mtuSize; |
| 1884 | DHCPParameters v4dhcpParms; |
| 1885 | DHCPParameters v6dhcpParms; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1886 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1887 | if (!json_util::readJsonPatch( |
| 1888 | req, asyncResp->res, "HostName", hostname, "FQDN", fqdn, |
| 1889 | "IPv4StaticAddresses", ipv4StaticAddresses, "MACAddress", |
| 1890 | macAddress, "StaticNameServers", staticNameServers, |
| 1891 | "IPv6DefaultGateway", ipv6DefaultGateway, "IPv6StaticAddresses", |
| 1892 | ipv6StaticAddresses, "DHCPv4", dhcpv4, "DHCPv6", dhcpv6, |
| 1893 | "MTUSize", mtuSize, "InterfaceEnabled", interfaceEnabled)) |
| 1894 | { |
| 1895 | return; |
| 1896 | } |
| 1897 | if (dhcpv4) |
| 1898 | { |
| 1899 | if (!json_util::readJson(*dhcpv4, asyncResp->res, "DHCPEnabled", |
| 1900 | v4dhcpParms.dhcpv4Enabled, "UseDNSServers", |
| 1901 | v4dhcpParms.useDnsServers, "UseNTPServers", |
| 1902 | v4dhcpParms.useNtpServers, "UseDomainName", |
| 1903 | v4dhcpParms.useDomainName)) |
| 1904 | { |
| 1905 | return; |
| 1906 | } |
| 1907 | } |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 1908 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1909 | if (dhcpv6) |
| 1910 | { |
| 1911 | if (!json_util::readJson(*dhcpv6, asyncResp->res, "OperatingMode", |
| 1912 | v6dhcpParms.dhcpv6OperatingMode, |
| 1913 | "UseDNSServers", v6dhcpParms.useDnsServers, |
| 1914 | "UseNTPServers", v6dhcpParms.useNtpServers, |
| 1915 | "UseDomainName", |
| 1916 | v6dhcpParms.useDomainName)) |
| 1917 | { |
| 1918 | return; |
| 1919 | } |
| 1920 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 1921 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1922 | // Get single eth interface data, and call the below callback |
| 1923 | // for JSON preparation |
| 1924 | getEthernetIfaceData( |
| 1925 | ifaceId, |
| 1926 | [asyncResp, ifaceId, hostname = std::move(hostname), |
| 1927 | fqdn = std::move(fqdn), macAddress = std::move(macAddress), |
| 1928 | ipv4StaticAddresses = std::move(ipv4StaticAddresses), |
| 1929 | ipv6DefaultGateway = std::move(ipv6DefaultGateway), |
| 1930 | ipv6StaticAddresses = std::move(ipv6StaticAddresses), |
| 1931 | staticNameServers = std::move(staticNameServers), |
Ed Tanous | bc20089 | 2022-06-30 17:49:12 -0700 | [diff] [blame] | 1932 | dhcpv4 = std::move(dhcpv4), dhcpv6 = std::move(dhcpv6), mtuSize, |
| 1933 | v4dhcpParms = std::move(v4dhcpParms), |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1934 | v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled]( |
| 1935 | const bool& success, const EthernetInterfaceData& ethData, |
| 1936 | const boost::container::flat_set<IPv4AddressData>& ipv4Data, |
| 1937 | const boost::container::flat_set<IPv6AddressData>& ipv6Data) { |
| 1938 | if (!success) |
| 1939 | { |
| 1940 | // ... otherwise return error |
| 1941 | // TODO(Pawel)consider distinguish between non |
| 1942 | // existing object, and other errors |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 1943 | messages::resourceNotFound(asyncResp->res, "EthernetInterface", |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1944 | ifaceId); |
| 1945 | return; |
| 1946 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 1947 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1948 | if (dhcpv4 || dhcpv6) |
| 1949 | { |
| 1950 | handleDHCPPatch(ifaceId, ethData, v4dhcpParms, v6dhcpParms, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1951 | asyncResp); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1952 | } |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 1953 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1954 | if (hostname) |
| 1955 | { |
| 1956 | handleHostnamePatch(*hostname, asyncResp); |
| 1957 | } |
| 1958 | |
| 1959 | if (fqdn) |
| 1960 | { |
| 1961 | handleFqdnPatch(ifaceId, *fqdn, asyncResp); |
| 1962 | } |
| 1963 | |
| 1964 | if (macAddress) |
| 1965 | { |
| 1966 | handleMACAddressPatch(ifaceId, *macAddress, asyncResp); |
| 1967 | } |
| 1968 | |
| 1969 | if (ipv4StaticAddresses) |
| 1970 | { |
| 1971 | // TODO(ed) for some reason the capture of |
| 1972 | // ipv4Addresses above is returning a const value, |
| 1973 | // not a non-const value. This doesn't really work |
| 1974 | // for us, as we need to be able to efficiently move |
| 1975 | // out the intermedia nlohmann::json objects. This |
| 1976 | // makes a copy of the structure, and operates on |
| 1977 | // that, but could be done more efficiently |
| 1978 | nlohmann::json ipv4Static = *ipv4StaticAddresses; |
| 1979 | handleIPv4StaticPatch(ifaceId, ipv4Static, ipv4Data, asyncResp); |
| 1980 | } |
| 1981 | |
| 1982 | if (staticNameServers) |
| 1983 | { |
| 1984 | handleStaticNameServersPatch(ifaceId, *staticNameServers, |
| 1985 | asyncResp); |
| 1986 | } |
| 1987 | |
| 1988 | if (ipv6DefaultGateway) |
| 1989 | { |
| 1990 | messages::propertyNotWritable(asyncResp->res, |
| 1991 | "IPv6DefaultGateway"); |
| 1992 | } |
| 1993 | |
| 1994 | if (ipv6StaticAddresses) |
| 1995 | { |
| 1996 | const nlohmann::json& ipv6Static = *ipv6StaticAddresses; |
| 1997 | handleIPv6StaticAddressesPatch(ifaceId, ipv6Static, ipv6Data, |
| 1998 | asyncResp); |
| 1999 | } |
| 2000 | |
| 2001 | if (interfaceEnabled) |
| 2002 | { |
| 2003 | setEthernetInterfaceBoolProperty(ifaceId, "NICEnabled", |
| 2004 | *interfaceEnabled, asyncResp); |
| 2005 | } |
| 2006 | |
| 2007 | if (mtuSize) |
| 2008 | { |
| 2009 | handleMTUSizePatch(ifaceId, *mtuSize, asyncResp); |
| 2010 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2011 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2012 | }); |
manojkiraneda | 2a13328 | 2019-02-19 13:09:43 +0530 | [diff] [blame] | 2013 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2014 | BMCWEB_ROUTE( |
| 2015 | app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2016 | .privileges(redfish::privileges::getVLanNetworkInterface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2017 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2018 | [&app](const crow::Request& req, |
| 2019 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2020 | const std::string& parentIfaceId, |
| 2021 | const std::string& ifaceId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2022 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2023 | { |
| 2024 | return; |
| 2025 | } |
| 2026 | asyncResp->res.jsonValue["@odata.type"] = |
| 2027 | "#VLanNetworkInterface.v1_1_0.VLanNetworkInterface"; |
| 2028 | asyncResp->res.jsonValue["Name"] = "VLAN Network Interface"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 2029 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2030 | if (!verifyNames(parentIfaceId, ifaceId)) |
| 2031 | { |
| 2032 | return; |
| 2033 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2034 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2035 | // Get single eth interface data, and call the below callback |
| 2036 | // for JSON preparation |
| 2037 | getEthernetIfaceData( |
| 2038 | ifaceId, |
| 2039 | [asyncResp, parentIfaceId, |
| 2040 | ifaceId](const bool& success, const EthernetInterfaceData& ethData, |
| 2041 | const boost::container::flat_set<IPv4AddressData>&, |
| 2042 | const boost::container::flat_set<IPv6AddressData>&) { |
| 2043 | if (success && ethData.vlanId) |
| 2044 | { |
Jiaqing Zhao | 22872ff | 2022-09-13 09:38:20 +0800 | [diff] [blame] | 2045 | asyncResp->res.jsonValue["Id"] = ifaceId; |
| 2046 | asyncResp->res.jsonValue["@odata.id"] = |
| 2047 | "/redfish/v1/Managers/bmc/EthernetInterfaces/" + |
| 2048 | parentIfaceId + "/VLANs/" + ifaceId; |
| 2049 | |
Jiaqing Zhao | 23a0631 | 2022-09-13 09:38:25 +0800 | [diff] [blame] | 2050 | asyncResp->res.jsonValue["VLANEnable"] = ethData.nicEnabled; |
Jiaqing Zhao | 22872ff | 2022-09-13 09:38:20 +0800 | [diff] [blame] | 2051 | asyncResp->res.jsonValue["VLANId"] = *ethData.vlanId; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2052 | } |
| 2053 | else |
| 2054 | { |
| 2055 | // ... otherwise return error |
| 2056 | // TODO(Pawel)consider distinguish between non |
| 2057 | // existing object, and other errors |
| 2058 | messages::resourceNotFound(asyncResp->res, |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 2059 | "VLanNetworkInterface", ifaceId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2060 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2061 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2062 | }); |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 2063 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2064 | BMCWEB_ROUTE( |
| 2065 | app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/<str>/") |
Abhishek Patel | 3d768a1 | 2021-07-31 16:44:51 -0500 | [diff] [blame] | 2066 | .privileges(redfish::privileges::patchVLanNetworkInterface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2067 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2068 | [&app](const crow::Request& req, |
| 2069 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2070 | const std::string& parentIfaceId, |
| 2071 | const std::string& ifaceId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2072 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2073 | { |
| 2074 | return; |
| 2075 | } |
| 2076 | if (!verifyNames(parentIfaceId, ifaceId)) |
| 2077 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 2078 | messages::resourceNotFound(asyncResp->res, "VLanNetworkInterface", |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2079 | ifaceId); |
| 2080 | return; |
| 2081 | } |
| 2082 | |
| 2083 | std::optional<bool> vlanEnable; |
| 2084 | std::optional<uint32_t> vlanId; |
| 2085 | |
| 2086 | if (!json_util::readJsonPatch(req, asyncResp->res, "VLANEnable", |
| 2087 | vlanEnable, "VLANId", vlanId)) |
| 2088 | { |
| 2089 | return; |
| 2090 | } |
| 2091 | |
| 2092 | if (vlanId) |
| 2093 | { |
| 2094 | messages::propertyNotWritable(asyncResp->res, "VLANId"); |
| 2095 | return; |
| 2096 | } |
| 2097 | |
| 2098 | // Get single eth interface data, and call the below callback |
| 2099 | // for JSON preparation |
| 2100 | getEthernetIfaceData( |
| 2101 | ifaceId, |
| 2102 | [asyncResp, parentIfaceId, ifaceId, vlanEnable]( |
| 2103 | const bool& success, const EthernetInterfaceData& ethData, |
| 2104 | const boost::container::flat_set<IPv4AddressData>&, |
| 2105 | const boost::container::flat_set<IPv6AddressData>&) { |
| 2106 | if (success && ethData.vlanId) |
| 2107 | { |
Jiaqing Zhao | 23a0631 | 2022-09-13 09:38:25 +0800 | [diff] [blame] | 2108 | if (vlanEnable) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2109 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2110 | crow::connections::systemBus->async_method_call( |
Jiaqing Zhao | 23a0631 | 2022-09-13 09:38:25 +0800 | [diff] [blame] | 2111 | [asyncResp](const boost::system::error_code ec) { |
| 2112 | if (ec) |
| 2113 | { |
| 2114 | messages::internalError(asyncResp->res); |
| 2115 | return; |
| 2116 | } |
| 2117 | }, |
| 2118 | "xyz.openbmc_project.Network", |
| 2119 | "/xyz/openbmc_project/network/" + ifaceId, |
| 2120 | "org.freedesktop.DBus.Properties", "Set", |
| 2121 | "xyz.openbmc_project.Network.EthernetInterface", |
| 2122 | "NICEnabled", |
| 2123 | dbus::utility::DbusVariantType(*vlanEnable)); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2124 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2125 | } |
| 2126 | else |
| 2127 | { |
| 2128 | // TODO(Pawel)consider distinguish between non |
| 2129 | // existing object, and other errors |
| 2130 | messages::resourceNotFound(asyncResp->res, |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 2131 | "VLanNetworkInterface", ifaceId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2132 | return; |
| 2133 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2134 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2135 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2136 | |
| 2137 | BMCWEB_ROUTE( |
| 2138 | app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/<str>/") |
Abhishek Patel | 3d768a1 | 2021-07-31 16:44:51 -0500 | [diff] [blame] | 2139 | .privileges(redfish::privileges::deleteVLanNetworkInterface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2140 | .methods(boost::beast::http::verb::delete_)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2141 | [&app](const crow::Request& req, |
| 2142 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2143 | const std::string& parentIfaceId, |
| 2144 | const std::string& ifaceId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2145 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2146 | { |
| 2147 | return; |
| 2148 | } |
| 2149 | if (!verifyNames(parentIfaceId, ifaceId)) |
| 2150 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 2151 | messages::resourceNotFound(asyncResp->res, "VLanNetworkInterface", |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2152 | ifaceId); |
| 2153 | return; |
| 2154 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2155 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2156 | // Get single eth interface data, and call the below callback |
| 2157 | // for JSON preparation |
| 2158 | getEthernetIfaceData( |
| 2159 | ifaceId, |
| 2160 | [asyncResp, parentIfaceId, |
| 2161 | ifaceId](const bool& success, const EthernetInterfaceData& ethData, |
| 2162 | const boost::container::flat_set<IPv4AddressData>&, |
| 2163 | const boost::container::flat_set<IPv6AddressData>&) { |
| 2164 | if (success && ethData.vlanId) |
| 2165 | { |
| 2166 | auto callback = |
| 2167 | [asyncResp](const boost::system::error_code ec) { |
| 2168 | if (ec) |
| 2169 | { |
| 2170 | messages::internalError(asyncResp->res); |
| 2171 | } |
| 2172 | }; |
| 2173 | crow::connections::systemBus->async_method_call( |
| 2174 | std::move(callback), "xyz.openbmc_project.Network", |
| 2175 | std::string("/xyz/openbmc_project/network/") + ifaceId, |
| 2176 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 2177 | } |
| 2178 | else |
| 2179 | { |
| 2180 | // ... otherwise return error |
| 2181 | // TODO(Pawel)consider distinguish between non |
| 2182 | // existing object, and other errors |
| 2183 | messages::resourceNotFound(asyncResp->res, |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 2184 | "VLanNetworkInterface", ifaceId); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2185 | } |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 2186 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2187 | }); |
Kowalski, Kamil | e439f0f | 2018-05-21 08:13:57 +0200 | [diff] [blame] | 2188 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2189 | BMCWEB_ROUTE(app, |
| 2190 | "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2191 | |
| 2192 | .privileges(redfish::privileges::getVLanNetworkInterfaceCollection) |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 2193 | .methods(boost::beast::http::verb::get)( |
| 2194 | [&app](const crow::Request& req, |
| 2195 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2196 | const std::string& rootInterfaceName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2197 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2198 | { |
| 2199 | return; |
| 2200 | } |
| 2201 | // Get eth interface list, and call the below callback for JSON |
| 2202 | // preparation |
| 2203 | getEthernetIfaceList( |
| 2204 | [asyncResp, rootInterfaceName]( |
| 2205 | const bool& success, |
| 2206 | const boost::container::flat_set<std::string>& ifaceList) { |
| 2207 | if (!success) |
| 2208 | { |
| 2209 | messages::internalError(asyncResp->res); |
| 2210 | return; |
| 2211 | } |
| 2212 | |
| 2213 | if (ifaceList.find(rootInterfaceName) == ifaceList.end()) |
| 2214 | { |
| 2215 | messages::resourceNotFound(asyncResp->res, |
| 2216 | "VLanNetworkInterfaceCollection", |
| 2217 | rootInterfaceName); |
| 2218 | return; |
| 2219 | } |
| 2220 | |
| 2221 | asyncResp->res.jsonValue["@odata.type"] = |
| 2222 | "#VLanNetworkInterfaceCollection." |
| 2223 | "VLanNetworkInterfaceCollection"; |
| 2224 | asyncResp->res.jsonValue["Name"] = |
| 2225 | "VLAN Network Interface Collection"; |
| 2226 | |
| 2227 | nlohmann::json ifaceArray = nlohmann::json::array(); |
| 2228 | |
| 2229 | for (const std::string& ifaceItem : ifaceList) |
| 2230 | { |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 2231 | if (ifaceItem.starts_with(rootInterfaceName + "_")) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2232 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2233 | std::string path = |
| 2234 | "/redfish/v1/Managers/bmc/EthernetInterfaces/"; |
| 2235 | path += rootInterfaceName; |
| 2236 | path += "/VLANs/"; |
| 2237 | path += ifaceItem; |
| 2238 | nlohmann::json::object_t iface; |
| 2239 | iface["@odata.id"] = std::move(path); |
| 2240 | ifaceArray.push_back(std::move(iface)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2241 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2242 | } |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 2243 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2244 | asyncResp->res.jsonValue["Members@odata.count"] = ifaceArray.size(); |
| 2245 | asyncResp->res.jsonValue["Members"] = std::move(ifaceArray); |
| 2246 | asyncResp->res.jsonValue["@odata.id"] = |
| 2247 | "/redfish/v1/Managers/bmc/EthernetInterfaces/" + |
| 2248 | rootInterfaceName + "/VLANs"; |
| 2249 | }); |
| 2250 | }); |
Kowalski, Kamil | e439f0f | 2018-05-21 08:13:57 +0200 | [diff] [blame] | 2251 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2252 | BMCWEB_ROUTE(app, |
| 2253 | "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/") |
Abhishek Patel | 3d768a1 | 2021-07-31 16:44:51 -0500 | [diff] [blame] | 2254 | .privileges(redfish::privileges::postVLanNetworkInterfaceCollection) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2255 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2256 | [&app](const crow::Request& req, |
| 2257 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2258 | const std::string& rootInterfaceName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2259 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2260 | { |
| 2261 | return; |
| 2262 | } |
| 2263 | bool vlanEnable = false; |
| 2264 | uint32_t vlanId = 0; |
| 2265 | if (!json_util::readJsonPatch(req, asyncResp->res, "VLANId", vlanId, |
| 2266 | "VLANEnable", vlanEnable)) |
| 2267 | { |
| 2268 | return; |
| 2269 | } |
| 2270 | // Need both vlanId and vlanEnable to service this request |
| 2271 | if (vlanId == 0U) |
| 2272 | { |
| 2273 | messages::propertyMissing(asyncResp->res, "VLANId"); |
| 2274 | } |
| 2275 | if (!vlanEnable) |
| 2276 | { |
| 2277 | messages::propertyMissing(asyncResp->res, "VLANEnable"); |
| 2278 | } |
| 2279 | if (static_cast<bool>(vlanId) ^ vlanEnable) |
| 2280 | { |
| 2281 | return; |
| 2282 | } |
Sunitha Harish | fda13ad | 2019-03-21 11:01:24 -0500 | [diff] [blame] | 2283 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2284 | auto callback = [asyncResp](const boost::system::error_code ec) { |
| 2285 | if (ec) |
| 2286 | { |
| 2287 | // TODO(ed) make more consistent error messages |
| 2288 | // based on phosphor-network responses |
| 2289 | messages::internalError(asyncResp->res); |
| 2290 | return; |
| 2291 | } |
| 2292 | messages::created(asyncResp->res); |
| 2293 | }; |
| 2294 | crow::connections::systemBus->async_method_call( |
| 2295 | std::move(callback), "xyz.openbmc_project.Network", |
| 2296 | "/xyz/openbmc_project/network", |
| 2297 | "xyz.openbmc_project.Network.VLAN.Create", "VLAN", |
| 2298 | rootInterfaceName, vlanId); |
| 2299 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2302 | } // namespace redfish |