blob: 218affef395b9a96928bd598c55dfd1159d6914d [file] [log] [blame]
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +01001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Willy Tu13451e32023-05-24 16:08:18 -070018#include "bmcweb_config.h"
19
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "app.hpp"
21#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080022#include "dbus_utility.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "error_messages.hpp"
24#include "health.hpp"
Ed Tanous2c5875a2023-05-15 09:56:06 -070025#include "human_sort.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080026#include "query.hpp"
27#include "registries/privilege_registry.hpp"
Ed Tanous033f1e42022-08-15 09:47:37 -070028#include "utils/ip_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080029#include "utils/json_utils.hpp"
Ed Tanous033f1e42022-08-15 09:47:37 -070030
Ed Tanous11ba3972022-07-11 09:50:41 -070031#include <boost/algorithm/string/classification.hpp>
32#include <boost/algorithm/string/split.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070033#include <boost/url/format.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050034
George Liu7a1dbc42022-12-07 16:03:22 +080035#include <array>
Ed Tanousa24526d2018-12-10 15:17:59 -080036#include <optional>
Joshi-Mansiab6554f2020-03-10 18:33:36 +053037#include <regex>
George Liu7a1dbc42022-12-07 16:03:22 +080038#include <string_view>
Ed Tanous77179532023-02-28 10:45:28 -080039#include <vector>
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010040
Ed Tanous1abe55e2018-09-05 08:30:59 -070041namespace redfish
42{
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010043
Ed Tanous4a0cb852018-10-15 07:55:04 -070044enum class LinkType
45{
46 Local,
47 Global
48};
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010049
50/**
51 * Structure for keeping IPv4 data required by Redfish
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010052 */
Ed Tanous1abe55e2018-09-05 08:30:59 -070053struct IPv4AddressData
54{
55 std::string id;
Ed Tanous4a0cb852018-10-15 07:55:04 -070056 std::string address;
57 std::string domain;
58 std::string gateway;
Ed Tanous1abe55e2018-09-05 08:30:59 -070059 std::string netmask;
60 std::string origin;
Ed Tanous77179532023-02-28 10:45:28 -080061 LinkType linktype{};
62 bool isActive{};
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010063};
64
65/**
Ravi Tejae48c0fc2019-04-16 08:37:20 -050066 * Structure for keeping IPv6 data required by Redfish
67 */
68struct IPv6AddressData
69{
70 std::string id;
71 std::string address;
72 std::string origin;
Ed Tanous77179532023-02-28 10:45:28 -080073 uint8_t prefixLength = 0;
Ravi Tejae48c0fc2019-04-16 08:37:20 -050074};
75/**
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010076 * Structure for keeping basic single Ethernet Interface information
77 * available from DBus
78 */
Ed Tanous1abe55e2018-09-05 08:30:59 -070079struct EthernetInterfaceData
80{
Ed Tanous4a0cb852018-10-15 07:55:04 -070081 uint32_t speed;
Tejas Patil35fb5312021-09-20 15:35:20 +053082 size_t mtuSize;
Jiaqing Zhao82695a52022-04-14 15:15:59 +080083 bool autoNeg;
84 bool dnsEnabled;
85 bool ntpEnabled;
86 bool hostNameEnabled;
Johnathan Manteyaa05fb22020-01-08 12:08:44 -080087 bool linkUp;
Johnathan Manteyeeedda22019-10-29 16:09:52 -070088 bool nicEnabled;
Jiaqing Zhao82695a52022-04-14 15:15:59 +080089 std::string dhcpEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -070090 std::string operatingMode;
Jiaqing Zhao82695a52022-04-14 15:15:59 +080091 std::string hostName;
92 std::string defaultGateway;
93 std::string ipv6DefaultGateway;
94 std::string macAddress;
Jiaqing Zhao17e22022022-04-14 18:58:06 +080095 std::optional<uint32_t> vlanId;
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -050096 std::vector<std::string> nameServers;
97 std::vector<std::string> staticNameServers;
Jennifer Leed24bfc72019-03-05 13:03:37 -080098 std::vector<std::string> domainnames;
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +010099};
100
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700101struct DHCPParameters
102{
103 std::optional<bool> dhcpv4Enabled;
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800104 std::optional<bool> useDnsServers;
105 std::optional<bool> useNtpServers;
106 std::optional<bool> useDomainName;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700107 std::optional<std::string> dhcpv6OperatingMode;
108};
109
Ed Tanous4a0cb852018-10-15 07:55:04 -0700110// Helper function that changes bits netmask notation (i.e. /24)
111// into full dot notation
112inline std::string getNetmask(unsigned int bits)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700113{
Ed Tanous4a0cb852018-10-15 07:55:04 -0700114 uint32_t value = 0xffffffff << (32 - bits);
115 std::string netmask = std::to_string((value >> 24) & 0xff) + "." +
116 std::to_string((value >> 16) & 0xff) + "." +
117 std::to_string((value >> 8) & 0xff) + "." +
118 std::to_string(value & 0xff);
119 return netmask;
120}
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +0100121
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800122inline bool translateDhcpEnabledToBool(const std::string& inputDHCP,
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700123 bool isIPv4)
124{
125 if (isIPv4)
126 {
127 return (
128 (inputDHCP ==
129 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4") ||
130 (inputDHCP ==
131 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
132 }
133 return ((inputDHCP ==
134 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") ||
135 (inputDHCP ==
136 "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
137}
138
Ed Tanous2c70f802020-09-28 14:29:23 -0700139inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700140{
141 if (isIPv4 && isIPv6)
142 {
143 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both";
144 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700145 if (isIPv4)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700146 {
147 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4";
148 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700149 if (isIPv6)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700150 {
151 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6";
152 }
153 return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none";
154}
155
Ed Tanous4a0cb852018-10-15 07:55:04 -0700156inline std::string
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500157 translateAddressOriginDbusToRedfish(const std::string& inputOrigin,
Ed Tanous4a0cb852018-10-15 07:55:04 -0700158 bool isIPv4)
159{
160 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700161 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700162 return "Static";
163 }
164 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal")
165 {
166 if (isIPv4)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700167 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700168 return "IPv4LinkLocal";
169 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700170 return "LinkLocal";
Ed Tanous4a0cb852018-10-15 07:55:04 -0700171 }
172 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
173 {
174 if (isIPv4)
175 {
176 return "DHCP";
177 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700178 return "DHCPv6";
Ed Tanous4a0cb852018-10-15 07:55:04 -0700179 }
180 if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC")
181 {
182 return "SLAAC";
183 }
184 return "";
185}
186
Ed Tanous02cad962022-06-30 16:50:15 -0700187inline bool extractEthernetInterfaceData(
188 const std::string& ethifaceId,
189 const dbus::utility::ManagedObjectType& dbusData,
190 EthernetInterfaceData& ethData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700191{
Ed Tanous4c9afe42019-05-03 16:59:57 -0700192 bool idFound = false;
Ed Tanous02cad962022-06-30 16:50:15 -0700193 for (const auto& objpath : dbusData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700194 {
Ed Tanous02cad962022-06-30 16:50:15 -0700195 for (const auto& ifacePair : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700196 {
Ed Tanous81ce6092020-12-17 16:54:55 +0000197 if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700198 {
Ed Tanous4c9afe42019-05-03 16:59:57 -0700199 idFound = true;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700200 if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700201 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500202 for (const auto& propertyPair : ifacePair.second)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700203 {
Ed Tanous4a0cb852018-10-15 07:55:04 -0700204 if (propertyPair.first == "MACAddress")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700205 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500206 const std::string* mac =
Ed Tanousabf2add2019-01-22 16:40:12 -0800207 std::get_if<std::string>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700208 if (mac != nullptr)
209 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800210 ethData.macAddress = *mac;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700211 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700212 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700213 }
214 }
215 else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN")
216 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500217 for (const auto& propertyPair : ifacePair.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700218 {
219 if (propertyPair.first == "Id")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700220 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500221 const uint32_t* id =
Ed Tanousabf2add2019-01-22 16:40:12 -0800222 std::get_if<uint32_t>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700223 if (id != nullptr)
224 {
Jiaqing Zhao17e22022022-04-14 18:58:06 +0800225 ethData.vlanId = *id;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700226 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700227 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700228 }
229 }
230 else if (ifacePair.first ==
231 "xyz.openbmc_project.Network.EthernetInterface")
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 == "AutoNeg")
236 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700237 const bool* autoNeg =
Ed Tanousabf2add2019-01-22 16:40:12 -0800238 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700239 if (autoNeg != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700240 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800241 ethData.autoNeg = *autoNeg;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700242 }
243 }
244 else if (propertyPair.first == "Speed")
245 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500246 const uint32_t* speed =
Ed Tanousabf2add2019-01-22 16:40:12 -0800247 std::get_if<uint32_t>(&propertyPair.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700248 if (speed != nullptr)
249 {
250 ethData.speed = *speed;
251 }
252 }
Tejas Patil35fb5312021-09-20 15:35:20 +0530253 else if (propertyPair.first == "MTU")
254 {
255 const uint32_t* mtuSize =
256 std::get_if<uint32_t>(&propertyPair.second);
257 if (mtuSize != nullptr)
258 {
259 ethData.mtuSize = *mtuSize;
260 }
261 }
Johnathan Manteyaa05fb22020-01-08 12:08:44 -0800262 else if (propertyPair.first == "LinkUp")
263 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500264 const bool* linkUp =
Johnathan Manteyaa05fb22020-01-08 12:08:44 -0800265 std::get_if<bool>(&propertyPair.second);
266 if (linkUp != nullptr)
267 {
268 ethData.linkUp = *linkUp;
269 }
270 }
Johnathan Manteyeeedda22019-10-29 16:09:52 -0700271 else if (propertyPair.first == "NICEnabled")
272 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500273 const bool* nicEnabled =
Johnathan Manteyeeedda22019-10-29 16:09:52 -0700274 std::get_if<bool>(&propertyPair.second);
275 if (nicEnabled != nullptr)
276 {
277 ethData.nicEnabled = *nicEnabled;
278 }
279 }
RAJESWARAN THILLAIGOVINDANf85837b2019-04-04 05:18:53 -0500280 else if (propertyPair.first == "Nameservers")
Ed Tanous4a0cb852018-10-15 07:55:04 -0700281 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500282 const std::vector<std::string>* nameservers =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500283 std::get_if<std::vector<std::string>>(
Ed Tanous029573d2019-02-01 10:57:49 -0800284 &propertyPair.second);
285 if (nameservers != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700286 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700287 ethData.nameServers = *nameservers;
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -0500288 }
289 }
290 else if (propertyPair.first == "StaticNameServers")
291 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500292 const std::vector<std::string>* staticNameServers =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500293 std::get_if<std::vector<std::string>>(
manojkiran.eda@gmail.com0f6efdc2019-10-03 04:53:44 -0500294 &propertyPair.second);
295 if (staticNameServers != nullptr)
296 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700297 ethData.staticNameServers = *staticNameServers;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700298 }
299 }
manojkiraneda2a133282019-02-19 13:09:43 +0530300 else if (propertyPair.first == "DHCPEnabled")
301 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700302 const std::string* dhcpEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700303 std::get_if<std::string>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700304 if (dhcpEnabled != nullptr)
manojkiraneda2a133282019-02-19 13:09:43 +0530305 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800306 ethData.dhcpEnabled = *dhcpEnabled;
manojkiraneda2a133282019-02-19 13:09:43 +0530307 }
308 }
Jennifer Leed24bfc72019-03-05 13:03:37 -0800309 else if (propertyPair.first == "DomainName")
310 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500311 const std::vector<std::string>* domainNames =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500312 std::get_if<std::vector<std::string>>(
Jennifer Leed24bfc72019-03-05 13:03:37 -0800313 &propertyPair.second);
314 if (domainNames != nullptr)
315 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700316 ethData.domainnames = *domainNames;
Jennifer Leed24bfc72019-03-05 13:03:37 -0800317 }
318 }
Ravi Teja9010ec22019-08-01 23:30:25 -0500319 else if (propertyPair.first == "DefaultGateway")
320 {
321 const std::string* defaultGateway =
322 std::get_if<std::string>(&propertyPair.second);
323 if (defaultGateway != nullptr)
324 {
325 std::string defaultGatewayStr = *defaultGateway;
326 if (defaultGatewayStr.empty())
327 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800328 ethData.defaultGateway = "0.0.0.0";
Ravi Teja9010ec22019-08-01 23:30:25 -0500329 }
330 else
331 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800332 ethData.defaultGateway = defaultGatewayStr;
Ravi Teja9010ec22019-08-01 23:30:25 -0500333 }
334 }
335 }
336 else if (propertyPair.first == "DefaultGateway6")
337 {
338 const std::string* defaultGateway6 =
339 std::get_if<std::string>(&propertyPair.second);
340 if (defaultGateway6 != nullptr)
341 {
342 std::string defaultGateway6Str =
343 *defaultGateway6;
344 if (defaultGateway6Str.empty())
345 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800346 ethData.ipv6DefaultGateway =
Ravi Teja9010ec22019-08-01 23:30:25 -0500347 "0:0:0:0:0:0:0:0";
348 }
349 else
350 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800351 ethData.ipv6DefaultGateway =
Ravi Teja9010ec22019-08-01 23:30:25 -0500352 defaultGateway6Str;
353 }
354 }
355 }
Ed Tanous029573d2019-02-01 10:57:49 -0800356 }
357 }
358 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700359
Jian Zhang1e3f85e2022-12-13 13:50:35 +0800360 if (objpath.first == "/xyz/openbmc_project/network/dhcp")
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700361 {
362 if (ifacePair.first ==
363 "xyz.openbmc_project.Network.DHCPConfiguration")
364 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500365 for (const auto& propertyPair : ifacePair.second)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700366 {
367 if (propertyPair.first == "DNSEnabled")
368 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700369 const bool* dnsEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700370 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700371 if (dnsEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700372 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800373 ethData.dnsEnabled = *dnsEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700374 }
375 }
376 else if (propertyPair.first == "NTPEnabled")
377 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700378 const bool* ntpEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700379 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700380 if (ntpEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700381 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800382 ethData.ntpEnabled = *ntpEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700383 }
384 }
385 else if (propertyPair.first == "HostNameEnabled")
386 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700387 const bool* hostNameEnabled =
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700388 std::get_if<bool>(&propertyPair.second);
Ed Tanous2c70f802020-09-28 14:29:23 -0700389 if (hostNameEnabled != nullptr)
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700390 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800391 ethData.hostNameEnabled = *hostNameEnabled;
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700392 }
393 }
Johnathan Mantey1f8c7b52019-06-18 12:44:21 -0700394 }
395 }
396 }
Ed Tanous029573d2019-02-01 10:57:49 -0800397 // System configuration shows up in the global namespace, so no need
398 // to check eth number
399 if (ifacePair.first ==
400 "xyz.openbmc_project.Network.SystemConfiguration")
401 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500402 for (const auto& propertyPair : ifacePair.second)
Ed Tanous029573d2019-02-01 10:57:49 -0800403 {
404 if (propertyPair.first == "HostName")
405 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500406 const std::string* hostname =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500407 std::get_if<std::string>(&propertyPair.second);
Ed Tanous029573d2019-02-01 10:57:49 -0800408 if (hostname != nullptr)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700409 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +0800410 ethData.hostName = *hostname;
Ed Tanous029573d2019-02-01 10:57:49 -0800411 }
412 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700413 }
414 }
415 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700416 }
Ed Tanous4c9afe42019-05-03 16:59:57 -0700417 return idFound;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700418}
419
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500420// Helper function that extracts data for single ethernet ipv6 address
Ed Tanous77179532023-02-28 10:45:28 -0800421inline void extractIPV6Data(const std::string& ethifaceId,
422 const dbus::utility::ManagedObjectType& dbusData,
423 std::vector<IPv6AddressData>& ipv6Config)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500424{
Patrick Williams89492a12023-05-10 07:51:34 -0500425 const std::string ipPathStart = "/xyz/openbmc_project/network/" +
426 ethifaceId;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500427
428 // Since there might be several IPv6 configurations aligned with
429 // single ethernet interface, loop over all of them
Ed Tanous81ce6092020-12-17 16:54:55 +0000430 for (const auto& objpath : dbusData)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500431 {
432 // Check if proper pattern for object path appears
Tony Lee353163e2022-11-23 11:06:10 +0800433 if (objpath.first.str.starts_with(ipPathStart + "/"))
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500434 {
Ed Tanous9eb808c2022-01-25 10:19:23 -0800435 for (const auto& interface : objpath.second)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500436 {
437 if (interface.first == "xyz.openbmc_project.Network.IP")
438 {
Tony Lee353163e2022-11-23 11:06:10 +0800439 auto type = std::find_if(interface.second.begin(),
440 interface.second.end(),
441 [](const auto& property) {
442 return property.first == "Type";
443 });
444 if (type == interface.second.end())
445 {
446 continue;
447 }
448
449 const std::string* typeStr =
450 std::get_if<std::string>(&type->second);
451
452 if (typeStr == nullptr ||
453 (*typeStr !=
454 "xyz.openbmc_project.Network.IP.Protocol.IPv6"))
455 {
456 continue;
457 }
458
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500459 // Instance IPv6AddressData structure, and set as
460 // appropriate
Ed Tanous77179532023-02-28 10:45:28 -0800461 IPv6AddressData& ipv6Address = ipv6Config.emplace_back();
Ed Tanous2c70f802020-09-28 14:29:23 -0700462 ipv6Address.id =
Tony Lee353163e2022-11-23 11:06:10 +0800463 objpath.first.str.substr(ipPathStart.size());
Ed Tanous9eb808c2022-01-25 10:19:23 -0800464 for (const auto& property : interface.second)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500465 {
466 if (property.first == "Address")
467 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500468 const std::string* address =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500469 std::get_if<std::string>(&property.second);
470 if (address != nullptr)
471 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700472 ipv6Address.address = *address;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500473 }
474 }
475 else if (property.first == "Origin")
476 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500477 const std::string* origin =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500478 std::get_if<std::string>(&property.second);
479 if (origin != nullptr)
480 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700481 ipv6Address.origin =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500482 translateAddressOriginDbusToRedfish(*origin,
483 false);
484 }
485 }
486 else if (property.first == "PrefixLength")
487 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500488 const uint8_t* prefix =
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500489 std::get_if<uint8_t>(&property.second);
490 if (prefix != nullptr)
491 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700492 ipv6Address.prefixLength = *prefix;
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500493 }
494 }
Asmitha Karunanithi889ff692021-11-29 08:43:30 -0600495 else if (property.first == "Type" ||
496 property.first == "Gateway")
497 {
498 // Type & Gateway is not used
499 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500500 else
501 {
Ed Tanous62598e32023-07-17 17:06:25 -0700502 BMCWEB_LOG_ERROR(
503 "Got extra property: {} on the {} object",
504 property.first, objpath.first.str);
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500505 }
506 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500507 }
508 }
509 }
510 }
511}
512
Ed Tanous4a0cb852018-10-15 07:55:04 -0700513// Helper function that extracts data for single ethernet ipv4 address
Ed Tanous77179532023-02-28 10:45:28 -0800514inline void extractIPData(const std::string& ethifaceId,
515 const dbus::utility::ManagedObjectType& dbusData,
516 std::vector<IPv4AddressData>& ipv4Config)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700517{
Patrick Williams89492a12023-05-10 07:51:34 -0500518 const std::string ipPathStart = "/xyz/openbmc_project/network/" +
519 ethifaceId;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700520
521 // Since there might be several IPv4 configurations aligned with
522 // single ethernet interface, loop over all of them
Ed Tanous81ce6092020-12-17 16:54:55 +0000523 for (const auto& objpath : dbusData)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700524 {
525 // Check if proper pattern for object path appears
Tony Lee353163e2022-11-23 11:06:10 +0800526 if (objpath.first.str.starts_with(ipPathStart + "/"))
Ed Tanous4a0cb852018-10-15 07:55:04 -0700527 {
Ed Tanous9eb808c2022-01-25 10:19:23 -0800528 for (const auto& interface : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700529 {
530 if (interface.first == "xyz.openbmc_project.Network.IP")
531 {
Tony Lee353163e2022-11-23 11:06:10 +0800532 auto type = std::find_if(interface.second.begin(),
533 interface.second.end(),
534 [](const auto& property) {
535 return property.first == "Type";
536 });
537 if (type == interface.second.end())
538 {
539 continue;
540 }
541
542 const std::string* typeStr =
543 std::get_if<std::string>(&type->second);
544
545 if (typeStr == nullptr ||
546 (*typeStr !=
547 "xyz.openbmc_project.Network.IP.Protocol.IPv4"))
548 {
549 continue;
550 }
551
Ed Tanous4a0cb852018-10-15 07:55:04 -0700552 // Instance IPv4AddressData structure, and set as
553 // appropriate
Ed Tanous77179532023-02-28 10:45:28 -0800554 IPv4AddressData& ipv4Address = ipv4Config.emplace_back();
Ed Tanous2c70f802020-09-28 14:29:23 -0700555 ipv4Address.id =
Tony Lee353163e2022-11-23 11:06:10 +0800556 objpath.first.str.substr(ipPathStart.size());
Ed Tanous9eb808c2022-01-25 10:19:23 -0800557 for (const auto& property : interface.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700558 {
559 if (property.first == "Address")
560 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500561 const std::string* address =
Ed Tanousabf2add2019-01-22 16:40:12 -0800562 std::get_if<std::string>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700563 if (address != nullptr)
564 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700565 ipv4Address.address = *address;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700566 }
567 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700568 else if (property.first == "Origin")
569 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500570 const std::string* origin =
Ed Tanousabf2add2019-01-22 16:40:12 -0800571 std::get_if<std::string>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700572 if (origin != nullptr)
573 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700574 ipv4Address.origin =
Ed Tanous4a0cb852018-10-15 07:55:04 -0700575 translateAddressOriginDbusToRedfish(*origin,
576 true);
577 }
578 }
579 else if (property.first == "PrefixLength")
580 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500581 const uint8_t* mask =
Ed Tanousabf2add2019-01-22 16:40:12 -0800582 std::get_if<uint8_t>(&property.second);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700583 if (mask != nullptr)
584 {
585 // convert it to the string
Ed Tanous2c70f802020-09-28 14:29:23 -0700586 ipv4Address.netmask = getNetmask(*mask);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700587 }
588 }
Asmitha Karunanithi889ff692021-11-29 08:43:30 -0600589 else if (property.first == "Type" ||
590 property.first == "Gateway")
591 {
592 // Type & Gateway is not used
593 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700594 else
595 {
Ed Tanous62598e32023-07-17 17:06:25 -0700596 BMCWEB_LOG_ERROR(
597 "Got extra property: {} on the {} object",
598 property.first, objpath.first.str);
Ed Tanous4a0cb852018-10-15 07:55:04 -0700599 }
600 }
601 // Check if given address is local, or global
Ed Tanous2c70f802020-09-28 14:29:23 -0700602 ipv4Address.linktype =
Ed Tanous11ba3972022-07-11 09:50:41 -0700603 ipv4Address.address.starts_with("169.254.")
Johnathan Mantey18659d12019-06-07 10:26:29 -0700604 ? LinkType::Local
605 : LinkType::Global;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700606 }
607 }
608 }
609 }
610}
611
612/**
Johnathan Mantey01784822019-06-18 12:44:21 -0700613 * @brief Deletes given IPv4 interface
Ed Tanous4a0cb852018-10-15 07:55:04 -0700614 *
615 * @param[in] ifaceId Id of interface whose IP should be deleted
Ed Tanous4a0cb852018-10-15 07:55:04 -0700616 * @param[in] ipHash DBus Hash id of IP that should be deleted
617 * @param[io] asyncResp Response object that will be returned to client
618 *
619 * @return None
620 */
Ravi Teja9c5e5852023-02-26 21:33:52 -0600621inline void deleteIPAddress(const std::string& ifaceId,
622 const std::string& ipHash,
623 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700624{
625 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800626 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700627 if (ec)
628 {
629 messages::internalError(asyncResp->res);
630 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700631 },
632 "xyz.openbmc_project.Network",
Ravi Teja9c5e5852023-02-26 21:33:52 -0600633 "/xyz/openbmc_project/network/" + ifaceId + ipHash,
Ed Tanous4a0cb852018-10-15 07:55:04 -0700634 "xyz.openbmc_project.Object.Delete", "Delete");
635}
Ed Tanous1abe55e2018-09-05 08:30:59 -0700636
Gunnar Mills244b6d52021-04-12 15:44:23 -0500637inline void updateIPv4DefaultGateway(
638 const std::string& ifaceId, const std::string& gateway,
639 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ravi Teja9010ec22019-08-01 23:30:25 -0500640{
George Liu9ae226f2023-06-21 17:56:46 +0800641 sdbusplus::asio::setProperty(
642 *crow::connections::systemBus, "xyz.openbmc_project.Network",
Ravi Teja9010ec22019-08-01 23:30:25 -0500643 "/xyz/openbmc_project/network/" + ifaceId,
Ravi Teja9010ec22019-08-01 23:30:25 -0500644 "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway",
George Liu9ae226f2023-06-21 17:56:46 +0800645 gateway, [asyncResp](const boost::system::error_code& ec) {
646 if (ec)
647 {
648 messages::internalError(asyncResp->res);
649 return;
650 }
651 asyncResp->res.result(boost::beast::http::status::no_content);
652 });
Ravi Teja9010ec22019-08-01 23:30:25 -0500653}
Ed Tanous4a0cb852018-10-15 07:55:04 -0700654/**
Johnathan Mantey01784822019-06-18 12:44:21 -0700655 * @brief Creates a static IPv4 entry
Ed Tanous4a0cb852018-10-15 07:55:04 -0700656 *
Johnathan Mantey01784822019-06-18 12:44:21 -0700657 * @param[in] ifaceId Id of interface upon which to create the IPv4 entry
658 * @param[in] prefixLength IPv4 prefix syntax for the subnet mask
659 * @param[in] gateway IPv4 address of this interfaces gateway
660 * @param[in] address IPv4 address to assign to this interface
661 * @param[io] asyncResp Response object that will be returned to client
Ed Tanous4a0cb852018-10-15 07:55:04 -0700662 *
663 * @return None
664 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000665inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
666 const std::string& gateway, const std::string& address,
zhanghch058d1b46d2021-04-01 11:18:24 +0800667 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700668{
Ed Tanous002d39b2022-05-31 08:59:27 -0700669 auto createIpHandler =
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800670 [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
Ravi Teja9010ec22019-08-01 23:30:25 -0500671 if (ec)
672 {
673 messages::internalError(asyncResp->res);
674 return;
675 }
676 updateIPv4DefaultGateway(ifaceId, gateway, asyncResp);
677 };
678
Ed Tanous4a0cb852018-10-15 07:55:04 -0700679 crow::connections::systemBus->async_method_call(
Ravi Teja9010ec22019-08-01 23:30:25 -0500680 std::move(createIpHandler), "xyz.openbmc_project.Network",
Ed Tanous4a0cb852018-10-15 07:55:04 -0700681 "/xyz/openbmc_project/network/" + ifaceId,
682 "xyz.openbmc_project.Network.IP.Create", "IP",
Johnathan Mantey01784822019-06-18 12:44:21 -0700683 "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength,
Ed Tanous4a0cb852018-10-15 07:55:04 -0700684 gateway);
685}
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500686
687/**
Johnathan Mantey01784822019-06-18 12:44:21 -0700688 * @brief Deletes the IPv6 entry for this interface and creates a replacement
689 * static IPv6 entry
690 *
691 * @param[in] ifaceId Id of interface upon which to create the IPv6 entry
692 * @param[in] id The unique hash entry identifying the DBus entry
693 * @param[in] prefixLength IPv6 prefix syntax for the subnet mask
694 * @param[in] address IPv6 address to assign to this interface
695 * @param[io] asyncResp Response object that will be returned to client
696 *
697 * @return None
698 */
Ravi Teja9c5e5852023-02-26 21:33:52 -0600699
700enum class IpVersion
701{
702 IpV4,
703 IpV6
704};
705
706inline void deleteAndCreateIPAddress(
707 IpVersion version, const std::string& ifaceId, const std::string& id,
708 uint8_t prefixLength, const std::string& address,
709 const std::string& gateway,
710 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Johnathan Mantey01784822019-06-18 12:44:21 -0700711{
712 crow::connections::systemBus->async_method_call(
Ravi Teja9c5e5852023-02-26 21:33:52 -0600713 [asyncResp, version, ifaceId, address, prefixLength,
714 gateway](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700715 if (ec)
716 {
717 messages::internalError(asyncResp->res);
718 }
Ravi Teja9c5e5852023-02-26 21:33:52 -0600719 std::string protocol = "xyz.openbmc_project.Network.IP.Protocol.";
720 protocol += version == IpVersion::IpV4 ? "IPv4" : "IPv6";
Ed Tanous002d39b2022-05-31 08:59:27 -0700721 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800722 [asyncResp](const boost::system::error_code& ec2) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700723 if (ec2)
Johnathan Mantey01784822019-06-18 12:44:21 -0700724 {
725 messages::internalError(asyncResp->res);
726 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700727 },
728 "xyz.openbmc_project.Network",
729 "/xyz/openbmc_project/network/" + ifaceId,
Ravi Teja9c5e5852023-02-26 21:33:52 -0600730 "xyz.openbmc_project.Network.IP.Create", "IP", protocol, address,
731 prefixLength, gateway);
Johnathan Mantey01784822019-06-18 12:44:21 -0700732 },
733 "xyz.openbmc_project.Network",
Ravi Teja9c5e5852023-02-26 21:33:52 -0600734 "/xyz/openbmc_project/network/" + ifaceId + id,
Johnathan Mantey01784822019-06-18 12:44:21 -0700735 "xyz.openbmc_project.Object.Delete", "Delete");
736}
737
738/**
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500739 * @brief Creates IPv6 with given data
740 *
741 * @param[in] ifaceId Id of interface whose IP should be added
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500742 * @param[in] prefixLength Prefix length that needs to be added
743 * @param[in] address IP address that needs to be added
744 * @param[io] asyncResp Response object that will be returned to client
745 *
746 * @return None
747 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500748inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength,
749 const std::string& address,
zhanghch058d1b46d2021-04-01 11:18:24 +0800750 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500751{
Nitin Kumar Kotaniafc23ef82023-06-29 04:55:09 -0500752 auto createIpHandler =
753 [asyncResp, address](const boost::system::error_code& ec) {
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500754 if (ec)
755 {
Nitin Kumar Kotaniafc23ef82023-06-29 04:55:09 -0500756 if (ec == boost::system::errc::io_error)
757 {
758 messages::propertyValueFormatError(asyncResp->res, address,
759 "Address");
760 }
761 else
762 {
763 messages::internalError(asyncResp->res);
764 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500765 }
766 };
767 // Passing null for gateway, as per redfish spec IPv6StaticAddresses object
Gunnar Mills4e0453b2020-07-08 14:00:30 -0500768 // does not have associated gateway property
Ravi Tejae48c0fc2019-04-16 08:37:20 -0500769 crow::connections::systemBus->async_method_call(
770 std::move(createIpHandler), "xyz.openbmc_project.Network",
771 "/xyz/openbmc_project/network/" + ifaceId,
772 "xyz.openbmc_project.Network.IP.Create", "IP",
773 "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength,
774 "");
775}
776
Ed Tanous4a0cb852018-10-15 07:55:04 -0700777/**
778 * Function that retrieves all properties for given Ethernet Interface
779 * Object
780 * from EntityManager Network Manager
781 * @param ethiface_id a eth interface id to query on DBus
782 * @param callback a function that shall be called to convert Dbus output
783 * into JSON
784 */
785template <typename CallbackFunc>
Ed Tanous81ce6092020-12-17 16:54:55 +0000786void getEthernetIfaceData(const std::string& ethifaceId,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500787 CallbackFunc&& callback)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700788{
George Liuf5892d02023-03-01 10:37:08 +0800789 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
790 dbus::utility::getManagedObjects(
791 "xyz.openbmc_project.Network", path,
Ed Tanousf94c4ec2022-01-06 12:44:41 -0800792 [ethifaceId{std::string{ethifaceId}},
793 callback{std::forward<CallbackFunc>(callback)}](
Ed Tanous8b242752023-06-27 17:17:13 -0700794 const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -0700795 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700796 EthernetInterfaceData ethData{};
Ed Tanous77179532023-02-28 10:45:28 -0800797 std::vector<IPv4AddressData> ipv4Data;
798 std::vector<IPv6AddressData> ipv6Data;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700799
Ed Tanous8b242752023-06-27 17:17:13 -0700800 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700801 {
802 callback(false, ethData, ipv4Data, ipv6Data);
803 return;
804 }
805
806 bool found = extractEthernetInterfaceData(ethifaceId, resp, ethData);
807 if (!found)
808 {
809 callback(false, ethData, ipv4Data, ipv6Data);
810 return;
811 }
812
813 extractIPData(ethifaceId, resp, ipv4Data);
814 // Fix global GW
815 for (IPv4AddressData& ipv4 : ipv4Data)
816 {
817 if (((ipv4.linktype == LinkType::Global) &&
818 (ipv4.gateway == "0.0.0.0")) ||
819 (ipv4.origin == "DHCP") || (ipv4.origin == "Static"))
Ed Tanous4a0cb852018-10-15 07:55:04 -0700820 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700821 ipv4.gateway = ethData.defaultGateway;
Ed Tanous4a0cb852018-10-15 07:55:04 -0700822 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700823 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700824
Ed Tanous002d39b2022-05-31 08:59:27 -0700825 extractIPV6Data(ethifaceId, resp, ipv6Data);
826 // Finally make a callback with useful data
827 callback(true, ethData, ipv4Data, ipv6Data);
George Liuf5892d02023-03-01 10:37:08 +0800828 });
Ed Tanous271584a2019-07-09 16:24:22 -0700829}
Ed Tanous4a0cb852018-10-15 07:55:04 -0700830
831/**
832 * Function that retrieves all Ethernet Interfaces available through Network
833 * Manager
834 * @param callback a function that shall be called to convert Dbus output
835 * into JSON.
836 */
837template <typename CallbackFunc>
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500838void getEthernetIfaceList(CallbackFunc&& callback)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700839{
George Liuf5892d02023-03-01 10:37:08 +0800840 sdbusplus::message::object_path path("/xyz/openbmc_project/network");
841 dbus::utility::getManagedObjects(
842 "xyz.openbmc_project.Network", path,
Ed Tanousf94c4ec2022-01-06 12:44:41 -0800843 [callback{std::forward<CallbackFunc>(callback)}](
Ed Tanous8b242752023-06-27 17:17:13 -0700844 const boost::system::error_code& ec,
George Liuf5892d02023-03-01 10:37:08 +0800845 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700846 // Callback requires vector<string> to retrieve all available
847 // ethernet interfaces
Ed Tanous77179532023-02-28 10:45:28 -0800848 std::vector<std::string> ifaceList;
Ed Tanous002d39b2022-05-31 08:59:27 -0700849 ifaceList.reserve(resp.size());
Ed Tanous8b242752023-06-27 17:17:13 -0700850 if (ec)
Ed Tanous002d39b2022-05-31 08:59:27 -0700851 {
852 callback(false, ifaceList);
853 return;
854 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700855
Ed Tanous002d39b2022-05-31 08:59:27 -0700856 // Iterate over all retrieved ObjectPaths.
857 for (const auto& objpath : resp)
858 {
859 // And all interfaces available for certain ObjectPath.
860 for (const auto& interface : objpath.second)
Ed Tanous4a0cb852018-10-15 07:55:04 -0700861 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700862 // If interface is
863 // xyz.openbmc_project.Network.EthernetInterface, this is
864 // what we're looking for.
865 if (interface.first ==
866 "xyz.openbmc_project.Network.EthernetInterface")
Ed Tanous4a0cb852018-10-15 07:55:04 -0700867 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700868 std::string ifaceId = objpath.first.filename();
869 if (ifaceId.empty())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700870 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700871 continue;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700872 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700873 // and put it into output vector.
Ed Tanous77179532023-02-28 10:45:28 -0800874 ifaceList.emplace_back(ifaceId);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700875 }
Ed Tanous4a0cb852018-10-15 07:55:04 -0700876 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700877 }
Ed Tanous2c5875a2023-05-15 09:56:06 -0700878
879 std::sort(ifaceList.begin(), ifaceList.end(),
880 AlphanumLess<std::string>());
881
Ed Tanous002d39b2022-05-31 08:59:27 -0700882 // Finally make a callback with useful data
883 callback(true, ifaceList);
George Liuf5892d02023-03-01 10:37:08 +0800884 });
Ed Tanous271584a2019-07-09 16:24:22 -0700885}
Rapkiewicz, Pawel9391bb92018-03-20 03:12:18 +0100886
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700887inline void
888 handleHostnamePatch(const std::string& hostname,
889 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700890{
Ed Tanousbf648f72021-06-03 15:00:14 -0700891 // SHOULD handle host names of up to 255 characters(RFC 1123)
892 if (hostname.length() > 255)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700893 {
Ed Tanousbf648f72021-06-03 15:00:14 -0700894 messages::propertyValueFormatError(asyncResp->res, hostname,
895 "HostName");
896 return;
897 }
George Liu9ae226f2023-06-21 17:56:46 +0800898 sdbusplus::asio::setProperty(
899 *crow::connections::systemBus, "xyz.openbmc_project.Network",
900 "/xyz/openbmc_project/network/config",
901 "xyz.openbmc_project.Network.SystemConfiguration", "HostName", hostname,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800902 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700903 if (ec)
904 {
905 messages::internalError(asyncResp->res);
906 }
George Liu9ae226f2023-06-21 17:56:46 +0800907 });
Ed Tanousbf648f72021-06-03 15:00:14 -0700908}
909
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700910inline void
Tejas Patil35fb5312021-09-20 15:35:20 +0530911 handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize,
912 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
913{
Patrick Williams89492a12023-05-10 07:51:34 -0500914 sdbusplus::message::object_path objPath = "/xyz/openbmc_project/network/" +
915 ifaceId;
George Liu9ae226f2023-06-21 17:56:46 +0800916 sdbusplus::asio::setProperty(
917 *crow::connections::systemBus, "xyz.openbmc_project.Network", objPath,
918 "xyz.openbmc_project.Network.EthernetInterface", "MTU", mtuSize,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800919 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700920 if (ec)
921 {
922 messages::internalError(asyncResp->res);
923 }
George Liu9ae226f2023-06-21 17:56:46 +0800924 });
Tejas Patil35fb5312021-09-20 15:35:20 +0530925}
926
927inline void
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700928 handleDomainnamePatch(const std::string& ifaceId,
929 const std::string& domainname,
930 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -0700931{
932 std::vector<std::string> vectorDomainname = {domainname};
George Liu9ae226f2023-06-21 17:56:46 +0800933 sdbusplus::asio::setProperty(
934 *crow::connections::systemBus, "xyz.openbmc_project.Network",
Ed Tanousbf648f72021-06-03 15:00:14 -0700935 "/xyz/openbmc_project/network/" + ifaceId,
Ed Tanousbf648f72021-06-03 15:00:14 -0700936 "xyz.openbmc_project.Network.EthernetInterface", "DomainName",
George Liu9ae226f2023-06-21 17:56:46 +0800937 vectorDomainname, [asyncResp](const boost::system::error_code& ec) {
938 if (ec)
939 {
940 messages::internalError(asyncResp->res);
941 }
942 });
Ed Tanousbf648f72021-06-03 15:00:14 -0700943}
944
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700945inline bool isHostnameValid(const std::string& hostname)
Ed Tanousbf648f72021-06-03 15:00:14 -0700946{
947 // A valid host name can never have the dotted-decimal form (RFC 1123)
948 if (std::all_of(hostname.begin(), hostname.end(), ::isdigit))
949 {
950 return false;
951 }
952 // Each label(hostname/subdomains) within a valid FQDN
953 // MUST handle host names of up to 63 characters (RFC 1123)
954 // labels cannot start or end with hyphens (RFC 952)
955 // labels can start with numbers (RFC 1123)
Ed Tanous4b242742023-05-11 09:51:51 -0700956 const static std::regex pattern(
Ed Tanousbf648f72021-06-03 15:00:14 -0700957 "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$");
958
959 return std::regex_match(hostname, pattern);
960}
961
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700962inline bool isDomainnameValid(const std::string& domainname)
Ed Tanousbf648f72021-06-03 15:00:14 -0700963{
964 // Can have multiple subdomains
965 // Top Level Domain's min length is 2 character
Ed Tanous4b242742023-05-11 09:51:51 -0700966 const static std::regex pattern(
George Liu0fda0f12021-11-16 10:06:17 +0800967 "^([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 -0700968
969 return std::regex_match(domainname, pattern);
970}
971
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700972inline void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn,
973 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -0700974{
975 // Total length of FQDN must not exceed 255 characters(RFC 1035)
976 if (fqdn.length() > 255)
977 {
978 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
979 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700980 }
981
Ed Tanousbf648f72021-06-03 15:00:14 -0700982 size_t pos = fqdn.find('.');
983 if (pos == std::string::npos)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700984 {
Ed Tanousbf648f72021-06-03 15:00:14 -0700985 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
986 return;
987 }
zhanghch058d1b46d2021-04-01 11:18:24 +0800988
Ed Tanousbf648f72021-06-03 15:00:14 -0700989 std::string hostname;
990 std::string domainname;
991 domainname = (fqdn).substr(pos + 1);
992 hostname = (fqdn).substr(0, pos);
993
994 if (!isHostnameValid(hostname) || !isDomainnameValid(domainname))
995 {
996 messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
997 return;
998 }
999
1000 handleHostnamePatch(hostname, asyncResp);
1001 handleDomainnamePatch(ifaceId, domainname, asyncResp);
1002}
1003
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001004inline void
1005 handleMACAddressPatch(const std::string& ifaceId,
1006 const std::string& macAddress,
1007 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001008{
Johnathan Mantey58283f42022-08-15 14:38:36 -07001009 static constexpr std::string_view dbusNotAllowedError =
1010 "xyz.openbmc_project.Common.Error.NotAllowed";
1011
George Liu9ae226f2023-06-21 17:56:46 +08001012 sdbusplus::asio::setProperty(
1013 *crow::connections::systemBus, "xyz.openbmc_project.Network",
1014 "/xyz/openbmc_project/network/" + ifaceId,
1015 "xyz.openbmc_project.Network.MACAddress", "MACAddress", macAddress,
1016 [asyncResp](const boost::system::error_code& ec,
1017 const sdbusplus::message_t& msg) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001018 if (ec)
1019 {
Johnathan Mantey58283f42022-08-15 14:38:36 -07001020 const sd_bus_error* err = msg.get_error();
1021 if (err == nullptr)
1022 {
1023 messages::internalError(asyncResp->res);
1024 return;
1025 }
1026 if (err->name == dbusNotAllowedError)
1027 {
1028 messages::propertyNotWritable(asyncResp->res, "MACAddress");
1029 return;
1030 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001031 messages::internalError(asyncResp->res);
1032 return;
1033 }
George Liu9ae226f2023-06-21 17:56:46 +08001034 });
Ed Tanousbf648f72021-06-03 15:00:14 -07001035}
1036
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001037inline void setDHCPEnabled(const std::string& ifaceId,
1038 const std::string& propertyName, const bool v4Value,
1039 const bool v6Value,
1040 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001041{
1042 const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
George Liu9ae226f2023-06-21 17:56:46 +08001043 sdbusplus::asio::setProperty(
1044 *crow::connections::systemBus, "xyz.openbmc_project.Network",
1045 "/xyz/openbmc_project/network/" + ifaceId,
1046 "xyz.openbmc_project.Network.EthernetInterface", propertyName, dhcp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001047 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001048 if (ec)
1049 {
Ed Tanous62598e32023-07-17 17:06:25 -07001050 BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001051 messages::internalError(asyncResp->res);
1052 return;
1053 }
1054 messages::success(asyncResp->res);
George Liu9ae226f2023-06-21 17:56:46 +08001055 });
Ed Tanousbf648f72021-06-03 15:00:14 -07001056}
1057
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001058inline void setEthernetInterfaceBoolProperty(
Ed Tanousbf648f72021-06-03 15:00:14 -07001059 const std::string& ifaceId, const std::string& propertyName,
1060 const bool& value, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1061{
George Liu9ae226f2023-06-21 17:56:46 +08001062 sdbusplus::asio::setProperty(
1063 *crow::connections::systemBus, "xyz.openbmc_project.Network",
1064 "/xyz/openbmc_project/network/" + ifaceId,
1065 "xyz.openbmc_project.Network.EthernetInterface", propertyName, value,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001066 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001067 if (ec)
1068 {
Ed Tanous62598e32023-07-17 17:06:25 -07001069 BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001070 messages::internalError(asyncResp->res);
1071 return;
1072 }
George Liu9ae226f2023-06-21 17:56:46 +08001073 });
Ed Tanousbf648f72021-06-03 15:00:14 -07001074}
1075
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001076inline void setDHCPv4Config(const std::string& propertyName, const bool& value,
1077 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001078{
Ed Tanous62598e32023-07-17 17:06:25 -07001079 BMCWEB_LOG_DEBUG("{} = {}", propertyName, value);
George Liu9ae226f2023-06-21 17:56:46 +08001080 sdbusplus::asio::setProperty(
1081 *crow::connections::systemBus, "xyz.openbmc_project.Network",
1082 "/xyz/openbmc_project/network/dhcp",
1083 "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, value,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001084 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001085 if (ec)
1086 {
Ed Tanous62598e32023-07-17 17:06:25 -07001087 BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001088 messages::internalError(asyncResp->res);
1089 return;
1090 }
George Liu9ae226f2023-06-21 17:56:46 +08001091 });
Ed Tanousbf648f72021-06-03 15:00:14 -07001092}
1093
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001094inline void handleDHCPPatch(const std::string& ifaceId,
1095 const EthernetInterfaceData& ethData,
1096 const DHCPParameters& v4dhcpParms,
1097 const DHCPParameters& v6dhcpParms,
1098 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001099{
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001100 bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
1101 bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false);
Ed Tanousbf648f72021-06-03 15:00:14 -07001102
1103 bool nextv4DHCPState =
1104 v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active;
1105
1106 bool nextv6DHCPState{};
1107 if (v6dhcpParms.dhcpv6OperatingMode)
1108 {
1109 if ((*v6dhcpParms.dhcpv6OperatingMode != "Stateful") &&
1110 (*v6dhcpParms.dhcpv6OperatingMode != "Stateless") &&
1111 (*v6dhcpParms.dhcpv6OperatingMode != "Disabled"))
1112 {
1113 messages::propertyValueFormatError(asyncResp->res,
1114 *v6dhcpParms.dhcpv6OperatingMode,
1115 "OperatingMode");
1116 return;
1117 }
1118 nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Stateful");
1119 }
1120 else
1121 {
1122 nextv6DHCPState = ipv6Active;
1123 }
1124
1125 bool nextDNS{};
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001126 if (v4dhcpParms.useDnsServers && v6dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001127 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001128 if (*v4dhcpParms.useDnsServers != *v6dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001129 {
1130 messages::generalError(asyncResp->res);
1131 return;
1132 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001133 nextDNS = *v4dhcpParms.useDnsServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001134 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001135 else if (v4dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001136 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001137 nextDNS = *v4dhcpParms.useDnsServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001138 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001139 else if (v6dhcpParms.useDnsServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001140 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001141 nextDNS = *v6dhcpParms.useDnsServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001142 }
1143 else
1144 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001145 nextDNS = ethData.dnsEnabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001146 }
1147
1148 bool nextNTP{};
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001149 if (v4dhcpParms.useNtpServers && v6dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001150 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001151 if (*v4dhcpParms.useNtpServers != *v6dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001152 {
1153 messages::generalError(asyncResp->res);
1154 return;
1155 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001156 nextNTP = *v4dhcpParms.useNtpServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001157 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001158 else if (v4dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001159 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001160 nextNTP = *v4dhcpParms.useNtpServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001161 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001162 else if (v6dhcpParms.useNtpServers)
Ed Tanousbf648f72021-06-03 15:00:14 -07001163 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001164 nextNTP = *v6dhcpParms.useNtpServers;
Ed Tanousbf648f72021-06-03 15:00:14 -07001165 }
1166 else
1167 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001168 nextNTP = ethData.ntpEnabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001169 }
1170
1171 bool nextUseDomain{};
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001172 if (v4dhcpParms.useDomainName && v6dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001173 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001174 if (*v4dhcpParms.useDomainName != *v6dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001175 {
1176 messages::generalError(asyncResp->res);
1177 return;
1178 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001179 nextUseDomain = *v4dhcpParms.useDomainName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001180 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001181 else if (v4dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001182 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001183 nextUseDomain = *v4dhcpParms.useDomainName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001184 }
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001185 else if (v6dhcpParms.useDomainName)
Ed Tanousbf648f72021-06-03 15:00:14 -07001186 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001187 nextUseDomain = *v6dhcpParms.useDomainName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001188 }
1189 else
1190 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001191 nextUseDomain = ethData.hostNameEnabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001192 }
1193
Ed Tanous62598e32023-07-17 17:06:25 -07001194 BMCWEB_LOG_DEBUG("set DHCPEnabled...");
Ed Tanousbf648f72021-06-03 15:00:14 -07001195 setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
1196 asyncResp);
Ed Tanous62598e32023-07-17 17:06:25 -07001197 BMCWEB_LOG_DEBUG("set DNSEnabled...");
Ed Tanousbf648f72021-06-03 15:00:14 -07001198 setDHCPv4Config("DNSEnabled", nextDNS, asyncResp);
Ed Tanous62598e32023-07-17 17:06:25 -07001199 BMCWEB_LOG_DEBUG("set NTPEnabled...");
Ed Tanousbf648f72021-06-03 15:00:14 -07001200 setDHCPv4Config("NTPEnabled", nextNTP, asyncResp);
Ed Tanous62598e32023-07-17 17:06:25 -07001201 BMCWEB_LOG_DEBUG("set HostNameEnabled...");
Ed Tanousbf648f72021-06-03 15:00:14 -07001202 setDHCPv4Config("HostNameEnabled", nextUseDomain, asyncResp);
1203}
1204
Ed Tanous77179532023-02-28 10:45:28 -08001205inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry(
1206 const std::vector<IPv4AddressData>::const_iterator& head,
1207 const std::vector<IPv4AddressData>::const_iterator& end)
Ed Tanousbf648f72021-06-03 15:00:14 -07001208{
1209 return std::find_if(head, end, [](const IPv4AddressData& value) {
1210 return value.origin == "Static";
1211 });
1212}
1213
Ed Tanous77179532023-02-28 10:45:28 -08001214inline std::vector<IPv6AddressData>::const_iterator getNextStaticIpEntry(
1215 const std::vector<IPv6AddressData>::const_iterator& head,
1216 const std::vector<IPv6AddressData>::const_iterator& end)
Ed Tanousbf648f72021-06-03 15:00:14 -07001217{
1218 return std::find_if(head, end, [](const IPv6AddressData& value) {
1219 return value.origin == "Static";
1220 });
1221}
1222
Ed Tanous77179532023-02-28 10:45:28 -08001223inline void
Ed Tanousddd70dc2023-03-01 16:00:27 -08001224 handleIPv4StaticPatch(const std::string& ifaceId,
1225 nlohmann::json::array_t& input,
Ed Tanous77179532023-02-28 10:45:28 -08001226 const std::vector<IPv4AddressData>& ipv4Data,
1227 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanousbf648f72021-06-03 15:00:14 -07001228{
Ed Tanousddd70dc2023-03-01 16:00:27 -08001229 if (input.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001230 {
Ed Tanous2e8c4bd2022-06-27 12:59:12 -07001231 messages::propertyValueTypeError(asyncResp->res, input,
1232 "IPv4StaticAddresses");
Ed Tanousbf648f72021-06-03 15:00:14 -07001233 return;
1234 }
1235
1236 unsigned entryIdx = 1;
1237 // Find the first static IP address currently active on the NIC and
1238 // match it to the first JSON element in the IPv4StaticAddresses array.
1239 // Match each subsequent JSON element to the next static IP programmed
1240 // into the NIC.
Ed Tanous77179532023-02-28 10:45:28 -08001241 std::vector<IPv4AddressData>::const_iterator nicIpEntry =
Ed Tanousbf648f72021-06-03 15:00:14 -07001242 getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend());
1243
1244 for (nlohmann::json& thisJson : input)
1245 {
Patrick Williams89492a12023-05-10 07:51:34 -05001246 std::string pathString = "IPv4StaticAddresses/" +
1247 std::to_string(entryIdx);
Ed Tanousbf648f72021-06-03 15:00:14 -07001248
1249 if (!thisJson.is_null() && !thisJson.empty())
1250 {
1251 std::optional<std::string> address;
1252 std::optional<std::string> subnetMask;
1253 std::optional<std::string> gateway;
1254
1255 if (!json_util::readJson(thisJson, asyncResp->res, "Address",
1256 address, "SubnetMask", subnetMask,
1257 "Gateway", gateway))
1258 {
Ed Tanousf818b042022-06-27 13:17:35 -07001259 messages::propertyValueFormatError(asyncResp->res, thisJson,
1260 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001261 return;
1262 }
1263
1264 // Find the address/subnet/gateway values. Any values that are
1265 // not explicitly provided are assumed to be unmodified from the
1266 // current state of the interface. Merge existing state into the
1267 // current request.
1268 const std::string* addr = nullptr;
1269 const std::string* gw = nullptr;
1270 uint8_t prefixLength = 0;
1271 bool errorInEntry = false;
1272 if (address)
1273 {
Ed Tanous033f1e42022-08-15 09:47:37 -07001274 if (ip_util::ipv4VerifyIpAndGetBitcount(*address))
Ed Tanousbf648f72021-06-03 15:00:14 -07001275 {
1276 addr = &(*address);
1277 }
1278 else
1279 {
1280 messages::propertyValueFormatError(asyncResp->res, *address,
1281 pathString + "/Address");
1282 errorInEntry = true;
1283 }
1284 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001285 else if (nicIpEntry != ipv4Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001286 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001287 addr = &(nicIpEntry->address);
Ed Tanousbf648f72021-06-03 15:00:14 -07001288 }
1289 else
1290 {
1291 messages::propertyMissing(asyncResp->res,
1292 pathString + "/Address");
1293 errorInEntry = true;
1294 }
1295
1296 if (subnetMask)
1297 {
Ed Tanous033f1e42022-08-15 09:47:37 -07001298 if (!ip_util::ipv4VerifyIpAndGetBitcount(*subnetMask,
1299 &prefixLength))
Ed Tanousbf648f72021-06-03 15:00:14 -07001300 {
1301 messages::propertyValueFormatError(
1302 asyncResp->res, *subnetMask,
1303 pathString + "/SubnetMask");
1304 errorInEntry = true;
1305 }
1306 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001307 else if (nicIpEntry != ipv4Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001308 {
Ed Tanous033f1e42022-08-15 09:47:37 -07001309 if (!ip_util::ipv4VerifyIpAndGetBitcount(nicIpEntry->netmask,
1310 &prefixLength))
Ed Tanousbf648f72021-06-03 15:00:14 -07001311 {
1312 messages::propertyValueFormatError(
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001313 asyncResp->res, nicIpEntry->netmask,
Ed Tanousbf648f72021-06-03 15:00:14 -07001314 pathString + "/SubnetMask");
1315 errorInEntry = true;
1316 }
1317 }
1318 else
1319 {
1320 messages::propertyMissing(asyncResp->res,
1321 pathString + "/SubnetMask");
1322 errorInEntry = true;
1323 }
1324
1325 if (gateway)
1326 {
Ed Tanous033f1e42022-08-15 09:47:37 -07001327 if (ip_util::ipv4VerifyIpAndGetBitcount(*gateway))
Ed Tanousbf648f72021-06-03 15:00:14 -07001328 {
1329 gw = &(*gateway);
1330 }
1331 else
1332 {
1333 messages::propertyValueFormatError(asyncResp->res, *gateway,
1334 pathString + "/Gateway");
1335 errorInEntry = true;
1336 }
1337 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001338 else if (nicIpEntry != ipv4Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001339 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001340 gw = &nicIpEntry->gateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001341 }
1342 else
1343 {
1344 messages::propertyMissing(asyncResp->res,
1345 pathString + "/Gateway");
1346 errorInEntry = true;
1347 }
1348
1349 if (errorInEntry)
1350 {
1351 return;
1352 }
1353
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001354 if (nicIpEntry != ipv4Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001355 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001356 deleteAndCreateIPAddress(IpVersion::IpV4, ifaceId,
1357 nicIpEntry->id, prefixLength, *gw,
1358 *addr, asyncResp);
Patrick Williams89492a12023-05-10 07:51:34 -05001359 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
1360 ipv4Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001361 }
1362 else
1363 {
1364 createIPv4(ifaceId, prefixLength, *gateway, *address,
1365 asyncResp);
1366 }
1367 entryIdx++;
1368 }
1369 else
1370 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001371 if (nicIpEntry == ipv4Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001372 {
1373 // Requesting a DELETE/DO NOT MODIFY action for an item
1374 // that isn't present on the eth(n) interface. Input JSON is
1375 // in error, so bail out.
1376 if (thisJson.is_null())
1377 {
1378 messages::resourceCannotBeDeleted(asyncResp->res);
1379 return;
1380 }
Ed Tanousf818b042022-06-27 13:17:35 -07001381 messages::propertyValueFormatError(asyncResp->res, thisJson,
1382 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001383 return;
1384 }
1385
1386 if (thisJson.is_null())
1387 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001388 deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001389 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001390 if (nicIpEntry != ipv4Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001391 {
Patrick Williams89492a12023-05-10 07:51:34 -05001392 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
1393 ipv4Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001394 }
1395 entryIdx++;
1396 }
1397 }
1398}
1399
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001400inline void handleStaticNameServersPatch(
Ed Tanousbf648f72021-06-03 15:00:14 -07001401 const std::string& ifaceId,
1402 const std::vector<std::string>& updatedStaticNameServers,
1403 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1404{
George Liu9ae226f2023-06-21 17:56:46 +08001405 sdbusplus::asio::setProperty(
1406 *crow::connections::systemBus, "xyz.openbmc_project.Network",
1407 "/xyz/openbmc_project/network/" + ifaceId,
1408 "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers",
1409 updatedStaticNameServers,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001410 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001411 if (ec)
1412 {
1413 messages::internalError(asyncResp->res);
1414 return;
1415 }
George Liu9ae226f2023-06-21 17:56:46 +08001416 });
Ed Tanousbf648f72021-06-03 15:00:14 -07001417}
1418
Ed Tanous4f48d5f2021-06-21 08:27:45 -07001419inline void handleIPv6StaticAddressesPatch(
Ed Tanousddd70dc2023-03-01 16:00:27 -08001420 const std::string& ifaceId, const nlohmann::json::array_t& input,
Ed Tanous77179532023-02-28 10:45:28 -08001421 const std::vector<IPv6AddressData>& ipv6Data,
Ed Tanousbf648f72021-06-03 15:00:14 -07001422 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1423{
Ed Tanousddd70dc2023-03-01 16:00:27 -08001424 if (input.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001425 {
Ed Tanous2e8c4bd2022-06-27 12:59:12 -07001426 messages::propertyValueTypeError(asyncResp->res, input,
1427 "IPv6StaticAddresses");
Ed Tanousbf648f72021-06-03 15:00:14 -07001428 return;
1429 }
1430 size_t entryIdx = 1;
Ed Tanous77179532023-02-28 10:45:28 -08001431 std::vector<IPv6AddressData>::const_iterator nicIpEntry =
Ed Tanousbf648f72021-06-03 15:00:14 -07001432 getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend());
1433 for (const nlohmann::json& thisJson : input)
1434 {
Patrick Williams89492a12023-05-10 07:51:34 -05001435 std::string pathString = "IPv6StaticAddresses/" +
1436 std::to_string(entryIdx);
Ed Tanousbf648f72021-06-03 15:00:14 -07001437
1438 if (!thisJson.is_null() && !thisJson.empty())
1439 {
1440 std::optional<std::string> address;
1441 std::optional<uint8_t> prefixLength;
1442 nlohmann::json thisJsonCopy = thisJson;
1443 if (!json_util::readJson(thisJsonCopy, asyncResp->res, "Address",
1444 address, "PrefixLength", prefixLength))
1445 {
Ed Tanousf818b042022-06-27 13:17:35 -07001446 messages::propertyValueFormatError(asyncResp->res, thisJson,
1447 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001448 return;
1449 }
1450
Ed Tanous543f4402022-01-06 13:12:53 -08001451 const std::string* addr = nullptr;
1452 uint8_t prefix = 0;
Ed Tanousbf648f72021-06-03 15:00:14 -07001453
1454 // Find the address and prefixLength values. Any values that are
1455 // not explicitly provided are assumed to be unmodified from the
1456 // current state of the interface. Merge existing state into the
1457 // current request.
1458 if (address)
1459 {
1460 addr = &(*address);
1461 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001462 else if (nicIpEntry != ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001463 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001464 addr = &(nicIpEntry->address);
Ed Tanousbf648f72021-06-03 15:00:14 -07001465 }
1466 else
1467 {
1468 messages::propertyMissing(asyncResp->res,
1469 pathString + "/Address");
1470 return;
1471 }
1472
1473 if (prefixLength)
1474 {
1475 prefix = *prefixLength;
1476 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001477 else if (nicIpEntry != ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001478 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001479 prefix = nicIpEntry->prefixLength;
Ed Tanousbf648f72021-06-03 15:00:14 -07001480 }
1481 else
1482 {
1483 messages::propertyMissing(asyncResp->res,
1484 pathString + "/PrefixLength");
1485 return;
1486 }
1487
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001488 if (nicIpEntry != ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001489 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001490 deleteAndCreateIPAddress(IpVersion::IpV6, ifaceId,
1491 nicIpEntry->id, prefix, "", *addr,
1492 asyncResp);
Patrick Williams89492a12023-05-10 07:51:34 -05001493 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
1494 ipv6Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001495 }
1496 else
1497 {
1498 createIPv6(ifaceId, *prefixLength, *addr, asyncResp);
1499 }
1500 entryIdx++;
1501 }
1502 else
1503 {
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001504 if (nicIpEntry == ipv6Data.end())
Ed Tanousbf648f72021-06-03 15:00:14 -07001505 {
1506 // Requesting a DELETE/DO NOT MODIFY action for an item
1507 // that isn't present on the eth(n) interface. Input JSON is
1508 // in error, so bail out.
1509 if (thisJson.is_null())
1510 {
1511 messages::resourceCannotBeDeleted(asyncResp->res);
1512 return;
1513 }
Ed Tanousf818b042022-06-27 13:17:35 -07001514 messages::propertyValueFormatError(asyncResp->res, thisJson,
1515 pathString);
Ed Tanousbf648f72021-06-03 15:00:14 -07001516 return;
1517 }
1518
1519 if (thisJson.is_null())
1520 {
Ravi Teja9c5e5852023-02-26 21:33:52 -06001521 deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp);
Ed Tanousbf648f72021-06-03 15:00:14 -07001522 }
Jiaqing Zhao85ffe862021-12-31 15:41:59 +08001523 if (nicIpEntry != ipv6Data.cend())
Ed Tanousbf648f72021-06-03 15:00:14 -07001524 {
Patrick Williams89492a12023-05-10 07:51:34 -05001525 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
1526 ipv6Data.cend());
Ed Tanousbf648f72021-06-03 15:00:14 -07001527 }
1528 entryIdx++;
1529 }
1530 }
1531}
1532
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001533inline std::string extractParentInterfaceName(const std::string& ifaceId)
1534{
1535 std::size_t pos = ifaceId.find('_');
1536 return ifaceId.substr(0, pos);
1537}
1538
Ed Tanous77179532023-02-28 10:45:28 -08001539inline void
1540 parseInterfaceData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1541 const std::string& ifaceId,
1542 const EthernetInterfaceData& ethData,
1543 const std::vector<IPv4AddressData>& ipv4Data,
1544 const std::vector<IPv6AddressData>& ipv6Data)
Ed Tanousbf648f72021-06-03 15:00:14 -07001545{
Ed Tanousbf648f72021-06-03 15:00:14 -07001546 nlohmann::json& jsonResponse = asyncResp->res.jsonValue;
1547 jsonResponse["Id"] = ifaceId;
Ed Tanousef4c65b2023-04-24 15:28:50 -07001548 jsonResponse["@odata.id"] = boost::urls::format(
1549 "/redfish/v1/Managers/bmc/EthernetInterfaces/{}", ifaceId);
Ed Tanousbf648f72021-06-03 15:00:14 -07001550 jsonResponse["InterfaceEnabled"] = ethData.nicEnabled;
1551
Willy Tu13451e32023-05-24 16:08:18 -07001552 if constexpr (bmcwebEnableHealthPopulate)
1553 {
1554 constexpr std::array<std::string_view, 1> inventoryForEthernet = {
1555 "xyz.openbmc_project.Inventory.Item.Ethernet"};
1556 auto health = std::make_shared<HealthPopulate>(asyncResp);
1557 dbus::utility::getSubTreePaths(
1558 "/", 0, inventoryForEthernet,
1559 [health](const boost::system::error_code& ec,
1560 const dbus::utility::MapperGetSubTreePathsResponse& resp) {
1561 if (ec)
1562 {
1563 return;
1564 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001565
Willy Tu13451e32023-05-24 16:08:18 -07001566 health->inventory = resp;
1567 });
Ed Tanousbf648f72021-06-03 15:00:14 -07001568
Willy Tu13451e32023-05-24 16:08:18 -07001569 health->populate();
1570 }
Ed Tanousbf648f72021-06-03 15:00:14 -07001571
1572 if (ethData.nicEnabled)
1573 {
Johnathan Mantey0ef0e282022-11-15 12:15:02 -08001574 jsonResponse["LinkStatus"] = ethData.linkUp ? "LinkUp" : "LinkDown";
Ed Tanousbf648f72021-06-03 15:00:14 -07001575 jsonResponse["Status"]["State"] = "Enabled";
1576 }
1577 else
1578 {
1579 jsonResponse["LinkStatus"] = "NoLink";
1580 jsonResponse["Status"]["State"] = "Disabled";
1581 }
1582
Ed Tanousbf648f72021-06-03 15:00:14 -07001583 jsonResponse["SpeedMbps"] = ethData.speed;
Tejas Patil35fb5312021-09-20 15:35:20 +05301584 jsonResponse["MTUSize"] = ethData.mtuSize;
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001585 jsonResponse["MACAddress"] = ethData.macAddress;
Ed Tanousbf648f72021-06-03 15:00:14 -07001586 jsonResponse["DHCPv4"]["DHCPEnabled"] =
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001587 translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
1588 jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpEnabled;
1589 jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsEnabled;
1590 jsonResponse["DHCPv4"]["UseDomainName"] = ethData.hostNameEnabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001591
1592 jsonResponse["DHCPv6"]["OperatingMode"] =
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001593 translateDhcpEnabledToBool(ethData.dhcpEnabled, false) ? "Stateful"
Ed Tanousbf648f72021-06-03 15:00:14 -07001594 : "Disabled";
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001595 jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpEnabled;
1596 jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsEnabled;
1597 jsonResponse["DHCPv6"]["UseDomainName"] = ethData.hostNameEnabled;
Ed Tanousbf648f72021-06-03 15:00:14 -07001598
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001599 if (!ethData.hostName.empty())
Ed Tanousbf648f72021-06-03 15:00:14 -07001600 {
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001601 jsonResponse["HostName"] = ethData.hostName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001602
1603 // When domain name is empty then it means, that it is a network
1604 // without domain names, and the host name itself must be treated as
1605 // FQDN
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001606 std::string fqdn = ethData.hostName;
Ed Tanousbf648f72021-06-03 15:00:14 -07001607 if (!ethData.domainnames.empty())
1608 {
1609 fqdn += "." + ethData.domainnames[0];
1610 }
1611 jsonResponse["FQDN"] = fqdn;
1612 }
1613
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001614 if (ethData.vlanId)
1615 {
1616 jsonResponse["EthernetInterfaceType"] = "Virtual";
1617 jsonResponse["VLAN"]["VLANEnable"] = true;
1618 jsonResponse["VLAN"]["VLANId"] = *ethData.vlanId;
1619 jsonResponse["VLAN"]["Tagged"] = true;
1620
1621 nlohmann::json::array_t relatedInterfaces;
1622 nlohmann::json& parentInterface = relatedInterfaces.emplace_back();
1623 parentInterface["@odata.id"] =
1624 boost::urls::format("/redfish/v1/Managers/bmc/EthernetInterfaces",
1625 extractParentInterfaceName(ifaceId));
1626 jsonResponse["Links"]["RelatedInterfaces"] =
1627 std::move(relatedInterfaces);
1628 }
1629 else
1630 {
1631 jsonResponse["EthernetInterfaceType"] = "Physical";
1632 }
1633
Ed Tanousbf648f72021-06-03 15:00:14 -07001634 jsonResponse["NameServers"] = ethData.nameServers;
1635 jsonResponse["StaticNameServers"] = ethData.staticNameServers;
1636
1637 nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"];
1638 nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
1639 ipv4Array = nlohmann::json::array();
1640 ipv4StaticArray = nlohmann::json::array();
Ed Tanous9eb808c2022-01-25 10:19:23 -08001641 for (const auto& ipv4Config : ipv4Data)
Ed Tanousbf648f72021-06-03 15:00:14 -07001642 {
Ed Tanousbf648f72021-06-03 15:00:14 -07001643 std::string gatewayStr = ipv4Config.gateway;
1644 if (gatewayStr.empty())
1645 {
1646 gatewayStr = "0.0.0.0";
1647 }
Ed Tanous14766872022-03-15 10:44:42 -07001648 nlohmann::json::object_t ipv4;
1649 ipv4["AddressOrigin"] = ipv4Config.origin;
1650 ipv4["SubnetMask"] = ipv4Config.netmask;
1651 ipv4["Address"] = ipv4Config.address;
1652 ipv4["Gateway"] = gatewayStr;
Ed Tanousbf648f72021-06-03 15:00:14 -07001653
Ed Tanousbf648f72021-06-03 15:00:14 -07001654 if (ipv4Config.origin == "Static")
1655 {
Ed Tanous14766872022-03-15 10:44:42 -07001656 ipv4StaticArray.push_back(ipv4);
Ed Tanousbf648f72021-06-03 15:00:14 -07001657 }
Ed Tanous14766872022-03-15 10:44:42 -07001658
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001659 ipv4Array.emplace_back(std::move(ipv4));
Ed Tanousbf648f72021-06-03 15:00:14 -07001660 }
1661
Jiaqing Zhao82695a52022-04-14 15:15:59 +08001662 std::string ipv6GatewayStr = ethData.ipv6DefaultGateway;
Ed Tanousbf648f72021-06-03 15:00:14 -07001663 if (ipv6GatewayStr.empty())
1664 {
1665 ipv6GatewayStr = "0:0:0:0:0:0:0:0";
1666 }
1667
1668 jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr;
1669
1670 nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"];
1671 nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"];
1672 ipv6Array = nlohmann::json::array();
1673 ipv6StaticArray = nlohmann::json::array();
1674 nlohmann::json& ipv6AddrPolicyTable =
1675 jsonResponse["IPv6AddressPolicyTable"];
1676 ipv6AddrPolicyTable = nlohmann::json::array();
Ed Tanous9eb808c2022-01-25 10:19:23 -08001677 for (const auto& ipv6Config : ipv6Data)
Ed Tanousbf648f72021-06-03 15:00:14 -07001678 {
Ed Tanous14766872022-03-15 10:44:42 -07001679 nlohmann::json::object_t ipv6;
1680 ipv6["Address"] = ipv6Config.address;
1681 ipv6["PrefixLength"] = ipv6Config.prefixLength;
1682 ipv6["AddressOrigin"] = ipv6Config.origin;
Sunitha Harishf8361272023-03-16 03:23:59 -05001683
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001684 ipv6Array.emplace_back(std::move(ipv6));
Ed Tanousbf648f72021-06-03 15:00:14 -07001685 if (ipv6Config.origin == "Static")
1686 {
Ed Tanous14766872022-03-15 10:44:42 -07001687 nlohmann::json::object_t ipv6Static;
1688 ipv6Static["Address"] = ipv6Config.address;
1689 ipv6Static["PrefixLength"] = ipv6Config.prefixLength;
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001690 ipv6StaticArray.emplace_back(std::move(ipv6Static));
Ed Tanousbf648f72021-06-03 15:00:14 -07001691 }
1692 }
1693}
1694
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08001695inline void afterDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1696 const std::string& ifaceId,
1697 const boost::system::error_code& ec,
1698 const sdbusplus::message_t& m)
1699{
1700 if (!ec)
1701 {
1702 return;
1703 }
1704 const sd_bus_error* dbusError = m.get_error();
1705 if (dbusError == nullptr)
1706 {
1707 messages::internalError(asyncResp->res);
1708 return;
1709 }
Ed Tanous62598e32023-07-17 17:06:25 -07001710 BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08001711
1712 if (std::string_view("org.freedesktop.DBus.Error.UnknownObject") ==
1713 dbusError->name)
1714 {
1715 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
1716 ifaceId);
1717 return;
1718 }
1719 if (std::string_view("org.freedesktop.DBus.Error.UnknownMethod") ==
1720 dbusError->name)
1721 {
1722 messages::resourceCannotBeDeleted(asyncResp->res);
1723 return;
1724 }
1725 messages::internalError(asyncResp->res);
1726}
1727
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08001728inline void afterVlanCreate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1729 const std::string& parentInterfaceUri,
1730 const std::string& vlanInterface,
1731 const boost::system::error_code& ec,
1732 const sdbusplus::message_t& m
1733
1734)
1735{
1736 if (ec)
1737 {
1738 const sd_bus_error* dbusError = m.get_error();
1739 if (dbusError == nullptr)
1740 {
1741 messages::internalError(asyncResp->res);
1742 return;
1743 }
Ed Tanous62598e32023-07-17 17:06:25 -07001744 BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08001745
1746 if (std::string_view(
1747 "xyz.openbmc_project.Common.Error.ResourceNotFound") ==
1748 dbusError->name)
1749 {
1750 messages::propertyValueNotInList(
1751 asyncResp->res, parentInterfaceUri,
1752 "Links/RelatedInterfaces/0/@odata.id");
1753 return;
1754 }
1755 if (std::string_view(
1756 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
1757 dbusError->name)
1758 {
1759 messages::resourceAlreadyExists(asyncResp->res, "EthernetInterface",
1760 "Id", vlanInterface);
1761 return;
1762 }
1763 messages::internalError(asyncResp->res);
1764 return;
1765 }
1766
1767 const boost::urls::url vlanInterfaceUri = boost::urls::format(
1768 "/redfish/v1/Managers/bmc/EthernetInterfaces/{}", vlanInterface);
1769 asyncResp->res.addHeader("Location", vlanInterfaceUri.buffer());
1770}
1771
Ed Tanousbf648f72021-06-03 15:00:14 -07001772inline void requestEthernetInterfacesRoutes(App& app)
1773{
1774 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/")
Ed Tanoused398212021-06-09 17:05:54 -07001775 .privileges(redfish::privileges::getEthernetInterfaceCollection)
Ed Tanous14766872022-03-15 10:44:42 -07001776 .methods(boost::beast::http::verb::get)(
1777 [&app](const crow::Request& req,
1778 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001779 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001780 {
1781 return;
1782 }
1783
1784 asyncResp->res.jsonValue["@odata.type"] =
1785 "#EthernetInterfaceCollection.EthernetInterfaceCollection";
1786 asyncResp->res.jsonValue["@odata.id"] =
1787 "/redfish/v1/Managers/bmc/EthernetInterfaces";
1788 asyncResp->res.jsonValue["Name"] =
1789 "Ethernet Network Interface Collection";
1790 asyncResp->res.jsonValue["Description"] =
1791 "Collection of EthernetInterfaces for this Manager";
1792
1793 // Get eth interface list, and call the below callback for JSON
1794 // preparation
1795 getEthernetIfaceList(
Ed Tanous77179532023-02-28 10:45:28 -08001796 [asyncResp](const bool& success,
1797 const std::vector<std::string>& ifaceList) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001798 if (!success)
1799 {
1800 messages::internalError(asyncResp->res);
1801 return;
1802 }
1803
1804 nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"];
1805 ifaceArray = nlohmann::json::array();
Ed Tanous002d39b2022-05-31 08:59:27 -07001806 for (const std::string& ifaceItem : ifaceList)
1807 {
Jiaqing Zhao7857cb82023-03-03 11:23:08 +08001808 nlohmann::json::object_t iface;
1809 iface["@odata.id"] = boost::urls::format(
1810 "/redfish/v1/Managers/bmc/EthernetInterfaces/{}",
1811 ifaceItem);
1812 ifaceArray.push_back(std::move(iface));
Ed Tanous002d39b2022-05-31 08:59:27 -07001813 }
Jason M. Billsf12894f2018-10-09 12:45:45 -07001814
Ed Tanous002d39b2022-05-31 08:59:27 -07001815 asyncResp->res.jsonValue["Members@odata.count"] = ifaceArray.size();
1816 asyncResp->res.jsonValue["@odata.id"] =
1817 "/redfish/v1/Managers/bmc/EthernetInterfaces";
1818 });
1819 });
Johnathan Mantey01784822019-06-18 12:44:21 -07001820
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08001821 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/")
1822 .privileges(redfish::privileges::postEthernetInterfaceCollection)
1823 .methods(boost::beast::http::verb::post)(
1824 [&app](const crow::Request& req,
1825 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
1826 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1827 {
1828 return;
1829 }
1830
1831 bool vlanEnable = false;
1832 uint32_t vlanId = 0;
1833 nlohmann::json::array_t relatedInterfaces;
1834
1835 if (!json_util::readJsonPatch(req, asyncResp->res, "VLAN/VLANEnable",
1836 vlanEnable, "VLAN/VLANId", vlanId,
1837 "Links/RelatedInterfaces",
1838 relatedInterfaces))
1839 {
1840 return;
1841 }
1842
1843 if (relatedInterfaces.size() != 1)
1844 {
1845 messages::arraySizeTooLong(asyncResp->res,
1846 "Links/RelatedInterfaces",
1847 relatedInterfaces.size());
1848 return;
1849 }
1850
1851 std::string parentInterfaceUri;
1852 if (!json_util::readJson(relatedInterfaces[0], asyncResp->res,
1853 "@odata.id", parentInterfaceUri))
1854 {
1855 messages::propertyMissing(asyncResp->res,
1856 "Links/RelatedInterfaces/0/@odata.id");
1857 return;
1858 }
Ed Tanous62598e32023-07-17 17:06:25 -07001859 BMCWEB_LOG_INFO("Parent Interface URI: {}", parentInterfaceUri);
Jiaqing Zhaob5ca3fd2023-03-08 15:14:58 +08001860
1861 boost::urls::result<boost::urls::url_view> parsedUri =
1862 boost::urls::parse_relative_ref(parentInterfaceUri);
1863 if (!parsedUri)
1864 {
1865 messages::propertyValueFormatError(
1866 asyncResp->res, parentInterfaceUri,
1867 "Links/RelatedInterfaces/0/@odata.id");
1868 return;
1869 }
1870
1871 std::string parentInterface;
1872 if (!crow::utility::readUrlSegments(
1873 *parsedUri, "redfish", "v1", "Managers", "bmc",
1874 "EthernetInterfaces", std::ref(parentInterface)))
1875 {
1876 messages::propertyValueNotInList(
1877 asyncResp->res, parentInterfaceUri,
1878 "Links/RelatedInterfaces/0/@odata.id");
1879 return;
1880 }
1881
1882 if (!vlanEnable)
1883 {
1884 // In OpenBMC implementation, VLANEnable cannot be false on
1885 // create
1886 messages::propertyValueIncorrect(asyncResp->res, "VLAN/VLANEnable",
1887 "false");
1888 return;
1889 }
1890
1891 std::string vlanInterface = parentInterface + "_" +
1892 std::to_string(vlanId);
1893 crow::connections::systemBus->async_method_call(
1894 [asyncResp, parentInterfaceUri,
1895 vlanInterface](const boost::system::error_code& ec,
1896 const sdbusplus::message_t& m) {
1897 afterVlanCreate(asyncResp, parentInterfaceUri, vlanInterface, ec,
1898 m);
1899 },
1900 "xyz.openbmc_project.Network", "/xyz/openbmc_project/network",
1901 "xyz.openbmc_project.Network.VLAN.Create", "VLAN", parentInterface,
1902 vlanId);
1903 });
1904
Ed Tanousbf648f72021-06-03 15:00:14 -07001905 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001906 .privileges(redfish::privileges::getEthernetInterface)
Ed Tanousbf648f72021-06-03 15:00:14 -07001907 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001908 [&app](const crow::Request& req,
1909 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1910 const std::string& ifaceId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001911 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001912 {
1913 return;
1914 }
1915 getEthernetIfaceData(
1916 ifaceId,
Ed Tanous77179532023-02-28 10:45:28 -08001917 [asyncResp, ifaceId](const bool& success,
1918 const EthernetInterfaceData& ethData,
1919 const std::vector<IPv4AddressData>& ipv4Data,
1920 const std::vector<IPv6AddressData>& ipv6Data) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001921 if (!success)
1922 {
1923 // TODO(Pawel)consider distinguish between non
1924 // existing object, and other errors
1925 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
1926 ifaceId);
1927 return;
1928 }
Johnathan Mantey01784822019-06-18 12:44:21 -07001929
Ed Tanous002d39b2022-05-31 08:59:27 -07001930 asyncResp->res.jsonValue["@odata.type"] =
Jiaqing Zhao93bbc952023-02-23 14:11:20 +08001931 "#EthernetInterface.v1_9_0.EthernetInterface";
Ed Tanous002d39b2022-05-31 08:59:27 -07001932 asyncResp->res.jsonValue["Name"] = "Manager Ethernet Interface";
1933 asyncResp->res.jsonValue["Description"] =
1934 "Management Network Interface";
Ratan Guptaf476acb2019-03-02 16:46:57 +05301935
Ed Tanous002d39b2022-05-31 08:59:27 -07001936 parseInterfaceData(asyncResp, ifaceId, ethData, ipv4Data, ipv6Data);
Ed Tanousbf648f72021-06-03 15:00:14 -07001937 });
Ed Tanous002d39b2022-05-31 08:59:27 -07001938 });
Johnathan Mantey01784822019-06-18 12:44:21 -07001939
Ed Tanousbf648f72021-06-03 15:00:14 -07001940 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07001941 .privileges(redfish::privileges::patchEthernetInterface)
Ed Tanousbf648f72021-06-03 15:00:14 -07001942 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001943 [&app](const crow::Request& req,
1944 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1945 const std::string& ifaceId) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001946 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001947 {
1948 return;
1949 }
1950 std::optional<std::string> hostname;
1951 std::optional<std::string> fqdn;
1952 std::optional<std::string> macAddress;
1953 std::optional<std::string> ipv6DefaultGateway;
Ed Tanousddd70dc2023-03-01 16:00:27 -08001954 std::optional<nlohmann::json::array_t> ipv4StaticAddresses;
1955 std::optional<nlohmann::json::array_t> ipv6StaticAddresses;
Ed Tanous002d39b2022-05-31 08:59:27 -07001956 std::optional<std::vector<std::string>> staticNameServers;
1957 std::optional<nlohmann::json> dhcpv4;
1958 std::optional<nlohmann::json> dhcpv6;
1959 std::optional<bool> interfaceEnabled;
1960 std::optional<size_t> mtuSize;
1961 DHCPParameters v4dhcpParms;
1962 DHCPParameters v6dhcpParms;
Ed Tanous1abe55e2018-09-05 08:30:59 -07001963
Ed Tanous002d39b2022-05-31 08:59:27 -07001964 if (!json_util::readJsonPatch(
1965 req, asyncResp->res, "HostName", hostname, "FQDN", fqdn,
1966 "IPv4StaticAddresses", ipv4StaticAddresses, "MACAddress",
1967 macAddress, "StaticNameServers", staticNameServers,
1968 "IPv6DefaultGateway", ipv6DefaultGateway, "IPv6StaticAddresses",
1969 ipv6StaticAddresses, "DHCPv4", dhcpv4, "DHCPv6", dhcpv6,
1970 "MTUSize", mtuSize, "InterfaceEnabled", interfaceEnabled))
1971 {
1972 return;
1973 }
1974 if (dhcpv4)
1975 {
1976 if (!json_util::readJson(*dhcpv4, asyncResp->res, "DHCPEnabled",
1977 v4dhcpParms.dhcpv4Enabled, "UseDNSServers",
1978 v4dhcpParms.useDnsServers, "UseNTPServers",
1979 v4dhcpParms.useNtpServers, "UseDomainName",
1980 v4dhcpParms.useDomainName))
1981 {
1982 return;
1983 }
1984 }
Johnathan Mantey01784822019-06-18 12:44:21 -07001985
Ed Tanous002d39b2022-05-31 08:59:27 -07001986 if (dhcpv6)
1987 {
1988 if (!json_util::readJson(*dhcpv6, asyncResp->res, "OperatingMode",
1989 v6dhcpParms.dhcpv6OperatingMode,
1990 "UseDNSServers", v6dhcpParms.useDnsServers,
1991 "UseNTPServers", v6dhcpParms.useNtpServers,
1992 "UseDomainName",
1993 v6dhcpParms.useDomainName))
1994 {
1995 return;
1996 }
1997 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -05001998
Ed Tanous002d39b2022-05-31 08:59:27 -07001999 // Get single eth interface data, and call the below callback
2000 // for JSON preparation
2001 getEthernetIfaceData(
2002 ifaceId,
2003 [asyncResp, ifaceId, hostname = std::move(hostname),
2004 fqdn = std::move(fqdn), macAddress = std::move(macAddress),
2005 ipv4StaticAddresses = std::move(ipv4StaticAddresses),
2006 ipv6DefaultGateway = std::move(ipv6DefaultGateway),
2007 ipv6StaticAddresses = std::move(ipv6StaticAddresses),
2008 staticNameServers = std::move(staticNameServers),
Ed Tanousbc200892022-06-30 17:49:12 -07002009 dhcpv4 = std::move(dhcpv4), dhcpv6 = std::move(dhcpv6), mtuSize,
2010 v4dhcpParms = std::move(v4dhcpParms),
Ed Tanous002d39b2022-05-31 08:59:27 -07002011 v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled](
2012 const bool& success, const EthernetInterfaceData& ethData,
Ed Tanous77179532023-02-28 10:45:28 -08002013 const std::vector<IPv4AddressData>& ipv4Data,
2014 const std::vector<IPv6AddressData>& ipv6Data) {
Ed Tanous002d39b2022-05-31 08:59:27 -07002015 if (!success)
2016 {
2017 // ... otherwise return error
2018 // TODO(Pawel)consider distinguish between non
2019 // existing object, and other errors
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +08002020 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
Ed Tanous002d39b2022-05-31 08:59:27 -07002021 ifaceId);
2022 return;
2023 }
Ravi Tejae48c0fc2019-04-16 08:37:20 -05002024
Ed Tanous002d39b2022-05-31 08:59:27 -07002025 if (dhcpv4 || dhcpv6)
2026 {
2027 handleDHCPPatch(ifaceId, ethData, v4dhcpParms, v6dhcpParms,
Ed Tanousbf648f72021-06-03 15:00:14 -07002028 asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -07002029 }
Tejas Patil35fb5312021-09-20 15:35:20 +05302030
Ed Tanous002d39b2022-05-31 08:59:27 -07002031 if (hostname)
2032 {
2033 handleHostnamePatch(*hostname, asyncResp);
2034 }
2035
2036 if (fqdn)
2037 {
2038 handleFqdnPatch(ifaceId, *fqdn, asyncResp);
2039 }
2040
2041 if (macAddress)
2042 {
2043 handleMACAddressPatch(ifaceId, *macAddress, asyncResp);
2044 }
2045
2046 if (ipv4StaticAddresses)
2047 {
2048 // TODO(ed) for some reason the capture of
2049 // ipv4Addresses above is returning a const value,
2050 // not a non-const value. This doesn't really work
2051 // for us, as we need to be able to efficiently move
2052 // out the intermedia nlohmann::json objects. This
2053 // makes a copy of the structure, and operates on
2054 // that, but could be done more efficiently
Ed Tanousddd70dc2023-03-01 16:00:27 -08002055 nlohmann::json::array_t ipv4Static = *ipv4StaticAddresses;
Ed Tanous002d39b2022-05-31 08:59:27 -07002056 handleIPv4StaticPatch(ifaceId, ipv4Static, ipv4Data, asyncResp);
2057 }
2058
2059 if (staticNameServers)
2060 {
2061 handleStaticNameServersPatch(ifaceId, *staticNameServers,
2062 asyncResp);
2063 }
2064
2065 if (ipv6DefaultGateway)
2066 {
2067 messages::propertyNotWritable(asyncResp->res,
2068 "IPv6DefaultGateway");
2069 }
2070
2071 if (ipv6StaticAddresses)
2072 {
Ed Tanousddd70dc2023-03-01 16:00:27 -08002073 handleIPv6StaticAddressesPatch(ifaceId, *ipv6StaticAddresses,
2074 ipv6Data, asyncResp);
Ed Tanous002d39b2022-05-31 08:59:27 -07002075 }
2076
2077 if (interfaceEnabled)
2078 {
2079 setEthernetInterfaceBoolProperty(ifaceId, "NICEnabled",
2080 *interfaceEnabled, asyncResp);
2081 }
2082
2083 if (mtuSize)
2084 {
2085 handleMTUSizePatch(ifaceId, *mtuSize, asyncResp);
2086 }
Ed Tanousbf648f72021-06-03 15:00:14 -07002087 });
Ed Tanous002d39b2022-05-31 08:59:27 -07002088 });
Jiaqing Zhaoe7caf252023-03-09 11:14:44 +08002089
2090 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/")
2091 .privileges(redfish::privileges::deleteEthernetInterface)
2092 .methods(boost::beast::http::verb::delete_)(
2093 [&app](const crow::Request& req,
2094 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2095 const std::string& ifaceId) {
2096 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2097 {
2098 return;
2099 }
2100
2101 crow::connections::systemBus->async_method_call(
2102 [asyncResp, ifaceId](const boost::system::error_code& ec,
2103 const sdbusplus::message_t& m) {
2104 afterDelete(asyncResp, ifaceId, ec, m);
2105 },
2106 "xyz.openbmc_project.Network",
2107 std::string("/xyz/openbmc_project/network/") + ifaceId,
2108 "xyz.openbmc_project.Object.Delete", "Delete");
2109 });
Ed Tanousbf648f72021-06-03 15:00:14 -07002110}
2111
Ed Tanous1abe55e2018-09-05 08:30:59 -07002112} // namespace redfish