blob: d0441202067610d5684820d659759b70878c99e6 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +01004#pragma once
5
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "app.hpp"
7#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +08008#include "dbus_utility.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08009#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070010#include "generated/enums/ethernet_interface.hpp"
11#include "generated/enums/resource.hpp"
Ed Tanous2c5875a2023-05-15 09:56:06 -070012#include "human_sort.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080013#include "query.hpp"
14#include "registries/privilege_registry.hpp"
Ed Tanous033f1e42022-08-15 09:47:37 -070015#include "utils/ip_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080016#include "utils/json_utils.hpp"
Ed Tanous033f1e42022-08-15 09:47:37 -070017
Sunitha Harishce73d5c2023-04-07 06:46:49 -050018#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070019#include <boost/url/format.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050020
George Liu7a1dbc42022-12-07 16:03:22 +080021#include <array>
Ed Tanous3dfed532024-03-06 14:41:27 -080022#include <cstddef>
Sunitha Harishce73d5c2023-04-07 06:46:49 -050023#include <memory>
Ed Tanousa24526d2018-12-10 15:17:59 -080024#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070025#include <ranges>
Joshi-Mansiab6554f2020-03-10 18:33:36 +053026#include <regex>
George Liu7a1dbc42022-12-07 16:03:22 +080027#include <string_view>
Ed Tanous3dfed532024-03-06 14:41:27 -080028#include <variant>
Ed Tanous77179532023-02-28 10:45:28 -080029#include <vector>
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010030
Ed Tanous1abe55e2018-09-05 08:30:59 -070031namespace redfish
32{
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010033
Ed Tanous4a0cb852018-10-15 07:55:04 -070034enum class LinkType
35{
36 Local,
37 Global
38};
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010039
Johnathan Mantey743eb1c2024-04-03 12:05:57 -070040enum class IpVersion
41{
42 IpV4,
43 IpV6
44};
45
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010046/**
47 * Structure for keeping IPv4 data required by Redfish
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010048 */
Ed Tanous1abe55e2018-09-05 08:30:59 -070049struct IPv4AddressData
50{
51 std::string id;
Ed Tanous4a0cb852018-10-15 07:55:04 -070052 std::string address;
53 std::string domain;
54 std::string gateway;
Ed Tanous1abe55e2018-09-05 08:30:59 -070055 std::string netmask;
56 std::string origin;
Ed Tanous77179532023-02-28 10:45:28 -080057 LinkType linktype{};
58 bool isActive{};
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010059};
60
61/**
Ravi Tejae48c0fc2019-04-16 08:37:20 -050062 * Structure for keeping IPv6 data required by Redfish
63 */
64struct IPv6AddressData
65{
66 std::string id;
67 std::string address;
68 std::string origin;
Ed Tanous77179532023-02-28 10:45:28 -080069 uint8_t prefixLength = 0;
Ravi Tejae48c0fc2019-04-16 08:37:20 -050070};
Sunitha Harishce73d5c2023-04-07 06:46:49 -050071
72/**
73 * Structure for keeping static route data required by Redfish
74 */
75struct StaticGatewayData
76{
77 std::string id;
78 std::string gateway;
79 size_t prefixLength = 0;
80 std::string protocol;
81};
82
Ravi Tejae48c0fc2019-04-16 08:37:20 -050083/**
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010084 * Structure for keeping basic single Ethernet Interface information
85 * available from DBus
86 */
Ed Tanous1abe55e2018-09-05 08:30:59 -070087struct EthernetInterfaceData
88{
Ed Tanous4a0cb852018-10-15 07:55:04 -070089 uint32_t speed;
Tejas Patil35fb5312021-09-20 15:35:20 +053090 size_t mtuSize;
Jiaqing Zhao82695a52022-04-14 15:15:59 +080091 bool autoNeg;
Jishnu CMe4588152023-05-11 00:04:40 -050092 bool dnsv4Enabled;
93 bool dnsv6Enabled;
Ravi Teja91c441e2024-02-23 09:03:43 -060094 bool domainv4Enabled;
95 bool domainv6Enabled;
Jishnu CMe4588152023-05-11 00:04:40 -050096 bool ntpv4Enabled;
97 bool ntpv6Enabled;
98 bool hostNamev4Enabled;
99 bool hostNamev6Enabled;
Johnathan Manteyaa05fb22020-01-08 12:08:44 -0800100 bool linkUp;
Johnathan Manteyeeedda22019-10-29 16:09:52 -0700101 bool nicEnabled;
Ravi Tejab10d8db2022-05-24 09:04:12 -0500102 bool ipv6AcceptRa;
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800103 std::string dhcpEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700104 std::string operatingMode;
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800105 std::string hostName;
106 std::string defaultGateway;
107 std::string ipv6DefaultGateway;
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500108 std::string ipv6StaticDefaultGateway;
Asmitha Karunanithi4652c642024-07-30 11:35:53 -0500109 std::optional<std::string> macAddress;
Jiaqing Zhao17e22022022-04-14 18:58:06 +0800110 std::optional<uint32_t> vlanId;
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -0500111 std::vector<std::string> nameServers;
112 std::vector<std::string> staticNameServers;
Jennifer Leed24bfc72019-03-05 13:03:37 -0800113 std::vector<std::string> domainnames;
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +0100114};
115
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700116struct DHCPParameters
117{
118 std::optional<bool> dhcpv4Enabled;
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800119 std::optional<bool> useDnsServers;
120 std::optional<bool> useNtpServers;
121 std::optional<bool> useDomainName;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700122 std::optional<std::string> dhcpv6OperatingMode;
123};
124
Ed Tanous4a0cb852018-10-15 07:55:04 -0700125// Helper function that changes bits netmask notation (i.e. /24)
126// into full dot notation
127inline std::string getNetmask(unsigned int bits)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700128{
Ed Tanous4a0cb852018-10-15 07:55:04 -0700129 uint32_t value = 0xffffffff << (32 - bits);
130 std::string netmask = std::to_string((value >> 24) & 0xff) + "." +
131 std::to_string((value >> 16) & 0xff) + "." +
132 std::to_string((value >> 8) & 0xff) + "." +
133 std::to_string(value & 0xff);
134 return netmask;
135}
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +0100136
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800137inline bool translateDhcpEnabledToBool(const std::string& inputDHCP,
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700138 bool isIPv4)
139{
140 if (isIPv4)
141 {
142 return (
143 (inputDHCP ==
144 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4") ||
145 (inputDHCP ==
146 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
147 }
148 return ((inputDHCP ==
149 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") ||
150 (inputDHCP ==
151 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
152}
153
Ed Tanous2c70f802020-09-28 14:29:23 -0700154inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700155{
156 if (isIPv4 && isIPv6)
157 {
158 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both";
159 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700160 if (isIPv4)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700161 {
162 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4";
163 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700164 if (isIPv6)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700165 {
166 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6";
167 }
168 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none";
169}
170
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400171inline std::string translateAddressOriginDbusToRedfish(
172 const std::string& inputOrigin, bool isIPv4)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700173{
174 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700175 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700176 return "Static";
177 }
178 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal")
179 {
180 if (isIPv4)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700181 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700182 return "IPv4LinkLocal";
183 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700184 return "LinkLocal";
Ed Tanous4a0cb852018-10-15 07:55:04 -0700185 }
186 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
187 {
188 if (isIPv4)
189 {
190 return "DHCP";
191 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700192 return "DHCPv6";
Ed Tanous4a0cb852018-10-15 07:55:04 -0700193 }
194 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC")
195 {
196 return "SLAAC";
197 }
198 return "";
199}
200
Ed Tanous02cad962022-06-30 16:50:15 -0700201inline bool extractEthernetInterfaceData(
202 const std::string& ethifaceId,
203 const dbus::utility::ManagedObjectType& dbusData,
204 EthernetInterfaceData& ethData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700205{
Ed Tanous4c9afe42019-05-03 16:59:57 -0700206 bool idFound = false;
Ed Tanous02cad962022-06-30 16:50:15 -0700207 for (const auto& objpath : dbusData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700208 {
Ed Tanous02cad962022-06-30 16:50:15 -0700209 for (const auto& ifacePair : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700210 {
Ed Tanous81ce6092020-12-17 16:54:55 +0000211 if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700212 {
Ed Tanous4c9afe42019-05-03 16:59:57 -0700213 idFound = true;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700214 if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700215 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500216 for (const auto& propertyPair : ifacePair.second)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700217 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700218 if (propertyPair.first == "MACAddress")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700219 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500220 const std::string* mac =
Ed Tanousabf2add2019-01-22 16:40:12 -0800221 std::get_if<std::string>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700222 if (mac != nullptr)
223 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800224 ethData.macAddress = *mac;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700225 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700226 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700227 }
228 }
229 else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN")
230 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500231 for (const auto& propertyPair : ifacePair.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700232 {
233 if (propertyPair.first == "Id")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700234 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500235 const uint32_t* id =
Ed Tanousabf2add2019-01-22 16:40:12 -0800236 std::get_if<uint32_t>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700237 if (id != nullptr)
238 {
Jiaqing Zhao17e22022022-04-14 18:58:06 +0800239 ethData.vlanId = *id;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700240 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700241 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700242 }
243 }
244 else if (ifacePair.first ==
245 "xyz.openbmc_project.Network.EthernetInterface")
246 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500247 for (const auto& propertyPair : ifacePair.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700248 {
249 if (propertyPair.first == "AutoNeg")
250 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700251 const bool* autoNeg =
Ed Tanousabf2add2019-01-22 16:40:12 -0800252 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700253 if (autoNeg != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700254 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800255 ethData.autoNeg = *autoNeg;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700256 }
257 }
258 else if (propertyPair.first == "Speed")
259 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500260 const uint32_t* speed =
Ed Tanousabf2add2019-01-22 16:40:12 -0800261 std::get_if<uint32_t>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700262 if (speed != nullptr)
263 {
264 ethData.speed = *speed;
265 }
266 }
Tejas Patil35fb5312021-09-20 15:35:20 +0530267 else if (propertyPair.first == "MTU")
268 {
Anthony3e7a8da2023-10-23 14:22:43 +0800269 const size_t* mtuSize =
270 std::get_if<size_t>(&propertyPair.second);
Tejas Patil35fb5312021-09-20 15:35:20 +0530271 if (mtuSize != nullptr)
272 {
273 ethData.mtuSize = *mtuSize;
274 }
275 }
Johnathan Manteyaa05fb22020-01-08 12:08:44 -0800276 else if (propertyPair.first == "LinkUp")
277 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500278 const bool* linkUp =
Johnathan Manteyaa05fb22020-01-08 12:08:44 -0800279 std::get_if<bool>(&propertyPair.second);
280 if (linkUp != nullptr)
281 {
282 ethData.linkUp = *linkUp;
283 }
284 }
Johnathan Manteyeeedda22019-10-29 16:09:52 -0700285 else if (propertyPair.first == "NICEnabled")
286 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500287 const bool* nicEnabled =
Johnathan Manteyeeedda22019-10-29 16:09:52 -0700288 std::get_if<bool>(&propertyPair.second);
289 if (nicEnabled != nullptr)
290 {
291 ethData.nicEnabled = *nicEnabled;
292 }
293 }
Ravi Tejab10d8db2022-05-24 09:04:12 -0500294 else if (propertyPair.first == "IPv6AcceptRA")
295 {
296 const bool* ipv6AcceptRa =
297 std::get_if<bool>(&propertyPair.second);
298 if (ipv6AcceptRa != nullptr)
299 {
300 ethData.ipv6AcceptRa = *ipv6AcceptRa;
301 }
302 }
RAJESWARAN THILLAIGOVINDANf85837b2019-04-04 05:18:53 -0500303 else if (propertyPair.first == "Nameservers")
Ed Tanous4a0cb852018-10-15 07:55:04 -0700304 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500305 const std::vector<std::string>* nameservers =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500306 std::get_if<std::vector<std::string>>(
Ed Tanous029573d2019-02-01 10:57:49 -0800307 &propertyPair.second);
308 if (nameservers != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700309 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700310 ethData.nameServers = *nameservers;
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -0500311 }
312 }
313 else if (propertyPair.first == "StaticNameServers")
314 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500315 const std::vector<std::string>* staticNameServers =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500316 std::get_if<std::vector<std::string>>(
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -0500317 &propertyPair.second);
318 if (staticNameServers != nullptr)
319 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700320 ethData.staticNameServers = *staticNameServers;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700321 }
322 }
manojkiraneda2a133282019-02-19 13:09:43 +0530323 else if (propertyPair.first == "DHCPEnabled")
324 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700325 const std::string* dhcpEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700326 std::get_if<std::string>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700327 if (dhcpEnabled != nullptr)
manojkiraneda2a133282019-02-19 13:09:43 +0530328 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800329 ethData.dhcpEnabled = *dhcpEnabled;
manojkiraneda2a133282019-02-19 13:09:43 +0530330 }
331 }
Jennifer Leed24bfc72019-03-05 13:03:37 -0800332 else if (propertyPair.first == "DomainName")
333 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500334 const std::vector<std::string>* domainNames =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500335 std::get_if<std::vector<std::string>>(
Jennifer Leed24bfc72019-03-05 13:03:37 -0800336 &propertyPair.second);
337 if (domainNames != nullptr)
338 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700339 ethData.domainnames = *domainNames;
Jennifer Leed24bfc72019-03-05 13:03:37 -0800340 }
341 }
Ravi Teja9010ec22019-08-01 23:30:25 -0500342 else if (propertyPair.first == "DefaultGateway")
343 {
344 const std::string* defaultGateway =
345 std::get_if<std::string>(&propertyPair.second);
346 if (defaultGateway != nullptr)
347 {
348 std::string defaultGatewayStr = *defaultGateway;
349 if (defaultGatewayStr.empty())
350 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800351 ethData.defaultGateway = "0.0.0.0";
Ravi Teja9010ec22019-08-01 23:30:25 -0500352 }
353 else
354 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800355 ethData.defaultGateway = defaultGatewayStr;
Ravi Teja9010ec22019-08-01 23:30:25 -0500356 }
357 }
358 }
359 else if (propertyPair.first == "DefaultGateway6")
360 {
361 const std::string* defaultGateway6 =
362 std::get_if<std::string>(&propertyPair.second);
363 if (defaultGateway6 != nullptr)
364 {
365 std::string defaultGateway6Str =
366 *defaultGateway6;
367 if (defaultGateway6Str.empty())
368 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800369 ethData.ipv6DefaultGateway =
Ravi Teja9010ec22019-08-01 23:30:25 -0500370 "0:0:0:0:0:0:0:0";
371 }
372 else
373 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800374 ethData.ipv6DefaultGateway =
Ravi Teja9010ec22019-08-01 23:30:25 -0500375 defaultGateway6Str;
376 }
377 }
378 }
Ed Tanous029573d2019-02-01 10:57:49 -0800379 }
380 }
381 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700382
Jishnu CMe4588152023-05-11 00:04:40 -0500383 sdbusplus::message::object_path path(
384 "/xyz/openbmc_project/network");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400385 sdbusplus::message::object_path dhcp4Path =
386 path / ethifaceId / "dhcp4";
Jishnu CMe4588152023-05-11 00:04:40 -0500387
388 if (sdbusplus::message::object_path(objpath.first) == dhcp4Path)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700389 {
390 if (ifacePair.first ==
391 "xyz.openbmc_project.Network.DHCPConfiguration")
392 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500393 for (const auto& propertyPair : ifacePair.second)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700394 {
395 if (propertyPair.first == "DNSEnabled")
396 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700397 const bool* dnsEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700398 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700399 if (dnsEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700400 {
Jishnu CMe4588152023-05-11 00:04:40 -0500401 ethData.dnsv4Enabled = *dnsEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700402 }
403 }
Ravi Teja91c441e2024-02-23 09:03:43 -0600404 else if (propertyPair.first == "DomainEnabled")
405 {
406 const bool* domainEnabled =
407 std::get_if<bool>(&propertyPair.second);
408 if (domainEnabled != nullptr)
409 {
410 ethData.domainv4Enabled = *domainEnabled;
411 }
412 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700413 else if (propertyPair.first == "NTPEnabled")
414 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700415 const bool* ntpEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700416 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700417 if (ntpEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700418 {
Jishnu CMe4588152023-05-11 00:04:40 -0500419 ethData.ntpv4Enabled = *ntpEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700420 }
421 }
422 else if (propertyPair.first == "HostNameEnabled")
423 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700424 const bool* hostNameEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700425 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700426 if (hostNameEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700427 {
Jishnu CMe4588152023-05-11 00:04:40 -0500428 ethData.hostNamev4Enabled = *hostNameEnabled;
429 }
430 }
431 }
432 }
433 }
434
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400435 sdbusplus::message::object_path dhcp6Path =
436 path / ethifaceId / "dhcp6";
Jishnu CMe4588152023-05-11 00:04:40 -0500437
438 if (sdbusplus::message::object_path(objpath.first) == dhcp6Path)
439 {
440 if (ifacePair.first ==
441 "xyz.openbmc_project.Network.DHCPConfiguration")
442 {
443 for (const auto& propertyPair : ifacePair.second)
444 {
445 if (propertyPair.first == "DNSEnabled")
446 {
447 const bool* dnsEnabled =
448 std::get_if<bool>(&propertyPair.second);
449 if (dnsEnabled != nullptr)
450 {
451 ethData.dnsv6Enabled = *dnsEnabled;
452 }
453 }
Ravi Teja91c441e2024-02-23 09:03:43 -0600454 if (propertyPair.first == "DomainEnabled")
455 {
456 const bool* domainEnabled =
457 std::get_if<bool>(&propertyPair.second);
458 if (domainEnabled != nullptr)
459 {
460 ethData.domainv6Enabled = *domainEnabled;
461 }
462 }
Jishnu CMe4588152023-05-11 00:04:40 -0500463 else if (propertyPair.first == "NTPEnabled")
464 {
465 const bool* ntpEnabled =
466 std::get_if<bool>(&propertyPair.second);
467 if (ntpEnabled != nullptr)
468 {
469 ethData.ntpv6Enabled = *ntpEnabled;
470 }
471 }
472 else if (propertyPair.first == "HostNameEnabled")
473 {
474 const bool* hostNameEnabled =
475 std::get_if<bool>(&propertyPair.second);
476 if (hostNameEnabled != nullptr)
477 {
478 ethData.hostNamev6Enabled = *hostNameEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700479 }
480 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700481 }
482 }
483 }
Ed Tanous029573d2019-02-01 10:57:49 -0800484 // System configuration shows up in the global namespace, so no need
485 // to check eth number
486 if (ifacePair.first ==
487 "xyz.openbmc_project.Network.SystemConfiguration")
488 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500489 for (const auto& propertyPair : ifacePair.second)
Ed Tanous029573d2019-02-01 10:57:49 -0800490 {
491 if (propertyPair.first == "HostName")
492 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500493 const std::string* hostname =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500494 std::get_if<std::string>(&propertyPair.second);
Ed Tanous029573d2019-02-01 10:57:49 -0800495 if (hostname != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700496 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800497 ethData.hostName = *hostname;
Ed Tanous029573d2019-02-01 10:57:49 -0800498 }
499 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700500 }
501 }
502 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700503 }
Ed Tanous4c9afe42019-05-03 16:59:57 -0700504 return idFound;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700505}
506
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500507// Helper function that extracts data for single ethernet ipv6 address
Ed Tanous77179532023-02-28 10:45:28 -0800508inline void extractIPV6Data(const std::string& ethifaceId,
509 const dbus::utility::ManagedObjectType& dbusData,
510 std::vector<IPv6AddressData>& ipv6Config)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500511{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400512 const std::string ipPathStart =
513 "/xyz/openbmc_project/network/" + ethifaceId;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500514
515 // Since there might be several IPv6 configurations aligned with
516 // single ethernet interface, loop over all of them
Ed Tanous81ce6092020-12-17 16:54:55 +0000517 for (const auto& objpath : dbusData)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500518 {
519 // Check if proper pattern for object path appears
Tony Lee353163e2022-11-23 11:06:10 +0800520 if (objpath.first.str.starts_with(ipPathStart + "/"))
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500521 {
Ed Tanous9eb808c2022-01-25 10:19:23 -0800522 for (const auto& interface : objpath.second)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500523 {
524 if (interface.first == "xyz.openbmc_project.Network.IP")
525 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400526 auto type = std::ranges::find_if(
527 interface.second, [](const auto& property) {
528 return property.first == "Type";
529 });
Tony Lee353163e2022-11-23 11:06:10 +0800530 if (type == interface.second.end())
531 {
532 continue;
533 }
534
535 const std::string* typeStr =
536 std::get_if<std::string>(&type->second);
537
538 if (typeStr == nullptr ||
539 (*typeStr !=
540 "xyz.openbmc_project.Network.IP.Protocol.IPv6"))
541 {
542 continue;
543 }
544
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500545 // Instance IPv6AddressData structure, and set as
546 // appropriate
Ed Tanous77179532023-02-28 10:45:28 -0800547 IPv6AddressData& ipv6Address = ipv6Config.emplace_back();
Ed Tanous2c70f802020-09-28 14:29:23 -0700548 ipv6Address.id =
Tony Lee353163e2022-11-23 11:06:10 +0800549 objpath.first.str.substr(ipPathStart.size());
Ed Tanous9eb808c2022-01-25 10:19:23 -0800550 for (const auto& property : interface.second)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500551 {
552 if (property.first == "Address")
553 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500554 const std::string* address =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500555 std::get_if<std::string>(&property.second);
556 if (address != nullptr)
557 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700558 ipv6Address.address = *address;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500559 }
560 }
561 else if (property.first == "Origin")
562 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500563 const std::string* origin =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500564 std::get_if<std::string>(&property.second);
565 if (origin != nullptr)
566 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700567 ipv6Address.origin =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500568 translateAddressOriginDbusToRedfish(*origin,
569 false);
570 }
571 }
572 else if (property.first == "PrefixLength")
573 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500574 const uint8_t* prefix =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500575 std::get_if<uint8_t>(&property.second);
576 if (prefix != nullptr)
577 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700578 ipv6Address.prefixLength = *prefix;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500579 }
580 }
Asmitha Karunanithi889ff692021-11-29 08:43:30 -0600581 else if (property.first == "Type" ||
582 property.first == "Gateway")
583 {
584 // Type & Gateway is not used
585 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500586 else
587 {
Ed Tanous62598e32023-07-17 17:06:25 -0700588 BMCWEB_LOG_ERROR(
589 "Got extra property: {} on the {} object",
590 property.first, objpath.first.str);
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500591 }
592 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500593 }
594 }
595 }
596 }
597}
598
Ed Tanous4a0cb852018-10-15 07:55:04 -0700599// Helper function that extracts data for single ethernet ipv4 address
Ed Tanous77179532023-02-28 10:45:28 -0800600inline void extractIPData(const std::string& ethifaceId,
601 const dbus::utility::ManagedObjectType& dbusData,
602 std::vector<IPv4AddressData>& ipv4Config)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700603{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400604 const std::string ipPathStart =
605 "/xyz/openbmc_project/network/" + ethifaceId;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700606
607 // Since there might be several IPv4 configurations aligned with
608 // single ethernet interface, loop over all of them
Ed Tanous81ce6092020-12-17 16:54:55 +0000609 for (const auto& objpath : dbusData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700610 {
611 // Check if proper pattern for object path appears
Tony Lee353163e2022-11-23 11:06:10 +0800612 if (objpath.first.str.starts_with(ipPathStart + "/"))
Ed Tanous4a0cb852018-10-15 07:55:04 -0700613 {
Ed Tanous9eb808c2022-01-25 10:19:23 -0800614 for (const auto& interface : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700615 {
616 if (interface.first == "xyz.openbmc_project.Network.IP")
617 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400618 auto type = std::ranges::find_if(
619 interface.second, [](const auto& property) {
620 return property.first == "Type";
621 });
Tony Lee353163e2022-11-23 11:06:10 +0800622 if (type == interface.second.end())
623 {
624 continue;
625 }
626
627 const std::string* typeStr =
628 std::get_if<std::string>(&type->second);
629
630 if (typeStr == nullptr ||
631 (*typeStr !=
632 "xyz.openbmc_project.Network.IP.Protocol.IPv4"))
633 {
634 continue;
635 }
636
Ed Tanous4a0cb852018-10-15 07:55:04 -0700637 // Instance IPv4AddressData structure, and set as
638 // appropriate
Ed Tanous77179532023-02-28 10:45:28 -0800639 IPv4AddressData& ipv4Address = ipv4Config.emplace_back();
Ed Tanous2c70f802020-09-28 14:29:23 -0700640 ipv4Address.id =
Tony Lee353163e2022-11-23 11:06:10 +0800641 objpath.first.str.substr(ipPathStart.size());
Ed Tanous9eb808c2022-01-25 10:19:23 -0800642 for (const auto& property : interface.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700643 {
644 if (property.first == "Address")
645 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500646 const std::string* address =
Ed Tanousabf2add2019-01-22 16:40:12 -0800647 std::get_if<std::string>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700648 if (address != nullptr)
649 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700650 ipv4Address.address = *address;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700651 }
652 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700653 else if (property.first == "Origin")
654 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500655 const std::string* origin =
Ed Tanousabf2add2019-01-22 16:40:12 -0800656 std::get_if<std::string>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700657 if (origin != nullptr)
658 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700659 ipv4Address.origin =
Ed Tanous4a0cb852018-10-15 07:55:04 -0700660 translateAddressOriginDbusToRedfish(*origin,
661 true);
662 }
663 }
664 else if (property.first == "PrefixLength")
665 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500666 const uint8_t* mask =
Ed Tanousabf2add2019-01-22 16:40:12 -0800667 std::get_if<uint8_t>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700668 if (mask != nullptr)
669 {
670 // convert it to the string
Ed Tanous2c70f802020-09-28 14:29:23 -0700671 ipv4Address.netmask = getNetmask(*mask);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700672 }
673 }
Asmitha Karunanithi889ff692021-11-29 08:43:30 -0600674 else if (property.first == "Type" ||
675 property.first == "Gateway")
676 {
677 // Type & Gateway is not used
678 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700679 else
680 {
Ed Tanous62598e32023-07-17 17:06:25 -0700681 BMCWEB_LOG_ERROR(
682 "Got extra property: {} on the {} object",
683 property.first, objpath.first.str);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700684 }
685 }
686 // Check if given address is local, or global
Ed Tanous2c70f802020-09-28 14:29:23 -0700687 ipv4Address.linktype =
Ed Tanous11ba3972022-07-11 09:50:41 -0700688 ipv4Address.address.starts_with("169.254.")
Johnathan Mantey18659d12019-06-07 10:26:29 -0700689 ? LinkType::Local
690 : LinkType::Global;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700691 }
692 }
693 }
694 }
695}
696
697/**
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700698 * @brief Modifies the default gateway assigned to the NIC
699 *
700 * @param[in] ifaceId Id of network interface whose default gateway is to be
701 * changed
702 * @param[in] gateway The new gateway value. Assigning an empty string
703 * causes the gateway to be deleted
704 * @param[io] asyncResp Response object that will be returned to client
705 *
706 * @return None
707 */
708inline void updateIPv4DefaultGateway(
709 const std::string& ifaceId, const std::string& gateway,
710 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
711{
712 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530713 asyncResp, "Gateway", "xyz.openbmc_project.Network",
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700714 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
715 ifaceId,
716 "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway",
Ginu Georgee93abac2024-06-14 17:35:27 +0530717 gateway);
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700718}
719
720/**
721 * @brief Deletes given static IP address for the interface
Ed Tanous4a0cb852018-10-15 07:55:04 -0700722 *
723 * @param[in] ifaceId Id of interface whose IP should be deleted
Ed Tanous4a0cb852018-10-15 07:55:04 -0700724 * @param[in] ipHash DBus Hash id of IP that should be deleted
725 * @param[io] asyncResp Response object that will be returned to client
726 *
727 * @return None
728 */
Ravi Teja9c5e5852023-02-26 21:33:52 -0600729inline void deleteIPAddress(const std::string& ifaceId,
730 const std::string& ipHash,
731 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700732{
733 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800734 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400735 if (ec)
736 {
737 messages::internalError(asyncResp->res);
738 }
739 },
Ed Tanous4a0cb852018-10-15 07:55:04 -0700740 "xyz.openbmc_project.Network",
Ravi Teja9c5e5852023-02-26 21:33:52 -0600741 "/xyz/openbmc_project/network/" + ifaceId + ipHash,
Ed Tanous4a0cb852018-10-15 07:55:04 -0700742 "xyz.openbmc_project.Object.Delete", "Delete");
743}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700744
Ed Tanous4a0cb852018-10-15 07:55:04 -0700745/**
Johnathan Mantey01784822019-06-18 12:44:21 -0700746 * @brief Creates a static IPv4 entry
Ed Tanous4a0cb852018-10-15 07:55:04 -0700747 *
Johnathan Mantey01784822019-06-18 12:44:21 -0700748 * @param[in] ifaceId Id of interface upon which to create the IPv4 entry
749 * @param[in] prefixLength IPv4 prefix syntax for the subnet mask
750 * @param[in] gateway IPv4 address of this interfaces gateway
751 * @param[in] address IPv4 address to assign to this interface
752 * @param[io] asyncResp Response object that will be returned to client
Ed Tanous4a0cb852018-10-15 07:55:04 -0700753 *
754 * @return None
755 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000756inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
757 const std::string& gateway, const std::string& address,
zhanghch058d1b46d2021-04-01 11:18:24 +0800758 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700759{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400760 auto createIpHandler =
761 [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
762 if (ec)
763 {
764 messages::internalError(asyncResp->res);
765 return;
766 }
767 };
Ravi Teja9010ec22019-08-01 23:30:25 -0500768
Ed Tanous4a0cb852018-10-15 07:55:04 -0700769 crow::connections::systemBus->async_method_call(
Ravi Teja9010ec22019-08-01 23:30:25 -0500770 std::move(createIpHandler), "xyz.openbmc_project.Network",
Ed Tanous4a0cb852018-10-15 07:55:04 -0700771 "/xyz/openbmc_project/network/" + ifaceId,
772 "xyz.openbmc_project.Network.IP.Create", "IP",
Johnathan Mantey01784822019-06-18 12:44:21 -0700773 "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength,
Ed Tanous4a0cb852018-10-15 07:55:04 -0700774 gateway);
775}
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500776
777/**
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700778 * @brief Deletes the IP entry for this interface and creates a replacement
779 * static entry
Johnathan Mantey01784822019-06-18 12:44:21 -0700780 *
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700781 * @param[in] ifaceId Id of interface upon which to create the IPv6 entry
782 * @param[in] id The unique hash entry identifying the DBus entry
783 * @param[in] prefixLength Prefix syntax for the subnet mask
784 * @param[in] address Address to assign to this interface
785 * @param[in] numStaticAddrs Count of IPv4 static addresses
786 * @param[io] asyncResp Response object that will be returned to client
Johnathan Mantey01784822019-06-18 12:44:21 -0700787 *
788 * @return None
789 */
Ravi Teja9c5e5852023-02-26 21:33:52 -0600790
Ravi Teja9c5e5852023-02-26 21:33:52 -0600791inline void deleteAndCreateIPAddress(
792 IpVersion version, const std::string& ifaceId, const std::string& id,
793 uint8_t prefixLength, const std::string& address,
794 const std::string& gateway,
795 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Johnathan Mantey01784822019-06-18 12:44:21 -0700796{
797 crow::connections::systemBus->async_method_call(
Ravi Teja9c5e5852023-02-26 21:33:52 -0600798 [asyncResp, version, ifaceId, address, prefixLength,
799 gateway](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400800 if (ec)
Johnathan Mantey01784822019-06-18 12:44:21 -0700801 {
802 messages::internalError(asyncResp->res);
803 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400804 std::string protocol = "xyz.openbmc_project.Network.IP.Protocol.";
805 protocol += version == IpVersion::IpV4 ? "IPv4" : "IPv6";
806 crow::connections::systemBus->async_method_call(
807 [asyncResp](const boost::system::error_code& ec2) {
808 if (ec2)
809 {
810 messages::internalError(asyncResp->res);
811 }
812 },
813 "xyz.openbmc_project.Network",
814 "/xyz/openbmc_project/network/" + ifaceId,
815 "xyz.openbmc_project.Network.IP.Create", "IP", protocol,
816 address, prefixLength, gateway);
Patrick Williams5a39f772023-10-20 11:20:21 -0500817 },
Johnathan Mantey01784822019-06-18 12:44:21 -0700818 "xyz.openbmc_project.Network",
Ravi Teja9c5e5852023-02-26 21:33:52 -0600819 "/xyz/openbmc_project/network/" + ifaceId + id,
Johnathan Mantey01784822019-06-18 12:44:21 -0700820 "xyz.openbmc_project.Object.Delete", "Delete");
821}
822
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500823inline bool extractIPv6DefaultGatewayData(
824 const std::string& ethifaceId,
825 const dbus::utility::ManagedObjectType& dbusData,
826 std::vector<StaticGatewayData>& staticGatewayConfig)
827{
828 std::string staticGatewayPathStart("/xyz/openbmc_project/network/");
829 staticGatewayPathStart += ethifaceId;
830
831 for (const auto& objpath : dbusData)
832 {
833 if (!std::string_view(objpath.first.str)
834 .starts_with(staticGatewayPathStart))
835 {
836 continue;
837 }
838 for (const auto& interface : objpath.second)
839 {
840 if (interface.first != "xyz.openbmc_project.Network.StaticGateway")
841 {
842 continue;
843 }
844 StaticGatewayData& staticGateway =
845 staticGatewayConfig.emplace_back();
846 staticGateway.id = objpath.first.filename();
847
848 bool success = sdbusplus::unpackPropertiesNoThrow(
849 redfish::dbus_utils::UnpackErrorPrinter(), interface.second,
Ravi Tejaab0d4392024-09-03 12:27:40 -0500850 "Gateway", staticGateway.gateway, "ProtocolType",
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500851 staticGateway.protocol);
852 if (!success)
853 {
854 return false;
855 }
856 }
857 }
858 return true;
859}
860
Johnathan Mantey01784822019-06-18 12:44:21 -0700861/**
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500862 * @brief Creates IPv6 with given data
863 *
864 * @param[in] ifaceId Id of interface whose IP should be added
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500865 * @param[in] prefixLength Prefix length that needs to be added
866 * @param[in] address IP address that needs to be added
867 * @param[io] asyncResp Response object that will be returned to client
868 *
869 * @return None
870 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500871inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength,
872 const std::string& address,
zhanghch058d1b46d2021-04-01 11:18:24 +0800873 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500874{
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500875 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
876 path /= ifaceId;
877
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400878 auto createIpHandler =
879 [asyncResp, address](const boost::system::error_code& ec) {
880 if (ec)
Nitin Kumar Kotaniafc23ef82023-06-29 04:55:09 -0500881 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400882 if (ec == boost::system::errc::io_error)
883 {
884 messages::propertyValueFormatError(asyncResp->res, address,
885 "Address");
886 }
887 else
888 {
889 messages::internalError(asyncResp->res);
890 }
Nitin Kumar Kotaniafc23ef82023-06-29 04:55:09 -0500891 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400892 };
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500893 // Passing null for gateway, as per redfish spec IPv6StaticAddresses
894 // object does not have associated gateway property
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500895 crow::connections::systemBus->async_method_call(
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500896 std::move(createIpHandler), "xyz.openbmc_project.Network", path,
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500897 "xyz.openbmc_project.Network.IP.Create", "IP",
898 "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength,
899 "");
900}
901
Ed Tanous4a0cb852018-10-15 07:55:04 -0700902/**
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500903 * @brief Deletes given IPv6 Static Gateway
904 *
905 * @param[in] ifaceId Id of interface whose IP should be deleted
906 * @param[in] ipHash DBus Hash id of IP that should be deleted
907 * @param[io] asyncResp Response object that will be returned to client
908 *
909 * @return None
910 */
911inline void
Ravi Teja739b27b2024-08-27 21:03:53 -0500912 deleteIPv6Gateway(std::string_view ifaceId, std::string_view gatewayId,
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500913 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
914{
915 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
Ravi Teja739b27b2024-08-27 21:03:53 -0500916 path /= ifaceId;
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500917 path /= gatewayId;
918 crow::connections::systemBus->async_method_call(
919 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400920 if (ec)
921 {
922 messages::internalError(asyncResp->res);
923 }
924 },
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500925 "xyz.openbmc_project.Network", path,
926 "xyz.openbmc_project.Object.Delete", "Delete");
927}
928
929/**
930 * @brief Creates IPv6 static default gateway with given data
931 *
932 * @param[in] ifaceId Id of interface whose IP should be added
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500933 * @param[in] gateway Gateway address that needs to be added
934 * @param[io] asyncResp Response object that will be returned to client
935 *
936 * @return None
937 */
938inline void createIPv6DefaultGateway(
Ravi Tejaab0d4392024-09-03 12:27:40 -0500939 std::string_view ifaceId, std::string_view gateway,
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500940 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
941{
942 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
943 path /= ifaceId;
944 auto createIpHandler = [asyncResp](const boost::system::error_code& ec) {
945 if (ec)
946 {
947 messages::internalError(asyncResp->res);
948 }
949 };
950 crow::connections::systemBus->async_method_call(
951 std::move(createIpHandler), "xyz.openbmc_project.Network", path,
952 "xyz.openbmc_project.Network.StaticGateway.Create", "StaticGateway",
Ravi Tejaab0d4392024-09-03 12:27:40 -0500953 gateway, "xyz.openbmc_project.Network.IP.Protocol.IPv6");
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500954}
955
956/**
957 * @brief Deletes the IPv6 default gateway entry for this interface and
958 * creates a replacement IPv6 default gateway entry
959 *
960 * @param[in] ifaceId Id of interface upon which to create the IPv6
961 * entry
962 * @param[in] gateway IPv6 gateway to assign to this interface
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500963 * @param[io] asyncResp Response object that will be returned to client
964 *
965 * @return None
966 */
967inline void deleteAndCreateIPv6DefaultGateway(
968 std::string_view ifaceId, std::string_view gatewayId,
Ravi Tejaab0d4392024-09-03 12:27:40 -0500969 std::string_view gateway,
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500970 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
971{
972 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
Ravi Teja739b27b2024-08-27 21:03:53 -0500973 path /= ifaceId;
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500974 path /= gatewayId;
975 crow::connections::systemBus->async_method_call(
Ravi Tejaab0d4392024-09-03 12:27:40 -0500976 [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400977 if (ec)
978 {
979 messages::internalError(asyncResp->res);
980 return;
981 }
Ravi Tejaab0d4392024-09-03 12:27:40 -0500982 createIPv6DefaultGateway(ifaceId, gateway, asyncResp);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400983 },
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500984 "xyz.openbmc_project.Network", path,
985 "xyz.openbmc_project.Object.Delete", "Delete");
986}
987
988/**
989 * @brief Sets IPv6 default gateway with given data
990 *
991 * @param[in] ifaceId Id of interface whose gateway should be added
992 * @param[in] input Contains address that needs to be added
993 * @param[in] staticGatewayData Current static gateways in the system
994 * @param[io] asyncResp Response object that will be returned to client
995 *
996 * @return None
997 */
998
999inline void handleIPv6DefaultGateway(
Ed Tanous3dfed532024-03-06 14:41:27 -08001000 const std::string& ifaceId,
1001 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001002 const std::vector<StaticGatewayData>& staticGatewayData,
1003 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1004{
1005 size_t entryIdx = 1;
1006 std::vector<StaticGatewayData>::const_iterator staticGatewayEntry =
1007 staticGatewayData.begin();
1008
Ed Tanous3dfed532024-03-06 14:41:27 -08001009 for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
1010 input)
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001011 {
1012 // find the next gateway entry
1013 while (staticGatewayEntry != staticGatewayData.end())
1014 {
1015 if (staticGatewayEntry->protocol ==
1016 "xyz.openbmc_project.Network.IP.Protocol.IPv6")
1017 {
1018 break;
1019 }
1020 staticGatewayEntry++;
1021 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001022 std::string pathString =
1023 "IPv6StaticDefaultGateways/" + std::to_string(entryIdx);
Ed Tanous3dfed532024-03-06 14:41:27 -08001024 nlohmann::json::object_t* obj =
1025 std::get_if<nlohmann::json::object_t>(&thisJson);
1026 if (obj == nullptr)
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001027 {
1028 if (staticGatewayEntry == staticGatewayData.end())
1029 {
1030 messages::resourceCannotBeDeleted(asyncResp->res);
1031 return;
1032 }
Ravi Teja739b27b2024-08-27 21:03:53 -05001033 deleteIPv6Gateway(ifaceId, staticGatewayEntry->id, asyncResp);
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001034 return;
1035 }
Ed Tanous3dfed532024-03-06 14:41:27 -08001036 if (obj->empty())
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001037 {
1038 // Do nothing, but make sure the entry exists.
1039 if (staticGatewayEntry == staticGatewayData.end())
1040 {
Ed Tanous3dfed532024-03-06 14:41:27 -08001041 messages::propertyValueFormatError(asyncResp->res, *obj,
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001042 pathString);
1043 return;
1044 }
1045 }
1046 std::optional<std::string> address;
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001047
Ravi Tejaab0d4392024-09-03 12:27:40 -05001048 if (!json_util::readJsonObject(*obj, asyncResp->res, "Address",
1049 address))
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001050 {
1051 return;
1052 }
1053 const std::string* addr = nullptr;
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001054 if (address)
1055 {
1056 addr = &(*address);
1057 }
1058 else if (staticGatewayEntry != staticGatewayData.end())
1059 {
1060 addr = &(staticGatewayEntry->gateway);
1061 }
1062 else
1063 {
1064 messages::propertyMissing(asyncResp->res, pathString + "/Address");
1065 return;
1066 }
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001067 if (staticGatewayEntry != staticGatewayData.end())
1068 {
1069 deleteAndCreateIPv6DefaultGateway(ifaceId, staticGatewayEntry->id,
Ravi Tejaab0d4392024-09-03 12:27:40 -05001070 *addr, asyncResp);
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001071 staticGatewayEntry++;
1072 }
1073 else
1074 {
Ravi Tejaab0d4392024-09-03 12:27:40 -05001075 createIPv6DefaultGateway(ifaceId, *addr, asyncResp);
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001076 }
1077 entryIdx++;
1078 }
1079}
1080
1081/**
Ed Tanous4a0cb852018-10-15 07:55:04 -07001082 * Function that retrieves all properties for given Ethernet Interface
1083 * Object
1084 * from EntityManager Network Manager
1085 * @param ethiface_id a eth interface id to query on DBus
1086 * @param callback a function that shall be called to convert Dbus output
1087 * into JSON
1088 */
1089template <typename CallbackFunc>
Ed Tanous81ce6092020-12-17 16:54:55 +00001090void getEthernetIfaceData(const std::string& ethifaceId,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001091 CallbackFunc&& callback)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001092{
George Liuf5892d02023-03-01 10:37:08 +08001093 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1094 dbus::utility::getManagedObjects(
1095 "xyz.openbmc_project.Network", path,
Ed Tanousf94c4ec2022-01-06 12:44:41 -08001096 [ethifaceId{std::string{ethifaceId}},
Ed Tanous8cb2c022024-03-27 16:31:46 -07001097 callback = std::forward<CallbackFunc>(callback)](
Ed Tanous8b242752023-06-27 17:17:13 -07001098 const boost::system::error_code& ec,
Ed Tanous3dfed532024-03-06 14:41:27 -08001099 const dbus::utility::ManagedObjectType& resp) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001100 EthernetInterfaceData ethData{};
1101 std::vector<IPv4AddressData> ipv4Data;
1102 std::vector<IPv6AddressData> ipv6Data;
1103 std::vector<StaticGatewayData> ipv6GatewayData;
Ed Tanous4a0cb852018-10-15 07:55:04 -07001104
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001105 if (ec)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001106 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001107 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1108 return;
Ed Tanous4a0cb852018-10-15 07:55:04 -07001109 }
1110
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001111 bool found =
1112 extractEthernetInterfaceData(ethifaceId, resp, ethData);
1113 if (!found)
1114 {
1115 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1116 return;
1117 }
1118
1119 extractIPData(ethifaceId, resp, ipv4Data);
1120 // Fix global GW
1121 for (IPv4AddressData& ipv4 : ipv4Data)
1122 {
1123 if (((ipv4.linktype == LinkType::Global) &&
1124 (ipv4.gateway == "0.0.0.0")) ||
1125 (ipv4.origin == "DHCP") || (ipv4.origin == "Static"))
1126 {
1127 ipv4.gateway = ethData.defaultGateway;
1128 }
1129 }
1130
1131 extractIPV6Data(ethifaceId, resp, ipv6Data);
1132 if (!extractIPv6DefaultGatewayData(ethifaceId, resp,
1133 ipv6GatewayData))
1134 {
1135 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1136 }
1137 // Finally make a callback with useful data
1138 callback(true, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1139 });
Ed Tanous271584a2019-07-09 16:24:22 -07001140}
Ed Tanous4a0cb852018-10-15 07:55:04 -07001141
1142/**
1143 * Function that retrieves all Ethernet Interfaces available through Network
1144 * Manager
1145 * @param callback a function that shall be called to convert Dbus output
1146 * into JSON.
1147 */
1148template <typename CallbackFunc>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001149void getEthernetIfaceList(CallbackFunc&& callback)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001150{
George Liuf5892d02023-03-01 10:37:08 +08001151 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1152 dbus::utility::getManagedObjects(
1153 "xyz.openbmc_project.Network", path,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001154 [callback = std::forward<CallbackFunc>(callback)](
Ed Tanous8b242752023-06-27 17:17:13 -07001155 const boost::system::error_code& ec,
George Liuf5892d02023-03-01 10:37:08 +08001156 const dbus::utility::ManagedObjectType& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001157 // Callback requires vector<string> to retrieve all available
1158 // ethernet interfaces
1159 std::vector<std::string> ifaceList;
1160 ifaceList.reserve(resp.size());
1161 if (ec)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001162 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001163 callback(false, ifaceList);
1164 return;
1165 }
1166
1167 // Iterate over all retrieved ObjectPaths.
1168 for (const auto& objpath : resp)
1169 {
1170 // And all interfaces available for certain ObjectPath.
1171 for (const auto& interface : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001172 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001173 // If interface is
1174 // xyz.openbmc_project.Network.EthernetInterface, this is
1175 // what we're looking for.
1176 if (interface.first ==
1177 "xyz.openbmc_project.Network.EthernetInterface")
Ed Tanous1abe55e2018-09-05 08:30:59 -07001178 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001179 std::string ifaceId = objpath.first.filename();
1180 if (ifaceId.empty())
1181 {
1182 continue;
1183 }
1184 // and put it into output vector.
1185 ifaceList.emplace_back(ifaceId);
Ed Tanous1abe55e2018-09-05 08:30:59 -07001186 }
1187 }
Ed Tanous4a0cb852018-10-15 07:55:04 -07001188 }
Ed Tanous2c5875a2023-05-15 09:56:06 -07001189
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001190 std::ranges::sort(ifaceList, AlphanumLess<std::string>());
Ed Tanous2c5875a2023-05-15 09:56:06 -07001191
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001192 // Finally make a callback with useful data
1193 callback(true, ifaceList);
1194 });
Ed Tanous271584a2019-07-09 16:24:22 -07001195}
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +01001196
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001197inline void
1198 handleHostnamePatch(const std::string& hostname,
1199 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001200{
Ed Tanousbf648f72021-06-03 15:00:14 -07001201 // SHOULD handle host names of up to 255 characters(RFC 1123)
1202 if (hostname.length() > 255)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001203 {
Ed Tanousbf648f72021-06-03 15:00:14 -07001204 messages::propertyValueFormatError(asyncResp->res, hostname,
1205 "HostName");
1206 return;
1207 }
Ed Tanousd02aad32024-02-13 14:43:34 -08001208 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301209 asyncResp, "HostName", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001210 sdbusplus::message::object_path("/xyz/openbmc_project/network/config"),
1211 "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
Ginu Georgee93abac2024-06-14 17:35:27 +05301212 hostname);
Ed Tanousbf648f72021-06-03 15:00:14 -07001213}
1214
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001215inline void
Tejas Patil35fb5312021-09-20 15:35:20 +05301216 handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize,
1217 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1218{
Ed Tanousd02aad32024-02-13 14:43:34 -08001219 sdbusplus::message::object_path objPath("/xyz/openbmc_project/network");
1220 objPath /= ifaceId;
Ginu Georgee93abac2024-06-14 17:35:27 +05301221 setDbusProperty(asyncResp, "MTUSize", "xyz.openbmc_project.Network",
1222 objPath, "xyz.openbmc_project.Network.EthernetInterface",
1223 "MTU", mtuSize);
Tejas Patil35fb5312021-09-20 15:35:20 +05301224}
1225
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001226inline void handleDomainnamePatch(
1227 const std::string& ifaceId, const std::string& domainname,
1228 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001229{
1230 std::vector<std::string> vectorDomainname = {domainname};
Ed Tanousd02aad32024-02-13 14:43:34 -08001231 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301232 asyncResp, "FQDN", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001233 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1234 ifaceId,
Ginu Georgee93abac2024-06-14 17:35:27 +05301235 "xyz.openbmc_project.Network.EthernetInterface", "DomainName",
Ed Tanousd02aad32024-02-13 14:43:34 -08001236 vectorDomainname);
Ed Tanousbf648f72021-06-03 15:00:14 -07001237}
1238
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001239inline bool isHostnameValid(const std::string& hostname)
Ed Tanousbf648f72021-06-03 15:00:14 -07001240{
1241 // A valid host name can never have the dotted-decimal form (RFC 1123)
Ed Tanous3544d2a2023-08-06 18:12:20 -07001242 if (std::ranges::all_of(hostname, ::isdigit))
Ed Tanousbf648f72021-06-03 15:00:14 -07001243 {
1244 return false;
1245 }
1246 // Each label(hostname/subdomains) within a valid FQDN
1247 // MUST handle host names of up to 63 characters (RFC 1123)
1248 // labels cannot start or end with hyphens (RFC 952)
1249 // labels can start with numbers (RFC 1123)
Ed Tanous4b242742023-05-11 09:51:51 -07001250 const static std::regex pattern(
Ed Tanousbf648f72021-06-03 15:00:14 -07001251 "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$");
1252
1253 return std::regex_match(hostname, pattern);
1254}
1255
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001256inline bool isDomainnameValid(const std::string& domainname)
Ed Tanousbf648f72021-06-03 15:00:14 -07001257{
1258 // Can have multiple subdomains
1259 // Top Level Domain's min length is 2 character
Ed Tanous4b242742023-05-11 09:51:51 -07001260 const static std::regex pattern(
George Liu0fda0f12021-11-16 10:06:17 +08001261 "^([A-Za-z0-9][a-zA-Z0-9\\-]{1,61}|[a-zA-Z0-9]{1,30}\\.)*[a-zA-Z]{2,}$");
Ed Tanousbf648f72021-06-03 15:00:14 -07001262
1263 return std::regex_match(domainname, pattern);
1264}
1265
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001266inline void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn,
1267 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001268{
1269 // Total length of FQDN must not exceed 255 characters(RFC 1035)
1270 if (fqdn.length() > 255)
1271 {
1272 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1273 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -07001274 }
1275
Ed Tanousbf648f72021-06-03 15:00:14 -07001276 size_t pos = fqdn.find('.');
1277 if (pos == std::string::npos)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001278 {
Ed Tanousbf648f72021-06-03 15:00:14 -07001279 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1280 return;
1281 }
zhanghch058d1b46d2021-04-01 11:18:24 +08001282
Ed Tanousbf648f72021-06-03 15:00:14 -07001283 std::string hostname;
1284 std::string domainname;
1285 domainname = (fqdn).substr(pos + 1);
1286 hostname = (fqdn).substr(0, pos);
1287
1288 if (!isHostnameValid(hostname) || !isDomainnameValid(domainname))
1289 {
1290 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1291 return;
1292 }
1293
1294 handleHostnamePatch(hostname, asyncResp);
1295 handleDomainnamePatch(ifaceId, domainname, asyncResp);
1296}
1297
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001298inline void handleMACAddressPatch(
1299 const std::string& ifaceId, const std::string& macAddress,
1300 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001301{
Ed Tanousd02aad32024-02-13 14:43:34 -08001302 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301303 asyncResp, "MACAddress", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001304 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1305 ifaceId,
Ginu Georgee93abac2024-06-14 17:35:27 +05301306 "xyz.openbmc_project.Network.MACAddress", "MACAddress", macAddress);
Ed Tanousbf648f72021-06-03 15:00:14 -07001307}
1308
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001309inline void setDHCPEnabled(const std::string& ifaceId,
1310 const std::string& propertyName, const bool v4Value,
1311 const bool v6Value,
1312 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001313{
1314 const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
Ed Tanousd02aad32024-02-13 14:43:34 -08001315 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301316 asyncResp, "DHCPv4", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001317 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1318 ifaceId,
Ginu Georgee93abac2024-06-14 17:35:27 +05301319 "xyz.openbmc_project.Network.EthernetInterface", propertyName, dhcp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001320}
1321
Jishnu CMe4588152023-05-11 00:04:40 -05001322enum class NetworkType
1323{
1324 dhcp4,
1325 dhcp6
1326};
1327
1328inline void setDHCPConfig(const std::string& propertyName, const bool& value,
1329 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1330 const std::string& ethifaceId, NetworkType type)
Ed Tanousbf648f72021-06-03 15:00:14 -07001331{
Ed Tanous62598e32023-07-17 17:06:25 -07001332 BMCWEB_LOG_DEBUG("{} = {}", propertyName, value);
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001333 std::string redfishPropertyName;
Jishnu CMe4588152023-05-11 00:04:40 -05001334 sdbusplus::message::object_path path("/xyz/openbmc_project/network/");
1335 path /= ethifaceId;
1336
1337 if (type == NetworkType::dhcp4)
1338 {
1339 path /= "dhcp4";
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001340 redfishPropertyName = "DHCPv4";
Jishnu CMe4588152023-05-11 00:04:40 -05001341 }
1342 else
1343 {
1344 path /= "dhcp6";
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001345 redfishPropertyName = "DHCPv6";
Jishnu CMe4588152023-05-11 00:04:40 -05001346 }
1347
Ginu Georgee93abac2024-06-14 17:35:27 +05301348 setDbusProperty(
1349 asyncResp, redfishPropertyName, "xyz.openbmc_project.Network", path,
1350 "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, value);
Ed Tanousbf648f72021-06-03 15:00:14 -07001351}
1352
Ravi Tejab10d8db2022-05-24 09:04:12 -05001353inline void handleSLAACAutoConfigPatch(
1354 const std::string& ifaceId, bool ipv6AutoConfigEnabled,
1355 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1356{
1357 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1358 path /= ifaceId;
Ginu Georgee93abac2024-06-14 17:35:27 +05301359 setDbusProperty(asyncResp,
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001360 "StatelessAddressAutoConfig/IPv6AutoConfigEnabled",
Ginu Georgee93abac2024-06-14 17:35:27 +05301361 "xyz.openbmc_project.Network", path,
1362 "xyz.openbmc_project.Network.EthernetInterface",
1363 "IPv6AcceptRA", ipv6AutoConfigEnabled);
Ravi Tejab10d8db2022-05-24 09:04:12 -05001364}
1365
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001366inline void handleDHCPPatch(
1367 const std::string& ifaceId, const EthernetInterfaceData& ethData,
1368 const DHCPParameters& v4dhcpParms, const DHCPParameters& v6dhcpParms,
1369 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001370{
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001371 bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
1372 bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false);
Ed Tanousbf648f72021-06-03 15:00:14 -07001373
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001374 if (ipv4Active)
1375 {
1376 updateIPv4DefaultGateway(ifaceId, "", asyncResp);
1377 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001378 bool nextv4DHCPState =
1379 v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active;
1380
1381 bool nextv6DHCPState{};
1382 if (v6dhcpParms.dhcpv6OperatingMode)
1383 {
Ravi Tejab10d8db2022-05-24 09:04:12 -05001384 if ((*v6dhcpParms.dhcpv6OperatingMode != "Enabled") &&
Ed Tanousbf648f72021-06-03 15:00:14 -07001385 (*v6dhcpParms.dhcpv6OperatingMode != "Disabled"))
1386 {
1387 messages::propertyValueFormatError(asyncResp->res,
1388 *v6dhcpParms.dhcpv6OperatingMode,
1389 "OperatingMode");
1390 return;
1391 }
Ravi Tejab10d8db2022-05-24 09:04:12 -05001392 nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Enabled");
Ed Tanousbf648f72021-06-03 15:00:14 -07001393 }
1394 else
1395 {
1396 nextv6DHCPState = ipv6Active;
1397 }
1398
Jishnu CMe4588152023-05-11 00:04:40 -05001399 bool nextDNSv4 = ethData.dnsv4Enabled;
1400 bool nextDNSv6 = ethData.dnsv6Enabled;
1401 if (v4dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001402 {
Jishnu CMe4588152023-05-11 00:04:40 -05001403 nextDNSv4 = *v4dhcpParms.useDnsServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001404 }
Jishnu CMe4588152023-05-11 00:04:40 -05001405 if (v6dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001406 {
Jishnu CMe4588152023-05-11 00:04:40 -05001407 nextDNSv6 = *v6dhcpParms.useDnsServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001408 }
1409
Jishnu CMe4588152023-05-11 00:04:40 -05001410 bool nextNTPv4 = ethData.ntpv4Enabled;
1411 bool nextNTPv6 = ethData.ntpv6Enabled;
1412 if (v4dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001413 {
Jishnu CMe4588152023-05-11 00:04:40 -05001414 nextNTPv4 = *v4dhcpParms.useNtpServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001415 }
Jishnu CMe4588152023-05-11 00:04:40 -05001416 if (v6dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001417 {
Jishnu CMe4588152023-05-11 00:04:40 -05001418 nextNTPv6 = *v6dhcpParms.useNtpServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001419 }
1420
Ravi Teja91c441e2024-02-23 09:03:43 -06001421 bool nextUsev4Domain = ethData.domainv4Enabled;
1422 bool nextUsev6Domain = ethData.domainv6Enabled;
Jishnu CMe4588152023-05-11 00:04:40 -05001423 if (v4dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001424 {
Jishnu CMe4588152023-05-11 00:04:40 -05001425 nextUsev4Domain = *v4dhcpParms.useDomainName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001426 }
Jishnu CMe4588152023-05-11 00:04:40 -05001427 if (v6dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001428 {
Jishnu CMe4588152023-05-11 00:04:40 -05001429 nextUsev6Domain = *v6dhcpParms.useDomainName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001430 }
1431
Ed Tanous62598e32023-07-17 17:06:25 -07001432 BMCWEB_LOG_DEBUG("set DHCPEnabled...");
Ed Tanousbf648f72021-06-03 15:00:14 -07001433 setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
1434 asyncResp);
Ed Tanous62598e32023-07-17 17:06:25 -07001435 BMCWEB_LOG_DEBUG("set DNSEnabled...");
Jishnu CMe4588152023-05-11 00:04:40 -05001436 setDHCPConfig("DNSEnabled", nextDNSv4, asyncResp, ifaceId,
1437 NetworkType::dhcp4);
Ed Tanous62598e32023-07-17 17:06:25 -07001438 BMCWEB_LOG_DEBUG("set NTPEnabled...");
Jishnu CMe4588152023-05-11 00:04:40 -05001439 setDHCPConfig("NTPEnabled", nextNTPv4, asyncResp, ifaceId,
1440 NetworkType::dhcp4);
Ravi Teja91c441e2024-02-23 09:03:43 -06001441 BMCWEB_LOG_DEBUG("set DomainEnabled...");
1442 setDHCPConfig("DomainEnabled", nextUsev4Domain, asyncResp, ifaceId,
Jishnu CMe4588152023-05-11 00:04:40 -05001443 NetworkType::dhcp4);
1444 BMCWEB_LOG_DEBUG("set DNSEnabled for dhcp6...");
1445 setDHCPConfig("DNSEnabled", nextDNSv6, asyncResp, ifaceId,
1446 NetworkType::dhcp6);
1447 BMCWEB_LOG_DEBUG("set NTPEnabled for dhcp6...");
1448 setDHCPConfig("NTPEnabled", nextNTPv6, asyncResp, ifaceId,
1449 NetworkType::dhcp6);
Ravi Teja91c441e2024-02-23 09:03:43 -06001450 BMCWEB_LOG_DEBUG("set DomainEnabled for dhcp6...");
1451 setDHCPConfig("DomainEnabled", nextUsev6Domain, asyncResp, ifaceId,
Jishnu CMe4588152023-05-11 00:04:40 -05001452 NetworkType::dhcp6);
Ed Tanousbf648f72021-06-03 15:00:14 -07001453}
1454
Ed Tanous77179532023-02-28 10:45:28 -08001455inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry(
1456 const std::vector<IPv4AddressData>::const_iterator& head,
1457 const std::vector<IPv4AddressData>::const_iterator& end)
Ed Tanousbf648f72021-06-03 15:00:14 -07001458{
1459 return std::find_if(head, end, [](const IPv4AddressData& value) {
1460 return value.origin == "Static";
1461 });
1462}
1463
Ed Tanous77179532023-02-28 10:45:28 -08001464inline std::vector<IPv6AddressData>::const_iterator getNextStaticIpEntry(
1465 const std::vector<IPv6AddressData>::const_iterator& head,
1466 const std::vector<IPv6AddressData>::const_iterator& end)
Ed Tanousbf648f72021-06-03 15:00:14 -07001467{
1468 return std::find_if(head, end, [](const IPv6AddressData& value) {
1469 return value.origin == "Static";
1470 });
1471}
1472
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001473enum class AddrChange
Ed Tanousbf648f72021-06-03 15:00:14 -07001474{
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001475 Noop,
1476 Delete,
1477 Update,
1478};
1479
1480// Struct representing a dbus change
1481struct AddressPatch
1482{
1483 std::string address;
1484 std::string gateway;
1485 uint8_t prefixLength = 0;
1486 std::string existingDbusId;
1487 AddrChange operation = AddrChange::Noop;
1488};
1489
1490inline bool parseAddresses(
1491 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
1492 const std::vector<IPv4AddressData>& ipv4Data, crow::Response& res,
1493 std::vector<AddressPatch>& addressesOut, std::string& gatewayOut)
1494{
Ed Tanous77179532023-02-28 10:45:28 -08001495 std::vector<IPv4AddressData>::const_iterator nicIpEntry =
Ed Tanousbf648f72021-06-03 15:00:14 -07001496 getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend());
1497
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001498 std::string lastGatewayPath;
1499 size_t entryIdx = 0;
Ed Tanous3dfed532024-03-06 14:41:27 -08001500 for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
1501 input)
Ed Tanousbf648f72021-06-03 15:00:14 -07001502 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001503 std::string pathString =
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001504 std::format("IPv4StaticAddresses/{}", entryIdx);
1505 AddressPatch& thisAddress = addressesOut.emplace_back();
Ed Tanous3dfed532024-03-06 14:41:27 -08001506 nlohmann::json::object_t* obj =
1507 std::get_if<nlohmann::json::object_t>(&thisJson);
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001508 if (nicIpEntry != ipv4Data.cend())
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001509 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001510 thisAddress.existingDbusId = nicIpEntry->id;
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001511 }
1512
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001513 if (obj == nullptr)
1514 {
1515 if (thisAddress.existingDbusId.empty())
1516 {
1517 // Received a DELETE action on an entry not assigned to the NIC
1518 messages::resourceCannotBeDeleted(res);
1519 return false;
1520 }
1521 thisAddress.operation = AddrChange::Delete;
1522 }
1523 else
Ed Tanousbf648f72021-06-03 15:00:14 -07001524 {
1525 std::optional<std::string> address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001526 std::optional<std::string> gateway;
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001527 std::optional<std::string> subnetMask;
1528 if (!obj->empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001529 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001530 if (!json_util::readJsonObject( //
1531 *obj, res, //
1532 "Address", address, //
1533 "Gateway", gateway, //
1534 "SubnetMask", subnetMask //
1535 ))
1536 {
1537 messages::propertyValueFormatError(res, *obj, pathString);
1538 return false;
1539 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001540 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001541 // Find the address/subnet/gateway values. Any values that are
1542 // not explicitly provided are assumed to be unmodified from the
1543 // current state of the interface. Merge existing state into the
1544 // current request.
Ed Tanousbf648f72021-06-03 15:00:14 -07001545 if (address)
1546 {
Ed Tanouse01d0c32023-06-30 13:21:32 -07001547 if (!ip_util::ipv4VerifyIpAndGetBitcount(*address))
Ed Tanousbf648f72021-06-03 15:00:14 -07001548 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001549 messages::propertyValueFormatError(res, *address,
Ed Tanousbf648f72021-06-03 15:00:14 -07001550 pathString + "/Address");
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001551 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001552 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001553 thisAddress.operation = AddrChange::Update;
1554 thisAddress.address = *address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001555 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001556 else if (thisAddress.existingDbusId.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001557 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001558 messages::propertyMissing(res, pathString + "/Address");
1559 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001560 }
1561 else
1562 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001563 thisAddress.address = nicIpEntry->address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001564 }
1565
1566 if (subnetMask)
1567 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001568 uint8_t prefixLength = 0;
Ed Tanous033f1e42022-08-15 09:47:37 -07001569 if (!ip_util::ipv4VerifyIpAndGetBitcount(*subnetMask,
1570 &prefixLength))
Ed Tanousbf648f72021-06-03 15:00:14 -07001571 {
1572 messages::propertyValueFormatError(
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001573 res, *subnetMask, pathString + "/SubnetMask");
1574 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001575 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001576 thisAddress.prefixLength = prefixLength;
1577 thisAddress.operation = AddrChange::Update;
Ed Tanousbf648f72021-06-03 15:00:14 -07001578 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001579 else if (thisAddress.existingDbusId.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001580 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001581 messages::propertyMissing(res, pathString + "/SubnetMask");
1582 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001583 }
1584 else
1585 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001586 uint8_t prefixLength = 0;
1587 // Ignore return code. It came from internal, it's it's invalid
1588 // nothing we can do
1589 ip_util::ipv4VerifyIpAndGetBitcount(nicIpEntry->netmask,
1590 &prefixLength);
Ed Tanousbf648f72021-06-03 15:00:14 -07001591
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001592 thisAddress.prefixLength = prefixLength;
1593 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001594 if (gateway)
1595 {
Ed Tanouse01d0c32023-06-30 13:21:32 -07001596 if (!ip_util::ipv4VerifyIpAndGetBitcount(*gateway))
Ed Tanousbf648f72021-06-03 15:00:14 -07001597 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001598 messages::propertyValueFormatError(res, *gateway,
Ed Tanousbf648f72021-06-03 15:00:14 -07001599 pathString + "/Gateway");
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001600 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001601 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001602 thisAddress.operation = AddrChange::Update;
1603 thisAddress.gateway = *gateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001604 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001605 else if (thisAddress.existingDbusId.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001606 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001607 // Default to null gateway
1608 gateway = "";
Ed Tanousbf648f72021-06-03 15:00:14 -07001609 }
1610 else
1611 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001612 thisAddress.gateway = nicIpEntry->gateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001613 }
1614
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001615 // Changing gateway from existing
1616 if (!thisAddress.gateway.empty() &&
1617 thisAddress.gateway != "0.0.0.0")
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001618 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001619 if (!gatewayOut.empty() && gatewayOut != thisAddress.gateway)
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001620 {
1621 // A NIC can only have a single active gateway value.
1622 // If any gateway in the array of static addresses
1623 // mismatch the PATCH is in error.
1624 std::string arg1 = pathString + "/Gateway";
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001625 std::string arg2 = lastGatewayPath + "/Gateway";
1626 messages::propertyValueConflict(res, arg1, arg2);
1627 return false;
1628 }
1629 gatewayOut = thisAddress.gateway;
1630 lastGatewayPath = pathString;
1631 }
1632 }
1633 nicIpEntry++;
1634 nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
1635 entryIdx++;
1636 }
1637
1638 // Delete the remaining IPs
1639 while (nicIpEntry != ipv4Data.cend())
1640 {
1641 AddressPatch& thisAddress = addressesOut.emplace_back();
1642 thisAddress.operation = AddrChange::Delete;
1643 thisAddress.existingDbusId = nicIpEntry->id;
1644 nicIpEntry++;
1645 nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
1646 }
1647
1648 return true;
1649}
1650
1651inline void handleIPv4StaticPatch(
1652 const std::string& ifaceId,
1653 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
1654 const EthernetInterfaceData& ethData,
1655 const std::vector<IPv4AddressData>& ipv4Data,
1656 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1657{
1658 std::vector<AddressPatch> addresses;
1659 std::string gatewayOut;
1660 if (!parseAddresses(input, ipv4Data, asyncResp->res, addresses, gatewayOut))
1661 {
1662 return;
1663 }
1664
1665 // If we're setting the gateway to something new, delete the
1666 // existing so we won't conflict
1667 if (!ethData.defaultGateway.empty() && ethData.defaultGateway != gatewayOut)
1668 {
1669 updateIPv4DefaultGateway(ifaceId, "", asyncResp);
1670 }
1671
1672 for (const AddressPatch& address : addresses)
1673 {
1674 switch (address.operation)
1675 {
1676 case AddrChange::Delete:
1677 {
1678 BMCWEB_LOG_ERROR("Deleting id {} on interface {}",
1679 address.existingDbusId, ifaceId);
1680 deleteIPAddress(ifaceId, address.existingDbusId, asyncResp);
1681 }
1682 break;
1683 case AddrChange::Update:
1684 {
1685 // Update is a delete then a recreate
1686 // Only need to update if there is an existing ip at this index
1687 if (!address.existingDbusId.empty())
1688 {
1689 BMCWEB_LOG_ERROR("Deleting id {} on interface {}",
1690 address.existingDbusId, ifaceId);
1691 deleteAndCreateIPAddress(
1692 IpVersion::IpV4, ifaceId, address.existingDbusId,
1693 address.prefixLength, address.address, address.gateway,
1694 asyncResp);
1695 }
1696 else
1697 {
1698 // Otherwise, just create a new one
1699 BMCWEB_LOG_ERROR(
1700 "creating ip {} prefix {} gateway {} on interface {}",
1701 address.address, address.prefixLength, address.gateway,
1702 ifaceId);
1703 createIPv4(ifaceId, address.prefixLength, address.gateway,
1704 address.address, asyncResp);
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001705 }
1706 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001707 break;
1708 default:
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001709 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001710 // Leave alone
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001711 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001712 break;
1713 }
1714 }
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001715
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001716 // now update to the new gateway.
1717 // Default gateway is already empty, so no need to update if we're clearing
1718 if (!gatewayOut.empty() && ethData.defaultGateway != gatewayOut)
1719 {
1720 updateIPv4DefaultGateway(ifaceId, gatewayOut, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001721 }
1722}
1723
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001724inline void handleStaticNameServersPatch(
Ed Tanousbf648f72021-06-03 15:00:14 -07001725 const std::string& ifaceId,
1726 const std::vector<std::string>& updatedStaticNameServers,
1727 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1728{
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001729 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301730 asyncResp, "StaticNameServers", "xyz.openbmc_project.Network",
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001731 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1732 ifaceId,
George Liu9ae226f2023-06-21 17:56:46 +08001733 "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers",
Ginu Georgee93abac2024-06-14 17:35:27 +05301734 updatedStaticNameServers);
Ed Tanousbf648f72021-06-03 15:00:14 -07001735}
1736
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001737inline void handleIPv6StaticAddressesPatch(
Ed Tanous3dfed532024-03-06 14:41:27 -08001738 const std::string& ifaceId,
1739 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
Ed Tanous77179532023-02-28 10:45:28 -08001740 const std::vector<IPv6AddressData>& ipv6Data,
Ed Tanousbf648f72021-06-03 15:00:14 -07001741 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1742{
Ed Tanousbf648f72021-06-03 15:00:14 -07001743 size_t entryIdx = 1;
Ed Tanous77179532023-02-28 10:45:28 -08001744 std::vector<IPv6AddressData>::const_iterator nicIpEntry =
Ed Tanousbf648f72021-06-03 15:00:14 -07001745 getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend());
Ed Tanous3dfed532024-03-06 14:41:27 -08001746 for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
1747 input)
Ed Tanousbf648f72021-06-03 15:00:14 -07001748 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001749 std::string pathString =
1750 "IPv6StaticAddresses/" + std::to_string(entryIdx);
Ed Tanous3dfed532024-03-06 14:41:27 -08001751 nlohmann::json::object_t* obj =
1752 std::get_if<nlohmann::json::object_t>(&thisJson);
1753 if (obj != nullptr && !obj->empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001754 {
1755 std::optional<std::string> address;
1756 std::optional<uint8_t> prefixLength;
Ed Tanous3dfed532024-03-06 14:41:27 -08001757 nlohmann::json::object_t thisJsonCopy = *obj;
Myung Baeafc474a2024-10-09 00:53:29 -07001758 if (!json_util::readJsonObject( //
1759 thisJsonCopy, asyncResp->res, //
1760 "Address", address, //
1761 "PrefixLength", prefixLength //
1762 ))
Ed Tanousbf648f72021-06-03 15:00:14 -07001763 {
Ed Tanous3dfed532024-03-06 14:41:27 -08001764 messages::propertyValueFormatError(asyncResp->res, thisJsonCopy,
Ed Tanousf818b042022-06-27 13:17:35 -07001765 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001766 return;
1767 }
1768
Ed Tanousbf648f72021-06-03 15:00:14 -07001769 // Find the address and prefixLength values. Any values that are
1770 // not explicitly provided are assumed to be unmodified from the
1771 // current state of the interface. Merge existing state into the
1772 // current request.
Ed Tanousd547d8d2024-03-16 18:04:41 -07001773 if (!address)
Ed Tanousbf648f72021-06-03 15:00:14 -07001774 {
Ed Tanousd547d8d2024-03-16 18:04:41 -07001775 if (nicIpEntry == ipv6Data.end())
1776 {
1777 messages::propertyMissing(asyncResp->res,
1778 pathString + "/Address");
1779 return;
1780 }
1781 address = nicIpEntry->address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001782 }
1783
Ed Tanousd547d8d2024-03-16 18:04:41 -07001784 if (!prefixLength)
Ed Tanousbf648f72021-06-03 15:00:14 -07001785 {
Ed Tanousd547d8d2024-03-16 18:04:41 -07001786 if (nicIpEntry == ipv6Data.end())
1787 {
1788 messages::propertyMissing(asyncResp->res,
1789 pathString + "/PrefixLength");
1790 return;
1791 }
1792 prefixLength = nicIpEntry->prefixLength;
Ed Tanousbf648f72021-06-03 15:00:14 -07001793 }
1794
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001795 if (nicIpEntry != ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001796 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001797 deleteAndCreateIPAddress(IpVersion::IpV6, ifaceId,
Ed Tanousd547d8d2024-03-16 18:04:41 -07001798 nicIpEntry->id, *prefixLength,
1799 *address, "", asyncResp);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001800 nicIpEntry =
1801 getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001802 }
1803 else
1804 {
Ed Tanousd547d8d2024-03-16 18:04:41 -07001805 createIPv6(ifaceId, *prefixLength, *address, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001806 }
1807 entryIdx++;
1808 }
1809 else
1810 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001811 if (nicIpEntry == ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001812 {
1813 // Requesting a DELETE/DO NOT MODIFY action for an item
1814 // that isn't present on the eth(n) interface. Input JSON is
1815 // in error, so bail out.
Ed Tanous3dfed532024-03-06 14:41:27 -08001816 if (obj == nullptr)
Ed Tanousbf648f72021-06-03 15:00:14 -07001817 {
1818 messages::resourceCannotBeDeleted(asyncResp->res);
1819 return;
1820 }
Ed Tanous3dfed532024-03-06 14:41:27 -08001821 messages::propertyValueFormatError(asyncResp->res, *obj,
Ed Tanousf818b042022-06-27 13:17:35 -07001822 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001823 return;
1824 }
1825
Ed Tanous3dfed532024-03-06 14:41:27 -08001826 if (obj == nullptr)
Ed Tanousbf648f72021-06-03 15:00:14 -07001827 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001828 deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001829 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001830 if (nicIpEntry != ipv6Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001831 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001832 nicIpEntry =
1833 getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001834 }
1835 entryIdx++;
1836 }
1837 }
1838}
1839
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001840inline std::string extractParentInterfaceName(const std::string& ifaceId)
1841{
1842 std::size_t pos = ifaceId.find('_');
1843 return ifaceId.substr(0, pos);
1844}
1845
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001846inline void parseInterfaceData(
1847 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1848 const std::string& ifaceId, const EthernetInterfaceData& ethData,
1849 const std::vector<IPv4AddressData>& ipv4Data,
1850 const std::vector<IPv6AddressData>& ipv6Data,
1851 const std::vector<StaticGatewayData>& ipv6GatewayData)
Ed Tanousbf648f72021-06-03 15:00:14 -07001852{
Ed Tanousbf648f72021-06-03 15:00:14 -07001853 nlohmann::json& jsonResponse = asyncResp->res.jsonValue;
1854 jsonResponse["Id"] = ifaceId;
Ed Tanous253f11b2024-05-16 09:38:31 -07001855 jsonResponse["@odata.id"] =
1856 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces/{}",
1857 BMCWEB_REDFISH_MANAGER_URI_NAME, ifaceId);
Ed Tanousbf648f72021-06-03 15:00:14 -07001858 jsonResponse["InterfaceEnabled"] = ethData.nicEnabled;
1859
Ed Tanousbf648f72021-06-03 15:00:14 -07001860 if (ethData.nicEnabled)
1861 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001862 jsonResponse["LinkStatus"] =
1863 ethData.linkUp ? ethernet_interface::LinkStatus::LinkUp
1864 : ethernet_interface::LinkStatus::LinkDown;
1865 jsonResponse["Status"]["State"] = resource::State::Enabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001866 }
1867 else
1868 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001869 jsonResponse["LinkStatus"] = ethernet_interface::LinkStatus::NoLink;
1870 jsonResponse["Status"]["State"] = resource::State::Disabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001871 }
1872
Ed Tanousbf648f72021-06-03 15:00:14 -07001873 jsonResponse["SpeedMbps"] = ethData.speed;
Tejas Patil35fb5312021-09-20 15:35:20 +05301874 jsonResponse["MTUSize"] = ethData.mtuSize;
Asmitha Karunanithi4652c642024-07-30 11:35:53 -05001875 if (ethData.macAddress)
1876 {
1877 jsonResponse["MACAddress"] = *ethData.macAddress;
1878 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001879 jsonResponse["DHCPv4"]["DHCPEnabled"] =
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001880 translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
Jishnu CMe4588152023-05-11 00:04:40 -05001881 jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpv4Enabled;
1882 jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsv4Enabled;
Ravi Tejade9ad762024-06-03 02:00:15 -05001883 jsonResponse["DHCPv4"]["UseDomainName"] = ethData.domainv4Enabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001884 jsonResponse["DHCPv6"]["OperatingMode"] =
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001885 translateDhcpEnabledToBool(ethData.dhcpEnabled, false)
1886 ? "Enabled"
1887 : "Disabled";
Jishnu CMe4588152023-05-11 00:04:40 -05001888 jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpv6Enabled;
1889 jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsv6Enabled;
Ravi Tejade9ad762024-06-03 02:00:15 -05001890 jsonResponse["DHCPv6"]["UseDomainName"] = ethData.domainv6Enabled;
Ravi Tejab10d8db2022-05-24 09:04:12 -05001891 jsonResponse["StatelessAddressAutoConfig"]["IPv6AutoConfigEnabled"] =
1892 ethData.ipv6AcceptRa;
Ed Tanousbf648f72021-06-03 15:00:14 -07001893
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001894 if (!ethData.hostName.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001895 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001896 jsonResponse["HostName"] = ethData.hostName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001897
1898 // When domain name is empty then it means, that it is a network
1899 // without domain names, and the host name itself must be treated as
1900 // FQDN
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001901 std::string fqdn = ethData.hostName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001902 if (!ethData.domainnames.empty())
1903 {
1904 fqdn += "." + ethData.domainnames[0];
1905 }
1906 jsonResponse["FQDN"] = fqdn;
1907 }
1908
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001909 if (ethData.vlanId)
1910 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001911 jsonResponse["EthernetInterfaceType"] =
1912 ethernet_interface::EthernetDeviceType::Virtual;
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001913 jsonResponse["VLAN"]["VLANEnable"] = true;
1914 jsonResponse["VLAN"]["VLANId"] = *ethData.vlanId;
1915 jsonResponse["VLAN"]["Tagged"] = true;
1916
1917 nlohmann::json::array_t relatedInterfaces;
1918 nlohmann::json& parentInterface = relatedInterfaces.emplace_back();
1919 parentInterface["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001920 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces",
1921 BMCWEB_REDFISH_MANAGER_URI_NAME,
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001922 extractParentInterfaceName(ifaceId));
1923 jsonResponse["Links"]["RelatedInterfaces"] =
1924 std::move(relatedInterfaces);
1925 }
1926 else
1927 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001928 jsonResponse["EthernetInterfaceType"] =
1929 ethernet_interface::EthernetDeviceType::Physical;
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001930 }
1931
Ed Tanousbf648f72021-06-03 15:00:14 -07001932 jsonResponse["NameServers"] = ethData.nameServers;
1933 jsonResponse["StaticNameServers"] = ethData.staticNameServers;
1934
1935 nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"];
1936 nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
1937 ipv4Array = nlohmann::json::array();
1938 ipv4StaticArray = nlohmann::json::array();
Ed Tanous9eb808c2022-01-25 10:19:23 -08001939 for (const auto& ipv4Config : ipv4Data)
Ed Tanousbf648f72021-06-03 15:00:14 -07001940 {
Ed Tanousbf648f72021-06-03 15:00:14 -07001941 std::string gatewayStr = ipv4Config.gateway;
1942 if (gatewayStr.empty())
1943 {
1944 gatewayStr = "0.0.0.0";
1945 }
Ed Tanous14766872022-03-15 10:44:42 -07001946 nlohmann::json::object_t ipv4;
1947 ipv4["AddressOrigin"] = ipv4Config.origin;
1948 ipv4["SubnetMask"] = ipv4Config.netmask;
1949 ipv4["Address"] = ipv4Config.address;
1950 ipv4["Gateway"] = gatewayStr;
Ed Tanousbf648f72021-06-03 15:00:14 -07001951
Ed Tanousbf648f72021-06-03 15:00:14 -07001952 if (ipv4Config.origin == "Static")
1953 {
Ed Tanous14766872022-03-15 10:44:42 -07001954 ipv4StaticArray.push_back(ipv4);
Ed Tanousbf648f72021-06-03 15:00:14 -07001955 }
Ed Tanous14766872022-03-15 10:44:42 -07001956
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001957 ipv4Array.emplace_back(std::move(ipv4));
Ed Tanousbf648f72021-06-03 15:00:14 -07001958 }
1959
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001960 std::string ipv6GatewayStr = ethData.ipv6DefaultGateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001961 if (ipv6GatewayStr.empty())
1962 {
1963 ipv6GatewayStr = "0:0:0:0:0:0:0:0";
1964 }
1965
1966 jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr;
1967
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001968 nlohmann::json::array_t ipv6StaticGatewayArray;
1969 for (const auto& ipv6GatewayConfig : ipv6GatewayData)
1970 {
1971 nlohmann::json::object_t ipv6Gateway;
1972 ipv6Gateway["Address"] = ipv6GatewayConfig.gateway;
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001973 ipv6StaticGatewayArray.emplace_back(std::move(ipv6Gateway));
1974 }
1975 jsonResponse["IPv6StaticDefaultGateways"] =
1976 std::move(ipv6StaticGatewayArray);
1977
Ed Tanousbf648f72021-06-03 15:00:14 -07001978 nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"];
1979 nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"];
1980 ipv6Array = nlohmann::json::array();
1981 ipv6StaticArray = nlohmann::json::array();
1982 nlohmann::json& ipv6AddrPolicyTable =
1983 jsonResponse["IPv6AddressPolicyTable"];
1984 ipv6AddrPolicyTable = nlohmann::json::array();
Ed Tanous9eb808c2022-01-25 10:19:23 -08001985 for (const auto& ipv6Config : ipv6Data)
Ed Tanousbf648f72021-06-03 15:00:14 -07001986 {
Ed Tanous14766872022-03-15 10:44:42 -07001987 nlohmann::json::object_t ipv6;
1988 ipv6["Address"] = ipv6Config.address;
1989 ipv6["PrefixLength"] = ipv6Config.prefixLength;
1990 ipv6["AddressOrigin"] = ipv6Config.origin;
Sunitha Harishf8361272023-03-16 03:23:59 -05001991
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001992 ipv6Array.emplace_back(std::move(ipv6));
Ed Tanousbf648f72021-06-03 15:00:14 -07001993 if (ipv6Config.origin == "Static")
1994 {
Ed Tanous14766872022-03-15 10:44:42 -07001995 nlohmann::json::object_t ipv6Static;
1996 ipv6Static["Address"] = ipv6Config.address;
1997 ipv6Static["PrefixLength"] = ipv6Config.prefixLength;
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001998 ipv6StaticArray.emplace_back(std::move(ipv6Static));
Ed Tanousbf648f72021-06-03 15:00:14 -07001999 }
2000 }
2001}
2002
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002003inline void afterDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2004 const std::string& ifaceId,
2005 const boost::system::error_code& ec,
2006 const sdbusplus::message_t& m)
2007{
2008 if (!ec)
2009 {
2010 return;
2011 }
2012 const sd_bus_error* dbusError = m.get_error();
2013 if (dbusError == nullptr)
2014 {
2015 messages::internalError(asyncResp->res);
2016 return;
2017 }
Ed Tanous62598e32023-07-17 17:06:25 -07002018 BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002019
2020 if (std::string_view("org.freedesktop.DBus.Error.UnknownObject") ==
2021 dbusError->name)
2022 {
2023 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
2024 ifaceId);
2025 return;
2026 }
2027 if (std::string_view("org.freedesktop.DBus.Error.UnknownMethod") ==
2028 dbusError->name)
2029 {
2030 messages::resourceCannotBeDeleted(asyncResp->res);
2031 return;
2032 }
2033 messages::internalError(asyncResp->res);
2034}
2035
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002036inline void afterVlanCreate(
2037 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2038 const std::string& parentInterfaceUri, const std::string& vlanInterface,
2039 const boost::system::error_code& ec, const sdbusplus::message_t& m
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002040
2041)
2042{
2043 if (ec)
2044 {
2045 const sd_bus_error* dbusError = m.get_error();
2046 if (dbusError == nullptr)
2047 {
2048 messages::internalError(asyncResp->res);
2049 return;
2050 }
Ed Tanous62598e32023-07-17 17:06:25 -07002051 BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002052
2053 if (std::string_view(
2054 "xyz.openbmc_project.Common.Error.ResourceNotFound") ==
2055 dbusError->name)
2056 {
2057 messages::propertyValueNotInList(
2058 asyncResp->res, parentInterfaceUri,
2059 "Links/RelatedInterfaces/0/@odata.id");
2060 return;
2061 }
2062 if (std::string_view(
2063 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
2064 dbusError->name)
2065 {
2066 messages::resourceAlreadyExists(asyncResp->res, "EthernetInterface",
2067 "Id", vlanInterface);
2068 return;
2069 }
2070 messages::internalError(asyncResp->res);
2071 return;
2072 }
2073
Ed Tanous253f11b2024-05-16 09:38:31 -07002074 const boost::urls::url vlanInterfaceUri =
2075 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces/{}",
2076 BMCWEB_REDFISH_MANAGER_URI_NAME, vlanInterface);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002077 asyncResp->res.addHeader("Location", vlanInterfaceUri.buffer());
2078}
2079
Ed Tanousbf648f72021-06-03 15:00:14 -07002080inline void requestEthernetInterfacesRoutes(App& app)
2081{
Ed Tanous253f11b2024-05-16 09:38:31 -07002082 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/")
Ed Tanoused398212021-06-09 17:05:54 -07002083 .privileges(redfish::privileges::getEthernetInterfaceCollection)
Ed Tanous14766872022-03-15 10:44:42 -07002084 .methods(boost::beast::http::verb::get)(
2085 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002086 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2087 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002088 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2089 {
2090 return;
2091 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002092
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002093 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2094 {
2095 messages::resourceNotFound(asyncResp->res, "Manager",
2096 managerId);
2097 return;
2098 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002099
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002100 asyncResp->res.jsonValue["@odata.type"] =
2101 "#EthernetInterfaceCollection.EthernetInterfaceCollection";
2102 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2103 "/redfish/v1/Managers/{}/EthernetInterfaces",
2104 BMCWEB_REDFISH_MANAGER_URI_NAME);
2105 asyncResp->res.jsonValue["Name"] =
2106 "Ethernet Network Interface Collection";
2107 asyncResp->res.jsonValue["Description"] =
2108 "Collection of EthernetInterfaces for this Manager";
2109
2110 // Get eth interface list, and call the below callback for JSON
2111 // preparation
2112 getEthernetIfaceList(
2113 [asyncResp](const bool& success,
2114 const std::vector<std::string>& ifaceList) {
2115 if (!success)
2116 {
2117 messages::internalError(asyncResp->res);
2118 return;
2119 }
2120
2121 nlohmann::json& ifaceArray =
2122 asyncResp->res.jsonValue["Members"];
2123 ifaceArray = nlohmann::json::array();
2124 for (const std::string& ifaceItem : ifaceList)
2125 {
2126 nlohmann::json::object_t iface;
2127 iface["@odata.id"] = boost::urls::format(
2128 "/redfish/v1/Managers/{}/EthernetInterfaces/{}",
2129 BMCWEB_REDFISH_MANAGER_URI_NAME, ifaceItem);
2130 ifaceArray.push_back(std::move(iface));
2131 }
2132
2133 asyncResp->res.jsonValue["Members@odata.count"] =
2134 ifaceArray.size();
2135 asyncResp->res.jsonValue["@odata.id"] =
2136 boost::urls::format(
2137 "/redfish/v1/Managers/{}/EthernetInterfaces",
Ed Tanous253f11b2024-05-16 09:38:31 -07002138 BMCWEB_REDFISH_MANAGER_URI_NAME);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002139 });
2140 });
Johnathan Mantey01784822019-06-18 12:44:21 -07002141
Ed Tanous253f11b2024-05-16 09:38:31 -07002142 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/")
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002143 .privileges(redfish::privileges::postEthernetInterfaceCollection)
2144 .methods(boost::beast::http::verb::post)(
2145 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002146 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2147 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002148 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2149 {
2150 return;
2151 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002152
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002153 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2154 {
2155 messages::resourceNotFound(asyncResp->res, "Manager",
2156 managerId);
2157 return;
2158 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002159
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002160 bool vlanEnable = false;
2161 uint32_t vlanId = 0;
2162 std::vector<nlohmann::json::object_t> relatedInterfaces;
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002163
Myung Baeafc474a2024-10-09 00:53:29 -07002164 if (!json_util::readJsonPatch( //
2165 req, asyncResp->res, //
2166 "Links/RelatedInterfaces", relatedInterfaces, //
2167 "VLAN/VLANEnable", vlanEnable, //
2168 "VLAN/VLANId", vlanId //
2169 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002170 {
2171 return;
2172 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002173
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002174 if (relatedInterfaces.size() != 1)
2175 {
2176 messages::arraySizeTooLong(asyncResp->res,
2177 "Links/RelatedInterfaces",
2178 relatedInterfaces.size());
2179 return;
2180 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002181
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002182 std::string parentInterfaceUri;
2183 if (!json_util::readJsonObject(relatedInterfaces[0],
2184 asyncResp->res, "@odata.id",
2185 parentInterfaceUri))
2186 {
2187 messages::propertyMissing(
2188 asyncResp->res, "Links/RelatedInterfaces/0/@odata.id");
2189 return;
2190 }
2191 BMCWEB_LOG_INFO("Parent Interface URI: {}", parentInterfaceUri);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002192
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002193 boost::system::result<boost::urls::url_view> parsedUri =
2194 boost::urls::parse_relative_ref(parentInterfaceUri);
2195 if (!parsedUri)
2196 {
2197 messages::propertyValueFormatError(
2198 asyncResp->res, parentInterfaceUri,
2199 "Links/RelatedInterfaces/0/@odata.id");
2200 return;
2201 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002202
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002203 std::string parentInterface;
2204 if (!crow::utility::readUrlSegments(
2205 *parsedUri, "redfish", "v1", "Managers", "bmc",
2206 "EthernetInterfaces", std::ref(parentInterface)))
2207 {
2208 messages::propertyValueNotInList(
2209 asyncResp->res, parentInterfaceUri,
2210 "Links/RelatedInterfaces/0/@odata.id");
2211 return;
2212 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002213
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002214 if (!vlanEnable)
2215 {
2216 // In OpenBMC implementation, VLANEnable cannot be false on
2217 // create
2218 messages::propertyValueIncorrect(
2219 asyncResp->res, "VLAN/VLANEnable", "false");
2220 return;
2221 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002222
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002223 std::string vlanInterface =
2224 parentInterface + "_" + std::to_string(vlanId);
2225 crow::connections::systemBus->async_method_call(
2226 [asyncResp, parentInterfaceUri,
2227 vlanInterface](const boost::system::error_code& ec,
2228 const sdbusplus::message_t& m) {
2229 afterVlanCreate(asyncResp, parentInterfaceUri,
2230 vlanInterface, ec, m);
2231 },
2232 "xyz.openbmc_project.Network",
2233 "/xyz/openbmc_project/network",
2234 "xyz.openbmc_project.Network.VLAN.Create", "VLAN",
2235 parentInterface, vlanId);
2236 });
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002237
Ed Tanous253f11b2024-05-16 09:38:31 -07002238 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002239 .privileges(redfish::privileges::getEthernetInterface)
Ed Tanousbf648f72021-06-03 15:00:14 -07002240 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002241 [&app](const crow::Request& req,
2242 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002243 const std::string& managerId, const std::string& ifaceId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002244 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2245 {
2246 return;
2247 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002248
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002249 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2250 {
2251 messages::resourceNotFound(asyncResp->res, "Manager",
2252 managerId);
2253 return;
2254 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002255
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002256 getEthernetIfaceData(
2257 ifaceId,
2258 [asyncResp, ifaceId](
2259 const bool& success,
2260 const EthernetInterfaceData& ethData,
2261 const std::vector<IPv4AddressData>& ipv4Data,
2262 const std::vector<IPv6AddressData>& ipv6Data,
2263 const std::vector<StaticGatewayData>& ipv6GatewayData) {
2264 if (!success)
2265 {
2266 // TODO(Pawel)consider distinguish between non
2267 // existing object, and other errors
2268 messages::resourceNotFound(
2269 asyncResp->res, "EthernetInterface", ifaceId);
2270 return;
2271 }
Johnathan Mantey01784822019-06-18 12:44:21 -07002272
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002273 asyncResp->res.jsonValue["@odata.type"] =
2274 "#EthernetInterface.v1_9_0.EthernetInterface";
2275 asyncResp->res.jsonValue["Name"] =
2276 "Manager Ethernet Interface";
2277 asyncResp->res.jsonValue["Description"] =
2278 "Management Network Interface";
Ratan Guptaf476acb2019-03-02 16:46:57 +05302279
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002280 parseInterfaceData(asyncResp, ifaceId, ethData,
2281 ipv4Data, ipv6Data, ipv6GatewayData);
2282 });
2283 });
Johnathan Mantey01784822019-06-18 12:44:21 -07002284
Ed Tanous253f11b2024-05-16 09:38:31 -07002285 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002286 .privileges(redfish::privileges::patchEthernetInterface)
Ed Tanousbf648f72021-06-03 15:00:14 -07002287 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002288 [&app](const crow::Request& req,
2289 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002290 const std::string& managerId, const std::string& ifaceId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002291 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2292 {
2293 return;
2294 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002295
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002296 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2297 {
2298 messages::resourceNotFound(asyncResp->res, "Manager",
2299 managerId);
2300 return;
2301 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002302
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002303 std::optional<std::string> hostname;
2304 std::optional<std::string> fqdn;
2305 std::optional<std::string> macAddress;
2306 std::optional<std::string> ipv6DefaultGateway;
2307 std::optional<std::vector<
2308 std::variant<nlohmann::json::object_t, std::nullptr_t>>>
2309 ipv4StaticAddresses;
2310 std::optional<std::vector<
2311 std::variant<nlohmann::json::object_t, std::nullptr_t>>>
2312 ipv6StaticAddresses;
2313 std::optional<std::vector<
2314 std::variant<nlohmann::json::object_t, std::nullptr_t>>>
2315 ipv6StaticDefaultGateways;
2316 std::optional<std::vector<std::string>> staticNameServers;
2317 std::optional<bool> ipv6AutoConfigEnabled;
2318 std::optional<bool> interfaceEnabled;
2319 std::optional<size_t> mtuSize;
2320 DHCPParameters v4dhcpParms;
2321 DHCPParameters v6dhcpParms;
Myung Baeafc474a2024-10-09 00:53:29 -07002322
2323 if (!json_util::readJsonPatch( //
2324 req, asyncResp->res, //
2325 "DHCPv4/DHCPEnabled", v4dhcpParms.dhcpv4Enabled, //
2326 "DHCPv4/UseDNSServers", v4dhcpParms.useDnsServers, //
2327 "DHCPv4/UseDomainName", v4dhcpParms.useDomainName, //
2328 "DHCPv4/UseNTPServers", v4dhcpParms.useNtpServers, //
2329 "DHCPv6/OperatingMode",
2330 v6dhcpParms.dhcpv6OperatingMode, //
2331 "DHCPv6/UseDNSServers", v6dhcpParms.useDnsServers, //
2332 "DHCPv6/UseDomainName", v6dhcpParms.useDomainName, //
2333 "DHCPv6/UseNTPServers", v6dhcpParms.useNtpServers, //
2334 "FQDN", fqdn, //
2335 "HostName", hostname, //
2336 "InterfaceEnabled", interfaceEnabled, //
2337 "IPv4StaticAddresses", ipv4StaticAddresses, //
2338 "IPv6DefaultGateway", ipv6DefaultGateway, //
2339 "IPv6StaticAddresses", ipv6StaticAddresses, //
2340 "IPv6StaticDefaultGateways",
2341 ipv6StaticDefaultGateways, //
2342 "InterfaceEnabled", interfaceEnabled, //
2343 "MACAddress", macAddress, //
2344 "MTUSize", mtuSize, //
2345 "StatelessAddressAutoConfig/IPv6AutoConfigEnabled",
2346 ipv6AutoConfigEnabled, //
2347 "StaticNameServers", staticNameServers //
2348 ))
2349 {
2350 return;
2351 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -05002352
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002353 // Get single eth interface data, and call the below callback
2354 // for JSON preparation
2355 getEthernetIfaceData(
2356 ifaceId,
2357 [asyncResp, ifaceId, hostname = std::move(hostname),
2358 fqdn = std::move(fqdn), macAddress = std::move(macAddress),
2359 ipv4StaticAddresses = std::move(ipv4StaticAddresses),
2360 ipv6DefaultGateway = std::move(ipv6DefaultGateway),
2361 ipv6StaticAddresses = std::move(ipv6StaticAddresses),
2362 ipv6StaticDefaultGateway =
2363 std::move(ipv6StaticDefaultGateways),
2364 staticNameServers = std::move(staticNameServers), mtuSize,
2365 ipv6AutoConfigEnabled,
2366 v4dhcpParms = std::move(v4dhcpParms),
2367 v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled](
2368 const bool success,
2369 const EthernetInterfaceData& ethData,
2370 const std::vector<IPv4AddressData>& ipv4Data,
2371 const std::vector<IPv6AddressData>& ipv6Data,
2372 const std::vector<StaticGatewayData>&
2373 ipv6GatewayData) mutable {
2374 if (!success)
2375 {
2376 // ... otherwise return error
2377 // TODO(Pawel)consider distinguish between non
2378 // existing object, and other errors
2379 messages::resourceNotFound(
2380 asyncResp->res, "EthernetInterface", ifaceId);
2381 return;
2382 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -05002383
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002384 handleDHCPPatch(ifaceId, ethData, v4dhcpParms,
2385 v6dhcpParms, asyncResp);
Tejas Patil35fb5312021-09-20 15:35:20 +05302386
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002387 if (hostname)
2388 {
2389 handleHostnamePatch(*hostname, asyncResp);
2390 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002391
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002392 if (ipv6AutoConfigEnabled)
2393 {
2394 handleSLAACAutoConfigPatch(
2395 ifaceId, *ipv6AutoConfigEnabled, asyncResp);
2396 }
Ravi Tejab10d8db2022-05-24 09:04:12 -05002397
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002398 if (fqdn)
2399 {
2400 handleFqdnPatch(ifaceId, *fqdn, asyncResp);
2401 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002402
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002403 if (macAddress)
2404 {
2405 handleMACAddressPatch(ifaceId, *macAddress,
2406 asyncResp);
2407 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002408
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002409 if (ipv4StaticAddresses)
2410 {
2411 handleIPv4StaticPatch(ifaceId, *ipv4StaticAddresses,
2412 ethData, ipv4Data, asyncResp);
2413 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002414
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002415 if (staticNameServers)
2416 {
2417 handleStaticNameServersPatch(
2418 ifaceId, *staticNameServers, asyncResp);
2419 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002420
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002421 if (ipv6DefaultGateway)
2422 {
2423 messages::propertyNotWritable(asyncResp->res,
2424 "IPv6DefaultGateway");
2425 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002426
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002427 if (ipv6StaticAddresses)
2428 {
2429 handleIPv6StaticAddressesPatch(ifaceId,
2430 *ipv6StaticAddresses,
2431 ipv6Data, asyncResp);
2432 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002433
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002434 if (ipv6StaticDefaultGateway)
2435 {
2436 handleIPv6DefaultGateway(
2437 ifaceId, *ipv6StaticDefaultGateway,
2438 ipv6GatewayData, asyncResp);
2439 }
Sunitha Harishce73d5c2023-04-07 06:46:49 -05002440
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002441 if (interfaceEnabled)
2442 {
2443 setDbusProperty(
2444 asyncResp, "InterfaceEnabled",
Ginu Georgee93abac2024-06-14 17:35:27 +05302445 "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08002446 sdbusplus::message::object_path(
2447 "/xyz/openbmc_project/network") /
2448 ifaceId,
2449 "xyz.openbmc_project.Network.EthernetInterface",
Ginu Georgee93abac2024-06-14 17:35:27 +05302450 "NICEnabled", *interfaceEnabled);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002451 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002452
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002453 if (mtuSize)
2454 {
2455 handleMTUSizePatch(ifaceId, *mtuSize, asyncResp);
2456 }
2457 });
2458 });
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002459
Ed Tanous253f11b2024-05-16 09:38:31 -07002460 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002461 .privileges(redfish::privileges::deleteEthernetInterface)
2462 .methods(boost::beast::http::verb::delete_)(
2463 [&app](const crow::Request& req,
2464 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002465 const std::string& managerId, const std::string& ifaceId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002466 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2467 {
2468 return;
2469 }
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002470
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002471 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2472 {
2473 messages::resourceNotFound(asyncResp->res, "Manager",
2474 managerId);
2475 return;
2476 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002477
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002478 crow::connections::systemBus->async_method_call(
2479 [asyncResp, ifaceId](const boost::system::error_code& ec,
2480 const sdbusplus::message_t& m) {
2481 afterDelete(asyncResp, ifaceId, ec, m);
2482 },
2483 "xyz.openbmc_project.Network",
2484 std::string("/xyz/openbmc_project/network/") + ifaceId,
2485 "xyz.openbmc_project.Object.Delete", "Delete");
2486 });
Ed Tanousbf648f72021-06-03 15:00:14 -07002487}
2488
Ed Tanous1abe55e2018-09-05 08:30:59 -07002489} // namespace redfish