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