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