xref: /openbmc/bmcweb/features/redfish/lib/ethernet.hpp (revision 8b24275d7696c9df071d11e16a0f905b1e800163)
19391bb9cSRapkiewicz, Pawel /*
29391bb9cSRapkiewicz, Pawel // Copyright (c) 2018 Intel Corporation
39391bb9cSRapkiewicz, Pawel //
49391bb9cSRapkiewicz, Pawel // Licensed under the Apache License, Version 2.0 (the "License");
59391bb9cSRapkiewicz, Pawel // you may not use this file except in compliance with the License.
69391bb9cSRapkiewicz, Pawel // You may obtain a copy of the License at
79391bb9cSRapkiewicz, Pawel //
89391bb9cSRapkiewicz, Pawel //      http://www.apache.org/licenses/LICENSE-2.0
99391bb9cSRapkiewicz, Pawel //
109391bb9cSRapkiewicz, Pawel // Unless required by applicable law or agreed to in writing, software
119391bb9cSRapkiewicz, Pawel // distributed under the License is distributed on an "AS IS" BASIS,
129391bb9cSRapkiewicz, Pawel // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139391bb9cSRapkiewicz, Pawel // See the License for the specific language governing permissions and
149391bb9cSRapkiewicz, Pawel // limitations under the License.
159391bb9cSRapkiewicz, Pawel */
169391bb9cSRapkiewicz, Pawel #pragma once
179391bb9cSRapkiewicz, Pawel 
1813451e39SWilly Tu #include "bmcweb_config.h"
1913451e39SWilly Tu 
203ccb3adbSEd Tanous #include "app.hpp"
213ccb3adbSEd Tanous #include "dbus_singleton.hpp"
227a1dbc48SGeorge Liu #include "dbus_utility.hpp"
233ccb3adbSEd Tanous #include "error_messages.hpp"
243ccb3adbSEd Tanous #include "health.hpp"
252c5875a2SEd Tanous #include "human_sort.hpp"
263ccb3adbSEd Tanous #include "query.hpp"
273ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
28033f1e4dSEd Tanous #include "utils/ip_utils.hpp"
293ccb3adbSEd Tanous #include "utils/json_utils.hpp"
30033f1e4dSEd Tanous 
3111ba3979SEd Tanous #include <boost/algorithm/string/classification.hpp>
3211ba3979SEd Tanous #include <boost/algorithm/string/split.hpp>
33ef4c65b7SEd Tanous #include <boost/url/format.hpp>
341214b7e7SGunnar Mills 
357a1dbc48SGeorge Liu #include <array>
36a24526dcSEd Tanous #include <optional>
37ab6554f1SJoshi-Mansi #include <regex>
387a1dbc48SGeorge Liu #include <string_view>
3977179532SEd Tanous #include <vector>
409391bb9cSRapkiewicz, Pawel 
411abe55efSEd Tanous namespace redfish
421abe55efSEd Tanous {
439391bb9cSRapkiewicz, Pawel 
444a0cb85cSEd Tanous enum class LinkType
454a0cb85cSEd Tanous {
464a0cb85cSEd Tanous     Local,
474a0cb85cSEd Tanous     Global
484a0cb85cSEd Tanous };
499391bb9cSRapkiewicz, Pawel 
509391bb9cSRapkiewicz, Pawel /**
519391bb9cSRapkiewicz, Pawel  * Structure for keeping IPv4 data required by Redfish
529391bb9cSRapkiewicz, Pawel  */
531abe55efSEd Tanous struct IPv4AddressData
541abe55efSEd Tanous {
55179db1d7SKowalski, Kamil     std::string id;
564a0cb85cSEd Tanous     std::string address;
574a0cb85cSEd Tanous     std::string domain;
584a0cb85cSEd Tanous     std::string gateway;
599391bb9cSRapkiewicz, Pawel     std::string netmask;
609391bb9cSRapkiewicz, Pawel     std::string origin;
6177179532SEd Tanous     LinkType linktype{};
6277179532SEd Tanous     bool isActive{};
639391bb9cSRapkiewicz, Pawel };
649391bb9cSRapkiewicz, Pawel 
659391bb9cSRapkiewicz, Pawel /**
66e48c0fc5SRavi Teja  * Structure for keeping IPv6 data required by Redfish
67e48c0fc5SRavi Teja  */
68e48c0fc5SRavi Teja struct IPv6AddressData
69e48c0fc5SRavi Teja {
70e48c0fc5SRavi Teja     std::string id;
71e48c0fc5SRavi Teja     std::string address;
72e48c0fc5SRavi Teja     std::string origin;
7377179532SEd Tanous     uint8_t prefixLength = 0;
74e48c0fc5SRavi Teja };
75e48c0fc5SRavi Teja /**
769391bb9cSRapkiewicz, Pawel  * Structure for keeping basic single Ethernet Interface information
779391bb9cSRapkiewicz, Pawel  * available from DBus
789391bb9cSRapkiewicz, Pawel  */
791abe55efSEd Tanous struct EthernetInterfaceData
801abe55efSEd Tanous {
814a0cb85cSEd Tanous     uint32_t speed;
8235fb5311STejas Patil     size_t mtuSize;
8382695a5bSJiaqing Zhao     bool autoNeg;
8482695a5bSJiaqing Zhao     bool dnsEnabled;
8582695a5bSJiaqing Zhao     bool ntpEnabled;
8682695a5bSJiaqing Zhao     bool hostNameEnabled;
87aa05fb27SJohnathan Mantey     bool linkUp;
88eeedda23SJohnathan Mantey     bool nicEnabled;
8982695a5bSJiaqing Zhao     std::string dhcpEnabled;
901f8c7b5dSJohnathan Mantey     std::string operatingMode;
9182695a5bSJiaqing Zhao     std::string hostName;
9282695a5bSJiaqing Zhao     std::string defaultGateway;
9382695a5bSJiaqing Zhao     std::string ipv6DefaultGateway;
9482695a5bSJiaqing Zhao     std::string macAddress;
9517e22024SJiaqing Zhao     std::optional<uint32_t> vlanId;
960f6efdc1Smanojkiran.eda@gmail.com     std::vector<std::string> nameServers;
970f6efdc1Smanojkiran.eda@gmail.com     std::vector<std::string> staticNameServers;
98d24bfc7aSJennifer Lee     std::vector<std::string> domainnames;
999391bb9cSRapkiewicz, Pawel };
1009391bb9cSRapkiewicz, Pawel 
1011f8c7b5dSJohnathan Mantey struct DHCPParameters
1021f8c7b5dSJohnathan Mantey {
1031f8c7b5dSJohnathan Mantey     std::optional<bool> dhcpv4Enabled;
10482695a5bSJiaqing Zhao     std::optional<bool> useDnsServers;
10582695a5bSJiaqing Zhao     std::optional<bool> useNtpServers;
10682695a5bSJiaqing Zhao     std::optional<bool> useDomainName;
1071f8c7b5dSJohnathan Mantey     std::optional<std::string> dhcpv6OperatingMode;
1081f8c7b5dSJohnathan Mantey };
1091f8c7b5dSJohnathan Mantey 
1109391bb9cSRapkiewicz, Pawel // Helper function that changes bits netmask notation (i.e. /24)
1119391bb9cSRapkiewicz, Pawel // into full dot notation
1121abe55efSEd Tanous inline std::string getNetmask(unsigned int bits)
1131abe55efSEd Tanous {
1149391bb9cSRapkiewicz, Pawel     uint32_t value = 0xffffffff << (32 - bits);
1159391bb9cSRapkiewicz, Pawel     std::string netmask = std::to_string((value >> 24) & 0xff) + "." +
1169391bb9cSRapkiewicz, Pawel                           std::to_string((value >> 16) & 0xff) + "." +
1179391bb9cSRapkiewicz, Pawel                           std::to_string((value >> 8) & 0xff) + "." +
1189391bb9cSRapkiewicz, Pawel                           std::to_string(value & 0xff);
1199391bb9cSRapkiewicz, Pawel     return netmask;
1209391bb9cSRapkiewicz, Pawel }
1219391bb9cSRapkiewicz, Pawel 
12282695a5bSJiaqing Zhao inline bool translateDhcpEnabledToBool(const std::string& inputDHCP,
1231f8c7b5dSJohnathan Mantey                                        bool isIPv4)
1241f8c7b5dSJohnathan Mantey {
1251f8c7b5dSJohnathan Mantey     if (isIPv4)
1261f8c7b5dSJohnathan Mantey     {
1271f8c7b5dSJohnathan Mantey         return (
1281f8c7b5dSJohnathan Mantey             (inputDHCP ==
1291f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4") ||
1301f8c7b5dSJohnathan Mantey             (inputDHCP ==
1311f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
1321f8c7b5dSJohnathan Mantey     }
1331f8c7b5dSJohnathan Mantey     return ((inputDHCP ==
1341f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") ||
1351f8c7b5dSJohnathan Mantey             (inputDHCP ==
1361f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
1371f8c7b5dSJohnathan Mantey }
1381f8c7b5dSJohnathan Mantey 
1392c70f800SEd Tanous inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6)
1401f8c7b5dSJohnathan Mantey {
1411f8c7b5dSJohnathan Mantey     if (isIPv4 && isIPv6)
1421f8c7b5dSJohnathan Mantey     {
1431f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both";
1441f8c7b5dSJohnathan Mantey     }
1453174e4dfSEd Tanous     if (isIPv4)
1461f8c7b5dSJohnathan Mantey     {
1471f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4";
1481f8c7b5dSJohnathan Mantey     }
1493174e4dfSEd Tanous     if (isIPv6)
1501f8c7b5dSJohnathan Mantey     {
1511f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6";
1521f8c7b5dSJohnathan Mantey     }
1531f8c7b5dSJohnathan Mantey     return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none";
1541f8c7b5dSJohnathan Mantey }
1551f8c7b5dSJohnathan Mantey 
1564a0cb85cSEd Tanous inline std::string
1574a0cb85cSEd Tanous     translateAddressOriginDbusToRedfish(const std::string& inputOrigin,
1584a0cb85cSEd Tanous                                         bool isIPv4)
1591abe55efSEd Tanous {
1604a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
1611abe55efSEd Tanous     {
1624a0cb85cSEd Tanous         return "Static";
1639391bb9cSRapkiewicz, Pawel     }
1644a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal")
1651abe55efSEd Tanous     {
1664a0cb85cSEd Tanous         if (isIPv4)
1671abe55efSEd Tanous         {
1684a0cb85cSEd Tanous             return "IPv4LinkLocal";
1691abe55efSEd Tanous         }
1704a0cb85cSEd Tanous         return "LinkLocal";
1719391bb9cSRapkiewicz, Pawel     }
1724a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
1731abe55efSEd Tanous     {
1744a0cb85cSEd Tanous         if (isIPv4)
1754a0cb85cSEd Tanous         {
1764a0cb85cSEd Tanous             return "DHCP";
1774a0cb85cSEd Tanous         }
1784a0cb85cSEd Tanous         return "DHCPv6";
1794a0cb85cSEd Tanous     }
1804a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC")
1814a0cb85cSEd Tanous     {
1824a0cb85cSEd Tanous         return "SLAAC";
1834a0cb85cSEd Tanous     }
1844a0cb85cSEd Tanous     return "";
1854a0cb85cSEd Tanous }
1864a0cb85cSEd Tanous 
18702cad96eSEd Tanous inline bool extractEthernetInterfaceData(
18802cad96eSEd Tanous     const std::string& ethifaceId,
18902cad96eSEd Tanous     const dbus::utility::ManagedObjectType& dbusData,
1904a0cb85cSEd Tanous     EthernetInterfaceData& ethData)
1914a0cb85cSEd Tanous {
1924c9afe43SEd Tanous     bool idFound = false;
19302cad96eSEd Tanous     for (const auto& objpath : dbusData)
1944a0cb85cSEd Tanous     {
19502cad96eSEd Tanous         for (const auto& ifacePair : objpath.second)
1964a0cb85cSEd Tanous         {
19781ce609eSEd Tanous             if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId)
198029573d4SEd Tanous             {
1994c9afe43SEd Tanous                 idFound = true;
2004a0cb85cSEd Tanous                 if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
2014a0cb85cSEd Tanous                 {
2024a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2034a0cb85cSEd Tanous                     {
2044a0cb85cSEd Tanous                         if (propertyPair.first == "MACAddress")
2054a0cb85cSEd Tanous                         {
2064a0cb85cSEd Tanous                             const std::string* mac =
207abf2add6SEd Tanous                                 std::get_if<std::string>(&propertyPair.second);
2084a0cb85cSEd Tanous                             if (mac != nullptr)
2094a0cb85cSEd Tanous                             {
21082695a5bSJiaqing Zhao                                 ethData.macAddress = *mac;
2114a0cb85cSEd Tanous                             }
2124a0cb85cSEd Tanous                         }
2134a0cb85cSEd Tanous                     }
2144a0cb85cSEd Tanous                 }
2154a0cb85cSEd Tanous                 else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN")
2164a0cb85cSEd Tanous                 {
2174a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2184a0cb85cSEd Tanous                     {
2194a0cb85cSEd Tanous                         if (propertyPair.first == "Id")
2204a0cb85cSEd Tanous                         {
2211b6b96c5SEd Tanous                             const uint32_t* id =
222abf2add6SEd Tanous                                 std::get_if<uint32_t>(&propertyPair.second);
2234a0cb85cSEd Tanous                             if (id != nullptr)
2244a0cb85cSEd Tanous                             {
22517e22024SJiaqing Zhao                                 ethData.vlanId = *id;
2264a0cb85cSEd Tanous                             }
2274a0cb85cSEd Tanous                         }
2284a0cb85cSEd Tanous                     }
2294a0cb85cSEd Tanous                 }
2304a0cb85cSEd Tanous                 else if (ifacePair.first ==
2314a0cb85cSEd Tanous                          "xyz.openbmc_project.Network.EthernetInterface")
2324a0cb85cSEd Tanous                 {
2334a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2344a0cb85cSEd Tanous                     {
2354a0cb85cSEd Tanous                         if (propertyPair.first == "AutoNeg")
2364a0cb85cSEd Tanous                         {
2372c70f800SEd Tanous                             const bool* autoNeg =
238abf2add6SEd Tanous                                 std::get_if<bool>(&propertyPair.second);
2392c70f800SEd Tanous                             if (autoNeg != nullptr)
2404a0cb85cSEd Tanous                             {
24182695a5bSJiaqing Zhao                                 ethData.autoNeg = *autoNeg;
2424a0cb85cSEd Tanous                             }
2434a0cb85cSEd Tanous                         }
2444a0cb85cSEd Tanous                         else if (propertyPair.first == "Speed")
2454a0cb85cSEd Tanous                         {
2464a0cb85cSEd Tanous                             const uint32_t* speed =
247abf2add6SEd Tanous                                 std::get_if<uint32_t>(&propertyPair.second);
2484a0cb85cSEd Tanous                             if (speed != nullptr)
2494a0cb85cSEd Tanous                             {
2504a0cb85cSEd Tanous                                 ethData.speed = *speed;
2514a0cb85cSEd Tanous                             }
2524a0cb85cSEd Tanous                         }
25335fb5311STejas Patil                         else if (propertyPair.first == "MTU")
25435fb5311STejas Patil                         {
25535fb5311STejas Patil                             const uint32_t* mtuSize =
25635fb5311STejas Patil                                 std::get_if<uint32_t>(&propertyPair.second);
25735fb5311STejas Patil                             if (mtuSize != nullptr)
25835fb5311STejas Patil                             {
25935fb5311STejas Patil                                 ethData.mtuSize = *mtuSize;
26035fb5311STejas Patil                             }
26135fb5311STejas Patil                         }
262aa05fb27SJohnathan Mantey                         else if (propertyPair.first == "LinkUp")
263aa05fb27SJohnathan Mantey                         {
264aa05fb27SJohnathan Mantey                             const bool* linkUp =
265aa05fb27SJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
266aa05fb27SJohnathan Mantey                             if (linkUp != nullptr)
267aa05fb27SJohnathan Mantey                             {
268aa05fb27SJohnathan Mantey                                 ethData.linkUp = *linkUp;
269aa05fb27SJohnathan Mantey                             }
270aa05fb27SJohnathan Mantey                         }
271eeedda23SJohnathan Mantey                         else if (propertyPair.first == "NICEnabled")
272eeedda23SJohnathan Mantey                         {
273eeedda23SJohnathan Mantey                             const bool* nicEnabled =
274eeedda23SJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
275eeedda23SJohnathan Mantey                             if (nicEnabled != nullptr)
276eeedda23SJohnathan Mantey                             {
277eeedda23SJohnathan Mantey                                 ethData.nicEnabled = *nicEnabled;
278eeedda23SJohnathan Mantey                             }
279eeedda23SJohnathan Mantey                         }
280f85837bfSRAJESWARAN THILLAIGOVINDAN                         else if (propertyPair.first == "Nameservers")
281029573d4SEd Tanous                         {
282029573d4SEd Tanous                             const std::vector<std::string>* nameservers =
2838d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
284029573d4SEd Tanous                                     &propertyPair.second);
285029573d4SEd Tanous                             if (nameservers != nullptr)
286029573d4SEd Tanous                             {
287f23b7296SEd Tanous                                 ethData.nameServers = *nameservers;
2880f6efdc1Smanojkiran.eda@gmail.com                             }
2890f6efdc1Smanojkiran.eda@gmail.com                         }
2900f6efdc1Smanojkiran.eda@gmail.com                         else if (propertyPair.first == "StaticNameServers")
2910f6efdc1Smanojkiran.eda@gmail.com                         {
2920f6efdc1Smanojkiran.eda@gmail.com                             const std::vector<std::string>* staticNameServers =
2938d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
2940f6efdc1Smanojkiran.eda@gmail.com                                     &propertyPair.second);
2950f6efdc1Smanojkiran.eda@gmail.com                             if (staticNameServers != nullptr)
2960f6efdc1Smanojkiran.eda@gmail.com                             {
297f23b7296SEd Tanous                                 ethData.staticNameServers = *staticNameServers;
2984a0cb85cSEd Tanous                             }
2994a0cb85cSEd Tanous                         }
3002a133282Smanojkiraneda                         else if (propertyPair.first == "DHCPEnabled")
3012a133282Smanojkiraneda                         {
3022c70f800SEd Tanous                             const std::string* dhcpEnabled =
3031f8c7b5dSJohnathan Mantey                                 std::get_if<std::string>(&propertyPair.second);
3042c70f800SEd Tanous                             if (dhcpEnabled != nullptr)
3052a133282Smanojkiraneda                             {
30682695a5bSJiaqing Zhao                                 ethData.dhcpEnabled = *dhcpEnabled;
3072a133282Smanojkiraneda                             }
3082a133282Smanojkiraneda                         }
309d24bfc7aSJennifer Lee                         else if (propertyPair.first == "DomainName")
310d24bfc7aSJennifer Lee                         {
311d24bfc7aSJennifer Lee                             const std::vector<std::string>* domainNames =
3128d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
313d24bfc7aSJennifer Lee                                     &propertyPair.second);
314d24bfc7aSJennifer Lee                             if (domainNames != nullptr)
315d24bfc7aSJennifer Lee                             {
316f23b7296SEd Tanous                                 ethData.domainnames = *domainNames;
317d24bfc7aSJennifer Lee                             }
318d24bfc7aSJennifer Lee                         }
3199010ec2eSRavi Teja                         else if (propertyPair.first == "DefaultGateway")
3209010ec2eSRavi Teja                         {
3219010ec2eSRavi Teja                             const std::string* defaultGateway =
3229010ec2eSRavi Teja                                 std::get_if<std::string>(&propertyPair.second);
3239010ec2eSRavi Teja                             if (defaultGateway != nullptr)
3249010ec2eSRavi Teja                             {
3259010ec2eSRavi Teja                                 std::string defaultGatewayStr = *defaultGateway;
3269010ec2eSRavi Teja                                 if (defaultGatewayStr.empty())
3279010ec2eSRavi Teja                                 {
32882695a5bSJiaqing Zhao                                     ethData.defaultGateway = "0.0.0.0";
3299010ec2eSRavi Teja                                 }
3309010ec2eSRavi Teja                                 else
3319010ec2eSRavi Teja                                 {
33282695a5bSJiaqing Zhao                                     ethData.defaultGateway = defaultGatewayStr;
3339010ec2eSRavi Teja                                 }
3349010ec2eSRavi Teja                             }
3359010ec2eSRavi Teja                         }
3369010ec2eSRavi Teja                         else if (propertyPair.first == "DefaultGateway6")
3379010ec2eSRavi Teja                         {
3389010ec2eSRavi Teja                             const std::string* defaultGateway6 =
3399010ec2eSRavi Teja                                 std::get_if<std::string>(&propertyPair.second);
3409010ec2eSRavi Teja                             if (defaultGateway6 != nullptr)
3419010ec2eSRavi Teja                             {
3429010ec2eSRavi Teja                                 std::string defaultGateway6Str =
3439010ec2eSRavi Teja                                     *defaultGateway6;
3449010ec2eSRavi Teja                                 if (defaultGateway6Str.empty())
3459010ec2eSRavi Teja                                 {
34682695a5bSJiaqing Zhao                                     ethData.ipv6DefaultGateway =
3479010ec2eSRavi Teja                                         "0:0:0:0:0:0:0:0";
3489010ec2eSRavi Teja                                 }
3499010ec2eSRavi Teja                                 else
3509010ec2eSRavi Teja                                 {
35182695a5bSJiaqing Zhao                                     ethData.ipv6DefaultGateway =
3529010ec2eSRavi Teja                                         defaultGateway6Str;
3539010ec2eSRavi Teja                                 }
3549010ec2eSRavi Teja                             }
3559010ec2eSRavi Teja                         }
356029573d4SEd Tanous                     }
357029573d4SEd Tanous                 }
358029573d4SEd Tanous             }
3591f8c7b5dSJohnathan Mantey 
3601e3f85e6SJian Zhang             if (objpath.first == "/xyz/openbmc_project/network/dhcp")
3611f8c7b5dSJohnathan Mantey             {
3621f8c7b5dSJohnathan Mantey                 if (ifacePair.first ==
3631f8c7b5dSJohnathan Mantey                     "xyz.openbmc_project.Network.DHCPConfiguration")
3641f8c7b5dSJohnathan Mantey                 {
3651f8c7b5dSJohnathan Mantey                     for (const auto& propertyPair : ifacePair.second)
3661f8c7b5dSJohnathan Mantey                     {
3671f8c7b5dSJohnathan Mantey                         if (propertyPair.first == "DNSEnabled")
3681f8c7b5dSJohnathan Mantey                         {
3692c70f800SEd Tanous                             const bool* dnsEnabled =
3701f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
3712c70f800SEd Tanous                             if (dnsEnabled != nullptr)
3721f8c7b5dSJohnathan Mantey                             {
37382695a5bSJiaqing Zhao                                 ethData.dnsEnabled = *dnsEnabled;
3741f8c7b5dSJohnathan Mantey                             }
3751f8c7b5dSJohnathan Mantey                         }
3761f8c7b5dSJohnathan Mantey                         else if (propertyPair.first == "NTPEnabled")
3771f8c7b5dSJohnathan Mantey                         {
3782c70f800SEd Tanous                             const bool* ntpEnabled =
3791f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
3802c70f800SEd Tanous                             if (ntpEnabled != nullptr)
3811f8c7b5dSJohnathan Mantey                             {
38282695a5bSJiaqing Zhao                                 ethData.ntpEnabled = *ntpEnabled;
3831f8c7b5dSJohnathan Mantey                             }
3841f8c7b5dSJohnathan Mantey                         }
3851f8c7b5dSJohnathan Mantey                         else if (propertyPair.first == "HostNameEnabled")
3861f8c7b5dSJohnathan Mantey                         {
3872c70f800SEd Tanous                             const bool* hostNameEnabled =
3881f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
3892c70f800SEd Tanous                             if (hostNameEnabled != nullptr)
3901f8c7b5dSJohnathan Mantey                             {
39182695a5bSJiaqing Zhao                                 ethData.hostNameEnabled = *hostNameEnabled;
3921f8c7b5dSJohnathan Mantey                             }
3931f8c7b5dSJohnathan Mantey                         }
3941f8c7b5dSJohnathan Mantey                     }
3951f8c7b5dSJohnathan Mantey                 }
3961f8c7b5dSJohnathan Mantey             }
397029573d4SEd Tanous             // System configuration shows up in the global namespace, so no need
398029573d4SEd Tanous             // to check eth number
399029573d4SEd Tanous             if (ifacePair.first ==
4004a0cb85cSEd Tanous                 "xyz.openbmc_project.Network.SystemConfiguration")
4014a0cb85cSEd Tanous             {
4024a0cb85cSEd Tanous                 for (const auto& propertyPair : ifacePair.second)
4034a0cb85cSEd Tanous                 {
4044a0cb85cSEd Tanous                     if (propertyPair.first == "HostName")
4054a0cb85cSEd Tanous                     {
4064a0cb85cSEd Tanous                         const std::string* hostname =
4078d78b7a9SPatrick Williams                             std::get_if<std::string>(&propertyPair.second);
4084a0cb85cSEd Tanous                         if (hostname != nullptr)
4094a0cb85cSEd Tanous                         {
41082695a5bSJiaqing Zhao                             ethData.hostName = *hostname;
4114a0cb85cSEd Tanous                         }
4124a0cb85cSEd Tanous                     }
4134a0cb85cSEd Tanous                 }
4144a0cb85cSEd Tanous             }
4154a0cb85cSEd Tanous         }
4164a0cb85cSEd Tanous     }
4174c9afe43SEd Tanous     return idFound;
4184a0cb85cSEd Tanous }
4194a0cb85cSEd Tanous 
420e48c0fc5SRavi Teja // Helper function that extracts data for single ethernet ipv6 address
42177179532SEd Tanous inline void extractIPV6Data(const std::string& ethifaceId,
422711ac7a9SEd Tanous                             const dbus::utility::ManagedObjectType& dbusData,
42377179532SEd Tanous                             std::vector<IPv6AddressData>& ipv6Config)
424e48c0fc5SRavi Teja {
42589492a15SPatrick Williams     const std::string ipPathStart = "/xyz/openbmc_project/network/" +
42689492a15SPatrick Williams                                     ethifaceId;
427e48c0fc5SRavi Teja 
428e48c0fc5SRavi Teja     // Since there might be several IPv6 configurations aligned with
429e48c0fc5SRavi Teja     // single ethernet interface, loop over all of them
43081ce609eSEd Tanous     for (const auto& objpath : dbusData)
431e48c0fc5SRavi Teja     {
432e48c0fc5SRavi Teja         // Check if proper pattern for object path appears
433353163e9STony Lee         if (objpath.first.str.starts_with(ipPathStart + "/"))
434e48c0fc5SRavi Teja         {
4359eb808c1SEd Tanous             for (const auto& interface : objpath.second)
436e48c0fc5SRavi Teja             {
437e48c0fc5SRavi Teja                 if (interface.first == "xyz.openbmc_project.Network.IP")
438e48c0fc5SRavi Teja                 {
439353163e9STony Lee                     auto type = std::find_if(interface.second.begin(),
440353163e9STony Lee                                              interface.second.end(),
441353163e9STony Lee                                              [](const auto& property) {
442353163e9STony Lee                         return property.first == "Type";
443353163e9STony Lee                     });
444353163e9STony Lee                     if (type == interface.second.end())
445353163e9STony Lee                     {
446353163e9STony Lee                         continue;
447353163e9STony Lee                     }
448353163e9STony Lee 
449353163e9STony Lee                     const std::string* typeStr =
450353163e9STony Lee                         std::get_if<std::string>(&type->second);
451353163e9STony Lee 
452353163e9STony Lee                     if (typeStr == nullptr ||
453353163e9STony Lee                         (*typeStr !=
454353163e9STony Lee                          "xyz.openbmc_project.Network.IP.Protocol.IPv6"))
455353163e9STony Lee                     {
456353163e9STony Lee                         continue;
457353163e9STony Lee                     }
458353163e9STony Lee 
459e48c0fc5SRavi Teja                     // Instance IPv6AddressData structure, and set as
460e48c0fc5SRavi Teja                     // appropriate
46177179532SEd Tanous                     IPv6AddressData& ipv6Address = ipv6Config.emplace_back();
4622c70f800SEd Tanous                     ipv6Address.id =
463353163e9STony Lee                         objpath.first.str.substr(ipPathStart.size());
4649eb808c1SEd Tanous                     for (const auto& property : interface.second)
465e48c0fc5SRavi Teja                     {
466e48c0fc5SRavi Teja                         if (property.first == "Address")
467e48c0fc5SRavi Teja                         {
468e48c0fc5SRavi Teja                             const std::string* address =
469e48c0fc5SRavi Teja                                 std::get_if<std::string>(&property.second);
470e48c0fc5SRavi Teja                             if (address != nullptr)
471e48c0fc5SRavi Teja                             {
4722c70f800SEd Tanous                                 ipv6Address.address = *address;
473e48c0fc5SRavi Teja                             }
474e48c0fc5SRavi Teja                         }
475e48c0fc5SRavi Teja                         else if (property.first == "Origin")
476e48c0fc5SRavi Teja                         {
477e48c0fc5SRavi Teja                             const std::string* origin =
478e48c0fc5SRavi Teja                                 std::get_if<std::string>(&property.second);
479e48c0fc5SRavi Teja                             if (origin != nullptr)
480e48c0fc5SRavi Teja                             {
4812c70f800SEd Tanous                                 ipv6Address.origin =
482e48c0fc5SRavi Teja                                     translateAddressOriginDbusToRedfish(*origin,
483e48c0fc5SRavi Teja                                                                         false);
484e48c0fc5SRavi Teja                             }
485e48c0fc5SRavi Teja                         }
486e48c0fc5SRavi Teja                         else if (property.first == "PrefixLength")
487e48c0fc5SRavi Teja                         {
488e48c0fc5SRavi Teja                             const uint8_t* prefix =
489e48c0fc5SRavi Teja                                 std::get_if<uint8_t>(&property.second);
490e48c0fc5SRavi Teja                             if (prefix != nullptr)
491e48c0fc5SRavi Teja                             {
4922c70f800SEd Tanous                                 ipv6Address.prefixLength = *prefix;
493e48c0fc5SRavi Teja                             }
494e48c0fc5SRavi Teja                         }
495889ff694SAsmitha Karunanithi                         else if (property.first == "Type" ||
496889ff694SAsmitha Karunanithi                                  property.first == "Gateway")
497889ff694SAsmitha Karunanithi                         {
498889ff694SAsmitha Karunanithi                             // Type & Gateway is not used
499889ff694SAsmitha Karunanithi                         }
500e48c0fc5SRavi Teja                         else
501e48c0fc5SRavi Teja                         {
502e48c0fc5SRavi Teja                             BMCWEB_LOG_ERROR
503e48c0fc5SRavi Teja                                 << "Got extra property: " << property.first
504e48c0fc5SRavi Teja                                 << " on the " << objpath.first.str << " object";
505e48c0fc5SRavi Teja                         }
506e48c0fc5SRavi Teja                     }
507e48c0fc5SRavi Teja                 }
508e48c0fc5SRavi Teja             }
509e48c0fc5SRavi Teja         }
510e48c0fc5SRavi Teja     }
511e48c0fc5SRavi Teja }
512e48c0fc5SRavi Teja 
5134a0cb85cSEd Tanous // Helper function that extracts data for single ethernet ipv4 address
51477179532SEd Tanous inline void extractIPData(const std::string& ethifaceId,
515711ac7a9SEd Tanous                           const dbus::utility::ManagedObjectType& dbusData,
51677179532SEd Tanous                           std::vector<IPv4AddressData>& ipv4Config)
5174a0cb85cSEd Tanous {
51889492a15SPatrick Williams     const std::string ipPathStart = "/xyz/openbmc_project/network/" +
51989492a15SPatrick Williams                                     ethifaceId;
5204a0cb85cSEd Tanous 
5214a0cb85cSEd Tanous     // Since there might be several IPv4 configurations aligned with
5224a0cb85cSEd Tanous     // single ethernet interface, loop over all of them
52381ce609eSEd Tanous     for (const auto& objpath : dbusData)
5244a0cb85cSEd Tanous     {
5254a0cb85cSEd Tanous         // Check if proper pattern for object path appears
526353163e9STony Lee         if (objpath.first.str.starts_with(ipPathStart + "/"))
5274a0cb85cSEd Tanous         {
5289eb808c1SEd Tanous             for (const auto& interface : objpath.second)
5294a0cb85cSEd Tanous             {
5304a0cb85cSEd Tanous                 if (interface.first == "xyz.openbmc_project.Network.IP")
5314a0cb85cSEd Tanous                 {
532353163e9STony Lee                     auto type = std::find_if(interface.second.begin(),
533353163e9STony Lee                                              interface.second.end(),
534353163e9STony Lee                                              [](const auto& property) {
535353163e9STony Lee                         return property.first == "Type";
536353163e9STony Lee                     });
537353163e9STony Lee                     if (type == interface.second.end())
538353163e9STony Lee                     {
539353163e9STony Lee                         continue;
540353163e9STony Lee                     }
541353163e9STony Lee 
542353163e9STony Lee                     const std::string* typeStr =
543353163e9STony Lee                         std::get_if<std::string>(&type->second);
544353163e9STony Lee 
545353163e9STony Lee                     if (typeStr == nullptr ||
546353163e9STony Lee                         (*typeStr !=
547353163e9STony Lee                          "xyz.openbmc_project.Network.IP.Protocol.IPv4"))
548353163e9STony Lee                     {
549353163e9STony Lee                         continue;
550353163e9STony Lee                     }
551353163e9STony Lee 
5524a0cb85cSEd Tanous                     // Instance IPv4AddressData structure, and set as
5534a0cb85cSEd Tanous                     // appropriate
55477179532SEd Tanous                     IPv4AddressData& ipv4Address = ipv4Config.emplace_back();
5552c70f800SEd Tanous                     ipv4Address.id =
556353163e9STony Lee                         objpath.first.str.substr(ipPathStart.size());
5579eb808c1SEd Tanous                     for (const auto& property : interface.second)
5584a0cb85cSEd Tanous                     {
5594a0cb85cSEd Tanous                         if (property.first == "Address")
5604a0cb85cSEd Tanous                         {
5614a0cb85cSEd Tanous                             const std::string* address =
562abf2add6SEd Tanous                                 std::get_if<std::string>(&property.second);
5634a0cb85cSEd Tanous                             if (address != nullptr)
5644a0cb85cSEd Tanous                             {
5652c70f800SEd Tanous                                 ipv4Address.address = *address;
5664a0cb85cSEd Tanous                             }
5674a0cb85cSEd Tanous                         }
5684a0cb85cSEd Tanous                         else if (property.first == "Origin")
5694a0cb85cSEd Tanous                         {
5704a0cb85cSEd Tanous                             const std::string* origin =
571abf2add6SEd Tanous                                 std::get_if<std::string>(&property.second);
5724a0cb85cSEd Tanous                             if (origin != nullptr)
5734a0cb85cSEd Tanous                             {
5742c70f800SEd Tanous                                 ipv4Address.origin =
5754a0cb85cSEd Tanous                                     translateAddressOriginDbusToRedfish(*origin,
5764a0cb85cSEd Tanous                                                                         true);
5774a0cb85cSEd Tanous                             }
5784a0cb85cSEd Tanous                         }
5794a0cb85cSEd Tanous                         else if (property.first == "PrefixLength")
5804a0cb85cSEd Tanous                         {
5814a0cb85cSEd Tanous                             const uint8_t* mask =
582abf2add6SEd Tanous                                 std::get_if<uint8_t>(&property.second);
5834a0cb85cSEd Tanous                             if (mask != nullptr)
5844a0cb85cSEd Tanous                             {
5854a0cb85cSEd Tanous                                 // convert it to the string
5862c70f800SEd Tanous                                 ipv4Address.netmask = getNetmask(*mask);
5874a0cb85cSEd Tanous                             }
5884a0cb85cSEd Tanous                         }
589889ff694SAsmitha Karunanithi                         else if (property.first == "Type" ||
590889ff694SAsmitha Karunanithi                                  property.first == "Gateway")
591889ff694SAsmitha Karunanithi                         {
592889ff694SAsmitha Karunanithi                             // Type & Gateway is not used
593889ff694SAsmitha Karunanithi                         }
5944a0cb85cSEd Tanous                         else
5954a0cb85cSEd Tanous                         {
5964a0cb85cSEd Tanous                             BMCWEB_LOG_ERROR
5974a0cb85cSEd Tanous                                 << "Got extra property: " << property.first
5984a0cb85cSEd Tanous                                 << " on the " << objpath.first.str << " object";
5994a0cb85cSEd Tanous                         }
6004a0cb85cSEd Tanous                     }
6014a0cb85cSEd Tanous                     // Check if given address is local, or global
6022c70f800SEd Tanous                     ipv4Address.linktype =
60311ba3979SEd Tanous                         ipv4Address.address.starts_with("169.254.")
60418659d10SJohnathan Mantey                             ? LinkType::Local
60518659d10SJohnathan Mantey                             : LinkType::Global;
6064a0cb85cSEd Tanous                 }
6074a0cb85cSEd Tanous             }
6084a0cb85cSEd Tanous         }
6094a0cb85cSEd Tanous     }
6104a0cb85cSEd Tanous }
611588c3f0dSKowalski, Kamil 
612588c3f0dSKowalski, Kamil /**
61301784826SJohnathan Mantey  * @brief Deletes given IPv4 interface
614179db1d7SKowalski, Kamil  *
615179db1d7SKowalski, Kamil  * @param[in] ifaceId     Id of interface whose IP should be deleted
616179db1d7SKowalski, Kamil  * @param[in] ipHash      DBus Hash id of IP that should be deleted
617179db1d7SKowalski, Kamil  * @param[io] asyncResp   Response object that will be returned to client
618179db1d7SKowalski, Kamil  *
619179db1d7SKowalski, Kamil  * @return None
620179db1d7SKowalski, Kamil  */
6219c5e585cSRavi Teja inline void deleteIPAddress(const std::string& ifaceId,
6229c5e585cSRavi Teja                             const std::string& ipHash,
6238d1b46d7Szhanghch05                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
6241abe55efSEd Tanous {
62555c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
6265e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
6271abe55efSEd Tanous         if (ec)
6281abe55efSEd Tanous         {
629a08b46ccSJason M. Bills             messages::internalError(asyncResp->res);
6301abe55efSEd Tanous         }
631179db1d7SKowalski, Kamil         },
632179db1d7SKowalski, Kamil         "xyz.openbmc_project.Network",
6339c5e585cSRavi Teja         "/xyz/openbmc_project/network/" + ifaceId + ipHash,
634179db1d7SKowalski, Kamil         "xyz.openbmc_project.Object.Delete", "Delete");
635179db1d7SKowalski, Kamil }
636179db1d7SKowalski, Kamil 
637244b6d5bSGunnar Mills inline void updateIPv4DefaultGateway(
638244b6d5bSGunnar Mills     const std::string& ifaceId, const std::string& gateway,
639244b6d5bSGunnar Mills     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
6409010ec2eSRavi Teja {
6419ae226faSGeorge Liu     sdbusplus::asio::setProperty(
6429ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
6439ae226faSGeorge Liu         "/xyz/openbmc_project/network/" + ifaceId,
6449ae226faSGeorge Liu         "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway",
6459ae226faSGeorge Liu         gateway, [asyncResp](const boost::system::error_code& ec) {
6469010ec2eSRavi Teja             if (ec)
6479010ec2eSRavi Teja             {
6489010ec2eSRavi Teja                 messages::internalError(asyncResp->res);
6499010ec2eSRavi Teja                 return;
6509010ec2eSRavi Teja             }
6519010ec2eSRavi Teja             asyncResp->res.result(boost::beast::http::status::no_content);
6529ae226faSGeorge Liu         });
6539010ec2eSRavi Teja }
654179db1d7SKowalski, Kamil /**
65501784826SJohnathan Mantey  * @brief Creates a static IPv4 entry
656179db1d7SKowalski, Kamil  *
65701784826SJohnathan Mantey  * @param[in] ifaceId      Id of interface upon which to create the IPv4 entry
65801784826SJohnathan Mantey  * @param[in] prefixLength IPv4 prefix syntax for the subnet mask
65901784826SJohnathan Mantey  * @param[in] gateway      IPv4 address of this interfaces gateway
66001784826SJohnathan Mantey  * @param[in] address      IPv4 address to assign to this interface
661179db1d7SKowalski, Kamil  * @param[io] asyncResp    Response object that will be returned to client
662179db1d7SKowalski, Kamil  *
663179db1d7SKowalski, Kamil  * @return None
664179db1d7SKowalski, Kamil  */
665cb13a392SEd Tanous inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
666cb13a392SEd Tanous                        const std::string& gateway, const std::string& address,
6678d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
6681abe55efSEd Tanous {
669002d39b4SEd Tanous     auto createIpHandler =
6705e7e2dc5SEd Tanous         [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
6711abe55efSEd Tanous         if (ec)
6721abe55efSEd Tanous         {
673a08b46ccSJason M. Bills             messages::internalError(asyncResp->res);
6749010ec2eSRavi Teja             return;
675179db1d7SKowalski, Kamil         }
6769010ec2eSRavi Teja         updateIPv4DefaultGateway(ifaceId, gateway, asyncResp);
6779010ec2eSRavi Teja     };
6789010ec2eSRavi Teja 
6799010ec2eSRavi Teja     crow::connections::systemBus->async_method_call(
6809010ec2eSRavi Teja         std::move(createIpHandler), "xyz.openbmc_project.Network",
681179db1d7SKowalski, Kamil         "/xyz/openbmc_project/network/" + ifaceId,
682179db1d7SKowalski, Kamil         "xyz.openbmc_project.Network.IP.Create", "IP",
68301784826SJohnathan Mantey         "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength,
684179db1d7SKowalski, Kamil         gateway);
685179db1d7SKowalski, Kamil }
686e48c0fc5SRavi Teja 
687e48c0fc5SRavi Teja /**
68801784826SJohnathan Mantey  * @brief Deletes the IPv6 entry for this interface and creates a replacement
68901784826SJohnathan Mantey  * static IPv6 entry
69001784826SJohnathan Mantey  *
69101784826SJohnathan Mantey  * @param[in] ifaceId      Id of interface upon which to create the IPv6 entry
69201784826SJohnathan Mantey  * @param[in] id           The unique hash entry identifying the DBus entry
69301784826SJohnathan Mantey  * @param[in] prefixLength IPv6 prefix syntax for the subnet mask
69401784826SJohnathan Mantey  * @param[in] address      IPv6 address to assign to this interface
69501784826SJohnathan Mantey  * @param[io] asyncResp    Response object that will be returned to client
69601784826SJohnathan Mantey  *
69701784826SJohnathan Mantey  * @return None
69801784826SJohnathan Mantey  */
6999c5e585cSRavi Teja 
7009c5e585cSRavi Teja enum class IpVersion
7019c5e585cSRavi Teja {
7029c5e585cSRavi Teja     IpV4,
7039c5e585cSRavi Teja     IpV6
7049c5e585cSRavi Teja };
7059c5e585cSRavi Teja 
7069c5e585cSRavi Teja inline void deleteAndCreateIPAddress(
7079c5e585cSRavi Teja     IpVersion version, const std::string& ifaceId, const std::string& id,
7088d1b46d7Szhanghch05     uint8_t prefixLength, const std::string& address,
7099c5e585cSRavi Teja     const std::string& gateway,
7108d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
71101784826SJohnathan Mantey {
71201784826SJohnathan Mantey     crow::connections::systemBus->async_method_call(
7139c5e585cSRavi Teja         [asyncResp, version, ifaceId, address, prefixLength,
7149c5e585cSRavi Teja          gateway](const boost::system::error_code& ec) {
71501784826SJohnathan Mantey         if (ec)
71601784826SJohnathan Mantey         {
71701784826SJohnathan Mantey             messages::internalError(asyncResp->res);
71801784826SJohnathan Mantey         }
7199c5e585cSRavi Teja         std::string protocol = "xyz.openbmc_project.Network.IP.Protocol.";
7209c5e585cSRavi Teja         protocol += version == IpVersion::IpV4 ? "IPv4" : "IPv6";
72101784826SJohnathan Mantey         crow::connections::systemBus->async_method_call(
7225e7e2dc5SEd Tanous             [asyncResp](const boost::system::error_code& ec2) {
72323a21a1cSEd Tanous             if (ec2)
72401784826SJohnathan Mantey             {
72501784826SJohnathan Mantey                 messages::internalError(asyncResp->res);
72601784826SJohnathan Mantey             }
72701784826SJohnathan Mantey             },
72801784826SJohnathan Mantey             "xyz.openbmc_project.Network",
72901784826SJohnathan Mantey             "/xyz/openbmc_project/network/" + ifaceId,
7309c5e585cSRavi Teja             "xyz.openbmc_project.Network.IP.Create", "IP", protocol, address,
7319c5e585cSRavi Teja             prefixLength, gateway);
73201784826SJohnathan Mantey         },
73301784826SJohnathan Mantey         "xyz.openbmc_project.Network",
7349c5e585cSRavi Teja         "/xyz/openbmc_project/network/" + ifaceId + id,
73501784826SJohnathan Mantey         "xyz.openbmc_project.Object.Delete", "Delete");
73601784826SJohnathan Mantey }
73701784826SJohnathan Mantey 
73801784826SJohnathan Mantey /**
739e48c0fc5SRavi Teja  * @brief Creates IPv6 with given data
740e48c0fc5SRavi Teja  *
741e48c0fc5SRavi Teja  * @param[in] ifaceId      Id of interface whose IP should be added
742e48c0fc5SRavi Teja  * @param[in] prefixLength Prefix length that needs to be added
743e48c0fc5SRavi Teja  * @param[in] address      IP address that needs to be added
744e48c0fc5SRavi Teja  * @param[io] asyncResp    Response object that will be returned to client
745e48c0fc5SRavi Teja  *
746e48c0fc5SRavi Teja  * @return None
747e48c0fc5SRavi Teja  */
74801784826SJohnathan Mantey inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength,
74901784826SJohnathan Mantey                        const std::string& address,
7508d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
751e48c0fc5SRavi Teja {
7525e7e2dc5SEd Tanous     auto createIpHandler = [asyncResp](const boost::system::error_code& ec) {
753e48c0fc5SRavi Teja         if (ec)
754e48c0fc5SRavi Teja         {
755e48c0fc5SRavi Teja             messages::internalError(asyncResp->res);
756e48c0fc5SRavi Teja         }
757e48c0fc5SRavi Teja     };
758e48c0fc5SRavi Teja     // Passing null for gateway, as per redfish spec IPv6StaticAddresses object
7594e0453b1SGunnar Mills     // does not have associated gateway property
760e48c0fc5SRavi Teja     crow::connections::systemBus->async_method_call(
761e48c0fc5SRavi Teja         std::move(createIpHandler), "xyz.openbmc_project.Network",
762e48c0fc5SRavi Teja         "/xyz/openbmc_project/network/" + ifaceId,
763e48c0fc5SRavi Teja         "xyz.openbmc_project.Network.IP.Create", "IP",
764e48c0fc5SRavi Teja         "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength,
765e48c0fc5SRavi Teja         "");
766e48c0fc5SRavi Teja }
767e48c0fc5SRavi Teja 
768179db1d7SKowalski, Kamil /**
769179db1d7SKowalski, Kamil  * Function that retrieves all properties for given Ethernet Interface
770179db1d7SKowalski, Kamil  * Object
771179db1d7SKowalski, Kamil  * from EntityManager Network Manager
7724a0cb85cSEd Tanous  * @param ethiface_id a eth interface id to query on DBus
773179db1d7SKowalski, Kamil  * @param callback a function that shall be called to convert Dbus output
774179db1d7SKowalski, Kamil  * into JSON
775179db1d7SKowalski, Kamil  */
776179db1d7SKowalski, Kamil template <typename CallbackFunc>
77781ce609eSEd Tanous void getEthernetIfaceData(const std::string& ethifaceId,
7781abe55efSEd Tanous                           CallbackFunc&& callback)
7791abe55efSEd Tanous {
780f5892d0dSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
781f5892d0dSGeorge Liu     dbus::utility::getManagedObjects(
782f5892d0dSGeorge Liu         "xyz.openbmc_project.Network", path,
783f94c4ecfSEd Tanous         [ethifaceId{std::string{ethifaceId}},
784f94c4ecfSEd Tanous          callback{std::forward<CallbackFunc>(callback)}](
785*8b24275dSEd Tanous             const boost::system::error_code& ec,
78602cad96eSEd Tanous             const dbus::utility::ManagedObjectType& resp) {
78755c7b7a2SEd Tanous         EthernetInterfaceData ethData{};
78877179532SEd Tanous         std::vector<IPv4AddressData> ipv4Data;
78977179532SEd Tanous         std::vector<IPv6AddressData> ipv6Data;
790179db1d7SKowalski, Kamil 
791*8b24275dSEd Tanous         if (ec)
7921abe55efSEd Tanous         {
79301784826SJohnathan Mantey             callback(false, ethData, ipv4Data, ipv6Data);
794179db1d7SKowalski, Kamil             return;
795179db1d7SKowalski, Kamil         }
796179db1d7SKowalski, Kamil 
797002d39b4SEd Tanous         bool found = extractEthernetInterfaceData(ethifaceId, resp, ethData);
7984c9afe43SEd Tanous         if (!found)
7994c9afe43SEd Tanous         {
80001784826SJohnathan Mantey             callback(false, ethData, ipv4Data, ipv6Data);
8014c9afe43SEd Tanous             return;
8024c9afe43SEd Tanous         }
8034c9afe43SEd Tanous 
8042c70f800SEd Tanous         extractIPData(ethifaceId, resp, ipv4Data);
805179db1d7SKowalski, Kamil         // Fix global GW
8061abe55efSEd Tanous         for (IPv4AddressData& ipv4 : ipv4Data)
8071abe55efSEd Tanous         {
808c619141bSRavi Teja             if (((ipv4.linktype == LinkType::Global) &&
809c619141bSRavi Teja                  (ipv4.gateway == "0.0.0.0")) ||
8109010ec2eSRavi Teja                 (ipv4.origin == "DHCP") || (ipv4.origin == "Static"))
8111abe55efSEd Tanous             {
81282695a5bSJiaqing Zhao                 ipv4.gateway = ethData.defaultGateway;
813179db1d7SKowalski, Kamil             }
814179db1d7SKowalski, Kamil         }
815179db1d7SKowalski, Kamil 
8162c70f800SEd Tanous         extractIPV6Data(ethifaceId, resp, ipv6Data);
8174e0453b1SGunnar Mills         // Finally make a callback with useful data
81801784826SJohnathan Mantey         callback(true, ethData, ipv4Data, ipv6Data);
819f5892d0dSGeorge Liu         });
820271584abSEd Tanous }
821179db1d7SKowalski, Kamil 
822179db1d7SKowalski, Kamil /**
8239391bb9cSRapkiewicz, Pawel  * Function that retrieves all Ethernet Interfaces available through Network
8249391bb9cSRapkiewicz, Pawel  * Manager
8251abe55efSEd Tanous  * @param callback a function that shall be called to convert Dbus output
8261abe55efSEd Tanous  * into JSON.
8279391bb9cSRapkiewicz, Pawel  */
8289391bb9cSRapkiewicz, Pawel template <typename CallbackFunc>
8291abe55efSEd Tanous void getEthernetIfaceList(CallbackFunc&& callback)
8301abe55efSEd Tanous {
831f5892d0dSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
832f5892d0dSGeorge Liu     dbus::utility::getManagedObjects(
833f5892d0dSGeorge Liu         "xyz.openbmc_project.Network", path,
834f94c4ecfSEd Tanous         [callback{std::forward<CallbackFunc>(callback)}](
835*8b24275dSEd Tanous             const boost::system::error_code& ec,
836f5892d0dSGeorge Liu             const dbus::utility::ManagedObjectType& resp) {
8371abe55efSEd Tanous         // Callback requires vector<string> to retrieve all available
8381abe55efSEd Tanous         // ethernet interfaces
83977179532SEd Tanous         std::vector<std::string> ifaceList;
8402c70f800SEd Tanous         ifaceList.reserve(resp.size());
841*8b24275dSEd Tanous         if (ec)
8421abe55efSEd Tanous         {
8432c70f800SEd Tanous             callback(false, ifaceList);
8449391bb9cSRapkiewicz, Pawel             return;
8459391bb9cSRapkiewicz, Pawel         }
8469391bb9cSRapkiewicz, Pawel 
8479391bb9cSRapkiewicz, Pawel         // Iterate over all retrieved ObjectPaths.
8484a0cb85cSEd Tanous         for (const auto& objpath : resp)
8491abe55efSEd Tanous         {
8509391bb9cSRapkiewicz, Pawel             // And all interfaces available for certain ObjectPath.
8514a0cb85cSEd Tanous             for (const auto& interface : objpath.second)
8521abe55efSEd Tanous             {
8531abe55efSEd Tanous                 // If interface is
8544a0cb85cSEd Tanous                 // xyz.openbmc_project.Network.EthernetInterface, this is
8554a0cb85cSEd Tanous                 // what we're looking for.
8569391bb9cSRapkiewicz, Pawel                 if (interface.first ==
8571abe55efSEd Tanous                     "xyz.openbmc_project.Network.EthernetInterface")
8581abe55efSEd Tanous                 {
8592dfd18efSEd Tanous                     std::string ifaceId = objpath.first.filename();
8602dfd18efSEd Tanous                     if (ifaceId.empty())
8611abe55efSEd Tanous                     {
8622dfd18efSEd Tanous                         continue;
8639391bb9cSRapkiewicz, Pawel                     }
8642dfd18efSEd Tanous                     // and put it into output vector.
86577179532SEd Tanous                     ifaceList.emplace_back(ifaceId);
8669391bb9cSRapkiewicz, Pawel                 }
8679391bb9cSRapkiewicz, Pawel             }
8689391bb9cSRapkiewicz, Pawel         }
8692c5875a2SEd Tanous 
8702c5875a2SEd Tanous         std::sort(ifaceList.begin(), ifaceList.end(),
8712c5875a2SEd Tanous                   AlphanumLess<std::string>());
8722c5875a2SEd Tanous 
873a434f2bdSEd Tanous         // Finally make a callback with useful data
8742c70f800SEd Tanous         callback(true, ifaceList);
875f5892d0dSGeorge Liu         });
876271584abSEd Tanous }
8779391bb9cSRapkiewicz, Pawel 
8784f48d5f6SEd Tanous inline void
8794f48d5f6SEd Tanous     handleHostnamePatch(const std::string& hostname,
8808d1b46d7Szhanghch05                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
8811abe55efSEd Tanous {
882ab6554f1SJoshi-Mansi     // SHOULD handle host names of up to 255 characters(RFC 1123)
883ab6554f1SJoshi-Mansi     if (hostname.length() > 255)
884ab6554f1SJoshi-Mansi     {
885ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, hostname,
886ab6554f1SJoshi-Mansi                                            "HostName");
887ab6554f1SJoshi-Mansi         return;
888ab6554f1SJoshi-Mansi     }
8899ae226faSGeorge Liu     sdbusplus::asio::setProperty(
8909ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
8919ae226faSGeorge Liu         "/xyz/openbmc_project/network/config",
8929ae226faSGeorge Liu         "xyz.openbmc_project.Network.SystemConfiguration", "HostName", hostname,
8935e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
8944a0cb85cSEd Tanous         if (ec)
8954a0cb85cSEd Tanous         {
896a08b46ccSJason M. Bills             messages::internalError(asyncResp->res);
8971abe55efSEd Tanous         }
8989ae226faSGeorge Liu         });
899588c3f0dSKowalski, Kamil }
900588c3f0dSKowalski, Kamil 
9014f48d5f6SEd Tanous inline void
90235fb5311STejas Patil     handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize,
90335fb5311STejas Patil                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
90435fb5311STejas Patil {
90589492a15SPatrick Williams     sdbusplus::message::object_path objPath = "/xyz/openbmc_project/network/" +
90689492a15SPatrick Williams                                               ifaceId;
9079ae226faSGeorge Liu     sdbusplus::asio::setProperty(
9089ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network", objPath,
9099ae226faSGeorge Liu         "xyz.openbmc_project.Network.EthernetInterface", "MTU", mtuSize,
9105e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
91135fb5311STejas Patil         if (ec)
91235fb5311STejas Patil         {
91335fb5311STejas Patil             messages::internalError(asyncResp->res);
91435fb5311STejas Patil         }
9159ae226faSGeorge Liu         });
91635fb5311STejas Patil }
91735fb5311STejas Patil 
91835fb5311STejas Patil inline void
9194f48d5f6SEd Tanous     handleDomainnamePatch(const std::string& ifaceId,
920bf648f77SEd Tanous                           const std::string& domainname,
9218d1b46d7Szhanghch05                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
922ab6554f1SJoshi-Mansi {
923ab6554f1SJoshi-Mansi     std::vector<std::string> vectorDomainname = {domainname};
9249ae226faSGeorge Liu     sdbusplus::asio::setProperty(
9259ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
9269ae226faSGeorge Liu         "/xyz/openbmc_project/network/" + ifaceId,
9279ae226faSGeorge Liu         "xyz.openbmc_project.Network.EthernetInterface", "DomainName",
9289ae226faSGeorge Liu         vectorDomainname, [asyncResp](const boost::system::error_code& ec) {
929ab6554f1SJoshi-Mansi             if (ec)
930ab6554f1SJoshi-Mansi             {
931ab6554f1SJoshi-Mansi                 messages::internalError(asyncResp->res);
932ab6554f1SJoshi-Mansi             }
9339ae226faSGeorge Liu         });
934ab6554f1SJoshi-Mansi }
935ab6554f1SJoshi-Mansi 
9364f48d5f6SEd Tanous inline bool isHostnameValid(const std::string& hostname)
937bf648f77SEd Tanous {
938bf648f77SEd Tanous     // A valid host name can never have the dotted-decimal form (RFC 1123)
939bf648f77SEd Tanous     if (std::all_of(hostname.begin(), hostname.end(), ::isdigit))
940bf648f77SEd Tanous     {
941bf648f77SEd Tanous         return false;
942bf648f77SEd Tanous     }
943bf648f77SEd Tanous     // Each label(hostname/subdomains) within a valid FQDN
944bf648f77SEd Tanous     // MUST handle host names of up to 63 characters (RFC 1123)
945bf648f77SEd Tanous     // labels cannot start or end with hyphens (RFC 952)
946bf648f77SEd Tanous     // labels can start with numbers (RFC 1123)
9474b242749SEd Tanous     const static std::regex pattern(
948bf648f77SEd Tanous         "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$");
949bf648f77SEd Tanous 
950bf648f77SEd Tanous     return std::regex_match(hostname, pattern);
951bf648f77SEd Tanous }
952bf648f77SEd Tanous 
9534f48d5f6SEd Tanous inline bool isDomainnameValid(const std::string& domainname)
954bf648f77SEd Tanous {
955bf648f77SEd Tanous     // Can have multiple subdomains
956bf648f77SEd Tanous     // Top Level Domain's min length is 2 character
9574b242749SEd Tanous     const static std::regex pattern(
9580fda0f12SGeorge Liu         "^([A-Za-z0-9][a-zA-Z0-9\\-]{1,61}|[a-zA-Z0-9]{1,30}\\.)*[a-zA-Z]{2,}$");
959bf648f77SEd Tanous 
960bf648f77SEd Tanous     return std::regex_match(domainname, pattern);
961bf648f77SEd Tanous }
962bf648f77SEd Tanous 
9634f48d5f6SEd Tanous inline void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn,
9648d1b46d7Szhanghch05                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
965ab6554f1SJoshi-Mansi {
966ab6554f1SJoshi-Mansi     // Total length of FQDN must not exceed 255 characters(RFC 1035)
967ab6554f1SJoshi-Mansi     if (fqdn.length() > 255)
968ab6554f1SJoshi-Mansi     {
969ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
970ab6554f1SJoshi-Mansi         return;
971ab6554f1SJoshi-Mansi     }
972ab6554f1SJoshi-Mansi 
973ab6554f1SJoshi-Mansi     size_t pos = fqdn.find('.');
974ab6554f1SJoshi-Mansi     if (pos == std::string::npos)
975ab6554f1SJoshi-Mansi     {
976ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
977ab6554f1SJoshi-Mansi         return;
978ab6554f1SJoshi-Mansi     }
979ab6554f1SJoshi-Mansi 
980ab6554f1SJoshi-Mansi     std::string hostname;
981ab6554f1SJoshi-Mansi     std::string domainname;
982ab6554f1SJoshi-Mansi     domainname = (fqdn).substr(pos + 1);
983ab6554f1SJoshi-Mansi     hostname = (fqdn).substr(0, pos);
984ab6554f1SJoshi-Mansi 
985ab6554f1SJoshi-Mansi     if (!isHostnameValid(hostname) || !isDomainnameValid(domainname))
986ab6554f1SJoshi-Mansi     {
987ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
988ab6554f1SJoshi-Mansi         return;
989ab6554f1SJoshi-Mansi     }
990ab6554f1SJoshi-Mansi 
991ab6554f1SJoshi-Mansi     handleHostnamePatch(hostname, asyncResp);
992ab6554f1SJoshi-Mansi     handleDomainnamePatch(ifaceId, domainname, asyncResp);
993ab6554f1SJoshi-Mansi }
994ab6554f1SJoshi-Mansi 
9954f48d5f6SEd Tanous inline void
9964f48d5f6SEd Tanous     handleMACAddressPatch(const std::string& ifaceId,
997bf648f77SEd Tanous                           const std::string& macAddress,
9988d1b46d7Szhanghch05                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
999d577665bSRatan Gupta {
100058283f41SJohnathan Mantey     static constexpr std::string_view dbusNotAllowedError =
100158283f41SJohnathan Mantey         "xyz.openbmc_project.Common.Error.NotAllowed";
100258283f41SJohnathan Mantey 
10039ae226faSGeorge Liu     sdbusplus::asio::setProperty(
10049ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
10059ae226faSGeorge Liu         "/xyz/openbmc_project/network/" + ifaceId,
10069ae226faSGeorge Liu         "xyz.openbmc_project.Network.MACAddress", "MACAddress", macAddress,
10079ae226faSGeorge Liu         [asyncResp](const boost::system::error_code& ec,
10085b378546SPatrick Williams                     const sdbusplus::message_t& msg) {
1009d577665bSRatan Gupta         if (ec)
1010d577665bSRatan Gupta         {
101158283f41SJohnathan Mantey             const sd_bus_error* err = msg.get_error();
101258283f41SJohnathan Mantey             if (err == nullptr)
101358283f41SJohnathan Mantey             {
101458283f41SJohnathan Mantey                 messages::internalError(asyncResp->res);
101558283f41SJohnathan Mantey                 return;
101658283f41SJohnathan Mantey             }
101758283f41SJohnathan Mantey             if (err->name == dbusNotAllowedError)
101858283f41SJohnathan Mantey             {
101958283f41SJohnathan Mantey                 messages::propertyNotWritable(asyncResp->res, "MACAddress");
102058283f41SJohnathan Mantey                 return;
102158283f41SJohnathan Mantey             }
1022d577665bSRatan Gupta             messages::internalError(asyncResp->res);
1023d577665bSRatan Gupta             return;
1024d577665bSRatan Gupta         }
10259ae226faSGeorge Liu         });
1026d577665bSRatan Gupta }
1027286b9118SJohnathan Mantey 
10284f48d5f6SEd Tanous inline void setDHCPEnabled(const std::string& ifaceId,
10294f48d5f6SEd Tanous                            const std::string& propertyName, const bool v4Value,
10304f48d5f6SEd Tanous                            const bool v6Value,
10318d1b46d7Szhanghch05                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1032da131a9aSJennifer Lee {
10332c70f800SEd Tanous     const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
10349ae226faSGeorge Liu     sdbusplus::asio::setProperty(
10359ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
10369ae226faSGeorge Liu         "/xyz/openbmc_project/network/" + ifaceId,
10379ae226faSGeorge Liu         "xyz.openbmc_project.Network.EthernetInterface", propertyName, dhcp,
10385e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1039da131a9aSJennifer Lee         if (ec)
1040da131a9aSJennifer Lee         {
1041da131a9aSJennifer Lee             BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1042da131a9aSJennifer Lee             messages::internalError(asyncResp->res);
1043da131a9aSJennifer Lee             return;
1044da131a9aSJennifer Lee         }
10458f7e9c19SJayaprakash Mutyala         messages::success(asyncResp->res);
10469ae226faSGeorge Liu         });
1047da131a9aSJennifer Lee }
10481f8c7b5dSJohnathan Mantey 
10494f48d5f6SEd Tanous inline void setEthernetInterfaceBoolProperty(
1050eeedda23SJohnathan Mantey     const std::string& ifaceId, const std::string& propertyName,
10518d1b46d7Szhanghch05     const bool& value, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1052eeedda23SJohnathan Mantey {
10539ae226faSGeorge Liu     sdbusplus::asio::setProperty(
10549ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
10559ae226faSGeorge Liu         "/xyz/openbmc_project/network/" + ifaceId,
10569ae226faSGeorge Liu         "xyz.openbmc_project.Network.EthernetInterface", propertyName, value,
10575e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1058eeedda23SJohnathan Mantey         if (ec)
1059eeedda23SJohnathan Mantey         {
1060eeedda23SJohnathan Mantey             BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1061eeedda23SJohnathan Mantey             messages::internalError(asyncResp->res);
1062eeedda23SJohnathan Mantey             return;
1063eeedda23SJohnathan Mantey         }
10649ae226faSGeorge Liu         });
1065eeedda23SJohnathan Mantey }
1066eeedda23SJohnathan Mantey 
10674f48d5f6SEd Tanous inline void setDHCPv4Config(const std::string& propertyName, const bool& value,
10688d1b46d7Szhanghch05                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1069da131a9aSJennifer Lee {
1070da131a9aSJennifer Lee     BMCWEB_LOG_DEBUG << propertyName << " = " << value;
10719ae226faSGeorge Liu     sdbusplus::asio::setProperty(
10729ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
10739ae226faSGeorge Liu         "/xyz/openbmc_project/network/dhcp",
10749ae226faSGeorge Liu         "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, value,
10755e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1076da131a9aSJennifer Lee         if (ec)
1077da131a9aSJennifer Lee         {
1078da131a9aSJennifer Lee             BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1079da131a9aSJennifer Lee             messages::internalError(asyncResp->res);
1080da131a9aSJennifer Lee             return;
1081da131a9aSJennifer Lee         }
10829ae226faSGeorge Liu         });
1083da131a9aSJennifer Lee }
1084d577665bSRatan Gupta 
10854f48d5f6SEd Tanous inline void handleDHCPPatch(const std::string& ifaceId,
10861f8c7b5dSJohnathan Mantey                             const EthernetInterfaceData& ethData,
1087f23b7296SEd Tanous                             const DHCPParameters& v4dhcpParms,
1088f23b7296SEd Tanous                             const DHCPParameters& v6dhcpParms,
10898d1b46d7Szhanghch05                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1090da131a9aSJennifer Lee {
109182695a5bSJiaqing Zhao     bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
109282695a5bSJiaqing Zhao     bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false);
1093da131a9aSJennifer Lee 
10941f8c7b5dSJohnathan Mantey     bool nextv4DHCPState =
10951f8c7b5dSJohnathan Mantey         v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active;
10961f8c7b5dSJohnathan Mantey 
10971f8c7b5dSJohnathan Mantey     bool nextv6DHCPState{};
10981f8c7b5dSJohnathan Mantey     if (v6dhcpParms.dhcpv6OperatingMode)
1099da131a9aSJennifer Lee     {
11001f8c7b5dSJohnathan Mantey         if ((*v6dhcpParms.dhcpv6OperatingMode != "Stateful") &&
11011f8c7b5dSJohnathan Mantey             (*v6dhcpParms.dhcpv6OperatingMode != "Stateless") &&
11021f8c7b5dSJohnathan Mantey             (*v6dhcpParms.dhcpv6OperatingMode != "Disabled"))
11031f8c7b5dSJohnathan Mantey         {
1104bf648f77SEd Tanous             messages::propertyValueFormatError(asyncResp->res,
1105bf648f77SEd Tanous                                                *v6dhcpParms.dhcpv6OperatingMode,
11061f8c7b5dSJohnathan Mantey                                                "OperatingMode");
1107da131a9aSJennifer Lee             return;
1108da131a9aSJennifer Lee         }
11091f8c7b5dSJohnathan Mantey         nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Stateful");
11101f8c7b5dSJohnathan Mantey     }
11111f8c7b5dSJohnathan Mantey     else
1112da131a9aSJennifer Lee     {
11131f8c7b5dSJohnathan Mantey         nextv6DHCPState = ipv6Active;
11141f8c7b5dSJohnathan Mantey     }
11151f8c7b5dSJohnathan Mantey 
11161f8c7b5dSJohnathan Mantey     bool nextDNS{};
111782695a5bSJiaqing Zhao     if (v4dhcpParms.useDnsServers && v6dhcpParms.useDnsServers)
11181f8c7b5dSJohnathan Mantey     {
111982695a5bSJiaqing Zhao         if (*v4dhcpParms.useDnsServers != *v6dhcpParms.useDnsServers)
11201f8c7b5dSJohnathan Mantey         {
11211f8c7b5dSJohnathan Mantey             messages::generalError(asyncResp->res);
11221f8c7b5dSJohnathan Mantey             return;
11231f8c7b5dSJohnathan Mantey         }
112482695a5bSJiaqing Zhao         nextDNS = *v4dhcpParms.useDnsServers;
11251f8c7b5dSJohnathan Mantey     }
112682695a5bSJiaqing Zhao     else if (v4dhcpParms.useDnsServers)
11271f8c7b5dSJohnathan Mantey     {
112882695a5bSJiaqing Zhao         nextDNS = *v4dhcpParms.useDnsServers;
11291f8c7b5dSJohnathan Mantey     }
113082695a5bSJiaqing Zhao     else if (v6dhcpParms.useDnsServers)
11311f8c7b5dSJohnathan Mantey     {
113282695a5bSJiaqing Zhao         nextDNS = *v6dhcpParms.useDnsServers;
11331f8c7b5dSJohnathan Mantey     }
11341f8c7b5dSJohnathan Mantey     else
11351f8c7b5dSJohnathan Mantey     {
113682695a5bSJiaqing Zhao         nextDNS = ethData.dnsEnabled;
11371f8c7b5dSJohnathan Mantey     }
11381f8c7b5dSJohnathan Mantey 
11391f8c7b5dSJohnathan Mantey     bool nextNTP{};
114082695a5bSJiaqing Zhao     if (v4dhcpParms.useNtpServers && v6dhcpParms.useNtpServers)
11411f8c7b5dSJohnathan Mantey     {
114282695a5bSJiaqing Zhao         if (*v4dhcpParms.useNtpServers != *v6dhcpParms.useNtpServers)
11431f8c7b5dSJohnathan Mantey         {
11441f8c7b5dSJohnathan Mantey             messages::generalError(asyncResp->res);
11451f8c7b5dSJohnathan Mantey             return;
11461f8c7b5dSJohnathan Mantey         }
114782695a5bSJiaqing Zhao         nextNTP = *v4dhcpParms.useNtpServers;
11481f8c7b5dSJohnathan Mantey     }
114982695a5bSJiaqing Zhao     else if (v4dhcpParms.useNtpServers)
11501f8c7b5dSJohnathan Mantey     {
115182695a5bSJiaqing Zhao         nextNTP = *v4dhcpParms.useNtpServers;
11521f8c7b5dSJohnathan Mantey     }
115382695a5bSJiaqing Zhao     else if (v6dhcpParms.useNtpServers)
11541f8c7b5dSJohnathan Mantey     {
115582695a5bSJiaqing Zhao         nextNTP = *v6dhcpParms.useNtpServers;
11561f8c7b5dSJohnathan Mantey     }
11571f8c7b5dSJohnathan Mantey     else
11581f8c7b5dSJohnathan Mantey     {
115982695a5bSJiaqing Zhao         nextNTP = ethData.ntpEnabled;
11601f8c7b5dSJohnathan Mantey     }
11611f8c7b5dSJohnathan Mantey 
11621f8c7b5dSJohnathan Mantey     bool nextUseDomain{};
116382695a5bSJiaqing Zhao     if (v4dhcpParms.useDomainName && v6dhcpParms.useDomainName)
11641f8c7b5dSJohnathan Mantey     {
116582695a5bSJiaqing Zhao         if (*v4dhcpParms.useDomainName != *v6dhcpParms.useDomainName)
11661f8c7b5dSJohnathan Mantey         {
11671f8c7b5dSJohnathan Mantey             messages::generalError(asyncResp->res);
11681f8c7b5dSJohnathan Mantey             return;
11691f8c7b5dSJohnathan Mantey         }
117082695a5bSJiaqing Zhao         nextUseDomain = *v4dhcpParms.useDomainName;
11711f8c7b5dSJohnathan Mantey     }
117282695a5bSJiaqing Zhao     else if (v4dhcpParms.useDomainName)
11731f8c7b5dSJohnathan Mantey     {
117482695a5bSJiaqing Zhao         nextUseDomain = *v4dhcpParms.useDomainName;
11751f8c7b5dSJohnathan Mantey     }
117682695a5bSJiaqing Zhao     else if (v6dhcpParms.useDomainName)
11771f8c7b5dSJohnathan Mantey     {
117882695a5bSJiaqing Zhao         nextUseDomain = *v6dhcpParms.useDomainName;
11791f8c7b5dSJohnathan Mantey     }
11801f8c7b5dSJohnathan Mantey     else
11811f8c7b5dSJohnathan Mantey     {
118282695a5bSJiaqing Zhao         nextUseDomain = ethData.hostNameEnabled;
11831f8c7b5dSJohnathan Mantey     }
11841f8c7b5dSJohnathan Mantey 
1185da131a9aSJennifer Lee     BMCWEB_LOG_DEBUG << "set DHCPEnabled...";
11861f8c7b5dSJohnathan Mantey     setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
11871f8c7b5dSJohnathan Mantey                    asyncResp);
1188da131a9aSJennifer Lee     BMCWEB_LOG_DEBUG << "set DNSEnabled...";
11891f8c7b5dSJohnathan Mantey     setDHCPv4Config("DNSEnabled", nextDNS, asyncResp);
1190da131a9aSJennifer Lee     BMCWEB_LOG_DEBUG << "set NTPEnabled...";
11911f8c7b5dSJohnathan Mantey     setDHCPv4Config("NTPEnabled", nextNTP, asyncResp);
11921f8c7b5dSJohnathan Mantey     BMCWEB_LOG_DEBUG << "set HostNameEnabled...";
11931f8c7b5dSJohnathan Mantey     setDHCPv4Config("HostNameEnabled", nextUseDomain, asyncResp);
1194da131a9aSJennifer Lee }
119501784826SJohnathan Mantey 
119677179532SEd Tanous inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry(
119777179532SEd Tanous     const std::vector<IPv4AddressData>::const_iterator& head,
119877179532SEd Tanous     const std::vector<IPv4AddressData>::const_iterator& end)
119901784826SJohnathan Mantey {
120017a897dfSManojkiran Eda     return std::find_if(head, end, [](const IPv4AddressData& value) {
120117a897dfSManojkiran Eda         return value.origin == "Static";
120217a897dfSManojkiran Eda     });
120301784826SJohnathan Mantey }
120401784826SJohnathan Mantey 
120577179532SEd Tanous inline std::vector<IPv6AddressData>::const_iterator getNextStaticIpEntry(
120677179532SEd Tanous     const std::vector<IPv6AddressData>::const_iterator& head,
120777179532SEd Tanous     const std::vector<IPv6AddressData>::const_iterator& end)
120801784826SJohnathan Mantey {
120917a897dfSManojkiran Eda     return std::find_if(head, end, [](const IPv6AddressData& value) {
121017a897dfSManojkiran Eda         return value.origin == "Static";
121117a897dfSManojkiran Eda     });
121201784826SJohnathan Mantey }
121301784826SJohnathan Mantey 
121477179532SEd Tanous inline void
1215ddd70dcaSEd Tanous     handleIPv4StaticPatch(const std::string& ifaceId,
1216ddd70dcaSEd Tanous                           nlohmann::json::array_t& input,
121777179532SEd Tanous                           const std::vector<IPv4AddressData>& ipv4Data,
12188d1b46d7Szhanghch05                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
12191abe55efSEd Tanous {
1220ddd70dcaSEd Tanous     if (input.empty())
1221f476acbfSRatan Gupta     {
12222e8c4bdaSEd Tanous         messages::propertyValueTypeError(asyncResp->res, input,
1223d1d50814SRavi Teja                                          "IPv4StaticAddresses");
1224f476acbfSRatan Gupta         return;
1225f476acbfSRatan Gupta     }
1226f476acbfSRatan Gupta 
1227271584abSEd Tanous     unsigned entryIdx = 1;
122801784826SJohnathan Mantey     // Find the first static IP address currently active on the NIC and
122901784826SJohnathan Mantey     // match it to the first JSON element in the IPv4StaticAddresses array.
123001784826SJohnathan Mantey     // Match each subsequent JSON element to the next static IP programmed
123101784826SJohnathan Mantey     // into the NIC.
123277179532SEd Tanous     std::vector<IPv4AddressData>::const_iterator nicIpEntry =
12332c70f800SEd Tanous         getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend());
123401784826SJohnathan Mantey 
1235537174c4SEd Tanous     for (nlohmann::json& thisJson : input)
12361abe55efSEd Tanous     {
123789492a15SPatrick Williams         std::string pathString = "IPv4StaticAddresses/" +
123889492a15SPatrick Williams                                  std::to_string(entryIdx);
1239179db1d7SKowalski, Kamil 
124001784826SJohnathan Mantey         if (!thisJson.is_null() && !thisJson.empty())
1241f476acbfSRatan Gupta         {
1242537174c4SEd Tanous             std::optional<std::string> address;
1243537174c4SEd Tanous             std::optional<std::string> subnetMask;
1244537174c4SEd Tanous             std::optional<std::string> gateway;
1245537174c4SEd Tanous 
1246537174c4SEd Tanous             if (!json_util::readJson(thisJson, asyncResp->res, "Address",
12477e27d832SJohnathan Mantey                                      address, "SubnetMask", subnetMask,
12487e27d832SJohnathan Mantey                                      "Gateway", gateway))
1249537174c4SEd Tanous             {
1250f818b04dSEd Tanous                 messages::propertyValueFormatError(asyncResp->res, thisJson,
125171f52d96SEd Tanous                                                    pathString);
1252537174c4SEd Tanous                 return;
1253179db1d7SKowalski, Kamil             }
1254179db1d7SKowalski, Kamil 
125501784826SJohnathan Mantey             // Find the address/subnet/gateway values. Any values that are
125601784826SJohnathan Mantey             // not explicitly provided are assumed to be unmodified from the
125701784826SJohnathan Mantey             // current state of the interface. Merge existing state into the
125801784826SJohnathan Mantey             // current request.
1259271584abSEd Tanous             const std::string* addr = nullptr;
1260271584abSEd Tanous             const std::string* gw = nullptr;
126101784826SJohnathan Mantey             uint8_t prefixLength = 0;
126201784826SJohnathan Mantey             bool errorInEntry = false;
1263537174c4SEd Tanous             if (address)
12641abe55efSEd Tanous             {
1265033f1e4dSEd Tanous                 if (ip_util::ipv4VerifyIpAndGetBitcount(*address))
12661abe55efSEd Tanous                 {
126701784826SJohnathan Mantey                     addr = &(*address);
12684a0cb85cSEd Tanous                 }
126901784826SJohnathan Mantey                 else
127001784826SJohnathan Mantey                 {
1271bf648f77SEd Tanous                     messages::propertyValueFormatError(asyncResp->res, *address,
1272bf648f77SEd Tanous                                                        pathString + "/Address");
127301784826SJohnathan Mantey                     errorInEntry = true;
127401784826SJohnathan Mantey                 }
127501784826SJohnathan Mantey             }
127685ffe86aSJiaqing Zhao             else if (nicIpEntry != ipv4Data.cend())
127701784826SJohnathan Mantey             {
127885ffe86aSJiaqing Zhao                 addr = &(nicIpEntry->address);
127901784826SJohnathan Mantey             }
128001784826SJohnathan Mantey             else
128101784826SJohnathan Mantey             {
128201784826SJohnathan Mantey                 messages::propertyMissing(asyncResp->res,
128301784826SJohnathan Mantey                                           pathString + "/Address");
128401784826SJohnathan Mantey                 errorInEntry = true;
12854a0cb85cSEd Tanous             }
12864a0cb85cSEd Tanous 
1287537174c4SEd Tanous             if (subnetMask)
12884a0cb85cSEd Tanous             {
1289033f1e4dSEd Tanous                 if (!ip_util::ipv4VerifyIpAndGetBitcount(*subnetMask,
1290033f1e4dSEd Tanous                                                          &prefixLength))
12914a0cb85cSEd Tanous                 {
1292f12894f8SJason M. Bills                     messages::propertyValueFormatError(
1293537174c4SEd Tanous                         asyncResp->res, *subnetMask,
12944a0cb85cSEd Tanous                         pathString + "/SubnetMask");
129501784826SJohnathan Mantey                     errorInEntry = true;
12964a0cb85cSEd Tanous                 }
12974a0cb85cSEd Tanous             }
129885ffe86aSJiaqing Zhao             else if (nicIpEntry != ipv4Data.cend())
12994a0cb85cSEd Tanous             {
1300033f1e4dSEd Tanous                 if (!ip_util::ipv4VerifyIpAndGetBitcount(nicIpEntry->netmask,
130101784826SJohnathan Mantey                                                          &prefixLength))
13024a0cb85cSEd Tanous                 {
130301784826SJohnathan Mantey                     messages::propertyValueFormatError(
130485ffe86aSJiaqing Zhao                         asyncResp->res, nicIpEntry->netmask,
130501784826SJohnathan Mantey                         pathString + "/SubnetMask");
130601784826SJohnathan Mantey                     errorInEntry = true;
13074a0cb85cSEd Tanous                 }
13084a0cb85cSEd Tanous             }
13091abe55efSEd Tanous             else
13101abe55efSEd Tanous             {
131101784826SJohnathan Mantey                 messages::propertyMissing(asyncResp->res,
131201784826SJohnathan Mantey                                           pathString + "/SubnetMask");
131301784826SJohnathan Mantey                 errorInEntry = true;
131401784826SJohnathan Mantey             }
131501784826SJohnathan Mantey 
131601784826SJohnathan Mantey             if (gateway)
131701784826SJohnathan Mantey             {
1318033f1e4dSEd Tanous                 if (ip_util::ipv4VerifyIpAndGetBitcount(*gateway))
131901784826SJohnathan Mantey                 {
132001784826SJohnathan Mantey                     gw = &(*gateway);
132101784826SJohnathan Mantey                 }
132201784826SJohnathan Mantey                 else
132301784826SJohnathan Mantey                 {
1324bf648f77SEd Tanous                     messages::propertyValueFormatError(asyncResp->res, *gateway,
1325bf648f77SEd Tanous                                                        pathString + "/Gateway");
132601784826SJohnathan Mantey                     errorInEntry = true;
132701784826SJohnathan Mantey                 }
132801784826SJohnathan Mantey             }
132985ffe86aSJiaqing Zhao             else if (nicIpEntry != ipv4Data.cend())
133001784826SJohnathan Mantey             {
133185ffe86aSJiaqing Zhao                 gw = &nicIpEntry->gateway;
133201784826SJohnathan Mantey             }
133301784826SJohnathan Mantey             else
13341abe55efSEd Tanous             {
1335a08b46ccSJason M. Bills                 messages::propertyMissing(asyncResp->res,
13364a0cb85cSEd Tanous                                           pathString + "/Gateway");
133701784826SJohnathan Mantey                 errorInEntry = true;
13384a0cb85cSEd Tanous             }
13394a0cb85cSEd Tanous 
134001784826SJohnathan Mantey             if (errorInEntry)
13411abe55efSEd Tanous             {
134201784826SJohnathan Mantey                 return;
13434a0cb85cSEd Tanous             }
13444a0cb85cSEd Tanous 
134585ffe86aSJiaqing Zhao             if (nicIpEntry != ipv4Data.cend())
13461abe55efSEd Tanous             {
13479c5e585cSRavi Teja                 deleteAndCreateIPAddress(IpVersion::IpV4, ifaceId,
13489c5e585cSRavi Teja                                          nicIpEntry->id, prefixLength, *gw,
1349bf648f77SEd Tanous                                          *addr, asyncResp);
135089492a15SPatrick Williams                 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
135189492a15SPatrick Williams                                                   ipv4Data.cend());
1352588c3f0dSKowalski, Kamil             }
135301784826SJohnathan Mantey             else
135401784826SJohnathan Mantey             {
1355cb13a392SEd Tanous                 createIPv4(ifaceId, prefixLength, *gateway, *address,
1356cb13a392SEd Tanous                            asyncResp);
13574a0cb85cSEd Tanous             }
13584a0cb85cSEd Tanous             entryIdx++;
13594a0cb85cSEd Tanous         }
136001784826SJohnathan Mantey         else
136101784826SJohnathan Mantey         {
136285ffe86aSJiaqing Zhao             if (nicIpEntry == ipv4Data.cend())
136301784826SJohnathan Mantey             {
136401784826SJohnathan Mantey                 // Requesting a DELETE/DO NOT MODIFY action for an item
136501784826SJohnathan Mantey                 // that isn't present on the eth(n) interface. Input JSON is
136601784826SJohnathan Mantey                 // in error, so bail out.
136701784826SJohnathan Mantey                 if (thisJson.is_null())
136801784826SJohnathan Mantey                 {
136901784826SJohnathan Mantey                     messages::resourceCannotBeDeleted(asyncResp->res);
137001784826SJohnathan Mantey                     return;
137101784826SJohnathan Mantey                 }
1372f818b04dSEd Tanous                 messages::propertyValueFormatError(asyncResp->res, thisJson,
137371f52d96SEd Tanous                                                    pathString);
137401784826SJohnathan Mantey                 return;
137501784826SJohnathan Mantey             }
137601784826SJohnathan Mantey 
137701784826SJohnathan Mantey             if (thisJson.is_null())
137801784826SJohnathan Mantey             {
13799c5e585cSRavi Teja                 deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp);
138001784826SJohnathan Mantey             }
138185ffe86aSJiaqing Zhao             if (nicIpEntry != ipv4Data.cend())
138201784826SJohnathan Mantey             {
138389492a15SPatrick Williams                 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
138489492a15SPatrick Williams                                                   ipv4Data.cend());
138501784826SJohnathan Mantey             }
138601784826SJohnathan Mantey             entryIdx++;
138701784826SJohnathan Mantey         }
138801784826SJohnathan Mantey     }
13894a0cb85cSEd Tanous }
13904a0cb85cSEd Tanous 
13914f48d5f6SEd Tanous inline void handleStaticNameServersPatch(
1392f85837bfSRAJESWARAN THILLAIGOVINDAN     const std::string& ifaceId,
1393f85837bfSRAJESWARAN THILLAIGOVINDAN     const std::vector<std::string>& updatedStaticNameServers,
13948d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1395f85837bfSRAJESWARAN THILLAIGOVINDAN {
13969ae226faSGeorge Liu     sdbusplus::asio::setProperty(
13979ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.Network",
13989ae226faSGeorge Liu         "/xyz/openbmc_project/network/" + ifaceId,
13999ae226faSGeorge Liu         "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers",
14009ae226faSGeorge Liu         updatedStaticNameServers,
14015e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
1402f85837bfSRAJESWARAN THILLAIGOVINDAN         if (ec)
1403f85837bfSRAJESWARAN THILLAIGOVINDAN         {
1404f85837bfSRAJESWARAN THILLAIGOVINDAN             messages::internalError(asyncResp->res);
1405f85837bfSRAJESWARAN THILLAIGOVINDAN             return;
1406f85837bfSRAJESWARAN THILLAIGOVINDAN         }
14079ae226faSGeorge Liu         });
1408f85837bfSRAJESWARAN THILLAIGOVINDAN }
1409f85837bfSRAJESWARAN THILLAIGOVINDAN 
14104f48d5f6SEd Tanous inline void handleIPv6StaticAddressesPatch(
1411ddd70dcaSEd Tanous     const std::string& ifaceId, const nlohmann::json::array_t& input,
141277179532SEd Tanous     const std::vector<IPv6AddressData>& ipv6Data,
14138d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1414e48c0fc5SRavi Teja {
1415ddd70dcaSEd Tanous     if (input.empty())
1416e48c0fc5SRavi Teja     {
14172e8c4bdaSEd Tanous         messages::propertyValueTypeError(asyncResp->res, input,
1418e48c0fc5SRavi Teja                                          "IPv6StaticAddresses");
1419e48c0fc5SRavi Teja         return;
1420e48c0fc5SRavi Teja     }
1421271584abSEd Tanous     size_t entryIdx = 1;
142277179532SEd Tanous     std::vector<IPv6AddressData>::const_iterator nicIpEntry =
14232c70f800SEd Tanous         getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend());
1424f23b7296SEd Tanous     for (const nlohmann::json& thisJson : input)
1425e48c0fc5SRavi Teja     {
142689492a15SPatrick Williams         std::string pathString = "IPv6StaticAddresses/" +
142789492a15SPatrick Williams                                  std::to_string(entryIdx);
1428e48c0fc5SRavi Teja 
142901784826SJohnathan Mantey         if (!thisJson.is_null() && !thisJson.empty())
1430e48c0fc5SRavi Teja         {
1431e48c0fc5SRavi Teja             std::optional<std::string> address;
1432e48c0fc5SRavi Teja             std::optional<uint8_t> prefixLength;
1433f23b7296SEd Tanous             nlohmann::json thisJsonCopy = thisJson;
1434bf648f77SEd Tanous             if (!json_util::readJson(thisJsonCopy, asyncResp->res, "Address",
1435bf648f77SEd Tanous                                      address, "PrefixLength", prefixLength))
1436e48c0fc5SRavi Teja             {
1437f818b04dSEd Tanous                 messages::propertyValueFormatError(asyncResp->res, thisJson,
143871f52d96SEd Tanous                                                    pathString);
1439e48c0fc5SRavi Teja                 return;
1440e48c0fc5SRavi Teja             }
1441e48c0fc5SRavi Teja 
1442543f4400SEd Tanous             const std::string* addr = nullptr;
1443543f4400SEd Tanous             uint8_t prefix = 0;
144401784826SJohnathan Mantey 
144501784826SJohnathan Mantey             // Find the address and prefixLength values. Any values that are
144601784826SJohnathan Mantey             // not explicitly provided are assumed to be unmodified from the
144701784826SJohnathan Mantey             // current state of the interface. Merge existing state into the
144801784826SJohnathan Mantey             // current request.
1449e48c0fc5SRavi Teja             if (address)
1450e48c0fc5SRavi Teja             {
145101784826SJohnathan Mantey                 addr = &(*address);
1452e48c0fc5SRavi Teja             }
145385ffe86aSJiaqing Zhao             else if (nicIpEntry != ipv6Data.end())
145401784826SJohnathan Mantey             {
145585ffe86aSJiaqing Zhao                 addr = &(nicIpEntry->address);
145601784826SJohnathan Mantey             }
145701784826SJohnathan Mantey             else
145801784826SJohnathan Mantey             {
145901784826SJohnathan Mantey                 messages::propertyMissing(asyncResp->res,
146001784826SJohnathan Mantey                                           pathString + "/Address");
146101784826SJohnathan Mantey                 return;
1462e48c0fc5SRavi Teja             }
1463e48c0fc5SRavi Teja 
1464e48c0fc5SRavi Teja             if (prefixLength)
1465e48c0fc5SRavi Teja             {
146601784826SJohnathan Mantey                 prefix = *prefixLength;
146701784826SJohnathan Mantey             }
146885ffe86aSJiaqing Zhao             else if (nicIpEntry != ipv6Data.end())
1469e48c0fc5SRavi Teja             {
147085ffe86aSJiaqing Zhao                 prefix = nicIpEntry->prefixLength;
1471e48c0fc5SRavi Teja             }
1472e48c0fc5SRavi Teja             else
1473e48c0fc5SRavi Teja             {
1474e48c0fc5SRavi Teja                 messages::propertyMissing(asyncResp->res,
1475e48c0fc5SRavi Teja                                           pathString + "/PrefixLength");
147601784826SJohnathan Mantey                 return;
1477e48c0fc5SRavi Teja             }
1478e48c0fc5SRavi Teja 
147985ffe86aSJiaqing Zhao             if (nicIpEntry != ipv6Data.end())
1480e48c0fc5SRavi Teja             {
14819c5e585cSRavi Teja                 deleteAndCreateIPAddress(IpVersion::IpV6, ifaceId,
14829c5e585cSRavi Teja                                          nicIpEntry->id, prefix, "", *addr,
1483e48c0fc5SRavi Teja                                          asyncResp);
148489492a15SPatrick Williams                 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
148589492a15SPatrick Williams                                                   ipv6Data.cend());
148601784826SJohnathan Mantey             }
148701784826SJohnathan Mantey             else
148801784826SJohnathan Mantey             {
148901784826SJohnathan Mantey                 createIPv6(ifaceId, *prefixLength, *addr, asyncResp);
1490e48c0fc5SRavi Teja             }
1491e48c0fc5SRavi Teja             entryIdx++;
1492e48c0fc5SRavi Teja         }
149301784826SJohnathan Mantey         else
149401784826SJohnathan Mantey         {
149585ffe86aSJiaqing Zhao             if (nicIpEntry == ipv6Data.end())
149601784826SJohnathan Mantey             {
149701784826SJohnathan Mantey                 // Requesting a DELETE/DO NOT MODIFY action for an item
149801784826SJohnathan Mantey                 // that isn't present on the eth(n) interface. Input JSON is
149901784826SJohnathan Mantey                 // in error, so bail out.
150001784826SJohnathan Mantey                 if (thisJson.is_null())
150101784826SJohnathan Mantey                 {
150201784826SJohnathan Mantey                     messages::resourceCannotBeDeleted(asyncResp->res);
150301784826SJohnathan Mantey                     return;
150401784826SJohnathan Mantey                 }
1505f818b04dSEd Tanous                 messages::propertyValueFormatError(asyncResp->res, thisJson,
150671f52d96SEd Tanous                                                    pathString);
150701784826SJohnathan Mantey                 return;
150801784826SJohnathan Mantey             }
150901784826SJohnathan Mantey 
151001784826SJohnathan Mantey             if (thisJson.is_null())
151101784826SJohnathan Mantey             {
15129c5e585cSRavi Teja                 deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp);
151301784826SJohnathan Mantey             }
151485ffe86aSJiaqing Zhao             if (nicIpEntry != ipv6Data.cend())
151501784826SJohnathan Mantey             {
151689492a15SPatrick Williams                 nicIpEntry = getNextStaticIpEntry(++nicIpEntry,
151789492a15SPatrick Williams                                                   ipv6Data.cend());
151801784826SJohnathan Mantey             }
151901784826SJohnathan Mantey             entryIdx++;
152001784826SJohnathan Mantey         }
152101784826SJohnathan Mantey     }
1522e48c0fc5SRavi Teja }
1523e48c0fc5SRavi Teja 
15247857cb8dSJiaqing Zhao inline std::string extractParentInterfaceName(const std::string& ifaceId)
15257857cb8dSJiaqing Zhao {
15267857cb8dSJiaqing Zhao     std::size_t pos = ifaceId.find('_');
15277857cb8dSJiaqing Zhao     return ifaceId.substr(0, pos);
15287857cb8dSJiaqing Zhao }
15297857cb8dSJiaqing Zhao 
153077179532SEd Tanous inline void
153177179532SEd Tanous     parseInterfaceData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
153277179532SEd Tanous                        const std::string& ifaceId,
153377179532SEd Tanous                        const EthernetInterfaceData& ethData,
153477179532SEd Tanous                        const std::vector<IPv4AddressData>& ipv4Data,
153577179532SEd Tanous                        const std::vector<IPv6AddressData>& ipv6Data)
15364a0cb85cSEd Tanous {
15372c70f800SEd Tanous     nlohmann::json& jsonResponse = asyncResp->res.jsonValue;
153881ce609eSEd Tanous     jsonResponse["Id"] = ifaceId;
1539ef4c65b7SEd Tanous     jsonResponse["@odata.id"] = boost::urls::format(
1540ef4c65b7SEd Tanous         "/redfish/v1/Managers/bmc/EthernetInterfaces/{}", ifaceId);
15412c70f800SEd Tanous     jsonResponse["InterfaceEnabled"] = ethData.nicEnabled;
1542eeedda23SJohnathan Mantey 
154313451e39SWilly Tu     if constexpr (bmcwebEnableHealthPopulate)
154413451e39SWilly Tu     {
154513451e39SWilly Tu         constexpr std::array<std::string_view, 1> inventoryForEthernet = {
154613451e39SWilly Tu             "xyz.openbmc_project.Inventory.Item.Ethernet"};
1547eeedda23SJohnathan Mantey         auto health = std::make_shared<HealthPopulate>(asyncResp);
15487a1dbc48SGeorge Liu         dbus::utility::getSubTreePaths(
15497a1dbc48SGeorge Liu             "/", 0, inventoryForEthernet,
15507a1dbc48SGeorge Liu             [health](const boost::system::error_code& ec,
1551b9d36b47SEd Tanous                      const dbus::utility::MapperGetSubTreePathsResponse& resp) {
1552eeedda23SJohnathan Mantey             if (ec)
1553029573d4SEd Tanous             {
1554eeedda23SJohnathan Mantey                 return;
1555eeedda23SJohnathan Mantey             }
1556eeedda23SJohnathan Mantey 
1557914e2d5dSEd Tanous             health->inventory = resp;
15587a1dbc48SGeorge Liu             });
1559eeedda23SJohnathan Mantey 
1560eeedda23SJohnathan Mantey         health->populate();
156113451e39SWilly Tu     }
1562eeedda23SJohnathan Mantey 
1563eeedda23SJohnathan Mantey     if (ethData.nicEnabled)
1564eeedda23SJohnathan Mantey     {
15650ef0e289SJohnathan Mantey         jsonResponse["LinkStatus"] = ethData.linkUp ? "LinkUp" : "LinkDown";
15662c70f800SEd Tanous         jsonResponse["Status"]["State"] = "Enabled";
1567029573d4SEd Tanous     }
1568029573d4SEd Tanous     else
1569029573d4SEd Tanous     {
15702c70f800SEd Tanous         jsonResponse["LinkStatus"] = "NoLink";
15712c70f800SEd Tanous         jsonResponse["Status"]["State"] = "Disabled";
1572029573d4SEd Tanous     }
1573aa05fb27SJohnathan Mantey 
15742c70f800SEd Tanous     jsonResponse["SpeedMbps"] = ethData.speed;
157535fb5311STejas Patil     jsonResponse["MTUSize"] = ethData.mtuSize;
157682695a5bSJiaqing Zhao     jsonResponse["MACAddress"] = ethData.macAddress;
15772c70f800SEd Tanous     jsonResponse["DHCPv4"]["DHCPEnabled"] =
157882695a5bSJiaqing Zhao         translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
157982695a5bSJiaqing Zhao     jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpEnabled;
158082695a5bSJiaqing Zhao     jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsEnabled;
158182695a5bSJiaqing Zhao     jsonResponse["DHCPv4"]["UseDomainName"] = ethData.hostNameEnabled;
15821f8c7b5dSJohnathan Mantey 
15832c70f800SEd Tanous     jsonResponse["DHCPv6"]["OperatingMode"] =
158482695a5bSJiaqing Zhao         translateDhcpEnabledToBool(ethData.dhcpEnabled, false) ? "Stateful"
15851f8c7b5dSJohnathan Mantey                                                                : "Disabled";
158682695a5bSJiaqing Zhao     jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpEnabled;
158782695a5bSJiaqing Zhao     jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsEnabled;
158882695a5bSJiaqing Zhao     jsonResponse["DHCPv6"]["UseDomainName"] = ethData.hostNameEnabled;
15892a133282Smanojkiraneda 
159082695a5bSJiaqing Zhao     if (!ethData.hostName.empty())
15914a0cb85cSEd Tanous     {
159282695a5bSJiaqing Zhao         jsonResponse["HostName"] = ethData.hostName;
1593ab6554f1SJoshi-Mansi 
1594ab6554f1SJoshi-Mansi         // When domain name is empty then it means, that it is a network
1595ab6554f1SJoshi-Mansi         // without domain names, and the host name itself must be treated as
1596ab6554f1SJoshi-Mansi         // FQDN
159782695a5bSJiaqing Zhao         std::string fqdn = ethData.hostName;
1598d24bfc7aSJennifer Lee         if (!ethData.domainnames.empty())
1599d24bfc7aSJennifer Lee         {
16002c70f800SEd Tanous             fqdn += "." + ethData.domainnames[0];
1601d24bfc7aSJennifer Lee         }
16022c70f800SEd Tanous         jsonResponse["FQDN"] = fqdn;
16034a0cb85cSEd Tanous     }
16044a0cb85cSEd Tanous 
16057857cb8dSJiaqing Zhao     if (ethData.vlanId)
16067857cb8dSJiaqing Zhao     {
16077857cb8dSJiaqing Zhao         jsonResponse["EthernetInterfaceType"] = "Virtual";
16087857cb8dSJiaqing Zhao         jsonResponse["VLAN"]["VLANEnable"] = true;
16097857cb8dSJiaqing Zhao         jsonResponse["VLAN"]["VLANId"] = *ethData.vlanId;
16107857cb8dSJiaqing Zhao         jsonResponse["VLAN"]["Tagged"] = true;
16117857cb8dSJiaqing Zhao 
16127857cb8dSJiaqing Zhao         nlohmann::json::array_t relatedInterfaces;
16137857cb8dSJiaqing Zhao         nlohmann::json& parentInterface = relatedInterfaces.emplace_back();
16147857cb8dSJiaqing Zhao         parentInterface["@odata.id"] =
16157857cb8dSJiaqing Zhao             boost::urls::format("/redfish/v1/Managers/bmc/EthernetInterfaces",
16167857cb8dSJiaqing Zhao                                 extractParentInterfaceName(ifaceId));
16177857cb8dSJiaqing Zhao         jsonResponse["Links"]["RelatedInterfaces"] =
16187857cb8dSJiaqing Zhao             std::move(relatedInterfaces);
16197857cb8dSJiaqing Zhao     }
16207857cb8dSJiaqing Zhao     else
16217857cb8dSJiaqing Zhao     {
16227857cb8dSJiaqing Zhao         jsonResponse["EthernetInterfaceType"] = "Physical";
16237857cb8dSJiaqing Zhao     }
16247857cb8dSJiaqing Zhao 
16252c70f800SEd Tanous     jsonResponse["NameServers"] = ethData.nameServers;
16262c70f800SEd Tanous     jsonResponse["StaticNameServers"] = ethData.staticNameServers;
16274a0cb85cSEd Tanous 
16282c70f800SEd Tanous     nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"];
16292c70f800SEd Tanous     nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
16302c70f800SEd Tanous     ipv4Array = nlohmann::json::array();
16312c70f800SEd Tanous     ipv4StaticArray = nlohmann::json::array();
16329eb808c1SEd Tanous     for (const auto& ipv4Config : ipv4Data)
16334a0cb85cSEd Tanous     {
16342c70f800SEd Tanous         std::string gatewayStr = ipv4Config.gateway;
1635fa5053a6SGunnar Mills         if (gatewayStr.empty())
1636fa5053a6SGunnar Mills         {
1637fa5053a6SGunnar Mills             gatewayStr = "0.0.0.0";
1638fa5053a6SGunnar Mills         }
16391476687dSEd Tanous         nlohmann::json::object_t ipv4;
16401476687dSEd Tanous         ipv4["AddressOrigin"] = ipv4Config.origin;
16411476687dSEd Tanous         ipv4["SubnetMask"] = ipv4Config.netmask;
16421476687dSEd Tanous         ipv4["Address"] = ipv4Config.address;
16431476687dSEd Tanous         ipv4["Gateway"] = gatewayStr;
1644fa5053a6SGunnar Mills 
16452c70f800SEd Tanous         if (ipv4Config.origin == "Static")
1646d1d50814SRavi Teja         {
16471476687dSEd Tanous             ipv4StaticArray.push_back(ipv4);
1648d1d50814SRavi Teja         }
16491476687dSEd Tanous 
1650b2ba3072SPatrick Williams         ipv4Array.emplace_back(std::move(ipv4));
165101784826SJohnathan Mantey     }
1652d1d50814SRavi Teja 
165382695a5bSJiaqing Zhao     std::string ipv6GatewayStr = ethData.ipv6DefaultGateway;
16547ea79e5eSRavi Teja     if (ipv6GatewayStr.empty())
16557ea79e5eSRavi Teja     {
16567ea79e5eSRavi Teja         ipv6GatewayStr = "0:0:0:0:0:0:0:0";
16577ea79e5eSRavi Teja     }
16587ea79e5eSRavi Teja 
16597ea79e5eSRavi Teja     jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr;
1660e48c0fc5SRavi Teja 
16612c70f800SEd Tanous     nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"];
16622c70f800SEd Tanous     nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"];
16632c70f800SEd Tanous     ipv6Array = nlohmann::json::array();
16642c70f800SEd Tanous     ipv6StaticArray = nlohmann::json::array();
16657f2e23e9SJohnathan Mantey     nlohmann::json& ipv6AddrPolicyTable =
16662c70f800SEd Tanous         jsonResponse["IPv6AddressPolicyTable"];
16677f2e23e9SJohnathan Mantey     ipv6AddrPolicyTable = nlohmann::json::array();
16689eb808c1SEd Tanous     for (const auto& ipv6Config : ipv6Data)
1669e48c0fc5SRavi Teja     {
16701476687dSEd Tanous         nlohmann::json::object_t ipv6;
16711476687dSEd Tanous         ipv6["Address"] = ipv6Config.address;
16721476687dSEd Tanous         ipv6["PrefixLength"] = ipv6Config.prefixLength;
16731476687dSEd Tanous         ipv6["AddressOrigin"] = ipv6Config.origin;
1674f8361275SSunitha Harish 
1675b2ba3072SPatrick Williams         ipv6Array.emplace_back(std::move(ipv6));
16762c70f800SEd Tanous         if (ipv6Config.origin == "Static")
1677e48c0fc5SRavi Teja         {
16781476687dSEd Tanous             nlohmann::json::object_t ipv6Static;
16791476687dSEd Tanous             ipv6Static["Address"] = ipv6Config.address;
16801476687dSEd Tanous             ipv6Static["PrefixLength"] = ipv6Config.prefixLength;
1681b2ba3072SPatrick Williams             ipv6StaticArray.emplace_back(std::move(ipv6Static));
168201784826SJohnathan Mantey         }
1683e48c0fc5SRavi Teja     }
1684588c3f0dSKowalski, Kamil }
1685588c3f0dSKowalski, Kamil 
1686e7caf250SJiaqing Zhao inline void afterDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1687e7caf250SJiaqing Zhao                         const std::string& ifaceId,
1688e7caf250SJiaqing Zhao                         const boost::system::error_code& ec,
1689e7caf250SJiaqing Zhao                         const sdbusplus::message_t& m)
1690e7caf250SJiaqing Zhao {
1691e7caf250SJiaqing Zhao     if (!ec)
1692e7caf250SJiaqing Zhao     {
1693e7caf250SJiaqing Zhao         return;
1694e7caf250SJiaqing Zhao     }
1695e7caf250SJiaqing Zhao     const sd_bus_error* dbusError = m.get_error();
1696e7caf250SJiaqing Zhao     if (dbusError == nullptr)
1697e7caf250SJiaqing Zhao     {
1698e7caf250SJiaqing Zhao         messages::internalError(asyncResp->res);
1699e7caf250SJiaqing Zhao         return;
1700e7caf250SJiaqing Zhao     }
1701e7caf250SJiaqing Zhao     BMCWEB_LOG_DEBUG << "DBus error: " << dbusError->name;
1702e7caf250SJiaqing Zhao 
1703e7caf250SJiaqing Zhao     if (std::string_view("org.freedesktop.DBus.Error.UnknownObject") ==
1704e7caf250SJiaqing Zhao         dbusError->name)
1705e7caf250SJiaqing Zhao     {
1706e7caf250SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "EthernetInterface",
1707e7caf250SJiaqing Zhao                                    ifaceId);
1708e7caf250SJiaqing Zhao         return;
1709e7caf250SJiaqing Zhao     }
1710e7caf250SJiaqing Zhao     if (std::string_view("org.freedesktop.DBus.Error.UnknownMethod") ==
1711e7caf250SJiaqing Zhao         dbusError->name)
1712e7caf250SJiaqing Zhao     {
1713e7caf250SJiaqing Zhao         messages::resourceCannotBeDeleted(asyncResp->res);
1714e7caf250SJiaqing Zhao         return;
1715e7caf250SJiaqing Zhao     }
1716e7caf250SJiaqing Zhao     messages::internalError(asyncResp->res);
1717e7caf250SJiaqing Zhao }
1718e7caf250SJiaqing Zhao 
1719b5ca3fdcSJiaqing Zhao inline void afterVlanCreate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1720b5ca3fdcSJiaqing Zhao                             const std::string& parentInterfaceUri,
1721b5ca3fdcSJiaqing Zhao                             const std::string& vlanInterface,
1722b5ca3fdcSJiaqing Zhao                             const boost::system::error_code& ec,
1723b5ca3fdcSJiaqing Zhao                             const sdbusplus::message_t& m
1724b5ca3fdcSJiaqing Zhao 
1725b5ca3fdcSJiaqing Zhao )
1726b5ca3fdcSJiaqing Zhao {
1727b5ca3fdcSJiaqing Zhao     if (ec)
1728b5ca3fdcSJiaqing Zhao     {
1729b5ca3fdcSJiaqing Zhao         const sd_bus_error* dbusError = m.get_error();
1730b5ca3fdcSJiaqing Zhao         if (dbusError == nullptr)
1731b5ca3fdcSJiaqing Zhao         {
1732b5ca3fdcSJiaqing Zhao             messages::internalError(asyncResp->res);
1733b5ca3fdcSJiaqing Zhao             return;
1734b5ca3fdcSJiaqing Zhao         }
1735b5ca3fdcSJiaqing Zhao         BMCWEB_LOG_DEBUG << "DBus error: " << dbusError->name;
1736b5ca3fdcSJiaqing Zhao 
1737b5ca3fdcSJiaqing Zhao         if (std::string_view(
1738b5ca3fdcSJiaqing Zhao                 "xyz.openbmc_project.Common.Error.ResourceNotFound") ==
1739b5ca3fdcSJiaqing Zhao             dbusError->name)
1740b5ca3fdcSJiaqing Zhao         {
1741b5ca3fdcSJiaqing Zhao             messages::propertyValueNotInList(
1742b5ca3fdcSJiaqing Zhao                 asyncResp->res, parentInterfaceUri,
1743b5ca3fdcSJiaqing Zhao                 "Links/RelatedInterfaces/0/@odata.id");
1744b5ca3fdcSJiaqing Zhao             return;
1745b5ca3fdcSJiaqing Zhao         }
1746b5ca3fdcSJiaqing Zhao         if (std::string_view(
1747b5ca3fdcSJiaqing Zhao                 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
1748b5ca3fdcSJiaqing Zhao             dbusError->name)
1749b5ca3fdcSJiaqing Zhao         {
1750b5ca3fdcSJiaqing Zhao             messages::resourceAlreadyExists(asyncResp->res, "EthernetInterface",
1751b5ca3fdcSJiaqing Zhao                                             "Id", vlanInterface);
1752b5ca3fdcSJiaqing Zhao             return;
1753b5ca3fdcSJiaqing Zhao         }
1754b5ca3fdcSJiaqing Zhao         messages::internalError(asyncResp->res);
1755b5ca3fdcSJiaqing Zhao         return;
1756b5ca3fdcSJiaqing Zhao     }
1757b5ca3fdcSJiaqing Zhao 
1758b5ca3fdcSJiaqing Zhao     const boost::urls::url vlanInterfaceUri = boost::urls::format(
1759b5ca3fdcSJiaqing Zhao         "/redfish/v1/Managers/bmc/EthernetInterfaces/{}", vlanInterface);
1760b5ca3fdcSJiaqing Zhao     asyncResp->res.addHeader("Location", vlanInterfaceUri.buffer());
1761b5ca3fdcSJiaqing Zhao }
1762b5ca3fdcSJiaqing Zhao 
1763bf648f77SEd Tanous inline void requestEthernetInterfacesRoutes(App& app)
1764bf648f77SEd Tanous {
1765bf648f77SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/")
1766ed398213SEd Tanous         .privileges(redfish::privileges::getEthernetInterfaceCollection)
17671476687dSEd Tanous         .methods(boost::beast::http::verb::get)(
17681476687dSEd Tanous             [&app](const crow::Request& req,
17691476687dSEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
17703ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
177145ca1b86SEd Tanous         {
177245ca1b86SEd Tanous             return;
177345ca1b86SEd Tanous         }
177445ca1b86SEd Tanous 
1775bf648f77SEd Tanous         asyncResp->res.jsonValue["@odata.type"] =
1776bf648f77SEd Tanous             "#EthernetInterfaceCollection.EthernetInterfaceCollection";
1777bf648f77SEd Tanous         asyncResp->res.jsonValue["@odata.id"] =
1778bf648f77SEd Tanous             "/redfish/v1/Managers/bmc/EthernetInterfaces";
1779bf648f77SEd Tanous         asyncResp->res.jsonValue["Name"] =
1780bf648f77SEd Tanous             "Ethernet Network Interface Collection";
1781bf648f77SEd Tanous         asyncResp->res.jsonValue["Description"] =
1782bf648f77SEd Tanous             "Collection of EthernetInterfaces for this Manager";
1783bf648f77SEd Tanous 
1784bf648f77SEd Tanous         // Get eth interface list, and call the below callback for JSON
1785bf648f77SEd Tanous         // preparation
1786002d39b4SEd Tanous         getEthernetIfaceList(
178777179532SEd Tanous             [asyncResp](const bool& success,
178877179532SEd Tanous                         const std::vector<std::string>& ifaceList) {
1789bf648f77SEd Tanous             if (!success)
17901abe55efSEd Tanous             {
1791f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
17929391bb9cSRapkiewicz, Pawel                 return;
17939391bb9cSRapkiewicz, Pawel             }
17949391bb9cSRapkiewicz, Pawel 
1795002d39b4SEd Tanous             nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"];
1796bf648f77SEd Tanous             ifaceArray = nlohmann::json::array();
1797bf648f77SEd Tanous             for (const std::string& ifaceItem : ifaceList)
1798bf648f77SEd Tanous             {
17991476687dSEd Tanous                 nlohmann::json::object_t iface;
1800ef4c65b7SEd Tanous                 iface["@odata.id"] = boost::urls::format(
1801ef4c65b7SEd Tanous                     "/redfish/v1/Managers/bmc/EthernetInterfaces/{}",
1802ef4c65b7SEd Tanous                     ifaceItem);
18037857cb8dSJiaqing Zhao                 ifaceArray.push_back(std::move(iface));
1804bf648f77SEd Tanous             }
1805bf648f77SEd Tanous 
1806002d39b4SEd Tanous             asyncResp->res.jsonValue["Members@odata.count"] = ifaceArray.size();
1807bf648f77SEd Tanous             asyncResp->res.jsonValue["@odata.id"] =
1808bf648f77SEd Tanous                 "/redfish/v1/Managers/bmc/EthernetInterfaces";
1809bf648f77SEd Tanous         });
1810bf648f77SEd Tanous         });
1811bf648f77SEd Tanous 
1812b5ca3fdcSJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/")
1813b5ca3fdcSJiaqing Zhao         .privileges(redfish::privileges::postEthernetInterfaceCollection)
1814b5ca3fdcSJiaqing Zhao         .methods(boost::beast::http::verb::post)(
1815b5ca3fdcSJiaqing Zhao             [&app](const crow::Request& req,
1816b5ca3fdcSJiaqing Zhao                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
1817b5ca3fdcSJiaqing Zhao         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1818b5ca3fdcSJiaqing Zhao         {
1819b5ca3fdcSJiaqing Zhao             return;
1820b5ca3fdcSJiaqing Zhao         }
1821b5ca3fdcSJiaqing Zhao 
1822b5ca3fdcSJiaqing Zhao         bool vlanEnable = false;
1823b5ca3fdcSJiaqing Zhao         uint32_t vlanId = 0;
1824b5ca3fdcSJiaqing Zhao         nlohmann::json::array_t relatedInterfaces;
1825b5ca3fdcSJiaqing Zhao 
1826b5ca3fdcSJiaqing Zhao         if (!json_util::readJsonPatch(req, asyncResp->res, "VLAN/VLANEnable",
1827b5ca3fdcSJiaqing Zhao                                       vlanEnable, "VLAN/VLANId", vlanId,
1828b5ca3fdcSJiaqing Zhao                                       "Links/RelatedInterfaces",
1829b5ca3fdcSJiaqing Zhao                                       relatedInterfaces))
1830b5ca3fdcSJiaqing Zhao         {
1831b5ca3fdcSJiaqing Zhao             return;
1832b5ca3fdcSJiaqing Zhao         }
1833b5ca3fdcSJiaqing Zhao 
1834b5ca3fdcSJiaqing Zhao         if (relatedInterfaces.size() != 1)
1835b5ca3fdcSJiaqing Zhao         {
1836b5ca3fdcSJiaqing Zhao             messages::arraySizeTooLong(asyncResp->res,
1837b5ca3fdcSJiaqing Zhao                                        "Links/RelatedInterfaces",
1838b5ca3fdcSJiaqing Zhao                                        relatedInterfaces.size());
1839b5ca3fdcSJiaqing Zhao             return;
1840b5ca3fdcSJiaqing Zhao         }
1841b5ca3fdcSJiaqing Zhao 
1842b5ca3fdcSJiaqing Zhao         std::string parentInterfaceUri;
1843b5ca3fdcSJiaqing Zhao         if (!json_util::readJson(relatedInterfaces[0], asyncResp->res,
1844b5ca3fdcSJiaqing Zhao                                  "@odata.id", parentInterfaceUri))
1845b5ca3fdcSJiaqing Zhao         {
1846b5ca3fdcSJiaqing Zhao             messages::propertyMissing(asyncResp->res,
1847b5ca3fdcSJiaqing Zhao                                       "Links/RelatedInterfaces/0/@odata.id");
1848b5ca3fdcSJiaqing Zhao             return;
1849b5ca3fdcSJiaqing Zhao         }
1850b5ca3fdcSJiaqing Zhao         BMCWEB_LOG_INFO << "Parent Interface URI: " << parentInterfaceUri;
1851b5ca3fdcSJiaqing Zhao 
1852b5ca3fdcSJiaqing Zhao         boost::urls::result<boost::urls::url_view> parsedUri =
1853b5ca3fdcSJiaqing Zhao             boost::urls::parse_relative_ref(parentInterfaceUri);
1854b5ca3fdcSJiaqing Zhao         if (!parsedUri)
1855b5ca3fdcSJiaqing Zhao         {
1856b5ca3fdcSJiaqing Zhao             messages::propertyValueFormatError(
1857b5ca3fdcSJiaqing Zhao                 asyncResp->res, parentInterfaceUri,
1858b5ca3fdcSJiaqing Zhao                 "Links/RelatedInterfaces/0/@odata.id");
1859b5ca3fdcSJiaqing Zhao             return;
1860b5ca3fdcSJiaqing Zhao         }
1861b5ca3fdcSJiaqing Zhao 
1862b5ca3fdcSJiaqing Zhao         std::string parentInterface;
1863b5ca3fdcSJiaqing Zhao         if (!crow::utility::readUrlSegments(
1864b5ca3fdcSJiaqing Zhao                 *parsedUri, "redfish", "v1", "Managers", "bmc",
1865b5ca3fdcSJiaqing Zhao                 "EthernetInterfaces", std::ref(parentInterface)))
1866b5ca3fdcSJiaqing Zhao         {
1867b5ca3fdcSJiaqing Zhao             messages::propertyValueNotInList(
1868b5ca3fdcSJiaqing Zhao                 asyncResp->res, parentInterfaceUri,
1869b5ca3fdcSJiaqing Zhao                 "Links/RelatedInterfaces/0/@odata.id");
1870b5ca3fdcSJiaqing Zhao             return;
1871b5ca3fdcSJiaqing Zhao         }
1872b5ca3fdcSJiaqing Zhao 
1873b5ca3fdcSJiaqing Zhao         if (!vlanEnable)
1874b5ca3fdcSJiaqing Zhao         {
1875b5ca3fdcSJiaqing Zhao             // In OpenBMC implementation, VLANEnable cannot be false on
1876b5ca3fdcSJiaqing Zhao             // create
1877b5ca3fdcSJiaqing Zhao             messages::propertyValueIncorrect(asyncResp->res, "VLAN/VLANEnable",
1878b5ca3fdcSJiaqing Zhao                                              "false");
1879b5ca3fdcSJiaqing Zhao             return;
1880b5ca3fdcSJiaqing Zhao         }
1881b5ca3fdcSJiaqing Zhao 
1882b5ca3fdcSJiaqing Zhao         std::string vlanInterface = parentInterface + "_" +
1883b5ca3fdcSJiaqing Zhao                                     std::to_string(vlanId);
1884b5ca3fdcSJiaqing Zhao         crow::connections::systemBus->async_method_call(
1885b5ca3fdcSJiaqing Zhao             [asyncResp, parentInterfaceUri,
1886b5ca3fdcSJiaqing Zhao              vlanInterface](const boost::system::error_code& ec,
1887b5ca3fdcSJiaqing Zhao                             const sdbusplus::message_t& m) {
1888b5ca3fdcSJiaqing Zhao             afterVlanCreate(asyncResp, parentInterfaceUri, vlanInterface, ec,
1889b5ca3fdcSJiaqing Zhao                             m);
1890b5ca3fdcSJiaqing Zhao             },
1891b5ca3fdcSJiaqing Zhao             "xyz.openbmc_project.Network", "/xyz/openbmc_project/network",
1892b5ca3fdcSJiaqing Zhao             "xyz.openbmc_project.Network.VLAN.Create", "VLAN", parentInterface,
1893b5ca3fdcSJiaqing Zhao             vlanId);
1894b5ca3fdcSJiaqing Zhao         });
1895b5ca3fdcSJiaqing Zhao 
1896bf648f77SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/")
1897ed398213SEd Tanous         .privileges(redfish::privileges::getEthernetInterface)
1898bf648f77SEd Tanous         .methods(boost::beast::http::verb::get)(
189945ca1b86SEd Tanous             [&app](const crow::Request& req,
1900bf648f77SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1901bf648f77SEd Tanous                    const std::string& ifaceId) {
19023ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
190345ca1b86SEd Tanous         {
190445ca1b86SEd Tanous             return;
190545ca1b86SEd Tanous         }
19064a0cb85cSEd Tanous         getEthernetIfaceData(
1907bf648f77SEd Tanous             ifaceId,
190877179532SEd Tanous             [asyncResp, ifaceId](const bool& success,
190977179532SEd Tanous                                  const EthernetInterfaceData& ethData,
191077179532SEd Tanous                                  const std::vector<IPv4AddressData>& ipv4Data,
191177179532SEd Tanous                                  const std::vector<IPv6AddressData>& ipv6Data) {
19124a0cb85cSEd Tanous             if (!success)
19131abe55efSEd Tanous             {
1914bf648f77SEd Tanous                 // TODO(Pawel)consider distinguish between non
1915bf648f77SEd Tanous                 // existing object, and other errors
1916002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
1917002d39b4SEd Tanous                                            ifaceId);
19184a0cb85cSEd Tanous                 return;
19199391bb9cSRapkiewicz, Pawel             }
19204c9afe43SEd Tanous 
19210f74e643SEd Tanous             asyncResp->res.jsonValue["@odata.type"] =
192293bbc953SJiaqing Zhao                 "#EthernetInterface.v1_9_0.EthernetInterface";
1923002d39b4SEd Tanous             asyncResp->res.jsonValue["Name"] = "Manager Ethernet Interface";
19240f74e643SEd Tanous             asyncResp->res.jsonValue["Description"] =
19250f74e643SEd Tanous                 "Management Network Interface";
19260f74e643SEd Tanous 
1927002d39b4SEd Tanous             parseInterfaceData(asyncResp, ifaceId, ethData, ipv4Data, ipv6Data);
19289391bb9cSRapkiewicz, Pawel             });
1929bf648f77SEd Tanous         });
19309391bb9cSRapkiewicz, Pawel 
1931bf648f77SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/")
1932ed398213SEd Tanous         .privileges(redfish::privileges::patchEthernetInterface)
1933bf648f77SEd Tanous         .methods(boost::beast::http::verb::patch)(
193445ca1b86SEd Tanous             [&app](const crow::Request& req,
1935bf648f77SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1936bf648f77SEd Tanous                    const std::string& ifaceId) {
19373ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
193845ca1b86SEd Tanous         {
193945ca1b86SEd Tanous             return;
194045ca1b86SEd Tanous         }
1941bc0bd6e0SEd Tanous         std::optional<std::string> hostname;
1942ab6554f1SJoshi-Mansi         std::optional<std::string> fqdn;
1943d577665bSRatan Gupta         std::optional<std::string> macAddress;
19449a6fc6feSRavi Teja         std::optional<std::string> ipv6DefaultGateway;
1945ddd70dcaSEd Tanous         std::optional<nlohmann::json::array_t> ipv4StaticAddresses;
1946ddd70dcaSEd Tanous         std::optional<nlohmann::json::array_t> ipv6StaticAddresses;
1947f85837bfSRAJESWARAN THILLAIGOVINDAN         std::optional<std::vector<std::string>> staticNameServers;
1948da131a9aSJennifer Lee         std::optional<nlohmann::json> dhcpv4;
19491f8c7b5dSJohnathan Mantey         std::optional<nlohmann::json> dhcpv6;
1950eeedda23SJohnathan Mantey         std::optional<bool> interfaceEnabled;
195135fb5311STejas Patil         std::optional<size_t> mtuSize;
19521f8c7b5dSJohnathan Mantey         DHCPParameters v4dhcpParms;
19531f8c7b5dSJohnathan Mantey         DHCPParameters v6dhcpParms;
19540627a2c7SEd Tanous 
195515ed6780SWilly Tu         if (!json_util::readJsonPatch(
19568d1b46d7Szhanghch05                 req, asyncResp->res, "HostName", hostname, "FQDN", fqdn,
1957002d39b4SEd Tanous                 "IPv4StaticAddresses", ipv4StaticAddresses, "MACAddress",
1958002d39b4SEd Tanous                 macAddress, "StaticNameServers", staticNameServers,
1959002d39b4SEd Tanous                 "IPv6DefaultGateway", ipv6DefaultGateway, "IPv6StaticAddresses",
1960ab6554f1SJoshi-Mansi                 ipv6StaticAddresses, "DHCPv4", dhcpv4, "DHCPv6", dhcpv6,
1961002d39b4SEd Tanous                 "MTUSize", mtuSize, "InterfaceEnabled", interfaceEnabled))
19621abe55efSEd Tanous         {
1963588c3f0dSKowalski, Kamil             return;
1964588c3f0dSKowalski, Kamil         }
1965da131a9aSJennifer Lee         if (dhcpv4)
1966da131a9aSJennifer Lee         {
1967002d39b4SEd Tanous             if (!json_util::readJson(*dhcpv4, asyncResp->res, "DHCPEnabled",
19681f8c7b5dSJohnathan Mantey                                      v4dhcpParms.dhcpv4Enabled, "UseDNSServers",
196982695a5bSJiaqing Zhao                                      v4dhcpParms.useDnsServers, "UseNTPServers",
197082695a5bSJiaqing Zhao                                      v4dhcpParms.useNtpServers, "UseDomainName",
197182695a5bSJiaqing Zhao                                      v4dhcpParms.useDomainName))
19721f8c7b5dSJohnathan Mantey             {
19731f8c7b5dSJohnathan Mantey                 return;
19741f8c7b5dSJohnathan Mantey             }
19751f8c7b5dSJohnathan Mantey         }
19761f8c7b5dSJohnathan Mantey 
19771f8c7b5dSJohnathan Mantey         if (dhcpv6)
19781f8c7b5dSJohnathan Mantey         {
1979002d39b4SEd Tanous             if (!json_util::readJson(*dhcpv6, asyncResp->res, "OperatingMode",
1980002d39b4SEd Tanous                                      v6dhcpParms.dhcpv6OperatingMode,
1981002d39b4SEd Tanous                                      "UseDNSServers", v6dhcpParms.useDnsServers,
1982002d39b4SEd Tanous                                      "UseNTPServers", v6dhcpParms.useNtpServers,
1983002d39b4SEd Tanous                                      "UseDomainName",
198482695a5bSJiaqing Zhao                                      v6dhcpParms.useDomainName))
19851f8c7b5dSJohnathan Mantey             {
19861f8c7b5dSJohnathan Mantey                 return;
19871f8c7b5dSJohnathan Mantey             }
1988da131a9aSJennifer Lee         }
1989da131a9aSJennifer Lee 
1990bf648f77SEd Tanous         // Get single eth interface data, and call the below callback
1991bf648f77SEd Tanous         // for JSON preparation
19924a0cb85cSEd Tanous         getEthernetIfaceData(
19932c70f800SEd Tanous             ifaceId,
1994bf648f77SEd Tanous             [asyncResp, ifaceId, hostname = std::move(hostname),
1995ab6554f1SJoshi-Mansi              fqdn = std::move(fqdn), macAddress = std::move(macAddress),
1996d1d50814SRavi Teja              ipv4StaticAddresses = std::move(ipv4StaticAddresses),
19979a6fc6feSRavi Teja              ipv6DefaultGateway = std::move(ipv6DefaultGateway),
1998e48c0fc5SRavi Teja              ipv6StaticAddresses = std::move(ipv6StaticAddresses),
19991f8c7b5dSJohnathan Mantey              staticNameServers = std::move(staticNameServers),
2000bc20089aSEd Tanous              dhcpv4 = std::move(dhcpv4), dhcpv6 = std::move(dhcpv6), mtuSize,
2001bc20089aSEd Tanous              v4dhcpParms = std::move(v4dhcpParms),
2002f23b7296SEd Tanous              v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled](
2003002d39b4SEd Tanous                 const bool& success, const EthernetInterfaceData& ethData,
200477179532SEd Tanous                 const std::vector<IPv4AddressData>& ipv4Data,
200577179532SEd Tanous                 const std::vector<IPv6AddressData>& ipv6Data) {
20061abe55efSEd Tanous             if (!success)
20071abe55efSEd Tanous             {
2008588c3f0dSKowalski, Kamil                 // ... otherwise return error
2009bf648f77SEd Tanous                 // TODO(Pawel)consider distinguish between non
2010bf648f77SEd Tanous                 // existing object, and other errors
2011002d39b4SEd Tanous                 messages::resourceNotFound(asyncResp->res, "EthernetInterface",
2012002d39b4SEd Tanous                                            ifaceId);
2013588c3f0dSKowalski, Kamil                 return;
2014588c3f0dSKowalski, Kamil             }
2015588c3f0dSKowalski, Kamil 
20161f8c7b5dSJohnathan Mantey             if (dhcpv4 || dhcpv6)
20171f8c7b5dSJohnathan Mantey             {
2018002d39b4SEd Tanous                 handleDHCPPatch(ifaceId, ethData, v4dhcpParms, v6dhcpParms,
2019002d39b4SEd Tanous                                 asyncResp);
20201f8c7b5dSJohnathan Mantey             }
20211f8c7b5dSJohnathan Mantey 
20220627a2c7SEd Tanous             if (hostname)
20231abe55efSEd Tanous             {
20240627a2c7SEd Tanous                 handleHostnamePatch(*hostname, asyncResp);
20251abe55efSEd Tanous             }
20260627a2c7SEd Tanous 
2027ab6554f1SJoshi-Mansi             if (fqdn)
2028ab6554f1SJoshi-Mansi             {
20292c70f800SEd Tanous                 handleFqdnPatch(ifaceId, *fqdn, asyncResp);
2030ab6554f1SJoshi-Mansi             }
2031ab6554f1SJoshi-Mansi 
2032d577665bSRatan Gupta             if (macAddress)
2033d577665bSRatan Gupta             {
2034002d39b4SEd Tanous                 handleMACAddressPatch(ifaceId, *macAddress, asyncResp);
2035d577665bSRatan Gupta             }
2036d577665bSRatan Gupta 
2037d1d50814SRavi Teja             if (ipv4StaticAddresses)
2038d1d50814SRavi Teja             {
2039bf648f77SEd Tanous                 // TODO(ed) for some reason the capture of
2040bf648f77SEd Tanous                 // ipv4Addresses above is returning a const value,
2041bf648f77SEd Tanous                 // not a non-const value. This doesn't really work
2042bf648f77SEd Tanous                 // for us, as we need to be able to efficiently move
2043bf648f77SEd Tanous                 // out the intermedia nlohmann::json objects. This
2044bf648f77SEd Tanous                 // makes a copy of the structure, and operates on
2045bf648f77SEd Tanous                 // that, but could be done more efficiently
2046ddd70dcaSEd Tanous                 nlohmann::json::array_t ipv4Static = *ipv4StaticAddresses;
2047002d39b4SEd Tanous                 handleIPv4StaticPatch(ifaceId, ipv4Static, ipv4Data, asyncResp);
20481abe55efSEd Tanous             }
20490627a2c7SEd Tanous 
2050f85837bfSRAJESWARAN THILLAIGOVINDAN             if (staticNameServers)
2051f85837bfSRAJESWARAN THILLAIGOVINDAN             {
2052002d39b4SEd Tanous                 handleStaticNameServersPatch(ifaceId, *staticNameServers,
2053002d39b4SEd Tanous                                              asyncResp);
2054f85837bfSRAJESWARAN THILLAIGOVINDAN             }
20559a6fc6feSRavi Teja 
20569a6fc6feSRavi Teja             if (ipv6DefaultGateway)
20579a6fc6feSRavi Teja             {
20589a6fc6feSRavi Teja                 messages::propertyNotWritable(asyncResp->res,
20599a6fc6feSRavi Teja                                               "IPv6DefaultGateway");
20609a6fc6feSRavi Teja             }
2061e48c0fc5SRavi Teja 
2062e48c0fc5SRavi Teja             if (ipv6StaticAddresses)
2063e48c0fc5SRavi Teja             {
2064ddd70dcaSEd Tanous                 handleIPv6StaticAddressesPatch(ifaceId, *ipv6StaticAddresses,
2065ddd70dcaSEd Tanous                                                ipv6Data, asyncResp);
2066e48c0fc5SRavi Teja             }
2067eeedda23SJohnathan Mantey 
2068eeedda23SJohnathan Mantey             if (interfaceEnabled)
2069eeedda23SJohnathan Mantey             {
2070002d39b4SEd Tanous                 setEthernetInterfaceBoolProperty(ifaceId, "NICEnabled",
2071002d39b4SEd Tanous                                                  *interfaceEnabled, asyncResp);
2072eeedda23SJohnathan Mantey             }
207335fb5311STejas Patil 
207435fb5311STejas Patil             if (mtuSize)
207535fb5311STejas Patil             {
207635fb5311STejas Patil                 handleMTUSizePatch(ifaceId, *mtuSize, asyncResp);
207735fb5311STejas Patil             }
2078588c3f0dSKowalski, Kamil             });
2079bf648f77SEd Tanous         });
2080e7caf250SJiaqing Zhao 
2081e7caf250SJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/")
2082e7caf250SJiaqing Zhao         .privileges(redfish::privileges::deleteEthernetInterface)
2083e7caf250SJiaqing Zhao         .methods(boost::beast::http::verb::delete_)(
2084e7caf250SJiaqing Zhao             [&app](const crow::Request& req,
2085e7caf250SJiaqing Zhao                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2086e7caf250SJiaqing Zhao                    const std::string& ifaceId) {
2087e7caf250SJiaqing Zhao         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2088e7caf250SJiaqing Zhao         {
2089e7caf250SJiaqing Zhao             return;
2090e7caf250SJiaqing Zhao         }
2091e7caf250SJiaqing Zhao 
2092e7caf250SJiaqing Zhao         crow::connections::systemBus->async_method_call(
2093e7caf250SJiaqing Zhao             [asyncResp, ifaceId](const boost::system::error_code& ec,
2094e7caf250SJiaqing Zhao                                  const sdbusplus::message_t& m) {
2095e7caf250SJiaqing Zhao             afterDelete(asyncResp, ifaceId, ec, m);
2096e7caf250SJiaqing Zhao             },
2097e7caf250SJiaqing Zhao             "xyz.openbmc_project.Network",
2098e7caf250SJiaqing Zhao             std::string("/xyz/openbmc_project/network/") + ifaceId,
2099e7caf250SJiaqing Zhao             "xyz.openbmc_project.Object.Delete", "Delete");
2100e7caf250SJiaqing Zhao         });
21014a0cb85cSEd Tanous }
2102bf648f77SEd Tanous 
21039391bb9cSRapkiewicz, Pawel } // namespace redfish
2104