blob: cda4db398a2af538a5321dce664dbc353d5d7125 [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 ==
Asmitha Karunanithi6e78b682024-12-13 04:45:31 -0600146 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both") ||
147 (inputDHCP ==
148 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4v6stateless"));
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700149 }
150 return ((inputDHCP ==
151 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") ||
152 (inputDHCP ==
153 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
154}
155
Ed Tanous2c70f802020-09-28 14:29:23 -0700156inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700157{
158 if (isIPv4 && isIPv6)
159 {
160 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both";
161 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700162 if (isIPv4)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700163 {
164 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4";
165 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700166 if (isIPv6)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700167 {
168 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6";
169 }
170 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none";
171}
172
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400173inline std::string translateAddressOriginDbusToRedfish(
174 const std::string& inputOrigin, bool isIPv4)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700175{
176 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700177 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700178 return "Static";
179 }
180 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal")
181 {
182 if (isIPv4)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700183 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700184 return "IPv4LinkLocal";
185 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700186 return "LinkLocal";
Ed Tanous4a0cb852018-10-15 07:55:04 -0700187 }
188 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
189 {
190 if (isIPv4)
191 {
192 return "DHCP";
193 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700194 return "DHCPv6";
Ed Tanous4a0cb852018-10-15 07:55:04 -0700195 }
196 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC")
197 {
198 return "SLAAC";
199 }
200 return "";
201}
202
Ed Tanous02cad962022-06-30 16:50:15 -0700203inline bool extractEthernetInterfaceData(
204 const std::string& ethifaceId,
205 const dbus::utility::ManagedObjectType& dbusData,
206 EthernetInterfaceData& ethData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700207{
Ed Tanous4c9afe42019-05-03 16:59:57 -0700208 bool idFound = false;
Ed Tanous02cad962022-06-30 16:50:15 -0700209 for (const auto& objpath : dbusData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700210 {
Ed Tanous02cad962022-06-30 16:50:15 -0700211 for (const auto& ifacePair : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700212 {
Ed Tanous81ce6092020-12-17 16:54:55 +0000213 if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700214 {
Ed Tanous4c9afe42019-05-03 16:59:57 -0700215 idFound = true;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700216 if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700217 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500218 for (const auto& propertyPair : ifacePair.second)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700219 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700220 if (propertyPair.first == "MACAddress")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700221 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500222 const std::string* mac =
Ed Tanousabf2add2019-01-22 16:40:12 -0800223 std::get_if<std::string>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700224 if (mac != nullptr)
225 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800226 ethData.macAddress = *mac;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700227 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700228 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700229 }
230 }
231 else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN")
232 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500233 for (const auto& propertyPair : ifacePair.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700234 {
235 if (propertyPair.first == "Id")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700236 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500237 const uint32_t* id =
Ed Tanousabf2add2019-01-22 16:40:12 -0800238 std::get_if<uint32_t>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700239 if (id != nullptr)
240 {
Jiaqing Zhao17e22022022-04-14 18:58:06 +0800241 ethData.vlanId = *id;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700242 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700243 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700244 }
245 }
246 else if (ifacePair.first ==
247 "xyz.openbmc_project.Network.EthernetInterface")
248 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500249 for (const auto& propertyPair : ifacePair.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700250 {
251 if (propertyPair.first == "AutoNeg")
252 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700253 const bool* autoNeg =
Ed Tanousabf2add2019-01-22 16:40:12 -0800254 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700255 if (autoNeg != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700256 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800257 ethData.autoNeg = *autoNeg;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700258 }
259 }
260 else if (propertyPair.first == "Speed")
261 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500262 const uint32_t* speed =
Ed Tanousabf2add2019-01-22 16:40:12 -0800263 std::get_if<uint32_t>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700264 if (speed != nullptr)
265 {
266 ethData.speed = *speed;
267 }
268 }
Tejas Patil35fb5312021-09-20 15:35:20 +0530269 else if (propertyPair.first == "MTU")
270 {
Anthony3e7a8da2023-10-23 14:22:43 +0800271 const size_t* mtuSize =
272 std::get_if<size_t>(&propertyPair.second);
Tejas Patil35fb5312021-09-20 15:35:20 +0530273 if (mtuSize != nullptr)
274 {
275 ethData.mtuSize = *mtuSize;
276 }
277 }
Johnathan Manteyaa05fb22020-01-08 12:08:44 -0800278 else if (propertyPair.first == "LinkUp")
279 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500280 const bool* linkUp =
Johnathan Manteyaa05fb22020-01-08 12:08:44 -0800281 std::get_if<bool>(&propertyPair.second);
282 if (linkUp != nullptr)
283 {
284 ethData.linkUp = *linkUp;
285 }
286 }
Johnathan Manteyeeedda22019-10-29 16:09:52 -0700287 else if (propertyPair.first == "NICEnabled")
288 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500289 const bool* nicEnabled =
Johnathan Manteyeeedda22019-10-29 16:09:52 -0700290 std::get_if<bool>(&propertyPair.second);
291 if (nicEnabled != nullptr)
292 {
293 ethData.nicEnabled = *nicEnabled;
294 }
295 }
Ravi Tejab10d8db2022-05-24 09:04:12 -0500296 else if (propertyPair.first == "IPv6AcceptRA")
297 {
298 const bool* ipv6AcceptRa =
299 std::get_if<bool>(&propertyPair.second);
300 if (ipv6AcceptRa != nullptr)
301 {
302 ethData.ipv6AcceptRa = *ipv6AcceptRa;
303 }
304 }
RAJESWARAN THILLAIGOVINDANf85837b2019-04-04 05:18:53 -0500305 else if (propertyPair.first == "Nameservers")
Ed Tanous4a0cb852018-10-15 07:55:04 -0700306 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500307 const std::vector<std::string>* nameservers =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500308 std::get_if<std::vector<std::string>>(
Ed Tanous029573d2019-02-01 10:57:49 -0800309 &propertyPair.second);
310 if (nameservers != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700311 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700312 ethData.nameServers = *nameservers;
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -0500313 }
314 }
315 else if (propertyPair.first == "StaticNameServers")
316 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500317 const std::vector<std::string>* staticNameServers =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500318 std::get_if<std::vector<std::string>>(
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -0500319 &propertyPair.second);
320 if (staticNameServers != nullptr)
321 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700322 ethData.staticNameServers = *staticNameServers;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700323 }
324 }
manojkiraneda2a133282019-02-19 13:09:43 +0530325 else if (propertyPair.first == "DHCPEnabled")
326 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700327 const std::string* dhcpEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700328 std::get_if<std::string>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700329 if (dhcpEnabled != nullptr)
manojkiraneda2a133282019-02-19 13:09:43 +0530330 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800331 ethData.dhcpEnabled = *dhcpEnabled;
manojkiraneda2a133282019-02-19 13:09:43 +0530332 }
333 }
Jennifer Leed24bfc72019-03-05 13:03:37 -0800334 else if (propertyPair.first == "DomainName")
335 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500336 const std::vector<std::string>* domainNames =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500337 std::get_if<std::vector<std::string>>(
Jennifer Leed24bfc72019-03-05 13:03:37 -0800338 &propertyPair.second);
339 if (domainNames != nullptr)
340 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700341 ethData.domainnames = *domainNames;
Jennifer Leed24bfc72019-03-05 13:03:37 -0800342 }
343 }
Ravi Teja9010ec22019-08-01 23:30:25 -0500344 else if (propertyPair.first == "DefaultGateway")
345 {
346 const std::string* defaultGateway =
347 std::get_if<std::string>(&propertyPair.second);
348 if (defaultGateway != nullptr)
349 {
350 std::string defaultGatewayStr = *defaultGateway;
351 if (defaultGatewayStr.empty())
352 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800353 ethData.defaultGateway = "0.0.0.0";
Ravi Teja9010ec22019-08-01 23:30:25 -0500354 }
355 else
356 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800357 ethData.defaultGateway = defaultGatewayStr;
Ravi Teja9010ec22019-08-01 23:30:25 -0500358 }
359 }
360 }
361 else if (propertyPair.first == "DefaultGateway6")
362 {
363 const std::string* defaultGateway6 =
364 std::get_if<std::string>(&propertyPair.second);
365 if (defaultGateway6 != nullptr)
366 {
367 std::string defaultGateway6Str =
368 *defaultGateway6;
369 if (defaultGateway6Str.empty())
370 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800371 ethData.ipv6DefaultGateway =
Ravi Teja9010ec22019-08-01 23:30:25 -0500372 "0:0:0:0:0:0:0:0";
373 }
374 else
375 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800376 ethData.ipv6DefaultGateway =
Ravi Teja9010ec22019-08-01 23:30:25 -0500377 defaultGateway6Str;
378 }
379 }
380 }
Ed Tanous029573d2019-02-01 10:57:49 -0800381 }
382 }
383 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700384
Jishnu CMe4588152023-05-11 00:04:40 -0500385 sdbusplus::message::object_path path(
386 "/xyz/openbmc_project/network");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400387 sdbusplus::message::object_path dhcp4Path =
388 path / ethifaceId / "dhcp4";
Jishnu CMe4588152023-05-11 00:04:40 -0500389
390 if (sdbusplus::message::object_path(objpath.first) == dhcp4Path)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700391 {
392 if (ifacePair.first ==
393 "xyz.openbmc_project.Network.DHCPConfiguration")
394 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500395 for (const auto& propertyPair : ifacePair.second)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700396 {
397 if (propertyPair.first == "DNSEnabled")
398 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700399 const bool* dnsEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700400 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700401 if (dnsEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700402 {
Jishnu CMe4588152023-05-11 00:04:40 -0500403 ethData.dnsv4Enabled = *dnsEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700404 }
405 }
Ravi Teja91c441e2024-02-23 09:03:43 -0600406 else if (propertyPair.first == "DomainEnabled")
407 {
408 const bool* domainEnabled =
409 std::get_if<bool>(&propertyPair.second);
410 if (domainEnabled != nullptr)
411 {
412 ethData.domainv4Enabled = *domainEnabled;
413 }
414 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700415 else if (propertyPair.first == "NTPEnabled")
416 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700417 const bool* ntpEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700418 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700419 if (ntpEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700420 {
Jishnu CMe4588152023-05-11 00:04:40 -0500421 ethData.ntpv4Enabled = *ntpEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700422 }
423 }
424 else if (propertyPair.first == "HostNameEnabled")
425 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700426 const bool* hostNameEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700427 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700428 if (hostNameEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700429 {
Jishnu CMe4588152023-05-11 00:04:40 -0500430 ethData.hostNamev4Enabled = *hostNameEnabled;
431 }
432 }
433 }
434 }
435 }
436
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400437 sdbusplus::message::object_path dhcp6Path =
438 path / ethifaceId / "dhcp6";
Jishnu CMe4588152023-05-11 00:04:40 -0500439
440 if (sdbusplus::message::object_path(objpath.first) == dhcp6Path)
441 {
442 if (ifacePair.first ==
443 "xyz.openbmc_project.Network.DHCPConfiguration")
444 {
445 for (const auto& propertyPair : ifacePair.second)
446 {
447 if (propertyPair.first == "DNSEnabled")
448 {
449 const bool* dnsEnabled =
450 std::get_if<bool>(&propertyPair.second);
451 if (dnsEnabled != nullptr)
452 {
453 ethData.dnsv6Enabled = *dnsEnabled;
454 }
455 }
Ravi Teja91c441e2024-02-23 09:03:43 -0600456 if (propertyPair.first == "DomainEnabled")
457 {
458 const bool* domainEnabled =
459 std::get_if<bool>(&propertyPair.second);
460 if (domainEnabled != nullptr)
461 {
462 ethData.domainv6Enabled = *domainEnabled;
463 }
464 }
Jishnu CMe4588152023-05-11 00:04:40 -0500465 else if (propertyPair.first == "NTPEnabled")
466 {
467 const bool* ntpEnabled =
468 std::get_if<bool>(&propertyPair.second);
469 if (ntpEnabled != nullptr)
470 {
471 ethData.ntpv6Enabled = *ntpEnabled;
472 }
473 }
474 else if (propertyPair.first == "HostNameEnabled")
475 {
476 const bool* hostNameEnabled =
477 std::get_if<bool>(&propertyPair.second);
478 if (hostNameEnabled != nullptr)
479 {
480 ethData.hostNamev6Enabled = *hostNameEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700481 }
482 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700483 }
484 }
485 }
Ed Tanous029573d2019-02-01 10:57:49 -0800486 // System configuration shows up in the global namespace, so no need
487 // to check eth number
488 if (ifacePair.first ==
489 "xyz.openbmc_project.Network.SystemConfiguration")
490 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500491 for (const auto& propertyPair : ifacePair.second)
Ed Tanous029573d2019-02-01 10:57:49 -0800492 {
493 if (propertyPair.first == "HostName")
494 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500495 const std::string* hostname =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500496 std::get_if<std::string>(&propertyPair.second);
Ed Tanous029573d2019-02-01 10:57:49 -0800497 if (hostname != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700498 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800499 ethData.hostName = *hostname;
Ed Tanous029573d2019-02-01 10:57:49 -0800500 }
501 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700502 }
503 }
504 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700505 }
Ed Tanous4c9afe42019-05-03 16:59:57 -0700506 return idFound;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700507}
508
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500509// Helper function that extracts data for single ethernet ipv6 address
Ed Tanous77179532023-02-28 10:45:28 -0800510inline void extractIPV6Data(const std::string& ethifaceId,
511 const dbus::utility::ManagedObjectType& dbusData,
512 std::vector<IPv6AddressData>& ipv6Config)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500513{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400514 const std::string ipPathStart =
515 "/xyz/openbmc_project/network/" + ethifaceId;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500516
517 // Since there might be several IPv6 configurations aligned with
518 // single ethernet interface, loop over all of them
Ed Tanous81ce6092020-12-17 16:54:55 +0000519 for (const auto& objpath : dbusData)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500520 {
521 // Check if proper pattern for object path appears
Tony Lee353163e2022-11-23 11:06:10 +0800522 if (objpath.first.str.starts_with(ipPathStart + "/"))
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500523 {
Ed Tanous9eb808c2022-01-25 10:19:23 -0800524 for (const auto& interface : objpath.second)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500525 {
526 if (interface.first == "xyz.openbmc_project.Network.IP")
527 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400528 auto type = std::ranges::find_if(
529 interface.second, [](const auto& property) {
530 return property.first == "Type";
531 });
Tony Lee353163e2022-11-23 11:06:10 +0800532 if (type == interface.second.end())
533 {
534 continue;
535 }
536
537 const std::string* typeStr =
538 std::get_if<std::string>(&type->second);
539
540 if (typeStr == nullptr ||
541 (*typeStr !=
542 "xyz.openbmc_project.Network.IP.Protocol.IPv6"))
543 {
544 continue;
545 }
546
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500547 // Instance IPv6AddressData structure, and set as
548 // appropriate
Ed Tanous77179532023-02-28 10:45:28 -0800549 IPv6AddressData& ipv6Address = ipv6Config.emplace_back();
Ed Tanous2c70f802020-09-28 14:29:23 -0700550 ipv6Address.id =
Tony Lee353163e2022-11-23 11:06:10 +0800551 objpath.first.str.substr(ipPathStart.size());
Ed Tanous9eb808c2022-01-25 10:19:23 -0800552 for (const auto& property : interface.second)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500553 {
554 if (property.first == "Address")
555 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500556 const std::string* address =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500557 std::get_if<std::string>(&property.second);
558 if (address != nullptr)
559 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700560 ipv6Address.address = *address;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500561 }
562 }
563 else if (property.first == "Origin")
564 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500565 const std::string* origin =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500566 std::get_if<std::string>(&property.second);
567 if (origin != nullptr)
568 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700569 ipv6Address.origin =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500570 translateAddressOriginDbusToRedfish(*origin,
571 false);
572 }
573 }
574 else if (property.first == "PrefixLength")
575 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500576 const uint8_t* prefix =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500577 std::get_if<uint8_t>(&property.second);
578 if (prefix != nullptr)
579 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700580 ipv6Address.prefixLength = *prefix;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500581 }
582 }
Asmitha Karunanithi889ff692021-11-29 08:43:30 -0600583 else if (property.first == "Type" ||
584 property.first == "Gateway")
585 {
586 // Type & Gateway is not used
587 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500588 else
589 {
Ed Tanous62598e32023-07-17 17:06:25 -0700590 BMCWEB_LOG_ERROR(
591 "Got extra property: {} on the {} object",
592 property.first, objpath.first.str);
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500593 }
594 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500595 }
596 }
597 }
598 }
599}
600
Ed Tanous4a0cb852018-10-15 07:55:04 -0700601// Helper function that extracts data for single ethernet ipv4 address
Ed Tanous77179532023-02-28 10:45:28 -0800602inline void extractIPData(const std::string& ethifaceId,
603 const dbus::utility::ManagedObjectType& dbusData,
604 std::vector<IPv4AddressData>& ipv4Config)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700605{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400606 const std::string ipPathStart =
607 "/xyz/openbmc_project/network/" + ethifaceId;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700608
609 // Since there might be several IPv4 configurations aligned with
610 // single ethernet interface, loop over all of them
Ed Tanous81ce6092020-12-17 16:54:55 +0000611 for (const auto& objpath : dbusData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700612 {
613 // Check if proper pattern for object path appears
Tony Lee353163e2022-11-23 11:06:10 +0800614 if (objpath.first.str.starts_with(ipPathStart + "/"))
Ed Tanous4a0cb852018-10-15 07:55:04 -0700615 {
Ed Tanous9eb808c2022-01-25 10:19:23 -0800616 for (const auto& interface : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700617 {
618 if (interface.first == "xyz.openbmc_project.Network.IP")
619 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400620 auto type = std::ranges::find_if(
621 interface.second, [](const auto& property) {
622 return property.first == "Type";
623 });
Tony Lee353163e2022-11-23 11:06:10 +0800624 if (type == interface.second.end())
625 {
626 continue;
627 }
628
629 const std::string* typeStr =
630 std::get_if<std::string>(&type->second);
631
632 if (typeStr == nullptr ||
633 (*typeStr !=
634 "xyz.openbmc_project.Network.IP.Protocol.IPv4"))
635 {
636 continue;
637 }
638
Ed Tanous4a0cb852018-10-15 07:55:04 -0700639 // Instance IPv4AddressData structure, and set as
640 // appropriate
Ed Tanous77179532023-02-28 10:45:28 -0800641 IPv4AddressData& ipv4Address = ipv4Config.emplace_back();
Ed Tanous2c70f802020-09-28 14:29:23 -0700642 ipv4Address.id =
Tony Lee353163e2022-11-23 11:06:10 +0800643 objpath.first.str.substr(ipPathStart.size());
Ed Tanous9eb808c2022-01-25 10:19:23 -0800644 for (const auto& property : interface.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700645 {
646 if (property.first == "Address")
647 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500648 const std::string* address =
Ed Tanousabf2add2019-01-22 16:40:12 -0800649 std::get_if<std::string>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700650 if (address != nullptr)
651 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700652 ipv4Address.address = *address;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700653 }
654 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700655 else if (property.first == "Origin")
656 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500657 const std::string* origin =
Ed Tanousabf2add2019-01-22 16:40:12 -0800658 std::get_if<std::string>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700659 if (origin != nullptr)
660 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700661 ipv4Address.origin =
Ed Tanous4a0cb852018-10-15 07:55:04 -0700662 translateAddressOriginDbusToRedfish(*origin,
663 true);
664 }
665 }
666 else if (property.first == "PrefixLength")
667 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500668 const uint8_t* mask =
Ed Tanousabf2add2019-01-22 16:40:12 -0800669 std::get_if<uint8_t>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700670 if (mask != nullptr)
671 {
672 // convert it to the string
Ed Tanous2c70f802020-09-28 14:29:23 -0700673 ipv4Address.netmask = getNetmask(*mask);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700674 }
675 }
Asmitha Karunanithi889ff692021-11-29 08:43:30 -0600676 else if (property.first == "Type" ||
677 property.first == "Gateway")
678 {
679 // Type & Gateway is not used
680 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700681 else
682 {
Ed Tanous62598e32023-07-17 17:06:25 -0700683 BMCWEB_LOG_ERROR(
684 "Got extra property: {} on the {} object",
685 property.first, objpath.first.str);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700686 }
687 }
688 // Check if given address is local, or global
Ed Tanous2c70f802020-09-28 14:29:23 -0700689 ipv4Address.linktype =
Ed Tanous11ba3972022-07-11 09:50:41 -0700690 ipv4Address.address.starts_with("169.254.")
Johnathan Mantey18659d12019-06-07 10:26:29 -0700691 ? LinkType::Local
692 : LinkType::Global;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700693 }
694 }
695 }
696 }
697}
698
699/**
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700700 * @brief Modifies the default gateway assigned to the NIC
701 *
702 * @param[in] ifaceId Id of network interface whose default gateway is to be
703 * changed
704 * @param[in] gateway The new gateway value. Assigning an empty string
705 * causes the gateway to be deleted
706 * @param[io] asyncResp Response object that will be returned to client
707 *
708 * @return None
709 */
710inline void updateIPv4DefaultGateway(
711 const std::string& ifaceId, const std::string& gateway,
712 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
713{
714 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530715 asyncResp, "Gateway", "xyz.openbmc_project.Network",
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700716 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
717 ifaceId,
718 "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway",
Ginu Georgee93abac2024-06-14 17:35:27 +0530719 gateway);
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700720}
721
722/**
723 * @brief Deletes given static IP address for the interface
Ed Tanous4a0cb852018-10-15 07:55:04 -0700724 *
725 * @param[in] ifaceId Id of interface whose IP should be deleted
Ed Tanous4a0cb852018-10-15 07:55:04 -0700726 * @param[in] ipHash DBus Hash id of IP that should be deleted
727 * @param[io] asyncResp Response object that will be returned to client
728 *
729 * @return None
730 */
Ravi Teja9c5e5852023-02-26 21:33:52 -0600731inline void deleteIPAddress(const std::string& ifaceId,
732 const std::string& ipHash,
733 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700734{
735 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800736 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400737 if (ec)
738 {
739 messages::internalError(asyncResp->res);
740 }
741 },
Ed Tanous4a0cb852018-10-15 07:55:04 -0700742 "xyz.openbmc_project.Network",
Ravi Teja9c5e5852023-02-26 21:33:52 -0600743 "/xyz/openbmc_project/network/" + ifaceId + ipHash,
Ed Tanous4a0cb852018-10-15 07:55:04 -0700744 "xyz.openbmc_project.Object.Delete", "Delete");
745}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700746
Ed Tanous4a0cb852018-10-15 07:55:04 -0700747/**
Johnathan Mantey01784822019-06-18 12:44:21 -0700748 * @brief Creates a static IPv4 entry
Ed Tanous4a0cb852018-10-15 07:55:04 -0700749 *
Johnathan Mantey01784822019-06-18 12:44:21 -0700750 * @param[in] ifaceId Id of interface upon which to create the IPv4 entry
751 * @param[in] prefixLength IPv4 prefix syntax for the subnet mask
752 * @param[in] gateway IPv4 address of this interfaces gateway
753 * @param[in] address IPv4 address to assign to this interface
754 * @param[io] asyncResp Response object that will be returned to client
Ed Tanous4a0cb852018-10-15 07:55:04 -0700755 *
756 * @return None
757 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000758inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
759 const std::string& gateway, const std::string& address,
zhanghch058d1b46d2021-04-01 11:18:24 +0800760 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700761{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400762 auto createIpHandler =
763 [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
764 if (ec)
765 {
766 messages::internalError(asyncResp->res);
767 return;
768 }
769 };
Ravi Teja9010ec22019-08-01 23:30:25 -0500770
Ed Tanous4a0cb852018-10-15 07:55:04 -0700771 crow::connections::systemBus->async_method_call(
Ravi Teja9010ec22019-08-01 23:30:25 -0500772 std::move(createIpHandler), "xyz.openbmc_project.Network",
Ed Tanous4a0cb852018-10-15 07:55:04 -0700773 "/xyz/openbmc_project/network/" + ifaceId,
774 "xyz.openbmc_project.Network.IP.Create", "IP",
Johnathan Mantey01784822019-06-18 12:44:21 -0700775 "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength,
Ed Tanous4a0cb852018-10-15 07:55:04 -0700776 gateway);
777}
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500778
779/**
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700780 * @brief Deletes the IP entry for this interface and creates a replacement
781 * static entry
Johnathan Mantey01784822019-06-18 12:44:21 -0700782 *
Johnathan Mantey743eb1c2024-04-03 12:05:57 -0700783 * @param[in] ifaceId Id of interface upon which to create the IPv6 entry
784 * @param[in] id The unique hash entry identifying the DBus entry
785 * @param[in] prefixLength Prefix syntax for the subnet mask
786 * @param[in] address Address to assign to this interface
787 * @param[in] numStaticAddrs Count of IPv4 static addresses
788 * @param[io] asyncResp Response object that will be returned to client
Johnathan Mantey01784822019-06-18 12:44:21 -0700789 *
790 * @return None
791 */
Ravi Teja9c5e5852023-02-26 21:33:52 -0600792
Ravi Teja9c5e5852023-02-26 21:33:52 -0600793inline void deleteAndCreateIPAddress(
794 IpVersion version, const std::string& ifaceId, const std::string& id,
795 uint8_t prefixLength, const std::string& address,
796 const std::string& gateway,
797 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Johnathan Mantey01784822019-06-18 12:44:21 -0700798{
799 crow::connections::systemBus->async_method_call(
Ravi Teja9c5e5852023-02-26 21:33:52 -0600800 [asyncResp, version, ifaceId, address, prefixLength,
801 gateway](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400802 if (ec)
Johnathan Mantey01784822019-06-18 12:44:21 -0700803 {
804 messages::internalError(asyncResp->res);
805 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400806 std::string protocol = "xyz.openbmc_project.Network.IP.Protocol.";
807 protocol += version == IpVersion::IpV4 ? "IPv4" : "IPv6";
808 crow::connections::systemBus->async_method_call(
809 [asyncResp](const boost::system::error_code& ec2) {
810 if (ec2)
811 {
812 messages::internalError(asyncResp->res);
813 }
814 },
815 "xyz.openbmc_project.Network",
816 "/xyz/openbmc_project/network/" + ifaceId,
817 "xyz.openbmc_project.Network.IP.Create", "IP", protocol,
818 address, prefixLength, gateway);
Patrick Williams5a39f772023-10-20 11:20:21 -0500819 },
Johnathan Mantey01784822019-06-18 12:44:21 -0700820 "xyz.openbmc_project.Network",
Ravi Teja9c5e5852023-02-26 21:33:52 -0600821 "/xyz/openbmc_project/network/" + ifaceId + id,
Johnathan Mantey01784822019-06-18 12:44:21 -0700822 "xyz.openbmc_project.Object.Delete", "Delete");
823}
824
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500825inline bool extractIPv6DefaultGatewayData(
826 const std::string& ethifaceId,
827 const dbus::utility::ManagedObjectType& dbusData,
828 std::vector<StaticGatewayData>& staticGatewayConfig)
829{
830 std::string staticGatewayPathStart("/xyz/openbmc_project/network/");
831 staticGatewayPathStart += ethifaceId;
832
833 for (const auto& objpath : dbusData)
834 {
835 if (!std::string_view(objpath.first.str)
836 .starts_with(staticGatewayPathStart))
837 {
838 continue;
839 }
840 for (const auto& interface : objpath.second)
841 {
842 if (interface.first != "xyz.openbmc_project.Network.StaticGateway")
843 {
844 continue;
845 }
846 StaticGatewayData& staticGateway =
847 staticGatewayConfig.emplace_back();
848 staticGateway.id = objpath.first.filename();
849
850 bool success = sdbusplus::unpackPropertiesNoThrow(
851 redfish::dbus_utils::UnpackErrorPrinter(), interface.second,
Ravi Tejaab0d4392024-09-03 12:27:40 -0500852 "Gateway", staticGateway.gateway, "ProtocolType",
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500853 staticGateway.protocol);
854 if (!success)
855 {
856 return false;
857 }
858 }
859 }
860 return true;
861}
862
Johnathan Mantey01784822019-06-18 12:44:21 -0700863/**
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500864 * @brief Creates IPv6 with given data
865 *
866 * @param[in] ifaceId Id of interface whose IP should be added
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500867 * @param[in] prefixLength Prefix length that needs to be added
868 * @param[in] address IP address that needs to be added
869 * @param[io] asyncResp Response object that will be returned to client
870 *
871 * @return None
872 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500873inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength,
874 const std::string& address,
zhanghch058d1b46d2021-04-01 11:18:24 +0800875 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500876{
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500877 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
878 path /= ifaceId;
879
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400880 auto createIpHandler =
881 [asyncResp, address](const boost::system::error_code& ec) {
882 if (ec)
Nitin Kumar Kotaniafc23ef82023-06-29 04:55:09 -0500883 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400884 if (ec == boost::system::errc::io_error)
885 {
886 messages::propertyValueFormatError(asyncResp->res, address,
887 "Address");
888 }
889 else
890 {
891 messages::internalError(asyncResp->res);
892 }
Nitin Kumar Kotaniafc23ef82023-06-29 04:55:09 -0500893 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400894 };
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500895 // Passing null for gateway, as per redfish spec IPv6StaticAddresses
896 // object does not have associated gateway property
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500897 crow::connections::systemBus->async_method_call(
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500898 std::move(createIpHandler), "xyz.openbmc_project.Network", path,
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500899 "xyz.openbmc_project.Network.IP.Create", "IP",
900 "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength,
901 "");
902}
903
Ed Tanous4a0cb852018-10-15 07:55:04 -0700904/**
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500905 * @brief Deletes given IPv6 Static Gateway
906 *
907 * @param[in] ifaceId Id of interface whose IP should be deleted
908 * @param[in] ipHash DBus Hash id of IP that should be deleted
909 * @param[io] asyncResp Response object that will be returned to client
910 *
911 * @return None
912 */
913inline void
Ravi Teja739b27b2024-08-27 21:03:53 -0500914 deleteIPv6Gateway(std::string_view ifaceId, std::string_view gatewayId,
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500915 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
916{
917 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
Ravi Teja739b27b2024-08-27 21:03:53 -0500918 path /= ifaceId;
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500919 path /= gatewayId;
920 crow::connections::systemBus->async_method_call(
921 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400922 if (ec)
923 {
924 messages::internalError(asyncResp->res);
925 }
926 },
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500927 "xyz.openbmc_project.Network", path,
928 "xyz.openbmc_project.Object.Delete", "Delete");
929}
930
931/**
932 * @brief Creates IPv6 static default gateway with given data
933 *
934 * @param[in] ifaceId Id of interface whose IP should be added
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500935 * @param[in] gateway Gateway address that needs to be added
936 * @param[io] asyncResp Response object that will be returned to client
937 *
938 * @return None
939 */
940inline void createIPv6DefaultGateway(
Asmitha Karunanithicf91c8c2025-01-24 04:39:15 -0600941 std::string_view ifaceId, const std::string& gateway,
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500942 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
943{
944 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
945 path /= ifaceId;
946 auto createIpHandler = [asyncResp](const boost::system::error_code& ec) {
947 if (ec)
948 {
949 messages::internalError(asyncResp->res);
950 }
951 };
952 crow::connections::systemBus->async_method_call(
953 std::move(createIpHandler), "xyz.openbmc_project.Network", path,
954 "xyz.openbmc_project.Network.StaticGateway.Create", "StaticGateway",
Ravi Tejaab0d4392024-09-03 12:27:40 -0500955 gateway, "xyz.openbmc_project.Network.IP.Protocol.IPv6");
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500956}
957
958/**
959 * @brief Deletes the IPv6 default gateway entry for this interface and
960 * creates a replacement IPv6 default gateway entry
961 *
962 * @param[in] ifaceId Id of interface upon which to create the IPv6
963 * entry
964 * @param[in] gateway IPv6 gateway to assign to this interface
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500965 * @param[io] asyncResp Response object that will be returned to client
966 *
967 * @return None
968 */
969inline void deleteAndCreateIPv6DefaultGateway(
970 std::string_view ifaceId, std::string_view gatewayId,
Asmitha Karunanithicf91c8c2025-01-24 04:39:15 -0600971 const std::string& gateway,
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500972 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
973{
974 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
Ravi Teja739b27b2024-08-27 21:03:53 -0500975 path /= ifaceId;
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500976 path /= gatewayId;
977 crow::connections::systemBus->async_method_call(
Ravi Tejaab0d4392024-09-03 12:27:40 -0500978 [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400979 if (ec)
980 {
981 messages::internalError(asyncResp->res);
982 return;
983 }
Ravi Tejaab0d4392024-09-03 12:27:40 -0500984 createIPv6DefaultGateway(ifaceId, gateway, asyncResp);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400985 },
Sunitha Harishce73d5c2023-04-07 06:46:49 -0500986 "xyz.openbmc_project.Network", path,
987 "xyz.openbmc_project.Object.Delete", "Delete");
988}
989
990/**
991 * @brief Sets IPv6 default gateway with given data
992 *
993 * @param[in] ifaceId Id of interface whose gateway should be added
994 * @param[in] input Contains address that needs to be added
995 * @param[in] staticGatewayData Current static gateways in the system
996 * @param[io] asyncResp Response object that will be returned to client
997 *
998 * @return None
999 */
1000
1001inline void handleIPv6DefaultGateway(
Ed Tanous3dfed532024-03-06 14:41:27 -08001002 const std::string& ifaceId,
1003 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001004 const std::vector<StaticGatewayData>& staticGatewayData,
1005 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1006{
1007 size_t entryIdx = 1;
1008 std::vector<StaticGatewayData>::const_iterator staticGatewayEntry =
1009 staticGatewayData.begin();
1010
Ed Tanous3dfed532024-03-06 14:41:27 -08001011 for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
1012 input)
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001013 {
1014 // find the next gateway entry
1015 while (staticGatewayEntry != staticGatewayData.end())
1016 {
1017 if (staticGatewayEntry->protocol ==
1018 "xyz.openbmc_project.Network.IP.Protocol.IPv6")
1019 {
1020 break;
1021 }
1022 staticGatewayEntry++;
1023 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001024 std::string pathString =
1025 "IPv6StaticDefaultGateways/" + std::to_string(entryIdx);
Ed Tanous3dfed532024-03-06 14:41:27 -08001026 nlohmann::json::object_t* obj =
1027 std::get_if<nlohmann::json::object_t>(&thisJson);
1028 if (obj == nullptr)
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001029 {
1030 if (staticGatewayEntry == staticGatewayData.end())
1031 {
1032 messages::resourceCannotBeDeleted(asyncResp->res);
1033 return;
1034 }
Ravi Teja739b27b2024-08-27 21:03:53 -05001035 deleteIPv6Gateway(ifaceId, staticGatewayEntry->id, asyncResp);
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001036 return;
1037 }
Ed Tanous3dfed532024-03-06 14:41:27 -08001038 if (obj->empty())
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001039 {
1040 // Do nothing, but make sure the entry exists.
1041 if (staticGatewayEntry == staticGatewayData.end())
1042 {
Ed Tanous3dfed532024-03-06 14:41:27 -08001043 messages::propertyValueFormatError(asyncResp->res, *obj,
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001044 pathString);
1045 return;
1046 }
1047 }
1048 std::optional<std::string> address;
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001049
Ravi Tejaab0d4392024-09-03 12:27:40 -05001050 if (!json_util::readJsonObject(*obj, asyncResp->res, "Address",
1051 address))
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001052 {
1053 return;
1054 }
1055 const std::string* addr = nullptr;
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001056 if (address)
1057 {
1058 addr = &(*address);
1059 }
1060 else if (staticGatewayEntry != staticGatewayData.end())
1061 {
1062 addr = &(staticGatewayEntry->gateway);
1063 }
1064 else
1065 {
1066 messages::propertyMissing(asyncResp->res, pathString + "/Address");
1067 return;
1068 }
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001069 if (staticGatewayEntry != staticGatewayData.end())
1070 {
1071 deleteAndCreateIPv6DefaultGateway(ifaceId, staticGatewayEntry->id,
Ravi Tejaab0d4392024-09-03 12:27:40 -05001072 *addr, asyncResp);
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001073 staticGatewayEntry++;
1074 }
1075 else
1076 {
Ravi Tejaab0d4392024-09-03 12:27:40 -05001077 createIPv6DefaultGateway(ifaceId, *addr, asyncResp);
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001078 }
1079 entryIdx++;
1080 }
1081}
1082
1083/**
Ed Tanous4a0cb852018-10-15 07:55:04 -07001084 * Function that retrieves all properties for given Ethernet Interface
1085 * Object
1086 * from EntityManager Network Manager
1087 * @param ethiface_id a eth interface id to query on DBus
1088 * @param callback a function that shall be called to convert Dbus output
1089 * into JSON
1090 */
1091template <typename CallbackFunc>
Ed Tanous81ce6092020-12-17 16:54:55 +00001092void getEthernetIfaceData(const std::string& ethifaceId,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001093 CallbackFunc&& callback)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001094{
George Liuf5892d02023-03-01 10:37:08 +08001095 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1096 dbus::utility::getManagedObjects(
1097 "xyz.openbmc_project.Network", path,
Ed Tanousf94c4ec2022-01-06 12:44:41 -08001098 [ethifaceId{std::string{ethifaceId}},
Ed Tanous8cb2c022024-03-27 16:31:46 -07001099 callback = std::forward<CallbackFunc>(callback)](
Ed Tanous8b242752023-06-27 17:17:13 -07001100 const boost::system::error_code& ec,
Ed Tanous3dfed532024-03-06 14:41:27 -08001101 const dbus::utility::ManagedObjectType& resp) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001102 EthernetInterfaceData ethData{};
1103 std::vector<IPv4AddressData> ipv4Data;
1104 std::vector<IPv6AddressData> ipv6Data;
1105 std::vector<StaticGatewayData> ipv6GatewayData;
Ed Tanous4a0cb852018-10-15 07:55:04 -07001106
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001107 if (ec)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001108 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001109 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1110 return;
Ed Tanous4a0cb852018-10-15 07:55:04 -07001111 }
1112
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001113 bool found =
1114 extractEthernetInterfaceData(ethifaceId, resp, ethData);
1115 if (!found)
1116 {
1117 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1118 return;
1119 }
1120
1121 extractIPData(ethifaceId, resp, ipv4Data);
1122 // Fix global GW
1123 for (IPv4AddressData& ipv4 : ipv4Data)
1124 {
1125 if (((ipv4.linktype == LinkType::Global) &&
1126 (ipv4.gateway == "0.0.0.0")) ||
1127 (ipv4.origin == "DHCP") || (ipv4.origin == "Static"))
1128 {
1129 ipv4.gateway = ethData.defaultGateway;
1130 }
1131 }
1132
1133 extractIPV6Data(ethifaceId, resp, ipv6Data);
1134 if (!extractIPv6DefaultGatewayData(ethifaceId, resp,
1135 ipv6GatewayData))
1136 {
1137 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1138 }
1139 // Finally make a callback with useful data
1140 callback(true, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1141 });
Ed Tanous271584a2019-07-09 16:24:22 -07001142}
Ed Tanous4a0cb852018-10-15 07:55:04 -07001143
1144/**
1145 * Function that retrieves all Ethernet Interfaces available through Network
1146 * Manager
1147 * @param callback a function that shall be called to convert Dbus output
1148 * into JSON.
1149 */
1150template <typename CallbackFunc>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001151void getEthernetIfaceList(CallbackFunc&& callback)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001152{
George Liuf5892d02023-03-01 10:37:08 +08001153 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1154 dbus::utility::getManagedObjects(
1155 "xyz.openbmc_project.Network", path,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001156 [callback = std::forward<CallbackFunc>(callback)](
Ed Tanous8b242752023-06-27 17:17:13 -07001157 const boost::system::error_code& ec,
George Liuf5892d02023-03-01 10:37:08 +08001158 const dbus::utility::ManagedObjectType& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001159 // Callback requires vector<string> to retrieve all available
1160 // ethernet interfaces
1161 std::vector<std::string> ifaceList;
1162 ifaceList.reserve(resp.size());
1163 if (ec)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001164 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001165 callback(false, ifaceList);
1166 return;
1167 }
1168
1169 // Iterate over all retrieved ObjectPaths.
1170 for (const auto& objpath : resp)
1171 {
1172 // And all interfaces available for certain ObjectPath.
1173 for (const auto& interface : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -07001174 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001175 // If interface is
1176 // xyz.openbmc_project.Network.EthernetInterface, this is
1177 // what we're looking for.
1178 if (interface.first ==
1179 "xyz.openbmc_project.Network.EthernetInterface")
Ed Tanous1abe55e2018-09-05 08:30:59 -07001180 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001181 std::string ifaceId = objpath.first.filename();
1182 if (ifaceId.empty())
1183 {
1184 continue;
1185 }
1186 // and put it into output vector.
1187 ifaceList.emplace_back(ifaceId);
Ed Tanous1abe55e2018-09-05 08:30:59 -07001188 }
1189 }
Ed Tanous4a0cb852018-10-15 07:55:04 -07001190 }
Ed Tanous2c5875a2023-05-15 09:56:06 -07001191
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001192 std::ranges::sort(ifaceList, AlphanumLess<std::string>());
Ed Tanous2c5875a2023-05-15 09:56:06 -07001193
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001194 // Finally make a callback with useful data
1195 callback(true, ifaceList);
1196 });
Ed Tanous271584a2019-07-09 16:24:22 -07001197}
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +01001198
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001199inline void
1200 handleHostnamePatch(const std::string& hostname,
1201 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001202{
Ed Tanousbf648f72021-06-03 15:00:14 -07001203 // SHOULD handle host names of up to 255 characters(RFC 1123)
1204 if (hostname.length() > 255)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001205 {
Ed Tanousbf648f72021-06-03 15:00:14 -07001206 messages::propertyValueFormatError(asyncResp->res, hostname,
1207 "HostName");
1208 return;
1209 }
Ed Tanousd02aad32024-02-13 14:43:34 -08001210 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301211 asyncResp, "HostName", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001212 sdbusplus::message::object_path("/xyz/openbmc_project/network/config"),
1213 "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
Ginu Georgee93abac2024-06-14 17:35:27 +05301214 hostname);
Ed Tanousbf648f72021-06-03 15:00:14 -07001215}
1216
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001217inline void
Tejas Patil35fb5312021-09-20 15:35:20 +05301218 handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize,
1219 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1220{
Ed Tanousd02aad32024-02-13 14:43:34 -08001221 sdbusplus::message::object_path objPath("/xyz/openbmc_project/network");
1222 objPath /= ifaceId;
Ginu Georgee93abac2024-06-14 17:35:27 +05301223 setDbusProperty(asyncResp, "MTUSize", "xyz.openbmc_project.Network",
1224 objPath, "xyz.openbmc_project.Network.EthernetInterface",
1225 "MTU", mtuSize);
Tejas Patil35fb5312021-09-20 15:35:20 +05301226}
1227
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001228inline void handleDomainnamePatch(
1229 const std::string& ifaceId, const std::string& domainname,
1230 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001231{
1232 std::vector<std::string> vectorDomainname = {domainname};
Ed Tanousd02aad32024-02-13 14:43:34 -08001233 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301234 asyncResp, "FQDN", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001235 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1236 ifaceId,
Ginu Georgee93abac2024-06-14 17:35:27 +05301237 "xyz.openbmc_project.Network.EthernetInterface", "DomainName",
Ed Tanousd02aad32024-02-13 14:43:34 -08001238 vectorDomainname);
Ed Tanousbf648f72021-06-03 15:00:14 -07001239}
1240
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001241inline bool isHostnameValid(const std::string& hostname)
Ed Tanousbf648f72021-06-03 15:00:14 -07001242{
1243 // A valid host name can never have the dotted-decimal form (RFC 1123)
Ed Tanous3544d2a2023-08-06 18:12:20 -07001244 if (std::ranges::all_of(hostname, ::isdigit))
Ed Tanousbf648f72021-06-03 15:00:14 -07001245 {
1246 return false;
1247 }
1248 // Each label(hostname/subdomains) within a valid FQDN
1249 // MUST handle host names of up to 63 characters (RFC 1123)
1250 // labels cannot start or end with hyphens (RFC 952)
1251 // labels can start with numbers (RFC 1123)
Ed Tanous4b242742023-05-11 09:51:51 -07001252 const static std::regex pattern(
Ed Tanousbf648f72021-06-03 15:00:14 -07001253 "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$");
1254
1255 return std::regex_match(hostname, pattern);
1256}
1257
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001258inline bool isDomainnameValid(const std::string& domainname)
Ed Tanousbf648f72021-06-03 15:00:14 -07001259{
1260 // Can have multiple subdomains
1261 // Top Level Domain's min length is 2 character
Ed Tanous4b242742023-05-11 09:51:51 -07001262 const static std::regex pattern(
George Liu0fda0f12021-11-16 10:06:17 +08001263 "^([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 -07001264
1265 return std::regex_match(domainname, pattern);
1266}
1267
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001268inline void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn,
1269 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001270{
1271 // Total length of FQDN must not exceed 255 characters(RFC 1035)
1272 if (fqdn.length() > 255)
1273 {
1274 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1275 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -07001276 }
1277
Ed Tanousbf648f72021-06-03 15:00:14 -07001278 size_t pos = fqdn.find('.');
1279 if (pos == std::string::npos)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001280 {
Ed Tanousbf648f72021-06-03 15:00:14 -07001281 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1282 return;
1283 }
zhanghch058d1b46d2021-04-01 11:18:24 +08001284
Ed Tanousbf648f72021-06-03 15:00:14 -07001285 std::string hostname;
1286 std::string domainname;
1287 domainname = (fqdn).substr(pos + 1);
1288 hostname = (fqdn).substr(0, pos);
1289
1290 if (!isHostnameValid(hostname) || !isDomainnameValid(domainname))
1291 {
1292 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1293 return;
1294 }
1295
1296 handleHostnamePatch(hostname, asyncResp);
1297 handleDomainnamePatch(ifaceId, domainname, asyncResp);
1298}
1299
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001300inline void handleMACAddressPatch(
1301 const std::string& ifaceId, const std::string& macAddress,
1302 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001303{
Ed Tanousd02aad32024-02-13 14:43:34 -08001304 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301305 asyncResp, "MACAddress", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001306 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1307 ifaceId,
Ginu Georgee93abac2024-06-14 17:35:27 +05301308 "xyz.openbmc_project.Network.MACAddress", "MACAddress", macAddress);
Ed Tanousbf648f72021-06-03 15:00:14 -07001309}
1310
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001311inline void setDHCPEnabled(const std::string& ifaceId,
1312 const std::string& propertyName, const bool v4Value,
1313 const bool v6Value,
1314 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001315{
1316 const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
Ed Tanousd02aad32024-02-13 14:43:34 -08001317 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301318 asyncResp, "DHCPv4", "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08001319 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1320 ifaceId,
Ginu Georgee93abac2024-06-14 17:35:27 +05301321 "xyz.openbmc_project.Network.EthernetInterface", propertyName, dhcp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001322}
1323
Jishnu CMe4588152023-05-11 00:04:40 -05001324enum class NetworkType
1325{
1326 dhcp4,
1327 dhcp6
1328};
1329
1330inline void setDHCPConfig(const std::string& propertyName, const bool& value,
1331 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1332 const std::string& ethifaceId, NetworkType type)
Ed Tanousbf648f72021-06-03 15:00:14 -07001333{
Ed Tanous62598e32023-07-17 17:06:25 -07001334 BMCWEB_LOG_DEBUG("{} = {}", propertyName, value);
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001335 std::string redfishPropertyName;
Jishnu CMe4588152023-05-11 00:04:40 -05001336 sdbusplus::message::object_path path("/xyz/openbmc_project/network/");
1337 path /= ethifaceId;
1338
1339 if (type == NetworkType::dhcp4)
1340 {
1341 path /= "dhcp4";
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001342 redfishPropertyName = "DHCPv4";
Jishnu CMe4588152023-05-11 00:04:40 -05001343 }
1344 else
1345 {
1346 path /= "dhcp6";
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001347 redfishPropertyName = "DHCPv6";
Jishnu CMe4588152023-05-11 00:04:40 -05001348 }
1349
Ginu Georgee93abac2024-06-14 17:35:27 +05301350 setDbusProperty(
1351 asyncResp, redfishPropertyName, "xyz.openbmc_project.Network", path,
1352 "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, value);
Ed Tanousbf648f72021-06-03 15:00:14 -07001353}
1354
Ravi Tejab10d8db2022-05-24 09:04:12 -05001355inline void handleSLAACAutoConfigPatch(
1356 const std::string& ifaceId, bool ipv6AutoConfigEnabled,
1357 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1358{
1359 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1360 path /= ifaceId;
Ginu Georgee93abac2024-06-14 17:35:27 +05301361 setDbusProperty(asyncResp,
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001362 "StatelessAddressAutoConfig/IPv6AutoConfigEnabled",
Ginu Georgee93abac2024-06-14 17:35:27 +05301363 "xyz.openbmc_project.Network", path,
1364 "xyz.openbmc_project.Network.EthernetInterface",
1365 "IPv6AcceptRA", ipv6AutoConfigEnabled);
Ravi Tejab10d8db2022-05-24 09:04:12 -05001366}
1367
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001368inline void handleDHCPPatch(
1369 const std::string& ifaceId, const EthernetInterfaceData& ethData,
1370 const DHCPParameters& v4dhcpParms, const DHCPParameters& v6dhcpParms,
1371 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001372{
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001373 bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
1374 bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false);
Ed Tanousbf648f72021-06-03 15:00:14 -07001375
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001376 if (ipv4Active)
1377 {
1378 updateIPv4DefaultGateway(ifaceId, "", asyncResp);
1379 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001380 bool nextv4DHCPState =
1381 v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active;
1382
1383 bool nextv6DHCPState{};
1384 if (v6dhcpParms.dhcpv6OperatingMode)
1385 {
Ravi Tejab10d8db2022-05-24 09:04:12 -05001386 if ((*v6dhcpParms.dhcpv6OperatingMode != "Enabled") &&
Ed Tanousbf648f72021-06-03 15:00:14 -07001387 (*v6dhcpParms.dhcpv6OperatingMode != "Disabled"))
1388 {
1389 messages::propertyValueFormatError(asyncResp->res,
1390 *v6dhcpParms.dhcpv6OperatingMode,
1391 "OperatingMode");
1392 return;
1393 }
Ravi Tejab10d8db2022-05-24 09:04:12 -05001394 nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Enabled");
Ed Tanousbf648f72021-06-03 15:00:14 -07001395 }
1396 else
1397 {
1398 nextv6DHCPState = ipv6Active;
1399 }
1400
Jishnu CMe4588152023-05-11 00:04:40 -05001401 bool nextDNSv4 = ethData.dnsv4Enabled;
1402 bool nextDNSv6 = ethData.dnsv6Enabled;
1403 if (v4dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001404 {
Jishnu CMe4588152023-05-11 00:04:40 -05001405 nextDNSv4 = *v4dhcpParms.useDnsServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001406 }
Jishnu CMe4588152023-05-11 00:04:40 -05001407 if (v6dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001408 {
Jishnu CMe4588152023-05-11 00:04:40 -05001409 nextDNSv6 = *v6dhcpParms.useDnsServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001410 }
1411
Jishnu CMe4588152023-05-11 00:04:40 -05001412 bool nextNTPv4 = ethData.ntpv4Enabled;
1413 bool nextNTPv6 = ethData.ntpv6Enabled;
1414 if (v4dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001415 {
Jishnu CMe4588152023-05-11 00:04:40 -05001416 nextNTPv4 = *v4dhcpParms.useNtpServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001417 }
Jishnu CMe4588152023-05-11 00:04:40 -05001418 if (v6dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001419 {
Jishnu CMe4588152023-05-11 00:04:40 -05001420 nextNTPv6 = *v6dhcpParms.useNtpServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001421 }
1422
Ravi Teja91c441e2024-02-23 09:03:43 -06001423 bool nextUsev4Domain = ethData.domainv4Enabled;
1424 bool nextUsev6Domain = ethData.domainv6Enabled;
Jishnu CMe4588152023-05-11 00:04:40 -05001425 if (v4dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001426 {
Jishnu CMe4588152023-05-11 00:04:40 -05001427 nextUsev4Domain = *v4dhcpParms.useDomainName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001428 }
Jishnu CMe4588152023-05-11 00:04:40 -05001429 if (v6dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001430 {
Jishnu CMe4588152023-05-11 00:04:40 -05001431 nextUsev6Domain = *v6dhcpParms.useDomainName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001432 }
1433
Ed Tanous62598e32023-07-17 17:06:25 -07001434 BMCWEB_LOG_DEBUG("set DHCPEnabled...");
Ed Tanousbf648f72021-06-03 15:00:14 -07001435 setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
1436 asyncResp);
Ed Tanous62598e32023-07-17 17:06:25 -07001437 BMCWEB_LOG_DEBUG("set DNSEnabled...");
Jishnu CMe4588152023-05-11 00:04:40 -05001438 setDHCPConfig("DNSEnabled", nextDNSv4, asyncResp, ifaceId,
1439 NetworkType::dhcp4);
Ed Tanous62598e32023-07-17 17:06:25 -07001440 BMCWEB_LOG_DEBUG("set NTPEnabled...");
Jishnu CMe4588152023-05-11 00:04:40 -05001441 setDHCPConfig("NTPEnabled", nextNTPv4, asyncResp, ifaceId,
1442 NetworkType::dhcp4);
Ravi Teja91c441e2024-02-23 09:03:43 -06001443 BMCWEB_LOG_DEBUG("set DomainEnabled...");
1444 setDHCPConfig("DomainEnabled", nextUsev4Domain, asyncResp, ifaceId,
Jishnu CMe4588152023-05-11 00:04:40 -05001445 NetworkType::dhcp4);
1446 BMCWEB_LOG_DEBUG("set DNSEnabled for dhcp6...");
1447 setDHCPConfig("DNSEnabled", nextDNSv6, asyncResp, ifaceId,
1448 NetworkType::dhcp6);
1449 BMCWEB_LOG_DEBUG("set NTPEnabled for dhcp6...");
1450 setDHCPConfig("NTPEnabled", nextNTPv6, asyncResp, ifaceId,
1451 NetworkType::dhcp6);
Ravi Teja91c441e2024-02-23 09:03:43 -06001452 BMCWEB_LOG_DEBUG("set DomainEnabled for dhcp6...");
1453 setDHCPConfig("DomainEnabled", nextUsev6Domain, asyncResp, ifaceId,
Jishnu CMe4588152023-05-11 00:04:40 -05001454 NetworkType::dhcp6);
Ed Tanousbf648f72021-06-03 15:00:14 -07001455}
1456
Ed Tanous77179532023-02-28 10:45:28 -08001457inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry(
1458 const std::vector<IPv4AddressData>::const_iterator& head,
1459 const std::vector<IPv4AddressData>::const_iterator& end)
Ed Tanousbf648f72021-06-03 15:00:14 -07001460{
1461 return std::find_if(head, end, [](const IPv4AddressData& value) {
1462 return value.origin == "Static";
1463 });
1464}
1465
Ed Tanous77179532023-02-28 10:45:28 -08001466inline std::vector<IPv6AddressData>::const_iterator getNextStaticIpEntry(
1467 const std::vector<IPv6AddressData>::const_iterator& head,
1468 const std::vector<IPv6AddressData>::const_iterator& end)
Ed Tanousbf648f72021-06-03 15:00:14 -07001469{
1470 return std::find_if(head, end, [](const IPv6AddressData& value) {
1471 return value.origin == "Static";
1472 });
1473}
1474
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001475enum class AddrChange
Ed Tanousbf648f72021-06-03 15:00:14 -07001476{
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001477 Noop,
1478 Delete,
1479 Update,
1480};
1481
1482// Struct representing a dbus change
1483struct AddressPatch
1484{
1485 std::string address;
1486 std::string gateway;
1487 uint8_t prefixLength = 0;
1488 std::string existingDbusId;
1489 AddrChange operation = AddrChange::Noop;
1490};
1491
1492inline bool parseAddresses(
1493 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
1494 const std::vector<IPv4AddressData>& ipv4Data, crow::Response& res,
1495 std::vector<AddressPatch>& addressesOut, std::string& gatewayOut)
1496{
Ed Tanous77179532023-02-28 10:45:28 -08001497 std::vector<IPv4AddressData>::const_iterator nicIpEntry =
Ed Tanousbf648f72021-06-03 15:00:14 -07001498 getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend());
1499
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001500 std::string lastGatewayPath;
1501 size_t entryIdx = 0;
Ed Tanous3dfed532024-03-06 14:41:27 -08001502 for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
1503 input)
Ed Tanousbf648f72021-06-03 15:00:14 -07001504 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001505 std::string pathString =
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001506 std::format("IPv4StaticAddresses/{}", entryIdx);
1507 AddressPatch& thisAddress = addressesOut.emplace_back();
Ed Tanous3dfed532024-03-06 14:41:27 -08001508 nlohmann::json::object_t* obj =
1509 std::get_if<nlohmann::json::object_t>(&thisJson);
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001510 if (nicIpEntry != ipv4Data.cend())
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001511 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001512 thisAddress.existingDbusId = nicIpEntry->id;
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001513 }
1514
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001515 if (obj == nullptr)
1516 {
1517 if (thisAddress.existingDbusId.empty())
1518 {
1519 // Received a DELETE action on an entry not assigned to the NIC
1520 messages::resourceCannotBeDeleted(res);
1521 return false;
1522 }
1523 thisAddress.operation = AddrChange::Delete;
1524 }
1525 else
Ed Tanousbf648f72021-06-03 15:00:14 -07001526 {
1527 std::optional<std::string> address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001528 std::optional<std::string> gateway;
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001529 std::optional<std::string> subnetMask;
1530 if (!obj->empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001531 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001532 if (!json_util::readJsonObject( //
1533 *obj, res, //
1534 "Address", address, //
1535 "Gateway", gateway, //
1536 "SubnetMask", subnetMask //
1537 ))
1538 {
1539 messages::propertyValueFormatError(res, *obj, pathString);
1540 return false;
1541 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001542 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001543 // Find the address/subnet/gateway values. Any values that are
1544 // not explicitly provided are assumed to be unmodified from the
1545 // current state of the interface. Merge existing state into the
1546 // current request.
Ed Tanousbf648f72021-06-03 15:00:14 -07001547 if (address)
1548 {
Ed Tanouse01d0c32023-06-30 13:21:32 -07001549 if (!ip_util::ipv4VerifyIpAndGetBitcount(*address))
Ed Tanousbf648f72021-06-03 15:00:14 -07001550 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001551 messages::propertyValueFormatError(res, *address,
Ed Tanousbf648f72021-06-03 15:00:14 -07001552 pathString + "/Address");
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001553 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001554 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001555 thisAddress.operation = AddrChange::Update;
1556 thisAddress.address = *address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001557 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001558 else if (thisAddress.existingDbusId.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001559 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001560 messages::propertyMissing(res, pathString + "/Address");
1561 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001562 }
1563 else
1564 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001565 thisAddress.address = nicIpEntry->address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001566 }
1567
1568 if (subnetMask)
1569 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001570 uint8_t prefixLength = 0;
Ed Tanous033f1e42022-08-15 09:47:37 -07001571 if (!ip_util::ipv4VerifyIpAndGetBitcount(*subnetMask,
1572 &prefixLength))
Ed Tanousbf648f72021-06-03 15:00:14 -07001573 {
1574 messages::propertyValueFormatError(
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001575 res, *subnetMask, pathString + "/SubnetMask");
1576 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001577 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001578 thisAddress.prefixLength = prefixLength;
1579 thisAddress.operation = AddrChange::Update;
Ed Tanousbf648f72021-06-03 15:00:14 -07001580 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001581 else if (thisAddress.existingDbusId.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001582 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001583 messages::propertyMissing(res, pathString + "/SubnetMask");
1584 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001585 }
1586 else
1587 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001588 uint8_t prefixLength = 0;
1589 // Ignore return code. It came from internal, it's it's invalid
1590 // nothing we can do
1591 ip_util::ipv4VerifyIpAndGetBitcount(nicIpEntry->netmask,
1592 &prefixLength);
Ed Tanousbf648f72021-06-03 15:00:14 -07001593
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001594 thisAddress.prefixLength = prefixLength;
1595 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001596 if (gateway)
1597 {
Ed Tanouse01d0c32023-06-30 13:21:32 -07001598 if (!ip_util::ipv4VerifyIpAndGetBitcount(*gateway))
Ed Tanousbf648f72021-06-03 15:00:14 -07001599 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001600 messages::propertyValueFormatError(res, *gateway,
Ed Tanousbf648f72021-06-03 15:00:14 -07001601 pathString + "/Gateway");
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001602 return false;
Ed Tanousbf648f72021-06-03 15:00:14 -07001603 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001604 thisAddress.operation = AddrChange::Update;
1605 thisAddress.gateway = *gateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001606 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001607 else if (thisAddress.existingDbusId.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001608 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001609 // Default to null gateway
1610 gateway = "";
Ed Tanousbf648f72021-06-03 15:00:14 -07001611 }
1612 else
1613 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001614 thisAddress.gateway = nicIpEntry->gateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001615 }
1616
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001617 // Changing gateway from existing
1618 if (!thisAddress.gateway.empty() &&
1619 thisAddress.gateway != "0.0.0.0")
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001620 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001621 if (!gatewayOut.empty() && gatewayOut != thisAddress.gateway)
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001622 {
1623 // A NIC can only have a single active gateway value.
1624 // If any gateway in the array of static addresses
1625 // mismatch the PATCH is in error.
1626 std::string arg1 = pathString + "/Gateway";
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001627 std::string arg2 = lastGatewayPath + "/Gateway";
1628 messages::propertyValueConflict(res, arg1, arg2);
1629 return false;
1630 }
1631 gatewayOut = thisAddress.gateway;
1632 lastGatewayPath = pathString;
1633 }
1634 }
1635 nicIpEntry++;
1636 nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
1637 entryIdx++;
1638 }
1639
1640 // Delete the remaining IPs
1641 while (nicIpEntry != ipv4Data.cend())
1642 {
1643 AddressPatch& thisAddress = addressesOut.emplace_back();
1644 thisAddress.operation = AddrChange::Delete;
1645 thisAddress.existingDbusId = nicIpEntry->id;
1646 nicIpEntry++;
1647 nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
1648 }
1649
1650 return true;
1651}
1652
1653inline void handleIPv4StaticPatch(
1654 const std::string& ifaceId,
1655 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
1656 const EthernetInterfaceData& ethData,
1657 const std::vector<IPv4AddressData>& ipv4Data,
1658 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1659{
1660 std::vector<AddressPatch> addresses;
1661 std::string gatewayOut;
1662 if (!parseAddresses(input, ipv4Data, asyncResp->res, addresses, gatewayOut))
1663 {
1664 return;
1665 }
1666
1667 // If we're setting the gateway to something new, delete the
1668 // existing so we won't conflict
1669 if (!ethData.defaultGateway.empty() && ethData.defaultGateway != gatewayOut)
1670 {
1671 updateIPv4DefaultGateway(ifaceId, "", asyncResp);
1672 }
1673
1674 for (const AddressPatch& address : addresses)
1675 {
1676 switch (address.operation)
1677 {
1678 case AddrChange::Delete:
1679 {
1680 BMCWEB_LOG_ERROR("Deleting id {} on interface {}",
1681 address.existingDbusId, ifaceId);
1682 deleteIPAddress(ifaceId, address.existingDbusId, asyncResp);
1683 }
1684 break;
1685 case AddrChange::Update:
1686 {
1687 // Update is a delete then a recreate
1688 // Only need to update if there is an existing ip at this index
1689 if (!address.existingDbusId.empty())
1690 {
1691 BMCWEB_LOG_ERROR("Deleting id {} on interface {}",
1692 address.existingDbusId, ifaceId);
1693 deleteAndCreateIPAddress(
1694 IpVersion::IpV4, ifaceId, address.existingDbusId,
1695 address.prefixLength, address.address, address.gateway,
1696 asyncResp);
1697 }
1698 else
1699 {
1700 // Otherwise, just create a new one
1701 BMCWEB_LOG_ERROR(
1702 "creating ip {} prefix {} gateway {} on interface {}",
1703 address.address, address.prefixLength, address.gateway,
1704 ifaceId);
1705 createIPv4(ifaceId, address.prefixLength, address.gateway,
1706 address.address, asyncResp);
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001707 }
1708 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001709 break;
1710 default:
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001711 {
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001712 // Leave alone
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001713 }
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001714 break;
1715 }
1716 }
Johnathan Mantey743eb1c2024-04-03 12:05:57 -07001717
Ed Tanous6e1a52f2024-11-15 19:44:16 -08001718 // now update to the new gateway.
1719 // Default gateway is already empty, so no need to update if we're clearing
1720 if (!gatewayOut.empty() && ethData.defaultGateway != gatewayOut)
1721 {
1722 updateIPv4DefaultGateway(ifaceId, gatewayOut, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001723 }
1724}
1725
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001726inline void handleStaticNameServersPatch(
Ed Tanousbf648f72021-06-03 15:00:14 -07001727 const std::string& ifaceId,
1728 const std::vector<std::string>& updatedStaticNameServers,
1729 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1730{
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001731 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301732 asyncResp, "StaticNameServers", "xyz.openbmc_project.Network",
Asmitha Karunanithi1847f2a2024-03-26 22:03:48 -05001733 sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1734 ifaceId,
George Liu9ae226f2023-06-21 17:56:46 +08001735 "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers",
Ginu Georgee93abac2024-06-14 17:35:27 +05301736 updatedStaticNameServers);
Ed Tanousbf648f72021-06-03 15:00:14 -07001737}
1738
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001739inline void handleIPv6StaticAddressesPatch(
Ed Tanous3dfed532024-03-06 14:41:27 -08001740 const std::string& ifaceId,
1741 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
Ed Tanous77179532023-02-28 10:45:28 -08001742 const std::vector<IPv6AddressData>& ipv6Data,
Ed Tanousbf648f72021-06-03 15:00:14 -07001743 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1744{
Ed Tanousbf648f72021-06-03 15:00:14 -07001745 size_t entryIdx = 1;
Ed Tanous77179532023-02-28 10:45:28 -08001746 std::vector<IPv6AddressData>::const_iterator nicIpEntry =
Ed Tanousbf648f72021-06-03 15:00:14 -07001747 getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend());
Ed Tanous3dfed532024-03-06 14:41:27 -08001748 for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
1749 input)
Ed Tanousbf648f72021-06-03 15:00:14 -07001750 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001751 std::string pathString =
1752 "IPv6StaticAddresses/" + std::to_string(entryIdx);
Ed Tanous3dfed532024-03-06 14:41:27 -08001753 nlohmann::json::object_t* obj =
1754 std::get_if<nlohmann::json::object_t>(&thisJson);
1755 if (obj != nullptr && !obj->empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001756 {
1757 std::optional<std::string> address;
1758 std::optional<uint8_t> prefixLength;
Ed Tanous3dfed532024-03-06 14:41:27 -08001759 nlohmann::json::object_t thisJsonCopy = *obj;
Myung Baeafc474a2024-10-09 00:53:29 -07001760 if (!json_util::readJsonObject( //
1761 thisJsonCopy, asyncResp->res, //
1762 "Address", address, //
1763 "PrefixLength", prefixLength //
1764 ))
Ed Tanousbf648f72021-06-03 15:00:14 -07001765 {
Ed Tanous3dfed532024-03-06 14:41:27 -08001766 messages::propertyValueFormatError(asyncResp->res, thisJsonCopy,
Ed Tanousf818b042022-06-27 13:17:35 -07001767 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001768 return;
1769 }
1770
Ed Tanousbf648f72021-06-03 15:00:14 -07001771 // Find the address and prefixLength values. Any values that are
1772 // not explicitly provided are assumed to be unmodified from the
1773 // current state of the interface. Merge existing state into the
1774 // current request.
Ed Tanousd547d8d2024-03-16 18:04:41 -07001775 if (!address)
Ed Tanousbf648f72021-06-03 15:00:14 -07001776 {
Ed Tanousd547d8d2024-03-16 18:04:41 -07001777 if (nicIpEntry == ipv6Data.end())
1778 {
1779 messages::propertyMissing(asyncResp->res,
1780 pathString + "/Address");
1781 return;
1782 }
1783 address = nicIpEntry->address;
Ed Tanousbf648f72021-06-03 15:00:14 -07001784 }
1785
Ed Tanousd547d8d2024-03-16 18:04:41 -07001786 if (!prefixLength)
Ed Tanousbf648f72021-06-03 15:00:14 -07001787 {
Ed Tanousd547d8d2024-03-16 18:04:41 -07001788 if (nicIpEntry == ipv6Data.end())
1789 {
1790 messages::propertyMissing(asyncResp->res,
1791 pathString + "/PrefixLength");
1792 return;
1793 }
1794 prefixLength = nicIpEntry->prefixLength;
Ed Tanousbf648f72021-06-03 15:00:14 -07001795 }
1796
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001797 if (nicIpEntry != ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001798 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001799 deleteAndCreateIPAddress(IpVersion::IpV6, ifaceId,
Ed Tanousd547d8d2024-03-16 18:04:41 -07001800 nicIpEntry->id, *prefixLength,
1801 *address, "", asyncResp);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001802 nicIpEntry =
1803 getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001804 }
1805 else
1806 {
Ed Tanousd547d8d2024-03-16 18:04:41 -07001807 createIPv6(ifaceId, *prefixLength, *address, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001808 }
1809 entryIdx++;
1810 }
1811 else
1812 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001813 if (nicIpEntry == ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001814 {
1815 // Requesting a DELETE/DO NOT MODIFY action for an item
1816 // that isn't present on the eth(n) interface. Input JSON is
1817 // in error, so bail out.
Ed Tanous3dfed532024-03-06 14:41:27 -08001818 if (obj == nullptr)
Ed Tanousbf648f72021-06-03 15:00:14 -07001819 {
1820 messages::resourceCannotBeDeleted(asyncResp->res);
1821 return;
1822 }
Ed Tanous3dfed532024-03-06 14:41:27 -08001823 messages::propertyValueFormatError(asyncResp->res, *obj,
Ed Tanousf818b042022-06-27 13:17:35 -07001824 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001825 return;
1826 }
1827
Ed Tanous3dfed532024-03-06 14:41:27 -08001828 if (obj == nullptr)
Ed Tanousbf648f72021-06-03 15:00:14 -07001829 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001830 deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001831 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001832 if (nicIpEntry != ipv6Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001833 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001834 nicIpEntry =
1835 getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001836 }
1837 entryIdx++;
1838 }
1839 }
1840}
1841
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001842inline std::string extractParentInterfaceName(const std::string& ifaceId)
1843{
1844 std::size_t pos = ifaceId.find('_');
1845 return ifaceId.substr(0, pos);
1846}
1847
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001848inline void parseInterfaceData(
1849 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1850 const std::string& ifaceId, const EthernetInterfaceData& ethData,
1851 const std::vector<IPv4AddressData>& ipv4Data,
1852 const std::vector<IPv6AddressData>& ipv6Data,
1853 const std::vector<StaticGatewayData>& ipv6GatewayData)
Ed Tanousbf648f72021-06-03 15:00:14 -07001854{
Ed Tanousbf648f72021-06-03 15:00:14 -07001855 nlohmann::json& jsonResponse = asyncResp->res.jsonValue;
1856 jsonResponse["Id"] = ifaceId;
Ed Tanous253f11b2024-05-16 09:38:31 -07001857 jsonResponse["@odata.id"] =
1858 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces/{}",
1859 BMCWEB_REDFISH_MANAGER_URI_NAME, ifaceId);
Ed Tanousbf648f72021-06-03 15:00:14 -07001860 jsonResponse["InterfaceEnabled"] = ethData.nicEnabled;
1861
Ed Tanousbf648f72021-06-03 15:00:14 -07001862 if (ethData.nicEnabled)
1863 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001864 jsonResponse["LinkStatus"] =
1865 ethData.linkUp ? ethernet_interface::LinkStatus::LinkUp
1866 : ethernet_interface::LinkStatus::LinkDown;
1867 jsonResponse["Status"]["State"] = resource::State::Enabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001868 }
1869 else
1870 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001871 jsonResponse["LinkStatus"] = ethernet_interface::LinkStatus::NoLink;
1872 jsonResponse["Status"]["State"] = resource::State::Disabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001873 }
1874
Ed Tanousbf648f72021-06-03 15:00:14 -07001875 jsonResponse["SpeedMbps"] = ethData.speed;
Tejas Patil35fb5312021-09-20 15:35:20 +05301876 jsonResponse["MTUSize"] = ethData.mtuSize;
Asmitha Karunanithi4652c642024-07-30 11:35:53 -05001877 if (ethData.macAddress)
1878 {
1879 jsonResponse["MACAddress"] = *ethData.macAddress;
1880 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001881 jsonResponse["DHCPv4"]["DHCPEnabled"] =
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001882 translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
Jishnu CMe4588152023-05-11 00:04:40 -05001883 jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpv4Enabled;
1884 jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsv4Enabled;
Ravi Tejade9ad762024-06-03 02:00:15 -05001885 jsonResponse["DHCPv4"]["UseDomainName"] = ethData.domainv4Enabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001886 jsonResponse["DHCPv6"]["OperatingMode"] =
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001887 translateDhcpEnabledToBool(ethData.dhcpEnabled, false)
1888 ? "Enabled"
1889 : "Disabled";
Jishnu CMe4588152023-05-11 00:04:40 -05001890 jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpv6Enabled;
1891 jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsv6Enabled;
Ravi Tejade9ad762024-06-03 02:00:15 -05001892 jsonResponse["DHCPv6"]["UseDomainName"] = ethData.domainv6Enabled;
Ravi Tejab10d8db2022-05-24 09:04:12 -05001893 jsonResponse["StatelessAddressAutoConfig"]["IPv6AutoConfigEnabled"] =
1894 ethData.ipv6AcceptRa;
Ed Tanousbf648f72021-06-03 15:00:14 -07001895
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001896 if (!ethData.hostName.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001897 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001898 jsonResponse["HostName"] = ethData.hostName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001899
1900 // When domain name is empty then it means, that it is a network
1901 // without domain names, and the host name itself must be treated as
1902 // FQDN
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001903 std::string fqdn = ethData.hostName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001904 if (!ethData.domainnames.empty())
1905 {
1906 fqdn += "." + ethData.domainnames[0];
1907 }
1908 jsonResponse["FQDN"] = fqdn;
1909 }
1910
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001911 if (ethData.vlanId)
1912 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001913 jsonResponse["EthernetInterfaceType"] =
1914 ethernet_interface::EthernetDeviceType::Virtual;
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001915 jsonResponse["VLAN"]["VLANEnable"] = true;
1916 jsonResponse["VLAN"]["VLANId"] = *ethData.vlanId;
1917 jsonResponse["VLAN"]["Tagged"] = true;
1918
1919 nlohmann::json::array_t relatedInterfaces;
1920 nlohmann::json& parentInterface = relatedInterfaces.emplace_back();
1921 parentInterface["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -07001922 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces",
1923 BMCWEB_REDFISH_MANAGER_URI_NAME,
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001924 extractParentInterfaceName(ifaceId));
1925 jsonResponse["Links"]["RelatedInterfaces"] =
1926 std::move(relatedInterfaces);
1927 }
1928 else
1929 {
Ed Tanous539d8c62024-06-19 14:38:27 -07001930 jsonResponse["EthernetInterfaceType"] =
1931 ethernet_interface::EthernetDeviceType::Physical;
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001932 }
1933
Ed Tanousbf648f72021-06-03 15:00:14 -07001934 jsonResponse["NameServers"] = ethData.nameServers;
1935 jsonResponse["StaticNameServers"] = ethData.staticNameServers;
1936
1937 nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"];
1938 nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
1939 ipv4Array = nlohmann::json::array();
1940 ipv4StaticArray = nlohmann::json::array();
Ed Tanous9eb808c2022-01-25 10:19:23 -08001941 for (const auto& ipv4Config : ipv4Data)
Ed Tanousbf648f72021-06-03 15:00:14 -07001942 {
Ed Tanousbf648f72021-06-03 15:00:14 -07001943 std::string gatewayStr = ipv4Config.gateway;
1944 if (gatewayStr.empty())
1945 {
1946 gatewayStr = "0.0.0.0";
1947 }
Ed Tanous14766872022-03-15 10:44:42 -07001948 nlohmann::json::object_t ipv4;
1949 ipv4["AddressOrigin"] = ipv4Config.origin;
1950 ipv4["SubnetMask"] = ipv4Config.netmask;
1951 ipv4["Address"] = ipv4Config.address;
1952 ipv4["Gateway"] = gatewayStr;
Ed Tanousbf648f72021-06-03 15:00:14 -07001953
Ed Tanousbf648f72021-06-03 15:00:14 -07001954 if (ipv4Config.origin == "Static")
1955 {
Ed Tanous14766872022-03-15 10:44:42 -07001956 ipv4StaticArray.push_back(ipv4);
Ed Tanousbf648f72021-06-03 15:00:14 -07001957 }
Ed Tanous14766872022-03-15 10:44:42 -07001958
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001959 ipv4Array.emplace_back(std::move(ipv4));
Ed Tanousbf648f72021-06-03 15:00:14 -07001960 }
1961
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001962 std::string ipv6GatewayStr = ethData.ipv6DefaultGateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001963 if (ipv6GatewayStr.empty())
1964 {
1965 ipv6GatewayStr = "0:0:0:0:0:0:0:0";
1966 }
1967
1968 jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr;
1969
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001970 nlohmann::json::array_t ipv6StaticGatewayArray;
1971 for (const auto& ipv6GatewayConfig : ipv6GatewayData)
1972 {
1973 nlohmann::json::object_t ipv6Gateway;
1974 ipv6Gateway["Address"] = ipv6GatewayConfig.gateway;
Sunitha Harishce73d5c2023-04-07 06:46:49 -05001975 ipv6StaticGatewayArray.emplace_back(std::move(ipv6Gateway));
1976 }
1977 jsonResponse["IPv6StaticDefaultGateways"] =
1978 std::move(ipv6StaticGatewayArray);
1979
Ed Tanousbf648f72021-06-03 15:00:14 -07001980 nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"];
1981 nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"];
1982 ipv6Array = nlohmann::json::array();
1983 ipv6StaticArray = nlohmann::json::array();
1984 nlohmann::json& ipv6AddrPolicyTable =
1985 jsonResponse["IPv6AddressPolicyTable"];
1986 ipv6AddrPolicyTable = nlohmann::json::array();
Ed Tanous9eb808c2022-01-25 10:19:23 -08001987 for (const auto& ipv6Config : ipv6Data)
Ed Tanousbf648f72021-06-03 15:00:14 -07001988 {
Ed Tanous14766872022-03-15 10:44:42 -07001989 nlohmann::json::object_t ipv6;
1990 ipv6["Address"] = ipv6Config.address;
1991 ipv6["PrefixLength"] = ipv6Config.prefixLength;
1992 ipv6["AddressOrigin"] = ipv6Config.origin;
Sunitha Harishf8361272023-03-16 03:23:59 -05001993
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001994 ipv6Array.emplace_back(std::move(ipv6));
Ed Tanousbf648f72021-06-03 15:00:14 -07001995 if (ipv6Config.origin == "Static")
1996 {
Ed Tanous14766872022-03-15 10:44:42 -07001997 nlohmann::json::object_t ipv6Static;
1998 ipv6Static["Address"] = ipv6Config.address;
1999 ipv6Static["PrefixLength"] = ipv6Config.prefixLength;
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002000 ipv6StaticArray.emplace_back(std::move(ipv6Static));
Ed Tanousbf648f72021-06-03 15:00:14 -07002001 }
2002 }
2003}
2004
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002005inline void afterDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2006 const std::string& ifaceId,
2007 const boost::system::error_code& ec,
2008 const sdbusplus::message_t& m)
2009{
2010 if (!ec)
2011 {
2012 return;
2013 }
2014 const sd_bus_error* dbusError = m.get_error();
2015 if (dbusError == nullptr)
2016 {
2017 messages::internalError(asyncResp->res);
2018 return;
2019 }
Ed Tanous62598e32023-07-17 17:06:25 -07002020 BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002021
2022 if (std::string_view("org.freedesktop.DBus.Error.UnknownObject") ==
2023 dbusError->name)
2024 {
2025 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
2026 ifaceId);
2027 return;
2028 }
2029 if (std::string_view("org.freedesktop.DBus.Error.UnknownMethod") ==
2030 dbusError->name)
2031 {
2032 messages::resourceCannotBeDeleted(asyncResp->res);
2033 return;
2034 }
2035 messages::internalError(asyncResp->res);
2036}
2037
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002038inline void afterVlanCreate(
2039 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2040 const std::string& parentInterfaceUri, const std::string& vlanInterface,
2041 const boost::system::error_code& ec, const sdbusplus::message_t& m
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002042
2043)
2044{
2045 if (ec)
2046 {
2047 const sd_bus_error* dbusError = m.get_error();
2048 if (dbusError == nullptr)
2049 {
2050 messages::internalError(asyncResp->res);
2051 return;
2052 }
Ed Tanous62598e32023-07-17 17:06:25 -07002053 BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002054
2055 if (std::string_view(
2056 "xyz.openbmc_project.Common.Error.ResourceNotFound") ==
2057 dbusError->name)
2058 {
2059 messages::propertyValueNotInList(
2060 asyncResp->res, parentInterfaceUri,
2061 "Links/RelatedInterfaces/0/@odata.id");
2062 return;
2063 }
2064 if (std::string_view(
2065 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
2066 dbusError->name)
2067 {
2068 messages::resourceAlreadyExists(asyncResp->res, "EthernetInterface",
2069 "Id", vlanInterface);
2070 return;
2071 }
2072 messages::internalError(asyncResp->res);
2073 return;
2074 }
2075
Ed Tanous253f11b2024-05-16 09:38:31 -07002076 const boost::urls::url vlanInterfaceUri =
2077 boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces/{}",
2078 BMCWEB_REDFISH_MANAGER_URI_NAME, vlanInterface);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002079 asyncResp->res.addHeader("Location", vlanInterfaceUri.buffer());
2080}
2081
Ed Tanousbf648f72021-06-03 15:00:14 -07002082inline void requestEthernetInterfacesRoutes(App& app)
2083{
Ed Tanous253f11b2024-05-16 09:38:31 -07002084 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/")
Ed Tanoused398212021-06-09 17:05:54 -07002085 .privileges(redfish::privileges::getEthernetInterfaceCollection)
Ed Tanous14766872022-03-15 10:44:42 -07002086 .methods(boost::beast::http::verb::get)(
2087 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002088 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2089 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002090 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2091 {
2092 return;
2093 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002094
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002095 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2096 {
2097 messages::resourceNotFound(asyncResp->res, "Manager",
2098 managerId);
2099 return;
2100 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002101
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002102 asyncResp->res.jsonValue["@odata.type"] =
2103 "#EthernetInterfaceCollection.EthernetInterfaceCollection";
2104 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2105 "/redfish/v1/Managers/{}/EthernetInterfaces",
2106 BMCWEB_REDFISH_MANAGER_URI_NAME);
2107 asyncResp->res.jsonValue["Name"] =
2108 "Ethernet Network Interface Collection";
2109 asyncResp->res.jsonValue["Description"] =
2110 "Collection of EthernetInterfaces for this Manager";
2111
2112 // Get eth interface list, and call the below callback for JSON
2113 // preparation
2114 getEthernetIfaceList(
2115 [asyncResp](const bool& success,
2116 const std::vector<std::string>& ifaceList) {
2117 if (!success)
2118 {
2119 messages::internalError(asyncResp->res);
2120 return;
2121 }
2122
2123 nlohmann::json& ifaceArray =
2124 asyncResp->res.jsonValue["Members"];
2125 ifaceArray = nlohmann::json::array();
2126 for (const std::string& ifaceItem : ifaceList)
2127 {
2128 nlohmann::json::object_t iface;
2129 iface["@odata.id"] = boost::urls::format(
2130 "/redfish/v1/Managers/{}/EthernetInterfaces/{}",
2131 BMCWEB_REDFISH_MANAGER_URI_NAME, ifaceItem);
2132 ifaceArray.push_back(std::move(iface));
2133 }
2134
2135 asyncResp->res.jsonValue["Members@odata.count"] =
2136 ifaceArray.size();
2137 asyncResp->res.jsonValue["@odata.id"] =
2138 boost::urls::format(
2139 "/redfish/v1/Managers/{}/EthernetInterfaces",
Ed Tanous253f11b2024-05-16 09:38:31 -07002140 BMCWEB_REDFISH_MANAGER_URI_NAME);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002141 });
2142 });
Johnathan Mantey01784822019-06-18 12:44:21 -07002143
Ed Tanous253f11b2024-05-16 09:38:31 -07002144 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/")
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002145 .privileges(redfish::privileges::postEthernetInterfaceCollection)
2146 .methods(boost::beast::http::verb::post)(
2147 [&app](const crow::Request& req,
Ed Tanous253f11b2024-05-16 09:38:31 -07002148 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2149 const std::string& managerId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002150 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2151 {
2152 return;
2153 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002154
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002155 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2156 {
2157 messages::resourceNotFound(asyncResp->res, "Manager",
2158 managerId);
2159 return;
2160 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002161
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002162 bool vlanEnable = false;
2163 uint32_t vlanId = 0;
2164 std::vector<nlohmann::json::object_t> relatedInterfaces;
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002165
Myung Baeafc474a2024-10-09 00:53:29 -07002166 if (!json_util::readJsonPatch( //
2167 req, asyncResp->res, //
2168 "Links/RelatedInterfaces", relatedInterfaces, //
2169 "VLAN/VLANEnable", vlanEnable, //
2170 "VLAN/VLANId", vlanId //
2171 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002172 {
2173 return;
2174 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002175
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002176 if (relatedInterfaces.size() != 1)
2177 {
2178 messages::arraySizeTooLong(asyncResp->res,
2179 "Links/RelatedInterfaces",
2180 relatedInterfaces.size());
2181 return;
2182 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002183
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002184 std::string parentInterfaceUri;
2185 if (!json_util::readJsonObject(relatedInterfaces[0],
2186 asyncResp->res, "@odata.id",
2187 parentInterfaceUri))
2188 {
2189 messages::propertyMissing(
2190 asyncResp->res, "Links/RelatedInterfaces/0/@odata.id");
2191 return;
2192 }
2193 BMCWEB_LOG_INFO("Parent Interface URI: {}", parentInterfaceUri);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002194
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002195 boost::system::result<boost::urls::url_view> parsedUri =
2196 boost::urls::parse_relative_ref(parentInterfaceUri);
2197 if (!parsedUri)
2198 {
2199 messages::propertyValueFormatError(
2200 asyncResp->res, parentInterfaceUri,
2201 "Links/RelatedInterfaces/0/@odata.id");
2202 return;
2203 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002204
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002205 std::string parentInterface;
2206 if (!crow::utility::readUrlSegments(
2207 *parsedUri, "redfish", "v1", "Managers", "bmc",
2208 "EthernetInterfaces", std::ref(parentInterface)))
2209 {
2210 messages::propertyValueNotInList(
2211 asyncResp->res, parentInterfaceUri,
2212 "Links/RelatedInterfaces/0/@odata.id");
2213 return;
2214 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002215
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002216 if (!vlanEnable)
2217 {
2218 // In OpenBMC implementation, VLANEnable cannot be false on
2219 // create
2220 messages::propertyValueIncorrect(
2221 asyncResp->res, "VLAN/VLANEnable", "false");
2222 return;
2223 }
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002224
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002225 std::string vlanInterface =
2226 parentInterface + "_" + std::to_string(vlanId);
2227 crow::connections::systemBus->async_method_call(
2228 [asyncResp, parentInterfaceUri,
2229 vlanInterface](const boost::system::error_code& ec,
2230 const sdbusplus::message_t& m) {
2231 afterVlanCreate(asyncResp, parentInterfaceUri,
2232 vlanInterface, ec, m);
2233 },
2234 "xyz.openbmc_project.Network",
2235 "/xyz/openbmc_project/network",
2236 "xyz.openbmc_project.Network.VLAN.Create", "VLAN",
2237 parentInterface, vlanId);
2238 });
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08002239
Ed Tanous253f11b2024-05-16 09:38:31 -07002240 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002241 .privileges(redfish::privileges::getEthernetInterface)
Ed Tanousbf648f72021-06-03 15:00:14 -07002242 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002243 [&app](const crow::Request& req,
2244 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002245 const std::string& managerId, const std::string& ifaceId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002246 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2247 {
2248 return;
2249 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002250
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002251 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2252 {
2253 messages::resourceNotFound(asyncResp->res, "Manager",
2254 managerId);
2255 return;
2256 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002257
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002258 getEthernetIfaceData(
2259 ifaceId,
2260 [asyncResp, ifaceId](
2261 const bool& success,
2262 const EthernetInterfaceData& ethData,
2263 const std::vector<IPv4AddressData>& ipv4Data,
2264 const std::vector<IPv6AddressData>& ipv6Data,
2265 const std::vector<StaticGatewayData>& ipv6GatewayData) {
2266 if (!success)
2267 {
2268 // TODO(Pawel)consider distinguish between non
2269 // existing object, and other errors
2270 messages::resourceNotFound(
2271 asyncResp->res, "EthernetInterface", ifaceId);
2272 return;
2273 }
Johnathan Mantey01784822019-06-18 12:44:21 -07002274
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002275 asyncResp->res.jsonValue["@odata.type"] =
2276 "#EthernetInterface.v1_9_0.EthernetInterface";
2277 asyncResp->res.jsonValue["Name"] =
2278 "Manager Ethernet Interface";
2279 asyncResp->res.jsonValue["Description"] =
2280 "Management Network Interface";
Ratan Guptaf476acb2019-03-02 16:46:57 +05302281
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002282 parseInterfaceData(asyncResp, ifaceId, ethData,
2283 ipv4Data, ipv6Data, ipv6GatewayData);
2284 });
2285 });
Johnathan Mantey01784822019-06-18 12:44:21 -07002286
Ed Tanous253f11b2024-05-16 09:38:31 -07002287 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002288 .privileges(redfish::privileges::patchEthernetInterface)
Ed Tanousbf648f72021-06-03 15:00:14 -07002289 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002290 [&app](const crow::Request& req,
2291 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002292 const std::string& managerId, const std::string& ifaceId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002293 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2294 {
2295 return;
2296 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002297
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002298 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2299 {
2300 messages::resourceNotFound(asyncResp->res, "Manager",
2301 managerId);
2302 return;
2303 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002304
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002305 std::optional<std::string> hostname;
2306 std::optional<std::string> fqdn;
2307 std::optional<std::string> macAddress;
2308 std::optional<std::string> ipv6DefaultGateway;
2309 std::optional<std::vector<
2310 std::variant<nlohmann::json::object_t, std::nullptr_t>>>
2311 ipv4StaticAddresses;
2312 std::optional<std::vector<
2313 std::variant<nlohmann::json::object_t, std::nullptr_t>>>
2314 ipv6StaticAddresses;
2315 std::optional<std::vector<
2316 std::variant<nlohmann::json::object_t, std::nullptr_t>>>
2317 ipv6StaticDefaultGateways;
2318 std::optional<std::vector<std::string>> staticNameServers;
2319 std::optional<bool> ipv6AutoConfigEnabled;
2320 std::optional<bool> interfaceEnabled;
2321 std::optional<size_t> mtuSize;
2322 DHCPParameters v4dhcpParms;
2323 DHCPParameters v6dhcpParms;
Myung Baeafc474a2024-10-09 00:53:29 -07002324
2325 if (!json_util::readJsonPatch( //
2326 req, asyncResp->res, //
2327 "DHCPv4/DHCPEnabled", v4dhcpParms.dhcpv4Enabled, //
2328 "DHCPv4/UseDNSServers", v4dhcpParms.useDnsServers, //
2329 "DHCPv4/UseDomainName", v4dhcpParms.useDomainName, //
2330 "DHCPv4/UseNTPServers", v4dhcpParms.useNtpServers, //
2331 "DHCPv6/OperatingMode",
2332 v6dhcpParms.dhcpv6OperatingMode, //
2333 "DHCPv6/UseDNSServers", v6dhcpParms.useDnsServers, //
2334 "DHCPv6/UseDomainName", v6dhcpParms.useDomainName, //
2335 "DHCPv6/UseNTPServers", v6dhcpParms.useNtpServers, //
2336 "FQDN", fqdn, //
2337 "HostName", hostname, //
2338 "InterfaceEnabled", interfaceEnabled, //
2339 "IPv4StaticAddresses", ipv4StaticAddresses, //
2340 "IPv6DefaultGateway", ipv6DefaultGateway, //
2341 "IPv6StaticAddresses", ipv6StaticAddresses, //
2342 "IPv6StaticDefaultGateways",
2343 ipv6StaticDefaultGateways, //
2344 "InterfaceEnabled", interfaceEnabled, //
2345 "MACAddress", macAddress, //
2346 "MTUSize", mtuSize, //
2347 "StatelessAddressAutoConfig/IPv6AutoConfigEnabled",
2348 ipv6AutoConfigEnabled, //
2349 "StaticNameServers", staticNameServers //
2350 ))
2351 {
2352 return;
2353 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -05002354
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002355 // Get single eth interface data, and call the below callback
2356 // for JSON preparation
2357 getEthernetIfaceData(
2358 ifaceId,
2359 [asyncResp, ifaceId, hostname = std::move(hostname),
2360 fqdn = std::move(fqdn), macAddress = std::move(macAddress),
2361 ipv4StaticAddresses = std::move(ipv4StaticAddresses),
2362 ipv6DefaultGateway = std::move(ipv6DefaultGateway),
2363 ipv6StaticAddresses = std::move(ipv6StaticAddresses),
2364 ipv6StaticDefaultGateway =
2365 std::move(ipv6StaticDefaultGateways),
2366 staticNameServers = std::move(staticNameServers), mtuSize,
2367 ipv6AutoConfigEnabled,
2368 v4dhcpParms = std::move(v4dhcpParms),
2369 v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled](
2370 const bool success,
2371 const EthernetInterfaceData& ethData,
2372 const std::vector<IPv4AddressData>& ipv4Data,
2373 const std::vector<IPv6AddressData>& ipv6Data,
2374 const std::vector<StaticGatewayData>&
2375 ipv6GatewayData) mutable {
2376 if (!success)
2377 {
2378 // ... otherwise return error
2379 // TODO(Pawel)consider distinguish between non
2380 // existing object, and other errors
2381 messages::resourceNotFound(
2382 asyncResp->res, "EthernetInterface", ifaceId);
2383 return;
2384 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -05002385
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002386 handleDHCPPatch(ifaceId, ethData, v4dhcpParms,
2387 v6dhcpParms, asyncResp);
Tejas Patil35fb5312021-09-20 15:35:20 +05302388
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002389 if (hostname)
2390 {
2391 handleHostnamePatch(*hostname, asyncResp);
2392 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002393
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002394 if (ipv6AutoConfigEnabled)
2395 {
2396 handleSLAACAutoConfigPatch(
2397 ifaceId, *ipv6AutoConfigEnabled, asyncResp);
2398 }
Ravi Tejab10d8db2022-05-24 09:04:12 -05002399
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002400 if (fqdn)
2401 {
2402 handleFqdnPatch(ifaceId, *fqdn, asyncResp);
2403 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002404
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002405 if (macAddress)
2406 {
2407 handleMACAddressPatch(ifaceId, *macAddress,
2408 asyncResp);
2409 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002410
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002411 if (ipv4StaticAddresses)
2412 {
2413 handleIPv4StaticPatch(ifaceId, *ipv4StaticAddresses,
2414 ethData, ipv4Data, asyncResp);
2415 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002416
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002417 if (staticNameServers)
2418 {
2419 handleStaticNameServersPatch(
2420 ifaceId, *staticNameServers, asyncResp);
2421 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002422
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002423 if (ipv6DefaultGateway)
2424 {
2425 messages::propertyNotWritable(asyncResp->res,
2426 "IPv6DefaultGateway");
2427 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002428
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002429 if (ipv6StaticAddresses)
2430 {
2431 handleIPv6StaticAddressesPatch(ifaceId,
2432 *ipv6StaticAddresses,
2433 ipv6Data, asyncResp);
2434 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002435
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002436 if (ipv6StaticDefaultGateway)
2437 {
2438 handleIPv6DefaultGateway(
2439 ifaceId, *ipv6StaticDefaultGateway,
2440 ipv6GatewayData, asyncResp);
2441 }
Sunitha Harishce73d5c2023-04-07 06:46:49 -05002442
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002443 if (interfaceEnabled)
2444 {
2445 setDbusProperty(
2446 asyncResp, "InterfaceEnabled",
Ginu Georgee93abac2024-06-14 17:35:27 +05302447 "xyz.openbmc_project.Network",
Ed Tanousd02aad32024-02-13 14:43:34 -08002448 sdbusplus::message::object_path(
2449 "/xyz/openbmc_project/network") /
2450 ifaceId,
2451 "xyz.openbmc_project.Network.EthernetInterface",
Ginu Georgee93abac2024-06-14 17:35:27 +05302452 "NICEnabled", *interfaceEnabled);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002453 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002454
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002455 if (mtuSize)
2456 {
2457 handleMTUSizePatch(ifaceId, *mtuSize, asyncResp);
2458 }
2459 });
2460 });
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002461
Ed Tanous253f11b2024-05-16 09:38:31 -07002462 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002463 .privileges(redfish::privileges::deleteEthernetInterface)
2464 .methods(boost::beast::http::verb::delete_)(
2465 [&app](const crow::Request& req,
2466 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -07002467 const std::string& managerId, const std::string& ifaceId) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002468 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2469 {
2470 return;
2471 }
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002472
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002473 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2474 {
2475 messages::resourceNotFound(asyncResp->res, "Manager",
2476 managerId);
2477 return;
2478 }
Ed Tanous253f11b2024-05-16 09:38:31 -07002479
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002480 crow::connections::systemBus->async_method_call(
2481 [asyncResp, ifaceId](const boost::system::error_code& ec,
2482 const sdbusplus::message_t& m) {
2483 afterDelete(asyncResp, ifaceId, ec, m);
2484 },
2485 "xyz.openbmc_project.Network",
2486 std::string("/xyz/openbmc_project/network/") + ifaceId,
2487 "xyz.openbmc_project.Object.Delete", "Delete");
2488 });
Ed Tanousbf648f72021-06-03 15:00:14 -07002489}
2490
Ed Tanous1abe55e2018-09-05 08:30:59 -07002491} // namespace redfish