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