xref: /openbmc/bmcweb/features/redfish/lib/ethernet.hpp (revision 40e9b92ec19acffb46f83a6e55b18974da5d708e)
1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
49391bb9cSRapkiewicz, Pawel #pragma once
59391bb9cSRapkiewicz, Pawel 
63ccb3adbSEd Tanous #include "app.hpp"
73ccb3adbSEd Tanous #include "dbus_singleton.hpp"
87a1dbc48SGeorge Liu #include "dbus_utility.hpp"
93ccb3adbSEd Tanous #include "error_messages.hpp"
10539d8c6bSEd Tanous #include "generated/enums/ethernet_interface.hpp"
11539d8c6bSEd Tanous #include "generated/enums/resource.hpp"
122c5875a2SEd Tanous #include "human_sort.hpp"
133ccb3adbSEd Tanous #include "query.hpp"
143ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
15033f1e4dSEd Tanous #include "utils/ip_utils.hpp"
163ccb3adbSEd Tanous #include "utils/json_utils.hpp"
17033f1e4dSEd Tanous 
18ce73d5c8SSunitha Harish #include <boost/system/error_code.hpp>
19ef4c65b7SEd Tanous #include <boost/url/format.hpp>
201214b7e7SGunnar Mills 
217a1dbc48SGeorge Liu #include <array>
223dfed536SEd Tanous #include <cstddef>
23ce73d5c8SSunitha Harish #include <memory>
24a24526dcSEd Tanous #include <optional>
253544d2a7SEd Tanous #include <ranges>
26ab6554f1SJoshi-Mansi #include <regex>
277a1dbc48SGeorge Liu #include <string_view>
283dfed536SEd Tanous #include <variant>
2977179532SEd Tanous #include <vector>
309391bb9cSRapkiewicz, Pawel 
311abe55efSEd Tanous namespace redfish
321abe55efSEd Tanous {
339391bb9cSRapkiewicz, Pawel 
344a0cb85cSEd Tanous enum class LinkType
354a0cb85cSEd Tanous {
364a0cb85cSEd Tanous     Local,
374a0cb85cSEd Tanous     Global
384a0cb85cSEd Tanous };
399391bb9cSRapkiewicz, Pawel 
40743eb1c0SJohnathan Mantey enum class IpVersion
41743eb1c0SJohnathan Mantey {
42743eb1c0SJohnathan Mantey     IpV4,
43743eb1c0SJohnathan Mantey     IpV6
44743eb1c0SJohnathan Mantey };
45743eb1c0SJohnathan Mantey 
469391bb9cSRapkiewicz, Pawel /**
479391bb9cSRapkiewicz, Pawel  * Structure for keeping IPv4 data required by Redfish
489391bb9cSRapkiewicz, Pawel  */
491abe55efSEd Tanous struct IPv4AddressData
501abe55efSEd Tanous {
51179db1d7SKowalski, Kamil     std::string id;
524a0cb85cSEd Tanous     std::string address;
534a0cb85cSEd Tanous     std::string domain;
544a0cb85cSEd Tanous     std::string gateway;
559391bb9cSRapkiewicz, Pawel     std::string netmask;
569391bb9cSRapkiewicz, Pawel     std::string origin;
5777179532SEd Tanous     LinkType linktype{};
5877179532SEd Tanous     bool isActive{};
599391bb9cSRapkiewicz, Pawel };
609391bb9cSRapkiewicz, Pawel 
619391bb9cSRapkiewicz, Pawel /**
62e48c0fc5SRavi Teja  * Structure for keeping IPv6 data required by Redfish
63e48c0fc5SRavi Teja  */
64e48c0fc5SRavi Teja struct IPv6AddressData
65e48c0fc5SRavi Teja {
66e48c0fc5SRavi Teja     std::string id;
67e48c0fc5SRavi Teja     std::string address;
68e48c0fc5SRavi Teja     std::string origin;
6977179532SEd Tanous     uint8_t prefixLength = 0;
70e48c0fc5SRavi Teja };
71ce73d5c8SSunitha Harish 
72ce73d5c8SSunitha Harish /**
73ce73d5c8SSunitha Harish  * Structure for keeping static route data required by Redfish
74ce73d5c8SSunitha Harish  */
75ce73d5c8SSunitha Harish struct StaticGatewayData
76ce73d5c8SSunitha Harish {
77ce73d5c8SSunitha Harish     std::string id;
78ce73d5c8SSunitha Harish     std::string gateway;
79ce73d5c8SSunitha Harish     size_t prefixLength = 0;
80ce73d5c8SSunitha Harish     std::string protocol;
81ce73d5c8SSunitha Harish };
82ce73d5c8SSunitha Harish 
83e48c0fc5SRavi Teja /**
849391bb9cSRapkiewicz, Pawel  * Structure for keeping basic single Ethernet Interface information
859391bb9cSRapkiewicz, Pawel  * available from DBus
869391bb9cSRapkiewicz, Pawel  */
871abe55efSEd Tanous struct EthernetInterfaceData
881abe55efSEd Tanous {
894a0cb85cSEd Tanous     uint32_t speed;
9035fb5311STejas Patil     size_t mtuSize;
9182695a5bSJiaqing Zhao     bool autoNeg;
92e4588158SJishnu CM     bool dnsv4Enabled;
93e4588158SJishnu CM     bool dnsv6Enabled;
9491c441ecSRavi Teja     bool domainv4Enabled;
9591c441ecSRavi Teja     bool domainv6Enabled;
96e4588158SJishnu CM     bool ntpv4Enabled;
97e4588158SJishnu CM     bool ntpv6Enabled;
98e4588158SJishnu CM     bool hostNamev4Enabled;
99e4588158SJishnu CM     bool hostNamev6Enabled;
100aa05fb27SJohnathan Mantey     bool linkUp;
101eeedda23SJohnathan Mantey     bool nicEnabled;
102b10d8db0SRavi Teja     bool ipv6AcceptRa;
10382695a5bSJiaqing Zhao     std::string dhcpEnabled;
1041f8c7b5dSJohnathan Mantey     std::string operatingMode;
10582695a5bSJiaqing Zhao     std::string hostName;
10682695a5bSJiaqing Zhao     std::string defaultGateway;
10782695a5bSJiaqing Zhao     std::string ipv6DefaultGateway;
108ce73d5c8SSunitha Harish     std::string ipv6StaticDefaultGateway;
1094652c640SAsmitha Karunanithi     std::optional<std::string> macAddress;
11017e22024SJiaqing Zhao     std::optional<uint32_t> vlanId;
1110f6efdc1Smanojkiran.eda@gmail.com     std::vector<std::string> nameServers;
1120f6efdc1Smanojkiran.eda@gmail.com     std::vector<std::string> staticNameServers;
113d24bfc7aSJennifer Lee     std::vector<std::string> domainnames;
1149391bb9cSRapkiewicz, Pawel };
1159391bb9cSRapkiewicz, Pawel 
1161f8c7b5dSJohnathan Mantey struct DHCPParameters
1171f8c7b5dSJohnathan Mantey {
1181f8c7b5dSJohnathan Mantey     std::optional<bool> dhcpv4Enabled;
11982695a5bSJiaqing Zhao     std::optional<bool> useDnsServers;
12082695a5bSJiaqing Zhao     std::optional<bool> useNtpServers;
12182695a5bSJiaqing Zhao     std::optional<bool> useDomainName;
1221f8c7b5dSJohnathan Mantey     std::optional<std::string> dhcpv6OperatingMode;
1231f8c7b5dSJohnathan Mantey };
1241f8c7b5dSJohnathan Mantey 
1259391bb9cSRapkiewicz, Pawel // Helper function that changes bits netmask notation (i.e. /24)
1269391bb9cSRapkiewicz, Pawel // into full dot notation
1271abe55efSEd Tanous inline std::string getNetmask(unsigned int bits)
1281abe55efSEd Tanous {
1299391bb9cSRapkiewicz, Pawel     uint32_t value = 0xffffffff << (32 - bits);
1309391bb9cSRapkiewicz, Pawel     std::string netmask = std::to_string((value >> 24) & 0xff) + "." +
1319391bb9cSRapkiewicz, Pawel                           std::to_string((value >> 16) & 0xff) + "." +
1329391bb9cSRapkiewicz, Pawel                           std::to_string((value >> 8) & 0xff) + "." +
1339391bb9cSRapkiewicz, Pawel                           std::to_string(value & 0xff);
1349391bb9cSRapkiewicz, Pawel     return netmask;
1359391bb9cSRapkiewicz, Pawel }
1369391bb9cSRapkiewicz, Pawel 
13782695a5bSJiaqing Zhao inline bool translateDhcpEnabledToBool(const std::string& inputDHCP,
1381f8c7b5dSJohnathan Mantey                                        bool isIPv4)
1391f8c7b5dSJohnathan Mantey {
1401f8c7b5dSJohnathan Mantey     if (isIPv4)
1411f8c7b5dSJohnathan Mantey     {
1421f8c7b5dSJohnathan Mantey         return (
1431f8c7b5dSJohnathan Mantey             (inputDHCP ==
1441f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4") ||
1451f8c7b5dSJohnathan Mantey             (inputDHCP ==
1461f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
1471f8c7b5dSJohnathan Mantey     }
1481f8c7b5dSJohnathan Mantey     return ((inputDHCP ==
1491f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") ||
1501f8c7b5dSJohnathan Mantey             (inputDHCP ==
1511f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
1521f8c7b5dSJohnathan Mantey }
1531f8c7b5dSJohnathan Mantey 
1542c70f800SEd Tanous inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6)
1551f8c7b5dSJohnathan Mantey {
1561f8c7b5dSJohnathan Mantey     if (isIPv4 && isIPv6)
1571f8c7b5dSJohnathan Mantey     {
1581f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both";
1591f8c7b5dSJohnathan Mantey     }
1603174e4dfSEd Tanous     if (isIPv4)
1611f8c7b5dSJohnathan Mantey     {
1621f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4";
1631f8c7b5dSJohnathan Mantey     }
1643174e4dfSEd Tanous     if (isIPv6)
1651f8c7b5dSJohnathan Mantey     {
1661f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6";
1671f8c7b5dSJohnathan Mantey     }
1681f8c7b5dSJohnathan Mantey     return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none";
1691f8c7b5dSJohnathan Mantey }
1701f8c7b5dSJohnathan Mantey 
171bd79bce8SPatrick Williams inline std::string translateAddressOriginDbusToRedfish(
172bd79bce8SPatrick Williams     const std::string& inputOrigin, bool isIPv4)
1731abe55efSEd Tanous {
1744a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
1751abe55efSEd Tanous     {
1764a0cb85cSEd Tanous         return "Static";
1779391bb9cSRapkiewicz, Pawel     }
1784a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal")
1791abe55efSEd Tanous     {
1804a0cb85cSEd Tanous         if (isIPv4)
1811abe55efSEd Tanous         {
1824a0cb85cSEd Tanous             return "IPv4LinkLocal";
1831abe55efSEd Tanous         }
1844a0cb85cSEd Tanous         return "LinkLocal";
1859391bb9cSRapkiewicz, Pawel     }
1864a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
1871abe55efSEd Tanous     {
1884a0cb85cSEd Tanous         if (isIPv4)
1894a0cb85cSEd Tanous         {
1904a0cb85cSEd Tanous             return "DHCP";
1914a0cb85cSEd Tanous         }
1924a0cb85cSEd Tanous         return "DHCPv6";
1934a0cb85cSEd Tanous     }
1944a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC")
1954a0cb85cSEd Tanous     {
1964a0cb85cSEd Tanous         return "SLAAC";
1974a0cb85cSEd Tanous     }
1984a0cb85cSEd Tanous     return "";
1994a0cb85cSEd Tanous }
2004a0cb85cSEd Tanous 
20102cad96eSEd Tanous inline bool extractEthernetInterfaceData(
20202cad96eSEd Tanous     const std::string& ethifaceId,
20302cad96eSEd Tanous     const dbus::utility::ManagedObjectType& dbusData,
2044a0cb85cSEd Tanous     EthernetInterfaceData& ethData)
2054a0cb85cSEd Tanous {
2064c9afe43SEd Tanous     bool idFound = false;
20702cad96eSEd Tanous     for (const auto& objpath : dbusData)
2084a0cb85cSEd Tanous     {
20902cad96eSEd Tanous         for (const auto& ifacePair : objpath.second)
2104a0cb85cSEd Tanous         {
21181ce609eSEd Tanous             if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId)
212029573d4SEd Tanous             {
2134c9afe43SEd Tanous                 idFound = true;
2144a0cb85cSEd Tanous                 if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
2154a0cb85cSEd Tanous                 {
2164a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2174a0cb85cSEd Tanous                     {
2184a0cb85cSEd Tanous                         if (propertyPair.first == "MACAddress")
2194a0cb85cSEd Tanous                         {
2204a0cb85cSEd Tanous                             const std::string* mac =
221abf2add6SEd Tanous                                 std::get_if<std::string>(&propertyPair.second);
2224a0cb85cSEd Tanous                             if (mac != nullptr)
2234a0cb85cSEd Tanous                             {
22482695a5bSJiaqing Zhao                                 ethData.macAddress = *mac;
2254a0cb85cSEd Tanous                             }
2264a0cb85cSEd Tanous                         }
2274a0cb85cSEd Tanous                     }
2284a0cb85cSEd Tanous                 }
2294a0cb85cSEd Tanous                 else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN")
2304a0cb85cSEd Tanous                 {
2314a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2324a0cb85cSEd Tanous                     {
2334a0cb85cSEd Tanous                         if (propertyPair.first == "Id")
2344a0cb85cSEd Tanous                         {
2351b6b96c5SEd Tanous                             const uint32_t* id =
236abf2add6SEd Tanous                                 std::get_if<uint32_t>(&propertyPair.second);
2374a0cb85cSEd Tanous                             if (id != nullptr)
2384a0cb85cSEd Tanous                             {
23917e22024SJiaqing Zhao                                 ethData.vlanId = *id;
2404a0cb85cSEd Tanous                             }
2414a0cb85cSEd Tanous                         }
2424a0cb85cSEd Tanous                     }
2434a0cb85cSEd Tanous                 }
2444a0cb85cSEd Tanous                 else if (ifacePair.first ==
2454a0cb85cSEd Tanous                          "xyz.openbmc_project.Network.EthernetInterface")
2464a0cb85cSEd Tanous                 {
2474a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2484a0cb85cSEd Tanous                     {
2494a0cb85cSEd Tanous                         if (propertyPair.first == "AutoNeg")
2504a0cb85cSEd Tanous                         {
2512c70f800SEd Tanous                             const bool* autoNeg =
252abf2add6SEd Tanous                                 std::get_if<bool>(&propertyPair.second);
2532c70f800SEd Tanous                             if (autoNeg != nullptr)
2544a0cb85cSEd Tanous                             {
25582695a5bSJiaqing Zhao                                 ethData.autoNeg = *autoNeg;
2564a0cb85cSEd Tanous                             }
2574a0cb85cSEd Tanous                         }
2584a0cb85cSEd Tanous                         else if (propertyPair.first == "Speed")
2594a0cb85cSEd Tanous                         {
2604a0cb85cSEd Tanous                             const uint32_t* speed =
261abf2add6SEd Tanous                                 std::get_if<uint32_t>(&propertyPair.second);
2624a0cb85cSEd Tanous                             if (speed != nullptr)
2634a0cb85cSEd Tanous                             {
2644a0cb85cSEd Tanous                                 ethData.speed = *speed;
2654a0cb85cSEd Tanous                             }
2664a0cb85cSEd Tanous                         }
26735fb5311STejas Patil                         else if (propertyPair.first == "MTU")
26835fb5311STejas Patil                         {
2693e7a8da6SAnthony                             const size_t* mtuSize =
2703e7a8da6SAnthony                                 std::get_if<size_t>(&propertyPair.second);
27135fb5311STejas Patil                             if (mtuSize != nullptr)
27235fb5311STejas Patil                             {
27335fb5311STejas Patil                                 ethData.mtuSize = *mtuSize;
27435fb5311STejas Patil                             }
27535fb5311STejas Patil                         }
276aa05fb27SJohnathan Mantey                         else if (propertyPair.first == "LinkUp")
277aa05fb27SJohnathan Mantey                         {
278aa05fb27SJohnathan Mantey                             const bool* linkUp =
279aa05fb27SJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
280aa05fb27SJohnathan Mantey                             if (linkUp != nullptr)
281aa05fb27SJohnathan Mantey                             {
282aa05fb27SJohnathan Mantey                                 ethData.linkUp = *linkUp;
283aa05fb27SJohnathan Mantey                             }
284aa05fb27SJohnathan Mantey                         }
285eeedda23SJohnathan Mantey                         else if (propertyPair.first == "NICEnabled")
286eeedda23SJohnathan Mantey                         {
287eeedda23SJohnathan Mantey                             const bool* nicEnabled =
288eeedda23SJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
289eeedda23SJohnathan Mantey                             if (nicEnabled != nullptr)
290eeedda23SJohnathan Mantey                             {
291eeedda23SJohnathan Mantey                                 ethData.nicEnabled = *nicEnabled;
292eeedda23SJohnathan Mantey                             }
293eeedda23SJohnathan Mantey                         }
294b10d8db0SRavi Teja                         else if (propertyPair.first == "IPv6AcceptRA")
295b10d8db0SRavi Teja                         {
296b10d8db0SRavi Teja                             const bool* ipv6AcceptRa =
297b10d8db0SRavi Teja                                 std::get_if<bool>(&propertyPair.second);
298b10d8db0SRavi Teja                             if (ipv6AcceptRa != nullptr)
299b10d8db0SRavi Teja                             {
300b10d8db0SRavi Teja                                 ethData.ipv6AcceptRa = *ipv6AcceptRa;
301b10d8db0SRavi Teja                             }
302b10d8db0SRavi Teja                         }
303f85837bfSRAJESWARAN THILLAIGOVINDAN                         else if (propertyPair.first == "Nameservers")
304029573d4SEd Tanous                         {
305029573d4SEd Tanous                             const std::vector<std::string>* nameservers =
3068d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
307029573d4SEd Tanous                                     &propertyPair.second);
308029573d4SEd Tanous                             if (nameservers != nullptr)
309029573d4SEd Tanous                             {
310f23b7296SEd Tanous                                 ethData.nameServers = *nameservers;
3110f6efdc1Smanojkiran.eda@gmail.com                             }
3120f6efdc1Smanojkiran.eda@gmail.com                         }
3130f6efdc1Smanojkiran.eda@gmail.com                         else if (propertyPair.first == "StaticNameServers")
3140f6efdc1Smanojkiran.eda@gmail.com                         {
3150f6efdc1Smanojkiran.eda@gmail.com                             const std::vector<std::string>* staticNameServers =
3168d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
3170f6efdc1Smanojkiran.eda@gmail.com                                     &propertyPair.second);
3180f6efdc1Smanojkiran.eda@gmail.com                             if (staticNameServers != nullptr)
3190f6efdc1Smanojkiran.eda@gmail.com                             {
320f23b7296SEd Tanous                                 ethData.staticNameServers = *staticNameServers;
3214a0cb85cSEd Tanous                             }
3224a0cb85cSEd Tanous                         }
3232a133282Smanojkiraneda                         else if (propertyPair.first == "DHCPEnabled")
3242a133282Smanojkiraneda                         {
3252c70f800SEd Tanous                             const std::string* dhcpEnabled =
3261f8c7b5dSJohnathan Mantey                                 std::get_if<std::string>(&propertyPair.second);
3272c70f800SEd Tanous                             if (dhcpEnabled != nullptr)
3282a133282Smanojkiraneda                             {
32982695a5bSJiaqing Zhao                                 ethData.dhcpEnabled = *dhcpEnabled;
3302a133282Smanojkiraneda                             }
3312a133282Smanojkiraneda                         }
332d24bfc7aSJennifer Lee                         else if (propertyPair.first == "DomainName")
333d24bfc7aSJennifer Lee                         {
334d24bfc7aSJennifer Lee                             const std::vector<std::string>* domainNames =
3358d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
336d24bfc7aSJennifer Lee                                     &propertyPair.second);
337d24bfc7aSJennifer Lee                             if (domainNames != nullptr)
338d24bfc7aSJennifer Lee                             {
339f23b7296SEd Tanous                                 ethData.domainnames = *domainNames;
340d24bfc7aSJennifer Lee                             }
341d24bfc7aSJennifer Lee                         }
3429010ec2eSRavi Teja                         else if (propertyPair.first == "DefaultGateway")
3439010ec2eSRavi Teja                         {
3449010ec2eSRavi Teja                             const std::string* defaultGateway =
3459010ec2eSRavi Teja                                 std::get_if<std::string>(&propertyPair.second);
3469010ec2eSRavi Teja                             if (defaultGateway != nullptr)
3479010ec2eSRavi Teja                             {
3489010ec2eSRavi Teja                                 std::string defaultGatewayStr = *defaultGateway;
3499010ec2eSRavi Teja                                 if (defaultGatewayStr.empty())
3509010ec2eSRavi Teja                                 {
35182695a5bSJiaqing Zhao                                     ethData.defaultGateway = "0.0.0.0";
3529010ec2eSRavi Teja                                 }
3539010ec2eSRavi Teja                                 else
3549010ec2eSRavi Teja                                 {
35582695a5bSJiaqing Zhao                                     ethData.defaultGateway = defaultGatewayStr;
3569010ec2eSRavi Teja                                 }
3579010ec2eSRavi Teja                             }
3589010ec2eSRavi Teja                         }
3599010ec2eSRavi Teja                         else if (propertyPair.first == "DefaultGateway6")
3609010ec2eSRavi Teja                         {
3619010ec2eSRavi Teja                             const std::string* defaultGateway6 =
3629010ec2eSRavi Teja                                 std::get_if<std::string>(&propertyPair.second);
3639010ec2eSRavi Teja                             if (defaultGateway6 != nullptr)
3649010ec2eSRavi Teja                             {
3659010ec2eSRavi Teja                                 std::string defaultGateway6Str =
3669010ec2eSRavi Teja                                     *defaultGateway6;
3679010ec2eSRavi Teja                                 if (defaultGateway6Str.empty())
3689010ec2eSRavi Teja                                 {
36982695a5bSJiaqing Zhao                                     ethData.ipv6DefaultGateway =
3709010ec2eSRavi Teja                                         "0:0:0:0:0:0:0:0";
3719010ec2eSRavi Teja                                 }
3729010ec2eSRavi Teja                                 else
3739010ec2eSRavi Teja                                 {
37482695a5bSJiaqing Zhao                                     ethData.ipv6DefaultGateway =
3759010ec2eSRavi Teja                                         defaultGateway6Str;
3769010ec2eSRavi Teja                                 }
3779010ec2eSRavi Teja                             }
3789010ec2eSRavi Teja                         }
379029573d4SEd Tanous                     }
380029573d4SEd Tanous                 }
381029573d4SEd Tanous             }
3821f8c7b5dSJohnathan Mantey 
383e4588158SJishnu CM             sdbusplus::message::object_path path(
384e4588158SJishnu CM                 "/xyz/openbmc_project/network");
385bd79bce8SPatrick Williams             sdbusplus::message::object_path dhcp4Path =
386bd79bce8SPatrick Williams                 path / ethifaceId / "dhcp4";
387e4588158SJishnu CM 
388e4588158SJishnu CM             if (sdbusplus::message::object_path(objpath.first) == dhcp4Path)
3891f8c7b5dSJohnathan Mantey             {
3901f8c7b5dSJohnathan Mantey                 if (ifacePair.first ==
3911f8c7b5dSJohnathan Mantey                     "xyz.openbmc_project.Network.DHCPConfiguration")
3921f8c7b5dSJohnathan Mantey                 {
3931f8c7b5dSJohnathan Mantey                     for (const auto& propertyPair : ifacePair.second)
3941f8c7b5dSJohnathan Mantey                     {
3951f8c7b5dSJohnathan Mantey                         if (propertyPair.first == "DNSEnabled")
3961f8c7b5dSJohnathan Mantey                         {
3972c70f800SEd Tanous                             const bool* dnsEnabled =
3981f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
3992c70f800SEd Tanous                             if (dnsEnabled != nullptr)
4001f8c7b5dSJohnathan Mantey                             {
401e4588158SJishnu CM                                 ethData.dnsv4Enabled = *dnsEnabled;
4021f8c7b5dSJohnathan Mantey                             }
4031f8c7b5dSJohnathan Mantey                         }
40491c441ecSRavi Teja                         else if (propertyPair.first == "DomainEnabled")
40591c441ecSRavi Teja                         {
40691c441ecSRavi Teja                             const bool* domainEnabled =
40791c441ecSRavi Teja                                 std::get_if<bool>(&propertyPair.second);
40891c441ecSRavi Teja                             if (domainEnabled != nullptr)
40991c441ecSRavi Teja                             {
41091c441ecSRavi Teja                                 ethData.domainv4Enabled = *domainEnabled;
41191c441ecSRavi Teja                             }
41291c441ecSRavi Teja                         }
4131f8c7b5dSJohnathan Mantey                         else if (propertyPair.first == "NTPEnabled")
4141f8c7b5dSJohnathan Mantey                         {
4152c70f800SEd Tanous                             const bool* ntpEnabled =
4161f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
4172c70f800SEd Tanous                             if (ntpEnabled != nullptr)
4181f8c7b5dSJohnathan Mantey                             {
419e4588158SJishnu CM                                 ethData.ntpv4Enabled = *ntpEnabled;
4201f8c7b5dSJohnathan Mantey                             }
4211f8c7b5dSJohnathan Mantey                         }
4221f8c7b5dSJohnathan Mantey                         else if (propertyPair.first == "HostNameEnabled")
4231f8c7b5dSJohnathan Mantey                         {
4242c70f800SEd Tanous                             const bool* hostNameEnabled =
4251f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
4262c70f800SEd Tanous                             if (hostNameEnabled != nullptr)
4271f8c7b5dSJohnathan Mantey                             {
428e4588158SJishnu CM                                 ethData.hostNamev4Enabled = *hostNameEnabled;
429e4588158SJishnu CM                             }
430e4588158SJishnu CM                         }
431e4588158SJishnu CM                     }
432e4588158SJishnu CM                 }
433e4588158SJishnu CM             }
434e4588158SJishnu CM 
435bd79bce8SPatrick Williams             sdbusplus::message::object_path dhcp6Path =
436bd79bce8SPatrick Williams                 path / ethifaceId / "dhcp6";
437e4588158SJishnu CM 
438e4588158SJishnu CM             if (sdbusplus::message::object_path(objpath.first) == dhcp6Path)
439e4588158SJishnu CM             {
440e4588158SJishnu CM                 if (ifacePair.first ==
441e4588158SJishnu CM                     "xyz.openbmc_project.Network.DHCPConfiguration")
442e4588158SJishnu CM                 {
443e4588158SJishnu CM                     for (const auto& propertyPair : ifacePair.second)
444e4588158SJishnu CM                     {
445e4588158SJishnu CM                         if (propertyPair.first == "DNSEnabled")
446e4588158SJishnu CM                         {
447e4588158SJishnu CM                             const bool* dnsEnabled =
448e4588158SJishnu CM                                 std::get_if<bool>(&propertyPair.second);
449e4588158SJishnu CM                             if (dnsEnabled != nullptr)
450e4588158SJishnu CM                             {
451e4588158SJishnu CM                                 ethData.dnsv6Enabled = *dnsEnabled;
452e4588158SJishnu CM                             }
453e4588158SJishnu CM                         }
45491c441ecSRavi Teja                         if (propertyPair.first == "DomainEnabled")
45591c441ecSRavi Teja                         {
45691c441ecSRavi Teja                             const bool* domainEnabled =
45791c441ecSRavi Teja                                 std::get_if<bool>(&propertyPair.second);
45891c441ecSRavi Teja                             if (domainEnabled != nullptr)
45991c441ecSRavi Teja                             {
46091c441ecSRavi Teja                                 ethData.domainv6Enabled = *domainEnabled;
46191c441ecSRavi Teja                             }
46291c441ecSRavi Teja                         }
463e4588158SJishnu CM                         else if (propertyPair.first == "NTPEnabled")
464e4588158SJishnu CM                         {
465e4588158SJishnu CM                             const bool* ntpEnabled =
466e4588158SJishnu CM                                 std::get_if<bool>(&propertyPair.second);
467e4588158SJishnu CM                             if (ntpEnabled != nullptr)
468e4588158SJishnu CM                             {
469e4588158SJishnu CM                                 ethData.ntpv6Enabled = *ntpEnabled;
470e4588158SJishnu CM                             }
471e4588158SJishnu CM                         }
472e4588158SJishnu CM                         else if (propertyPair.first == "HostNameEnabled")
473e4588158SJishnu CM                         {
474e4588158SJishnu CM                             const bool* hostNameEnabled =
475e4588158SJishnu CM                                 std::get_if<bool>(&propertyPair.second);
476e4588158SJishnu CM                             if (hostNameEnabled != nullptr)
477e4588158SJishnu CM                             {
478e4588158SJishnu CM                                 ethData.hostNamev6Enabled = *hostNameEnabled;
4791f8c7b5dSJohnathan Mantey                             }
4801f8c7b5dSJohnathan Mantey                         }
4811f8c7b5dSJohnathan Mantey                     }
4821f8c7b5dSJohnathan Mantey                 }
4831f8c7b5dSJohnathan Mantey             }
484029573d4SEd Tanous             // System configuration shows up in the global namespace, so no need
485029573d4SEd Tanous             // to check eth number
486029573d4SEd Tanous             if (ifacePair.first ==
4874a0cb85cSEd Tanous                 "xyz.openbmc_project.Network.SystemConfiguration")
4884a0cb85cSEd Tanous             {
4894a0cb85cSEd Tanous                 for (const auto& propertyPair : ifacePair.second)
4904a0cb85cSEd Tanous                 {
4914a0cb85cSEd Tanous                     if (propertyPair.first == "HostName")
4924a0cb85cSEd Tanous                     {
4934a0cb85cSEd Tanous                         const std::string* hostname =
4948d78b7a9SPatrick Williams                             std::get_if<std::string>(&propertyPair.second);
4954a0cb85cSEd Tanous                         if (hostname != nullptr)
4964a0cb85cSEd Tanous                         {
49782695a5bSJiaqing Zhao                             ethData.hostName = *hostname;
4984a0cb85cSEd Tanous                         }
4994a0cb85cSEd Tanous                     }
5004a0cb85cSEd Tanous                 }
5014a0cb85cSEd Tanous             }
5024a0cb85cSEd Tanous         }
5034a0cb85cSEd Tanous     }
5044c9afe43SEd Tanous     return idFound;
5054a0cb85cSEd Tanous }
5064a0cb85cSEd Tanous 
507e48c0fc5SRavi Teja // Helper function that extracts data for single ethernet ipv6 address
50877179532SEd Tanous inline void extractIPV6Data(const std::string& ethifaceId,
509711ac7a9SEd Tanous                             const dbus::utility::ManagedObjectType& dbusData,
51077179532SEd Tanous                             std::vector<IPv6AddressData>& ipv6Config)
511e48c0fc5SRavi Teja {
512bd79bce8SPatrick Williams     const std::string ipPathStart =
513bd79bce8SPatrick Williams         "/xyz/openbmc_project/network/" + ethifaceId;
514e48c0fc5SRavi Teja 
515e48c0fc5SRavi Teja     // Since there might be several IPv6 configurations aligned with
516e48c0fc5SRavi Teja     // single ethernet interface, loop over all of them
51781ce609eSEd Tanous     for (const auto& objpath : dbusData)
518e48c0fc5SRavi Teja     {
519e48c0fc5SRavi Teja         // Check if proper pattern for object path appears
520353163e9STony Lee         if (objpath.first.str.starts_with(ipPathStart + "/"))
521e48c0fc5SRavi Teja         {
5229eb808c1SEd Tanous             for (const auto& interface : objpath.second)
523e48c0fc5SRavi Teja             {
524e48c0fc5SRavi Teja                 if (interface.first == "xyz.openbmc_project.Network.IP")
525e48c0fc5SRavi Teja                 {
526bd79bce8SPatrick Williams                     auto type = std::ranges::find_if(
527bd79bce8SPatrick Williams                         interface.second, [](const auto& property) {
528353163e9STony Lee                             return property.first == "Type";
529353163e9STony Lee                         });
530353163e9STony Lee                     if (type == interface.second.end())
531353163e9STony Lee                     {
532353163e9STony Lee                         continue;
533353163e9STony Lee                     }
534353163e9STony Lee 
535353163e9STony Lee                     const std::string* typeStr =
536353163e9STony Lee                         std::get_if<std::string>(&type->second);
537353163e9STony Lee 
538353163e9STony Lee                     if (typeStr == nullptr ||
539353163e9STony Lee                         (*typeStr !=
540353163e9STony Lee                          "xyz.openbmc_project.Network.IP.Protocol.IPv6"))
541353163e9STony Lee                     {
542353163e9STony Lee                         continue;
543353163e9STony Lee                     }
544353163e9STony Lee 
545e48c0fc5SRavi Teja                     // Instance IPv6AddressData structure, and set as
546e48c0fc5SRavi Teja                     // appropriate
54777179532SEd Tanous                     IPv6AddressData& ipv6Address = ipv6Config.emplace_back();
5482c70f800SEd Tanous                     ipv6Address.id =
549353163e9STony Lee                         objpath.first.str.substr(ipPathStart.size());
5509eb808c1SEd Tanous                     for (const auto& property : interface.second)
551e48c0fc5SRavi Teja                     {
552e48c0fc5SRavi Teja                         if (property.first == "Address")
553e48c0fc5SRavi Teja                         {
554e48c0fc5SRavi Teja                             const std::string* address =
555e48c0fc5SRavi Teja                                 std::get_if<std::string>(&property.second);
556e48c0fc5SRavi Teja                             if (address != nullptr)
557e48c0fc5SRavi Teja                             {
5582c70f800SEd Tanous                                 ipv6Address.address = *address;
559e48c0fc5SRavi Teja                             }
560e48c0fc5SRavi Teja                         }
561e48c0fc5SRavi Teja                         else if (property.first == "Origin")
562e48c0fc5SRavi Teja                         {
563e48c0fc5SRavi Teja                             const std::string* origin =
564e48c0fc5SRavi Teja                                 std::get_if<std::string>(&property.second);
565e48c0fc5SRavi Teja                             if (origin != nullptr)
566e48c0fc5SRavi Teja                             {
5672c70f800SEd Tanous                                 ipv6Address.origin =
568e48c0fc5SRavi Teja                                     translateAddressOriginDbusToRedfish(*origin,
569e48c0fc5SRavi Teja                                                                         false);
570e48c0fc5SRavi Teja                             }
571e48c0fc5SRavi Teja                         }
572e48c0fc5SRavi Teja                         else if (property.first == "PrefixLength")
573e48c0fc5SRavi Teja                         {
574e48c0fc5SRavi Teja                             const uint8_t* prefix =
575e48c0fc5SRavi Teja                                 std::get_if<uint8_t>(&property.second);
576e48c0fc5SRavi Teja                             if (prefix != nullptr)
577e48c0fc5SRavi Teja                             {
5782c70f800SEd Tanous                                 ipv6Address.prefixLength = *prefix;
579e48c0fc5SRavi Teja                             }
580e48c0fc5SRavi Teja                         }
581889ff694SAsmitha Karunanithi                         else if (property.first == "Type" ||
582889ff694SAsmitha Karunanithi                                  property.first == "Gateway")
583889ff694SAsmitha Karunanithi                         {
584889ff694SAsmitha Karunanithi                             // Type & Gateway is not used
585889ff694SAsmitha Karunanithi                         }
586e48c0fc5SRavi Teja                         else
587e48c0fc5SRavi Teja                         {
58862598e31SEd Tanous                             BMCWEB_LOG_ERROR(
58962598e31SEd Tanous                                 "Got extra property: {} on the {} object",
59062598e31SEd Tanous                                 property.first, objpath.first.str);
591e48c0fc5SRavi Teja                         }
592e48c0fc5SRavi Teja                     }
593e48c0fc5SRavi Teja                 }
594e48c0fc5SRavi Teja             }
595e48c0fc5SRavi Teja         }
596e48c0fc5SRavi Teja     }
597e48c0fc5SRavi Teja }
598e48c0fc5SRavi Teja 
5994a0cb85cSEd Tanous // Helper function that extracts data for single ethernet ipv4 address
60077179532SEd Tanous inline void extractIPData(const std::string& ethifaceId,
601711ac7a9SEd Tanous                           const dbus::utility::ManagedObjectType& dbusData,
60277179532SEd Tanous                           std::vector<IPv4AddressData>& ipv4Config)
6034a0cb85cSEd Tanous {
604bd79bce8SPatrick Williams     const std::string ipPathStart =
605bd79bce8SPatrick Williams         "/xyz/openbmc_project/network/" + ethifaceId;
6064a0cb85cSEd Tanous 
6074a0cb85cSEd Tanous     // Since there might be several IPv4 configurations aligned with
6084a0cb85cSEd Tanous     // single ethernet interface, loop over all of them
60981ce609eSEd Tanous     for (const auto& objpath : dbusData)
6104a0cb85cSEd Tanous     {
6114a0cb85cSEd Tanous         // Check if proper pattern for object path appears
612353163e9STony Lee         if (objpath.first.str.starts_with(ipPathStart + "/"))
6134a0cb85cSEd Tanous         {
6149eb808c1SEd Tanous             for (const auto& interface : objpath.second)
6154a0cb85cSEd Tanous             {
6164a0cb85cSEd Tanous                 if (interface.first == "xyz.openbmc_project.Network.IP")
6174a0cb85cSEd Tanous                 {
618bd79bce8SPatrick Williams                     auto type = std::ranges::find_if(
619bd79bce8SPatrick Williams                         interface.second, [](const auto& property) {
620353163e9STony Lee                             return property.first == "Type";
621353163e9STony Lee                         });
622353163e9STony Lee                     if (type == interface.second.end())
623353163e9STony Lee                     {
624353163e9STony Lee                         continue;
625353163e9STony Lee                     }
626353163e9STony Lee 
627353163e9STony Lee                     const std::string* typeStr =
628353163e9STony Lee                         std::get_if<std::string>(&type->second);
629353163e9STony Lee 
630353163e9STony Lee                     if (typeStr == nullptr ||
631353163e9STony Lee                         (*typeStr !=
632353163e9STony Lee                          "xyz.openbmc_project.Network.IP.Protocol.IPv4"))
633353163e9STony Lee                     {
634353163e9STony Lee                         continue;
635353163e9STony Lee                     }
636353163e9STony Lee 
6374a0cb85cSEd Tanous                     // Instance IPv4AddressData structure, and set as
6384a0cb85cSEd Tanous                     // appropriate
63977179532SEd Tanous                     IPv4AddressData& ipv4Address = ipv4Config.emplace_back();
6402c70f800SEd Tanous                     ipv4Address.id =
641353163e9STony Lee                         objpath.first.str.substr(ipPathStart.size());
6429eb808c1SEd Tanous                     for (const auto& property : interface.second)
6434a0cb85cSEd Tanous                     {
6444a0cb85cSEd Tanous                         if (property.first == "Address")
6454a0cb85cSEd Tanous                         {
6464a0cb85cSEd Tanous                             const std::string* address =
647abf2add6SEd Tanous                                 std::get_if<std::string>(&property.second);
6484a0cb85cSEd Tanous                             if (address != nullptr)
6494a0cb85cSEd Tanous                             {
6502c70f800SEd Tanous                                 ipv4Address.address = *address;
6514a0cb85cSEd Tanous                             }
6524a0cb85cSEd Tanous                         }
6534a0cb85cSEd Tanous                         else if (property.first == "Origin")
6544a0cb85cSEd Tanous                         {
6554a0cb85cSEd Tanous                             const std::string* origin =
656abf2add6SEd Tanous                                 std::get_if<std::string>(&property.second);
6574a0cb85cSEd Tanous                             if (origin != nullptr)
6584a0cb85cSEd Tanous                             {
6592c70f800SEd Tanous                                 ipv4Address.origin =
6604a0cb85cSEd Tanous                                     translateAddressOriginDbusToRedfish(*origin,
6614a0cb85cSEd Tanous                                                                         true);
6624a0cb85cSEd Tanous                             }
6634a0cb85cSEd Tanous                         }
6644a0cb85cSEd Tanous                         else if (property.first == "PrefixLength")
6654a0cb85cSEd Tanous                         {
6664a0cb85cSEd Tanous                             const uint8_t* mask =
667abf2add6SEd Tanous                                 std::get_if<uint8_t>(&property.second);
6684a0cb85cSEd Tanous                             if (mask != nullptr)
6694a0cb85cSEd Tanous                             {
6704a0cb85cSEd Tanous                                 // convert it to the string
6712c70f800SEd Tanous                                 ipv4Address.netmask = getNetmask(*mask);
6724a0cb85cSEd Tanous                             }
6734a0cb85cSEd Tanous                         }
674889ff694SAsmitha Karunanithi                         else if (property.first == "Type" ||
675889ff694SAsmitha Karunanithi                                  property.first == "Gateway")
676889ff694SAsmitha Karunanithi                         {
677889ff694SAsmitha Karunanithi                             // Type & Gateway is not used
678889ff694SAsmitha Karunanithi                         }
6794a0cb85cSEd Tanous                         else
6804a0cb85cSEd Tanous                         {
68162598e31SEd Tanous                             BMCWEB_LOG_ERROR(
68262598e31SEd Tanous                                 "Got extra property: {} on the {} object",
68362598e31SEd Tanous                                 property.first, objpath.first.str);
6844a0cb85cSEd Tanous                         }
6854a0cb85cSEd Tanous                     }
6864a0cb85cSEd Tanous                     // Check if given address is local, or global
6872c70f800SEd Tanous                     ipv4Address.linktype =
68811ba3979SEd Tanous                         ipv4Address.address.starts_with("169.254.")
68918659d10SJohnathan Mantey                             ? LinkType::Local
69018659d10SJohnathan Mantey                             : LinkType::Global;
6914a0cb85cSEd Tanous                 }
6924a0cb85cSEd Tanous             }
6934a0cb85cSEd Tanous         }
6944a0cb85cSEd Tanous     }
6954a0cb85cSEd Tanous }
696588c3f0dSKowalski, Kamil 
697588c3f0dSKowalski, Kamil /**
698743eb1c0SJohnathan Mantey  * @brief Modifies the default gateway assigned to the NIC
699743eb1c0SJohnathan Mantey  *
700743eb1c0SJohnathan Mantey  * @param[in] ifaceId     Id of network interface whose default gateway is to be
701743eb1c0SJohnathan Mantey  *                        changed
702743eb1c0SJohnathan Mantey  * @param[in] gateway     The new gateway value. Assigning an empty string
703743eb1c0SJohnathan Mantey  *                        causes the gateway to be deleted
704743eb1c0SJohnathan Mantey  * @param[io] asyncResp   Response object that will be returned to client
705743eb1c0SJohnathan Mantey  *
706743eb1c0SJohnathan Mantey  * @return None
707743eb1c0SJohnathan Mantey  */
708743eb1c0SJohnathan Mantey inline void updateIPv4DefaultGateway(
709743eb1c0SJohnathan Mantey     const std::string& ifaceId, const std::string& gateway,
710743eb1c0SJohnathan Mantey     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
711743eb1c0SJohnathan Mantey {
712743eb1c0SJohnathan Mantey     setDbusProperty(
713e93abac6SGinu George         asyncResp, "Gateway", "xyz.openbmc_project.Network",
714743eb1c0SJohnathan Mantey         sdbusplus::message::object_path("/xyz/openbmc_project/network") /
715743eb1c0SJohnathan Mantey             ifaceId,
716743eb1c0SJohnathan Mantey         "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway",
717e93abac6SGinu George         gateway);
718743eb1c0SJohnathan Mantey }
719743eb1c0SJohnathan Mantey 
720743eb1c0SJohnathan Mantey /**
721743eb1c0SJohnathan Mantey  * @brief Deletes given static IP address for the interface
722179db1d7SKowalski, Kamil  *
723179db1d7SKowalski, Kamil  * @param[in] ifaceId     Id of interface whose IP should be deleted
724179db1d7SKowalski, Kamil  * @param[in] ipHash      DBus Hash id of IP that should be deleted
725179db1d7SKowalski, Kamil  * @param[io] asyncResp   Response object that will be returned to client
726179db1d7SKowalski, Kamil  *
727179db1d7SKowalski, Kamil  * @return None
728179db1d7SKowalski, Kamil  */
7299c5e585cSRavi Teja inline void deleteIPAddress(const std::string& ifaceId,
7309c5e585cSRavi Teja                             const std::string& ipHash,
7318d1b46d7Szhanghch05                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
7321abe55efSEd Tanous {
73355c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
7345e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
7351abe55efSEd Tanous             if (ec)
7361abe55efSEd Tanous             {
737a08b46ccSJason M. Bills                 messages::internalError(asyncResp->res);
7381abe55efSEd Tanous             }
739179db1d7SKowalski, Kamil         },
740179db1d7SKowalski, Kamil         "xyz.openbmc_project.Network",
7419c5e585cSRavi Teja         "/xyz/openbmc_project/network/" + ifaceId + ipHash,
742179db1d7SKowalski, Kamil         "xyz.openbmc_project.Object.Delete", "Delete");
743179db1d7SKowalski, Kamil }
744179db1d7SKowalski, Kamil 
745179db1d7SKowalski, Kamil /**
74601784826SJohnathan Mantey  * @brief Creates a static IPv4 entry
747179db1d7SKowalski, Kamil  *
74801784826SJohnathan Mantey  * @param[in] ifaceId      Id of interface upon which to create the IPv4 entry
74901784826SJohnathan Mantey  * @param[in] prefixLength IPv4 prefix syntax for the subnet mask
75001784826SJohnathan Mantey  * @param[in] gateway      IPv4 address of this interfaces gateway
75101784826SJohnathan Mantey  * @param[in] address      IPv4 address to assign to this interface
752179db1d7SKowalski, Kamil  * @param[io] asyncResp    Response object that will be returned to client
753179db1d7SKowalski, Kamil  *
754179db1d7SKowalski, Kamil  * @return None
755179db1d7SKowalski, Kamil  */
756cb13a392SEd Tanous inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
757cb13a392SEd Tanous                        const std::string& gateway, const std::string& address,
7588d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
7591abe55efSEd Tanous {
760bd79bce8SPatrick Williams     auto createIpHandler =
761bd79bce8SPatrick Williams         [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
7621abe55efSEd Tanous             if (ec)
7631abe55efSEd Tanous             {
764a08b46ccSJason M. Bills                 messages::internalError(asyncResp->res);
7659010ec2eSRavi Teja                 return;
766179db1d7SKowalski, Kamil             }
7679010ec2eSRavi Teja         };
7689010ec2eSRavi Teja 
7699010ec2eSRavi Teja     crow::connections::systemBus->async_method_call(
7709010ec2eSRavi Teja         std::move(createIpHandler), "xyz.openbmc_project.Network",
771179db1d7SKowalski, Kamil         "/xyz/openbmc_project/network/" + ifaceId,
772179db1d7SKowalski, Kamil         "xyz.openbmc_project.Network.IP.Create", "IP",
77301784826SJohnathan Mantey         "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength,
774179db1d7SKowalski, Kamil         gateway);
775179db1d7SKowalski, Kamil }
776e48c0fc5SRavi Teja 
777e48c0fc5SRavi Teja /**
778743eb1c0SJohnathan Mantey  * @brief Deletes the IP entry for this interface and creates a replacement
779743eb1c0SJohnathan Mantey  * static entry
78001784826SJohnathan Mantey  *
78101784826SJohnathan Mantey  * @param[in] ifaceId        Id of interface upon which to create the IPv6 entry
78201784826SJohnathan Mantey  * @param[in] id             The unique hash entry identifying the DBus entry
783743eb1c0SJohnathan Mantey  * @param[in] prefixLength   Prefix syntax for the subnet mask
784743eb1c0SJohnathan Mantey  * @param[in] address        Address to assign to this interface
785743eb1c0SJohnathan Mantey  * @param[in] numStaticAddrs Count of IPv4 static addresses
78601784826SJohnathan Mantey  * @param[io] asyncResp      Response object that will be returned to client
78701784826SJohnathan Mantey  *
78801784826SJohnathan Mantey  * @return None
78901784826SJohnathan Mantey  */
7909c5e585cSRavi Teja 
7919c5e585cSRavi Teja inline void deleteAndCreateIPAddress(
7929c5e585cSRavi Teja     IpVersion version, const std::string& ifaceId, const std::string& id,
7938d1b46d7Szhanghch05     uint8_t prefixLength, const std::string& address,
7949c5e585cSRavi Teja     const std::string& gateway,
7958d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
79601784826SJohnathan Mantey {
79701784826SJohnathan Mantey     crow::connections::systemBus->async_method_call(
7989c5e585cSRavi Teja         [asyncResp, version, ifaceId, address, prefixLength,
7999c5e585cSRavi Teja          gateway](const boost::system::error_code& ec) {
80001784826SJohnathan Mantey             if (ec)
80101784826SJohnathan Mantey             {
80201784826SJohnathan Mantey                 messages::internalError(asyncResp->res);
80301784826SJohnathan Mantey             }
8049c5e585cSRavi Teja             std::string protocol = "xyz.openbmc_project.Network.IP.Protocol.";
8059c5e585cSRavi Teja             protocol += version == IpVersion::IpV4 ? "IPv4" : "IPv6";
80601784826SJohnathan Mantey             crow::connections::systemBus->async_method_call(
8075e7e2dc5SEd Tanous                 [asyncResp](const boost::system::error_code& ec2) {
80823a21a1cSEd Tanous                     if (ec2)
80901784826SJohnathan Mantey                     {
81001784826SJohnathan Mantey                         messages::internalError(asyncResp->res);
81101784826SJohnathan Mantey                     }
81201784826SJohnathan Mantey                 },
81301784826SJohnathan Mantey                 "xyz.openbmc_project.Network",
81401784826SJohnathan Mantey                 "/xyz/openbmc_project/network/" + ifaceId,
815bd79bce8SPatrick Williams                 "xyz.openbmc_project.Network.IP.Create", "IP", protocol,
816bd79bce8SPatrick Williams                 address, prefixLength, gateway);
81701784826SJohnathan Mantey         },
81801784826SJohnathan Mantey         "xyz.openbmc_project.Network",
8199c5e585cSRavi Teja         "/xyz/openbmc_project/network/" + ifaceId + id,
82001784826SJohnathan Mantey         "xyz.openbmc_project.Object.Delete", "Delete");
82101784826SJohnathan Mantey }
82201784826SJohnathan Mantey 
823ce73d5c8SSunitha Harish inline bool extractIPv6DefaultGatewayData(
824ce73d5c8SSunitha Harish     const std::string& ethifaceId,
825ce73d5c8SSunitha Harish     const dbus::utility::ManagedObjectType& dbusData,
826ce73d5c8SSunitha Harish     std::vector<StaticGatewayData>& staticGatewayConfig)
827ce73d5c8SSunitha Harish {
828ce73d5c8SSunitha Harish     std::string staticGatewayPathStart("/xyz/openbmc_project/network/");
829ce73d5c8SSunitha Harish     staticGatewayPathStart += ethifaceId;
830ce73d5c8SSunitha Harish 
831ce73d5c8SSunitha Harish     for (const auto& objpath : dbusData)
832ce73d5c8SSunitha Harish     {
833ce73d5c8SSunitha Harish         if (!std::string_view(objpath.first.str)
834ce73d5c8SSunitha Harish                  .starts_with(staticGatewayPathStart))
835ce73d5c8SSunitha Harish         {
836ce73d5c8SSunitha Harish             continue;
837ce73d5c8SSunitha Harish         }
838ce73d5c8SSunitha Harish         for (const auto& interface : objpath.second)
839ce73d5c8SSunitha Harish         {
840ce73d5c8SSunitha Harish             if (interface.first != "xyz.openbmc_project.Network.StaticGateway")
841ce73d5c8SSunitha Harish             {
842ce73d5c8SSunitha Harish                 continue;
843ce73d5c8SSunitha Harish             }
844ce73d5c8SSunitha Harish             StaticGatewayData& staticGateway =
845ce73d5c8SSunitha Harish                 staticGatewayConfig.emplace_back();
846ce73d5c8SSunitha Harish             staticGateway.id = objpath.first.filename();
847ce73d5c8SSunitha Harish 
848ce73d5c8SSunitha Harish             bool success = sdbusplus::unpackPropertiesNoThrow(
849ce73d5c8SSunitha Harish                 redfish::dbus_utils::UnpackErrorPrinter(), interface.second,
850ab0d4390SRavi Teja                 "Gateway", staticGateway.gateway, "ProtocolType",
851ce73d5c8SSunitha Harish                 staticGateway.protocol);
852ce73d5c8SSunitha Harish             if (!success)
853ce73d5c8SSunitha Harish             {
854ce73d5c8SSunitha Harish                 return false;
855ce73d5c8SSunitha Harish             }
856ce73d5c8SSunitha Harish         }
857ce73d5c8SSunitha Harish     }
858ce73d5c8SSunitha Harish     return true;
859ce73d5c8SSunitha Harish }
860ce73d5c8SSunitha Harish 
86101784826SJohnathan Mantey /**
862e48c0fc5SRavi Teja  * @brief Creates IPv6 with given data
863e48c0fc5SRavi Teja  *
864e48c0fc5SRavi Teja  * @param[in] ifaceId      Id of interface whose IP should be added
865e48c0fc5SRavi Teja  * @param[in] prefixLength Prefix length that needs to be added
866e48c0fc5SRavi Teja  * @param[in] address      IP address that needs to be added
867e48c0fc5SRavi Teja  * @param[io] asyncResp    Response object that will be returned to client
868e48c0fc5SRavi Teja  *
869e48c0fc5SRavi Teja  * @return None
870e48c0fc5SRavi Teja  */
87101784826SJohnathan Mantey inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength,
87201784826SJohnathan Mantey                        const std::string& address,
8738d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
874e48c0fc5SRavi Teja {
875ce73d5c8SSunitha Harish     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
876ce73d5c8SSunitha Harish     path /= ifaceId;
877ce73d5c8SSunitha Harish 
878bd79bce8SPatrick Williams     auto createIpHandler =
879bd79bce8SPatrick Williams         [asyncResp, address](const boost::system::error_code& ec) {
880e48c0fc5SRavi Teja             if (ec)
881e48c0fc5SRavi Teja             {
882fc23ef8aSNitin Kumar Kotania                 if (ec == boost::system::errc::io_error)
883fc23ef8aSNitin Kumar Kotania                 {
884fc23ef8aSNitin Kumar Kotania                     messages::propertyValueFormatError(asyncResp->res, address,
885fc23ef8aSNitin Kumar Kotania                                                        "Address");
886fc23ef8aSNitin Kumar Kotania                 }
887fc23ef8aSNitin Kumar Kotania                 else
888fc23ef8aSNitin Kumar Kotania                 {
889e48c0fc5SRavi Teja                     messages::internalError(asyncResp->res);
890e48c0fc5SRavi Teja                 }
891fc23ef8aSNitin Kumar Kotania             }
892e48c0fc5SRavi Teja         };
893ce73d5c8SSunitha Harish     // Passing null for gateway, as per redfish spec IPv6StaticAddresses
894ce73d5c8SSunitha Harish     // object does not have associated gateway property
895e48c0fc5SRavi Teja     crow::connections::systemBus->async_method_call(
896ce73d5c8SSunitha Harish         std::move(createIpHandler), "xyz.openbmc_project.Network", path,
897e48c0fc5SRavi Teja         "xyz.openbmc_project.Network.IP.Create", "IP",
898e48c0fc5SRavi Teja         "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength,
899e48c0fc5SRavi Teja         "");
900e48c0fc5SRavi Teja }
901e48c0fc5SRavi Teja 
902179db1d7SKowalski, Kamil /**
903ce73d5c8SSunitha Harish  * @brief Deletes given IPv6 Static Gateway
904ce73d5c8SSunitha Harish  *
905ce73d5c8SSunitha Harish  * @param[in] ifaceId     Id of interface whose IP should be deleted
906ce73d5c8SSunitha Harish  * @param[in] ipHash      DBus Hash id of IP that should be deleted
907ce73d5c8SSunitha Harish  * @param[io] asyncResp   Response object that will be returned to client
908ce73d5c8SSunitha Harish  *
909ce73d5c8SSunitha Harish  * @return None
910ce73d5c8SSunitha Harish  */
911ce73d5c8SSunitha Harish inline void
912739b27b2SRavi Teja     deleteIPv6Gateway(std::string_view ifaceId, std::string_view gatewayId,
913ce73d5c8SSunitha Harish                       const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
914ce73d5c8SSunitha Harish {
915ce73d5c8SSunitha Harish     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
916739b27b2SRavi Teja     path /= ifaceId;
917ce73d5c8SSunitha Harish     path /= gatewayId;
918ce73d5c8SSunitha Harish     crow::connections::systemBus->async_method_call(
919ce73d5c8SSunitha Harish         [asyncResp](const boost::system::error_code& ec) {
920ce73d5c8SSunitha Harish             if (ec)
921ce73d5c8SSunitha Harish             {
922ce73d5c8SSunitha Harish                 messages::internalError(asyncResp->res);
923ce73d5c8SSunitha Harish             }
924ce73d5c8SSunitha Harish         },
925ce73d5c8SSunitha Harish         "xyz.openbmc_project.Network", path,
926ce73d5c8SSunitha Harish         "xyz.openbmc_project.Object.Delete", "Delete");
927ce73d5c8SSunitha Harish }
928ce73d5c8SSunitha Harish 
929ce73d5c8SSunitha Harish /**
930ce73d5c8SSunitha Harish  * @brief Creates IPv6 static default gateway with given data
931ce73d5c8SSunitha Harish  *
932ce73d5c8SSunitha Harish  * @param[in] ifaceId      Id of interface whose IP should be added
933ce73d5c8SSunitha Harish  * @param[in] gateway      Gateway address that needs to be added
934ce73d5c8SSunitha Harish  * @param[io] asyncResp    Response object that will be returned to client
935ce73d5c8SSunitha Harish  *
936ce73d5c8SSunitha Harish  * @return None
937ce73d5c8SSunitha Harish  */
938ce73d5c8SSunitha Harish inline void createIPv6DefaultGateway(
939ab0d4390SRavi Teja     std::string_view ifaceId, std::string_view gateway,
940ce73d5c8SSunitha Harish     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
941ce73d5c8SSunitha Harish {
942ce73d5c8SSunitha Harish     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
943ce73d5c8SSunitha Harish     path /= ifaceId;
944ce73d5c8SSunitha Harish     auto createIpHandler = [asyncResp](const boost::system::error_code& ec) {
945ce73d5c8SSunitha Harish         if (ec)
946ce73d5c8SSunitha Harish         {
947ce73d5c8SSunitha Harish             messages::internalError(asyncResp->res);
948ce73d5c8SSunitha Harish         }
949ce73d5c8SSunitha Harish     };
950ce73d5c8SSunitha Harish     crow::connections::systemBus->async_method_call(
951ce73d5c8SSunitha Harish         std::move(createIpHandler), "xyz.openbmc_project.Network", path,
952ce73d5c8SSunitha Harish         "xyz.openbmc_project.Network.StaticGateway.Create", "StaticGateway",
953ab0d4390SRavi Teja         gateway, "xyz.openbmc_project.Network.IP.Protocol.IPv6");
954ce73d5c8SSunitha Harish }
955ce73d5c8SSunitha Harish 
956ce73d5c8SSunitha Harish /**
957ce73d5c8SSunitha Harish  * @brief Deletes the IPv6 default gateway entry for this interface and
958ce73d5c8SSunitha Harish  * creates a replacement IPv6 default gateway entry
959ce73d5c8SSunitha Harish  *
960ce73d5c8SSunitha Harish  * @param[in] ifaceId      Id of interface upon which to create the IPv6
961ce73d5c8SSunitha Harish  * entry
962ce73d5c8SSunitha Harish  * @param[in] gateway      IPv6 gateway to assign to this interface
963ce73d5c8SSunitha Harish  * @param[io] asyncResp    Response object that will be returned to client
964ce73d5c8SSunitha Harish  *
965ce73d5c8SSunitha Harish  * @return None
966ce73d5c8SSunitha Harish  */
967ce73d5c8SSunitha Harish inline void deleteAndCreateIPv6DefaultGateway(
968ce73d5c8SSunitha Harish     std::string_view ifaceId, std::string_view gatewayId,
969ab0d4390SRavi Teja     std::string_view gateway,
970ce73d5c8SSunitha Harish     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
971ce73d5c8SSunitha Harish {
972ce73d5c8SSunitha Harish     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
973739b27b2SRavi Teja     path /= ifaceId;
974ce73d5c8SSunitha Harish     path /= gatewayId;
975ce73d5c8SSunitha Harish     crow::connections::systemBus->async_method_call(
976ab0d4390SRavi Teja         [asyncResp, ifaceId, gateway](const boost::system::error_code& ec) {
977ce73d5c8SSunitha Harish             if (ec)
978ce73d5c8SSunitha Harish             {
979ce73d5c8SSunitha Harish                 messages::internalError(asyncResp->res);
980ce73d5c8SSunitha Harish                 return;
981ce73d5c8SSunitha Harish             }
982ab0d4390SRavi Teja             createIPv6DefaultGateway(ifaceId, gateway, asyncResp);
983ce73d5c8SSunitha Harish         },
984ce73d5c8SSunitha Harish         "xyz.openbmc_project.Network", path,
985ce73d5c8SSunitha Harish         "xyz.openbmc_project.Object.Delete", "Delete");
986ce73d5c8SSunitha Harish }
987ce73d5c8SSunitha Harish 
988ce73d5c8SSunitha Harish /**
989ce73d5c8SSunitha Harish  * @brief Sets IPv6 default gateway with given data
990ce73d5c8SSunitha Harish  *
991ce73d5c8SSunitha Harish  * @param[in] ifaceId      Id of interface whose gateway should be added
992ce73d5c8SSunitha Harish  * @param[in] input        Contains address that needs to be added
993ce73d5c8SSunitha Harish  * @param[in] staticGatewayData  Current static gateways in the system
994ce73d5c8SSunitha Harish  * @param[io] asyncResp    Response object that will be returned to client
995ce73d5c8SSunitha Harish  *
996ce73d5c8SSunitha Harish  * @return None
997ce73d5c8SSunitha Harish  */
998ce73d5c8SSunitha Harish 
999ce73d5c8SSunitha Harish inline void handleIPv6DefaultGateway(
10003dfed536SEd Tanous     const std::string& ifaceId,
10013dfed536SEd Tanous     std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
1002ce73d5c8SSunitha Harish     const std::vector<StaticGatewayData>& staticGatewayData,
1003ce73d5c8SSunitha Harish     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1004ce73d5c8SSunitha Harish {
1005ce73d5c8SSunitha Harish     size_t entryIdx = 1;
1006ce73d5c8SSunitha Harish     std::vector<StaticGatewayData>::const_iterator staticGatewayEntry =
1007ce73d5c8SSunitha Harish         staticGatewayData.begin();
1008ce73d5c8SSunitha Harish 
10093dfed536SEd Tanous     for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
10103dfed536SEd Tanous          input)
1011ce73d5c8SSunitha Harish     {
1012ce73d5c8SSunitha Harish         // find the next gateway entry
1013ce73d5c8SSunitha Harish         while (staticGatewayEntry != staticGatewayData.end())
1014ce73d5c8SSunitha Harish         {
1015ce73d5c8SSunitha Harish             if (staticGatewayEntry->protocol ==
1016ce73d5c8SSunitha Harish                 "xyz.openbmc_project.Network.IP.Protocol.IPv6")
1017ce73d5c8SSunitha Harish             {
1018ce73d5c8SSunitha Harish                 break;
1019ce73d5c8SSunitha Harish             }
1020ce73d5c8SSunitha Harish             staticGatewayEntry++;
1021ce73d5c8SSunitha Harish         }
1022bd79bce8SPatrick Williams         std::string pathString =
1023bd79bce8SPatrick Williams             "IPv6StaticDefaultGateways/" + std::to_string(entryIdx);
10243dfed536SEd Tanous         nlohmann::json::object_t* obj =
10253dfed536SEd Tanous             std::get_if<nlohmann::json::object_t>(&thisJson);
10263dfed536SEd Tanous         if (obj == nullptr)
1027ce73d5c8SSunitha Harish         {
1028ce73d5c8SSunitha Harish             if (staticGatewayEntry == staticGatewayData.end())
1029ce73d5c8SSunitha Harish             {
1030ce73d5c8SSunitha Harish                 messages::resourceCannotBeDeleted(asyncResp->res);
1031ce73d5c8SSunitha Harish                 return;
1032ce73d5c8SSunitha Harish             }
1033739b27b2SRavi Teja             deleteIPv6Gateway(ifaceId, staticGatewayEntry->id, asyncResp);
1034ce73d5c8SSunitha Harish             return;
1035ce73d5c8SSunitha Harish         }
10363dfed536SEd Tanous         if (obj->empty())
1037ce73d5c8SSunitha Harish         {
1038ce73d5c8SSunitha Harish             // Do nothing, but make sure the entry exists.
1039ce73d5c8SSunitha Harish             if (staticGatewayEntry == staticGatewayData.end())
1040ce73d5c8SSunitha Harish             {
10413dfed536SEd Tanous                 messages::propertyValueFormatError(asyncResp->res, *obj,
1042ce73d5c8SSunitha Harish                                                    pathString);
1043ce73d5c8SSunitha Harish                 return;
1044ce73d5c8SSunitha Harish             }
1045ce73d5c8SSunitha Harish         }
1046ce73d5c8SSunitha Harish         std::optional<std::string> address;
1047ce73d5c8SSunitha Harish 
1048ab0d4390SRavi Teja         if (!json_util::readJsonObject(*obj, asyncResp->res, "Address",
1049ab0d4390SRavi Teja                                        address))
1050ce73d5c8SSunitha Harish         {
1051ce73d5c8SSunitha Harish             return;
1052ce73d5c8SSunitha Harish         }
1053ce73d5c8SSunitha Harish         const std::string* addr = nullptr;
1054ce73d5c8SSunitha Harish         if (address)
1055ce73d5c8SSunitha Harish         {
1056ce73d5c8SSunitha Harish             addr = &(*address);
1057ce73d5c8SSunitha Harish         }
1058ce73d5c8SSunitha Harish         else if (staticGatewayEntry != staticGatewayData.end())
1059ce73d5c8SSunitha Harish         {
1060ce73d5c8SSunitha Harish             addr = &(staticGatewayEntry->gateway);
1061ce73d5c8SSunitha Harish         }
1062ce73d5c8SSunitha Harish         else
1063ce73d5c8SSunitha Harish         {
1064ce73d5c8SSunitha Harish             messages::propertyMissing(asyncResp->res, pathString + "/Address");
1065ce73d5c8SSunitha Harish             return;
1066ce73d5c8SSunitha Harish         }
1067ce73d5c8SSunitha Harish         if (staticGatewayEntry != staticGatewayData.end())
1068ce73d5c8SSunitha Harish         {
1069ce73d5c8SSunitha Harish             deleteAndCreateIPv6DefaultGateway(ifaceId, staticGatewayEntry->id,
1070ab0d4390SRavi Teja                                               *addr, asyncResp);
1071ce73d5c8SSunitha Harish             staticGatewayEntry++;
1072ce73d5c8SSunitha Harish         }
1073ce73d5c8SSunitha Harish         else
1074ce73d5c8SSunitha Harish         {
1075ab0d4390SRavi Teja             createIPv6DefaultGateway(ifaceId, *addr, asyncResp);
1076ce73d5c8SSunitha Harish         }
1077ce73d5c8SSunitha Harish         entryIdx++;
1078ce73d5c8SSunitha Harish     }
1079ce73d5c8SSunitha Harish }
1080ce73d5c8SSunitha Harish 
1081ce73d5c8SSunitha Harish /**
1082179db1d7SKowalski, Kamil  * Function that retrieves all properties for given Ethernet Interface
1083179db1d7SKowalski, Kamil  * Object
1084179db1d7SKowalski, Kamil  * from EntityManager Network Manager
10854a0cb85cSEd Tanous  * @param ethiface_id a eth interface id to query on DBus
1086179db1d7SKowalski, Kamil  * @param callback a function that shall be called to convert Dbus output
1087179db1d7SKowalski, Kamil  * into JSON
1088179db1d7SKowalski, Kamil  */
1089179db1d7SKowalski, Kamil template <typename CallbackFunc>
109081ce609eSEd Tanous void getEthernetIfaceData(const std::string& ethifaceId,
10911abe55efSEd Tanous                           CallbackFunc&& callback)
10921abe55efSEd Tanous {
1093f5892d0dSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1094f5892d0dSGeorge Liu     dbus::utility::getManagedObjects(
1095f5892d0dSGeorge Liu         "xyz.openbmc_project.Network", path,
1096f94c4ecfSEd Tanous         [ethifaceId{std::string{ethifaceId}},
10978cb2c024SEd Tanous          callback = std::forward<CallbackFunc>(callback)](
10988b24275dSEd Tanous             const boost::system::error_code& ec,
10993dfed536SEd Tanous             const dbus::utility::ManagedObjectType& resp) mutable {
110055c7b7a2SEd Tanous             EthernetInterfaceData ethData{};
110177179532SEd Tanous             std::vector<IPv4AddressData> ipv4Data;
110277179532SEd Tanous             std::vector<IPv6AddressData> ipv6Data;
1103ce73d5c8SSunitha Harish             std::vector<StaticGatewayData> ipv6GatewayData;
1104179db1d7SKowalski, Kamil 
11058b24275dSEd Tanous             if (ec)
11061abe55efSEd Tanous             {
1107ce73d5c8SSunitha Harish                 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1108179db1d7SKowalski, Kamil                 return;
1109179db1d7SKowalski, Kamil             }
1110179db1d7SKowalski, Kamil 
1111bd79bce8SPatrick Williams             bool found =
1112bd79bce8SPatrick Williams                 extractEthernetInterfaceData(ethifaceId, resp, ethData);
11134c9afe43SEd Tanous             if (!found)
11144c9afe43SEd Tanous             {
1115ce73d5c8SSunitha Harish                 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
11164c9afe43SEd Tanous                 return;
11174c9afe43SEd Tanous             }
11184c9afe43SEd Tanous 
11192c70f800SEd Tanous             extractIPData(ethifaceId, resp, ipv4Data);
1120179db1d7SKowalski, Kamil             // Fix global GW
11211abe55efSEd Tanous             for (IPv4AddressData& ipv4 : ipv4Data)
11221abe55efSEd Tanous             {
1123c619141bSRavi Teja                 if (((ipv4.linktype == LinkType::Global) &&
1124c619141bSRavi Teja                      (ipv4.gateway == "0.0.0.0")) ||
11259010ec2eSRavi Teja                     (ipv4.origin == "DHCP") || (ipv4.origin == "Static"))
11261abe55efSEd Tanous                 {
112782695a5bSJiaqing Zhao                     ipv4.gateway = ethData.defaultGateway;
1128179db1d7SKowalski, Kamil                 }
1129179db1d7SKowalski, Kamil             }
1130179db1d7SKowalski, Kamil 
11312c70f800SEd Tanous             extractIPV6Data(ethifaceId, resp, ipv6Data);
1132bd79bce8SPatrick Williams             if (!extractIPv6DefaultGatewayData(ethifaceId, resp,
1133bd79bce8SPatrick Williams                                                ipv6GatewayData))
1134ce73d5c8SSunitha Harish             {
1135ce73d5c8SSunitha Harish                 callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1136ce73d5c8SSunitha Harish             }
11374e0453b1SGunnar Mills             // Finally make a callback with useful data
1138ce73d5c8SSunitha Harish             callback(true, ethData, ipv4Data, ipv6Data, ipv6GatewayData);
1139f5892d0dSGeorge Liu         });
1140271584abSEd Tanous }
1141179db1d7SKowalski, Kamil 
1142179db1d7SKowalski, Kamil /**
11439391bb9cSRapkiewicz, Pawel  * Function that retrieves all Ethernet Interfaces available through Network
11449391bb9cSRapkiewicz, Pawel  * Manager
11451abe55efSEd Tanous  * @param callback a function that shall be called to convert Dbus output
11461abe55efSEd Tanous  * into JSON.
11479391bb9cSRapkiewicz, Pawel  */
11489391bb9cSRapkiewicz, Pawel template <typename CallbackFunc>
11491abe55efSEd Tanous void getEthernetIfaceList(CallbackFunc&& callback)
11501abe55efSEd Tanous {
1151f5892d0dSGeorge Liu     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1152f5892d0dSGeorge Liu     dbus::utility::getManagedObjects(
1153f5892d0dSGeorge Liu         "xyz.openbmc_project.Network", path,
11548cb2c024SEd Tanous         [callback = std::forward<CallbackFunc>(callback)](
11558b24275dSEd Tanous             const boost::system::error_code& ec,
1156f5892d0dSGeorge Liu             const dbus::utility::ManagedObjectType& resp) {
11571abe55efSEd Tanous             // Callback requires vector<string> to retrieve all available
11581abe55efSEd Tanous             // ethernet interfaces
115977179532SEd Tanous             std::vector<std::string> ifaceList;
11602c70f800SEd Tanous             ifaceList.reserve(resp.size());
11618b24275dSEd Tanous             if (ec)
11621abe55efSEd Tanous             {
11632c70f800SEd Tanous                 callback(false, ifaceList);
11649391bb9cSRapkiewicz, Pawel                 return;
11659391bb9cSRapkiewicz, Pawel             }
11669391bb9cSRapkiewicz, Pawel 
11679391bb9cSRapkiewicz, Pawel             // Iterate over all retrieved ObjectPaths.
11684a0cb85cSEd Tanous             for (const auto& objpath : resp)
11691abe55efSEd Tanous             {
11709391bb9cSRapkiewicz, Pawel                 // And all interfaces available for certain ObjectPath.
11714a0cb85cSEd Tanous                 for (const auto& interface : objpath.second)
11721abe55efSEd Tanous                 {
11731abe55efSEd Tanous                     // If interface is
11744a0cb85cSEd Tanous                     // xyz.openbmc_project.Network.EthernetInterface, this is
11754a0cb85cSEd Tanous                     // what we're looking for.
11769391bb9cSRapkiewicz, Pawel                     if (interface.first ==
11771abe55efSEd Tanous                         "xyz.openbmc_project.Network.EthernetInterface")
11781abe55efSEd Tanous                     {
11792dfd18efSEd Tanous                         std::string ifaceId = objpath.first.filename();
11802dfd18efSEd Tanous                         if (ifaceId.empty())
11811abe55efSEd Tanous                         {
11822dfd18efSEd Tanous                             continue;
11839391bb9cSRapkiewicz, Pawel                         }
11842dfd18efSEd Tanous                         // and put it into output vector.
118577179532SEd Tanous                         ifaceList.emplace_back(ifaceId);
11869391bb9cSRapkiewicz, Pawel                     }
11879391bb9cSRapkiewicz, Pawel                 }
11889391bb9cSRapkiewicz, Pawel             }
11892c5875a2SEd Tanous 
11903544d2a7SEd Tanous             std::ranges::sort(ifaceList, AlphanumLess<std::string>());
11912c5875a2SEd Tanous 
1192a434f2bdSEd Tanous             // Finally make a callback with useful data
11932c70f800SEd Tanous             callback(true, ifaceList);
1194f5892d0dSGeorge Liu         });
1195271584abSEd Tanous }
11969391bb9cSRapkiewicz, Pawel 
11974f48d5f6SEd Tanous inline void
11984f48d5f6SEd Tanous     handleHostnamePatch(const std::string& hostname,
11998d1b46d7Szhanghch05                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
12001abe55efSEd Tanous {
1201ab6554f1SJoshi-Mansi     // SHOULD handle host names of up to 255 characters(RFC 1123)
1202ab6554f1SJoshi-Mansi     if (hostname.length() > 255)
1203ab6554f1SJoshi-Mansi     {
1204ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, hostname,
1205ab6554f1SJoshi-Mansi                                            "HostName");
1206ab6554f1SJoshi-Mansi         return;
1207ab6554f1SJoshi-Mansi     }
1208d02aad39SEd Tanous     setDbusProperty(
1209e93abac6SGinu George         asyncResp, "HostName", "xyz.openbmc_project.Network",
1210d02aad39SEd Tanous         sdbusplus::message::object_path("/xyz/openbmc_project/network/config"),
1211d02aad39SEd Tanous         "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
1212e93abac6SGinu George         hostname);
1213588c3f0dSKowalski, Kamil }
1214588c3f0dSKowalski, Kamil 
12154f48d5f6SEd Tanous inline void
121635fb5311STejas Patil     handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize,
121735fb5311STejas Patil                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
121835fb5311STejas Patil {
1219d02aad39SEd Tanous     sdbusplus::message::object_path objPath("/xyz/openbmc_project/network");
1220d02aad39SEd Tanous     objPath /= ifaceId;
1221e93abac6SGinu George     setDbusProperty(asyncResp, "MTUSize", "xyz.openbmc_project.Network",
1222e93abac6SGinu George                     objPath, "xyz.openbmc_project.Network.EthernetInterface",
1223e93abac6SGinu George                     "MTU", mtuSize);
122435fb5311STejas Patil }
122535fb5311STejas Patil 
1226bd79bce8SPatrick Williams inline void handleDomainnamePatch(
1227bd79bce8SPatrick Williams     const std::string& ifaceId, const std::string& domainname,
12288d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1229ab6554f1SJoshi-Mansi {
1230ab6554f1SJoshi-Mansi     std::vector<std::string> vectorDomainname = {domainname};
1231d02aad39SEd Tanous     setDbusProperty(
1232e93abac6SGinu George         asyncResp, "FQDN", "xyz.openbmc_project.Network",
1233d02aad39SEd Tanous         sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1234d02aad39SEd Tanous             ifaceId,
1235e93abac6SGinu George         "xyz.openbmc_project.Network.EthernetInterface", "DomainName",
1236d02aad39SEd Tanous         vectorDomainname);
1237ab6554f1SJoshi-Mansi }
1238ab6554f1SJoshi-Mansi 
12394f48d5f6SEd Tanous inline bool isHostnameValid(const std::string& hostname)
1240bf648f77SEd Tanous {
1241bf648f77SEd Tanous     // A valid host name can never have the dotted-decimal form (RFC 1123)
12423544d2a7SEd Tanous     if (std::ranges::all_of(hostname, ::isdigit))
1243bf648f77SEd Tanous     {
1244bf648f77SEd Tanous         return false;
1245bf648f77SEd Tanous     }
1246bf648f77SEd Tanous     // Each label(hostname/subdomains) within a valid FQDN
1247bf648f77SEd Tanous     // MUST handle host names of up to 63 characters (RFC 1123)
1248bf648f77SEd Tanous     // labels cannot start or end with hyphens (RFC 952)
1249bf648f77SEd Tanous     // labels can start with numbers (RFC 1123)
12504b242749SEd Tanous     const static std::regex pattern(
1251bf648f77SEd Tanous         "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$");
1252bf648f77SEd Tanous 
1253bf648f77SEd Tanous     return std::regex_match(hostname, pattern);
1254bf648f77SEd Tanous }
1255bf648f77SEd Tanous 
12564f48d5f6SEd Tanous inline bool isDomainnameValid(const std::string& domainname)
1257bf648f77SEd Tanous {
1258bf648f77SEd Tanous     // Can have multiple subdomains
1259bf648f77SEd Tanous     // Top Level Domain's min length is 2 character
12604b242749SEd Tanous     const static std::regex pattern(
12610fda0f12SGeorge Liu         "^([A-Za-z0-9][a-zA-Z0-9\\-]{1,61}|[a-zA-Z0-9]{1,30}\\.)*[a-zA-Z]{2,}$");
1262bf648f77SEd Tanous 
1263bf648f77SEd Tanous     return std::regex_match(domainname, pattern);
1264bf648f77SEd Tanous }
1265bf648f77SEd Tanous 
12664f48d5f6SEd Tanous inline void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn,
12678d1b46d7Szhanghch05                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1268ab6554f1SJoshi-Mansi {
1269ab6554f1SJoshi-Mansi     // Total length of FQDN must not exceed 255 characters(RFC 1035)
1270ab6554f1SJoshi-Mansi     if (fqdn.length() > 255)
1271ab6554f1SJoshi-Mansi     {
1272ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1273ab6554f1SJoshi-Mansi         return;
1274ab6554f1SJoshi-Mansi     }
1275ab6554f1SJoshi-Mansi 
1276ab6554f1SJoshi-Mansi     size_t pos = fqdn.find('.');
1277ab6554f1SJoshi-Mansi     if (pos == std::string::npos)
1278ab6554f1SJoshi-Mansi     {
1279ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1280ab6554f1SJoshi-Mansi         return;
1281ab6554f1SJoshi-Mansi     }
1282ab6554f1SJoshi-Mansi 
1283ab6554f1SJoshi-Mansi     std::string hostname;
1284ab6554f1SJoshi-Mansi     std::string domainname;
1285ab6554f1SJoshi-Mansi     domainname = (fqdn).substr(pos + 1);
1286ab6554f1SJoshi-Mansi     hostname = (fqdn).substr(0, pos);
1287ab6554f1SJoshi-Mansi 
1288ab6554f1SJoshi-Mansi     if (!isHostnameValid(hostname) || !isDomainnameValid(domainname))
1289ab6554f1SJoshi-Mansi     {
1290ab6554f1SJoshi-Mansi         messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1291ab6554f1SJoshi-Mansi         return;
1292ab6554f1SJoshi-Mansi     }
1293ab6554f1SJoshi-Mansi 
1294ab6554f1SJoshi-Mansi     handleHostnamePatch(hostname, asyncResp);
1295ab6554f1SJoshi-Mansi     handleDomainnamePatch(ifaceId, domainname, asyncResp);
1296ab6554f1SJoshi-Mansi }
1297ab6554f1SJoshi-Mansi 
1298bd79bce8SPatrick Williams inline void handleMACAddressPatch(
1299bd79bce8SPatrick Williams     const std::string& ifaceId, const std::string& macAddress,
13008d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1301d577665bSRatan Gupta {
1302d02aad39SEd Tanous     setDbusProperty(
1303e93abac6SGinu George         asyncResp, "MACAddress", "xyz.openbmc_project.Network",
1304d02aad39SEd Tanous         sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1305d02aad39SEd Tanous             ifaceId,
1306e93abac6SGinu George         "xyz.openbmc_project.Network.MACAddress", "MACAddress", macAddress);
1307d577665bSRatan Gupta }
1308286b9118SJohnathan Mantey 
13094f48d5f6SEd Tanous inline void setDHCPEnabled(const std::string& ifaceId,
13104f48d5f6SEd Tanous                            const std::string& propertyName, const bool v4Value,
13114f48d5f6SEd Tanous                            const bool v6Value,
13128d1b46d7Szhanghch05                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1313da131a9aSJennifer Lee {
13142c70f800SEd Tanous     const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
1315d02aad39SEd Tanous     setDbusProperty(
1316e93abac6SGinu George         asyncResp, "DHCPv4", "xyz.openbmc_project.Network",
1317d02aad39SEd Tanous         sdbusplus::message::object_path("/xyz/openbmc_project/network") /
1318d02aad39SEd Tanous             ifaceId,
1319e93abac6SGinu George         "xyz.openbmc_project.Network.EthernetInterface", propertyName, dhcp);
1320eeedda23SJohnathan Mantey }
1321eeedda23SJohnathan Mantey 
1322e4588158SJishnu CM enum class NetworkType
1323e4588158SJishnu CM {
1324e4588158SJishnu CM     dhcp4,
1325e4588158SJishnu CM     dhcp6
1326e4588158SJishnu CM };
1327e4588158SJishnu CM 
1328e4588158SJishnu CM inline void setDHCPConfig(const std::string& propertyName, const bool& value,
1329e4588158SJishnu CM                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1330e4588158SJishnu CM                           const std::string& ethifaceId, NetworkType type)
1331da131a9aSJennifer Lee {
133262598e31SEd Tanous     BMCWEB_LOG_DEBUG("{} = {}", propertyName, value);
13331847f2a0SAsmitha Karunanithi     std::string redfishPropertyName;
1334e4588158SJishnu CM     sdbusplus::message::object_path path("/xyz/openbmc_project/network/");
1335e4588158SJishnu CM     path /= ethifaceId;
1336e4588158SJishnu CM 
1337e4588158SJishnu CM     if (type == NetworkType::dhcp4)
1338e4588158SJishnu CM     {
1339e4588158SJishnu CM         path /= "dhcp4";
13401847f2a0SAsmitha Karunanithi         redfishPropertyName = "DHCPv4";
1341e4588158SJishnu CM     }
1342e4588158SJishnu CM     else
1343e4588158SJishnu CM     {
1344e4588158SJishnu CM         path /= "dhcp6";
13451847f2a0SAsmitha Karunanithi         redfishPropertyName = "DHCPv6";
1346e4588158SJishnu CM     }
1347e4588158SJishnu CM 
1348e93abac6SGinu George     setDbusProperty(
1349e93abac6SGinu George         asyncResp, redfishPropertyName, "xyz.openbmc_project.Network", path,
1350e93abac6SGinu George         "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, value);
1351da131a9aSJennifer Lee }
1352d577665bSRatan Gupta 
1353b10d8db0SRavi Teja inline void handleSLAACAutoConfigPatch(
1354b10d8db0SRavi Teja     const std::string& ifaceId, bool ipv6AutoConfigEnabled,
1355b10d8db0SRavi Teja     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1356b10d8db0SRavi Teja {
1357b10d8db0SRavi Teja     sdbusplus::message::object_path path("/xyz/openbmc_project/network");
1358b10d8db0SRavi Teja     path /= ifaceId;
1359e93abac6SGinu George     setDbusProperty(asyncResp,
13601847f2a0SAsmitha Karunanithi                     "StatelessAddressAutoConfig/IPv6AutoConfigEnabled",
1361e93abac6SGinu George                     "xyz.openbmc_project.Network", path,
1362e93abac6SGinu George                     "xyz.openbmc_project.Network.EthernetInterface",
1363e93abac6SGinu George                     "IPv6AcceptRA", ipv6AutoConfigEnabled);
1364b10d8db0SRavi Teja }
1365b10d8db0SRavi Teja 
1366bd79bce8SPatrick Williams inline void handleDHCPPatch(
1367bd79bce8SPatrick Williams     const std::string& ifaceId, const EthernetInterfaceData& ethData,
1368bd79bce8SPatrick Williams     const DHCPParameters& v4dhcpParms, const DHCPParameters& v6dhcpParms,
13698d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1370da131a9aSJennifer Lee {
137182695a5bSJiaqing Zhao     bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
137282695a5bSJiaqing Zhao     bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false);
1373da131a9aSJennifer Lee 
1374743eb1c0SJohnathan Mantey     if (ipv4Active)
1375743eb1c0SJohnathan Mantey     {
1376743eb1c0SJohnathan Mantey         updateIPv4DefaultGateway(ifaceId, "", asyncResp);
1377743eb1c0SJohnathan Mantey     }
13781f8c7b5dSJohnathan Mantey     bool nextv4DHCPState =
13791f8c7b5dSJohnathan Mantey         v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active;
13801f8c7b5dSJohnathan Mantey 
13811f8c7b5dSJohnathan Mantey     bool nextv6DHCPState{};
13821f8c7b5dSJohnathan Mantey     if (v6dhcpParms.dhcpv6OperatingMode)
1383da131a9aSJennifer Lee     {
1384b10d8db0SRavi Teja         if ((*v6dhcpParms.dhcpv6OperatingMode != "Enabled") &&
13851f8c7b5dSJohnathan Mantey             (*v6dhcpParms.dhcpv6OperatingMode != "Disabled"))
13861f8c7b5dSJohnathan Mantey         {
1387bf648f77SEd Tanous             messages::propertyValueFormatError(asyncResp->res,
1388bf648f77SEd Tanous                                                *v6dhcpParms.dhcpv6OperatingMode,
13891f8c7b5dSJohnathan Mantey                                                "OperatingMode");
1390da131a9aSJennifer Lee             return;
1391da131a9aSJennifer Lee         }
1392b10d8db0SRavi Teja         nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Enabled");
13931f8c7b5dSJohnathan Mantey     }
13941f8c7b5dSJohnathan Mantey     else
1395da131a9aSJennifer Lee     {
13961f8c7b5dSJohnathan Mantey         nextv6DHCPState = ipv6Active;
13971f8c7b5dSJohnathan Mantey     }
13981f8c7b5dSJohnathan Mantey 
1399e4588158SJishnu CM     bool nextDNSv4 = ethData.dnsv4Enabled;
1400e4588158SJishnu CM     bool nextDNSv6 = ethData.dnsv6Enabled;
1401e4588158SJishnu CM     if (v4dhcpParms.useDnsServers)
14021f8c7b5dSJohnathan Mantey     {
1403e4588158SJishnu CM         nextDNSv4 = *v4dhcpParms.useDnsServers;
14041f8c7b5dSJohnathan Mantey     }
1405e4588158SJishnu CM     if (v6dhcpParms.useDnsServers)
14061f8c7b5dSJohnathan Mantey     {
1407e4588158SJishnu CM         nextDNSv6 = *v6dhcpParms.useDnsServers;
14081f8c7b5dSJohnathan Mantey     }
14091f8c7b5dSJohnathan Mantey 
1410e4588158SJishnu CM     bool nextNTPv4 = ethData.ntpv4Enabled;
1411e4588158SJishnu CM     bool nextNTPv6 = ethData.ntpv6Enabled;
1412e4588158SJishnu CM     if (v4dhcpParms.useNtpServers)
14131f8c7b5dSJohnathan Mantey     {
1414e4588158SJishnu CM         nextNTPv4 = *v4dhcpParms.useNtpServers;
14151f8c7b5dSJohnathan Mantey     }
1416e4588158SJishnu CM     if (v6dhcpParms.useNtpServers)
14171f8c7b5dSJohnathan Mantey     {
1418e4588158SJishnu CM         nextNTPv6 = *v6dhcpParms.useNtpServers;
14191f8c7b5dSJohnathan Mantey     }
14201f8c7b5dSJohnathan Mantey 
142191c441ecSRavi Teja     bool nextUsev4Domain = ethData.domainv4Enabled;
142291c441ecSRavi Teja     bool nextUsev6Domain = ethData.domainv6Enabled;
1423e4588158SJishnu CM     if (v4dhcpParms.useDomainName)
14241f8c7b5dSJohnathan Mantey     {
1425e4588158SJishnu CM         nextUsev4Domain = *v4dhcpParms.useDomainName;
14261f8c7b5dSJohnathan Mantey     }
1427e4588158SJishnu CM     if (v6dhcpParms.useDomainName)
14281f8c7b5dSJohnathan Mantey     {
1429e4588158SJishnu CM         nextUsev6Domain = *v6dhcpParms.useDomainName;
14301f8c7b5dSJohnathan Mantey     }
14311f8c7b5dSJohnathan Mantey 
143262598e31SEd Tanous     BMCWEB_LOG_DEBUG("set DHCPEnabled...");
14331f8c7b5dSJohnathan Mantey     setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
14341f8c7b5dSJohnathan Mantey                    asyncResp);
143562598e31SEd Tanous     BMCWEB_LOG_DEBUG("set DNSEnabled...");
1436e4588158SJishnu CM     setDHCPConfig("DNSEnabled", nextDNSv4, asyncResp, ifaceId,
1437e4588158SJishnu CM                   NetworkType::dhcp4);
143862598e31SEd Tanous     BMCWEB_LOG_DEBUG("set NTPEnabled...");
1439e4588158SJishnu CM     setDHCPConfig("NTPEnabled", nextNTPv4, asyncResp, ifaceId,
1440e4588158SJishnu CM                   NetworkType::dhcp4);
144191c441ecSRavi Teja     BMCWEB_LOG_DEBUG("set DomainEnabled...");
144291c441ecSRavi Teja     setDHCPConfig("DomainEnabled", nextUsev4Domain, asyncResp, ifaceId,
1443e4588158SJishnu CM                   NetworkType::dhcp4);
1444e4588158SJishnu CM     BMCWEB_LOG_DEBUG("set DNSEnabled for dhcp6...");
1445e4588158SJishnu CM     setDHCPConfig("DNSEnabled", nextDNSv6, asyncResp, ifaceId,
1446e4588158SJishnu CM                   NetworkType::dhcp6);
1447e4588158SJishnu CM     BMCWEB_LOG_DEBUG("set NTPEnabled for dhcp6...");
1448e4588158SJishnu CM     setDHCPConfig("NTPEnabled", nextNTPv6, asyncResp, ifaceId,
1449e4588158SJishnu CM                   NetworkType::dhcp6);
145091c441ecSRavi Teja     BMCWEB_LOG_DEBUG("set DomainEnabled for dhcp6...");
145191c441ecSRavi Teja     setDHCPConfig("DomainEnabled", nextUsev6Domain, asyncResp, ifaceId,
1452e4588158SJishnu CM                   NetworkType::dhcp6);
1453da131a9aSJennifer Lee }
145401784826SJohnathan Mantey 
145577179532SEd Tanous inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry(
145677179532SEd Tanous     const std::vector<IPv4AddressData>::const_iterator& head,
145777179532SEd Tanous     const std::vector<IPv4AddressData>::const_iterator& end)
145801784826SJohnathan Mantey {
145917a897dfSManojkiran Eda     return std::find_if(head, end, [](const IPv4AddressData& value) {
146017a897dfSManojkiran Eda         return value.origin == "Static";
146117a897dfSManojkiran Eda     });
146201784826SJohnathan Mantey }
146301784826SJohnathan Mantey 
146477179532SEd Tanous inline std::vector<IPv6AddressData>::const_iterator getNextStaticIpEntry(
146577179532SEd Tanous     const std::vector<IPv6AddressData>::const_iterator& head,
146677179532SEd Tanous     const std::vector<IPv6AddressData>::const_iterator& end)
146701784826SJohnathan Mantey {
146817a897dfSManojkiran Eda     return std::find_if(head, end, [](const IPv6AddressData& value) {
146917a897dfSManojkiran Eda         return value.origin == "Static";
147017a897dfSManojkiran Eda     });
147101784826SJohnathan Mantey }
147201784826SJohnathan Mantey 
14736e1a52faSEd Tanous enum class AddrChange
14741abe55efSEd Tanous {
14756e1a52faSEd Tanous     Noop,
14766e1a52faSEd Tanous     Delete,
14776e1a52faSEd Tanous     Update,
14786e1a52faSEd Tanous };
14796e1a52faSEd Tanous 
14806e1a52faSEd Tanous // Struct representing a dbus change
14816e1a52faSEd Tanous struct AddressPatch
14826e1a52faSEd Tanous {
14836e1a52faSEd Tanous     std::string address;
14846e1a52faSEd Tanous     std::string gateway;
14856e1a52faSEd Tanous     uint8_t prefixLength = 0;
14866e1a52faSEd Tanous     std::string existingDbusId;
14876e1a52faSEd Tanous     AddrChange operation = AddrChange::Noop;
14886e1a52faSEd Tanous };
14896e1a52faSEd Tanous 
14906e1a52faSEd Tanous inline bool parseAddresses(
14916e1a52faSEd Tanous     std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
14926e1a52faSEd Tanous     const std::vector<IPv4AddressData>& ipv4Data, crow::Response& res,
14936e1a52faSEd Tanous     std::vector<AddressPatch>& addressesOut, std::string& gatewayOut)
14946e1a52faSEd Tanous {
149577179532SEd Tanous     std::vector<IPv4AddressData>::const_iterator nicIpEntry =
14962c70f800SEd Tanous         getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend());
149701784826SJohnathan Mantey 
14986e1a52faSEd Tanous     std::string lastGatewayPath;
14996e1a52faSEd Tanous     size_t entryIdx = 0;
15003dfed536SEd Tanous     for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
15013dfed536SEd Tanous          input)
15021abe55efSEd Tanous     {
1503bd79bce8SPatrick Williams         std::string pathString =
15046e1a52faSEd Tanous             std::format("IPv4StaticAddresses/{}", entryIdx);
15056e1a52faSEd Tanous         AddressPatch& thisAddress = addressesOut.emplace_back();
15063dfed536SEd Tanous         nlohmann::json::object_t* obj =
15073dfed536SEd Tanous             std::get_if<nlohmann::json::object_t>(&thisJson);
1508743eb1c0SJohnathan Mantey         if (nicIpEntry != ipv4Data.cend())
1509743eb1c0SJohnathan Mantey         {
15106e1a52faSEd Tanous             thisAddress.existingDbusId = nicIpEntry->id;
1511743eb1c0SJohnathan Mantey         }
1512743eb1c0SJohnathan Mantey 
15136e1a52faSEd Tanous         if (obj == nullptr)
15146e1a52faSEd Tanous         {
15156e1a52faSEd Tanous             if (thisAddress.existingDbusId.empty())
15166e1a52faSEd Tanous             {
15176e1a52faSEd Tanous                 // Received a DELETE action on an entry not assigned to the NIC
15186e1a52faSEd Tanous                 messages::resourceCannotBeDeleted(res);
15196e1a52faSEd Tanous                 return false;
15206e1a52faSEd Tanous             }
15216e1a52faSEd Tanous             thisAddress.operation = AddrChange::Delete;
15226e1a52faSEd Tanous         }
15236e1a52faSEd Tanous         else
1524f476acbfSRatan Gupta         {
1525537174c4SEd Tanous             std::optional<std::string> address;
1526537174c4SEd Tanous             std::optional<std::string> gateway;
15276e1a52faSEd Tanous             std::optional<std::string> subnetMask;
15286e1a52faSEd Tanous             if (!obj->empty())
15296e1a52faSEd Tanous             {
1530afc474aeSMyung Bae                 if (!json_util::readJsonObject( //
15316e1a52faSEd Tanous                         *obj, res, //
1532afc474aeSMyung Bae                         "Address", address, //
1533afc474aeSMyung Bae                         "Gateway", gateway, //
1534afc474aeSMyung Bae                         "SubnetMask", subnetMask //
1535afc474aeSMyung Bae                         ))
1536537174c4SEd Tanous                 {
15376e1a52faSEd Tanous                     messages::propertyValueFormatError(res, *obj, pathString);
15386e1a52faSEd Tanous                     return false;
1539179db1d7SKowalski, Kamil                 }
15406e1a52faSEd Tanous             }
154101784826SJohnathan Mantey             // Find the address/subnet/gateway values. Any values that are
154201784826SJohnathan Mantey             // not explicitly provided are assumed to be unmodified from the
154301784826SJohnathan Mantey             // current state of the interface. Merge existing state into the
154401784826SJohnathan Mantey             // current request.
1545537174c4SEd Tanous             if (address)
15461abe55efSEd Tanous             {
1547e01d0c36SEd Tanous                 if (!ip_util::ipv4VerifyIpAndGetBitcount(*address))
154801784826SJohnathan Mantey                 {
15496e1a52faSEd Tanous                     messages::propertyValueFormatError(res, *address,
1550bf648f77SEd Tanous                                                        pathString + "/Address");
15516e1a52faSEd Tanous                     return false;
155201784826SJohnathan Mantey                 }
15536e1a52faSEd Tanous                 thisAddress.operation = AddrChange::Update;
15546e1a52faSEd Tanous                 thisAddress.address = *address;
155501784826SJohnathan Mantey             }
15566e1a52faSEd Tanous             else if (thisAddress.existingDbusId.empty())
155701784826SJohnathan Mantey             {
15586e1a52faSEd Tanous                 messages::propertyMissing(res, pathString + "/Address");
15596e1a52faSEd Tanous                 return false;
156001784826SJohnathan Mantey             }
156101784826SJohnathan Mantey             else
156201784826SJohnathan Mantey             {
15636e1a52faSEd Tanous                 thisAddress.address = nicIpEntry->address;
15644a0cb85cSEd Tanous             }
15654a0cb85cSEd Tanous 
1566537174c4SEd Tanous             if (subnetMask)
15674a0cb85cSEd Tanous             {
15686e1a52faSEd Tanous                 uint8_t prefixLength = 0;
1569033f1e4dSEd Tanous                 if (!ip_util::ipv4VerifyIpAndGetBitcount(*subnetMask,
1570033f1e4dSEd Tanous                                                          &prefixLength))
15714a0cb85cSEd Tanous                 {
1572f12894f8SJason M. Bills                     messages::propertyValueFormatError(
15736e1a52faSEd Tanous                         res, *subnetMask, pathString + "/SubnetMask");
15746e1a52faSEd Tanous                     return false;
15754a0cb85cSEd Tanous                 }
15766e1a52faSEd Tanous                 thisAddress.prefixLength = prefixLength;
15776e1a52faSEd Tanous                 thisAddress.operation = AddrChange::Update;
15784a0cb85cSEd Tanous             }
15796e1a52faSEd Tanous             else if (thisAddress.existingDbusId.empty())
15804a0cb85cSEd Tanous             {
15816e1a52faSEd Tanous                 messages::propertyMissing(res, pathString + "/SubnetMask");
15826e1a52faSEd Tanous                 return false;
15834a0cb85cSEd Tanous             }
15841abe55efSEd Tanous             else
15851abe55efSEd Tanous             {
15866e1a52faSEd Tanous                 uint8_t prefixLength = 0;
15876e1a52faSEd Tanous                 // Ignore return code.  It came from internal, it's it's invalid
15886e1a52faSEd Tanous                 // nothing we can do
15896e1a52faSEd Tanous                 ip_util::ipv4VerifyIpAndGetBitcount(nicIpEntry->netmask,
15906e1a52faSEd Tanous                                                     &prefixLength);
159101784826SJohnathan Mantey 
15926e1a52faSEd Tanous                 thisAddress.prefixLength = prefixLength;
15936e1a52faSEd Tanous             }
159401784826SJohnathan Mantey             if (gateway)
159501784826SJohnathan Mantey             {
1596e01d0c36SEd Tanous                 if (!ip_util::ipv4VerifyIpAndGetBitcount(*gateway))
159701784826SJohnathan Mantey                 {
15986e1a52faSEd Tanous                     messages::propertyValueFormatError(res, *gateway,
1599bf648f77SEd Tanous                                                        pathString + "/Gateway");
16006e1a52faSEd Tanous                     return false;
160101784826SJohnathan Mantey                 }
16026e1a52faSEd Tanous                 thisAddress.operation = AddrChange::Update;
16036e1a52faSEd Tanous                 thisAddress.gateway = *gateway;
160401784826SJohnathan Mantey             }
16056e1a52faSEd Tanous             else if (thisAddress.existingDbusId.empty())
160601784826SJohnathan Mantey             {
16076e1a52faSEd Tanous                 // Default to null gateway
16086e1a52faSEd Tanous                 gateway = "";
160901784826SJohnathan Mantey             }
161001784826SJohnathan Mantey             else
16111abe55efSEd Tanous             {
16126e1a52faSEd Tanous                 thisAddress.gateway = nicIpEntry->gateway;
16134a0cb85cSEd Tanous             }
16144a0cb85cSEd Tanous 
16156e1a52faSEd Tanous             // Changing gateway from existing
16166e1a52faSEd Tanous             if (!thisAddress.gateway.empty() &&
16176e1a52faSEd Tanous                 thisAddress.gateway != "0.0.0.0")
1618743eb1c0SJohnathan Mantey             {
16196e1a52faSEd Tanous                 if (!gatewayOut.empty() && gatewayOut != thisAddress.gateway)
1620743eb1c0SJohnathan Mantey                 {
1621743eb1c0SJohnathan Mantey                     // A NIC can only have a single active gateway value.
1622743eb1c0SJohnathan Mantey                     // If any gateway in the array of static addresses
1623743eb1c0SJohnathan Mantey                     // mismatch the PATCH is in error.
1624743eb1c0SJohnathan Mantey                     std::string arg1 = pathString + "/Gateway";
16256e1a52faSEd Tanous                     std::string arg2 = lastGatewayPath + "/Gateway";
16266e1a52faSEd Tanous                     messages::propertyValueConflict(res, arg1, arg2);
16276e1a52faSEd Tanous                     return false;
16286e1a52faSEd Tanous                 }
16296e1a52faSEd Tanous                 gatewayOut = thisAddress.gateway;
16306e1a52faSEd Tanous                 lastGatewayPath = pathString;
1631743eb1c0SJohnathan Mantey             }
1632743eb1c0SJohnathan Mantey         }
16336e1a52faSEd Tanous         nicIpEntry++;
16346e1a52faSEd Tanous         nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
16356e1a52faSEd Tanous         entryIdx++;
1636743eb1c0SJohnathan Mantey     }
1637743eb1c0SJohnathan Mantey 
16386e1a52faSEd Tanous     // Delete the remaining IPs
16396e1a52faSEd Tanous     while (nicIpEntry != ipv4Data.cend())
16401abe55efSEd Tanous     {
16416e1a52faSEd Tanous         AddressPatch& thisAddress = addressesOut.emplace_back();
16426e1a52faSEd Tanous         thisAddress.operation = AddrChange::Delete;
16436e1a52faSEd Tanous         thisAddress.existingDbusId = nicIpEntry->id;
16446e1a52faSEd Tanous         nicIpEntry++;
16456e1a52faSEd Tanous         nicIpEntry = getNextStaticIpEntry(nicIpEntry, ipv4Data.cend());
1646588c3f0dSKowalski, Kamil     }
16476e1a52faSEd Tanous 
16486e1a52faSEd Tanous     return true;
16494a0cb85cSEd Tanous }
16506e1a52faSEd Tanous 
16516e1a52faSEd Tanous inline void handleIPv4StaticPatch(
16526e1a52faSEd Tanous     const std::string& ifaceId,
16536e1a52faSEd Tanous     std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
16546e1a52faSEd Tanous     const EthernetInterfaceData& ethData,
16556e1a52faSEd Tanous     const std::vector<IPv4AddressData>& ipv4Data,
16566e1a52faSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
165701784826SJohnathan Mantey {
16586e1a52faSEd Tanous     std::vector<AddressPatch> addresses;
16596e1a52faSEd Tanous     std::string gatewayOut;
16606e1a52faSEd Tanous     if (!parseAddresses(input, ipv4Data, asyncResp->res, addresses, gatewayOut))
166101784826SJohnathan Mantey     {
1662743eb1c0SJohnathan Mantey         return;
1663743eb1c0SJohnathan Mantey     }
16646e1a52faSEd Tanous 
16656e1a52faSEd Tanous     // If we're setting the gateway to something new, delete the
16666e1a52faSEd Tanous     // existing so we won't conflict
16676e1a52faSEd Tanous     if (!ethData.defaultGateway.empty() && ethData.defaultGateway != gatewayOut)
16686e1a52faSEd Tanous     {
16696e1a52faSEd Tanous         updateIPv4DefaultGateway(ifaceId, "", asyncResp);
1670743eb1c0SJohnathan Mantey     }
16716e1a52faSEd Tanous 
16726e1a52faSEd Tanous     for (const AddressPatch& address : addresses)
16736e1a52faSEd Tanous     {
16746e1a52faSEd Tanous         switch (address.operation)
16756e1a52faSEd Tanous         {
16766e1a52faSEd Tanous             case AddrChange::Delete:
16776e1a52faSEd Tanous             {
16786e1a52faSEd Tanous                 BMCWEB_LOG_ERROR("Deleting id {} on interface {}",
16796e1a52faSEd Tanous                                  address.existingDbusId, ifaceId);
16806e1a52faSEd Tanous                 deleteIPAddress(ifaceId, address.existingDbusId, asyncResp);
16816e1a52faSEd Tanous             }
16826e1a52faSEd Tanous             break;
16836e1a52faSEd Tanous             case AddrChange::Update:
16846e1a52faSEd Tanous             {
16856e1a52faSEd Tanous                 // Update is a delete then a recreate
16866e1a52faSEd Tanous                 // Only need to update if there is an existing ip at this index
16876e1a52faSEd Tanous                 if (!address.existingDbusId.empty())
16886e1a52faSEd Tanous                 {
16896e1a52faSEd Tanous                     BMCWEB_LOG_ERROR("Deleting id {} on interface {}",
16906e1a52faSEd Tanous                                      address.existingDbusId, ifaceId);
16916e1a52faSEd Tanous                     deleteAndCreateIPAddress(
16926e1a52faSEd Tanous                         IpVersion::IpV4, ifaceId, address.existingDbusId,
16936e1a52faSEd Tanous                         address.prefixLength, address.address, address.gateway,
16946e1a52faSEd Tanous                         asyncResp);
16956e1a52faSEd Tanous                 }
16966e1a52faSEd Tanous                 else
16976e1a52faSEd Tanous                 {
16986e1a52faSEd Tanous                     // Otherwise, just create a new one
16996e1a52faSEd Tanous                     BMCWEB_LOG_ERROR(
17006e1a52faSEd Tanous                         "creating ip {} prefix {} gateway {} on interface {}",
17016e1a52faSEd Tanous                         address.address, address.prefixLength, address.gateway,
17026e1a52faSEd Tanous                         ifaceId);
17036e1a52faSEd Tanous                     createIPv4(ifaceId, address.prefixLength, address.gateway,
17046e1a52faSEd Tanous                                address.address, asyncResp);
17056e1a52faSEd Tanous                 }
17066e1a52faSEd Tanous             }
17076e1a52faSEd Tanous             break;
17086e1a52faSEd Tanous             default:
17096e1a52faSEd Tanous             {
17106e1a52faSEd Tanous                 // Leave alone
17116e1a52faSEd Tanous             }
17126e1a52faSEd Tanous             break;
17136e1a52faSEd Tanous         }
17146e1a52faSEd Tanous     }
17156e1a52faSEd Tanous 
17166e1a52faSEd Tanous     // now update to the new gateway.
17176e1a52faSEd Tanous     // Default gateway is already empty, so no need to update if we're clearing
17186e1a52faSEd Tanous     if (!gatewayOut.empty() && ethData.defaultGateway != gatewayOut)
17196e1a52faSEd Tanous     {
17206e1a52faSEd Tanous         updateIPv4DefaultGateway(ifaceId, gatewayOut, asyncResp);
172101784826SJohnathan Mantey     }
17224a0cb85cSEd Tanous }
17234a0cb85cSEd Tanous 
17244f48d5f6SEd Tanous inline void handleStaticNameServersPatch(
1725f85837bfSRAJESWARAN THILLAIGOVINDAN     const std::string& ifaceId,
1726f85837bfSRAJESWARAN THILLAIGOVINDAN     const std::vector<std::string>& updatedStaticNameServers,
17278d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1728f85837bfSRAJESWARAN THILLAIGOVINDAN {
17291847f2a0SAsmitha Karunanithi     setDbusProperty(
1730e93abac6SGinu George         asyncResp, "StaticNameServers", "xyz.openbmc_project.Network",
17311847f2a0SAsmitha Karunanithi         sdbusplus::message::object_path("/xyz/openbmc_project/network") /
17321847f2a0SAsmitha Karunanithi             ifaceId,
17339ae226faSGeorge Liu         "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers",
1734e93abac6SGinu George         updatedStaticNameServers);
1735f85837bfSRAJESWARAN THILLAIGOVINDAN }
1736f85837bfSRAJESWARAN THILLAIGOVINDAN 
17374f48d5f6SEd Tanous inline void handleIPv6StaticAddressesPatch(
17383dfed536SEd Tanous     const std::string& ifaceId,
17393dfed536SEd Tanous     std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input,
174077179532SEd Tanous     const std::vector<IPv6AddressData>& ipv6Data,
17418d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1742e48c0fc5SRavi Teja {
1743271584abSEd Tanous     size_t entryIdx = 1;
174477179532SEd Tanous     std::vector<IPv6AddressData>::const_iterator nicIpEntry =
17452c70f800SEd Tanous         getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend());
17463dfed536SEd Tanous     for (std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson :
17473dfed536SEd Tanous          input)
1748e48c0fc5SRavi Teja     {
1749bd79bce8SPatrick Williams         std::string pathString =
1750bd79bce8SPatrick Williams             "IPv6StaticAddresses/" + std::to_string(entryIdx);
17513dfed536SEd Tanous         nlohmann::json::object_t* obj =
17523dfed536SEd Tanous             std::get_if<nlohmann::json::object_t>(&thisJson);
17533dfed536SEd Tanous         if (obj != nullptr && !obj->empty())
1754e48c0fc5SRavi Teja         {
1755e48c0fc5SRavi Teja             std::optional<std::string> address;
1756e48c0fc5SRavi Teja             std::optional<uint8_t> prefixLength;
17573dfed536SEd Tanous             nlohmann::json::object_t thisJsonCopy = *obj;
1758afc474aeSMyung Bae             if (!json_util::readJsonObject( //
1759afc474aeSMyung Bae                     thisJsonCopy, asyncResp->res, //
1760afc474aeSMyung Bae                     "Address", address, //
1761afc474aeSMyung Bae                     "PrefixLength", prefixLength //
1762afc474aeSMyung Bae                     ))
1763e48c0fc5SRavi Teja             {
17643dfed536SEd Tanous                 messages::propertyValueFormatError(asyncResp->res, thisJsonCopy,
176571f52d96SEd Tanous                                                    pathString);
1766e48c0fc5SRavi Teja                 return;
1767e48c0fc5SRavi Teja             }
1768e48c0fc5SRavi Teja 
176901784826SJohnathan Mantey             // Find the address and prefixLength values. Any values that are
177001784826SJohnathan Mantey             // not explicitly provided are assumed to be unmodified from the
177101784826SJohnathan Mantey             // current state of the interface. Merge existing state into the
177201784826SJohnathan Mantey             // current request.
1773d547d8d2SEd Tanous             if (!address)
1774e48c0fc5SRavi Teja             {
1775d547d8d2SEd Tanous                 if (nicIpEntry == ipv6Data.end())
177601784826SJohnathan Mantey                 {
177701784826SJohnathan Mantey                     messages::propertyMissing(asyncResp->res,
177801784826SJohnathan Mantey                                               pathString + "/Address");
177901784826SJohnathan Mantey                     return;
1780e48c0fc5SRavi Teja                 }
1781d547d8d2SEd Tanous                 address = nicIpEntry->address;
1782d547d8d2SEd Tanous             }
1783e48c0fc5SRavi Teja 
1784d547d8d2SEd Tanous             if (!prefixLength)
1785e48c0fc5SRavi Teja             {
1786d547d8d2SEd Tanous                 if (nicIpEntry == ipv6Data.end())
1787e48c0fc5SRavi Teja                 {
1788e48c0fc5SRavi Teja                     messages::propertyMissing(asyncResp->res,
1789e48c0fc5SRavi Teja                                               pathString + "/PrefixLength");
179001784826SJohnathan Mantey                     return;
1791e48c0fc5SRavi Teja                 }
1792d547d8d2SEd Tanous                 prefixLength = nicIpEntry->prefixLength;
1793d547d8d2SEd Tanous             }
1794e48c0fc5SRavi Teja 
179585ffe86aSJiaqing Zhao             if (nicIpEntry != ipv6Data.end())
1796e48c0fc5SRavi Teja             {
17979c5e585cSRavi Teja                 deleteAndCreateIPAddress(IpVersion::IpV6, ifaceId,
1798d547d8d2SEd Tanous                                          nicIpEntry->id, *prefixLength,
1799d547d8d2SEd Tanous                                          *address, "", asyncResp);
1800bd79bce8SPatrick Williams                 nicIpEntry =
1801bd79bce8SPatrick Williams                     getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend());
180201784826SJohnathan Mantey             }
180301784826SJohnathan Mantey             else
180401784826SJohnathan Mantey             {
1805d547d8d2SEd Tanous                 createIPv6(ifaceId, *prefixLength, *address, asyncResp);
1806e48c0fc5SRavi Teja             }
1807e48c0fc5SRavi Teja             entryIdx++;
1808e48c0fc5SRavi Teja         }
180901784826SJohnathan Mantey         else
181001784826SJohnathan Mantey         {
181185ffe86aSJiaqing Zhao             if (nicIpEntry == ipv6Data.end())
181201784826SJohnathan Mantey             {
181301784826SJohnathan Mantey                 // Requesting a DELETE/DO NOT MODIFY action for an item
181401784826SJohnathan Mantey                 // that isn't present on the eth(n) interface. Input JSON is
181501784826SJohnathan Mantey                 // in error, so bail out.
18163dfed536SEd Tanous                 if (obj == nullptr)
181701784826SJohnathan Mantey                 {
181801784826SJohnathan Mantey                     messages::resourceCannotBeDeleted(asyncResp->res);
181901784826SJohnathan Mantey                     return;
182001784826SJohnathan Mantey                 }
18213dfed536SEd Tanous                 messages::propertyValueFormatError(asyncResp->res, *obj,
182271f52d96SEd Tanous                                                    pathString);
182301784826SJohnathan Mantey                 return;
182401784826SJohnathan Mantey             }
182501784826SJohnathan Mantey 
18263dfed536SEd Tanous             if (obj == nullptr)
182701784826SJohnathan Mantey             {
18289c5e585cSRavi Teja                 deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp);
182901784826SJohnathan Mantey             }
183085ffe86aSJiaqing Zhao             if (nicIpEntry != ipv6Data.cend())
183101784826SJohnathan Mantey             {
1832bd79bce8SPatrick Williams                 nicIpEntry =
1833bd79bce8SPatrick Williams                     getNextStaticIpEntry(++nicIpEntry, ipv6Data.cend());
183401784826SJohnathan Mantey             }
183501784826SJohnathan Mantey             entryIdx++;
183601784826SJohnathan Mantey         }
183701784826SJohnathan Mantey     }
1838e48c0fc5SRavi Teja }
1839e48c0fc5SRavi Teja 
18407857cb8dSJiaqing Zhao inline std::string extractParentInterfaceName(const std::string& ifaceId)
18417857cb8dSJiaqing Zhao {
18427857cb8dSJiaqing Zhao     std::size_t pos = ifaceId.find('_');
18437857cb8dSJiaqing Zhao     return ifaceId.substr(0, pos);
18447857cb8dSJiaqing Zhao }
18457857cb8dSJiaqing Zhao 
1846bd79bce8SPatrick Williams inline void parseInterfaceData(
1847bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1848bd79bce8SPatrick Williams     const std::string& ifaceId, const EthernetInterfaceData& ethData,
184977179532SEd Tanous     const std::vector<IPv4AddressData>& ipv4Data,
1850ce73d5c8SSunitha Harish     const std::vector<IPv6AddressData>& ipv6Data,
1851ce73d5c8SSunitha Harish     const std::vector<StaticGatewayData>& ipv6GatewayData)
18524a0cb85cSEd Tanous {
18532c70f800SEd Tanous     nlohmann::json& jsonResponse = asyncResp->res.jsonValue;
185481ce609eSEd Tanous     jsonResponse["Id"] = ifaceId;
1855253f11b8SEd Tanous     jsonResponse["@odata.id"] =
1856253f11b8SEd Tanous         boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces/{}",
1857253f11b8SEd Tanous                             BMCWEB_REDFISH_MANAGER_URI_NAME, ifaceId);
18582c70f800SEd Tanous     jsonResponse["InterfaceEnabled"] = ethData.nicEnabled;
1859eeedda23SJohnathan Mantey 
1860eeedda23SJohnathan Mantey     if (ethData.nicEnabled)
1861eeedda23SJohnathan Mantey     {
1862539d8c6bSEd Tanous         jsonResponse["LinkStatus"] =
1863539d8c6bSEd Tanous             ethData.linkUp ? ethernet_interface::LinkStatus::LinkUp
1864539d8c6bSEd Tanous                            : ethernet_interface::LinkStatus::LinkDown;
1865539d8c6bSEd Tanous         jsonResponse["Status"]["State"] = resource::State::Enabled;
1866029573d4SEd Tanous     }
1867029573d4SEd Tanous     else
1868029573d4SEd Tanous     {
1869539d8c6bSEd Tanous         jsonResponse["LinkStatus"] = ethernet_interface::LinkStatus::NoLink;
1870539d8c6bSEd Tanous         jsonResponse["Status"]["State"] = resource::State::Disabled;
1871029573d4SEd Tanous     }
1872aa05fb27SJohnathan Mantey 
18732c70f800SEd Tanous     jsonResponse["SpeedMbps"] = ethData.speed;
187435fb5311STejas Patil     jsonResponse["MTUSize"] = ethData.mtuSize;
18754652c640SAsmitha Karunanithi     if (ethData.macAddress)
18764652c640SAsmitha Karunanithi     {
18774652c640SAsmitha Karunanithi         jsonResponse["MACAddress"] = *ethData.macAddress;
18784652c640SAsmitha Karunanithi     }
18792c70f800SEd Tanous     jsonResponse["DHCPv4"]["DHCPEnabled"] =
188082695a5bSJiaqing Zhao         translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
1881e4588158SJishnu CM     jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpv4Enabled;
1882e4588158SJishnu CM     jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsv4Enabled;
1883de9ad764SRavi Teja     jsonResponse["DHCPv4"]["UseDomainName"] = ethData.domainv4Enabled;
18842c70f800SEd Tanous     jsonResponse["DHCPv6"]["OperatingMode"] =
1885bd79bce8SPatrick Williams         translateDhcpEnabledToBool(ethData.dhcpEnabled, false)
1886bd79bce8SPatrick Williams             ? "Enabled"
18871f8c7b5dSJohnathan Mantey             : "Disabled";
1888e4588158SJishnu CM     jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpv6Enabled;
1889e4588158SJishnu CM     jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsv6Enabled;
1890de9ad764SRavi Teja     jsonResponse["DHCPv6"]["UseDomainName"] = ethData.domainv6Enabled;
1891b10d8db0SRavi Teja     jsonResponse["StatelessAddressAutoConfig"]["IPv6AutoConfigEnabled"] =
1892b10d8db0SRavi Teja         ethData.ipv6AcceptRa;
18932a133282Smanojkiraneda 
189482695a5bSJiaqing Zhao     if (!ethData.hostName.empty())
18954a0cb85cSEd Tanous     {
189682695a5bSJiaqing Zhao         jsonResponse["HostName"] = ethData.hostName;
1897ab6554f1SJoshi-Mansi 
1898ab6554f1SJoshi-Mansi         // When domain name is empty then it means, that it is a network
1899ab6554f1SJoshi-Mansi         // without domain names, and the host name itself must be treated as
1900ab6554f1SJoshi-Mansi         // FQDN
190182695a5bSJiaqing Zhao         std::string fqdn = ethData.hostName;
1902d24bfc7aSJennifer Lee         if (!ethData.domainnames.empty())
1903d24bfc7aSJennifer Lee         {
19042c70f800SEd Tanous             fqdn += "." + ethData.domainnames[0];
1905d24bfc7aSJennifer Lee         }
19062c70f800SEd Tanous         jsonResponse["FQDN"] = fqdn;
19074a0cb85cSEd Tanous     }
19084a0cb85cSEd Tanous 
19097857cb8dSJiaqing Zhao     if (ethData.vlanId)
19107857cb8dSJiaqing Zhao     {
1911539d8c6bSEd Tanous         jsonResponse["EthernetInterfaceType"] =
1912539d8c6bSEd Tanous             ethernet_interface::EthernetDeviceType::Virtual;
19137857cb8dSJiaqing Zhao         jsonResponse["VLAN"]["VLANEnable"] = true;
19147857cb8dSJiaqing Zhao         jsonResponse["VLAN"]["VLANId"] = *ethData.vlanId;
19157857cb8dSJiaqing Zhao         jsonResponse["VLAN"]["Tagged"] = true;
19167857cb8dSJiaqing Zhao 
19177857cb8dSJiaqing Zhao         nlohmann::json::array_t relatedInterfaces;
19187857cb8dSJiaqing Zhao         nlohmann::json& parentInterface = relatedInterfaces.emplace_back();
19197857cb8dSJiaqing Zhao         parentInterface["@odata.id"] =
1920253f11b8SEd Tanous             boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces",
1921253f11b8SEd Tanous                                 BMCWEB_REDFISH_MANAGER_URI_NAME,
19227857cb8dSJiaqing Zhao                                 extractParentInterfaceName(ifaceId));
19237857cb8dSJiaqing Zhao         jsonResponse["Links"]["RelatedInterfaces"] =
19247857cb8dSJiaqing Zhao             std::move(relatedInterfaces);
19257857cb8dSJiaqing Zhao     }
19267857cb8dSJiaqing Zhao     else
19277857cb8dSJiaqing Zhao     {
1928539d8c6bSEd Tanous         jsonResponse["EthernetInterfaceType"] =
1929539d8c6bSEd Tanous             ethernet_interface::EthernetDeviceType::Physical;
19307857cb8dSJiaqing Zhao     }
19317857cb8dSJiaqing Zhao 
19322c70f800SEd Tanous     jsonResponse["NameServers"] = ethData.nameServers;
19332c70f800SEd Tanous     jsonResponse["StaticNameServers"] = ethData.staticNameServers;
19344a0cb85cSEd Tanous 
19352c70f800SEd Tanous     nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"];
19362c70f800SEd Tanous     nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
19372c70f800SEd Tanous     ipv4Array = nlohmann::json::array();
19382c70f800SEd Tanous     ipv4StaticArray = nlohmann::json::array();
19399eb808c1SEd Tanous     for (const auto& ipv4Config : ipv4Data)
19404a0cb85cSEd Tanous     {
19412c70f800SEd Tanous         std::string gatewayStr = ipv4Config.gateway;
1942fa5053a6SGunnar Mills         if (gatewayStr.empty())
1943fa5053a6SGunnar Mills         {
1944fa5053a6SGunnar Mills             gatewayStr = "0.0.0.0";
1945fa5053a6SGunnar Mills         }
19461476687dSEd Tanous         nlohmann::json::object_t ipv4;
19471476687dSEd Tanous         ipv4["AddressOrigin"] = ipv4Config.origin;
19481476687dSEd Tanous         ipv4["SubnetMask"] = ipv4Config.netmask;
19491476687dSEd Tanous         ipv4["Address"] = ipv4Config.address;
19501476687dSEd Tanous         ipv4["Gateway"] = gatewayStr;
1951fa5053a6SGunnar Mills 
19522c70f800SEd Tanous         if (ipv4Config.origin == "Static")
1953d1d50814SRavi Teja         {
19541476687dSEd Tanous             ipv4StaticArray.push_back(ipv4);
1955d1d50814SRavi Teja         }
19561476687dSEd Tanous 
1957b2ba3072SPatrick Williams         ipv4Array.emplace_back(std::move(ipv4));
195801784826SJohnathan Mantey     }
1959d1d50814SRavi Teja 
196082695a5bSJiaqing Zhao     std::string ipv6GatewayStr = ethData.ipv6DefaultGateway;
19617ea79e5eSRavi Teja     if (ipv6GatewayStr.empty())
19627ea79e5eSRavi Teja     {
19637ea79e5eSRavi Teja         ipv6GatewayStr = "0:0:0:0:0:0:0:0";
19647ea79e5eSRavi Teja     }
19657ea79e5eSRavi Teja 
19667ea79e5eSRavi Teja     jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr;
1967e48c0fc5SRavi Teja 
1968ce73d5c8SSunitha Harish     nlohmann::json::array_t ipv6StaticGatewayArray;
1969ce73d5c8SSunitha Harish     for (const auto& ipv6GatewayConfig : ipv6GatewayData)
1970ce73d5c8SSunitha Harish     {
1971ce73d5c8SSunitha Harish         nlohmann::json::object_t ipv6Gateway;
1972ce73d5c8SSunitha Harish         ipv6Gateway["Address"] = ipv6GatewayConfig.gateway;
1973ce73d5c8SSunitha Harish         ipv6StaticGatewayArray.emplace_back(std::move(ipv6Gateway));
1974ce73d5c8SSunitha Harish     }
1975ce73d5c8SSunitha Harish     jsonResponse["IPv6StaticDefaultGateways"] =
1976ce73d5c8SSunitha Harish         std::move(ipv6StaticGatewayArray);
1977ce73d5c8SSunitha Harish 
19782c70f800SEd Tanous     nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"];
19792c70f800SEd Tanous     nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"];
19802c70f800SEd Tanous     ipv6Array = nlohmann::json::array();
19812c70f800SEd Tanous     ipv6StaticArray = nlohmann::json::array();
19827f2e23e9SJohnathan Mantey     nlohmann::json& ipv6AddrPolicyTable =
19832c70f800SEd Tanous         jsonResponse["IPv6AddressPolicyTable"];
19847f2e23e9SJohnathan Mantey     ipv6AddrPolicyTable = nlohmann::json::array();
19859eb808c1SEd Tanous     for (const auto& ipv6Config : ipv6Data)
1986e48c0fc5SRavi Teja     {
19871476687dSEd Tanous         nlohmann::json::object_t ipv6;
19881476687dSEd Tanous         ipv6["Address"] = ipv6Config.address;
19891476687dSEd Tanous         ipv6["PrefixLength"] = ipv6Config.prefixLength;
19901476687dSEd Tanous         ipv6["AddressOrigin"] = ipv6Config.origin;
1991f8361275SSunitha Harish 
1992b2ba3072SPatrick Williams         ipv6Array.emplace_back(std::move(ipv6));
19932c70f800SEd Tanous         if (ipv6Config.origin == "Static")
1994e48c0fc5SRavi Teja         {
19951476687dSEd Tanous             nlohmann::json::object_t ipv6Static;
19961476687dSEd Tanous             ipv6Static["Address"] = ipv6Config.address;
19971476687dSEd Tanous             ipv6Static["PrefixLength"] = ipv6Config.prefixLength;
1998b2ba3072SPatrick Williams             ipv6StaticArray.emplace_back(std::move(ipv6Static));
199901784826SJohnathan Mantey         }
2000e48c0fc5SRavi Teja     }
2001588c3f0dSKowalski, Kamil }
2002588c3f0dSKowalski, Kamil 
2003e7caf250SJiaqing Zhao inline void afterDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2004e7caf250SJiaqing Zhao                         const std::string& ifaceId,
2005e7caf250SJiaqing Zhao                         const boost::system::error_code& ec,
2006e7caf250SJiaqing Zhao                         const sdbusplus::message_t& m)
2007e7caf250SJiaqing Zhao {
2008e7caf250SJiaqing Zhao     if (!ec)
2009e7caf250SJiaqing Zhao     {
2010e7caf250SJiaqing Zhao         return;
2011e7caf250SJiaqing Zhao     }
2012e7caf250SJiaqing Zhao     const sd_bus_error* dbusError = m.get_error();
2013e7caf250SJiaqing Zhao     if (dbusError == nullptr)
2014e7caf250SJiaqing Zhao     {
2015e7caf250SJiaqing Zhao         messages::internalError(asyncResp->res);
2016e7caf250SJiaqing Zhao         return;
2017e7caf250SJiaqing Zhao     }
201862598e31SEd Tanous     BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
2019e7caf250SJiaqing Zhao 
2020e7caf250SJiaqing Zhao     if (std::string_view("org.freedesktop.DBus.Error.UnknownObject") ==
2021e7caf250SJiaqing Zhao         dbusError->name)
2022e7caf250SJiaqing Zhao     {
2023e7caf250SJiaqing Zhao         messages::resourceNotFound(asyncResp->res, "EthernetInterface",
2024e7caf250SJiaqing Zhao                                    ifaceId);
2025e7caf250SJiaqing Zhao         return;
2026e7caf250SJiaqing Zhao     }
2027e7caf250SJiaqing Zhao     if (std::string_view("org.freedesktop.DBus.Error.UnknownMethod") ==
2028e7caf250SJiaqing Zhao         dbusError->name)
2029e7caf250SJiaqing Zhao     {
2030e7caf250SJiaqing Zhao         messages::resourceCannotBeDeleted(asyncResp->res);
2031e7caf250SJiaqing Zhao         return;
2032e7caf250SJiaqing Zhao     }
2033e7caf250SJiaqing Zhao     messages::internalError(asyncResp->res);
2034e7caf250SJiaqing Zhao }
2035e7caf250SJiaqing Zhao 
2036bd79bce8SPatrick Williams inline void afterVlanCreate(
2037bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2038bd79bce8SPatrick Williams     const std::string& parentInterfaceUri, const std::string& vlanInterface,
2039bd79bce8SPatrick Williams     const boost::system::error_code& ec, const sdbusplus::message_t& m
2040b5ca3fdcSJiaqing Zhao 
2041b5ca3fdcSJiaqing Zhao )
2042b5ca3fdcSJiaqing Zhao {
2043b5ca3fdcSJiaqing Zhao     if (ec)
2044b5ca3fdcSJiaqing Zhao     {
2045b5ca3fdcSJiaqing Zhao         const sd_bus_error* dbusError = m.get_error();
2046b5ca3fdcSJiaqing Zhao         if (dbusError == nullptr)
2047b5ca3fdcSJiaqing Zhao         {
2048b5ca3fdcSJiaqing Zhao             messages::internalError(asyncResp->res);
2049b5ca3fdcSJiaqing Zhao             return;
2050b5ca3fdcSJiaqing Zhao         }
205162598e31SEd Tanous         BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name);
2052b5ca3fdcSJiaqing Zhao 
2053b5ca3fdcSJiaqing Zhao         if (std::string_view(
2054b5ca3fdcSJiaqing Zhao                 "xyz.openbmc_project.Common.Error.ResourceNotFound") ==
2055b5ca3fdcSJiaqing Zhao             dbusError->name)
2056b5ca3fdcSJiaqing Zhao         {
2057b5ca3fdcSJiaqing Zhao             messages::propertyValueNotInList(
2058b5ca3fdcSJiaqing Zhao                 asyncResp->res, parentInterfaceUri,
2059b5ca3fdcSJiaqing Zhao                 "Links/RelatedInterfaces/0/@odata.id");
2060b5ca3fdcSJiaqing Zhao             return;
2061b5ca3fdcSJiaqing Zhao         }
2062b5ca3fdcSJiaqing Zhao         if (std::string_view(
2063b5ca3fdcSJiaqing Zhao                 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
2064b5ca3fdcSJiaqing Zhao             dbusError->name)
2065b5ca3fdcSJiaqing Zhao         {
2066b5ca3fdcSJiaqing Zhao             messages::resourceAlreadyExists(asyncResp->res, "EthernetInterface",
2067b5ca3fdcSJiaqing Zhao                                             "Id", vlanInterface);
2068b5ca3fdcSJiaqing Zhao             return;
2069b5ca3fdcSJiaqing Zhao         }
2070b5ca3fdcSJiaqing Zhao         messages::internalError(asyncResp->res);
2071b5ca3fdcSJiaqing Zhao         return;
2072b5ca3fdcSJiaqing Zhao     }
2073b5ca3fdcSJiaqing Zhao 
2074253f11b8SEd Tanous     const boost::urls::url vlanInterfaceUri =
2075253f11b8SEd Tanous         boost::urls::format("/redfish/v1/Managers/{}/EthernetInterfaces/{}",
2076253f11b8SEd Tanous                             BMCWEB_REDFISH_MANAGER_URI_NAME, vlanInterface);
2077b5ca3fdcSJiaqing Zhao     asyncResp->res.addHeader("Location", vlanInterfaceUri.buffer());
2078b5ca3fdcSJiaqing Zhao }
2079b5ca3fdcSJiaqing Zhao 
2080bf648f77SEd Tanous inline void requestEthernetInterfacesRoutes(App& app)
2081bf648f77SEd Tanous {
2082253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/")
2083ed398213SEd Tanous         .privileges(redfish::privileges::getEthernetInterfaceCollection)
20841476687dSEd Tanous         .methods(boost::beast::http::verb::get)(
20851476687dSEd Tanous             [&app](const crow::Request& req,
2086253f11b8SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2087253f11b8SEd Tanous                    const std::string& managerId) {
20883ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
208945ca1b86SEd Tanous                 {
209045ca1b86SEd Tanous                     return;
209145ca1b86SEd Tanous                 }
209245ca1b86SEd Tanous 
2093253f11b8SEd Tanous                 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2094253f11b8SEd Tanous                 {
2095bd79bce8SPatrick Williams                     messages::resourceNotFound(asyncResp->res, "Manager",
2096bd79bce8SPatrick Williams                                                managerId);
2097253f11b8SEd Tanous                     return;
2098253f11b8SEd Tanous                 }
2099253f11b8SEd Tanous 
2100bf648f77SEd Tanous                 asyncResp->res.jsonValue["@odata.type"] =
2101bf648f77SEd Tanous                     "#EthernetInterfaceCollection.EthernetInterfaceCollection";
2102bd79bce8SPatrick Williams                 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2103bd79bce8SPatrick Williams                     "/redfish/v1/Managers/{}/EthernetInterfaces",
2104253f11b8SEd Tanous                     BMCWEB_REDFISH_MANAGER_URI_NAME);
2105bf648f77SEd Tanous                 asyncResp->res.jsonValue["Name"] =
2106bf648f77SEd Tanous                     "Ethernet Network Interface Collection";
2107bf648f77SEd Tanous                 asyncResp->res.jsonValue["Description"] =
2108bf648f77SEd Tanous                     "Collection of EthernetInterfaces for this Manager";
2109bf648f77SEd Tanous 
2110bf648f77SEd Tanous                 // Get eth interface list, and call the below callback for JSON
2111bf648f77SEd Tanous                 // preparation
2112002d39b4SEd Tanous                 getEthernetIfaceList(
211377179532SEd Tanous                     [asyncResp](const bool& success,
211477179532SEd Tanous                                 const std::vector<std::string>& ifaceList) {
2115bf648f77SEd Tanous                         if (!success)
21161abe55efSEd Tanous                         {
2117f12894f8SJason M. Bills                             messages::internalError(asyncResp->res);
21189391bb9cSRapkiewicz, Pawel                             return;
21199391bb9cSRapkiewicz, Pawel                         }
21209391bb9cSRapkiewicz, Pawel 
2121bd79bce8SPatrick Williams                         nlohmann::json& ifaceArray =
2122bd79bce8SPatrick Williams                             asyncResp->res.jsonValue["Members"];
2123bf648f77SEd Tanous                         ifaceArray = nlohmann::json::array();
2124bf648f77SEd Tanous                         for (const std::string& ifaceItem : ifaceList)
2125bf648f77SEd Tanous                         {
21261476687dSEd Tanous                             nlohmann::json::object_t iface;
2127ef4c65b7SEd Tanous                             iface["@odata.id"] = boost::urls::format(
2128253f11b8SEd Tanous                                 "/redfish/v1/Managers/{}/EthernetInterfaces/{}",
2129253f11b8SEd Tanous                                 BMCWEB_REDFISH_MANAGER_URI_NAME, ifaceItem);
21307857cb8dSJiaqing Zhao                             ifaceArray.push_back(std::move(iface));
2131bf648f77SEd Tanous                         }
2132bf648f77SEd Tanous 
2133bd79bce8SPatrick Williams                         asyncResp->res.jsonValue["Members@odata.count"] =
2134bd79bce8SPatrick Williams                             ifaceArray.size();
2135bd79bce8SPatrick Williams                         asyncResp->res.jsonValue["@odata.id"] =
2136bd79bce8SPatrick Williams                             boost::urls::format(
2137253f11b8SEd Tanous                                 "/redfish/v1/Managers/{}/EthernetInterfaces",
2138253f11b8SEd Tanous                                 BMCWEB_REDFISH_MANAGER_URI_NAME);
2139bf648f77SEd Tanous                     });
2140bf648f77SEd Tanous             });
2141bf648f77SEd Tanous 
2142253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/")
2143b5ca3fdcSJiaqing Zhao         .privileges(redfish::privileges::postEthernetInterfaceCollection)
2144b5ca3fdcSJiaqing Zhao         .methods(boost::beast::http::verb::post)(
2145b5ca3fdcSJiaqing Zhao             [&app](const crow::Request& req,
2146253f11b8SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2147253f11b8SEd Tanous                    const std::string& managerId) {
2148b5ca3fdcSJiaqing Zhao                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2149b5ca3fdcSJiaqing Zhao                 {
2150b5ca3fdcSJiaqing Zhao                     return;
2151b5ca3fdcSJiaqing Zhao                 }
2152b5ca3fdcSJiaqing Zhao 
2153253f11b8SEd Tanous                 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2154253f11b8SEd Tanous                 {
2155bd79bce8SPatrick Williams                     messages::resourceNotFound(asyncResp->res, "Manager",
2156bd79bce8SPatrick Williams                                                managerId);
2157253f11b8SEd Tanous                     return;
2158253f11b8SEd Tanous                 }
2159253f11b8SEd Tanous 
2160b5ca3fdcSJiaqing Zhao                 bool vlanEnable = false;
2161b5ca3fdcSJiaqing Zhao                 uint32_t vlanId = 0;
21623dfed536SEd Tanous                 std::vector<nlohmann::json::object_t> relatedInterfaces;
2163b5ca3fdcSJiaqing Zhao 
2164afc474aeSMyung Bae                 if (!json_util::readJsonPatch( //
2165afc474aeSMyung Bae                         req, asyncResp->res, //
2166afc474aeSMyung Bae                         "Links/RelatedInterfaces", relatedInterfaces, //
2167afc474aeSMyung Bae                         "VLAN/VLANEnable", vlanEnable, //
2168afc474aeSMyung Bae                         "VLAN/VLANId", vlanId //
2169afc474aeSMyung Bae                         ))
2170b5ca3fdcSJiaqing Zhao                 {
2171b5ca3fdcSJiaqing Zhao                     return;
2172b5ca3fdcSJiaqing Zhao                 }
2173b5ca3fdcSJiaqing Zhao 
2174b5ca3fdcSJiaqing Zhao                 if (relatedInterfaces.size() != 1)
2175b5ca3fdcSJiaqing Zhao                 {
2176b5ca3fdcSJiaqing Zhao                     messages::arraySizeTooLong(asyncResp->res,
2177b5ca3fdcSJiaqing Zhao                                                "Links/RelatedInterfaces",
2178b5ca3fdcSJiaqing Zhao                                                relatedInterfaces.size());
2179b5ca3fdcSJiaqing Zhao                     return;
2180b5ca3fdcSJiaqing Zhao                 }
2181b5ca3fdcSJiaqing Zhao 
2182b5ca3fdcSJiaqing Zhao                 std::string parentInterfaceUri;
2183bd79bce8SPatrick Williams                 if (!json_util::readJsonObject(relatedInterfaces[0],
2184bd79bce8SPatrick Williams                                                asyncResp->res, "@odata.id",
2185bd79bce8SPatrick Williams                                                parentInterfaceUri))
2186b5ca3fdcSJiaqing Zhao                 {
2187bd79bce8SPatrick Williams                     messages::propertyMissing(
2188bd79bce8SPatrick Williams                         asyncResp->res, "Links/RelatedInterfaces/0/@odata.id");
2189b5ca3fdcSJiaqing Zhao                     return;
2190b5ca3fdcSJiaqing Zhao                 }
219162598e31SEd Tanous                 BMCWEB_LOG_INFO("Parent Interface URI: {}", parentInterfaceUri);
2192b5ca3fdcSJiaqing Zhao 
21936fd29553SEd Tanous                 boost::system::result<boost::urls::url_view> parsedUri =
2194b5ca3fdcSJiaqing Zhao                     boost::urls::parse_relative_ref(parentInterfaceUri);
2195b5ca3fdcSJiaqing Zhao                 if (!parsedUri)
2196b5ca3fdcSJiaqing Zhao                 {
2197b5ca3fdcSJiaqing Zhao                     messages::propertyValueFormatError(
2198b5ca3fdcSJiaqing Zhao                         asyncResp->res, parentInterfaceUri,
2199b5ca3fdcSJiaqing Zhao                         "Links/RelatedInterfaces/0/@odata.id");
2200b5ca3fdcSJiaqing Zhao                     return;
2201b5ca3fdcSJiaqing Zhao                 }
2202b5ca3fdcSJiaqing Zhao 
2203b5ca3fdcSJiaqing Zhao                 std::string parentInterface;
2204b5ca3fdcSJiaqing Zhao                 if (!crow::utility::readUrlSegments(
2205b5ca3fdcSJiaqing Zhao                         *parsedUri, "redfish", "v1", "Managers", "bmc",
2206b5ca3fdcSJiaqing Zhao                         "EthernetInterfaces", std::ref(parentInterface)))
2207b5ca3fdcSJiaqing Zhao                 {
2208b5ca3fdcSJiaqing Zhao                     messages::propertyValueNotInList(
2209b5ca3fdcSJiaqing Zhao                         asyncResp->res, parentInterfaceUri,
2210b5ca3fdcSJiaqing Zhao                         "Links/RelatedInterfaces/0/@odata.id");
2211b5ca3fdcSJiaqing Zhao                     return;
2212b5ca3fdcSJiaqing Zhao                 }
2213b5ca3fdcSJiaqing Zhao 
2214b5ca3fdcSJiaqing Zhao                 if (!vlanEnable)
2215b5ca3fdcSJiaqing Zhao                 {
2216b5ca3fdcSJiaqing Zhao                     // In OpenBMC implementation, VLANEnable cannot be false on
2217b5ca3fdcSJiaqing Zhao                     // create
2218bd79bce8SPatrick Williams                     messages::propertyValueIncorrect(
2219bd79bce8SPatrick Williams                         asyncResp->res, "VLAN/VLANEnable", "false");
2220b5ca3fdcSJiaqing Zhao                     return;
2221b5ca3fdcSJiaqing Zhao                 }
2222b5ca3fdcSJiaqing Zhao 
2223bd79bce8SPatrick Williams                 std::string vlanInterface =
2224bd79bce8SPatrick Williams                     parentInterface + "_" + std::to_string(vlanId);
2225b5ca3fdcSJiaqing Zhao                 crow::connections::systemBus->async_method_call(
2226b5ca3fdcSJiaqing Zhao                     [asyncResp, parentInterfaceUri,
2227b5ca3fdcSJiaqing Zhao                      vlanInterface](const boost::system::error_code& ec,
2228b5ca3fdcSJiaqing Zhao                                     const sdbusplus::message_t& m) {
2229bd79bce8SPatrick Williams                         afterVlanCreate(asyncResp, parentInterfaceUri,
2230bd79bce8SPatrick Williams                                         vlanInterface, ec, m);
2231b5ca3fdcSJiaqing Zhao                     },
2232bd79bce8SPatrick Williams                     "xyz.openbmc_project.Network",
2233bd79bce8SPatrick Williams                     "/xyz/openbmc_project/network",
2234bd79bce8SPatrick Williams                     "xyz.openbmc_project.Network.VLAN.Create", "VLAN",
2235bd79bce8SPatrick Williams                     parentInterface, vlanId);
2236b5ca3fdcSJiaqing Zhao             });
2237b5ca3fdcSJiaqing Zhao 
2238253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
2239ed398213SEd Tanous         .privileges(redfish::privileges::getEthernetInterface)
2240bf648f77SEd Tanous         .methods(boost::beast::http::verb::get)(
224145ca1b86SEd Tanous             [&app](const crow::Request& req,
2242bf648f77SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2243253f11b8SEd Tanous                    const std::string& managerId, const std::string& ifaceId) {
22443ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
224545ca1b86SEd Tanous                 {
224645ca1b86SEd Tanous                     return;
224745ca1b86SEd Tanous                 }
2248253f11b8SEd Tanous 
2249253f11b8SEd Tanous                 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2250253f11b8SEd Tanous                 {
2251bd79bce8SPatrick Williams                     messages::resourceNotFound(asyncResp->res, "Manager",
2252bd79bce8SPatrick Williams                                                managerId);
2253253f11b8SEd Tanous                     return;
2254253f11b8SEd Tanous                 }
2255253f11b8SEd Tanous 
22564a0cb85cSEd Tanous                 getEthernetIfaceData(
2257bf648f77SEd Tanous                     ifaceId,
2258bd79bce8SPatrick Williams                     [asyncResp, ifaceId](
2259bd79bce8SPatrick Williams                         const bool& success,
2260bd79bce8SPatrick Williams                         const EthernetInterfaceData& ethData,
226177179532SEd Tanous                         const std::vector<IPv4AddressData>& ipv4Data,
2262ce73d5c8SSunitha Harish                         const std::vector<IPv6AddressData>& ipv6Data,
2263ce73d5c8SSunitha Harish                         const std::vector<StaticGatewayData>& ipv6GatewayData) {
22644a0cb85cSEd Tanous                         if (!success)
22651abe55efSEd Tanous                         {
2266bf648f77SEd Tanous                             // TODO(Pawel)consider distinguish between non
2267bf648f77SEd Tanous                             // existing object, and other errors
2268bd79bce8SPatrick Williams                             messages::resourceNotFound(
2269bd79bce8SPatrick Williams                                 asyncResp->res, "EthernetInterface", ifaceId);
22704a0cb85cSEd Tanous                             return;
22719391bb9cSRapkiewicz, Pawel                         }
22724c9afe43SEd Tanous 
22730f74e643SEd Tanous                         asyncResp->res.jsonValue["@odata.type"] =
227493bbc953SJiaqing Zhao                             "#EthernetInterface.v1_9_0.EthernetInterface";
2275bd79bce8SPatrick Williams                         asyncResp->res.jsonValue["Name"] =
2276bd79bce8SPatrick Williams                             "Manager Ethernet Interface";
22770f74e643SEd Tanous                         asyncResp->res.jsonValue["Description"] =
22780f74e643SEd Tanous                             "Management Network Interface";
22790f74e643SEd Tanous 
2280bd79bce8SPatrick Williams                         parseInterfaceData(asyncResp, ifaceId, ethData,
2281bd79bce8SPatrick Williams                                            ipv4Data, ipv6Data, ipv6GatewayData);
22829391bb9cSRapkiewicz, Pawel                     });
2283bf648f77SEd Tanous             });
22849391bb9cSRapkiewicz, Pawel 
2285253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
2286ed398213SEd Tanous         .privileges(redfish::privileges::patchEthernetInterface)
2287bf648f77SEd Tanous         .methods(boost::beast::http::verb::patch)(
228845ca1b86SEd Tanous             [&app](const crow::Request& req,
2289bf648f77SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2290253f11b8SEd Tanous                    const std::string& managerId, const std::string& ifaceId) {
22913ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
229245ca1b86SEd Tanous                 {
229345ca1b86SEd Tanous                     return;
229445ca1b86SEd Tanous                 }
2295253f11b8SEd Tanous 
2296253f11b8SEd Tanous                 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2297253f11b8SEd Tanous                 {
2298bd79bce8SPatrick Williams                     messages::resourceNotFound(asyncResp->res, "Manager",
2299bd79bce8SPatrick Williams                                                managerId);
2300253f11b8SEd Tanous                     return;
2301253f11b8SEd Tanous                 }
2302253f11b8SEd Tanous 
2303bc0bd6e0SEd Tanous                 std::optional<std::string> hostname;
2304ab6554f1SJoshi-Mansi                 std::optional<std::string> fqdn;
2305d577665bSRatan Gupta                 std::optional<std::string> macAddress;
23069a6fc6feSRavi Teja                 std::optional<std::string> ipv6DefaultGateway;
2307bd79bce8SPatrick Williams                 std::optional<std::vector<
2308bd79bce8SPatrick Williams                     std::variant<nlohmann::json::object_t, std::nullptr_t>>>
23093dfed536SEd Tanous                     ipv4StaticAddresses;
2310bd79bce8SPatrick Williams                 std::optional<std::vector<
2311bd79bce8SPatrick Williams                     std::variant<nlohmann::json::object_t, std::nullptr_t>>>
23123dfed536SEd Tanous                     ipv6StaticAddresses;
2313bd79bce8SPatrick Williams                 std::optional<std::vector<
2314bd79bce8SPatrick Williams                     std::variant<nlohmann::json::object_t, std::nullptr_t>>>
23153dfed536SEd Tanous                     ipv6StaticDefaultGateways;
2316f85837bfSRAJESWARAN THILLAIGOVINDAN                 std::optional<std::vector<std::string>> staticNameServers;
2317b10d8db0SRavi Teja                 std::optional<bool> ipv6AutoConfigEnabled;
2318eeedda23SJohnathan Mantey                 std::optional<bool> interfaceEnabled;
231935fb5311STejas Patil                 std::optional<size_t> mtuSize;
23201f8c7b5dSJohnathan Mantey                 DHCPParameters v4dhcpParms;
23211f8c7b5dSJohnathan Mantey                 DHCPParameters v6dhcpParms;
2322afc474aeSMyung Bae 
2323afc474aeSMyung Bae                 if (!json_util::readJsonPatch( //
2324afc474aeSMyung Bae                         req, asyncResp->res, //
2325afc474aeSMyung Bae                         "DHCPv4/DHCPEnabled", v4dhcpParms.dhcpv4Enabled, //
2326afc474aeSMyung Bae                         "DHCPv4/UseDNSServers", v4dhcpParms.useDnsServers, //
2327afc474aeSMyung Bae                         "DHCPv4/UseDomainName", v4dhcpParms.useDomainName, //
2328afc474aeSMyung Bae                         "DHCPv4/UseNTPServers", v4dhcpParms.useNtpServers, //
2329afc474aeSMyung Bae                         "DHCPv6/OperatingMode",
2330afc474aeSMyung Bae                         v6dhcpParms.dhcpv6OperatingMode, //
2331afc474aeSMyung Bae                         "DHCPv6/UseDNSServers", v6dhcpParms.useDnsServers, //
2332afc474aeSMyung Bae                         "DHCPv6/UseDomainName", v6dhcpParms.useDomainName, //
2333afc474aeSMyung Bae                         "DHCPv6/UseNTPServers", v6dhcpParms.useNtpServers, //
2334afc474aeSMyung Bae                         "FQDN", fqdn, //
2335afc474aeSMyung Bae                         "HostName", hostname, //
2336afc474aeSMyung Bae                         "InterfaceEnabled", interfaceEnabled, //
2337afc474aeSMyung Bae                         "IPv4StaticAddresses", ipv4StaticAddresses, //
2338afc474aeSMyung Bae                         "IPv6DefaultGateway", ipv6DefaultGateway, //
2339afc474aeSMyung Bae                         "IPv6StaticAddresses", ipv6StaticAddresses, //
2340afc474aeSMyung Bae                         "IPv6StaticDefaultGateways",
2341afc474aeSMyung Bae                         ipv6StaticDefaultGateways, //
2342afc474aeSMyung Bae                         "InterfaceEnabled", interfaceEnabled, //
2343afc474aeSMyung Bae                         "MACAddress", macAddress, //
2344afc474aeSMyung Bae                         "MTUSize", mtuSize, //
2345afc474aeSMyung Bae                         "StatelessAddressAutoConfig/IPv6AutoConfigEnabled",
2346afc474aeSMyung Bae                         ipv6AutoConfigEnabled, //
2347afc474aeSMyung Bae                         "StaticNameServers", staticNameServers //
2348afc474aeSMyung Bae                         ))
23491abe55efSEd Tanous                 {
2350588c3f0dSKowalski, Kamil                     return;
2351588c3f0dSKowalski, Kamil                 }
2352da131a9aSJennifer Lee 
2353bf648f77SEd Tanous                 // Get single eth interface data, and call the below callback
2354bf648f77SEd Tanous                 // for JSON preparation
23554a0cb85cSEd Tanous                 getEthernetIfaceData(
23562c70f800SEd Tanous                     ifaceId,
2357bf648f77SEd Tanous                     [asyncResp, ifaceId, hostname = std::move(hostname),
2358ab6554f1SJoshi-Mansi                      fqdn = std::move(fqdn), macAddress = std::move(macAddress),
2359d1d50814SRavi Teja                      ipv4StaticAddresses = std::move(ipv4StaticAddresses),
23609a6fc6feSRavi Teja                      ipv6DefaultGateway = std::move(ipv6DefaultGateway),
2361e48c0fc5SRavi Teja                      ipv6StaticAddresses = std::move(ipv6StaticAddresses),
2362bd79bce8SPatrick Williams                      ipv6StaticDefaultGateway =
2363bd79bce8SPatrick Williams                          std::move(ipv6StaticDefaultGateways),
23643dfed536SEd Tanous                      staticNameServers = std::move(staticNameServers), mtuSize,
2365bd79bce8SPatrick Williams                      ipv6AutoConfigEnabled,
2366bd79bce8SPatrick Williams                      v4dhcpParms = std::move(v4dhcpParms),
2367f23b7296SEd Tanous                      v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled](
2368bd79bce8SPatrick Williams                         const bool success,
2369bd79bce8SPatrick Williams                         const EthernetInterfaceData& ethData,
237077179532SEd Tanous                         const std::vector<IPv4AddressData>& ipv4Data,
2371ce73d5c8SSunitha Harish                         const std::vector<IPv6AddressData>& ipv6Data,
2372bd79bce8SPatrick Williams                         const std::vector<StaticGatewayData>&
2373bd79bce8SPatrick Williams                             ipv6GatewayData) mutable {
23741abe55efSEd Tanous                         if (!success)
23751abe55efSEd Tanous                         {
2376588c3f0dSKowalski, Kamil                             // ... otherwise return error
2377bf648f77SEd Tanous                             // TODO(Pawel)consider distinguish between non
2378bf648f77SEd Tanous                             // existing object, and other errors
2379bd79bce8SPatrick Williams                             messages::resourceNotFound(
2380bd79bce8SPatrick Williams                                 asyncResp->res, "EthernetInterface", ifaceId);
2381588c3f0dSKowalski, Kamil                             return;
2382588c3f0dSKowalski, Kamil                         }
2383588c3f0dSKowalski, Kamil 
2384bd79bce8SPatrick Williams                         handleDHCPPatch(ifaceId, ethData, v4dhcpParms,
2385bd79bce8SPatrick Williams                                         v6dhcpParms, asyncResp);
23861f8c7b5dSJohnathan Mantey 
23870627a2c7SEd Tanous                         if (hostname)
23881abe55efSEd Tanous                         {
23890627a2c7SEd Tanous                             handleHostnamePatch(*hostname, asyncResp);
23901abe55efSEd Tanous                         }
23910627a2c7SEd Tanous 
2392b10d8db0SRavi Teja                         if (ipv6AutoConfigEnabled)
2393b10d8db0SRavi Teja                         {
2394bd79bce8SPatrick Williams                             handleSLAACAutoConfigPatch(
2395bd79bce8SPatrick Williams                                 ifaceId, *ipv6AutoConfigEnabled, asyncResp);
2396b10d8db0SRavi Teja                         }
2397b10d8db0SRavi Teja 
2398ab6554f1SJoshi-Mansi                         if (fqdn)
2399ab6554f1SJoshi-Mansi                         {
24002c70f800SEd Tanous                             handleFqdnPatch(ifaceId, *fqdn, asyncResp);
2401ab6554f1SJoshi-Mansi                         }
2402ab6554f1SJoshi-Mansi 
2403d577665bSRatan Gupta                         if (macAddress)
2404d577665bSRatan Gupta                         {
2405bd79bce8SPatrick Williams                             handleMACAddressPatch(ifaceId, *macAddress,
2406bd79bce8SPatrick Williams                                                   asyncResp);
2407d577665bSRatan Gupta                         }
2408d577665bSRatan Gupta 
2409d1d50814SRavi Teja                         if (ipv4StaticAddresses)
2410d1d50814SRavi Teja                         {
2411bd79bce8SPatrick Williams                             handleIPv4StaticPatch(ifaceId, *ipv4StaticAddresses,
2412bd79bce8SPatrick Williams                                                   ethData, ipv4Data, asyncResp);
24131abe55efSEd Tanous                         }
24140627a2c7SEd Tanous 
2415f85837bfSRAJESWARAN THILLAIGOVINDAN                         if (staticNameServers)
2416f85837bfSRAJESWARAN THILLAIGOVINDAN                         {
2417bd79bce8SPatrick Williams                             handleStaticNameServersPatch(
2418bd79bce8SPatrick Williams                                 ifaceId, *staticNameServers, asyncResp);
2419f85837bfSRAJESWARAN THILLAIGOVINDAN                         }
24209a6fc6feSRavi Teja 
24219a6fc6feSRavi Teja                         if (ipv6DefaultGateway)
24229a6fc6feSRavi Teja                         {
24239a6fc6feSRavi Teja                             messages::propertyNotWritable(asyncResp->res,
24249a6fc6feSRavi Teja                                                           "IPv6DefaultGateway");
24259a6fc6feSRavi Teja                         }
2426e48c0fc5SRavi Teja 
2427e48c0fc5SRavi Teja                         if (ipv6StaticAddresses)
2428e48c0fc5SRavi Teja                         {
2429bd79bce8SPatrick Williams                             handleIPv6StaticAddressesPatch(ifaceId,
2430bd79bce8SPatrick Williams                                                            *ipv6StaticAddresses,
2431ddd70dcaSEd Tanous                                                            ipv6Data, asyncResp);
2432e48c0fc5SRavi Teja                         }
2433eeedda23SJohnathan Mantey 
2434ce73d5c8SSunitha Harish                         if (ipv6StaticDefaultGateway)
2435ce73d5c8SSunitha Harish                         {
2436bd79bce8SPatrick Williams                             handleIPv6DefaultGateway(
2437bd79bce8SPatrick Williams                                 ifaceId, *ipv6StaticDefaultGateway,
2438ce73d5c8SSunitha Harish                                 ipv6GatewayData, asyncResp);
2439ce73d5c8SSunitha Harish                         }
2440ce73d5c8SSunitha Harish 
2441eeedda23SJohnathan Mantey                         if (interfaceEnabled)
2442eeedda23SJohnathan Mantey                         {
2443bd79bce8SPatrick Williams                             setDbusProperty(
2444bd79bce8SPatrick Williams                                 asyncResp, "InterfaceEnabled",
2445e93abac6SGinu George                                 "xyz.openbmc_project.Network",
2446d02aad39SEd Tanous                                 sdbusplus::message::object_path(
2447d02aad39SEd Tanous                                     "/xyz/openbmc_project/network") /
2448d02aad39SEd Tanous                                     ifaceId,
2449d02aad39SEd Tanous                                 "xyz.openbmc_project.Network.EthernetInterface",
2450e93abac6SGinu George                                 "NICEnabled", *interfaceEnabled);
2451eeedda23SJohnathan Mantey                         }
245235fb5311STejas Patil 
245335fb5311STejas Patil                         if (mtuSize)
245435fb5311STejas Patil                         {
245535fb5311STejas Patil                             handleMTUSizePatch(ifaceId, *mtuSize, asyncResp);
245635fb5311STejas Patil                         }
2457588c3f0dSKowalski, Kamil                     });
2458bf648f77SEd Tanous             });
2459e7caf250SJiaqing Zhao 
2460253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/EthernetInterfaces/<str>/")
2461e7caf250SJiaqing Zhao         .privileges(redfish::privileges::deleteEthernetInterface)
2462e7caf250SJiaqing Zhao         .methods(boost::beast::http::verb::delete_)(
2463e7caf250SJiaqing Zhao             [&app](const crow::Request& req,
2464e7caf250SJiaqing Zhao                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2465253f11b8SEd Tanous                    const std::string& managerId, const std::string& ifaceId) {
2466e7caf250SJiaqing Zhao                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2467e7caf250SJiaqing Zhao                 {
2468e7caf250SJiaqing Zhao                     return;
2469e7caf250SJiaqing Zhao                 }
2470e7caf250SJiaqing Zhao 
2471253f11b8SEd Tanous                 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
2472253f11b8SEd Tanous                 {
2473bd79bce8SPatrick Williams                     messages::resourceNotFound(asyncResp->res, "Manager",
2474bd79bce8SPatrick Williams                                                managerId);
2475253f11b8SEd Tanous                     return;
2476253f11b8SEd Tanous                 }
2477253f11b8SEd Tanous 
2478e7caf250SJiaqing Zhao                 crow::connections::systemBus->async_method_call(
2479e7caf250SJiaqing Zhao                     [asyncResp, ifaceId](const boost::system::error_code& ec,
2480e7caf250SJiaqing Zhao                                          const sdbusplus::message_t& m) {
2481e7caf250SJiaqing Zhao                         afterDelete(asyncResp, ifaceId, ec, m);
2482e7caf250SJiaqing Zhao                     },
2483e7caf250SJiaqing Zhao                     "xyz.openbmc_project.Network",
2484e7caf250SJiaqing Zhao                     std::string("/xyz/openbmc_project/network/") + ifaceId,
2485e7caf250SJiaqing Zhao                     "xyz.openbmc_project.Object.Delete", "Delete");
2486e7caf250SJiaqing Zhao             });
24874a0cb85cSEd Tanous }
2488bf648f77SEd Tanous 
24899391bb9cSRapkiewicz, Pawel } // namespace redfish
2490