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