xref: /openbmc/bmcweb/features/redfish/lib/ethernet.hpp (revision 9010ec2e1dd5f8ad5edb61281b45019f2ea02eaa)
19391bb9cSRapkiewicz, Pawel /*
29391bb9cSRapkiewicz, Pawel // Copyright (c) 2018 Intel Corporation
39391bb9cSRapkiewicz, Pawel //
49391bb9cSRapkiewicz, Pawel // Licensed under the Apache License, Version 2.0 (the "License");
59391bb9cSRapkiewicz, Pawel // you may not use this file except in compliance with the License.
69391bb9cSRapkiewicz, Pawel // You may obtain a copy of the License at
79391bb9cSRapkiewicz, Pawel //
89391bb9cSRapkiewicz, Pawel //      http://www.apache.org/licenses/LICENSE-2.0
99391bb9cSRapkiewicz, Pawel //
109391bb9cSRapkiewicz, Pawel // Unless required by applicable law or agreed to in writing, software
119391bb9cSRapkiewicz, Pawel // distributed under the License is distributed on an "AS IS" BASIS,
129391bb9cSRapkiewicz, Pawel // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139391bb9cSRapkiewicz, Pawel // See the License for the specific language governing permissions and
149391bb9cSRapkiewicz, Pawel // limitations under the License.
159391bb9cSRapkiewicz, Pawel */
169391bb9cSRapkiewicz, Pawel #pragma once
179391bb9cSRapkiewicz, Pawel 
181abe55efSEd Tanous #include <boost/container/flat_map.hpp>
194a0cb85cSEd Tanous #include <boost/container/flat_set.hpp>
20179db1d7SKowalski, Kamil #include <dbus_singleton.hpp>
21588c3f0dSKowalski, Kamil #include <error_messages.hpp>
22179db1d7SKowalski, Kamil #include <node.hpp>
231214b7e7SGunnar Mills #include <utils/json_utils.hpp>
241214b7e7SGunnar Mills 
25a24526dcSEd Tanous #include <optional>
26ab6554f1SJoshi-Mansi #include <regex>
27abf2add6SEd Tanous #include <variant>
289391bb9cSRapkiewicz, Pawel 
291abe55efSEd Tanous namespace redfish
301abe55efSEd Tanous {
319391bb9cSRapkiewicz, Pawel 
329391bb9cSRapkiewicz, Pawel /**
339391bb9cSRapkiewicz, Pawel  * DBus types primitives for several generic DBus interfaces
349391bb9cSRapkiewicz, Pawel  * TODO(Pawel) consider move this to separate file into boost::dbus
359391bb9cSRapkiewicz, Pawel  */
36aa2e59c1SEd Tanous using PropertiesMapType = boost::container::flat_map<
37abf2add6SEd Tanous     std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t,
38aa2e59c1SEd Tanous                               int32_t, uint32_t, int64_t, uint64_t, double>>;
399391bb9cSRapkiewicz, Pawel 
404a0cb85cSEd Tanous using GetManagedObjects = std::vector<std::pair<
41aa2e59c1SEd Tanous     sdbusplus::message::object_path,
424a0cb85cSEd Tanous     std::vector<std::pair<
43aa2e59c1SEd Tanous         std::string,
44aa2e59c1SEd Tanous         boost::container::flat_map<
4519bd78d9SPatrick Williams             std::string,
4619bd78d9SPatrick Williams             std::variant<std::string, bool, uint8_t, int16_t, uint16_t, int32_t,
4719bd78d9SPatrick Williams                          uint32_t, int64_t, uint64_t, double,
48029573d4SEd Tanous                          std::vector<std::string>>>>>>>;
494a0cb85cSEd Tanous 
504a0cb85cSEd Tanous enum class LinkType
514a0cb85cSEd Tanous {
524a0cb85cSEd Tanous     Local,
534a0cb85cSEd Tanous     Global
544a0cb85cSEd Tanous };
559391bb9cSRapkiewicz, Pawel 
569391bb9cSRapkiewicz, Pawel /**
579391bb9cSRapkiewicz, Pawel  * Structure for keeping IPv4 data required by Redfish
589391bb9cSRapkiewicz, Pawel  */
591abe55efSEd Tanous struct IPv4AddressData
601abe55efSEd Tanous {
61179db1d7SKowalski, Kamil     std::string id;
624a0cb85cSEd Tanous     std::string address;
634a0cb85cSEd Tanous     std::string domain;
644a0cb85cSEd Tanous     std::string gateway;
659391bb9cSRapkiewicz, Pawel     std::string netmask;
669391bb9cSRapkiewicz, Pawel     std::string origin;
674a0cb85cSEd Tanous     LinkType linktype;
6801c6e858SSunitha Harish     bool isActive;
694a0cb85cSEd Tanous 
701abe55efSEd Tanous     bool operator<(const IPv4AddressData& obj) const
711abe55efSEd Tanous     {
724a0cb85cSEd Tanous         return id < obj.id;
731abe55efSEd Tanous     }
749391bb9cSRapkiewicz, Pawel };
759391bb9cSRapkiewicz, Pawel 
769391bb9cSRapkiewicz, Pawel /**
77e48c0fc5SRavi Teja  * Structure for keeping IPv6 data required by Redfish
78e48c0fc5SRavi Teja  */
79e48c0fc5SRavi Teja struct IPv6AddressData
80e48c0fc5SRavi Teja {
81e48c0fc5SRavi Teja     std::string id;
82e48c0fc5SRavi Teja     std::string address;
83e48c0fc5SRavi Teja     std::string origin;
84e48c0fc5SRavi Teja     uint8_t prefixLength;
85e48c0fc5SRavi Teja 
86e48c0fc5SRavi Teja     bool operator<(const IPv6AddressData& obj) const
87e48c0fc5SRavi Teja     {
88e48c0fc5SRavi Teja         return id < obj.id;
89e48c0fc5SRavi Teja     }
90e48c0fc5SRavi Teja };
91e48c0fc5SRavi Teja /**
929391bb9cSRapkiewicz, Pawel  * Structure for keeping basic single Ethernet Interface information
939391bb9cSRapkiewicz, Pawel  * available from DBus
949391bb9cSRapkiewicz, Pawel  */
951abe55efSEd Tanous struct EthernetInterfaceData
961abe55efSEd Tanous {
974a0cb85cSEd Tanous     uint32_t speed;
984a0cb85cSEd Tanous     bool auto_neg;
991f8c7b5dSJohnathan Mantey     bool DNSEnabled;
1001f8c7b5dSJohnathan Mantey     bool NTPEnabled;
1011f8c7b5dSJohnathan Mantey     bool HostNameEnabled;
1021f8c7b5dSJohnathan Mantey     bool SendHostNameEnabled;
103aa05fb27SJohnathan Mantey     bool linkUp;
104eeedda23SJohnathan Mantey     bool nicEnabled;
1051f8c7b5dSJohnathan Mantey     std::string DHCPEnabled;
1061f8c7b5dSJohnathan Mantey     std::string operatingMode;
1074a0cb85cSEd Tanous     std::string hostname;
1084a0cb85cSEd Tanous     std::string default_gateway;
1099a6fc6feSRavi Teja     std::string ipv6_default_gateway;
1104a0cb85cSEd Tanous     std::string mac_address;
111fda13ad2SSunitha Harish     std::vector<std::uint32_t> vlan_id;
1120f6efdc1Smanojkiran.eda@gmail.com     std::vector<std::string> nameServers;
1130f6efdc1Smanojkiran.eda@gmail.com     std::vector<std::string> staticNameServers;
114d24bfc7aSJennifer Lee     std::vector<std::string> domainnames;
1159391bb9cSRapkiewicz, Pawel };
1169391bb9cSRapkiewicz, Pawel 
1171f8c7b5dSJohnathan Mantey struct DHCPParameters
1181f8c7b5dSJohnathan Mantey {
1191f8c7b5dSJohnathan Mantey     std::optional<bool> dhcpv4Enabled;
1201f8c7b5dSJohnathan Mantey     std::optional<bool> useDNSServers;
1211f8c7b5dSJohnathan Mantey     std::optional<bool> useNTPServers;
1221f8c7b5dSJohnathan Mantey     std::optional<bool> useUseDomainName;
1231f8c7b5dSJohnathan Mantey     std::optional<std::string> dhcpv6OperatingMode;
1241f8c7b5dSJohnathan Mantey };
1251f8c7b5dSJohnathan Mantey 
1269391bb9cSRapkiewicz, Pawel // Helper function that changes bits netmask notation (i.e. /24)
1279391bb9cSRapkiewicz, Pawel // into full dot notation
1281abe55efSEd Tanous inline std::string getNetmask(unsigned int bits)
1291abe55efSEd Tanous {
1309391bb9cSRapkiewicz, Pawel     uint32_t value = 0xffffffff << (32 - bits);
1319391bb9cSRapkiewicz, Pawel     std::string netmask = std::to_string((value >> 24) & 0xff) + "." +
1329391bb9cSRapkiewicz, Pawel                           std::to_string((value >> 16) & 0xff) + "." +
1339391bb9cSRapkiewicz, Pawel                           std::to_string((value >> 8) & 0xff) + "." +
1349391bb9cSRapkiewicz, Pawel                           std::to_string(value & 0xff);
1359391bb9cSRapkiewicz, Pawel     return netmask;
1369391bb9cSRapkiewicz, Pawel }
1379391bb9cSRapkiewicz, Pawel 
1381f8c7b5dSJohnathan Mantey inline bool translateDHCPEnabledToBool(const std::string& inputDHCP,
1391f8c7b5dSJohnathan Mantey                                        bool isIPv4)
1401f8c7b5dSJohnathan Mantey {
1411f8c7b5dSJohnathan Mantey     if (isIPv4)
1421f8c7b5dSJohnathan Mantey     {
1431f8c7b5dSJohnathan Mantey         return (
1441f8c7b5dSJohnathan Mantey             (inputDHCP ==
1451f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4") ||
1461f8c7b5dSJohnathan Mantey             (inputDHCP ==
1471f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
1481f8c7b5dSJohnathan Mantey     }
1491f8c7b5dSJohnathan Mantey     return ((inputDHCP ==
1501f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") ||
1511f8c7b5dSJohnathan Mantey             (inputDHCP ==
1521f8c7b5dSJohnathan Mantey              "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"));
1531f8c7b5dSJohnathan Mantey }
1541f8c7b5dSJohnathan Mantey 
1552c70f800SEd Tanous inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6)
1561f8c7b5dSJohnathan Mantey {
1571f8c7b5dSJohnathan Mantey     if (isIPv4 && isIPv6)
1581f8c7b5dSJohnathan Mantey     {
1591f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both";
1601f8c7b5dSJohnathan Mantey     }
1613174e4dfSEd Tanous     if (isIPv4)
1621f8c7b5dSJohnathan Mantey     {
1631f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4";
1641f8c7b5dSJohnathan Mantey     }
1653174e4dfSEd Tanous     if (isIPv6)
1661f8c7b5dSJohnathan Mantey     {
1671f8c7b5dSJohnathan Mantey         return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6";
1681f8c7b5dSJohnathan Mantey     }
1691f8c7b5dSJohnathan Mantey     return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none";
1701f8c7b5dSJohnathan Mantey }
1711f8c7b5dSJohnathan Mantey 
1724a0cb85cSEd Tanous inline std::string
1734a0cb85cSEd Tanous     translateAddressOriginDbusToRedfish(const std::string& inputOrigin,
1744a0cb85cSEd Tanous                                         bool isIPv4)
1751abe55efSEd Tanous {
1764a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static")
1771abe55efSEd Tanous     {
1784a0cb85cSEd Tanous         return "Static";
1799391bb9cSRapkiewicz, Pawel     }
1804a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal")
1811abe55efSEd Tanous     {
1824a0cb85cSEd Tanous         if (isIPv4)
1831abe55efSEd Tanous         {
1844a0cb85cSEd Tanous             return "IPv4LinkLocal";
1851abe55efSEd Tanous         }
1864a0cb85cSEd Tanous         return "LinkLocal";
1879391bb9cSRapkiewicz, Pawel     }
1884a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
1891abe55efSEd Tanous     {
1904a0cb85cSEd Tanous         if (isIPv4)
1914a0cb85cSEd Tanous         {
1924a0cb85cSEd Tanous             return "DHCP";
1934a0cb85cSEd Tanous         }
1944a0cb85cSEd Tanous         return "DHCPv6";
1954a0cb85cSEd Tanous     }
1964a0cb85cSEd Tanous     if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC")
1974a0cb85cSEd Tanous     {
1984a0cb85cSEd Tanous         return "SLAAC";
1994a0cb85cSEd Tanous     }
2004a0cb85cSEd Tanous     return "";
2014a0cb85cSEd Tanous }
2024a0cb85cSEd Tanous 
20381ce609eSEd Tanous inline bool extractEthernetInterfaceData(const std::string& ethifaceId,
20481ce609eSEd Tanous                                          GetManagedObjects& dbusData,
2054a0cb85cSEd Tanous                                          EthernetInterfaceData& ethData)
2064a0cb85cSEd Tanous {
2074c9afe43SEd Tanous     bool idFound = false;
20881ce609eSEd Tanous     for (auto& objpath : dbusData)
2094a0cb85cSEd Tanous     {
210f23b7296SEd Tanous         for (auto& ifacePair : objpath.second)
2114a0cb85cSEd Tanous         {
21281ce609eSEd Tanous             if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId)
213029573d4SEd Tanous             {
2144c9afe43SEd Tanous                 idFound = true;
2154a0cb85cSEd Tanous                 if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress")
2164a0cb85cSEd Tanous                 {
2174a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2184a0cb85cSEd Tanous                     {
2194a0cb85cSEd Tanous                         if (propertyPair.first == "MACAddress")
2204a0cb85cSEd Tanous                         {
2214a0cb85cSEd Tanous                             const std::string* mac =
222abf2add6SEd Tanous                                 std::get_if<std::string>(&propertyPair.second);
2234a0cb85cSEd Tanous                             if (mac != nullptr)
2244a0cb85cSEd Tanous                             {
2254a0cb85cSEd Tanous                                 ethData.mac_address = *mac;
2264a0cb85cSEd Tanous                             }
2274a0cb85cSEd Tanous                         }
2284a0cb85cSEd Tanous                     }
2294a0cb85cSEd Tanous                 }
2304a0cb85cSEd Tanous                 else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN")
2314a0cb85cSEd Tanous                 {
2324a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2334a0cb85cSEd Tanous                     {
2344a0cb85cSEd Tanous                         if (propertyPair.first == "Id")
2354a0cb85cSEd Tanous                         {
2361b6b96c5SEd Tanous                             const uint32_t* id =
237abf2add6SEd Tanous                                 std::get_if<uint32_t>(&propertyPair.second);
2384a0cb85cSEd Tanous                             if (id != nullptr)
2394a0cb85cSEd Tanous                             {
240fda13ad2SSunitha Harish                                 ethData.vlan_id.push_back(*id);
2414a0cb85cSEd Tanous                             }
2424a0cb85cSEd Tanous                         }
2434a0cb85cSEd Tanous                     }
2444a0cb85cSEd Tanous                 }
2454a0cb85cSEd Tanous                 else if (ifacePair.first ==
2464a0cb85cSEd Tanous                          "xyz.openbmc_project.Network.EthernetInterface")
2474a0cb85cSEd Tanous                 {
2484a0cb85cSEd Tanous                     for (const auto& propertyPair : ifacePair.second)
2494a0cb85cSEd Tanous                     {
2504a0cb85cSEd Tanous                         if (propertyPair.first == "AutoNeg")
2514a0cb85cSEd Tanous                         {
2522c70f800SEd Tanous                             const bool* autoNeg =
253abf2add6SEd Tanous                                 std::get_if<bool>(&propertyPair.second);
2542c70f800SEd Tanous                             if (autoNeg != nullptr)
2554a0cb85cSEd Tanous                             {
2562c70f800SEd Tanous                                 ethData.auto_neg = *autoNeg;
2574a0cb85cSEd Tanous                             }
2584a0cb85cSEd Tanous                         }
2594a0cb85cSEd Tanous                         else if (propertyPair.first == "Speed")
2604a0cb85cSEd Tanous                         {
2614a0cb85cSEd Tanous                             const uint32_t* speed =
262abf2add6SEd Tanous                                 std::get_if<uint32_t>(&propertyPair.second);
2634a0cb85cSEd Tanous                             if (speed != nullptr)
2644a0cb85cSEd Tanous                             {
2654a0cb85cSEd Tanous                                 ethData.speed = *speed;
2664a0cb85cSEd Tanous                             }
2674a0cb85cSEd Tanous                         }
268aa05fb27SJohnathan Mantey                         else if (propertyPair.first == "LinkUp")
269aa05fb27SJohnathan Mantey                         {
270aa05fb27SJohnathan Mantey                             const bool* linkUp =
271aa05fb27SJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
272aa05fb27SJohnathan Mantey                             if (linkUp != nullptr)
273aa05fb27SJohnathan Mantey                             {
274aa05fb27SJohnathan Mantey                                 ethData.linkUp = *linkUp;
275aa05fb27SJohnathan Mantey                             }
276aa05fb27SJohnathan Mantey                         }
277eeedda23SJohnathan Mantey                         else if (propertyPair.first == "NICEnabled")
278eeedda23SJohnathan Mantey                         {
279eeedda23SJohnathan Mantey                             const bool* nicEnabled =
280eeedda23SJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
281eeedda23SJohnathan Mantey                             if (nicEnabled != nullptr)
282eeedda23SJohnathan Mantey                             {
283eeedda23SJohnathan Mantey                                 ethData.nicEnabled = *nicEnabled;
284eeedda23SJohnathan Mantey                             }
285eeedda23SJohnathan Mantey                         }
286f85837bfSRAJESWARAN THILLAIGOVINDAN                         else if (propertyPair.first == "Nameservers")
287029573d4SEd Tanous                         {
288029573d4SEd Tanous                             const std::vector<std::string>* nameservers =
2898d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
290029573d4SEd Tanous                                     &propertyPair.second);
291029573d4SEd Tanous                             if (nameservers != nullptr)
292029573d4SEd Tanous                             {
293f23b7296SEd Tanous                                 ethData.nameServers = *nameservers;
2940f6efdc1Smanojkiran.eda@gmail.com                             }
2950f6efdc1Smanojkiran.eda@gmail.com                         }
2960f6efdc1Smanojkiran.eda@gmail.com                         else if (propertyPair.first == "StaticNameServers")
2970f6efdc1Smanojkiran.eda@gmail.com                         {
2980f6efdc1Smanojkiran.eda@gmail.com                             const std::vector<std::string>* staticNameServers =
2998d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
3000f6efdc1Smanojkiran.eda@gmail.com                                     &propertyPair.second);
3010f6efdc1Smanojkiran.eda@gmail.com                             if (staticNameServers != nullptr)
3020f6efdc1Smanojkiran.eda@gmail.com                             {
303f23b7296SEd Tanous                                 ethData.staticNameServers = *staticNameServers;
3044a0cb85cSEd Tanous                             }
3054a0cb85cSEd Tanous                         }
3062a133282Smanojkiraneda                         else if (propertyPair.first == "DHCPEnabled")
3072a133282Smanojkiraneda                         {
3082c70f800SEd Tanous                             const std::string* dhcpEnabled =
3091f8c7b5dSJohnathan Mantey                                 std::get_if<std::string>(&propertyPair.second);
3102c70f800SEd Tanous                             if (dhcpEnabled != nullptr)
3112a133282Smanojkiraneda                             {
3122c70f800SEd Tanous                                 ethData.DHCPEnabled = *dhcpEnabled;
3132a133282Smanojkiraneda                             }
3142a133282Smanojkiraneda                         }
315d24bfc7aSJennifer Lee                         else if (propertyPair.first == "DomainName")
316d24bfc7aSJennifer Lee                         {
317d24bfc7aSJennifer Lee                             const std::vector<std::string>* domainNames =
3188d78b7a9SPatrick Williams                                 std::get_if<std::vector<std::string>>(
319d24bfc7aSJennifer Lee                                     &propertyPair.second);
320d24bfc7aSJennifer Lee                             if (domainNames != nullptr)
321d24bfc7aSJennifer Lee                             {
322f23b7296SEd Tanous                                 ethData.domainnames = *domainNames;
323d24bfc7aSJennifer Lee                             }
324d24bfc7aSJennifer Lee                         }
325*9010ec2eSRavi Teja                         else if (propertyPair.first == "DefaultGateway")
326*9010ec2eSRavi Teja                         {
327*9010ec2eSRavi Teja                             const std::string* defaultGateway =
328*9010ec2eSRavi Teja                                 std::get_if<std::string>(&propertyPair.second);
329*9010ec2eSRavi Teja                             if (defaultGateway != nullptr)
330*9010ec2eSRavi Teja                             {
331*9010ec2eSRavi Teja                                 std::string defaultGatewayStr = *defaultGateway;
332*9010ec2eSRavi Teja                                 if (defaultGatewayStr.empty())
333*9010ec2eSRavi Teja                                 {
334*9010ec2eSRavi Teja                                     ethData.default_gateway = "0.0.0.0";
335*9010ec2eSRavi Teja                                 }
336*9010ec2eSRavi Teja                                 else
337*9010ec2eSRavi Teja                                 {
338*9010ec2eSRavi Teja                                     ethData.default_gateway = defaultGatewayStr;
339*9010ec2eSRavi Teja                                 }
340*9010ec2eSRavi Teja                             }
341*9010ec2eSRavi Teja                         }
342*9010ec2eSRavi Teja                         else if (propertyPair.first == "DefaultGateway6")
343*9010ec2eSRavi Teja                         {
344*9010ec2eSRavi Teja                             const std::string* defaultGateway6 =
345*9010ec2eSRavi Teja                                 std::get_if<std::string>(&propertyPair.second);
346*9010ec2eSRavi Teja                             if (defaultGateway6 != nullptr)
347*9010ec2eSRavi Teja                             {
348*9010ec2eSRavi Teja                                 std::string defaultGateway6Str =
349*9010ec2eSRavi Teja                                     *defaultGateway6;
350*9010ec2eSRavi Teja                                 if (defaultGateway6Str.empty())
351*9010ec2eSRavi Teja                                 {
352*9010ec2eSRavi Teja                                     ethData.ipv6_default_gateway =
353*9010ec2eSRavi Teja                                         "0:0:0:0:0:0:0:0";
354*9010ec2eSRavi Teja                                 }
355*9010ec2eSRavi Teja                                 else
356*9010ec2eSRavi Teja                                 {
357*9010ec2eSRavi Teja                                     ethData.ipv6_default_gateway =
358*9010ec2eSRavi Teja                                         defaultGateway6Str;
359*9010ec2eSRavi Teja                                 }
360*9010ec2eSRavi Teja                             }
361*9010ec2eSRavi Teja                         }
362029573d4SEd Tanous                     }
363029573d4SEd Tanous                 }
364029573d4SEd Tanous             }
3651f8c7b5dSJohnathan Mantey 
3661f8c7b5dSJohnathan Mantey             if (objpath.first == "/xyz/openbmc_project/network/config/dhcp")
3671f8c7b5dSJohnathan Mantey             {
3681f8c7b5dSJohnathan Mantey                 if (ifacePair.first ==
3691f8c7b5dSJohnathan Mantey                     "xyz.openbmc_project.Network.DHCPConfiguration")
3701f8c7b5dSJohnathan Mantey                 {
3711f8c7b5dSJohnathan Mantey                     for (const auto& propertyPair : ifacePair.second)
3721f8c7b5dSJohnathan Mantey                     {
3731f8c7b5dSJohnathan Mantey                         if (propertyPair.first == "DNSEnabled")
3741f8c7b5dSJohnathan Mantey                         {
3752c70f800SEd Tanous                             const bool* dnsEnabled =
3761f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
3772c70f800SEd Tanous                             if (dnsEnabled != nullptr)
3781f8c7b5dSJohnathan Mantey                             {
3792c70f800SEd Tanous                                 ethData.DNSEnabled = *dnsEnabled;
3801f8c7b5dSJohnathan Mantey                             }
3811f8c7b5dSJohnathan Mantey                         }
3821f8c7b5dSJohnathan Mantey                         else if (propertyPair.first == "NTPEnabled")
3831f8c7b5dSJohnathan Mantey                         {
3842c70f800SEd Tanous                             const bool* ntpEnabled =
3851f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
3862c70f800SEd Tanous                             if (ntpEnabled != nullptr)
3871f8c7b5dSJohnathan Mantey                             {
3882c70f800SEd Tanous                                 ethData.NTPEnabled = *ntpEnabled;
3891f8c7b5dSJohnathan Mantey                             }
3901f8c7b5dSJohnathan Mantey                         }
3911f8c7b5dSJohnathan Mantey                         else if (propertyPair.first == "HostNameEnabled")
3921f8c7b5dSJohnathan Mantey                         {
3932c70f800SEd Tanous                             const bool* hostNameEnabled =
3941f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
3952c70f800SEd Tanous                             if (hostNameEnabled != nullptr)
3961f8c7b5dSJohnathan Mantey                             {
3972c70f800SEd Tanous                                 ethData.HostNameEnabled = *hostNameEnabled;
3981f8c7b5dSJohnathan Mantey                             }
3991f8c7b5dSJohnathan Mantey                         }
4001f8c7b5dSJohnathan Mantey                         else if (propertyPair.first == "SendHostNameEnabled")
4011f8c7b5dSJohnathan Mantey                         {
4022c70f800SEd Tanous                             const bool* sendHostNameEnabled =
4031f8c7b5dSJohnathan Mantey                                 std::get_if<bool>(&propertyPair.second);
4042c70f800SEd Tanous                             if (sendHostNameEnabled != nullptr)
4051f8c7b5dSJohnathan Mantey                             {
4061f8c7b5dSJohnathan Mantey                                 ethData.SendHostNameEnabled =
4072c70f800SEd Tanous                                     *sendHostNameEnabled;
4081f8c7b5dSJohnathan Mantey                             }
4091f8c7b5dSJohnathan Mantey                         }
4101f8c7b5dSJohnathan Mantey                     }
4111f8c7b5dSJohnathan Mantey                 }
4121f8c7b5dSJohnathan Mantey             }
413029573d4SEd Tanous             // System configuration shows up in the global namespace, so no need
414029573d4SEd Tanous             // to check eth number
415029573d4SEd Tanous             if (ifacePair.first ==
4164a0cb85cSEd Tanous                 "xyz.openbmc_project.Network.SystemConfiguration")
4174a0cb85cSEd Tanous             {
4184a0cb85cSEd Tanous                 for (const auto& propertyPair : ifacePair.second)
4194a0cb85cSEd Tanous                 {
4204a0cb85cSEd Tanous                     if (propertyPair.first == "HostName")
4214a0cb85cSEd Tanous                     {
4224a0cb85cSEd Tanous                         const std::string* hostname =
4238d78b7a9SPatrick Williams                             std::get_if<std::string>(&propertyPair.second);
4244a0cb85cSEd Tanous                         if (hostname != nullptr)
4254a0cb85cSEd Tanous                         {
4264a0cb85cSEd Tanous                             ethData.hostname = *hostname;
4274a0cb85cSEd Tanous                         }
4284a0cb85cSEd Tanous                     }
4294a0cb85cSEd Tanous                 }
4304a0cb85cSEd Tanous             }
4314a0cb85cSEd Tanous         }
4324a0cb85cSEd Tanous     }
4334c9afe43SEd Tanous     return idFound;
4344a0cb85cSEd Tanous }
4354a0cb85cSEd Tanous 
436e48c0fc5SRavi Teja // Helper function that extracts data for single ethernet ipv6 address
43701784826SJohnathan Mantey inline void
43881ce609eSEd Tanous     extractIPV6Data(const std::string& ethifaceId,
43981ce609eSEd Tanous                     const GetManagedObjects& dbusData,
44081ce609eSEd Tanous                     boost::container::flat_set<IPv6AddressData>& ipv6Config)
441e48c0fc5SRavi Teja {
442e48c0fc5SRavi Teja     const std::string ipv6PathStart =
44381ce609eSEd Tanous         "/xyz/openbmc_project/network/" + ethifaceId + "/ipv6/";
444e48c0fc5SRavi Teja 
445e48c0fc5SRavi Teja     // Since there might be several IPv6 configurations aligned with
446e48c0fc5SRavi Teja     // single ethernet interface, loop over all of them
44781ce609eSEd Tanous     for (const auto& objpath : dbusData)
448e48c0fc5SRavi Teja     {
449e48c0fc5SRavi Teja         // Check if proper pattern for object path appears
450e48c0fc5SRavi Teja         if (boost::starts_with(objpath.first.str, ipv6PathStart))
451e48c0fc5SRavi Teja         {
452e48c0fc5SRavi Teja             for (auto& interface : objpath.second)
453e48c0fc5SRavi Teja             {
454e48c0fc5SRavi Teja                 if (interface.first == "xyz.openbmc_project.Network.IP")
455e48c0fc5SRavi Teja                 {
456e48c0fc5SRavi Teja                     // Instance IPv6AddressData structure, and set as
457e48c0fc5SRavi Teja                     // appropriate
458e48c0fc5SRavi Teja                     std::pair<
459e48c0fc5SRavi Teja                         boost::container::flat_set<IPv6AddressData>::iterator,
460e48c0fc5SRavi Teja                         bool>
46181ce609eSEd Tanous                         it = ipv6Config.insert(IPv6AddressData{});
4622c70f800SEd Tanous                     IPv6AddressData& ipv6Address = *it.first;
4632c70f800SEd Tanous                     ipv6Address.id =
464271584abSEd Tanous                         objpath.first.str.substr(ipv6PathStart.size());
465e48c0fc5SRavi Teja                     for (auto& property : interface.second)
466e48c0fc5SRavi Teja                     {
467e48c0fc5SRavi Teja                         if (property.first == "Address")
468e48c0fc5SRavi Teja                         {
469e48c0fc5SRavi Teja                             const std::string* address =
470e48c0fc5SRavi Teja                                 std::get_if<std::string>(&property.second);
471e48c0fc5SRavi Teja                             if (address != nullptr)
472e48c0fc5SRavi Teja                             {
4732c70f800SEd Tanous                                 ipv6Address.address = *address;
474e48c0fc5SRavi Teja                             }
475e48c0fc5SRavi Teja                         }
476e48c0fc5SRavi Teja                         else if (property.first == "Origin")
477e48c0fc5SRavi Teja                         {
478e48c0fc5SRavi Teja                             const std::string* origin =
479e48c0fc5SRavi Teja                                 std::get_if<std::string>(&property.second);
480e48c0fc5SRavi Teja                             if (origin != nullptr)
481e48c0fc5SRavi Teja                             {
4822c70f800SEd Tanous                                 ipv6Address.origin =
483e48c0fc5SRavi Teja                                     translateAddressOriginDbusToRedfish(*origin,
484e48c0fc5SRavi Teja                                                                         false);
485e48c0fc5SRavi Teja                             }
486e48c0fc5SRavi Teja                         }
487e48c0fc5SRavi Teja                         else if (property.first == "PrefixLength")
488e48c0fc5SRavi Teja                         {
489e48c0fc5SRavi Teja                             const uint8_t* prefix =
490e48c0fc5SRavi Teja                                 std::get_if<uint8_t>(&property.second);
491e48c0fc5SRavi Teja                             if (prefix != nullptr)
492e48c0fc5SRavi Teja                             {
4932c70f800SEd Tanous                                 ipv6Address.prefixLength = *prefix;
494e48c0fc5SRavi Teja                             }
495e48c0fc5SRavi Teja                         }
496e48c0fc5SRavi Teja                         else
497e48c0fc5SRavi Teja                         {
498e48c0fc5SRavi Teja                             BMCWEB_LOG_ERROR
499e48c0fc5SRavi Teja                                 << "Got extra property: " << property.first
500e48c0fc5SRavi Teja                                 << " on the " << objpath.first.str << " object";
501e48c0fc5SRavi Teja                         }
502e48c0fc5SRavi Teja                     }
503e48c0fc5SRavi Teja                 }
504e48c0fc5SRavi Teja             }
505e48c0fc5SRavi Teja         }
506e48c0fc5SRavi Teja     }
507e48c0fc5SRavi Teja }
508e48c0fc5SRavi Teja 
5094a0cb85cSEd Tanous // Helper function that extracts data for single ethernet ipv4 address
51001784826SJohnathan Mantey inline void
51181ce609eSEd Tanous     extractIPData(const std::string& ethifaceId,
51281ce609eSEd Tanous                   const GetManagedObjects& dbusData,
51381ce609eSEd Tanous                   boost::container::flat_set<IPv4AddressData>& ipv4Config)
5144a0cb85cSEd Tanous {
5154a0cb85cSEd Tanous     const std::string ipv4PathStart =
51681ce609eSEd Tanous         "/xyz/openbmc_project/network/" + ethifaceId + "/ipv4/";
5174a0cb85cSEd Tanous 
5184a0cb85cSEd Tanous     // Since there might be several IPv4 configurations aligned with
5194a0cb85cSEd Tanous     // single ethernet interface, loop over all of them
52081ce609eSEd Tanous     for (const auto& objpath : dbusData)
5214a0cb85cSEd Tanous     {
5224a0cb85cSEd Tanous         // Check if proper pattern for object path appears
5234a0cb85cSEd Tanous         if (boost::starts_with(objpath.first.str, ipv4PathStart))
5244a0cb85cSEd Tanous         {
5254a0cb85cSEd Tanous             for (auto& interface : objpath.second)
5264a0cb85cSEd Tanous             {
5274a0cb85cSEd Tanous                 if (interface.first == "xyz.openbmc_project.Network.IP")
5284a0cb85cSEd Tanous                 {
5294a0cb85cSEd Tanous                     // Instance IPv4AddressData structure, and set as
5304a0cb85cSEd Tanous                     // appropriate
5314a0cb85cSEd Tanous                     std::pair<
5324a0cb85cSEd Tanous                         boost::container::flat_set<IPv4AddressData>::iterator,
5334a0cb85cSEd Tanous                         bool>
53481ce609eSEd Tanous                         it = ipv4Config.insert(IPv4AddressData{});
5352c70f800SEd Tanous                     IPv4AddressData& ipv4Address = *it.first;
5362c70f800SEd Tanous                     ipv4Address.id =
537271584abSEd Tanous                         objpath.first.str.substr(ipv4PathStart.size());
5384a0cb85cSEd Tanous                     for (auto& property : interface.second)
5394a0cb85cSEd Tanous                     {
5404a0cb85cSEd Tanous                         if (property.first == "Address")
5414a0cb85cSEd Tanous                         {
5424a0cb85cSEd Tanous                             const std::string* address =
543abf2add6SEd Tanous                                 std::get_if<std::string>(&property.second);
5444a0cb85cSEd Tanous                             if (address != nullptr)
5454a0cb85cSEd Tanous                             {
5462c70f800SEd Tanous                                 ipv4Address.address = *address;
5474a0cb85cSEd Tanous                             }
5484a0cb85cSEd Tanous                         }
5494a0cb85cSEd Tanous                         else if (property.first == "Origin")
5504a0cb85cSEd Tanous                         {
5514a0cb85cSEd Tanous                             const std::string* origin =
552abf2add6SEd Tanous                                 std::get_if<std::string>(&property.second);
5534a0cb85cSEd Tanous                             if (origin != nullptr)
5544a0cb85cSEd Tanous                             {
5552c70f800SEd Tanous                                 ipv4Address.origin =
5564a0cb85cSEd Tanous                                     translateAddressOriginDbusToRedfish(*origin,
5574a0cb85cSEd Tanous                                                                         true);
5584a0cb85cSEd Tanous                             }
5594a0cb85cSEd Tanous                         }
5604a0cb85cSEd Tanous                         else if (property.first == "PrefixLength")
5614a0cb85cSEd Tanous                         {
5624a0cb85cSEd Tanous                             const uint8_t* mask =
563abf2add6SEd Tanous                                 std::get_if<uint8_t>(&property.second);
5644a0cb85cSEd Tanous                             if (mask != nullptr)
5654a0cb85cSEd Tanous                             {
5664a0cb85cSEd Tanous                                 // convert it to the string
5672c70f800SEd Tanous                                 ipv4Address.netmask = getNetmask(*mask);
5684a0cb85cSEd Tanous                             }
5694a0cb85cSEd Tanous                         }
5704a0cb85cSEd Tanous                         else
5714a0cb85cSEd Tanous                         {
5724a0cb85cSEd Tanous                             BMCWEB_LOG_ERROR
5734a0cb85cSEd Tanous                                 << "Got extra property: " << property.first
5744a0cb85cSEd Tanous                                 << " on the " << objpath.first.str << " object";
5754a0cb85cSEd Tanous                         }
5764a0cb85cSEd Tanous                     }
5774a0cb85cSEd Tanous                     // Check if given address is local, or global
5782c70f800SEd Tanous                     ipv4Address.linktype =
5792c70f800SEd Tanous                         boost::starts_with(ipv4Address.address, "169.254.")
58018659d10SJohnathan Mantey                             ? LinkType::Local
58118659d10SJohnathan Mantey                             : LinkType::Global;
5824a0cb85cSEd Tanous                 }
5834a0cb85cSEd Tanous             }
5844a0cb85cSEd Tanous         }
5854a0cb85cSEd Tanous     }
5864a0cb85cSEd Tanous }
587588c3f0dSKowalski, Kamil 
588588c3f0dSKowalski, Kamil /**
589588c3f0dSKowalski, Kamil  * @brief Sets given Id on the given VLAN interface through D-Bus
590588c3f0dSKowalski, Kamil  *
591588c3f0dSKowalski, Kamil  * @param[in] ifaceId       Id of VLAN interface that should be modified
592588c3f0dSKowalski, Kamil  * @param[in] inputVlanId   New ID of the VLAN
593588c3f0dSKowalski, Kamil  * @param[in] callback      Function that will be called after the operation
594588c3f0dSKowalski, Kamil  *
595588c3f0dSKowalski, Kamil  * @return None.
596588c3f0dSKowalski, Kamil  */
597588c3f0dSKowalski, Kamil template <typename CallbackFunc>
5984a0cb85cSEd Tanous void changeVlanId(const std::string& ifaceId, const uint32_t& inputVlanId,
5991abe55efSEd Tanous                   CallbackFunc&& callback)
6001abe55efSEd Tanous {
60155c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
602588c3f0dSKowalski, Kamil         callback, "xyz.openbmc_project.Network",
603588c3f0dSKowalski, Kamil         std::string("/xyz/openbmc_project/network/") + ifaceId,
604588c3f0dSKowalski, Kamil         "org.freedesktop.DBus.Properties", "Set",
605588c3f0dSKowalski, Kamil         "xyz.openbmc_project.Network.VLAN", "Id",
606abf2add6SEd Tanous         std::variant<uint32_t>(inputVlanId));
6074a0cb85cSEd Tanous }
608588c3f0dSKowalski, Kamil 
609588c3f0dSKowalski, Kamil /**
610179db1d7SKowalski, Kamil  * @brief Helper function that verifies IP address to check if it is in
611179db1d7SKowalski, Kamil  *        proper format. If bits pointer is provided, also calculates active
612179db1d7SKowalski, Kamil  *        bit count for Subnet Mask.
613179db1d7SKowalski, Kamil  *
614179db1d7SKowalski, Kamil  * @param[in]  ip     IP that will be verified
615179db1d7SKowalski, Kamil  * @param[out] bits   Calculated mask in bits notation
616179db1d7SKowalski, Kamil  *
617179db1d7SKowalski, Kamil  * @return true in case of success, false otherwise
618179db1d7SKowalski, Kamil  */
6194a0cb85cSEd Tanous inline bool ipv4VerifyIpAndGetBitcount(const std::string& ip,
6201abe55efSEd Tanous                                        uint8_t* bits = nullptr)
6211abe55efSEd Tanous {
622179db1d7SKowalski, Kamil     std::vector<std::string> bytesInMask;
623179db1d7SKowalski, Kamil 
624179db1d7SKowalski, Kamil     boost::split(bytesInMask, ip, boost::is_any_of("."));
625179db1d7SKowalski, Kamil 
6264a0cb85cSEd Tanous     static const constexpr int ipV4AddressSectionsCount = 4;
6271abe55efSEd Tanous     if (bytesInMask.size() != ipV4AddressSectionsCount)
6281abe55efSEd Tanous     {
629179db1d7SKowalski, Kamil         return false;
630179db1d7SKowalski, Kamil     }
631179db1d7SKowalski, Kamil 
6321abe55efSEd Tanous     if (bits != nullptr)
6331abe55efSEd Tanous     {
634179db1d7SKowalski, Kamil         *bits = 0;
635179db1d7SKowalski, Kamil     }
636179db1d7SKowalski, Kamil 
637179db1d7SKowalski, Kamil     char* endPtr;
638179db1d7SKowalski, Kamil     long previousValue = 255;
639179db1d7SKowalski, Kamil     bool firstZeroInByteHit;
6401abe55efSEd Tanous     for (const std::string& byte : bytesInMask)
6411abe55efSEd Tanous     {
6421abe55efSEd Tanous         if (byte.empty())
6431abe55efSEd Tanous         {
6441db9ca37SKowalski, Kamil             return false;
6451db9ca37SKowalski, Kamil         }
6461db9ca37SKowalski, Kamil 
647179db1d7SKowalski, Kamil         // Use strtol instead of stroi to avoid exceptions
6481db9ca37SKowalski, Kamil         long value = std::strtol(byte.c_str(), &endPtr, 10);
649179db1d7SKowalski, Kamil 
6504a0cb85cSEd Tanous         // endPtr should point to the end of the string, otherwise given string
6514a0cb85cSEd Tanous         // is not 100% number
6521abe55efSEd Tanous         if (*endPtr != '\0')
6531abe55efSEd Tanous         {
654179db1d7SKowalski, Kamil             return false;
655179db1d7SKowalski, Kamil         }
656179db1d7SKowalski, Kamil 
657179db1d7SKowalski, Kamil         // Value should be contained in byte
6581abe55efSEd Tanous         if (value < 0 || value > 255)
6591abe55efSEd Tanous         {
660179db1d7SKowalski, Kamil             return false;
661179db1d7SKowalski, Kamil         }
662179db1d7SKowalski, Kamil 
6631abe55efSEd Tanous         if (bits != nullptr)
6641abe55efSEd Tanous         {
665179db1d7SKowalski, Kamil             // Mask has to be continuous between bytes
6661abe55efSEd Tanous             if (previousValue != 255 && value != 0)
6671abe55efSEd Tanous             {
668179db1d7SKowalski, Kamil                 return false;
669179db1d7SKowalski, Kamil             }
670179db1d7SKowalski, Kamil 
671179db1d7SKowalski, Kamil             // Mask has to be continuous inside bytes
672179db1d7SKowalski, Kamil             firstZeroInByteHit = false;
673179db1d7SKowalski, Kamil 
674179db1d7SKowalski, Kamil             // Count bits
67523a21a1cSEd Tanous             for (long bitIdx = 7; bitIdx >= 0; bitIdx--)
6761abe55efSEd Tanous             {
67723a21a1cSEd Tanous                 if (value & (1L << bitIdx))
6781abe55efSEd Tanous                 {
6791abe55efSEd Tanous                     if (firstZeroInByteHit)
6801abe55efSEd Tanous                     {
681179db1d7SKowalski, Kamil                         // Continuity not preserved
682179db1d7SKowalski, Kamil                         return false;
6831abe55efSEd Tanous                     }
684179db1d7SKowalski, Kamil                     (*bits)++;
685179db1d7SKowalski, Kamil                 }
6861abe55efSEd Tanous                 else
6871abe55efSEd Tanous                 {
688179db1d7SKowalski, Kamil                     firstZeroInByteHit = true;
689179db1d7SKowalski, Kamil                 }
690179db1d7SKowalski, Kamil             }
691179db1d7SKowalski, Kamil         }
692179db1d7SKowalski, Kamil 
693179db1d7SKowalski, Kamil         previousValue = value;
694179db1d7SKowalski, Kamil     }
695179db1d7SKowalski, Kamil 
696179db1d7SKowalski, Kamil     return true;
697179db1d7SKowalski, Kamil }
698179db1d7SKowalski, Kamil 
699179db1d7SKowalski, Kamil /**
70001784826SJohnathan Mantey  * @brief Deletes given IPv4 interface
701179db1d7SKowalski, Kamil  *
702179db1d7SKowalski, Kamil  * @param[in] ifaceId     Id of interface whose IP should be deleted
703179db1d7SKowalski, Kamil  * @param[in] ipHash      DBus Hash id of IP that should be deleted
704179db1d7SKowalski, Kamil  * @param[io] asyncResp   Response object that will be returned to client
705179db1d7SKowalski, Kamil  *
706179db1d7SKowalski, Kamil  * @return None
707179db1d7SKowalski, Kamil  */
7084a0cb85cSEd Tanous inline void deleteIPv4(const std::string& ifaceId, const std::string& ipHash,
7098d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
7101abe55efSEd Tanous {
71155c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
712286b9118SJohnathan Mantey         [asyncResp](const boost::system::error_code ec) {
7131abe55efSEd Tanous             if (ec)
7141abe55efSEd Tanous             {
715a08b46ccSJason M. Bills                 messages::internalError(asyncResp->res);
7161abe55efSEd Tanous             }
717179db1d7SKowalski, Kamil         },
718179db1d7SKowalski, Kamil         "xyz.openbmc_project.Network",
719179db1d7SKowalski, Kamil         "/xyz/openbmc_project/network/" + ifaceId + "/ipv4/" + ipHash,
720179db1d7SKowalski, Kamil         "xyz.openbmc_project.Object.Delete", "Delete");
721179db1d7SKowalski, Kamil }
722179db1d7SKowalski, Kamil 
723*9010ec2eSRavi Teja inline void
724*9010ec2eSRavi Teja     updateIPv4DefaultGateway(const std::string& ifaceId,
725*9010ec2eSRavi Teja                              const std::string& gateway,
726*9010ec2eSRavi Teja                              const std::shared_ptr<AsyncResp>& asyncResp)
727*9010ec2eSRavi Teja {
728*9010ec2eSRavi Teja     crow::connections::systemBus->async_method_call(
729*9010ec2eSRavi Teja         [asyncResp](const boost::system::error_code ec) {
730*9010ec2eSRavi Teja             if (ec)
731*9010ec2eSRavi Teja             {
732*9010ec2eSRavi Teja                 messages::internalError(asyncResp->res);
733*9010ec2eSRavi Teja                 return;
734*9010ec2eSRavi Teja             }
735*9010ec2eSRavi Teja             asyncResp->res.result(boost::beast::http::status::no_content);
736*9010ec2eSRavi Teja         },
737*9010ec2eSRavi Teja         "xyz.openbmc_project.Network",
738*9010ec2eSRavi Teja         "/xyz/openbmc_project/network/" + ifaceId,
739*9010ec2eSRavi Teja         "org.freedesktop.DBus.Properties", "Set",
740*9010ec2eSRavi Teja         "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway",
741*9010ec2eSRavi Teja         std::variant<std::string>(gateway));
742*9010ec2eSRavi Teja }
743179db1d7SKowalski, Kamil /**
74401784826SJohnathan Mantey  * @brief Creates a static IPv4 entry
745179db1d7SKowalski, Kamil  *
74601784826SJohnathan Mantey  * @param[in] ifaceId      Id of interface upon which to create the IPv4 entry
74701784826SJohnathan Mantey  * @param[in] prefixLength IPv4 prefix syntax for the subnet mask
74801784826SJohnathan Mantey  * @param[in] gateway      IPv4 address of this interfaces gateway
74901784826SJohnathan Mantey  * @param[in] address      IPv4 address to assign to this interface
750179db1d7SKowalski, Kamil  * @param[io] asyncResp    Response object that will be returned to client
751179db1d7SKowalski, Kamil  *
752179db1d7SKowalski, Kamil  * @return None
753179db1d7SKowalski, Kamil  */
754cb13a392SEd Tanous inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
755cb13a392SEd Tanous                        const std::string& gateway, const std::string& address,
7568d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
7571abe55efSEd Tanous {
758*9010ec2eSRavi Teja     auto createIpHandler = [asyncResp, ifaceId,
759*9010ec2eSRavi Teja                             gateway](const boost::system::error_code ec) {
7601abe55efSEd Tanous         if (ec)
7611abe55efSEd Tanous         {
762a08b46ccSJason M. Bills             messages::internalError(asyncResp->res);
763*9010ec2eSRavi Teja             return;
764179db1d7SKowalski, Kamil         }
765*9010ec2eSRavi Teja         updateIPv4DefaultGateway(ifaceId, gateway, asyncResp);
766*9010ec2eSRavi Teja     };
767*9010ec2eSRavi Teja 
768*9010ec2eSRavi Teja     crow::connections::systemBus->async_method_call(
769*9010ec2eSRavi Teja         std::move(createIpHandler), "xyz.openbmc_project.Network",
770179db1d7SKowalski, Kamil         "/xyz/openbmc_project/network/" + ifaceId,
771179db1d7SKowalski, Kamil         "xyz.openbmc_project.Network.IP.Create", "IP",
77201784826SJohnathan Mantey         "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength,
773179db1d7SKowalski, Kamil         gateway);
774179db1d7SKowalski, Kamil }
775e48c0fc5SRavi Teja 
776e48c0fc5SRavi Teja /**
77701784826SJohnathan Mantey  * @brief Deletes the IPv4 entry for this interface and creates a replacement
77801784826SJohnathan Mantey  * static IPv4 entry
77901784826SJohnathan Mantey  *
78001784826SJohnathan Mantey  * @param[in] ifaceId      Id of interface upon which to create the IPv4 entry
78101784826SJohnathan Mantey  * @param[in] id           The unique hash entry identifying the DBus entry
78201784826SJohnathan Mantey  * @param[in] prefixLength IPv4 prefix syntax for the subnet mask
78301784826SJohnathan Mantey  * @param[in] gateway      IPv4 address of this interfaces gateway
78401784826SJohnathan Mantey  * @param[in] address      IPv4 address to assign to this interface
78501784826SJohnathan Mantey  * @param[io] asyncResp    Response object that will be returned to client
78601784826SJohnathan Mantey  *
78701784826SJohnathan Mantey  * @return None
78801784826SJohnathan Mantey  */
7898d1b46d7Szhanghch05 inline void
7908d1b46d7Szhanghch05     deleteAndCreateIPv4(const std::string& ifaceId, const std::string& id,
7918d1b46d7Szhanghch05                         uint8_t prefixLength, const std::string& gateway,
79201784826SJohnathan Mantey                         const std::string& address,
7938d1b46d7Szhanghch05                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
79401784826SJohnathan Mantey {
79501784826SJohnathan Mantey     crow::connections::systemBus->async_method_call(
79601784826SJohnathan Mantey         [asyncResp, ifaceId, address, prefixLength,
79701784826SJohnathan Mantey          gateway](const boost::system::error_code ec) {
79801784826SJohnathan Mantey             if (ec)
79901784826SJohnathan Mantey             {
80001784826SJohnathan Mantey                 messages::internalError(asyncResp->res);
801*9010ec2eSRavi Teja                 return;
80201784826SJohnathan Mantey             }
803*9010ec2eSRavi Teja 
80401784826SJohnathan Mantey             crow::connections::systemBus->async_method_call(
805*9010ec2eSRavi Teja                 [asyncResp, ifaceId,
806*9010ec2eSRavi Teja                  gateway](const boost::system::error_code ec2) {
80723a21a1cSEd Tanous                     if (ec2)
80801784826SJohnathan Mantey                     {
80901784826SJohnathan Mantey                         messages::internalError(asyncResp->res);
810*9010ec2eSRavi Teja                         return;
81101784826SJohnathan Mantey                     }
812*9010ec2eSRavi Teja                     updateIPv4DefaultGateway(ifaceId, gateway, asyncResp);
81301784826SJohnathan Mantey                 },
81401784826SJohnathan Mantey                 "xyz.openbmc_project.Network",
81501784826SJohnathan Mantey                 "/xyz/openbmc_project/network/" + ifaceId,
81601784826SJohnathan Mantey                 "xyz.openbmc_project.Network.IP.Create", "IP",
81701784826SJohnathan Mantey                 "xyz.openbmc_project.Network.IP.Protocol.IPv4", address,
81801784826SJohnathan Mantey                 prefixLength, gateway);
81901784826SJohnathan Mantey         },
82001784826SJohnathan Mantey         "xyz.openbmc_project.Network",
82101784826SJohnathan Mantey         +"/xyz/openbmc_project/network/" + ifaceId + "/ipv4/" + id,
82201784826SJohnathan Mantey         "xyz.openbmc_project.Object.Delete", "Delete");
82301784826SJohnathan Mantey }
82401784826SJohnathan Mantey 
82501784826SJohnathan Mantey /**
826e48c0fc5SRavi Teja  * @brief Deletes given IPv6
827e48c0fc5SRavi Teja  *
828e48c0fc5SRavi Teja  * @param[in] ifaceId     Id of interface whose IP should be deleted
829e48c0fc5SRavi Teja  * @param[in] ipHash      DBus Hash id of IP that should be deleted
830e48c0fc5SRavi Teja  * @param[io] asyncResp   Response object that will be returned to client
831e48c0fc5SRavi Teja  *
832e48c0fc5SRavi Teja  * @return None
833e48c0fc5SRavi Teja  */
834e48c0fc5SRavi Teja inline void deleteIPv6(const std::string& ifaceId, const std::string& ipHash,
8358d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
836e48c0fc5SRavi Teja {
837e48c0fc5SRavi Teja     crow::connections::systemBus->async_method_call(
838286b9118SJohnathan Mantey         [asyncResp](const boost::system::error_code ec) {
839e48c0fc5SRavi Teja             if (ec)
840e48c0fc5SRavi Teja             {
841e48c0fc5SRavi Teja                 messages::internalError(asyncResp->res);
842e48c0fc5SRavi Teja             }
843e48c0fc5SRavi Teja         },
844e48c0fc5SRavi Teja         "xyz.openbmc_project.Network",
845e48c0fc5SRavi Teja         "/xyz/openbmc_project/network/" + ifaceId + "/ipv6/" + ipHash,
846e48c0fc5SRavi Teja         "xyz.openbmc_project.Object.Delete", "Delete");
847e48c0fc5SRavi Teja }
848e48c0fc5SRavi Teja 
849e48c0fc5SRavi Teja /**
85001784826SJohnathan Mantey  * @brief Deletes the IPv6 entry for this interface and creates a replacement
85101784826SJohnathan Mantey  * static IPv6 entry
85201784826SJohnathan Mantey  *
85301784826SJohnathan Mantey  * @param[in] ifaceId      Id of interface upon which to create the IPv6 entry
85401784826SJohnathan Mantey  * @param[in] id           The unique hash entry identifying the DBus entry
85501784826SJohnathan Mantey  * @param[in] prefixLength IPv6 prefix syntax for the subnet mask
85601784826SJohnathan Mantey  * @param[in] address      IPv6 address to assign to this interface
85701784826SJohnathan Mantey  * @param[io] asyncResp    Response object that will be returned to client
85801784826SJohnathan Mantey  *
85901784826SJohnathan Mantey  * @return None
86001784826SJohnathan Mantey  */
8618d1b46d7Szhanghch05 inline void
8628d1b46d7Szhanghch05     deleteAndCreateIPv6(const std::string& ifaceId, const std::string& id,
8638d1b46d7Szhanghch05                         uint8_t prefixLength, const std::string& address,
8648d1b46d7Szhanghch05                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
86501784826SJohnathan Mantey {
86601784826SJohnathan Mantey     crow::connections::systemBus->async_method_call(
86701784826SJohnathan Mantey         [asyncResp, ifaceId, address,
86801784826SJohnathan Mantey          prefixLength](const boost::system::error_code ec) {
86901784826SJohnathan Mantey             if (ec)
87001784826SJohnathan Mantey             {
87101784826SJohnathan Mantey                 messages::internalError(asyncResp->res);
87201784826SJohnathan Mantey             }
87301784826SJohnathan Mantey             crow::connections::systemBus->async_method_call(
87423a21a1cSEd Tanous                 [asyncResp](const boost::system::error_code ec2) {
87523a21a1cSEd Tanous                     if (ec2)
87601784826SJohnathan Mantey                     {
87701784826SJohnathan Mantey                         messages::internalError(asyncResp->res);
87801784826SJohnathan Mantey                     }
87901784826SJohnathan Mantey                 },
88001784826SJohnathan Mantey                 "xyz.openbmc_project.Network",
88101784826SJohnathan Mantey                 "/xyz/openbmc_project/network/" + ifaceId,
88201784826SJohnathan Mantey                 "xyz.openbmc_project.Network.IP.Create", "IP",
88301784826SJohnathan Mantey                 "xyz.openbmc_project.Network.IP.Protocol.IPv6", address,
88401784826SJohnathan Mantey                 prefixLength, "");
88501784826SJohnathan Mantey         },
88601784826SJohnathan Mantey         "xyz.openbmc_project.Network",
88701784826SJohnathan Mantey         +"/xyz/openbmc_project/network/" + ifaceId + "/ipv6/" + id,
88801784826SJohnathan Mantey         "xyz.openbmc_project.Object.Delete", "Delete");
88901784826SJohnathan Mantey }
89001784826SJohnathan Mantey 
89101784826SJohnathan Mantey /**
892e48c0fc5SRavi Teja  * @brief Creates IPv6 with given data
893e48c0fc5SRavi Teja  *
894e48c0fc5SRavi Teja  * @param[in] ifaceId      Id of interface whose IP should be added
895e48c0fc5SRavi Teja  * @param[in] prefixLength Prefix length that needs to be added
896e48c0fc5SRavi Teja  * @param[in] address      IP address that needs to be added
897e48c0fc5SRavi Teja  * @param[io] asyncResp    Response object that will be returned to client
898e48c0fc5SRavi Teja  *
899e48c0fc5SRavi Teja  * @return None
900e48c0fc5SRavi Teja  */
90101784826SJohnathan Mantey inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength,
90201784826SJohnathan Mantey                        const std::string& address,
9038d1b46d7Szhanghch05                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
904e48c0fc5SRavi Teja {
905e48c0fc5SRavi Teja     auto createIpHandler = [asyncResp](const boost::system::error_code ec) {
906e48c0fc5SRavi Teja         if (ec)
907e48c0fc5SRavi Teja         {
908e48c0fc5SRavi Teja             messages::internalError(asyncResp->res);
909e48c0fc5SRavi Teja         }
910e48c0fc5SRavi Teja     };
911e48c0fc5SRavi Teja     // Passing null for gateway, as per redfish spec IPv6StaticAddresses object
9124e0453b1SGunnar Mills     // does not have associated gateway property
913e48c0fc5SRavi Teja     crow::connections::systemBus->async_method_call(
914e48c0fc5SRavi Teja         std::move(createIpHandler), "xyz.openbmc_project.Network",
915e48c0fc5SRavi Teja         "/xyz/openbmc_project/network/" + ifaceId,
916e48c0fc5SRavi Teja         "xyz.openbmc_project.Network.IP.Create", "IP",
917e48c0fc5SRavi Teja         "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength,
918e48c0fc5SRavi Teja         "");
919e48c0fc5SRavi Teja }
920e48c0fc5SRavi Teja 
921179db1d7SKowalski, Kamil /**
922179db1d7SKowalski, Kamil  * Function that retrieves all properties for given Ethernet Interface
923179db1d7SKowalski, Kamil  * Object
924179db1d7SKowalski, Kamil  * from EntityManager Network Manager
9254a0cb85cSEd Tanous  * @param ethiface_id a eth interface id to query on DBus
926179db1d7SKowalski, Kamil  * @param callback a function that shall be called to convert Dbus output
927179db1d7SKowalski, Kamil  * into JSON
928179db1d7SKowalski, Kamil  */
929179db1d7SKowalski, Kamil template <typename CallbackFunc>
93081ce609eSEd Tanous void getEthernetIfaceData(const std::string& ethifaceId,
9311abe55efSEd Tanous                           CallbackFunc&& callback)
9321abe55efSEd Tanous {
93355c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
93481ce609eSEd Tanous         [ethifaceId{std::string{ethifaceId}}, callback{std::move(callback)}](
93581ce609eSEd Tanous             const boost::system::error_code errorCode,
936f23b7296SEd Tanous             GetManagedObjects& resp) {
93755c7b7a2SEd Tanous             EthernetInterfaceData ethData{};
9384a0cb85cSEd Tanous             boost::container::flat_set<IPv4AddressData> ipv4Data;
939e48c0fc5SRavi Teja             boost::container::flat_set<IPv6AddressData> ipv6Data;
940179db1d7SKowalski, Kamil 
94181ce609eSEd Tanous             if (errorCode)
9421abe55efSEd Tanous             {
94301784826SJohnathan Mantey                 callback(false, ethData, ipv4Data, ipv6Data);
944179db1d7SKowalski, Kamil                 return;
945179db1d7SKowalski, Kamil             }
946179db1d7SKowalski, Kamil 
9474c9afe43SEd Tanous             bool found =
9482c70f800SEd Tanous                 extractEthernetInterfaceData(ethifaceId, resp, ethData);
9494c9afe43SEd Tanous             if (!found)
9504c9afe43SEd Tanous             {
95101784826SJohnathan Mantey                 callback(false, ethData, ipv4Data, ipv6Data);
9524c9afe43SEd Tanous                 return;
9534c9afe43SEd Tanous             }
9544c9afe43SEd Tanous 
9552c70f800SEd Tanous             extractIPData(ethifaceId, resp, ipv4Data);
956179db1d7SKowalski, Kamil             // Fix global GW
9571abe55efSEd Tanous             for (IPv4AddressData& ipv4 : ipv4Data)
9581abe55efSEd Tanous             {
959c619141bSRavi Teja                 if (((ipv4.linktype == LinkType::Global) &&
960c619141bSRavi Teja                      (ipv4.gateway == "0.0.0.0")) ||
961*9010ec2eSRavi Teja                     (ipv4.origin == "DHCP") || (ipv4.origin == "Static"))
9621abe55efSEd Tanous                 {
9634a0cb85cSEd Tanous                     ipv4.gateway = ethData.default_gateway;
964179db1d7SKowalski, Kamil                 }
965179db1d7SKowalski, Kamil             }
966179db1d7SKowalski, Kamil 
9672c70f800SEd Tanous             extractIPV6Data(ethifaceId, resp, ipv6Data);
9684e0453b1SGunnar Mills             // Finally make a callback with useful data
96901784826SJohnathan Mantey             callback(true, ethData, ipv4Data, ipv6Data);
970179db1d7SKowalski, Kamil         },
971179db1d7SKowalski, Kamil         "xyz.openbmc_project.Network", "/xyz/openbmc_project/network",
972179db1d7SKowalski, Kamil         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
973271584abSEd Tanous }
974179db1d7SKowalski, Kamil 
975179db1d7SKowalski, Kamil /**
9769391bb9cSRapkiewicz, Pawel  * Function that retrieves all Ethernet Interfaces available through Network
9779391bb9cSRapkiewicz, Pawel  * Manager
9781abe55efSEd Tanous  * @param callback a function that shall be called to convert Dbus output
9791abe55efSEd Tanous  * into JSON.
9809391bb9cSRapkiewicz, Pawel  */
9819391bb9cSRapkiewicz, Pawel template <typename CallbackFunc>
9821abe55efSEd Tanous void getEthernetIfaceList(CallbackFunc&& callback)
9831abe55efSEd Tanous {
98455c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
9854a0cb85cSEd Tanous         [callback{std::move(callback)}](
98681ce609eSEd Tanous             const boost::system::error_code errorCode,
9874a0cb85cSEd Tanous             GetManagedObjects& resp) {
9881abe55efSEd Tanous             // Callback requires vector<string> to retrieve all available
9891abe55efSEd Tanous             // ethernet interfaces
9902c70f800SEd Tanous             boost::container::flat_set<std::string> ifaceList;
9912c70f800SEd Tanous             ifaceList.reserve(resp.size());
99281ce609eSEd Tanous             if (errorCode)
9931abe55efSEd Tanous             {
9942c70f800SEd Tanous                 callback(false, ifaceList);
9959391bb9cSRapkiewicz, Pawel                 return;
9969391bb9cSRapkiewicz, Pawel             }
9979391bb9cSRapkiewicz, Pawel 
9989391bb9cSRapkiewicz, Pawel             // Iterate over all retrieved ObjectPaths.
9994a0cb85cSEd Tanous             for (const auto& objpath : resp)
10001abe55efSEd Tanous             {
10019391bb9cSRapkiewicz, Pawel                 // And all interfaces available for certain ObjectPath.
10024a0cb85cSEd Tanous                 for (const auto& interface : objpath.second)
10031abe55efSEd Tanous                 {
10041abe55efSEd Tanous                     // If interface is
10054a0cb85cSEd Tanous                     // xyz.openbmc_project.Network.EthernetInterface, this is
10064a0cb85cSEd Tanous                     // what we're looking for.
10079391bb9cSRapkiewicz, Pawel                     if (interface.first ==
10081abe55efSEd Tanous                         "xyz.openbmc_project.Network.EthernetInterface")
10091abe55efSEd Tanous                     {
10102dfd18efSEd Tanous                         std::string ifaceId = objpath.first.filename();
10112dfd18efSEd Tanous                         if (ifaceId.empty())
10121abe55efSEd Tanous                         {
10132dfd18efSEd Tanous                             continue;
10149391bb9cSRapkiewicz, Pawel                         }
10152dfd18efSEd Tanous                         // and put it into output vector.
10162dfd18efSEd Tanous                         ifaceList.emplace(ifaceId);
10179391bb9cSRapkiewicz, Pawel                     }
10189391bb9cSRapkiewicz, Pawel                 }
10199391bb9cSRapkiewicz, Pawel             }
1020a434f2bdSEd Tanous             // Finally make a callback with useful data
10212c70f800SEd Tanous             callback(true, ifaceList);
10229391bb9cSRapkiewicz, Pawel         },
1023aa2e59c1SEd Tanous         "xyz.openbmc_project.Network", "/xyz/openbmc_project/network",
1024aa2e59c1SEd Tanous         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
1025271584abSEd Tanous }
10269391bb9cSRapkiewicz, Pawel 
10279391bb9cSRapkiewicz, Pawel /**
10289391bb9cSRapkiewicz, Pawel  * EthernetCollection derived class for delivering Ethernet Collection Schema
10299391bb9cSRapkiewicz, Pawel  */
10301abe55efSEd Tanous class EthernetCollection : public Node
10311abe55efSEd Tanous {
10329391bb9cSRapkiewicz, Pawel   public:
103352cc112dSEd Tanous     EthernetCollection(App& app) :
10344a0cb85cSEd Tanous         Node(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/")
10351abe55efSEd Tanous     {
1036588c3f0dSKowalski, Kamil         entityPrivileges = {
1037588c3f0dSKowalski, Kamil             {boost::beast::http::verb::get, {{"Login"}}},
1038e0d918bcSEd Tanous             {boost::beast::http::verb::head, {{"Login"}}},
1039e0d918bcSEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1040e0d918bcSEd Tanous             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1041e0d918bcSEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1042e0d918bcSEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
10439391bb9cSRapkiewicz, Pawel     }
10449391bb9cSRapkiewicz, Pawel 
10459391bb9cSRapkiewicz, Pawel   private:
10469391bb9cSRapkiewicz, Pawel     /**
10479391bb9cSRapkiewicz, Pawel      * Functions triggers appropriate requests on DBus
10489391bb9cSRapkiewicz, Pawel      */
10498d1b46d7Szhanghch05     void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
10508d1b46d7Szhanghch05                const crow::Request&, const std::vector<std::string>&) override
10511abe55efSEd Tanous     {
10528d1b46d7Szhanghch05         asyncResp->res.jsonValue["@odata.type"] =
10530f74e643SEd Tanous             "#EthernetInterfaceCollection.EthernetInterfaceCollection";
10548d1b46d7Szhanghch05         asyncResp->res.jsonValue["@odata.id"] =
10550f74e643SEd Tanous             "/redfish/v1/Managers/bmc/EthernetInterfaces";
10568d1b46d7Szhanghch05         asyncResp->res.jsonValue["Name"] =
10578d1b46d7Szhanghch05             "Ethernet Network Interface Collection";
10588d1b46d7Szhanghch05         asyncResp->res.jsonValue["Description"] =
10590f74e643SEd Tanous             "Collection of EthernetInterfaces for this Manager";
10608d1b46d7Szhanghch05 
10614a0cb85cSEd Tanous         // Get eth interface list, and call the below callback for JSON
10621abe55efSEd Tanous         // preparation
1063f12894f8SJason M. Bills         getEthernetIfaceList(
10644c9afe43SEd Tanous             [asyncResp](
10654c9afe43SEd Tanous                 const bool& success,
106681ce609eSEd Tanous                 const boost::container::flat_set<std::string>& ifaceList) {
10674a0cb85cSEd Tanous                 if (!success)
10681abe55efSEd Tanous                 {
10694c9afe43SEd Tanous                     messages::internalError(asyncResp->res);
10704a0cb85cSEd Tanous                     return;
10714a0cb85cSEd Tanous                 }
10724a0cb85cSEd Tanous 
10732c70f800SEd Tanous                 nlohmann::json& ifaceArray =
10744c9afe43SEd Tanous                     asyncResp->res.jsonValue["Members"];
10752c70f800SEd Tanous                 ifaceArray = nlohmann::json::array();
1076fda13ad2SSunitha Harish                 std::string tag = "_";
107781ce609eSEd Tanous                 for (const std::string& ifaceItem : ifaceList)
10781abe55efSEd Tanous                 {
10792c70f800SEd Tanous                     std::size_t found = ifaceItem.find(tag);
1080fda13ad2SSunitha Harish                     if (found == std::string::npos)
1081fda13ad2SSunitha Harish                     {
10822c70f800SEd Tanous                         ifaceArray.push_back(
10834a0cb85cSEd Tanous                             {{"@odata.id",
10844a0cb85cSEd Tanous                               "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
10852c70f800SEd Tanous                                   ifaceItem}});
10869391bb9cSRapkiewicz, Pawel                     }
1087fda13ad2SSunitha Harish                 }
10884a0cb85cSEd Tanous 
10894c9afe43SEd Tanous                 asyncResp->res.jsonValue["Members@odata.count"] =
10902c70f800SEd Tanous                     ifaceArray.size();
10914c9afe43SEd Tanous                 asyncResp->res.jsonValue["@odata.id"] =
10924a0cb85cSEd Tanous                     "/redfish/v1/Managers/bmc/EthernetInterfaces";
10939391bb9cSRapkiewicz, Pawel             });
10949391bb9cSRapkiewicz, Pawel     }
10959391bb9cSRapkiewicz, Pawel };
10969391bb9cSRapkiewicz, Pawel 
10979391bb9cSRapkiewicz, Pawel /**
10989391bb9cSRapkiewicz, Pawel  * EthernetInterface derived class for delivering Ethernet Schema
10999391bb9cSRapkiewicz, Pawel  */
11001abe55efSEd Tanous class EthernetInterface : public Node
11011abe55efSEd Tanous {
11029391bb9cSRapkiewicz, Pawel   public:
11039391bb9cSRapkiewicz, Pawel     /*
11049391bb9cSRapkiewicz, Pawel      * Default Constructor
11059391bb9cSRapkiewicz, Pawel      */
110652cc112dSEd Tanous     EthernetInterface(App& app) :
11074a0cb85cSEd Tanous         Node(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/",
11081abe55efSEd Tanous              std::string())
11091abe55efSEd Tanous     {
1110588c3f0dSKowalski, Kamil         entityPrivileges = {
1111588c3f0dSKowalski, Kamil             {boost::beast::http::verb::get, {{"Login"}}},
1112e0d918bcSEd Tanous             {boost::beast::http::verb::head, {{"Login"}}},
1113e0d918bcSEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1114e0d918bcSEd Tanous             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1115e0d918bcSEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1116e0d918bcSEd Tanous             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
11179391bb9cSRapkiewicz, Pawel     }
11189391bb9cSRapkiewicz, Pawel 
1119e439f0f8SKowalski, Kamil   private:
11208d1b46d7Szhanghch05     void
11218d1b46d7Szhanghch05         handleHostnamePatch(const std::string& hostname,
11228d1b46d7Szhanghch05                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
11231abe55efSEd Tanous     {
1124ab6554f1SJoshi-Mansi         // SHOULD handle host names of up to 255 characters(RFC 1123)
1125ab6554f1SJoshi-Mansi         if (hostname.length() > 255)
1126ab6554f1SJoshi-Mansi         {
1127ab6554f1SJoshi-Mansi             messages::propertyValueFormatError(asyncResp->res, hostname,
1128ab6554f1SJoshi-Mansi                                                "HostName");
1129ab6554f1SJoshi-Mansi             return;
1130ab6554f1SJoshi-Mansi         }
1131bc0bd6e0SEd Tanous         crow::connections::systemBus->async_method_call(
1132bc0bd6e0SEd Tanous             [asyncResp](const boost::system::error_code ec) {
11334a0cb85cSEd Tanous                 if (ec)
11344a0cb85cSEd Tanous                 {
1135a08b46ccSJason M. Bills                     messages::internalError(asyncResp->res);
11361abe55efSEd Tanous                 }
1137bc0bd6e0SEd Tanous             },
1138bc0bd6e0SEd Tanous             "xyz.openbmc_project.Network",
1139bc0bd6e0SEd Tanous             "/xyz/openbmc_project/network/config",
1140bc0bd6e0SEd Tanous             "org.freedesktop.DBus.Properties", "Set",
1141bc0bd6e0SEd Tanous             "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
1142abf2add6SEd Tanous             std::variant<std::string>(hostname));
1143588c3f0dSKowalski, Kamil     }
1144588c3f0dSKowalski, Kamil 
11458d1b46d7Szhanghch05     void handleDomainnamePatch(
11468d1b46d7Szhanghch05         const std::string& ifaceId, const std::string& domainname,
11478d1b46d7Szhanghch05         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1148ab6554f1SJoshi-Mansi     {
1149ab6554f1SJoshi-Mansi         std::vector<std::string> vectorDomainname = {domainname};
1150ab6554f1SJoshi-Mansi         crow::connections::systemBus->async_method_call(
1151ab6554f1SJoshi-Mansi             [asyncResp](const boost::system::error_code ec) {
1152ab6554f1SJoshi-Mansi                 if (ec)
1153ab6554f1SJoshi-Mansi                 {
1154ab6554f1SJoshi-Mansi                     messages::internalError(asyncResp->res);
1155ab6554f1SJoshi-Mansi                 }
1156ab6554f1SJoshi-Mansi             },
1157ab6554f1SJoshi-Mansi             "xyz.openbmc_project.Network",
1158ab6554f1SJoshi-Mansi             "/xyz/openbmc_project/network/" + ifaceId,
1159ab6554f1SJoshi-Mansi             "org.freedesktop.DBus.Properties", "Set",
1160ab6554f1SJoshi-Mansi             "xyz.openbmc_project.Network.EthernetInterface", "DomainName",
1161ab6554f1SJoshi-Mansi             std::variant<std::vector<std::string>>(vectorDomainname));
1162ab6554f1SJoshi-Mansi     }
1163ab6554f1SJoshi-Mansi 
1164ab6554f1SJoshi-Mansi     void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn,
11658d1b46d7Szhanghch05                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1166ab6554f1SJoshi-Mansi     {
1167ab6554f1SJoshi-Mansi         // Total length of FQDN must not exceed 255 characters(RFC 1035)
1168ab6554f1SJoshi-Mansi         if (fqdn.length() > 255)
1169ab6554f1SJoshi-Mansi         {
1170ab6554f1SJoshi-Mansi             messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1171ab6554f1SJoshi-Mansi             return;
1172ab6554f1SJoshi-Mansi         }
1173ab6554f1SJoshi-Mansi 
1174ab6554f1SJoshi-Mansi         size_t pos = fqdn.find('.');
1175ab6554f1SJoshi-Mansi         if (pos == std::string::npos)
1176ab6554f1SJoshi-Mansi         {
1177ab6554f1SJoshi-Mansi             messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1178ab6554f1SJoshi-Mansi             return;
1179ab6554f1SJoshi-Mansi         }
1180ab6554f1SJoshi-Mansi 
1181ab6554f1SJoshi-Mansi         std::string hostname;
1182ab6554f1SJoshi-Mansi         std::string domainname;
1183ab6554f1SJoshi-Mansi         domainname = (fqdn).substr(pos + 1);
1184ab6554f1SJoshi-Mansi         hostname = (fqdn).substr(0, pos);
1185ab6554f1SJoshi-Mansi 
1186ab6554f1SJoshi-Mansi         if (!isHostnameValid(hostname) || !isDomainnameValid(domainname))
1187ab6554f1SJoshi-Mansi         {
1188ab6554f1SJoshi-Mansi             messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN");
1189ab6554f1SJoshi-Mansi             return;
1190ab6554f1SJoshi-Mansi         }
1191ab6554f1SJoshi-Mansi 
1192ab6554f1SJoshi-Mansi         handleHostnamePatch(hostname, asyncResp);
1193ab6554f1SJoshi-Mansi         handleDomainnamePatch(ifaceId, domainname, asyncResp);
1194ab6554f1SJoshi-Mansi     }
1195ab6554f1SJoshi-Mansi 
1196ab6554f1SJoshi-Mansi     bool isHostnameValid(const std::string& hostname)
1197ab6554f1SJoshi-Mansi     {
1198ab6554f1SJoshi-Mansi         // A valid host name can never have the dotted-decimal form (RFC 1123)
1199ab6554f1SJoshi-Mansi         if (std::all_of(hostname.begin(), hostname.end(), ::isdigit))
1200ab6554f1SJoshi-Mansi         {
1201ab6554f1SJoshi-Mansi             return false;
1202ab6554f1SJoshi-Mansi         }
1203ab6554f1SJoshi-Mansi         // Each label(hostname/subdomains) within a valid FQDN
1204ab6554f1SJoshi-Mansi         // MUST handle host names of up to 63 characters (RFC 1123)
1205ab6554f1SJoshi-Mansi         // labels cannot start or end with hyphens (RFC 952)
1206ab6554f1SJoshi-Mansi         // labels can start with numbers (RFC 1123)
1207ab6554f1SJoshi-Mansi         const std::regex pattern(
1208ab6554f1SJoshi-Mansi             "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$");
1209ab6554f1SJoshi-Mansi 
1210ab6554f1SJoshi-Mansi         return std::regex_match(hostname, pattern);
1211ab6554f1SJoshi-Mansi     }
1212ab6554f1SJoshi-Mansi 
1213ab6554f1SJoshi-Mansi     bool isDomainnameValid(const std::string& domainname)
1214ab6554f1SJoshi-Mansi     {
1215ab6554f1SJoshi-Mansi         // Can have multiple subdomains
1216ab6554f1SJoshi-Mansi         // Top Level Domain's min length is 2 character
1217ab6554f1SJoshi-Mansi         const std::regex pattern("^([A-Za-z0-9][a-zA-Z0-9\\-]{1,61}|[a-zA-Z0-9]"
1218ab6554f1SJoshi-Mansi                                  "{1,30}\\.)*[a-zA-Z]{2,}$");
1219ab6554f1SJoshi-Mansi 
1220ab6554f1SJoshi-Mansi         return std::regex_match(domainname, pattern);
1221ab6554f1SJoshi-Mansi     }
1222ab6554f1SJoshi-Mansi 
12238d1b46d7Szhanghch05     void handleMACAddressPatch(
12248d1b46d7Szhanghch05         const std::string& ifaceId, const std::string& macAddress,
12258d1b46d7Szhanghch05         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1226d577665bSRatan Gupta     {
1227d577665bSRatan Gupta         crow::connections::systemBus->async_method_call(
1228d577665bSRatan Gupta             [asyncResp, macAddress](const boost::system::error_code ec) {
1229d577665bSRatan Gupta                 if (ec)
1230d577665bSRatan Gupta                 {
1231d577665bSRatan Gupta                     messages::internalError(asyncResp->res);
1232d577665bSRatan Gupta                     return;
1233d577665bSRatan Gupta                 }
1234d577665bSRatan Gupta             },
1235d577665bSRatan Gupta             "xyz.openbmc_project.Network",
1236d577665bSRatan Gupta             "/xyz/openbmc_project/network/" + ifaceId,
1237d577665bSRatan Gupta             "org.freedesktop.DBus.Properties", "Set",
1238d577665bSRatan Gupta             "xyz.openbmc_project.Network.MACAddress", "MACAddress",
1239d577665bSRatan Gupta             std::variant<std::string>(macAddress));
1240d577665bSRatan Gupta     }
1241286b9118SJohnathan Mantey 
1242da131a9aSJennifer Lee     void setDHCPEnabled(const std::string& ifaceId,
12431f8c7b5dSJohnathan Mantey                         const std::string& propertyName, const bool v4Value,
12441f8c7b5dSJohnathan Mantey                         const bool v6Value,
12458d1b46d7Szhanghch05                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1246da131a9aSJennifer Lee     {
12472c70f800SEd Tanous         const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
1248da131a9aSJennifer Lee         crow::connections::systemBus->async_method_call(
1249da131a9aSJennifer Lee             [asyncResp](const boost::system::error_code ec) {
1250da131a9aSJennifer Lee                 if (ec)
1251da131a9aSJennifer Lee                 {
1252da131a9aSJennifer Lee                     BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1253da131a9aSJennifer Lee                     messages::internalError(asyncResp->res);
1254da131a9aSJennifer Lee                     return;
1255da131a9aSJennifer Lee                 }
12568f7e9c19SJayaprakash Mutyala                 messages::success(asyncResp->res);
1257da131a9aSJennifer Lee             },
1258da131a9aSJennifer Lee             "xyz.openbmc_project.Network",
1259da131a9aSJennifer Lee             "/xyz/openbmc_project/network/" + ifaceId,
1260da131a9aSJennifer Lee             "org.freedesktop.DBus.Properties", "Set",
1261da131a9aSJennifer Lee             "xyz.openbmc_project.Network.EthernetInterface", propertyName,
12621f8c7b5dSJohnathan Mantey             std::variant<std::string>{dhcp});
1263da131a9aSJennifer Lee     }
12641f8c7b5dSJohnathan Mantey 
1265eeedda23SJohnathan Mantey     void setEthernetInterfaceBoolProperty(
1266eeedda23SJohnathan Mantey         const std::string& ifaceId, const std::string& propertyName,
12678d1b46d7Szhanghch05         const bool& value, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1268eeedda23SJohnathan Mantey     {
1269eeedda23SJohnathan Mantey         crow::connections::systemBus->async_method_call(
1270eeedda23SJohnathan Mantey             [asyncResp](const boost::system::error_code ec) {
1271eeedda23SJohnathan Mantey                 if (ec)
1272eeedda23SJohnathan Mantey                 {
1273eeedda23SJohnathan Mantey                     BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1274eeedda23SJohnathan Mantey                     messages::internalError(asyncResp->res);
1275eeedda23SJohnathan Mantey                     return;
1276eeedda23SJohnathan Mantey                 }
1277eeedda23SJohnathan Mantey             },
1278eeedda23SJohnathan Mantey             "xyz.openbmc_project.Network",
1279eeedda23SJohnathan Mantey             "/xyz/openbmc_project/network/" + ifaceId,
1280eeedda23SJohnathan Mantey             "org.freedesktop.DBus.Properties", "Set",
1281eeedda23SJohnathan Mantey             "xyz.openbmc_project.Network.EthernetInterface", propertyName,
1282eeedda23SJohnathan Mantey             std::variant<bool>{value});
1283eeedda23SJohnathan Mantey     }
1284eeedda23SJohnathan Mantey 
1285da131a9aSJennifer Lee     void setDHCPv4Config(const std::string& propertyName, const bool& value,
12868d1b46d7Szhanghch05                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1287da131a9aSJennifer Lee     {
1288da131a9aSJennifer Lee         BMCWEB_LOG_DEBUG << propertyName << " = " << value;
1289da131a9aSJennifer Lee         crow::connections::systemBus->async_method_call(
1290da131a9aSJennifer Lee             [asyncResp](const boost::system::error_code ec) {
1291da131a9aSJennifer Lee                 if (ec)
1292da131a9aSJennifer Lee                 {
1293da131a9aSJennifer Lee                     BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1294da131a9aSJennifer Lee                     messages::internalError(asyncResp->res);
1295da131a9aSJennifer Lee                     return;
1296da131a9aSJennifer Lee                 }
1297da131a9aSJennifer Lee             },
1298da131a9aSJennifer Lee             "xyz.openbmc_project.Network",
1299da131a9aSJennifer Lee             "/xyz/openbmc_project/network/config/dhcp",
1300da131a9aSJennifer Lee             "org.freedesktop.DBus.Properties", "Set",
1301da131a9aSJennifer Lee             "xyz.openbmc_project.Network.DHCPConfiguration", propertyName,
1302da131a9aSJennifer Lee             std::variant<bool>{value});
1303da131a9aSJennifer Lee     }
1304d577665bSRatan Gupta 
13051f8c7b5dSJohnathan Mantey     void handleDHCPPatch(const std::string& ifaceId,
13061f8c7b5dSJohnathan Mantey                          const EthernetInterfaceData& ethData,
1307f23b7296SEd Tanous                          const DHCPParameters& v4dhcpParms,
1308f23b7296SEd Tanous                          const DHCPParameters& v6dhcpParms,
13098d1b46d7Szhanghch05                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1310da131a9aSJennifer Lee     {
13111f8c7b5dSJohnathan Mantey         bool ipv4Active = translateDHCPEnabledToBool(ethData.DHCPEnabled, true);
13121f8c7b5dSJohnathan Mantey         bool ipv6Active =
13131f8c7b5dSJohnathan Mantey             translateDHCPEnabledToBool(ethData.DHCPEnabled, false);
1314da131a9aSJennifer Lee 
13151f8c7b5dSJohnathan Mantey         bool nextv4DHCPState =
13161f8c7b5dSJohnathan Mantey             v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active;
13171f8c7b5dSJohnathan Mantey 
13181f8c7b5dSJohnathan Mantey         bool nextv6DHCPState{};
13191f8c7b5dSJohnathan Mantey         if (v6dhcpParms.dhcpv6OperatingMode)
1320da131a9aSJennifer Lee         {
13211f8c7b5dSJohnathan Mantey             if ((*v6dhcpParms.dhcpv6OperatingMode != "Stateful") &&
13221f8c7b5dSJohnathan Mantey                 (*v6dhcpParms.dhcpv6OperatingMode != "Stateless") &&
13231f8c7b5dSJohnathan Mantey                 (*v6dhcpParms.dhcpv6OperatingMode != "Disabled"))
13241f8c7b5dSJohnathan Mantey             {
13251f8c7b5dSJohnathan Mantey                 messages::propertyValueFormatError(
13261f8c7b5dSJohnathan Mantey                     asyncResp->res, *v6dhcpParms.dhcpv6OperatingMode,
13271f8c7b5dSJohnathan Mantey                     "OperatingMode");
1328da131a9aSJennifer Lee                 return;
1329da131a9aSJennifer Lee             }
13301f8c7b5dSJohnathan Mantey             nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Stateful");
13311f8c7b5dSJohnathan Mantey         }
13321f8c7b5dSJohnathan Mantey         else
1333da131a9aSJennifer Lee         {
13341f8c7b5dSJohnathan Mantey             nextv6DHCPState = ipv6Active;
13351f8c7b5dSJohnathan Mantey         }
13361f8c7b5dSJohnathan Mantey 
13371f8c7b5dSJohnathan Mantey         bool nextDNS{};
13381f8c7b5dSJohnathan Mantey         if (v4dhcpParms.useDNSServers && v6dhcpParms.useDNSServers)
13391f8c7b5dSJohnathan Mantey         {
13401f8c7b5dSJohnathan Mantey             if (*v4dhcpParms.useDNSServers != *v6dhcpParms.useDNSServers)
13411f8c7b5dSJohnathan Mantey             {
13421f8c7b5dSJohnathan Mantey                 messages::generalError(asyncResp->res);
13431f8c7b5dSJohnathan Mantey                 return;
13441f8c7b5dSJohnathan Mantey             }
13451f8c7b5dSJohnathan Mantey             nextDNS = *v4dhcpParms.useDNSServers;
13461f8c7b5dSJohnathan Mantey         }
13471f8c7b5dSJohnathan Mantey         else if (v4dhcpParms.useDNSServers)
13481f8c7b5dSJohnathan Mantey         {
13491f8c7b5dSJohnathan Mantey             nextDNS = *v4dhcpParms.useDNSServers;
13501f8c7b5dSJohnathan Mantey         }
13511f8c7b5dSJohnathan Mantey         else if (v6dhcpParms.useDNSServers)
13521f8c7b5dSJohnathan Mantey         {
13531f8c7b5dSJohnathan Mantey             nextDNS = *v6dhcpParms.useDNSServers;
13541f8c7b5dSJohnathan Mantey         }
13551f8c7b5dSJohnathan Mantey         else
13561f8c7b5dSJohnathan Mantey         {
13571f8c7b5dSJohnathan Mantey             nextDNS = ethData.DNSEnabled;
13581f8c7b5dSJohnathan Mantey         }
13591f8c7b5dSJohnathan Mantey 
13601f8c7b5dSJohnathan Mantey         bool nextNTP{};
13611f8c7b5dSJohnathan Mantey         if (v4dhcpParms.useNTPServers && v6dhcpParms.useNTPServers)
13621f8c7b5dSJohnathan Mantey         {
13631f8c7b5dSJohnathan Mantey             if (*v4dhcpParms.useNTPServers != *v6dhcpParms.useNTPServers)
13641f8c7b5dSJohnathan Mantey             {
13651f8c7b5dSJohnathan Mantey                 messages::generalError(asyncResp->res);
13661f8c7b5dSJohnathan Mantey                 return;
13671f8c7b5dSJohnathan Mantey             }
13681f8c7b5dSJohnathan Mantey             nextNTP = *v4dhcpParms.useNTPServers;
13691f8c7b5dSJohnathan Mantey         }
13701f8c7b5dSJohnathan Mantey         else if (v4dhcpParms.useNTPServers)
13711f8c7b5dSJohnathan Mantey         {
13721f8c7b5dSJohnathan Mantey             nextNTP = *v4dhcpParms.useNTPServers;
13731f8c7b5dSJohnathan Mantey         }
13741f8c7b5dSJohnathan Mantey         else if (v6dhcpParms.useNTPServers)
13751f8c7b5dSJohnathan Mantey         {
13761f8c7b5dSJohnathan Mantey             nextNTP = *v6dhcpParms.useNTPServers;
13771f8c7b5dSJohnathan Mantey         }
13781f8c7b5dSJohnathan Mantey         else
13791f8c7b5dSJohnathan Mantey         {
13801f8c7b5dSJohnathan Mantey             nextNTP = ethData.NTPEnabled;
13811f8c7b5dSJohnathan Mantey         }
13821f8c7b5dSJohnathan Mantey 
13831f8c7b5dSJohnathan Mantey         bool nextUseDomain{};
13841f8c7b5dSJohnathan Mantey         if (v4dhcpParms.useUseDomainName && v6dhcpParms.useUseDomainName)
13851f8c7b5dSJohnathan Mantey         {
13861f8c7b5dSJohnathan Mantey             if (*v4dhcpParms.useUseDomainName != *v6dhcpParms.useUseDomainName)
13871f8c7b5dSJohnathan Mantey             {
13881f8c7b5dSJohnathan Mantey                 messages::generalError(asyncResp->res);
13891f8c7b5dSJohnathan Mantey                 return;
13901f8c7b5dSJohnathan Mantey             }
13911f8c7b5dSJohnathan Mantey             nextUseDomain = *v4dhcpParms.useUseDomainName;
13921f8c7b5dSJohnathan Mantey         }
13931f8c7b5dSJohnathan Mantey         else if (v4dhcpParms.useUseDomainName)
13941f8c7b5dSJohnathan Mantey         {
13951f8c7b5dSJohnathan Mantey             nextUseDomain = *v4dhcpParms.useUseDomainName;
13961f8c7b5dSJohnathan Mantey         }
13971f8c7b5dSJohnathan Mantey         else if (v6dhcpParms.useUseDomainName)
13981f8c7b5dSJohnathan Mantey         {
13991f8c7b5dSJohnathan Mantey             nextUseDomain = *v6dhcpParms.useUseDomainName;
14001f8c7b5dSJohnathan Mantey         }
14011f8c7b5dSJohnathan Mantey         else
14021f8c7b5dSJohnathan Mantey         {
14031f8c7b5dSJohnathan Mantey             nextUseDomain = ethData.HostNameEnabled;
14041f8c7b5dSJohnathan Mantey         }
14051f8c7b5dSJohnathan Mantey 
1406da131a9aSJennifer Lee         BMCWEB_LOG_DEBUG << "set DHCPEnabled...";
14071f8c7b5dSJohnathan Mantey         setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
14081f8c7b5dSJohnathan Mantey                        asyncResp);
1409da131a9aSJennifer Lee         BMCWEB_LOG_DEBUG << "set DNSEnabled...";
14101f8c7b5dSJohnathan Mantey         setDHCPv4Config("DNSEnabled", nextDNS, asyncResp);
1411da131a9aSJennifer Lee         BMCWEB_LOG_DEBUG << "set NTPEnabled...";
14121f8c7b5dSJohnathan Mantey         setDHCPv4Config("NTPEnabled", nextNTP, asyncResp);
14131f8c7b5dSJohnathan Mantey         BMCWEB_LOG_DEBUG << "set HostNameEnabled...";
14141f8c7b5dSJohnathan Mantey         setDHCPv4Config("HostNameEnabled", nextUseDomain, asyncResp);
1415da131a9aSJennifer Lee     }
141601784826SJohnathan Mantey 
141701784826SJohnathan Mantey     boost::container::flat_set<IPv4AddressData>::const_iterator
14182c70f800SEd Tanous         getNextStaticIpEntry(
141917a897dfSManojkiran Eda             const boost::container::flat_set<IPv4AddressData>::const_iterator&
142017a897dfSManojkiran Eda                 head,
1421b5a76932SEd Tanous             const boost::container::flat_set<IPv4AddressData>::const_iterator&
1422b5a76932SEd Tanous                 end)
142301784826SJohnathan Mantey     {
142417a897dfSManojkiran Eda         return std::find_if(head, end, [](const IPv4AddressData& value) {
142517a897dfSManojkiran Eda             return value.origin == "Static";
142617a897dfSManojkiran Eda         });
142701784826SJohnathan Mantey     }
142801784826SJohnathan Mantey 
142901784826SJohnathan Mantey     boost::container::flat_set<IPv6AddressData>::const_iterator
14302c70f800SEd Tanous         getNextStaticIpEntry(
143117a897dfSManojkiran Eda             const boost::container::flat_set<IPv6AddressData>::const_iterator&
143217a897dfSManojkiran Eda                 head,
1433b5a76932SEd Tanous             const boost::container::flat_set<IPv6AddressData>::const_iterator&
1434b5a76932SEd Tanous                 end)
143501784826SJohnathan Mantey     {
143617a897dfSManojkiran Eda         return std::find_if(head, end, [](const IPv6AddressData& value) {
143717a897dfSManojkiran Eda             return value.origin == "Static";
143817a897dfSManojkiran Eda         });
143901784826SJohnathan Mantey     }
144001784826SJohnathan Mantey 
1441d1d50814SRavi Teja     void handleIPv4StaticPatch(
1442f476acbfSRatan Gupta         const std::string& ifaceId, nlohmann::json& input,
144301784826SJohnathan Mantey         const boost::container::flat_set<IPv4AddressData>& ipv4Data,
14448d1b46d7Szhanghch05         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
14451abe55efSEd Tanous     {
144601784826SJohnathan Mantey         if ((!input.is_array()) || input.empty())
1447f476acbfSRatan Gupta         {
144871f52d96SEd Tanous             messages::propertyValueTypeError(
144971f52d96SEd Tanous                 asyncResp->res,
145071f52d96SEd Tanous                 input.dump(2, ' ', true,
145171f52d96SEd Tanous                            nlohmann::json::error_handler_t::replace),
1452d1d50814SRavi Teja                 "IPv4StaticAddresses");
1453f476acbfSRatan Gupta             return;
1454f476acbfSRatan Gupta         }
1455f476acbfSRatan Gupta 
1456271584abSEd Tanous         unsigned entryIdx = 1;
145701784826SJohnathan Mantey         // Find the first static IP address currently active on the NIC and
145801784826SJohnathan Mantey         // match it to the first JSON element in the IPv4StaticAddresses array.
145901784826SJohnathan Mantey         // Match each subsequent JSON element to the next static IP programmed
146001784826SJohnathan Mantey         // into the NIC.
14612c70f800SEd Tanous         boost::container::flat_set<IPv4AddressData>::const_iterator niciPentry =
14622c70f800SEd Tanous             getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend());
146301784826SJohnathan Mantey 
1464537174c4SEd Tanous         for (nlohmann::json& thisJson : input)
14651abe55efSEd Tanous         {
14664a0cb85cSEd Tanous             std::string pathString =
1467d1d50814SRavi Teja                 "IPv4StaticAddresses/" + std::to_string(entryIdx);
1468179db1d7SKowalski, Kamil 
146901784826SJohnathan Mantey             if (!thisJson.is_null() && !thisJson.empty())
1470f476acbfSRatan Gupta             {
1471537174c4SEd Tanous                 std::optional<std::string> address;
1472537174c4SEd Tanous                 std::optional<std::string> subnetMask;
1473537174c4SEd Tanous                 std::optional<std::string> gateway;
1474537174c4SEd Tanous 
1475537174c4SEd Tanous                 if (!json_util::readJson(thisJson, asyncResp->res, "Address",
14767e27d832SJohnathan Mantey                                          address, "SubnetMask", subnetMask,
14777e27d832SJohnathan Mantey                                          "Gateway", gateway))
1478537174c4SEd Tanous                 {
147901784826SJohnathan Mantey                     messages::propertyValueFormatError(
148071f52d96SEd Tanous                         asyncResp->res,
148171f52d96SEd Tanous                         thisJson.dump(2, ' ', true,
148271f52d96SEd Tanous                                       nlohmann::json::error_handler_t::replace),
148371f52d96SEd Tanous                         pathString);
1484537174c4SEd Tanous                     return;
1485179db1d7SKowalski, Kamil                 }
1486179db1d7SKowalski, Kamil 
148701784826SJohnathan Mantey                 // Find the address/subnet/gateway values. Any values that are
148801784826SJohnathan Mantey                 // not explicitly provided are assumed to be unmodified from the
148901784826SJohnathan Mantey                 // current state of the interface. Merge existing state into the
149001784826SJohnathan Mantey                 // current request.
1491271584abSEd Tanous                 const std::string* addr = nullptr;
1492271584abSEd Tanous                 const std::string* gw = nullptr;
149301784826SJohnathan Mantey                 uint8_t prefixLength = 0;
149401784826SJohnathan Mantey                 bool errorInEntry = false;
1495537174c4SEd Tanous                 if (address)
14961abe55efSEd Tanous                 {
149701784826SJohnathan Mantey                     if (ipv4VerifyIpAndGetBitcount(*address))
14981abe55efSEd Tanous                     {
149901784826SJohnathan Mantey                         addr = &(*address);
15004a0cb85cSEd Tanous                     }
150101784826SJohnathan Mantey                     else
150201784826SJohnathan Mantey                     {
150301784826SJohnathan Mantey                         messages::propertyValueFormatError(
150401784826SJohnathan Mantey                             asyncResp->res, *address, pathString + "/Address");
150501784826SJohnathan Mantey                         errorInEntry = true;
150601784826SJohnathan Mantey                     }
150701784826SJohnathan Mantey                 }
15082c70f800SEd Tanous                 else if (niciPentry != ipv4Data.cend())
150901784826SJohnathan Mantey                 {
15102c70f800SEd Tanous                     addr = &(niciPentry->address);
151101784826SJohnathan Mantey                 }
151201784826SJohnathan Mantey                 else
151301784826SJohnathan Mantey                 {
151401784826SJohnathan Mantey                     messages::propertyMissing(asyncResp->res,
151501784826SJohnathan Mantey                                               pathString + "/Address");
151601784826SJohnathan Mantey                     errorInEntry = true;
15174a0cb85cSEd Tanous                 }
15184a0cb85cSEd Tanous 
1519537174c4SEd Tanous                 if (subnetMask)
15204a0cb85cSEd Tanous                 {
1521537174c4SEd Tanous                     if (!ipv4VerifyIpAndGetBitcount(*subnetMask, &prefixLength))
15224a0cb85cSEd Tanous                     {
1523f12894f8SJason M. Bills                         messages::propertyValueFormatError(
1524537174c4SEd Tanous                             asyncResp->res, *subnetMask,
15254a0cb85cSEd Tanous                             pathString + "/SubnetMask");
152601784826SJohnathan Mantey                         errorInEntry = true;
15274a0cb85cSEd Tanous                     }
15284a0cb85cSEd Tanous                 }
15292c70f800SEd Tanous                 else if (niciPentry != ipv4Data.cend())
15304a0cb85cSEd Tanous                 {
15312c70f800SEd Tanous                     if (!ipv4VerifyIpAndGetBitcount(niciPentry->netmask,
153201784826SJohnathan Mantey                                                     &prefixLength))
15334a0cb85cSEd Tanous                     {
153401784826SJohnathan Mantey                         messages::propertyValueFormatError(
15352c70f800SEd Tanous                             asyncResp->res, niciPentry->netmask,
153601784826SJohnathan Mantey                             pathString + "/SubnetMask");
153701784826SJohnathan Mantey                         errorInEntry = true;
15384a0cb85cSEd Tanous                     }
15394a0cb85cSEd Tanous                 }
15401abe55efSEd Tanous                 else
15411abe55efSEd Tanous                 {
154201784826SJohnathan Mantey                     messages::propertyMissing(asyncResp->res,
154301784826SJohnathan Mantey                                               pathString + "/SubnetMask");
154401784826SJohnathan Mantey                     errorInEntry = true;
154501784826SJohnathan Mantey                 }
154601784826SJohnathan Mantey 
154701784826SJohnathan Mantey                 if (gateway)
154801784826SJohnathan Mantey                 {
154901784826SJohnathan Mantey                     if (ipv4VerifyIpAndGetBitcount(*gateway))
155001784826SJohnathan Mantey                     {
155101784826SJohnathan Mantey                         gw = &(*gateway);
155201784826SJohnathan Mantey                     }
155301784826SJohnathan Mantey                     else
155401784826SJohnathan Mantey                     {
155501784826SJohnathan Mantey                         messages::propertyValueFormatError(
155601784826SJohnathan Mantey                             asyncResp->res, *gateway, pathString + "/Gateway");
155701784826SJohnathan Mantey                         errorInEntry = true;
155801784826SJohnathan Mantey                     }
155901784826SJohnathan Mantey                 }
15602c70f800SEd Tanous                 else if (niciPentry != ipv4Data.cend())
156101784826SJohnathan Mantey                 {
15622c70f800SEd Tanous                     gw = &niciPentry->gateway;
156301784826SJohnathan Mantey                 }
156401784826SJohnathan Mantey                 else
15651abe55efSEd Tanous                 {
1566a08b46ccSJason M. Bills                     messages::propertyMissing(asyncResp->res,
15674a0cb85cSEd Tanous                                               pathString + "/Gateway");
156801784826SJohnathan Mantey                     errorInEntry = true;
15694a0cb85cSEd Tanous                 }
15704a0cb85cSEd Tanous 
157101784826SJohnathan Mantey                 if (errorInEntry)
15721abe55efSEd Tanous                 {
157301784826SJohnathan Mantey                     return;
15744a0cb85cSEd Tanous                 }
15754a0cb85cSEd Tanous 
15762c70f800SEd Tanous                 if (niciPentry != ipv4Data.cend())
15771abe55efSEd Tanous                 {
15782c70f800SEd Tanous                     deleteAndCreateIPv4(ifaceId, niciPentry->id, prefixLength,
157901784826SJohnathan Mantey                                         *gw, *addr, asyncResp);
15802c70f800SEd Tanous                     niciPentry =
15812c70f800SEd Tanous                         getNextStaticIpEntry(++niciPentry, ipv4Data.cend());
1582588c3f0dSKowalski, Kamil                 }
158301784826SJohnathan Mantey                 else
158401784826SJohnathan Mantey                 {
1585cb13a392SEd Tanous                     createIPv4(ifaceId, prefixLength, *gateway, *address,
1586cb13a392SEd Tanous                                asyncResp);
15874a0cb85cSEd Tanous                 }
15884a0cb85cSEd Tanous                 entryIdx++;
15894a0cb85cSEd Tanous             }
159001784826SJohnathan Mantey             else
159101784826SJohnathan Mantey             {
15922c70f800SEd Tanous                 if (niciPentry == ipv4Data.cend())
159301784826SJohnathan Mantey                 {
159401784826SJohnathan Mantey                     // Requesting a DELETE/DO NOT MODIFY action for an item
159501784826SJohnathan Mantey                     // that isn't present on the eth(n) interface. Input JSON is
159601784826SJohnathan Mantey                     // in error, so bail out.
159701784826SJohnathan Mantey                     if (thisJson.is_null())
159801784826SJohnathan Mantey                     {
159901784826SJohnathan Mantey                         messages::resourceCannotBeDeleted(asyncResp->res);
160001784826SJohnathan Mantey                         return;
160101784826SJohnathan Mantey                     }
160201784826SJohnathan Mantey                     messages::propertyValueFormatError(
160371f52d96SEd Tanous                         asyncResp->res,
160471f52d96SEd Tanous                         thisJson.dump(2, ' ', true,
160571f52d96SEd Tanous                                       nlohmann::json::error_handler_t::replace),
160671f52d96SEd Tanous                         pathString);
160701784826SJohnathan Mantey                     return;
160801784826SJohnathan Mantey                 }
160901784826SJohnathan Mantey 
161001784826SJohnathan Mantey                 if (thisJson.is_null())
161101784826SJohnathan Mantey                 {
16122c70f800SEd Tanous                     deleteIPv4(ifaceId, niciPentry->id, asyncResp);
161301784826SJohnathan Mantey                 }
16142c70f800SEd Tanous                 if (niciPentry != ipv4Data.cend())
161501784826SJohnathan Mantey                 {
16162c70f800SEd Tanous                     niciPentry =
16172c70f800SEd Tanous                         getNextStaticIpEntry(++niciPentry, ipv4Data.cend());
161801784826SJohnathan Mantey                 }
161901784826SJohnathan Mantey                 entryIdx++;
162001784826SJohnathan Mantey             }
162101784826SJohnathan Mantey         }
16224a0cb85cSEd Tanous     }
16234a0cb85cSEd Tanous 
1624f85837bfSRAJESWARAN THILLAIGOVINDAN     void handleStaticNameServersPatch(
1625f85837bfSRAJESWARAN THILLAIGOVINDAN         const std::string& ifaceId,
1626f85837bfSRAJESWARAN THILLAIGOVINDAN         const std::vector<std::string>& updatedStaticNameServers,
16278d1b46d7Szhanghch05         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1628f85837bfSRAJESWARAN THILLAIGOVINDAN     {
1629f85837bfSRAJESWARAN THILLAIGOVINDAN         crow::connections::systemBus->async_method_call(
1630286b9118SJohnathan Mantey             [asyncResp](const boost::system::error_code ec) {
1631f85837bfSRAJESWARAN THILLAIGOVINDAN                 if (ec)
1632f85837bfSRAJESWARAN THILLAIGOVINDAN                 {
1633f85837bfSRAJESWARAN THILLAIGOVINDAN                     messages::internalError(asyncResp->res);
1634f85837bfSRAJESWARAN THILLAIGOVINDAN                     return;
1635f85837bfSRAJESWARAN THILLAIGOVINDAN                 }
1636f85837bfSRAJESWARAN THILLAIGOVINDAN             },
1637f85837bfSRAJESWARAN THILLAIGOVINDAN             "xyz.openbmc_project.Network",
1638f85837bfSRAJESWARAN THILLAIGOVINDAN             "/xyz/openbmc_project/network/" + ifaceId,
1639f85837bfSRAJESWARAN THILLAIGOVINDAN             "org.freedesktop.DBus.Properties", "Set",
16400f6efdc1Smanojkiran.eda@gmail.com             "xyz.openbmc_project.Network.EthernetInterface",
16410f6efdc1Smanojkiran.eda@gmail.com             "StaticNameServers",
1642f85837bfSRAJESWARAN THILLAIGOVINDAN             std::variant<std::vector<std::string>>{updatedStaticNameServers});
1643f85837bfSRAJESWARAN THILLAIGOVINDAN     }
1644f85837bfSRAJESWARAN THILLAIGOVINDAN 
1645e48c0fc5SRavi Teja     void handleIPv6StaticAddressesPatch(
1646f23b7296SEd Tanous         const std::string& ifaceId, const nlohmann::json& input,
164701784826SJohnathan Mantey         const boost::container::flat_set<IPv6AddressData>& ipv6Data,
16488d1b46d7Szhanghch05         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1649e48c0fc5SRavi Teja     {
165001784826SJohnathan Mantey         if (!input.is_array() || input.empty())
1651e48c0fc5SRavi Teja         {
165271f52d96SEd Tanous             messages::propertyValueTypeError(
165371f52d96SEd Tanous                 asyncResp->res,
165471f52d96SEd Tanous                 input.dump(2, ' ', true,
165571f52d96SEd Tanous                            nlohmann::json::error_handler_t::replace),
1656e48c0fc5SRavi Teja                 "IPv6StaticAddresses");
1657e48c0fc5SRavi Teja             return;
1658e48c0fc5SRavi Teja         }
1659271584abSEd Tanous         size_t entryIdx = 1;
16602c70f800SEd Tanous         boost::container::flat_set<IPv6AddressData>::const_iterator niciPentry =
16612c70f800SEd Tanous             getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend());
1662f23b7296SEd Tanous         for (const nlohmann::json& thisJson : input)
1663e48c0fc5SRavi Teja         {
1664e48c0fc5SRavi Teja             std::string pathString =
1665e48c0fc5SRavi Teja                 "IPv6StaticAddresses/" + std::to_string(entryIdx);
1666e48c0fc5SRavi Teja 
166701784826SJohnathan Mantey             if (!thisJson.is_null() && !thisJson.empty())
1668e48c0fc5SRavi Teja             {
1669e48c0fc5SRavi Teja                 std::optional<std::string> address;
1670e48c0fc5SRavi Teja                 std::optional<uint8_t> prefixLength;
1671f23b7296SEd Tanous                 nlohmann::json thisJsonCopy = thisJson;
1672f23b7296SEd Tanous                 if (!json_util::readJson(thisJsonCopy, asyncResp->res,
1673f23b7296SEd Tanous                                          "Address", address, "PrefixLength",
1674f23b7296SEd Tanous                                          prefixLength))
1675e48c0fc5SRavi Teja                 {
167601784826SJohnathan Mantey                     messages::propertyValueFormatError(
167771f52d96SEd Tanous                         asyncResp->res,
167871f52d96SEd Tanous                         thisJson.dump(2, ' ', true,
167971f52d96SEd Tanous                                       nlohmann::json::error_handler_t::replace),
168071f52d96SEd Tanous                         pathString);
1681e48c0fc5SRavi Teja                     return;
1682e48c0fc5SRavi Teja                 }
1683e48c0fc5SRavi Teja 
168401784826SJohnathan Mantey                 const std::string* addr;
168501784826SJohnathan Mantey                 uint8_t prefix;
168601784826SJohnathan Mantey 
168701784826SJohnathan Mantey                 // Find the address and prefixLength values. Any values that are
168801784826SJohnathan Mantey                 // not explicitly provided are assumed to be unmodified from the
168901784826SJohnathan Mantey                 // current state of the interface. Merge existing state into the
169001784826SJohnathan Mantey                 // current request.
1691e48c0fc5SRavi Teja                 if (address)
1692e48c0fc5SRavi Teja                 {
169301784826SJohnathan Mantey                     addr = &(*address);
1694e48c0fc5SRavi Teja                 }
16952c70f800SEd Tanous                 else if (niciPentry != ipv6Data.end())
169601784826SJohnathan Mantey                 {
16972c70f800SEd Tanous                     addr = &(niciPentry->address);
169801784826SJohnathan Mantey                 }
169901784826SJohnathan Mantey                 else
170001784826SJohnathan Mantey                 {
170101784826SJohnathan Mantey                     messages::propertyMissing(asyncResp->res,
170201784826SJohnathan Mantey                                               pathString + "/Address");
170301784826SJohnathan Mantey                     return;
1704e48c0fc5SRavi Teja                 }
1705e48c0fc5SRavi Teja 
1706e48c0fc5SRavi Teja                 if (prefixLength)
1707e48c0fc5SRavi Teja                 {
170801784826SJohnathan Mantey                     prefix = *prefixLength;
170901784826SJohnathan Mantey                 }
17102c70f800SEd Tanous                 else if (niciPentry != ipv6Data.end())
1711e48c0fc5SRavi Teja                 {
17122c70f800SEd Tanous                     prefix = niciPentry->prefixLength;
1713e48c0fc5SRavi Teja                 }
1714e48c0fc5SRavi Teja                 else
1715e48c0fc5SRavi Teja                 {
1716e48c0fc5SRavi Teja                     messages::propertyMissing(asyncResp->res,
1717e48c0fc5SRavi Teja                                               pathString + "/PrefixLength");
171801784826SJohnathan Mantey                     return;
1719e48c0fc5SRavi Teja                 }
1720e48c0fc5SRavi Teja 
17212c70f800SEd Tanous                 if (niciPentry != ipv6Data.end())
1722e48c0fc5SRavi Teja                 {
17232c70f800SEd Tanous                     deleteAndCreateIPv6(ifaceId, niciPentry->id, prefix, *addr,
1724e48c0fc5SRavi Teja                                         asyncResp);
17252c70f800SEd Tanous                     niciPentry =
17262c70f800SEd Tanous                         getNextStaticIpEntry(++niciPentry, ipv6Data.cend());
172701784826SJohnathan Mantey                 }
172801784826SJohnathan Mantey                 else
172901784826SJohnathan Mantey                 {
173001784826SJohnathan Mantey                     createIPv6(ifaceId, *prefixLength, *addr, asyncResp);
1731e48c0fc5SRavi Teja                 }
1732e48c0fc5SRavi Teja                 entryIdx++;
1733e48c0fc5SRavi Teja             }
173401784826SJohnathan Mantey             else
173501784826SJohnathan Mantey             {
17362c70f800SEd Tanous                 if (niciPentry == ipv6Data.end())
173701784826SJohnathan Mantey                 {
173801784826SJohnathan Mantey                     // Requesting a DELETE/DO NOT MODIFY action for an item
173901784826SJohnathan Mantey                     // that isn't present on the eth(n) interface. Input JSON is
174001784826SJohnathan Mantey                     // in error, so bail out.
174101784826SJohnathan Mantey                     if (thisJson.is_null())
174201784826SJohnathan Mantey                     {
174301784826SJohnathan Mantey                         messages::resourceCannotBeDeleted(asyncResp->res);
174401784826SJohnathan Mantey                         return;
174501784826SJohnathan Mantey                     }
174601784826SJohnathan Mantey                     messages::propertyValueFormatError(
174771f52d96SEd Tanous                         asyncResp->res,
174871f52d96SEd Tanous                         thisJson.dump(2, ' ', true,
174971f52d96SEd Tanous                                       nlohmann::json::error_handler_t::replace),
175071f52d96SEd Tanous                         pathString);
175101784826SJohnathan Mantey                     return;
175201784826SJohnathan Mantey                 }
175301784826SJohnathan Mantey 
175401784826SJohnathan Mantey                 if (thisJson.is_null())
175501784826SJohnathan Mantey                 {
17562c70f800SEd Tanous                     deleteIPv6(ifaceId, niciPentry->id, asyncResp);
175701784826SJohnathan Mantey                 }
17582c70f800SEd Tanous                 if (niciPentry != ipv6Data.cend())
175901784826SJohnathan Mantey                 {
17602c70f800SEd Tanous                     niciPentry =
17612c70f800SEd Tanous                         getNextStaticIpEntry(++niciPentry, ipv6Data.cend());
176201784826SJohnathan Mantey                 }
176301784826SJohnathan Mantey                 entryIdx++;
176401784826SJohnathan Mantey             }
176501784826SJohnathan Mantey         }
1766e48c0fc5SRavi Teja     }
1767e48c0fc5SRavi Teja 
17680f74e643SEd Tanous     void parseInterfaceData(
17698d1b46d7Szhanghch05         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
17708d1b46d7Szhanghch05         const std::string& ifaceId, const EthernetInterfaceData& ethData,
1771e48c0fc5SRavi Teja         const boost::container::flat_set<IPv4AddressData>& ipv4Data,
177201784826SJohnathan Mantey         const boost::container::flat_set<IPv6AddressData>& ipv6Data)
17734a0cb85cSEd Tanous     {
1774eeedda23SJohnathan Mantey         constexpr const std::array<const char*, 1> inventoryForEthernet = {
1775eeedda23SJohnathan Mantey             "xyz.openbmc_project.Inventory.Item.Ethernet"};
1776eeedda23SJohnathan Mantey 
17772c70f800SEd Tanous         nlohmann::json& jsonResponse = asyncResp->res.jsonValue;
177881ce609eSEd Tanous         jsonResponse["Id"] = ifaceId;
17792c70f800SEd Tanous         jsonResponse["@odata.id"] =
178081ce609eSEd Tanous             "/redfish/v1/Managers/bmc/EthernetInterfaces/" + ifaceId;
17812c70f800SEd Tanous         jsonResponse["InterfaceEnabled"] = ethData.nicEnabled;
1782eeedda23SJohnathan Mantey 
1783eeedda23SJohnathan Mantey         auto health = std::make_shared<HealthPopulate>(asyncResp);
1784eeedda23SJohnathan Mantey 
1785eeedda23SJohnathan Mantey         crow::connections::systemBus->async_method_call(
1786eeedda23SJohnathan Mantey             [health](const boost::system::error_code ec,
1787eeedda23SJohnathan Mantey                      std::vector<std::string>& resp) {
1788eeedda23SJohnathan Mantey                 if (ec)
1789029573d4SEd Tanous                 {
1790eeedda23SJohnathan Mantey                     return;
1791eeedda23SJohnathan Mantey                 }
1792eeedda23SJohnathan Mantey 
1793eeedda23SJohnathan Mantey                 health->inventory = std::move(resp);
1794eeedda23SJohnathan Mantey             },
1795eeedda23SJohnathan Mantey             "xyz.openbmc_project.ObjectMapper",
1796eeedda23SJohnathan Mantey             "/xyz/openbmc_project/object_mapper",
1797eeedda23SJohnathan Mantey             "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/",
1798eeedda23SJohnathan Mantey             int32_t(0), inventoryForEthernet);
1799eeedda23SJohnathan Mantey 
1800eeedda23SJohnathan Mantey         health->populate();
1801eeedda23SJohnathan Mantey 
1802eeedda23SJohnathan Mantey         if (ethData.nicEnabled)
1803eeedda23SJohnathan Mantey         {
18042c70f800SEd Tanous             jsonResponse["LinkStatus"] = "LinkUp";
18052c70f800SEd Tanous             jsonResponse["Status"]["State"] = "Enabled";
1806029573d4SEd Tanous         }
1807029573d4SEd Tanous         else
1808029573d4SEd Tanous         {
18092c70f800SEd Tanous             jsonResponse["LinkStatus"] = "NoLink";
18102c70f800SEd Tanous             jsonResponse["Status"]["State"] = "Disabled";
1811029573d4SEd Tanous         }
1812aa05fb27SJohnathan Mantey 
18132c70f800SEd Tanous         jsonResponse["LinkStatus"] = ethData.linkUp ? "LinkUp" : "LinkDown";
18142c70f800SEd Tanous         jsonResponse["SpeedMbps"] = ethData.speed;
18152c70f800SEd Tanous         jsonResponse["MACAddress"] = ethData.mac_address;
18162c70f800SEd Tanous         jsonResponse["DHCPv4"]["DHCPEnabled"] =
18171f8c7b5dSJohnathan Mantey             translateDHCPEnabledToBool(ethData.DHCPEnabled, true);
18182c70f800SEd Tanous         jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.NTPEnabled;
18192c70f800SEd Tanous         jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.DNSEnabled;
18202c70f800SEd Tanous         jsonResponse["DHCPv4"]["UseDomainName"] = ethData.HostNameEnabled;
18211f8c7b5dSJohnathan Mantey 
18222c70f800SEd Tanous         jsonResponse["DHCPv6"]["OperatingMode"] =
18231f8c7b5dSJohnathan Mantey             translateDHCPEnabledToBool(ethData.DHCPEnabled, false) ? "Stateful"
18241f8c7b5dSJohnathan Mantey                                                                    : "Disabled";
18252c70f800SEd Tanous         jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.NTPEnabled;
18262c70f800SEd Tanous         jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.DNSEnabled;
18272c70f800SEd Tanous         jsonResponse["DHCPv6"]["UseDomainName"] = ethData.HostNameEnabled;
18282a133282Smanojkiraneda 
18294a0cb85cSEd Tanous         if (!ethData.hostname.empty())
18304a0cb85cSEd Tanous         {
18312c70f800SEd Tanous             jsonResponse["HostName"] = ethData.hostname;
1832ab6554f1SJoshi-Mansi 
1833ab6554f1SJoshi-Mansi             // When domain name is empty then it means, that it is a network
1834ab6554f1SJoshi-Mansi             // without domain names, and the host name itself must be treated as
1835ab6554f1SJoshi-Mansi             // FQDN
1836f23b7296SEd Tanous             std::string fqdn = ethData.hostname;
1837d24bfc7aSJennifer Lee             if (!ethData.domainnames.empty())
1838d24bfc7aSJennifer Lee             {
18392c70f800SEd Tanous                 fqdn += "." + ethData.domainnames[0];
1840d24bfc7aSJennifer Lee             }
18412c70f800SEd Tanous             jsonResponse["FQDN"] = fqdn;
18424a0cb85cSEd Tanous         }
18434a0cb85cSEd Tanous 
18442c70f800SEd Tanous         jsonResponse["VLANs"] = {
1845fda13ad2SSunitha Harish             {"@odata.id", "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
184681ce609eSEd Tanous                               ifaceId + "/VLANs"}};
1847fda13ad2SSunitha Harish 
18482c70f800SEd Tanous         jsonResponse["NameServers"] = ethData.nameServers;
18492c70f800SEd Tanous         jsonResponse["StaticNameServers"] = ethData.staticNameServers;
18504a0cb85cSEd Tanous 
18512c70f800SEd Tanous         nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"];
18522c70f800SEd Tanous         nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
18532c70f800SEd Tanous         ipv4Array = nlohmann::json::array();
18542c70f800SEd Tanous         ipv4StaticArray = nlohmann::json::array();
18552c70f800SEd Tanous         for (auto& ipv4Config : ipv4Data)
18564a0cb85cSEd Tanous         {
1857fa5053a6SGunnar Mills 
18582c70f800SEd Tanous             std::string gatewayStr = ipv4Config.gateway;
1859fa5053a6SGunnar Mills             if (gatewayStr.empty())
1860fa5053a6SGunnar Mills             {
1861fa5053a6SGunnar Mills                 gatewayStr = "0.0.0.0";
1862fa5053a6SGunnar Mills             }
1863fa5053a6SGunnar Mills 
18642c70f800SEd Tanous             ipv4Array.push_back({{"AddressOrigin", ipv4Config.origin},
18652c70f800SEd Tanous                                  {"SubnetMask", ipv4Config.netmask},
18662c70f800SEd Tanous                                  {"Address", ipv4Config.address},
1867fa5053a6SGunnar Mills                                  {"Gateway", gatewayStr}});
18682c70f800SEd Tanous             if (ipv4Config.origin == "Static")
1869d1d50814SRavi Teja             {
18702c70f800SEd Tanous                 ipv4StaticArray.push_back({{"AddressOrigin", ipv4Config.origin},
18712c70f800SEd Tanous                                            {"SubnetMask", ipv4Config.netmask},
18722c70f800SEd Tanous                                            {"Address", ipv4Config.address},
1873d1d50814SRavi Teja                                            {"Gateway", gatewayStr}});
1874d1d50814SRavi Teja             }
187501784826SJohnathan Mantey         }
1876d1d50814SRavi Teja 
18777ea79e5eSRavi Teja         std::string ipv6GatewayStr = ethData.ipv6_default_gateway;
18787ea79e5eSRavi Teja         if (ipv6GatewayStr.empty())
18797ea79e5eSRavi Teja         {
18807ea79e5eSRavi Teja             ipv6GatewayStr = "0:0:0:0:0:0:0:0";
18817ea79e5eSRavi Teja         }
18827ea79e5eSRavi Teja 
18837ea79e5eSRavi Teja         jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr;
1884e48c0fc5SRavi Teja 
18852c70f800SEd Tanous         nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"];
18862c70f800SEd Tanous         nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"];
18872c70f800SEd Tanous         ipv6Array = nlohmann::json::array();
18882c70f800SEd Tanous         ipv6StaticArray = nlohmann::json::array();
18897f2e23e9SJohnathan Mantey         nlohmann::json& ipv6AddrPolicyTable =
18902c70f800SEd Tanous             jsonResponse["IPv6AddressPolicyTable"];
18917f2e23e9SJohnathan Mantey         ipv6AddrPolicyTable = nlohmann::json::array();
18922c70f800SEd Tanous         for (auto& ipv6Config : ipv6Data)
1893e48c0fc5SRavi Teja         {
18942c70f800SEd Tanous             ipv6Array.push_back({{"Address", ipv6Config.address},
18952c70f800SEd Tanous                                  {"PrefixLength", ipv6Config.prefixLength},
18962c70f800SEd Tanous                                  {"AddressOrigin", ipv6Config.origin},
18975fd16e4bSJohnathan Mantey                                  {"AddressState", nullptr}});
18982c70f800SEd Tanous             if (ipv6Config.origin == "Static")
1899e48c0fc5SRavi Teja             {
19002c70f800SEd Tanous                 ipv6StaticArray.push_back(
19012c70f800SEd Tanous                     {{"Address", ipv6Config.address},
19022c70f800SEd Tanous                      {"PrefixLength", ipv6Config.prefixLength},
19032c70f800SEd Tanous                      {"AddressOrigin", ipv6Config.origin},
19045fd16e4bSJohnathan Mantey                      {"AddressState", nullptr}});
190501784826SJohnathan Mantey             }
1906e48c0fc5SRavi Teja         }
1907588c3f0dSKowalski, Kamil     }
1908588c3f0dSKowalski, Kamil 
19099391bb9cSRapkiewicz, Pawel     /**
19109391bb9cSRapkiewicz, Pawel      * Functions triggers appropriate requests on DBus
19119391bb9cSRapkiewicz, Pawel      */
19128d1b46d7Szhanghch05     void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
19138d1b46d7Szhanghch05                const crow::Request&,
19141abe55efSEd Tanous                const std::vector<std::string>& params) override
19151abe55efSEd Tanous     {
19161abe55efSEd Tanous         if (params.size() != 1)
19171abe55efSEd Tanous         {
1918f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
19199391bb9cSRapkiewicz, Pawel             return;
19209391bb9cSRapkiewicz, Pawel         }
19219391bb9cSRapkiewicz, Pawel 
19224a0cb85cSEd Tanous         getEthernetIfaceData(
19234a0cb85cSEd Tanous             params[0],
19242c70f800SEd Tanous             [this, asyncResp, ifaceId{std::string(params[0])}](
19254a0cb85cSEd Tanous                 const bool& success, const EthernetInterfaceData& ethData,
1926e48c0fc5SRavi Teja                 const boost::container::flat_set<IPv4AddressData>& ipv4Data,
192701784826SJohnathan Mantey                 const boost::container::flat_set<IPv6AddressData>& ipv6Data) {
19284a0cb85cSEd Tanous                 if (!success)
19291abe55efSEd Tanous                 {
19301abe55efSEd Tanous                     // TODO(Pawel)consider distinguish between non existing
19311abe55efSEd Tanous                     // object, and other errors
1932f12894f8SJason M. Bills                     messages::resourceNotFound(asyncResp->res,
19332c70f800SEd Tanous                                                "EthernetInterface", ifaceId);
19344a0cb85cSEd Tanous                     return;
19359391bb9cSRapkiewicz, Pawel                 }
19364c9afe43SEd Tanous 
19370f74e643SEd Tanous                 asyncResp->res.jsonValue["@odata.type"] =
1938fda13ad2SSunitha Harish                     "#EthernetInterface.v1_4_1.EthernetInterface";
19390f74e643SEd Tanous                 asyncResp->res.jsonValue["Name"] = "Manager Ethernet Interface";
19400f74e643SEd Tanous                 asyncResp->res.jsonValue["Description"] =
19410f74e643SEd Tanous                     "Management Network Interface";
19420f74e643SEd Tanous 
19432c70f800SEd Tanous                 parseInterfaceData(asyncResp, ifaceId, ethData, ipv4Data,
1944eeedda23SJohnathan Mantey                                    ipv6Data);
19459391bb9cSRapkiewicz, Pawel             });
19469391bb9cSRapkiewicz, Pawel     }
19479391bb9cSRapkiewicz, Pawel 
19488d1b46d7Szhanghch05     void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
19498d1b46d7Szhanghch05                  const crow::Request& req,
19501abe55efSEd Tanous                  const std::vector<std::string>& params) override
19511abe55efSEd Tanous     {
19528d1b46d7Szhanghch05 
19531abe55efSEd Tanous         if (params.size() != 1)
19541abe55efSEd Tanous         {
1955f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1956588c3f0dSKowalski, Kamil             return;
1957588c3f0dSKowalski, Kamil         }
1958588c3f0dSKowalski, Kamil 
19592c70f800SEd Tanous         const std::string& ifaceId = params[0];
1960588c3f0dSKowalski, Kamil 
1961bc0bd6e0SEd Tanous         std::optional<std::string> hostname;
1962ab6554f1SJoshi-Mansi         std::optional<std::string> fqdn;
1963d577665bSRatan Gupta         std::optional<std::string> macAddress;
19649a6fc6feSRavi Teja         std::optional<std::string> ipv6DefaultGateway;
1965d1d50814SRavi Teja         std::optional<nlohmann::json> ipv4StaticAddresses;
1966e48c0fc5SRavi Teja         std::optional<nlohmann::json> ipv6StaticAddresses;
1967f85837bfSRAJESWARAN THILLAIGOVINDAN         std::optional<std::vector<std::string>> staticNameServers;
1968da131a9aSJennifer Lee         std::optional<nlohmann::json> dhcpv4;
19691f8c7b5dSJohnathan Mantey         std::optional<nlohmann::json> dhcpv6;
1970eeedda23SJohnathan Mantey         std::optional<bool> interfaceEnabled;
19711f8c7b5dSJohnathan Mantey         DHCPParameters v4dhcpParms;
19721f8c7b5dSJohnathan Mantey         DHCPParameters v6dhcpParms;
19730627a2c7SEd Tanous 
19741f8c7b5dSJohnathan Mantey         if (!json_util::readJson(
19758d1b46d7Szhanghch05                 req, asyncResp->res, "HostName", hostname, "FQDN", fqdn,
1976ab6554f1SJoshi-Mansi                 "IPv4StaticAddresses", ipv4StaticAddresses, "MACAddress",
1977ab6554f1SJoshi-Mansi                 macAddress, "StaticNameServers", staticNameServers,
1978ab6554f1SJoshi-Mansi                 "IPv6DefaultGateway", ipv6DefaultGateway, "IPv6StaticAddresses",
1979ab6554f1SJoshi-Mansi                 ipv6StaticAddresses, "DHCPv4", dhcpv4, "DHCPv6", dhcpv6,
1980ab6554f1SJoshi-Mansi                 "InterfaceEnabled", interfaceEnabled))
19811abe55efSEd Tanous         {
1982588c3f0dSKowalski, Kamil             return;
1983588c3f0dSKowalski, Kamil         }
1984da131a9aSJennifer Lee         if (dhcpv4)
1985da131a9aSJennifer Lee         {
19868d1b46d7Szhanghch05             if (!json_util::readJson(*dhcpv4, asyncResp->res, "DHCPEnabled",
19871f8c7b5dSJohnathan Mantey                                      v4dhcpParms.dhcpv4Enabled, "UseDNSServers",
19881f8c7b5dSJohnathan Mantey                                      v4dhcpParms.useDNSServers, "UseNTPServers",
19891f8c7b5dSJohnathan Mantey                                      v4dhcpParms.useNTPServers, "UseDomainName",
19901f8c7b5dSJohnathan Mantey                                      v4dhcpParms.useUseDomainName))
19911f8c7b5dSJohnathan Mantey             {
19921f8c7b5dSJohnathan Mantey                 return;
19931f8c7b5dSJohnathan Mantey             }
19941f8c7b5dSJohnathan Mantey         }
19951f8c7b5dSJohnathan Mantey 
19961f8c7b5dSJohnathan Mantey         if (dhcpv6)
19971f8c7b5dSJohnathan Mantey         {
19988d1b46d7Szhanghch05             if (!json_util::readJson(*dhcpv6, asyncResp->res, "OperatingMode",
19991f8c7b5dSJohnathan Mantey                                      v6dhcpParms.dhcpv6OperatingMode,
20001f8c7b5dSJohnathan Mantey                                      "UseDNSServers", v6dhcpParms.useDNSServers,
20011f8c7b5dSJohnathan Mantey                                      "UseNTPServers", v6dhcpParms.useNTPServers,
20021f8c7b5dSJohnathan Mantey                                      "UseDomainName",
20031f8c7b5dSJohnathan Mantey                                      v6dhcpParms.useUseDomainName))
20041f8c7b5dSJohnathan Mantey             {
20051f8c7b5dSJohnathan Mantey                 return;
20061f8c7b5dSJohnathan Mantey             }
2007da131a9aSJennifer Lee         }
2008da131a9aSJennifer Lee 
200901784826SJohnathan Mantey         // Get single eth interface data, and call the below callback for
201001784826SJohnathan Mantey         // JSON preparation
20114a0cb85cSEd Tanous         getEthernetIfaceData(
20122c70f800SEd Tanous             ifaceId,
20132c70f800SEd Tanous             [this, asyncResp, ifaceId, hostname = std::move(hostname),
2014ab6554f1SJoshi-Mansi              fqdn = std::move(fqdn), macAddress = std::move(macAddress),
2015d1d50814SRavi Teja              ipv4StaticAddresses = std::move(ipv4StaticAddresses),
20169a6fc6feSRavi Teja              ipv6DefaultGateway = std::move(ipv6DefaultGateway),
2017e48c0fc5SRavi Teja              ipv6StaticAddresses = std::move(ipv6StaticAddresses),
20181f8c7b5dSJohnathan Mantey              staticNameServers = std::move(staticNameServers),
20191f8c7b5dSJohnathan Mantey              dhcpv4 = std::move(dhcpv4), dhcpv6 = std::move(dhcpv6),
20201f8c7b5dSJohnathan Mantey              v4dhcpParms = std::move(v4dhcpParms),
2021f23b7296SEd Tanous              v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled](
20224a0cb85cSEd Tanous                 const bool& success, const EthernetInterfaceData& ethData,
2023e48c0fc5SRavi Teja                 const boost::container::flat_set<IPv4AddressData>& ipv4Data,
202401784826SJohnathan Mantey                 const boost::container::flat_set<IPv6AddressData>& ipv6Data) {
20251abe55efSEd Tanous                 if (!success)
20261abe55efSEd Tanous                 {
2027588c3f0dSKowalski, Kamil                     // ... otherwise return error
20281abe55efSEd Tanous                     // TODO(Pawel)consider distinguish between non existing
20291abe55efSEd Tanous                     // object, and other errors
2030fda13ad2SSunitha Harish                     messages::resourceNotFound(asyncResp->res,
20312c70f800SEd Tanous                                                "Ethernet Interface", ifaceId);
2032588c3f0dSKowalski, Kamil                     return;
2033588c3f0dSKowalski, Kamil                 }
2034588c3f0dSKowalski, Kamil 
20351f8c7b5dSJohnathan Mantey                 if (dhcpv4 || dhcpv6)
20361f8c7b5dSJohnathan Mantey                 {
2037f23b7296SEd Tanous                     handleDHCPPatch(ifaceId, ethData, v4dhcpParms, v6dhcpParms,
2038f23b7296SEd Tanous                                     asyncResp);
20391f8c7b5dSJohnathan Mantey                 }
20401f8c7b5dSJohnathan Mantey 
20410627a2c7SEd Tanous                 if (hostname)
20421abe55efSEd Tanous                 {
20430627a2c7SEd Tanous                     handleHostnamePatch(*hostname, asyncResp);
20441abe55efSEd Tanous                 }
20450627a2c7SEd Tanous 
2046ab6554f1SJoshi-Mansi                 if (fqdn)
2047ab6554f1SJoshi-Mansi                 {
20482c70f800SEd Tanous                     handleFqdnPatch(ifaceId, *fqdn, asyncResp);
2049ab6554f1SJoshi-Mansi                 }
2050ab6554f1SJoshi-Mansi 
2051d577665bSRatan Gupta                 if (macAddress)
2052d577665bSRatan Gupta                 {
20532c70f800SEd Tanous                     handleMACAddressPatch(ifaceId, *macAddress, asyncResp);
2054d577665bSRatan Gupta                 }
2055d577665bSRatan Gupta 
2056d1d50814SRavi Teja                 if (ipv4StaticAddresses)
2057d1d50814SRavi Teja                 {
2058537174c4SEd Tanous                     // TODO(ed) for some reason the capture of ipv4Addresses
205901784826SJohnathan Mantey                     // above is returning a const value, not a non-const
206001784826SJohnathan Mantey                     // value. This doesn't really work for us, as we need to
206101784826SJohnathan Mantey                     // be able to efficiently move out the intermedia
206201784826SJohnathan Mantey                     // nlohmann::json objects. This makes a copy of the
206301784826SJohnathan Mantey                     // structure, and operates on that, but could be done
206401784826SJohnathan Mantey                     // more efficiently
2065f23b7296SEd Tanous                     nlohmann::json ipv4Static = *ipv4StaticAddresses;
20662c70f800SEd Tanous                     handleIPv4StaticPatch(ifaceId, ipv4Static, ipv4Data,
2067d1d50814SRavi Teja                                           asyncResp);
20681abe55efSEd Tanous                 }
20690627a2c7SEd Tanous 
2070f85837bfSRAJESWARAN THILLAIGOVINDAN                 if (staticNameServers)
2071f85837bfSRAJESWARAN THILLAIGOVINDAN                 {
20722c70f800SEd Tanous                     handleStaticNameServersPatch(ifaceId, *staticNameServers,
2073f85837bfSRAJESWARAN THILLAIGOVINDAN                                                  asyncResp);
2074f85837bfSRAJESWARAN THILLAIGOVINDAN                 }
20759a6fc6feSRavi Teja 
20769a6fc6feSRavi Teja                 if (ipv6DefaultGateway)
20779a6fc6feSRavi Teja                 {
20789a6fc6feSRavi Teja                     messages::propertyNotWritable(asyncResp->res,
20799a6fc6feSRavi Teja                                                   "IPv6DefaultGateway");
20809a6fc6feSRavi Teja                 }
2081e48c0fc5SRavi Teja 
2082e48c0fc5SRavi Teja                 if (ipv6StaticAddresses)
2083e48c0fc5SRavi Teja                 {
2084f23b7296SEd Tanous                     nlohmann::json ipv6Static = *ipv6StaticAddresses;
20852c70f800SEd Tanous                     handleIPv6StaticAddressesPatch(ifaceId, ipv6Static,
208601784826SJohnathan Mantey                                                    ipv6Data, asyncResp);
2087e48c0fc5SRavi Teja                 }
2088eeedda23SJohnathan Mantey 
2089eeedda23SJohnathan Mantey                 if (interfaceEnabled)
2090eeedda23SJohnathan Mantey                 {
2091eeedda23SJohnathan Mantey                     setEthernetInterfaceBoolProperty(
20922c70f800SEd Tanous                         ifaceId, "NICEnabled", *interfaceEnabled, asyncResp);
2093eeedda23SJohnathan Mantey                 }
2094588c3f0dSKowalski, Kamil             });
2095588c3f0dSKowalski, Kamil     }
20969391bb9cSRapkiewicz, Pawel };
20979391bb9cSRapkiewicz, Pawel 
2098e439f0f8SKowalski, Kamil /**
20994a0cb85cSEd Tanous  * VlanNetworkInterface derived class for delivering VLANNetworkInterface
21004a0cb85cSEd Tanous  * Schema
2101e439f0f8SKowalski, Kamil  */
21021abe55efSEd Tanous class VlanNetworkInterface : public Node
21031abe55efSEd Tanous {
2104e439f0f8SKowalski, Kamil   public:
2105e439f0f8SKowalski, Kamil     /*
2106e439f0f8SKowalski, Kamil      * Default Constructor
2107e439f0f8SKowalski, Kamil      */
210852cc112dSEd Tanous     VlanNetworkInterface(App& app) :
21094a0cb85cSEd Tanous         Node(app,
21107af91514SGunnar Mills              "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/<str>/",
21111abe55efSEd Tanous              std::string(), std::string())
21121abe55efSEd Tanous     {
2113e439f0f8SKowalski, Kamil         entityPrivileges = {
2114e439f0f8SKowalski, Kamil             {boost::beast::http::verb::get, {{"Login"}}},
2115e439f0f8SKowalski, Kamil             {boost::beast::http::verb::head, {{"Login"}}},
2116e439f0f8SKowalski, Kamil             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2117e439f0f8SKowalski, Kamil             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2118e439f0f8SKowalski, Kamil             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2119e439f0f8SKowalski, Kamil             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2120e439f0f8SKowalski, Kamil     }
2121e439f0f8SKowalski, Kamil 
2122e439f0f8SKowalski, Kamil   private:
212381ce609eSEd Tanous     void parseInterfaceData(nlohmann::json& jsonResponse,
212481ce609eSEd Tanous                             const std::string& parentIfaceId,
212581ce609eSEd Tanous                             const std::string& ifaceId,
2126cb13a392SEd Tanous                             const EthernetInterfaceData& ethData)
21271abe55efSEd Tanous     {
2128e439f0f8SKowalski, Kamil         // Fill out obvious data...
212981ce609eSEd Tanous         jsonResponse["Id"] = ifaceId;
213081ce609eSEd Tanous         jsonResponse["@odata.id"] =
213181ce609eSEd Tanous             "/redfish/v1/Managers/bmc/EthernetInterfaces/" + parentIfaceId +
213281ce609eSEd Tanous             "/VLANs/" + ifaceId;
2133e439f0f8SKowalski, Kamil 
213481ce609eSEd Tanous         jsonResponse["VLANEnable"] = true;
2135fda13ad2SSunitha Harish         if (!ethData.vlan_id.empty())
21364a0cb85cSEd Tanous         {
213781ce609eSEd Tanous             jsonResponse["VLANId"] = ethData.vlan_id.back();
21384a0cb85cSEd Tanous         }
2139e439f0f8SKowalski, Kamil     }
2140e439f0f8SKowalski, Kamil 
2141fda13ad2SSunitha Harish     bool verifyNames(const std::string& parent, const std::string& iface)
21421abe55efSEd Tanous     {
21431abe55efSEd Tanous         if (!boost::starts_with(iface, parent + "_"))
21441abe55efSEd Tanous         {
2145927a505aSKowalski, Kamil             return false;
21461abe55efSEd Tanous         }
2147927a505aSKowalski, Kamil         return true;
2148927a505aSKowalski, Kamil     }
2149927a505aSKowalski, Kamil 
2150e439f0f8SKowalski, Kamil     /**
2151e439f0f8SKowalski, Kamil      * Functions triggers appropriate requests on DBus
2152e439f0f8SKowalski, Kamil      */
21538d1b46d7Szhanghch05     void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
21548d1b46d7Szhanghch05                const crow::Request&,
21551abe55efSEd Tanous                const std::vector<std::string>& params) override
21561abe55efSEd Tanous     {
21574a0cb85cSEd Tanous         // TODO(Pawel) this shall be parameterized call (two params) to get
2158e439f0f8SKowalski, Kamil         // EthernetInterfaces for any Manager, not only hardcoded 'openbmc'.
2159e439f0f8SKowalski, Kamil         // Check if there is required param, truly entering this shall be
2160e439f0f8SKowalski, Kamil         // impossible.
21611abe55efSEd Tanous         if (params.size() != 2)
21621abe55efSEd Tanous         {
21638d1b46d7Szhanghch05             messages::internalError(asyncResp->res);
2164e439f0f8SKowalski, Kamil             return;
2165e439f0f8SKowalski, Kamil         }
2166e439f0f8SKowalski, Kamil 
21672c70f800SEd Tanous         const std::string& parentIfaceId = params[0];
21682c70f800SEd Tanous         const std::string& ifaceId = params[1];
21698d1b46d7Szhanghch05         asyncResp->res.jsonValue["@odata.type"] =
21700f74e643SEd Tanous             "#VLanNetworkInterface.v1_1_0.VLanNetworkInterface";
21718d1b46d7Szhanghch05         asyncResp->res.jsonValue["Name"] = "VLAN Network Interface";
2172e439f0f8SKowalski, Kamil 
21732c70f800SEd Tanous         if (!verifyNames(parentIfaceId, ifaceId))
21741abe55efSEd Tanous         {
2175a434f2bdSEd Tanous             return;
2176a434f2bdSEd Tanous         }
2177a434f2bdSEd Tanous 
217801784826SJohnathan Mantey         // Get single eth interface data, and call the below callback for
217901784826SJohnathan Mantey         // JSON preparation
21804a0cb85cSEd Tanous         getEthernetIfaceData(
2181fda13ad2SSunitha Harish             params[1],
21822c70f800SEd Tanous             [this, asyncResp, parentIfaceId{std::string(params[0])},
21832c70f800SEd Tanous              ifaceId{std::string(params[1])}](
21844a0cb85cSEd Tanous                 const bool& success, const EthernetInterfaceData& ethData,
2185cb13a392SEd Tanous                 const boost::container::flat_set<IPv4AddressData>&,
2186cb13a392SEd Tanous                 const boost::container::flat_set<IPv6AddressData>&) {
2187fda13ad2SSunitha Harish                 if (success && ethData.vlan_id.size() != 0)
21881abe55efSEd Tanous                 {
21892c70f800SEd Tanous                     parseInterfaceData(asyncResp->res.jsonValue, parentIfaceId,
21902c70f800SEd Tanous                                        ifaceId, ethData);
21911abe55efSEd Tanous                 }
21921abe55efSEd Tanous                 else
21931abe55efSEd Tanous                 {
2194e439f0f8SKowalski, Kamil                     // ... otherwise return error
21951abe55efSEd Tanous                     // TODO(Pawel)consider distinguish between non existing
21961abe55efSEd Tanous                     // object, and other errors
2197f12894f8SJason M. Bills                     messages::resourceNotFound(
21982c70f800SEd Tanous                         asyncResp->res, "VLAN Network Interface", ifaceId);
2199e439f0f8SKowalski, Kamil                 }
2200e439f0f8SKowalski, Kamil             });
2201e439f0f8SKowalski, Kamil     }
2202e439f0f8SKowalski, Kamil 
22038d1b46d7Szhanghch05     void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
22048d1b46d7Szhanghch05                  const crow::Request& req,
22051abe55efSEd Tanous                  const std::vector<std::string>& params) override
22061abe55efSEd Tanous     {
22078d1b46d7Szhanghch05 
22081abe55efSEd Tanous         if (params.size() != 2)
22091abe55efSEd Tanous         {
2210f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2211e439f0f8SKowalski, Kamil             return;
2212e439f0f8SKowalski, Kamil         }
2213e439f0f8SKowalski, Kamil 
2214d76323e5SEd Tanous         const std::string& parentIfaceId = params[0];
221555c7b7a2SEd Tanous         const std::string& ifaceId = params[1];
2216927a505aSKowalski, Kamil 
2217fda13ad2SSunitha Harish         if (!verifyNames(parentIfaceId, ifaceId))
22181abe55efSEd Tanous         {
2219fda13ad2SSunitha Harish             messages::resourceNotFound(asyncResp->res, "VLAN Network Interface",
2220fda13ad2SSunitha Harish                                        ifaceId);
2221927a505aSKowalski, Kamil             return;
2222927a505aSKowalski, Kamil         }
2223927a505aSKowalski, Kamil 
22240627a2c7SEd Tanous         bool vlanEnable = false;
222538268fa8SAndrew Geissler         uint32_t vlanId = 0;
22260627a2c7SEd Tanous 
22278d1b46d7Szhanghch05         if (!json_util::readJson(req, asyncResp->res, "VLANEnable", vlanEnable,
22288d1b46d7Szhanghch05                                  "VLANId", vlanId))
22291abe55efSEd Tanous         {
2230927a505aSKowalski, Kamil             return;
2231927a505aSKowalski, Kamil         }
2232927a505aSKowalski, Kamil 
223301784826SJohnathan Mantey         // Get single eth interface data, and call the below callback for
223401784826SJohnathan Mantey         // JSON preparation
2235e48c0fc5SRavi Teja         getEthernetIfaceData(
2236e48c0fc5SRavi Teja             params[1],
2237271584abSEd Tanous             [asyncResp, parentIfaceId{std::string(params[0])},
2238cb13a392SEd Tanous              ifaceId{std::string(params[1])}, &vlanEnable,
2239cb13a392SEd Tanous              &vlanId](const bool& success, const EthernetInterfaceData& ethData,
2240cb13a392SEd Tanous                       const boost::container::flat_set<IPv4AddressData>&,
2241cb13a392SEd Tanous                       const boost::container::flat_set<IPv6AddressData>&) {
224208244d02SSunitha Harish                 if (success && !ethData.vlan_id.empty())
224308244d02SSunitha Harish                 {
224408244d02SSunitha Harish                     auto callback =
224508244d02SSunitha Harish                         [asyncResp](const boost::system::error_code ec) {
224608244d02SSunitha Harish                             if (ec)
224708244d02SSunitha Harish                             {
224808244d02SSunitha Harish                                 messages::internalError(asyncResp->res);
224908244d02SSunitha Harish                             }
225008244d02SSunitha Harish                         };
225108244d02SSunitha Harish 
225208244d02SSunitha Harish                     if (vlanEnable == true)
225308244d02SSunitha Harish                     {
225408244d02SSunitha Harish                         crow::connections::systemBus->async_method_call(
225508244d02SSunitha Harish                             std::move(callback), "xyz.openbmc_project.Network",
225608244d02SSunitha Harish                             "/xyz/openbmc_project/network/" + ifaceId,
225708244d02SSunitha Harish                             "org.freedesktop.DBus.Properties", "Set",
225808244d02SSunitha Harish                             "xyz.openbmc_project.Network.VLAN", "Id",
225908244d02SSunitha Harish                             std::variant<uint32_t>(vlanId));
226008244d02SSunitha Harish                     }
226108244d02SSunitha Harish                     else
226208244d02SSunitha Harish                     {
2263e48c0fc5SRavi Teja                         BMCWEB_LOG_DEBUG << "vlanEnable is false. Deleting the "
2264e48c0fc5SRavi Teja                                             "vlan interface";
226508244d02SSunitha Harish                         crow::connections::systemBus->async_method_call(
226608244d02SSunitha Harish                             std::move(callback), "xyz.openbmc_project.Network",
2267e48c0fc5SRavi Teja                             std::string("/xyz/openbmc_project/network/") +
2268e48c0fc5SRavi Teja                                 ifaceId,
226908244d02SSunitha Harish                             "xyz.openbmc_project.Object.Delete", "Delete");
227008244d02SSunitha Harish                     }
227108244d02SSunitha Harish                 }
227208244d02SSunitha Harish                 else
22731abe55efSEd Tanous                 {
22741abe55efSEd Tanous                     // TODO(Pawel)consider distinguish between non existing
22751abe55efSEd Tanous                     // object, and other errors
2276e48c0fc5SRavi Teja                     messages::resourceNotFound(
2277e48c0fc5SRavi Teja                         asyncResp->res, "VLAN Network Interface", ifaceId);
2278927a505aSKowalski, Kamil                     return;
2279927a505aSKowalski, Kamil                 }
2280927a505aSKowalski, Kamil             });
2281e439f0f8SKowalski, Kamil     }
2282e439f0f8SKowalski, Kamil 
22838d1b46d7Szhanghch05     void doDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
22848d1b46d7Szhanghch05                   const crow::Request&,
22851abe55efSEd Tanous                   const std::vector<std::string>& params) override
22861abe55efSEd Tanous     {
22871abe55efSEd Tanous         if (params.size() != 2)
22881abe55efSEd Tanous         {
2289f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2290e439f0f8SKowalski, Kamil             return;
2291e439f0f8SKowalski, Kamil         }
2292e439f0f8SKowalski, Kamil 
2293d76323e5SEd Tanous         const std::string& parentIfaceId = params[0];
229455c7b7a2SEd Tanous         const std::string& ifaceId = params[1];
2295927a505aSKowalski, Kamil 
2296fda13ad2SSunitha Harish         if (!verifyNames(parentIfaceId, ifaceId))
22971abe55efSEd Tanous         {
2298fda13ad2SSunitha Harish             messages::resourceNotFound(asyncResp->res, "VLAN Network Interface",
2299fda13ad2SSunitha Harish                                        ifaceId);
2300927a505aSKowalski, Kamil             return;
2301927a505aSKowalski, Kamil         }
2302927a505aSKowalski, Kamil 
230301784826SJohnathan Mantey         // Get single eth interface data, and call the below callback for
230401784826SJohnathan Mantey         // JSON preparation
2305f12894f8SJason M. Bills         getEthernetIfaceData(
2306fda13ad2SSunitha Harish             params[1],
2307271584abSEd Tanous             [asyncResp, parentIfaceId{std::string(params[0])},
2308fda13ad2SSunitha Harish              ifaceId{std::string(params[1])}](
2309f12894f8SJason M. Bills                 const bool& success, const EthernetInterfaceData& ethData,
2310cb13a392SEd Tanous                 const boost::container::flat_set<IPv4AddressData>&,
2311cb13a392SEd Tanous                 const boost::container::flat_set<IPv6AddressData>&) {
2312fda13ad2SSunitha Harish                 if (success && !ethData.vlan_id.empty())
23131abe55efSEd Tanous                 {
2314f12894f8SJason M. Bills                     auto callback =
2315f12894f8SJason M. Bills                         [asyncResp](const boost::system::error_code ec) {
23161abe55efSEd Tanous                             if (ec)
23171abe55efSEd Tanous                             {
2318f12894f8SJason M. Bills                                 messages::internalError(asyncResp->res);
2319927a505aSKowalski, Kamil                             }
23204a0cb85cSEd Tanous                         };
23214a0cb85cSEd Tanous                     crow::connections::systemBus->async_method_call(
23224a0cb85cSEd Tanous                         std::move(callback), "xyz.openbmc_project.Network",
23234a0cb85cSEd Tanous                         std::string("/xyz/openbmc_project/network/") + ifaceId,
23244a0cb85cSEd Tanous                         "xyz.openbmc_project.Object.Delete", "Delete");
23251abe55efSEd Tanous                 }
23261abe55efSEd Tanous                 else
23271abe55efSEd Tanous                 {
2328927a505aSKowalski, Kamil                     // ... otherwise return error
2329f12894f8SJason M. Bills                     // TODO(Pawel)consider distinguish between non existing
2330f12894f8SJason M. Bills                     // object, and other errors
2331f12894f8SJason M. Bills                     messages::resourceNotFound(
2332f12894f8SJason M. Bills                         asyncResp->res, "VLAN Network Interface", ifaceId);
2333927a505aSKowalski, Kamil                 }
2334927a505aSKowalski, Kamil             });
2335e439f0f8SKowalski, Kamil     }
2336e439f0f8SKowalski, Kamil };
2337e439f0f8SKowalski, Kamil 
2338e439f0f8SKowalski, Kamil /**
2339e439f0f8SKowalski, Kamil  * VlanNetworkInterfaceCollection derived class for delivering
2340e439f0f8SKowalski, Kamil  * VLANNetworkInterface Collection Schema
2341e439f0f8SKowalski, Kamil  */
23421abe55efSEd Tanous class VlanNetworkInterfaceCollection : public Node
23431abe55efSEd Tanous {
2344e439f0f8SKowalski, Kamil   public:
234552cc112dSEd Tanous     VlanNetworkInterfaceCollection(App& app) :
23464a0cb85cSEd Tanous         Node(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/VLANs/",
23474a0cb85cSEd Tanous              std::string())
23481abe55efSEd Tanous     {
2349e439f0f8SKowalski, Kamil         entityPrivileges = {
2350e439f0f8SKowalski, Kamil             {boost::beast::http::verb::get, {{"Login"}}},
2351e439f0f8SKowalski, Kamil             {boost::beast::http::verb::head, {{"Login"}}},
2352e439f0f8SKowalski, Kamil             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2353e439f0f8SKowalski, Kamil             {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2354e439f0f8SKowalski, Kamil             {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2355e439f0f8SKowalski, Kamil             {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2356e439f0f8SKowalski, Kamil     }
2357e439f0f8SKowalski, Kamil 
2358e439f0f8SKowalski, Kamil   private:
2359e439f0f8SKowalski, Kamil     /**
2360e439f0f8SKowalski, Kamil      * Functions triggers appropriate requests on DBus
2361e439f0f8SKowalski, Kamil      */
23628d1b46d7Szhanghch05     void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
23638d1b46d7Szhanghch05                const crow::Request&,
23641abe55efSEd Tanous                const std::vector<std::string>& params) override
23651abe55efSEd Tanous     {
23661abe55efSEd Tanous         if (params.size() != 1)
23671abe55efSEd Tanous         {
2368e439f0f8SKowalski, Kamil             // This means there is a problem with the router
2369f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2370e439f0f8SKowalski, Kamil             return;
2371e439f0f8SKowalski, Kamil         }
2372e439f0f8SKowalski, Kamil 
23734a0cb85cSEd Tanous         const std::string& rootInterfaceName = params[0];
2374e439f0f8SKowalski, Kamil 
23754a0cb85cSEd Tanous         // Get eth interface list, and call the below callback for JSON
23761abe55efSEd Tanous         // preparation
2377f12894f8SJason M. Bills         getEthernetIfaceList(
237843b761d0SEd Tanous             [asyncResp, rootInterfaceName{std::string(rootInterfaceName)}](
23791abe55efSEd Tanous                 const bool& success,
238081ce609eSEd Tanous                 const boost::container::flat_set<std::string>& ifaceList) {
23814a0cb85cSEd Tanous                 if (!success)
23821abe55efSEd Tanous                 {
2383f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
23844a0cb85cSEd Tanous                     return;
23851abe55efSEd Tanous                 }
23864c9afe43SEd Tanous 
238781ce609eSEd Tanous                 if (ifaceList.find(rootInterfaceName) == ifaceList.end())
23884c9afe43SEd Tanous                 {
23894c9afe43SEd Tanous                     messages::resourceNotFound(asyncResp->res,
23904c9afe43SEd Tanous                                                "VLanNetworkInterfaceCollection",
23914c9afe43SEd Tanous                                                rootInterfaceName);
23924c9afe43SEd Tanous                     return;
23934c9afe43SEd Tanous                 }
23944c9afe43SEd Tanous 
23950f74e643SEd Tanous                 asyncResp->res.jsonValue["@odata.type"] =
23960f74e643SEd Tanous                     "#VLanNetworkInterfaceCollection."
23970f74e643SEd Tanous                     "VLanNetworkInterfaceCollection";
23980f74e643SEd Tanous                 asyncResp->res.jsonValue["Name"] =
23990f74e643SEd Tanous                     "VLAN Network Interface Collection";
24004a0cb85cSEd Tanous 
24012c70f800SEd Tanous                 nlohmann::json ifaceArray = nlohmann::json::array();
24024a0cb85cSEd Tanous 
240381ce609eSEd Tanous                 for (const std::string& ifaceItem : ifaceList)
24041abe55efSEd Tanous                 {
24052c70f800SEd Tanous                     if (boost::starts_with(ifaceItem, rootInterfaceName + "_"))
24064a0cb85cSEd Tanous                     {
2407f23b7296SEd Tanous                         std::string path =
2408f23b7296SEd Tanous                             "/redfish/v1/Managers/bmc/EthernetInterfaces/";
2409f23b7296SEd Tanous                         path += rootInterfaceName;
2410f23b7296SEd Tanous                         path += "/VLANs/";
2411f23b7296SEd Tanous                         path += ifaceItem;
2412f23b7296SEd Tanous                         ifaceArray.push_back({{"@odata.id", std::move(path)}});
2413e439f0f8SKowalski, Kamil                     }
2414e439f0f8SKowalski, Kamil                 }
2415e439f0f8SKowalski, Kamil 
24164a0cb85cSEd Tanous                 asyncResp->res.jsonValue["Members@odata.count"] =
24172c70f800SEd Tanous                     ifaceArray.size();
24182c70f800SEd Tanous                 asyncResp->res.jsonValue["Members"] = std::move(ifaceArray);
24194a0cb85cSEd Tanous                 asyncResp->res.jsonValue["@odata.id"] =
24204a0cb85cSEd Tanous                     "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
24214a0cb85cSEd Tanous                     rootInterfaceName + "/VLANs";
2422e439f0f8SKowalski, Kamil             });
2423e439f0f8SKowalski, Kamil     }
2424e439f0f8SKowalski, Kamil 
24258d1b46d7Szhanghch05     void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
24268d1b46d7Szhanghch05                 const crow::Request& req,
24271abe55efSEd Tanous                 const std::vector<std::string>& params) override
24281abe55efSEd Tanous     {
24291abe55efSEd Tanous         if (params.size() != 1)
24301abe55efSEd Tanous         {
2431f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
2432e439f0f8SKowalski, Kamil             return;
2433e439f0f8SKowalski, Kamil         }
2434fda13ad2SSunitha Harish         bool vlanEnable = false;
24350627a2c7SEd Tanous         uint32_t vlanId = 0;
24368d1b46d7Szhanghch05         if (!json_util::readJson(req, asyncResp->res, "VLANId", vlanId,
24378d1b46d7Szhanghch05                                  "VLANEnable", vlanEnable))
24381abe55efSEd Tanous         {
24394a0cb85cSEd Tanous             return;
2440e439f0f8SKowalski, Kamil         }
2441fda13ad2SSunitha Harish         // Need both vlanId and vlanEnable to service this request
2442fda13ad2SSunitha Harish         if (!vlanId)
2443fda13ad2SSunitha Harish         {
2444fda13ad2SSunitha Harish             messages::propertyMissing(asyncResp->res, "VLANId");
2445fda13ad2SSunitha Harish         }
2446fda13ad2SSunitha Harish         if (!vlanEnable)
2447fda13ad2SSunitha Harish         {
2448fda13ad2SSunitha Harish             messages::propertyMissing(asyncResp->res, "VLANEnable");
2449fda13ad2SSunitha Harish         }
2450271584abSEd Tanous         if (static_cast<bool>(vlanId) ^ vlanEnable)
2451fda13ad2SSunitha Harish         {
2452fda13ad2SSunitha Harish             return;
2453fda13ad2SSunitha Harish         }
2454fda13ad2SSunitha Harish 
24554a0cb85cSEd Tanous         const std::string& rootInterfaceName = params[0];
24564a0cb85cSEd Tanous         auto callback = [asyncResp](const boost::system::error_code ec) {
24571abe55efSEd Tanous             if (ec)
24581abe55efSEd Tanous             {
24594a0cb85cSEd Tanous                 // TODO(ed) make more consistent error messages based on
24604a0cb85cSEd Tanous                 // phosphor-network responses
2461f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
24624a0cb85cSEd Tanous                 return;
24631abe55efSEd Tanous             }
2464f12894f8SJason M. Bills             messages::created(asyncResp->res);
2465e439f0f8SKowalski, Kamil         };
24664a0cb85cSEd Tanous         crow::connections::systemBus->async_method_call(
24674a0cb85cSEd Tanous             std::move(callback), "xyz.openbmc_project.Network",
24684a0cb85cSEd Tanous             "/xyz/openbmc_project/network",
24694a0cb85cSEd Tanous             "xyz.openbmc_project.Network.VLAN.Create", "VLAN",
24700627a2c7SEd Tanous             rootInterfaceName, vlanId);
24714a0cb85cSEd Tanous     }
24724a0cb85cSEd Tanous };
24739391bb9cSRapkiewicz, Pawel } // namespace redfish
2474