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