Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 18 | #include "bmcweb_config.h" |
| 19 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "app.hpp" |
| 21 | #include "dbus_singleton.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 22 | #include "dbus_utility.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 23 | #include "error_messages.hpp" |
| 24 | #include "health.hpp" |
Ed Tanous | 2c5875a | 2023-05-15 09:56:06 -0700 | [diff] [blame] | 25 | #include "human_sort.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 26 | #include "query.hpp" |
| 27 | #include "registries/privilege_registry.hpp" |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 28 | #include "utils/ip_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 29 | #include "utils/json_utils.hpp" |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 30 | |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 31 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 32 | #include <boost/url/format.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 33 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 34 | #include <array> |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 35 | #include <memory> |
Ed Tanous | a24526d | 2018-12-10 15:17:59 -0800 | [diff] [blame] | 36 | #include <optional> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 37 | #include <ranges> |
Joshi-Mansi | ab6554f | 2020-03-10 18:33:36 +0530 | [diff] [blame] | 38 | #include <regex> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 39 | #include <string_view> |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 40 | #include <vector> |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 41 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 42 | namespace redfish |
| 43 | { |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 44 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 45 | enum class LinkType |
| 46 | { |
| 47 | Local, |
| 48 | Global |
| 49 | }; |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Structure for keeping IPv4 data required by Redfish |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 53 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 54 | struct IPv4AddressData |
| 55 | { |
| 56 | std::string id; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 57 | std::string address; |
| 58 | std::string domain; |
| 59 | std::string gateway; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 60 | std::string netmask; |
| 61 | std::string origin; |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 62 | LinkType linktype{}; |
| 63 | bool isActive{}; |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /** |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 67 | * Structure for keeping IPv6 data required by Redfish |
| 68 | */ |
| 69 | struct IPv6AddressData |
| 70 | { |
| 71 | std::string id; |
| 72 | std::string address; |
| 73 | std::string origin; |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 74 | uint8_t prefixLength = 0; |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 75 | }; |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Structure for keeping static route data required by Redfish |
| 79 | */ |
| 80 | struct StaticGatewayData |
| 81 | { |
| 82 | std::string id; |
| 83 | std::string gateway; |
| 84 | size_t prefixLength = 0; |
| 85 | std::string protocol; |
| 86 | }; |
| 87 | |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 88 | /** |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 89 | * Structure for keeping basic single Ethernet Interface information |
| 90 | * available from DBus |
| 91 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 92 | struct EthernetInterfaceData |
| 93 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 94 | uint32_t speed; |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 95 | size_t mtuSize; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 96 | bool autoNeg; |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 97 | bool dnsv4Enabled; |
| 98 | bool dnsv6Enabled; |
Ravi Teja | 91c441e | 2024-02-23 09:03:43 -0600 | [diff] [blame] | 99 | bool domainv4Enabled; |
| 100 | bool domainv6Enabled; |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 101 | bool ntpv4Enabled; |
| 102 | bool ntpv6Enabled; |
| 103 | bool hostNamev4Enabled; |
| 104 | bool hostNamev6Enabled; |
Johnathan Mantey | aa05fb2 | 2020-01-08 12:08:44 -0800 | [diff] [blame] | 105 | bool linkUp; |
Johnathan Mantey | eeedda2 | 2019-10-29 16:09:52 -0700 | [diff] [blame] | 106 | bool nicEnabled; |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 107 | bool ipv6AcceptRa; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 108 | std::string dhcpEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 109 | std::string operatingMode; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 110 | std::string hostName; |
| 111 | std::string defaultGateway; |
| 112 | std::string ipv6DefaultGateway; |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 113 | std::string ipv6StaticDefaultGateway; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 114 | std::string macAddress; |
Jiaqing Zhao | 17e2202 | 2022-04-14 18:58:06 +0800 | [diff] [blame] | 115 | std::optional<uint32_t> vlanId; |
manojkiran.eda@gmail.com | 0f6efdc | 2019-10-03 04:53:44 -0500 | [diff] [blame] | 116 | std::vector<std::string> nameServers; |
| 117 | std::vector<std::string> staticNameServers; |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 118 | std::vector<std::string> domainnames; |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 119 | }; |
| 120 | |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 121 | struct DHCPParameters |
| 122 | { |
| 123 | std::optional<bool> dhcpv4Enabled; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 124 | std::optional<bool> useDnsServers; |
| 125 | std::optional<bool> useNtpServers; |
| 126 | std::optional<bool> useDomainName; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 127 | std::optional<std::string> dhcpv6OperatingMode; |
| 128 | }; |
| 129 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 130 | // Helper function that changes bits netmask notation (i.e. /24) |
| 131 | // into full dot notation |
| 132 | inline std::string getNetmask(unsigned int bits) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 133 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 134 | uint32_t value = 0xffffffff << (32 - bits); |
| 135 | std::string netmask = std::to_string((value >> 24) & 0xff) + "." + |
| 136 | std::to_string((value >> 16) & 0xff) + "." + |
| 137 | std::to_string((value >> 8) & 0xff) + "." + |
| 138 | std::to_string(value & 0xff); |
| 139 | return netmask; |
| 140 | } |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 141 | |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 142 | inline bool translateDhcpEnabledToBool(const std::string& inputDHCP, |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 143 | bool isIPv4) |
| 144 | { |
| 145 | if (isIPv4) |
| 146 | { |
| 147 | return ( |
| 148 | (inputDHCP == |
| 149 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4") || |
| 150 | (inputDHCP == |
| 151 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both")); |
| 152 | } |
| 153 | return ((inputDHCP == |
| 154 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6") || |
| 155 | (inputDHCP == |
| 156 | "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both")); |
| 157 | } |
| 158 | |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 159 | inline std::string getDhcpEnabledEnumeration(bool isIPv4, bool isIPv6) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 160 | { |
| 161 | if (isIPv4 && isIPv6) |
| 162 | { |
| 163 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"; |
| 164 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 165 | if (isIPv4) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 166 | { |
| 167 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v4"; |
| 168 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 169 | if (isIPv6) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 170 | { |
| 171 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.v6"; |
| 172 | } |
| 173 | return "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.none"; |
| 174 | } |
| 175 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 176 | inline std::string |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 177 | translateAddressOriginDbusToRedfish(const std::string& inputOrigin, |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 178 | bool isIPv4) |
| 179 | { |
| 180 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.Static") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 181 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 182 | return "Static"; |
| 183 | } |
| 184 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.LinkLocal") |
| 185 | { |
| 186 | if (isIPv4) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 187 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 188 | return "IPv4LinkLocal"; |
| 189 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 190 | return "LinkLocal"; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 191 | } |
| 192 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP") |
| 193 | { |
| 194 | if (isIPv4) |
| 195 | { |
| 196 | return "DHCP"; |
| 197 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 198 | return "DHCPv6"; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 199 | } |
| 200 | if (inputOrigin == "xyz.openbmc_project.Network.IP.AddressOrigin.SLAAC") |
| 201 | { |
| 202 | return "SLAAC"; |
| 203 | } |
| 204 | return ""; |
| 205 | } |
| 206 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 207 | inline bool extractEthernetInterfaceData( |
| 208 | const std::string& ethifaceId, |
| 209 | const dbus::utility::ManagedObjectType& dbusData, |
| 210 | EthernetInterfaceData& ethData) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 211 | { |
Ed Tanous | 4c9afe4 | 2019-05-03 16:59:57 -0700 | [diff] [blame] | 212 | bool idFound = false; |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 213 | for (const auto& objpath : dbusData) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 214 | { |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 215 | for (const auto& ifacePair : objpath.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 216 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 217 | if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 218 | { |
Ed Tanous | 4c9afe4 | 2019-05-03 16:59:57 -0700 | [diff] [blame] | 219 | idFound = true; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 220 | if (ifacePair.first == "xyz.openbmc_project.Network.MACAddress") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 221 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 222 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 223 | { |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 224 | if (propertyPair.first == "MACAddress") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 225 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 226 | const std::string* mac = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 227 | std::get_if<std::string>(&propertyPair.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 228 | if (mac != nullptr) |
| 229 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 230 | ethData.macAddress = *mac; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 231 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 232 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | else if (ifacePair.first == "xyz.openbmc_project.Network.VLAN") |
| 236 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 237 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 238 | { |
| 239 | if (propertyPair.first == "Id") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 240 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 241 | const uint32_t* id = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 242 | std::get_if<uint32_t>(&propertyPair.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 243 | if (id != nullptr) |
| 244 | { |
Jiaqing Zhao | 17e2202 | 2022-04-14 18:58:06 +0800 | [diff] [blame] | 245 | ethData.vlanId = *id; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 246 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 247 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | else if (ifacePair.first == |
| 251 | "xyz.openbmc_project.Network.EthernetInterface") |
| 252 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 253 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 254 | { |
| 255 | if (propertyPair.first == "AutoNeg") |
| 256 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 257 | const bool* autoNeg = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 258 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 259 | if (autoNeg != nullptr) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 260 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 261 | ethData.autoNeg = *autoNeg; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | else if (propertyPair.first == "Speed") |
| 265 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 266 | const uint32_t* speed = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 267 | std::get_if<uint32_t>(&propertyPair.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 268 | if (speed != nullptr) |
| 269 | { |
| 270 | ethData.speed = *speed; |
| 271 | } |
| 272 | } |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 273 | else if (propertyPair.first == "MTU") |
| 274 | { |
Anthony | 3e7a8da | 2023-10-23 14:22:43 +0800 | [diff] [blame] | 275 | const size_t* mtuSize = |
| 276 | std::get_if<size_t>(&propertyPair.second); |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 277 | if (mtuSize != nullptr) |
| 278 | { |
| 279 | ethData.mtuSize = *mtuSize; |
| 280 | } |
| 281 | } |
Johnathan Mantey | aa05fb2 | 2020-01-08 12:08:44 -0800 | [diff] [blame] | 282 | else if (propertyPair.first == "LinkUp") |
| 283 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 284 | const bool* linkUp = |
Johnathan Mantey | aa05fb2 | 2020-01-08 12:08:44 -0800 | [diff] [blame] | 285 | std::get_if<bool>(&propertyPair.second); |
| 286 | if (linkUp != nullptr) |
| 287 | { |
| 288 | ethData.linkUp = *linkUp; |
| 289 | } |
| 290 | } |
Johnathan Mantey | eeedda2 | 2019-10-29 16:09:52 -0700 | [diff] [blame] | 291 | else if (propertyPair.first == "NICEnabled") |
| 292 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 293 | const bool* nicEnabled = |
Johnathan Mantey | eeedda2 | 2019-10-29 16:09:52 -0700 | [diff] [blame] | 294 | std::get_if<bool>(&propertyPair.second); |
| 295 | if (nicEnabled != nullptr) |
| 296 | { |
| 297 | ethData.nicEnabled = *nicEnabled; |
| 298 | } |
| 299 | } |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 300 | else if (propertyPair.first == "IPv6AcceptRA") |
| 301 | { |
| 302 | const bool* ipv6AcceptRa = |
| 303 | std::get_if<bool>(&propertyPair.second); |
| 304 | if (ipv6AcceptRa != nullptr) |
| 305 | { |
| 306 | ethData.ipv6AcceptRa = *ipv6AcceptRa; |
| 307 | } |
| 308 | } |
RAJESWARAN THILLAIGOVINDAN | f85837b | 2019-04-04 05:18:53 -0500 | [diff] [blame] | 309 | else if (propertyPair.first == "Nameservers") |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 310 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 311 | const std::vector<std::string>* nameservers = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 312 | std::get_if<std::vector<std::string>>( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 313 | &propertyPair.second); |
| 314 | if (nameservers != nullptr) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 315 | { |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 316 | ethData.nameServers = *nameservers; |
manojkiran.eda@gmail.com | 0f6efdc | 2019-10-03 04:53:44 -0500 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | else if (propertyPair.first == "StaticNameServers") |
| 320 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 321 | const std::vector<std::string>* staticNameServers = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 322 | std::get_if<std::vector<std::string>>( |
manojkiran.eda@gmail.com | 0f6efdc | 2019-10-03 04:53:44 -0500 | [diff] [blame] | 323 | &propertyPair.second); |
| 324 | if (staticNameServers != nullptr) |
| 325 | { |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 326 | ethData.staticNameServers = *staticNameServers; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 327 | } |
| 328 | } |
manojkiraneda | 2a13328 | 2019-02-19 13:09:43 +0530 | [diff] [blame] | 329 | else if (propertyPair.first == "DHCPEnabled") |
| 330 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 331 | const std::string* dhcpEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 332 | std::get_if<std::string>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 333 | if (dhcpEnabled != nullptr) |
manojkiraneda | 2a13328 | 2019-02-19 13:09:43 +0530 | [diff] [blame] | 334 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 335 | ethData.dhcpEnabled = *dhcpEnabled; |
manojkiraneda | 2a13328 | 2019-02-19 13:09:43 +0530 | [diff] [blame] | 336 | } |
| 337 | } |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 338 | else if (propertyPair.first == "DomainName") |
| 339 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 340 | const std::vector<std::string>* domainNames = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 341 | std::get_if<std::vector<std::string>>( |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 342 | &propertyPair.second); |
| 343 | if (domainNames != nullptr) |
| 344 | { |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 345 | ethData.domainnames = *domainNames; |
Jennifer Lee | d24bfc7 | 2019-03-05 13:03:37 -0800 | [diff] [blame] | 346 | } |
| 347 | } |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 348 | else if (propertyPair.first == "DefaultGateway") |
| 349 | { |
| 350 | const std::string* defaultGateway = |
| 351 | std::get_if<std::string>(&propertyPair.second); |
| 352 | if (defaultGateway != nullptr) |
| 353 | { |
| 354 | std::string defaultGatewayStr = *defaultGateway; |
| 355 | if (defaultGatewayStr.empty()) |
| 356 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 357 | ethData.defaultGateway = "0.0.0.0"; |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 358 | } |
| 359 | else |
| 360 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 361 | ethData.defaultGateway = defaultGatewayStr; |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | } |
| 365 | else if (propertyPair.first == "DefaultGateway6") |
| 366 | { |
| 367 | const std::string* defaultGateway6 = |
| 368 | std::get_if<std::string>(&propertyPair.second); |
| 369 | if (defaultGateway6 != nullptr) |
| 370 | { |
| 371 | std::string defaultGateway6Str = |
| 372 | *defaultGateway6; |
| 373 | if (defaultGateway6Str.empty()) |
| 374 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 375 | ethData.ipv6DefaultGateway = |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 376 | "0:0:0:0:0:0:0:0"; |
| 377 | } |
| 378 | else |
| 379 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 380 | ethData.ipv6DefaultGateway = |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 381 | defaultGateway6Str; |
| 382 | } |
| 383 | } |
| 384 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | } |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 388 | |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 389 | sdbusplus::message::object_path path( |
| 390 | "/xyz/openbmc_project/network"); |
| 391 | sdbusplus::message::object_path dhcp4Path = path / ethifaceId / |
| 392 | "dhcp4"; |
| 393 | |
| 394 | if (sdbusplus::message::object_path(objpath.first) == dhcp4Path) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 395 | { |
| 396 | if (ifacePair.first == |
| 397 | "xyz.openbmc_project.Network.DHCPConfiguration") |
| 398 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 399 | for (const auto& propertyPair : ifacePair.second) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 400 | { |
| 401 | if (propertyPair.first == "DNSEnabled") |
| 402 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 403 | const bool* dnsEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 404 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 405 | if (dnsEnabled != nullptr) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 406 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 407 | ethData.dnsv4Enabled = *dnsEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
Ravi Teja | 91c441e | 2024-02-23 09:03:43 -0600 | [diff] [blame] | 410 | else if (propertyPair.first == "DomainEnabled") |
| 411 | { |
| 412 | const bool* domainEnabled = |
| 413 | std::get_if<bool>(&propertyPair.second); |
| 414 | if (domainEnabled != nullptr) |
| 415 | { |
| 416 | ethData.domainv4Enabled = *domainEnabled; |
| 417 | } |
| 418 | } |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 419 | else if (propertyPair.first == "NTPEnabled") |
| 420 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 421 | const bool* ntpEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 422 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 423 | if (ntpEnabled != nullptr) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 424 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 425 | ethData.ntpv4Enabled = *ntpEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | else if (propertyPair.first == "HostNameEnabled") |
| 429 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 430 | const bool* hostNameEnabled = |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 431 | std::get_if<bool>(&propertyPair.second); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 432 | if (hostNameEnabled != nullptr) |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 433 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 434 | ethData.hostNamev4Enabled = *hostNameEnabled; |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | sdbusplus::message::object_path dhcp6Path = path / ethifaceId / |
| 442 | "dhcp6"; |
| 443 | |
| 444 | if (sdbusplus::message::object_path(objpath.first) == dhcp6Path) |
| 445 | { |
| 446 | if (ifacePair.first == |
| 447 | "xyz.openbmc_project.Network.DHCPConfiguration") |
| 448 | { |
| 449 | for (const auto& propertyPair : ifacePair.second) |
| 450 | { |
| 451 | if (propertyPair.first == "DNSEnabled") |
| 452 | { |
| 453 | const bool* dnsEnabled = |
| 454 | std::get_if<bool>(&propertyPair.second); |
| 455 | if (dnsEnabled != nullptr) |
| 456 | { |
| 457 | ethData.dnsv6Enabled = *dnsEnabled; |
| 458 | } |
| 459 | } |
Ravi Teja | 91c441e | 2024-02-23 09:03:43 -0600 | [diff] [blame] | 460 | if (propertyPair.first == "DomainEnabled") |
| 461 | { |
| 462 | const bool* domainEnabled = |
| 463 | std::get_if<bool>(&propertyPair.second); |
| 464 | if (domainEnabled != nullptr) |
| 465 | { |
| 466 | ethData.domainv6Enabled = *domainEnabled; |
| 467 | } |
| 468 | } |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 469 | else if (propertyPair.first == "NTPEnabled") |
| 470 | { |
| 471 | const bool* ntpEnabled = |
| 472 | std::get_if<bool>(&propertyPair.second); |
| 473 | if (ntpEnabled != nullptr) |
| 474 | { |
| 475 | ethData.ntpv6Enabled = *ntpEnabled; |
| 476 | } |
| 477 | } |
| 478 | else if (propertyPair.first == "HostNameEnabled") |
| 479 | { |
| 480 | const bool* hostNameEnabled = |
| 481 | std::get_if<bool>(&propertyPair.second); |
| 482 | if (hostNameEnabled != nullptr) |
| 483 | { |
| 484 | ethData.hostNamev6Enabled = *hostNameEnabled; |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 485 | } |
| 486 | } |
Johnathan Mantey | 1f8c7b5 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 490 | // System configuration shows up in the global namespace, so no need |
| 491 | // to check eth number |
| 492 | if (ifacePair.first == |
| 493 | "xyz.openbmc_project.Network.SystemConfiguration") |
| 494 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 495 | for (const auto& propertyPair : ifacePair.second) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 496 | { |
| 497 | if (propertyPair.first == "HostName") |
| 498 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 499 | const std::string* hostname = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 500 | std::get_if<std::string>(&propertyPair.second); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 501 | if (hostname != nullptr) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 502 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 503 | ethData.hostName = *hostname; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 509 | } |
Ed Tanous | 4c9afe4 | 2019-05-03 16:59:57 -0700 | [diff] [blame] | 510 | return idFound; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 513 | // Helper function that extracts data for single ethernet ipv6 address |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 514 | inline void extractIPV6Data(const std::string& ethifaceId, |
| 515 | const dbus::utility::ManagedObjectType& dbusData, |
| 516 | std::vector<IPv6AddressData>& ipv6Config) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 517 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 518 | const std::string ipPathStart = "/xyz/openbmc_project/network/" + |
| 519 | ethifaceId; |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 520 | |
| 521 | // Since there might be several IPv6 configurations aligned with |
| 522 | // single ethernet interface, loop over all of them |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 523 | for (const auto& objpath : dbusData) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 524 | { |
| 525 | // Check if proper pattern for object path appears |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 526 | if (objpath.first.str.starts_with(ipPathStart + "/")) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 527 | { |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 528 | for (const auto& interface : objpath.second) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 529 | { |
| 530 | if (interface.first == "xyz.openbmc_project.Network.IP") |
| 531 | { |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 532 | auto type = std::ranges::find_if(interface.second, |
| 533 | [](const auto& property) { |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 534 | return property.first == "Type"; |
| 535 | }); |
| 536 | if (type == interface.second.end()) |
| 537 | { |
| 538 | continue; |
| 539 | } |
| 540 | |
| 541 | const std::string* typeStr = |
| 542 | std::get_if<std::string>(&type->second); |
| 543 | |
| 544 | if (typeStr == nullptr || |
| 545 | (*typeStr != |
| 546 | "xyz.openbmc_project.Network.IP.Protocol.IPv6")) |
| 547 | { |
| 548 | continue; |
| 549 | } |
| 550 | |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 551 | // Instance IPv6AddressData structure, and set as |
| 552 | // appropriate |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 553 | IPv6AddressData& ipv6Address = ipv6Config.emplace_back(); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 554 | ipv6Address.id = |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 555 | objpath.first.str.substr(ipPathStart.size()); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 556 | for (const auto& property : interface.second) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 557 | { |
| 558 | if (property.first == "Address") |
| 559 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 560 | const std::string* address = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 561 | std::get_if<std::string>(&property.second); |
| 562 | if (address != nullptr) |
| 563 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 564 | ipv6Address.address = *address; |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | else if (property.first == "Origin") |
| 568 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 569 | const std::string* origin = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 570 | std::get_if<std::string>(&property.second); |
| 571 | if (origin != nullptr) |
| 572 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 573 | ipv6Address.origin = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 574 | translateAddressOriginDbusToRedfish(*origin, |
| 575 | false); |
| 576 | } |
| 577 | } |
| 578 | else if (property.first == "PrefixLength") |
| 579 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 580 | const uint8_t* prefix = |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 581 | std::get_if<uint8_t>(&property.second); |
| 582 | if (prefix != nullptr) |
| 583 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 584 | ipv6Address.prefixLength = *prefix; |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 585 | } |
| 586 | } |
Asmitha Karunanithi | 889ff69 | 2021-11-29 08:43:30 -0600 | [diff] [blame] | 587 | else if (property.first == "Type" || |
| 588 | property.first == "Gateway") |
| 589 | { |
| 590 | // Type & Gateway is not used |
| 591 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 592 | else |
| 593 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 594 | BMCWEB_LOG_ERROR( |
| 595 | "Got extra property: {} on the {} object", |
| 596 | property.first, objpath.first.str); |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 597 | } |
| 598 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 605 | // Helper function that extracts data for single ethernet ipv4 address |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 606 | inline void extractIPData(const std::string& ethifaceId, |
| 607 | const dbus::utility::ManagedObjectType& dbusData, |
| 608 | std::vector<IPv4AddressData>& ipv4Config) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 609 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 610 | const std::string ipPathStart = "/xyz/openbmc_project/network/" + |
| 611 | ethifaceId; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 612 | |
| 613 | // Since there might be several IPv4 configurations aligned with |
| 614 | // single ethernet interface, loop over all of them |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 615 | for (const auto& objpath : dbusData) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 616 | { |
| 617 | // Check if proper pattern for object path appears |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 618 | if (objpath.first.str.starts_with(ipPathStart + "/")) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 619 | { |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 620 | for (const auto& interface : objpath.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 621 | { |
| 622 | if (interface.first == "xyz.openbmc_project.Network.IP") |
| 623 | { |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 624 | auto type = std::ranges::find_if(interface.second, |
| 625 | [](const auto& property) { |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 626 | return property.first == "Type"; |
| 627 | }); |
| 628 | if (type == interface.second.end()) |
| 629 | { |
| 630 | continue; |
| 631 | } |
| 632 | |
| 633 | const std::string* typeStr = |
| 634 | std::get_if<std::string>(&type->second); |
| 635 | |
| 636 | if (typeStr == nullptr || |
| 637 | (*typeStr != |
| 638 | "xyz.openbmc_project.Network.IP.Protocol.IPv4")) |
| 639 | { |
| 640 | continue; |
| 641 | } |
| 642 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 643 | // Instance IPv4AddressData structure, and set as |
| 644 | // appropriate |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 645 | IPv4AddressData& ipv4Address = ipv4Config.emplace_back(); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 646 | ipv4Address.id = |
Tony Lee | 353163e | 2022-11-23 11:06:10 +0800 | [diff] [blame] | 647 | objpath.first.str.substr(ipPathStart.size()); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 648 | for (const auto& property : interface.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 649 | { |
| 650 | if (property.first == "Address") |
| 651 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 652 | const std::string* address = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 653 | std::get_if<std::string>(&property.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 654 | if (address != nullptr) |
| 655 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 656 | ipv4Address.address = *address; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 659 | else if (property.first == "Origin") |
| 660 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 661 | const std::string* origin = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 662 | std::get_if<std::string>(&property.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 663 | if (origin != nullptr) |
| 664 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 665 | ipv4Address.origin = |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 666 | translateAddressOriginDbusToRedfish(*origin, |
| 667 | true); |
| 668 | } |
| 669 | } |
| 670 | else if (property.first == "PrefixLength") |
| 671 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 672 | const uint8_t* mask = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 673 | std::get_if<uint8_t>(&property.second); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 674 | if (mask != nullptr) |
| 675 | { |
| 676 | // convert it to the string |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 677 | ipv4Address.netmask = getNetmask(*mask); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
Asmitha Karunanithi | 889ff69 | 2021-11-29 08:43:30 -0600 | [diff] [blame] | 680 | else if (property.first == "Type" || |
| 681 | property.first == "Gateway") |
| 682 | { |
| 683 | // Type & Gateway is not used |
| 684 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 685 | else |
| 686 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 687 | BMCWEB_LOG_ERROR( |
| 688 | "Got extra property: {} on the {} object", |
| 689 | property.first, objpath.first.str); |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | // Check if given address is local, or global |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 693 | ipv4Address.linktype = |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 694 | ipv4Address.address.starts_with("169.254.") |
Johnathan Mantey | 18659d1 | 2019-06-07 10:26:29 -0700 | [diff] [blame] | 695 | ? LinkType::Local |
| 696 | : LinkType::Global; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | /** |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 704 | * @brief Deletes given IPv4 interface |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 705 | * |
| 706 | * @param[in] ifaceId Id of interface whose IP should be deleted |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 707 | * @param[in] ipHash DBus Hash id of IP that should be deleted |
| 708 | * @param[io] asyncResp Response object that will be returned to client |
| 709 | * |
| 710 | * @return None |
| 711 | */ |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 712 | inline void deleteIPAddress(const std::string& ifaceId, |
| 713 | const std::string& ipHash, |
| 714 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 715 | { |
| 716 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 717 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 718 | if (ec) |
| 719 | { |
| 720 | messages::internalError(asyncResp->res); |
| 721 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 722 | }, |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 723 | "xyz.openbmc_project.Network", |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 724 | "/xyz/openbmc_project/network/" + ifaceId + ipHash, |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 725 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 726 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 727 | |
Gunnar Mills | 244b6d5 | 2021-04-12 15:44:23 -0500 | [diff] [blame] | 728 | inline void updateIPv4DefaultGateway( |
| 729 | const std::string& ifaceId, const std::string& gateway, |
| 730 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 731 | { |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 732 | sdbusplus::asio::setProperty( |
| 733 | *crow::connections::systemBus, "xyz.openbmc_project.Network", |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 734 | "/xyz/openbmc_project/network/" + ifaceId, |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 735 | "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway", |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 736 | gateway, [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 737 | if (ec) |
| 738 | { |
| 739 | messages::internalError(asyncResp->res); |
| 740 | return; |
| 741 | } |
| 742 | asyncResp->res.result(boost::beast::http::status::no_content); |
| 743 | }); |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 744 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 745 | /** |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 746 | * @brief Creates a static IPv4 entry |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 747 | * |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 748 | * @param[in] ifaceId Id of interface upon which to create the IPv4 entry |
| 749 | * @param[in] prefixLength IPv4 prefix syntax for the subnet mask |
| 750 | * @param[in] gateway IPv4 address of this interfaces gateway |
| 751 | * @param[in] address IPv4 address to assign to this interface |
| 752 | * @param[io] asyncResp Response object that will be returned to client |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 753 | * |
| 754 | * @return None |
| 755 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 756 | inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength, |
| 757 | const std::string& gateway, const std::string& address, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 758 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 759 | { |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 760 | auto createIpHandler = [asyncResp, ifaceId, |
| 761 | gateway](const boost::system::error_code& ec) { |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 762 | if (ec) |
| 763 | { |
| 764 | messages::internalError(asyncResp->res); |
| 765 | return; |
| 766 | } |
| 767 | updateIPv4DefaultGateway(ifaceId, gateway, asyncResp); |
| 768 | }; |
| 769 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 770 | crow::connections::systemBus->async_method_call( |
Ravi Teja | 9010ec2 | 2019-08-01 23:30:25 -0500 | [diff] [blame] | 771 | std::move(createIpHandler), "xyz.openbmc_project.Network", |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 772 | "/xyz/openbmc_project/network/" + ifaceId, |
| 773 | "xyz.openbmc_project.Network.IP.Create", "IP", |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 774 | "xyz.openbmc_project.Network.IP.Protocol.IPv4", address, prefixLength, |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 775 | gateway); |
| 776 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 777 | |
| 778 | /** |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 779 | * @brief Deletes the IPv6 entry for this interface and creates a replacement |
| 780 | * static IPv6 entry |
| 781 | * |
| 782 | * @param[in] ifaceId Id of interface upon which to create the IPv6 entry |
| 783 | * @param[in] id The unique hash entry identifying the DBus entry |
| 784 | * @param[in] prefixLength IPv6 prefix syntax for the subnet mask |
| 785 | * @param[in] address IPv6 address to assign to this interface |
| 786 | * @param[io] asyncResp Response object that will be returned to client |
| 787 | * |
| 788 | * @return None |
| 789 | */ |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 790 | |
| 791 | enum class IpVersion |
| 792 | { |
| 793 | IpV4, |
| 794 | IpV6 |
| 795 | }; |
| 796 | |
| 797 | inline void deleteAndCreateIPAddress( |
| 798 | IpVersion version, const std::string& ifaceId, const std::string& id, |
| 799 | uint8_t prefixLength, const std::string& address, |
| 800 | const std::string& gateway, |
| 801 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 802 | { |
| 803 | crow::connections::systemBus->async_method_call( |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 804 | [asyncResp, version, ifaceId, address, prefixLength, |
| 805 | gateway](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 806 | if (ec) |
| 807 | { |
| 808 | messages::internalError(asyncResp->res); |
| 809 | } |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 810 | std::string protocol = "xyz.openbmc_project.Network.IP.Protocol."; |
| 811 | protocol += version == IpVersion::IpV4 ? "IPv4" : "IPv6"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 812 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 813 | [asyncResp](const boost::system::error_code& ec2) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 814 | if (ec2) |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 815 | { |
| 816 | messages::internalError(asyncResp->res); |
| 817 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 818 | }, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 819 | "xyz.openbmc_project.Network", |
| 820 | "/xyz/openbmc_project/network/" + ifaceId, |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 821 | "xyz.openbmc_project.Network.IP.Create", "IP", protocol, address, |
| 822 | prefixLength, gateway); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 823 | }, |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 824 | "xyz.openbmc_project.Network", |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 825 | "/xyz/openbmc_project/network/" + ifaceId + id, |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 826 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 827 | } |
| 828 | |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 829 | inline bool extractIPv6DefaultGatewayData( |
| 830 | const std::string& ethifaceId, |
| 831 | const dbus::utility::ManagedObjectType& dbusData, |
| 832 | std::vector<StaticGatewayData>& staticGatewayConfig) |
| 833 | { |
| 834 | std::string staticGatewayPathStart("/xyz/openbmc_project/network/"); |
| 835 | staticGatewayPathStart += ethifaceId; |
| 836 | |
| 837 | for (const auto& objpath : dbusData) |
| 838 | { |
| 839 | if (!std::string_view(objpath.first.str) |
| 840 | .starts_with(staticGatewayPathStart)) |
| 841 | { |
| 842 | continue; |
| 843 | } |
| 844 | for (const auto& interface : objpath.second) |
| 845 | { |
| 846 | if (interface.first != "xyz.openbmc_project.Network.StaticGateway") |
| 847 | { |
| 848 | continue; |
| 849 | } |
| 850 | StaticGatewayData& staticGateway = |
| 851 | staticGatewayConfig.emplace_back(); |
| 852 | staticGateway.id = objpath.first.filename(); |
| 853 | |
| 854 | bool success = sdbusplus::unpackPropertiesNoThrow( |
| 855 | redfish::dbus_utils::UnpackErrorPrinter(), interface.second, |
| 856 | "Gateway", staticGateway.gateway, "PrefixLength", |
| 857 | staticGateway.prefixLength, "ProtocolType", |
| 858 | staticGateway.protocol); |
| 859 | if (!success) |
| 860 | { |
| 861 | return false; |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | return true; |
| 866 | } |
| 867 | |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 868 | /** |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 869 | * @brief Creates IPv6 with given data |
| 870 | * |
| 871 | * @param[in] ifaceId Id of interface whose IP should be added |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 872 | * @param[in] prefixLength Prefix length that needs to be added |
| 873 | * @param[in] address IP address that needs to be added |
| 874 | * @param[io] asyncResp Response object that will be returned to client |
| 875 | * |
| 876 | * @return None |
| 877 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 878 | inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength, |
| 879 | const std::string& address, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 880 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 881 | { |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 882 | sdbusplus::message::object_path path("/xyz/openbmc_project/network"); |
| 883 | path /= ifaceId; |
| 884 | |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 885 | auto createIpHandler = [asyncResp, |
| 886 | address](const boost::system::error_code& ec) { |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 887 | if (ec) |
| 888 | { |
Nitin Kumar Kotania | fc23ef8 | 2023-06-29 04:55:09 -0500 | [diff] [blame] | 889 | if (ec == boost::system::errc::io_error) |
| 890 | { |
| 891 | messages::propertyValueFormatError(asyncResp->res, address, |
| 892 | "Address"); |
| 893 | } |
| 894 | else |
| 895 | { |
| 896 | messages::internalError(asyncResp->res); |
| 897 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 898 | } |
| 899 | }; |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 900 | // Passing null for gateway, as per redfish spec IPv6StaticAddresses |
| 901 | // object does not have associated gateway property |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 902 | crow::connections::systemBus->async_method_call( |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 903 | std::move(createIpHandler), "xyz.openbmc_project.Network", path, |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 904 | "xyz.openbmc_project.Network.IP.Create", "IP", |
| 905 | "xyz.openbmc_project.Network.IP.Protocol.IPv6", address, prefixLength, |
| 906 | ""); |
| 907 | } |
| 908 | |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 909 | /** |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 910 | * @brief Deletes given IPv6 Static Gateway |
| 911 | * |
| 912 | * @param[in] ifaceId Id of interface whose IP should be deleted |
| 913 | * @param[in] ipHash DBus Hash id of IP that should be deleted |
| 914 | * @param[io] asyncResp Response object that will be returned to client |
| 915 | * |
| 916 | * @return None |
| 917 | */ |
| 918 | inline void |
| 919 | deleteIPv6Gateway(std::string_view gatewayId, |
| 920 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 921 | { |
| 922 | sdbusplus::message::object_path path("/xyz/openbmc_project/network"); |
| 923 | path /= gatewayId; |
| 924 | crow::connections::systemBus->async_method_call( |
| 925 | [asyncResp](const boost::system::error_code& ec) { |
| 926 | if (ec) |
| 927 | { |
| 928 | messages::internalError(asyncResp->res); |
| 929 | } |
| 930 | }, |
| 931 | "xyz.openbmc_project.Network", path, |
| 932 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * @brief Creates IPv6 static default gateway with given data |
| 937 | * |
| 938 | * @param[in] ifaceId Id of interface whose IP should be added |
| 939 | * @param[in] prefixLength Prefix length that needs to be added |
| 940 | * @param[in] gateway Gateway address that needs to be added |
| 941 | * @param[io] asyncResp Response object that will be returned to client |
| 942 | * |
| 943 | * @return None |
| 944 | */ |
| 945 | inline void createIPv6DefaultGateway( |
| 946 | std::string_view ifaceId, size_t prefixLength, std::string_view gateway, |
| 947 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 948 | { |
| 949 | sdbusplus::message::object_path path("/xyz/openbmc_project/network"); |
| 950 | path /= ifaceId; |
| 951 | auto createIpHandler = [asyncResp](const boost::system::error_code& ec) { |
| 952 | if (ec) |
| 953 | { |
| 954 | messages::internalError(asyncResp->res); |
| 955 | } |
| 956 | }; |
| 957 | crow::connections::systemBus->async_method_call( |
| 958 | std::move(createIpHandler), "xyz.openbmc_project.Network", path, |
| 959 | "xyz.openbmc_project.Network.StaticGateway.Create", "StaticGateway", |
| 960 | gateway, prefixLength, "xyz.openbmc_project.Network.IP.Protocol.IPv6"); |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * @brief Deletes the IPv6 default gateway entry for this interface and |
| 965 | * creates a replacement IPv6 default gateway entry |
| 966 | * |
| 967 | * @param[in] ifaceId Id of interface upon which to create the IPv6 |
| 968 | * entry |
| 969 | * @param[in] gateway IPv6 gateway to assign to this interface |
| 970 | * @param[in] prefixLength IPv6 prefix syntax for the subnet mask |
| 971 | * @param[io] asyncResp Response object that will be returned to client |
| 972 | * |
| 973 | * @return None |
| 974 | */ |
| 975 | inline void deleteAndCreateIPv6DefaultGateway( |
| 976 | std::string_view ifaceId, std::string_view gatewayId, |
| 977 | std::string_view gateway, size_t prefixLength, |
| 978 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 979 | { |
| 980 | sdbusplus::message::object_path path("/xyz/openbmc_project/network"); |
| 981 | path /= gatewayId; |
| 982 | crow::connections::systemBus->async_method_call( |
| 983 | [asyncResp, ifaceId, gateway, |
| 984 | prefixLength](const boost::system::error_code& ec) { |
| 985 | if (ec) |
| 986 | { |
| 987 | messages::internalError(asyncResp->res); |
| 988 | return; |
| 989 | } |
| 990 | createIPv6DefaultGateway(ifaceId, prefixLength, gateway, asyncResp); |
| 991 | }, |
| 992 | "xyz.openbmc_project.Network", path, |
| 993 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * @brief Sets IPv6 default gateway with given data |
| 998 | * |
| 999 | * @param[in] ifaceId Id of interface whose gateway should be added |
| 1000 | * @param[in] input Contains address that needs to be added |
| 1001 | * @param[in] staticGatewayData Current static gateways in the system |
| 1002 | * @param[io] asyncResp Response object that will be returned to client |
| 1003 | * |
| 1004 | * @return None |
| 1005 | */ |
| 1006 | |
| 1007 | inline void handleIPv6DefaultGateway( |
| 1008 | const std::string& ifaceId, const nlohmann::json::array_t& input, |
| 1009 | const std::vector<StaticGatewayData>& staticGatewayData, |
| 1010 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1011 | { |
| 1012 | size_t entryIdx = 1; |
| 1013 | std::vector<StaticGatewayData>::const_iterator staticGatewayEntry = |
| 1014 | staticGatewayData.begin(); |
| 1015 | |
| 1016 | for (const nlohmann::json& thisJson : input) |
| 1017 | { |
| 1018 | // find the next gateway entry |
| 1019 | while (staticGatewayEntry != staticGatewayData.end()) |
| 1020 | { |
| 1021 | if (staticGatewayEntry->protocol == |
| 1022 | "xyz.openbmc_project.Network.IP.Protocol.IPv6") |
| 1023 | { |
| 1024 | break; |
| 1025 | } |
| 1026 | staticGatewayEntry++; |
| 1027 | } |
| 1028 | std::string pathString = "IPv6StaticDefaultGateways/" + |
| 1029 | std::to_string(entryIdx); |
| 1030 | if (thisJson.is_null()) |
| 1031 | { |
| 1032 | if (staticGatewayEntry == staticGatewayData.end()) |
| 1033 | { |
| 1034 | messages::resourceCannotBeDeleted(asyncResp->res); |
| 1035 | return; |
| 1036 | } |
| 1037 | deleteIPv6Gateway(staticGatewayEntry->id, asyncResp); |
| 1038 | return; |
| 1039 | } |
| 1040 | if (thisJson.is_object() && thisJson.empty()) |
| 1041 | { |
| 1042 | // Do nothing, but make sure the entry exists. |
| 1043 | if (staticGatewayEntry == staticGatewayData.end()) |
| 1044 | { |
| 1045 | messages::propertyValueFormatError(asyncResp->res, thisJson, |
| 1046 | pathString); |
| 1047 | return; |
| 1048 | } |
| 1049 | } |
| 1050 | std::optional<std::string> address; |
| 1051 | std::optional<size_t> prefixLength; |
| 1052 | |
| 1053 | nlohmann::json thisJsonCopy = thisJson; |
| 1054 | if (!json_util::readJson(thisJsonCopy, asyncResp->res, "Address", |
| 1055 | address, "PrefixLength", prefixLength)) |
| 1056 | { |
| 1057 | return; |
| 1058 | } |
| 1059 | const std::string* addr = nullptr; |
| 1060 | size_t prefix = 0; |
| 1061 | if (address) |
| 1062 | { |
| 1063 | addr = &(*address); |
| 1064 | } |
| 1065 | else if (staticGatewayEntry != staticGatewayData.end()) |
| 1066 | { |
| 1067 | addr = &(staticGatewayEntry->gateway); |
| 1068 | } |
| 1069 | else |
| 1070 | { |
| 1071 | messages::propertyMissing(asyncResp->res, pathString + "/Address"); |
| 1072 | return; |
| 1073 | } |
| 1074 | if (prefixLength) |
| 1075 | { |
| 1076 | prefix = *prefixLength; |
| 1077 | } |
| 1078 | else if (staticGatewayEntry != staticGatewayData.end()) |
| 1079 | { |
| 1080 | prefix = staticGatewayEntry->prefixLength; |
| 1081 | } |
| 1082 | else |
| 1083 | { |
| 1084 | messages::propertyMissing(asyncResp->res, |
| 1085 | pathString + "/PrefixLength"); |
| 1086 | return; |
| 1087 | } |
| 1088 | if (staticGatewayEntry != staticGatewayData.end()) |
| 1089 | { |
| 1090 | deleteAndCreateIPv6DefaultGateway(ifaceId, staticGatewayEntry->id, |
| 1091 | *addr, prefix, asyncResp); |
| 1092 | staticGatewayEntry++; |
| 1093 | } |
| 1094 | else |
| 1095 | { |
| 1096 | createIPv6DefaultGateway(ifaceId, prefix, *addr, asyncResp); |
| 1097 | } |
| 1098 | entryIdx++; |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | /** |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1103 | * Function that retrieves all properties for given Ethernet Interface |
| 1104 | * Object |
| 1105 | * from EntityManager Network Manager |
| 1106 | * @param ethiface_id a eth interface id to query on DBus |
| 1107 | * @param callback a function that shall be called to convert Dbus output |
| 1108 | * into JSON |
| 1109 | */ |
| 1110 | template <typename CallbackFunc> |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 1111 | void getEthernetIfaceData(const std::string& ethifaceId, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1112 | CallbackFunc&& callback) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1113 | { |
George Liu | f5892d0 | 2023-03-01 10:37:08 +0800 | [diff] [blame] | 1114 | sdbusplus::message::object_path path("/xyz/openbmc_project/network"); |
| 1115 | dbus::utility::getManagedObjects( |
| 1116 | "xyz.openbmc_project.Network", path, |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 1117 | [ethifaceId{std::string{ethifaceId}}, |
| 1118 | callback{std::forward<CallbackFunc>(callback)}]( |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 1119 | const boost::system::error_code& ec, |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 1120 | const dbus::utility::ManagedObjectType& resp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1121 | EthernetInterfaceData ethData{}; |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1122 | std::vector<IPv4AddressData> ipv4Data; |
| 1123 | std::vector<IPv6AddressData> ipv6Data; |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 1124 | std::vector<StaticGatewayData> ipv6GatewayData; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1125 | |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 1126 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1127 | { |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 1128 | callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1129 | return; |
| 1130 | } |
| 1131 | |
| 1132 | bool found = extractEthernetInterfaceData(ethifaceId, resp, ethData); |
| 1133 | if (!found) |
| 1134 | { |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 1135 | callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1136 | return; |
| 1137 | } |
| 1138 | |
| 1139 | extractIPData(ethifaceId, resp, ipv4Data); |
| 1140 | // Fix global GW |
| 1141 | for (IPv4AddressData& ipv4 : ipv4Data) |
| 1142 | { |
| 1143 | if (((ipv4.linktype == LinkType::Global) && |
| 1144 | (ipv4.gateway == "0.0.0.0")) || |
| 1145 | (ipv4.origin == "DHCP") || (ipv4.origin == "Static")) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1146 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1147 | ipv4.gateway = ethData.defaultGateway; |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1148 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1149 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1150 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1151 | extractIPV6Data(ethifaceId, resp, ipv6Data); |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 1152 | if (!extractIPv6DefaultGatewayData(ethifaceId, resp, ipv6GatewayData)) |
| 1153 | { |
| 1154 | callback(false, ethData, ipv4Data, ipv6Data, ipv6GatewayData); |
| 1155 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1156 | // Finally make a callback with useful data |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 1157 | callback(true, ethData, ipv4Data, ipv6Data, ipv6GatewayData); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1158 | }); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1159 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1160 | |
| 1161 | /** |
| 1162 | * Function that retrieves all Ethernet Interfaces available through Network |
| 1163 | * Manager |
| 1164 | * @param callback a function that shall be called to convert Dbus output |
| 1165 | * into JSON. |
| 1166 | */ |
| 1167 | template <typename CallbackFunc> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1168 | void getEthernetIfaceList(CallbackFunc&& callback) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1169 | { |
George Liu | f5892d0 | 2023-03-01 10:37:08 +0800 | [diff] [blame] | 1170 | sdbusplus::message::object_path path("/xyz/openbmc_project/network"); |
| 1171 | dbus::utility::getManagedObjects( |
| 1172 | "xyz.openbmc_project.Network", path, |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 1173 | [callback{std::forward<CallbackFunc>(callback)}]( |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 1174 | const boost::system::error_code& ec, |
George Liu | f5892d0 | 2023-03-01 10:37:08 +0800 | [diff] [blame] | 1175 | const dbus::utility::ManagedObjectType& resp) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1176 | // Callback requires vector<string> to retrieve all available |
| 1177 | // ethernet interfaces |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1178 | std::vector<std::string> ifaceList; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1179 | ifaceList.reserve(resp.size()); |
Ed Tanous | 8b24275 | 2023-06-27 17:17:13 -0700 | [diff] [blame] | 1180 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1181 | { |
| 1182 | callback(false, ifaceList); |
| 1183 | return; |
| 1184 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1185 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1186 | // Iterate over all retrieved ObjectPaths. |
| 1187 | for (const auto& objpath : resp) |
| 1188 | { |
| 1189 | // And all interfaces available for certain ObjectPath. |
| 1190 | for (const auto& interface : objpath.second) |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1191 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1192 | // If interface is |
| 1193 | // xyz.openbmc_project.Network.EthernetInterface, this is |
| 1194 | // what we're looking for. |
| 1195 | if (interface.first == |
| 1196 | "xyz.openbmc_project.Network.EthernetInterface") |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1197 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1198 | std::string ifaceId = objpath.first.filename(); |
| 1199 | if (ifaceId.empty()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1200 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1201 | continue; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1202 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1203 | // and put it into output vector. |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1204 | ifaceList.emplace_back(ifaceId); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1205 | } |
Ed Tanous | 4a0cb85 | 2018-10-15 07:55:04 -0700 | [diff] [blame] | 1206 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1207 | } |
Ed Tanous | 2c5875a | 2023-05-15 09:56:06 -0700 | [diff] [blame] | 1208 | |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 1209 | std::ranges::sort(ifaceList, AlphanumLess<std::string>()); |
Ed Tanous | 2c5875a | 2023-05-15 09:56:06 -0700 | [diff] [blame] | 1210 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1211 | // Finally make a callback with useful data |
| 1212 | callback(true, ifaceList); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1213 | }); |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1214 | } |
Rapkiewicz, Pawel | 9391bb9 | 2018-03-20 03:12:18 +0100 | [diff] [blame] | 1215 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1216 | inline void |
| 1217 | handleHostnamePatch(const std::string& hostname, |
| 1218 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1219 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1220 | // SHOULD handle host names of up to 255 characters(RFC 1123) |
| 1221 | if (hostname.length() > 255) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1222 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1223 | messages::propertyValueFormatError(asyncResp->res, hostname, |
| 1224 | "HostName"); |
| 1225 | return; |
| 1226 | } |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1227 | sdbusplus::asio::setProperty( |
| 1228 | *crow::connections::systemBus, "xyz.openbmc_project.Network", |
| 1229 | "/xyz/openbmc_project/network/config", |
| 1230 | "xyz.openbmc_project.Network.SystemConfiguration", "HostName", hostname, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1231 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1232 | if (ec) |
| 1233 | { |
| 1234 | messages::internalError(asyncResp->res); |
| 1235 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1236 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1239 | inline void |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 1240 | handleMTUSizePatch(const std::string& ifaceId, const size_t mtuSize, |
| 1241 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1242 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1243 | sdbusplus::message::object_path objPath = "/xyz/openbmc_project/network/" + |
| 1244 | ifaceId; |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1245 | sdbusplus::asio::setProperty( |
| 1246 | *crow::connections::systemBus, "xyz.openbmc_project.Network", objPath, |
| 1247 | "xyz.openbmc_project.Network.EthernetInterface", "MTU", mtuSize, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1248 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1249 | if (ec) |
| 1250 | { |
| 1251 | messages::internalError(asyncResp->res); |
| 1252 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1253 | }); |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | inline void |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1257 | handleDomainnamePatch(const std::string& ifaceId, |
| 1258 | const std::string& domainname, |
| 1259 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1260 | { |
| 1261 | std::vector<std::string> vectorDomainname = {domainname}; |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1262 | sdbusplus::asio::setProperty( |
| 1263 | *crow::connections::systemBus, "xyz.openbmc_project.Network", |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1264 | "/xyz/openbmc_project/network/" + ifaceId, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1265 | "xyz.openbmc_project.Network.EthernetInterface", "DomainName", |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1266 | vectorDomainname, [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1267 | if (ec) |
| 1268 | { |
| 1269 | messages::internalError(asyncResp->res); |
| 1270 | } |
| 1271 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1274 | inline bool isHostnameValid(const std::string& hostname) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1275 | { |
| 1276 | // A valid host name can never have the dotted-decimal form (RFC 1123) |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 1277 | if (std::ranges::all_of(hostname, ::isdigit)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1278 | { |
| 1279 | return false; |
| 1280 | } |
| 1281 | // Each label(hostname/subdomains) within a valid FQDN |
| 1282 | // MUST handle host names of up to 63 characters (RFC 1123) |
| 1283 | // labels cannot start or end with hyphens (RFC 952) |
| 1284 | // labels can start with numbers (RFC 1123) |
Ed Tanous | 4b24274 | 2023-05-11 09:51:51 -0700 | [diff] [blame] | 1285 | const static std::regex pattern( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1286 | "^[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]$"); |
| 1287 | |
| 1288 | return std::regex_match(hostname, pattern); |
| 1289 | } |
| 1290 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1291 | inline bool isDomainnameValid(const std::string& domainname) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1292 | { |
| 1293 | // Can have multiple subdomains |
| 1294 | // Top Level Domain's min length is 2 character |
Ed Tanous | 4b24274 | 2023-05-11 09:51:51 -0700 | [diff] [blame] | 1295 | const static std::regex pattern( |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1296 | "^([A-Za-z0-9][a-zA-Z0-9\\-]{1,61}|[a-zA-Z0-9]{1,30}\\.)*[a-zA-Z]{2,}$"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1297 | |
| 1298 | return std::regex_match(domainname, pattern); |
| 1299 | } |
| 1300 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1301 | inline void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn, |
| 1302 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1303 | { |
| 1304 | // Total length of FQDN must not exceed 255 characters(RFC 1035) |
| 1305 | if (fqdn.length() > 255) |
| 1306 | { |
| 1307 | messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN"); |
| 1308 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1311 | size_t pos = fqdn.find('.'); |
| 1312 | if (pos == std::string::npos) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1313 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1314 | messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN"); |
| 1315 | return; |
| 1316 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1317 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1318 | std::string hostname; |
| 1319 | std::string domainname; |
| 1320 | domainname = (fqdn).substr(pos + 1); |
| 1321 | hostname = (fqdn).substr(0, pos); |
| 1322 | |
| 1323 | if (!isHostnameValid(hostname) || !isDomainnameValid(domainname)) |
| 1324 | { |
| 1325 | messages::propertyValueFormatError(asyncResp->res, fqdn, "FQDN"); |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| 1329 | handleHostnamePatch(hostname, asyncResp); |
| 1330 | handleDomainnamePatch(ifaceId, domainname, asyncResp); |
| 1331 | } |
| 1332 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1333 | inline void |
| 1334 | handleMACAddressPatch(const std::string& ifaceId, |
| 1335 | const std::string& macAddress, |
| 1336 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1337 | { |
Johnathan Mantey | 58283f4 | 2022-08-15 14:38:36 -0700 | [diff] [blame] | 1338 | static constexpr std::string_view dbusNotAllowedError = |
| 1339 | "xyz.openbmc_project.Common.Error.NotAllowed"; |
| 1340 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1341 | sdbusplus::asio::setProperty( |
| 1342 | *crow::connections::systemBus, "xyz.openbmc_project.Network", |
| 1343 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1344 | "xyz.openbmc_project.Network.MACAddress", "MACAddress", macAddress, |
| 1345 | [asyncResp](const boost::system::error_code& ec, |
| 1346 | const sdbusplus::message_t& msg) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1347 | if (ec) |
| 1348 | { |
Johnathan Mantey | 58283f4 | 2022-08-15 14:38:36 -0700 | [diff] [blame] | 1349 | const sd_bus_error* err = msg.get_error(); |
| 1350 | if (err == nullptr) |
| 1351 | { |
| 1352 | messages::internalError(asyncResp->res); |
| 1353 | return; |
| 1354 | } |
| 1355 | if (err->name == dbusNotAllowedError) |
| 1356 | { |
| 1357 | messages::propertyNotWritable(asyncResp->res, "MACAddress"); |
| 1358 | return; |
| 1359 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1360 | messages::internalError(asyncResp->res); |
| 1361 | return; |
| 1362 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1363 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1366 | inline void setDHCPEnabled(const std::string& ifaceId, |
| 1367 | const std::string& propertyName, const bool v4Value, |
| 1368 | const bool v6Value, |
| 1369 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1370 | { |
| 1371 | const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value); |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1372 | sdbusplus::asio::setProperty( |
| 1373 | *crow::connections::systemBus, "xyz.openbmc_project.Network", |
| 1374 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1375 | "xyz.openbmc_project.Network.EthernetInterface", propertyName, dhcp, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1376 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1377 | if (ec) |
| 1378 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1379 | BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1380 | messages::internalError(asyncResp->res); |
| 1381 | return; |
| 1382 | } |
| 1383 | messages::success(asyncResp->res); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1384 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1387 | inline void setEthernetInterfaceBoolProperty( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1388 | const std::string& ifaceId, const std::string& propertyName, |
| 1389 | const bool& value, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1390 | { |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1391 | sdbusplus::asio::setProperty( |
| 1392 | *crow::connections::systemBus, "xyz.openbmc_project.Network", |
| 1393 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1394 | "xyz.openbmc_project.Network.EthernetInterface", propertyName, value, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1395 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1396 | if (ec) |
| 1397 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1398 | BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1399 | messages::internalError(asyncResp->res); |
| 1400 | return; |
| 1401 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1402 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1405 | enum class NetworkType |
| 1406 | { |
| 1407 | dhcp4, |
| 1408 | dhcp6 |
| 1409 | }; |
| 1410 | |
| 1411 | inline void setDHCPConfig(const std::string& propertyName, const bool& value, |
| 1412 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1413 | const std::string& ethifaceId, NetworkType type) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1414 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1415 | BMCWEB_LOG_DEBUG("{} = {}", propertyName, value); |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1416 | sdbusplus::message::object_path path("/xyz/openbmc_project/network/"); |
| 1417 | path /= ethifaceId; |
| 1418 | |
| 1419 | if (type == NetworkType::dhcp4) |
| 1420 | { |
| 1421 | path /= "dhcp4"; |
| 1422 | } |
| 1423 | else |
| 1424 | { |
| 1425 | path /= "dhcp6"; |
| 1426 | } |
| 1427 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1428 | sdbusplus::asio::setProperty( |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1429 | *crow::connections::systemBus, "xyz.openbmc_project.Network", path, |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1430 | "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, value, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1431 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1432 | if (ec) |
| 1433 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1434 | BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1435 | messages::internalError(asyncResp->res); |
| 1436 | return; |
| 1437 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1438 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 1441 | inline void handleSLAACAutoConfigPatch( |
| 1442 | const std::string& ifaceId, bool ipv6AutoConfigEnabled, |
| 1443 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1444 | { |
| 1445 | sdbusplus::message::object_path path("/xyz/openbmc_project/network"); |
| 1446 | path /= ifaceId; |
| 1447 | sdbusplus::asio::setProperty( |
| 1448 | *crow::connections::systemBus, "xyz.openbmc_project.Network", path, |
| 1449 | "xyz.openbmc_project.Network.EthernetInterface", "IPv6AcceptRA", |
| 1450 | ipv6AutoConfigEnabled, |
| 1451 | [asyncResp](const boost::system::error_code& ec) { |
| 1452 | if (ec) |
| 1453 | { |
| 1454 | BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); |
| 1455 | messages::internalError(asyncResp->res); |
| 1456 | return; |
| 1457 | } |
| 1458 | messages::success(asyncResp->res); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1459 | }); |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 1460 | } |
| 1461 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1462 | inline void handleDHCPPatch(const std::string& ifaceId, |
| 1463 | const EthernetInterfaceData& ethData, |
| 1464 | const DHCPParameters& v4dhcpParms, |
| 1465 | const DHCPParameters& v6dhcpParms, |
| 1466 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1467 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1468 | bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true); |
| 1469 | bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1470 | |
| 1471 | bool nextv4DHCPState = |
| 1472 | v4dhcpParms.dhcpv4Enabled ? *v4dhcpParms.dhcpv4Enabled : ipv4Active; |
| 1473 | |
| 1474 | bool nextv6DHCPState{}; |
| 1475 | if (v6dhcpParms.dhcpv6OperatingMode) |
| 1476 | { |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 1477 | if ((*v6dhcpParms.dhcpv6OperatingMode != "Enabled") && |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1478 | (*v6dhcpParms.dhcpv6OperatingMode != "Disabled")) |
| 1479 | { |
| 1480 | messages::propertyValueFormatError(asyncResp->res, |
| 1481 | *v6dhcpParms.dhcpv6OperatingMode, |
| 1482 | "OperatingMode"); |
| 1483 | return; |
| 1484 | } |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 1485 | nextv6DHCPState = (*v6dhcpParms.dhcpv6OperatingMode == "Enabled"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1486 | } |
| 1487 | else |
| 1488 | { |
| 1489 | nextv6DHCPState = ipv6Active; |
| 1490 | } |
| 1491 | |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1492 | bool nextDNSv4 = ethData.dnsv4Enabled; |
| 1493 | bool nextDNSv6 = ethData.dnsv6Enabled; |
| 1494 | if (v4dhcpParms.useDnsServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1495 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1496 | nextDNSv4 = *v4dhcpParms.useDnsServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1497 | } |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1498 | if (v6dhcpParms.useDnsServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1499 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1500 | nextDNSv6 = *v6dhcpParms.useDnsServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1503 | bool nextNTPv4 = ethData.ntpv4Enabled; |
| 1504 | bool nextNTPv6 = ethData.ntpv6Enabled; |
| 1505 | if (v4dhcpParms.useNtpServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1506 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1507 | nextNTPv4 = *v4dhcpParms.useNtpServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1508 | } |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1509 | if (v6dhcpParms.useNtpServers) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1510 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1511 | nextNTPv6 = *v6dhcpParms.useNtpServers; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
Ravi Teja | 91c441e | 2024-02-23 09:03:43 -0600 | [diff] [blame] | 1514 | bool nextUsev4Domain = ethData.domainv4Enabled; |
| 1515 | bool nextUsev6Domain = ethData.domainv6Enabled; |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1516 | if (v4dhcpParms.useDomainName) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1517 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1518 | nextUsev4Domain = *v4dhcpParms.useDomainName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1519 | } |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1520 | if (v6dhcpParms.useDomainName) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1521 | { |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1522 | nextUsev6Domain = *v6dhcpParms.useDomainName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1525 | BMCWEB_LOG_DEBUG("set DHCPEnabled..."); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1526 | setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState, |
| 1527 | asyncResp); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1528 | BMCWEB_LOG_DEBUG("set DNSEnabled..."); |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1529 | setDHCPConfig("DNSEnabled", nextDNSv4, asyncResp, ifaceId, |
| 1530 | NetworkType::dhcp4); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1531 | BMCWEB_LOG_DEBUG("set NTPEnabled..."); |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1532 | setDHCPConfig("NTPEnabled", nextNTPv4, asyncResp, ifaceId, |
| 1533 | NetworkType::dhcp4); |
Ravi Teja | 91c441e | 2024-02-23 09:03:43 -0600 | [diff] [blame] | 1534 | BMCWEB_LOG_DEBUG("set DomainEnabled..."); |
| 1535 | setDHCPConfig("DomainEnabled", nextUsev4Domain, asyncResp, ifaceId, |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1536 | NetworkType::dhcp4); |
| 1537 | BMCWEB_LOG_DEBUG("set DNSEnabled for dhcp6..."); |
| 1538 | setDHCPConfig("DNSEnabled", nextDNSv6, asyncResp, ifaceId, |
| 1539 | NetworkType::dhcp6); |
| 1540 | BMCWEB_LOG_DEBUG("set NTPEnabled for dhcp6..."); |
| 1541 | setDHCPConfig("NTPEnabled", nextNTPv6, asyncResp, ifaceId, |
| 1542 | NetworkType::dhcp6); |
Ravi Teja | 91c441e | 2024-02-23 09:03:43 -0600 | [diff] [blame] | 1543 | BMCWEB_LOG_DEBUG("set DomainEnabled for dhcp6..."); |
| 1544 | setDHCPConfig("DomainEnabled", nextUsev6Domain, asyncResp, ifaceId, |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1545 | NetworkType::dhcp6); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1548 | inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry( |
| 1549 | const std::vector<IPv4AddressData>::const_iterator& head, |
| 1550 | const std::vector<IPv4AddressData>::const_iterator& end) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1551 | { |
| 1552 | return std::find_if(head, end, [](const IPv4AddressData& value) { |
| 1553 | return value.origin == "Static"; |
| 1554 | }); |
| 1555 | } |
| 1556 | |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1557 | inline std::vector<IPv6AddressData>::const_iterator getNextStaticIpEntry( |
| 1558 | const std::vector<IPv6AddressData>::const_iterator& head, |
| 1559 | const std::vector<IPv6AddressData>::const_iterator& end) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1560 | { |
| 1561 | return std::find_if(head, end, [](const IPv6AddressData& value) { |
| 1562 | return value.origin == "Static"; |
| 1563 | }); |
| 1564 | } |
| 1565 | |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1566 | inline void |
Ed Tanous | ddd70dc | 2023-03-01 16:00:27 -0800 | [diff] [blame] | 1567 | handleIPv4StaticPatch(const std::string& ifaceId, |
| 1568 | nlohmann::json::array_t& input, |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1569 | const std::vector<IPv4AddressData>& ipv4Data, |
| 1570 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1571 | { |
Ed Tanous | ddd70dc | 2023-03-01 16:00:27 -0800 | [diff] [blame] | 1572 | if (input.empty()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1573 | { |
Ed Tanous | 2e8c4bd | 2022-06-27 12:59:12 -0700 | [diff] [blame] | 1574 | messages::propertyValueTypeError(asyncResp->res, input, |
| 1575 | "IPv4StaticAddresses"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1576 | return; |
| 1577 | } |
| 1578 | |
| 1579 | unsigned entryIdx = 1; |
| 1580 | // Find the first static IP address currently active on the NIC and |
| 1581 | // match it to the first JSON element in the IPv4StaticAddresses array. |
| 1582 | // Match each subsequent JSON element to the next static IP programmed |
| 1583 | // into the NIC. |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1584 | std::vector<IPv4AddressData>::const_iterator nicIpEntry = |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1585 | getNextStaticIpEntry(ipv4Data.cbegin(), ipv4Data.cend()); |
| 1586 | |
| 1587 | for (nlohmann::json& thisJson : input) |
| 1588 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1589 | std::string pathString = "IPv4StaticAddresses/" + |
| 1590 | std::to_string(entryIdx); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1591 | |
| 1592 | if (!thisJson.is_null() && !thisJson.empty()) |
| 1593 | { |
| 1594 | std::optional<std::string> address; |
| 1595 | std::optional<std::string> subnetMask; |
| 1596 | std::optional<std::string> gateway; |
| 1597 | |
| 1598 | if (!json_util::readJson(thisJson, asyncResp->res, "Address", |
| 1599 | address, "SubnetMask", subnetMask, |
| 1600 | "Gateway", gateway)) |
| 1601 | { |
Ed Tanous | f818b04 | 2022-06-27 13:17:35 -0700 | [diff] [blame] | 1602 | messages::propertyValueFormatError(asyncResp->res, thisJson, |
| 1603 | pathString); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1604 | return; |
| 1605 | } |
| 1606 | |
| 1607 | // Find the address/subnet/gateway values. Any values that are |
| 1608 | // not explicitly provided are assumed to be unmodified from the |
| 1609 | // current state of the interface. Merge existing state into the |
| 1610 | // current request. |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1611 | if (address) |
| 1612 | { |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1613 | if (!ip_util::ipv4VerifyIpAndGetBitcount(*address)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1614 | { |
| 1615 | messages::propertyValueFormatError(asyncResp->res, *address, |
| 1616 | pathString + "/Address"); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1617 | return; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1618 | } |
| 1619 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1620 | else if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1621 | { |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1622 | address = (nicIpEntry->address); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1623 | } |
| 1624 | else |
| 1625 | { |
| 1626 | messages::propertyMissing(asyncResp->res, |
| 1627 | pathString + "/Address"); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1628 | return; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1631 | uint8_t prefixLength = 0; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1632 | if (subnetMask) |
| 1633 | { |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 1634 | if (!ip_util::ipv4VerifyIpAndGetBitcount(*subnetMask, |
| 1635 | &prefixLength)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1636 | { |
| 1637 | messages::propertyValueFormatError( |
| 1638 | asyncResp->res, *subnetMask, |
| 1639 | pathString + "/SubnetMask"); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1640 | return; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1641 | } |
| 1642 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1643 | else if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1644 | { |
Ed Tanous | 033f1e4 | 2022-08-15 09:47:37 -0700 | [diff] [blame] | 1645 | if (!ip_util::ipv4VerifyIpAndGetBitcount(nicIpEntry->netmask, |
| 1646 | &prefixLength)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1647 | { |
| 1648 | messages::propertyValueFormatError( |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1649 | asyncResp->res, nicIpEntry->netmask, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1650 | pathString + "/SubnetMask"); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1651 | return; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1652 | } |
| 1653 | } |
| 1654 | else |
| 1655 | { |
| 1656 | messages::propertyMissing(asyncResp->res, |
| 1657 | pathString + "/SubnetMask"); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1658 | return; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | if (gateway) |
| 1662 | { |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1663 | if (!ip_util::ipv4VerifyIpAndGetBitcount(*gateway)) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1664 | { |
| 1665 | messages::propertyValueFormatError(asyncResp->res, *gateway, |
| 1666 | pathString + "/Gateway"); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1667 | return; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1668 | } |
| 1669 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1670 | else if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1671 | { |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1672 | gateway = nicIpEntry->gateway; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1673 | } |
| 1674 | else |
| 1675 | { |
| 1676 | messages::propertyMissing(asyncResp->res, |
| 1677 | pathString + "/Gateway"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1678 | return; |
| 1679 | } |
| 1680 | |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1681 | if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1682 | { |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 1683 | deleteAndCreateIPAddress(IpVersion::IpV4, ifaceId, |
Ed Tanous | 77eb015 | 2023-09-06 10:19:18 -0700 | [diff] [blame] | 1684 | nicIpEntry->id, prefixLength, *address, |
| 1685 | *gateway, asyncResp); |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1686 | nicIpEntry = getNextStaticIpEntry(++nicIpEntry, |
| 1687 | ipv4Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1688 | } |
| 1689 | else |
| 1690 | { |
| 1691 | createIPv4(ifaceId, prefixLength, *gateway, *address, |
| 1692 | asyncResp); |
| 1693 | } |
| 1694 | entryIdx++; |
| 1695 | } |
| 1696 | else |
| 1697 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1698 | if (nicIpEntry == ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1699 | { |
| 1700 | // Requesting a DELETE/DO NOT MODIFY action for an item |
| 1701 | // that isn't present on the eth(n) interface. Input JSON is |
| 1702 | // in error, so bail out. |
| 1703 | if (thisJson.is_null()) |
| 1704 | { |
| 1705 | messages::resourceCannotBeDeleted(asyncResp->res); |
| 1706 | return; |
| 1707 | } |
Ed Tanous | f818b04 | 2022-06-27 13:17:35 -0700 | [diff] [blame] | 1708 | messages::propertyValueFormatError(asyncResp->res, thisJson, |
| 1709 | pathString); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1710 | return; |
| 1711 | } |
| 1712 | |
| 1713 | if (thisJson.is_null()) |
| 1714 | { |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 1715 | deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1716 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1717 | if (nicIpEntry != ipv4Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1718 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1719 | nicIpEntry = getNextStaticIpEntry(++nicIpEntry, |
| 1720 | ipv4Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1721 | } |
| 1722 | entryIdx++; |
| 1723 | } |
| 1724 | } |
| 1725 | } |
| 1726 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1727 | inline void handleStaticNameServersPatch( |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1728 | const std::string& ifaceId, |
| 1729 | const std::vector<std::string>& updatedStaticNameServers, |
| 1730 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1731 | { |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1732 | sdbusplus::asio::setProperty( |
| 1733 | *crow::connections::systemBus, "xyz.openbmc_project.Network", |
| 1734 | "/xyz/openbmc_project/network/" + ifaceId, |
| 1735 | "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers", |
| 1736 | updatedStaticNameServers, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1737 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1738 | if (ec) |
| 1739 | { |
| 1740 | messages::internalError(asyncResp->res); |
| 1741 | return; |
| 1742 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1743 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 1746 | inline void handleIPv6StaticAddressesPatch( |
Ed Tanous | ddd70dc | 2023-03-01 16:00:27 -0800 | [diff] [blame] | 1747 | const std::string& ifaceId, const nlohmann::json::array_t& input, |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1748 | const std::vector<IPv6AddressData>& ipv6Data, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1749 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1750 | { |
Ed Tanous | ddd70dc | 2023-03-01 16:00:27 -0800 | [diff] [blame] | 1751 | if (input.empty()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1752 | { |
Ed Tanous | 2e8c4bd | 2022-06-27 12:59:12 -0700 | [diff] [blame] | 1753 | messages::propertyValueTypeError(asyncResp->res, input, |
| 1754 | "IPv6StaticAddresses"); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1755 | return; |
| 1756 | } |
| 1757 | size_t entryIdx = 1; |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1758 | std::vector<IPv6AddressData>::const_iterator nicIpEntry = |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1759 | getNextStaticIpEntry(ipv6Data.cbegin(), ipv6Data.cend()); |
| 1760 | for (const nlohmann::json& thisJson : input) |
| 1761 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1762 | std::string pathString = "IPv6StaticAddresses/" + |
| 1763 | std::to_string(entryIdx); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1764 | |
| 1765 | if (!thisJson.is_null() && !thisJson.empty()) |
| 1766 | { |
| 1767 | std::optional<std::string> address; |
| 1768 | std::optional<uint8_t> prefixLength; |
| 1769 | nlohmann::json thisJsonCopy = thisJson; |
| 1770 | if (!json_util::readJson(thisJsonCopy, asyncResp->res, "Address", |
| 1771 | address, "PrefixLength", prefixLength)) |
| 1772 | { |
Ed Tanous | f818b04 | 2022-06-27 13:17:35 -0700 | [diff] [blame] | 1773 | messages::propertyValueFormatError(asyncResp->res, thisJson, |
| 1774 | pathString); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1775 | return; |
| 1776 | } |
| 1777 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1778 | // Find the address and prefixLength values. Any values that are |
| 1779 | // not explicitly provided are assumed to be unmodified from the |
| 1780 | // current state of the interface. Merge existing state into the |
| 1781 | // current request. |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame^] | 1782 | if (!address) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1783 | { |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame^] | 1784 | if (nicIpEntry == ipv6Data.end()) |
| 1785 | { |
| 1786 | messages::propertyMissing(asyncResp->res, |
| 1787 | pathString + "/Address"); |
| 1788 | return; |
| 1789 | } |
| 1790 | address = nicIpEntry->address; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame^] | 1793 | if (!prefixLength) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1794 | { |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame^] | 1795 | if (nicIpEntry == ipv6Data.end()) |
| 1796 | { |
| 1797 | messages::propertyMissing(asyncResp->res, |
| 1798 | pathString + "/PrefixLength"); |
| 1799 | return; |
| 1800 | } |
| 1801 | prefixLength = nicIpEntry->prefixLength; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1804 | if (nicIpEntry != ipv6Data.end()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1805 | { |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 1806 | deleteAndCreateIPAddress(IpVersion::IpV6, ifaceId, |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame^] | 1807 | nicIpEntry->id, *prefixLength, |
| 1808 | *address, "", asyncResp); |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1809 | nicIpEntry = getNextStaticIpEntry(++nicIpEntry, |
| 1810 | ipv6Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1811 | } |
| 1812 | else |
| 1813 | { |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame^] | 1814 | createIPv6(ifaceId, *prefixLength, *address, asyncResp); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1815 | } |
| 1816 | entryIdx++; |
| 1817 | } |
| 1818 | else |
| 1819 | { |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1820 | if (nicIpEntry == ipv6Data.end()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1821 | { |
| 1822 | // Requesting a DELETE/DO NOT MODIFY action for an item |
| 1823 | // that isn't present on the eth(n) interface. Input JSON is |
| 1824 | // in error, so bail out. |
| 1825 | if (thisJson.is_null()) |
| 1826 | { |
| 1827 | messages::resourceCannotBeDeleted(asyncResp->res); |
| 1828 | return; |
| 1829 | } |
Ed Tanous | f818b04 | 2022-06-27 13:17:35 -0700 | [diff] [blame] | 1830 | messages::propertyValueFormatError(asyncResp->res, thisJson, |
| 1831 | pathString); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1832 | return; |
| 1833 | } |
| 1834 | |
| 1835 | if (thisJson.is_null()) |
| 1836 | { |
Ravi Teja | 9c5e585 | 2023-02-26 21:33:52 -0600 | [diff] [blame] | 1837 | deleteIPAddress(ifaceId, nicIpEntry->id, asyncResp); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1838 | } |
Jiaqing Zhao | 85ffe86 | 2021-12-31 15:41:59 +0800 | [diff] [blame] | 1839 | if (nicIpEntry != ipv6Data.cend()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1840 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 1841 | nicIpEntry = getNextStaticIpEntry(++nicIpEntry, |
| 1842 | ipv6Data.cend()); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1843 | } |
| 1844 | entryIdx++; |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | |
Jiaqing Zhao | 7857cb8 | 2023-03-03 11:23:08 +0800 | [diff] [blame] | 1849 | inline std::string extractParentInterfaceName(const std::string& ifaceId) |
| 1850 | { |
| 1851 | std::size_t pos = ifaceId.find('_'); |
| 1852 | return ifaceId.substr(0, pos); |
| 1853 | } |
| 1854 | |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 1855 | inline void |
| 1856 | parseInterfaceData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1857 | const std::string& ifaceId, |
| 1858 | const EthernetInterfaceData& ethData, |
| 1859 | const std::vector<IPv4AddressData>& ipv4Data, |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 1860 | const std::vector<IPv6AddressData>& ipv6Data, |
| 1861 | const std::vector<StaticGatewayData>& ipv6GatewayData) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1862 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1863 | nlohmann::json& jsonResponse = asyncResp->res.jsonValue; |
| 1864 | jsonResponse["Id"] = ifaceId; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1865 | jsonResponse["@odata.id"] = boost::urls::format( |
| 1866 | "/redfish/v1/Managers/bmc/EthernetInterfaces/{}", ifaceId); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1867 | jsonResponse["InterfaceEnabled"] = ethData.nicEnabled; |
| 1868 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 1869 | if constexpr (bmcwebEnableHealthPopulate) |
| 1870 | { |
| 1871 | constexpr std::array<std::string_view, 1> inventoryForEthernet = { |
| 1872 | "xyz.openbmc_project.Inventory.Item.Ethernet"}; |
| 1873 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 1874 | dbus::utility::getSubTreePaths( |
| 1875 | "/", 0, inventoryForEthernet, |
| 1876 | [health](const boost::system::error_code& ec, |
| 1877 | const dbus::utility::MapperGetSubTreePathsResponse& resp) { |
| 1878 | if (ec) |
| 1879 | { |
| 1880 | return; |
| 1881 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1882 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 1883 | health->inventory = resp; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1884 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1885 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 1886 | health->populate(); |
| 1887 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1888 | |
| 1889 | if (ethData.nicEnabled) |
| 1890 | { |
Johnathan Mantey | 0ef0e28 | 2022-11-15 12:15:02 -0800 | [diff] [blame] | 1891 | jsonResponse["LinkStatus"] = ethData.linkUp ? "LinkUp" : "LinkDown"; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1892 | jsonResponse["Status"]["State"] = "Enabled"; |
| 1893 | } |
| 1894 | else |
| 1895 | { |
| 1896 | jsonResponse["LinkStatus"] = "NoLink"; |
| 1897 | jsonResponse["Status"]["State"] = "Disabled"; |
| 1898 | } |
| 1899 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1900 | jsonResponse["SpeedMbps"] = ethData.speed; |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 1901 | jsonResponse["MTUSize"] = ethData.mtuSize; |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1902 | jsonResponse["MACAddress"] = ethData.macAddress; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1903 | jsonResponse["DHCPv4"]["DHCPEnabled"] = |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1904 | translateDhcpEnabledToBool(ethData.dhcpEnabled, true); |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1905 | jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpv4Enabled; |
| 1906 | jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsv4Enabled; |
| 1907 | jsonResponse["DHCPv4"]["UseDomainName"] = ethData.hostNamev4Enabled; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1908 | jsonResponse["DHCPv6"]["OperatingMode"] = |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 1909 | translateDhcpEnabledToBool(ethData.dhcpEnabled, false) ? "Enabled" |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1910 | : "Disabled"; |
Jishnu CM | e458815 | 2023-05-11 00:04:40 -0500 | [diff] [blame] | 1911 | jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpv6Enabled; |
| 1912 | jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsv6Enabled; |
| 1913 | jsonResponse["DHCPv6"]["UseDomainName"] = ethData.hostNamev6Enabled; |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 1914 | jsonResponse["StatelessAddressAutoConfig"]["IPv6AutoConfigEnabled"] = |
| 1915 | ethData.ipv6AcceptRa; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1916 | |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1917 | if (!ethData.hostName.empty()) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1918 | { |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1919 | jsonResponse["HostName"] = ethData.hostName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1920 | |
| 1921 | // When domain name is empty then it means, that it is a network |
| 1922 | // without domain names, and the host name itself must be treated as |
| 1923 | // FQDN |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1924 | std::string fqdn = ethData.hostName; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1925 | if (!ethData.domainnames.empty()) |
| 1926 | { |
| 1927 | fqdn += "." + ethData.domainnames[0]; |
| 1928 | } |
| 1929 | jsonResponse["FQDN"] = fqdn; |
| 1930 | } |
| 1931 | |
Jiaqing Zhao | 7857cb8 | 2023-03-03 11:23:08 +0800 | [diff] [blame] | 1932 | if (ethData.vlanId) |
| 1933 | { |
| 1934 | jsonResponse["EthernetInterfaceType"] = "Virtual"; |
| 1935 | jsonResponse["VLAN"]["VLANEnable"] = true; |
| 1936 | jsonResponse["VLAN"]["VLANId"] = *ethData.vlanId; |
| 1937 | jsonResponse["VLAN"]["Tagged"] = true; |
| 1938 | |
| 1939 | nlohmann::json::array_t relatedInterfaces; |
| 1940 | nlohmann::json& parentInterface = relatedInterfaces.emplace_back(); |
| 1941 | parentInterface["@odata.id"] = |
| 1942 | boost::urls::format("/redfish/v1/Managers/bmc/EthernetInterfaces", |
| 1943 | extractParentInterfaceName(ifaceId)); |
| 1944 | jsonResponse["Links"]["RelatedInterfaces"] = |
| 1945 | std::move(relatedInterfaces); |
| 1946 | } |
| 1947 | else |
| 1948 | { |
| 1949 | jsonResponse["EthernetInterfaceType"] = "Physical"; |
| 1950 | } |
| 1951 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1952 | jsonResponse["NameServers"] = ethData.nameServers; |
| 1953 | jsonResponse["StaticNameServers"] = ethData.staticNameServers; |
| 1954 | |
| 1955 | nlohmann::json& ipv4Array = jsonResponse["IPv4Addresses"]; |
| 1956 | nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"]; |
| 1957 | ipv4Array = nlohmann::json::array(); |
| 1958 | ipv4StaticArray = nlohmann::json::array(); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 1959 | for (const auto& ipv4Config : ipv4Data) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1960 | { |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1961 | std::string gatewayStr = ipv4Config.gateway; |
| 1962 | if (gatewayStr.empty()) |
| 1963 | { |
| 1964 | gatewayStr = "0.0.0.0"; |
| 1965 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1966 | nlohmann::json::object_t ipv4; |
| 1967 | ipv4["AddressOrigin"] = ipv4Config.origin; |
| 1968 | ipv4["SubnetMask"] = ipv4Config.netmask; |
| 1969 | ipv4["Address"] = ipv4Config.address; |
| 1970 | ipv4["Gateway"] = gatewayStr; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1971 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1972 | if (ipv4Config.origin == "Static") |
| 1973 | { |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1974 | ipv4StaticArray.push_back(ipv4); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1975 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 1976 | |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 1977 | ipv4Array.emplace_back(std::move(ipv4)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Jiaqing Zhao | 82695a5 | 2022-04-14 15:15:59 +0800 | [diff] [blame] | 1980 | std::string ipv6GatewayStr = ethData.ipv6DefaultGateway; |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1981 | if (ipv6GatewayStr.empty()) |
| 1982 | { |
| 1983 | ipv6GatewayStr = "0:0:0:0:0:0:0:0"; |
| 1984 | } |
| 1985 | |
| 1986 | jsonResponse["IPv6DefaultGateway"] = ipv6GatewayStr; |
| 1987 | |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 1988 | nlohmann::json::array_t ipv6StaticGatewayArray; |
| 1989 | for (const auto& ipv6GatewayConfig : ipv6GatewayData) |
| 1990 | { |
| 1991 | nlohmann::json::object_t ipv6Gateway; |
| 1992 | ipv6Gateway["Address"] = ipv6GatewayConfig.gateway; |
| 1993 | ipv6Gateway["PrefixLength"] = ipv6GatewayConfig.prefixLength; |
| 1994 | ipv6StaticGatewayArray.emplace_back(std::move(ipv6Gateway)); |
| 1995 | } |
| 1996 | jsonResponse["IPv6StaticDefaultGateways"] = |
| 1997 | std::move(ipv6StaticGatewayArray); |
| 1998 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 1999 | nlohmann::json& ipv6Array = jsonResponse["IPv6Addresses"]; |
| 2000 | nlohmann::json& ipv6StaticArray = jsonResponse["IPv6StaticAddresses"]; |
| 2001 | ipv6Array = nlohmann::json::array(); |
| 2002 | ipv6StaticArray = nlohmann::json::array(); |
| 2003 | nlohmann::json& ipv6AddrPolicyTable = |
| 2004 | jsonResponse["IPv6AddressPolicyTable"]; |
| 2005 | ipv6AddrPolicyTable = nlohmann::json::array(); |
Ed Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 2006 | for (const auto& ipv6Config : ipv6Data) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2007 | { |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 2008 | nlohmann::json::object_t ipv6; |
| 2009 | ipv6["Address"] = ipv6Config.address; |
| 2010 | ipv6["PrefixLength"] = ipv6Config.prefixLength; |
| 2011 | ipv6["AddressOrigin"] = ipv6Config.origin; |
Sunitha Harish | f836127 | 2023-03-16 03:23:59 -0500 | [diff] [blame] | 2012 | |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 2013 | ipv6Array.emplace_back(std::move(ipv6)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2014 | if (ipv6Config.origin == "Static") |
| 2015 | { |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 2016 | nlohmann::json::object_t ipv6Static; |
| 2017 | ipv6Static["Address"] = ipv6Config.address; |
| 2018 | ipv6Static["PrefixLength"] = ipv6Config.prefixLength; |
Patrick Williams | b2ba307 | 2023-05-12 10:27:39 -0500 | [diff] [blame] | 2019 | ipv6StaticArray.emplace_back(std::move(ipv6Static)); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2020 | } |
| 2021 | } |
| 2022 | } |
| 2023 | |
Jiaqing Zhao | e7caf25 | 2023-03-09 11:14:44 +0800 | [diff] [blame] | 2024 | inline void afterDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2025 | const std::string& ifaceId, |
| 2026 | const boost::system::error_code& ec, |
| 2027 | const sdbusplus::message_t& m) |
| 2028 | { |
| 2029 | if (!ec) |
| 2030 | { |
| 2031 | return; |
| 2032 | } |
| 2033 | const sd_bus_error* dbusError = m.get_error(); |
| 2034 | if (dbusError == nullptr) |
| 2035 | { |
| 2036 | messages::internalError(asyncResp->res); |
| 2037 | return; |
| 2038 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2039 | BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name); |
Jiaqing Zhao | e7caf25 | 2023-03-09 11:14:44 +0800 | [diff] [blame] | 2040 | |
| 2041 | if (std::string_view("org.freedesktop.DBus.Error.UnknownObject") == |
| 2042 | dbusError->name) |
| 2043 | { |
| 2044 | messages::resourceNotFound(asyncResp->res, "EthernetInterface", |
| 2045 | ifaceId); |
| 2046 | return; |
| 2047 | } |
| 2048 | if (std::string_view("org.freedesktop.DBus.Error.UnknownMethod") == |
| 2049 | dbusError->name) |
| 2050 | { |
| 2051 | messages::resourceCannotBeDeleted(asyncResp->res); |
| 2052 | return; |
| 2053 | } |
| 2054 | messages::internalError(asyncResp->res); |
| 2055 | } |
| 2056 | |
Jiaqing Zhao | b5ca3fd | 2023-03-08 15:14:58 +0800 | [diff] [blame] | 2057 | inline void afterVlanCreate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2058 | const std::string& parentInterfaceUri, |
| 2059 | const std::string& vlanInterface, |
| 2060 | const boost::system::error_code& ec, |
| 2061 | const sdbusplus::message_t& m |
| 2062 | |
| 2063 | ) |
| 2064 | { |
| 2065 | if (ec) |
| 2066 | { |
| 2067 | const sd_bus_error* dbusError = m.get_error(); |
| 2068 | if (dbusError == nullptr) |
| 2069 | { |
| 2070 | messages::internalError(asyncResp->res); |
| 2071 | return; |
| 2072 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2073 | BMCWEB_LOG_DEBUG("DBus error: {}", dbusError->name); |
Jiaqing Zhao | b5ca3fd | 2023-03-08 15:14:58 +0800 | [diff] [blame] | 2074 | |
| 2075 | if (std::string_view( |
| 2076 | "xyz.openbmc_project.Common.Error.ResourceNotFound") == |
| 2077 | dbusError->name) |
| 2078 | { |
| 2079 | messages::propertyValueNotInList( |
| 2080 | asyncResp->res, parentInterfaceUri, |
| 2081 | "Links/RelatedInterfaces/0/@odata.id"); |
| 2082 | return; |
| 2083 | } |
| 2084 | if (std::string_view( |
| 2085 | "xyz.openbmc_project.Common.Error.InvalidArgument") == |
| 2086 | dbusError->name) |
| 2087 | { |
| 2088 | messages::resourceAlreadyExists(asyncResp->res, "EthernetInterface", |
| 2089 | "Id", vlanInterface); |
| 2090 | return; |
| 2091 | } |
| 2092 | messages::internalError(asyncResp->res); |
| 2093 | return; |
| 2094 | } |
| 2095 | |
| 2096 | const boost::urls::url vlanInterfaceUri = boost::urls::format( |
| 2097 | "/redfish/v1/Managers/bmc/EthernetInterfaces/{}", vlanInterface); |
| 2098 | asyncResp->res.addHeader("Location", vlanInterfaceUri.buffer()); |
| 2099 | } |
| 2100 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2101 | inline void requestEthernetInterfacesRoutes(App& app) |
| 2102 | { |
| 2103 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2104 | .privileges(redfish::privileges::getEthernetInterfaceCollection) |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 2105 | .methods(boost::beast::http::verb::get)( |
| 2106 | [&app](const crow::Request& req, |
| 2107 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2108 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2109 | { |
| 2110 | return; |
| 2111 | } |
| 2112 | |
| 2113 | asyncResp->res.jsonValue["@odata.type"] = |
| 2114 | "#EthernetInterfaceCollection.EthernetInterfaceCollection"; |
| 2115 | asyncResp->res.jsonValue["@odata.id"] = |
| 2116 | "/redfish/v1/Managers/bmc/EthernetInterfaces"; |
| 2117 | asyncResp->res.jsonValue["Name"] = |
| 2118 | "Ethernet Network Interface Collection"; |
| 2119 | asyncResp->res.jsonValue["Description"] = |
| 2120 | "Collection of EthernetInterfaces for this Manager"; |
| 2121 | |
| 2122 | // Get eth interface list, and call the below callback for JSON |
| 2123 | // preparation |
| 2124 | getEthernetIfaceList( |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 2125 | [asyncResp](const bool& success, |
| 2126 | const std::vector<std::string>& ifaceList) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2127 | if (!success) |
| 2128 | { |
| 2129 | messages::internalError(asyncResp->res); |
| 2130 | return; |
| 2131 | } |
| 2132 | |
| 2133 | nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"]; |
| 2134 | ifaceArray = nlohmann::json::array(); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2135 | for (const std::string& ifaceItem : ifaceList) |
| 2136 | { |
Jiaqing Zhao | 7857cb8 | 2023-03-03 11:23:08 +0800 | [diff] [blame] | 2137 | nlohmann::json::object_t iface; |
| 2138 | iface["@odata.id"] = boost::urls::format( |
| 2139 | "/redfish/v1/Managers/bmc/EthernetInterfaces/{}", |
| 2140 | ifaceItem); |
| 2141 | ifaceArray.push_back(std::move(iface)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2142 | } |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 2143 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2144 | asyncResp->res.jsonValue["Members@odata.count"] = ifaceArray.size(); |
| 2145 | asyncResp->res.jsonValue["@odata.id"] = |
| 2146 | "/redfish/v1/Managers/bmc/EthernetInterfaces"; |
| 2147 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 2148 | }); |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 2149 | |
Jiaqing Zhao | b5ca3fd | 2023-03-08 15:14:58 +0800 | [diff] [blame] | 2150 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/") |
| 2151 | .privileges(redfish::privileges::postEthernetInterfaceCollection) |
| 2152 | .methods(boost::beast::http::verb::post)( |
| 2153 | [&app](const crow::Request& req, |
| 2154 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
| 2155 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2156 | { |
| 2157 | return; |
| 2158 | } |
| 2159 | |
| 2160 | bool vlanEnable = false; |
| 2161 | uint32_t vlanId = 0; |
| 2162 | nlohmann::json::array_t relatedInterfaces; |
| 2163 | |
| 2164 | if (!json_util::readJsonPatch(req, asyncResp->res, "VLAN/VLANEnable", |
| 2165 | vlanEnable, "VLAN/VLANId", vlanId, |
| 2166 | "Links/RelatedInterfaces", |
| 2167 | relatedInterfaces)) |
| 2168 | { |
| 2169 | return; |
| 2170 | } |
| 2171 | |
| 2172 | if (relatedInterfaces.size() != 1) |
| 2173 | { |
| 2174 | messages::arraySizeTooLong(asyncResp->res, |
| 2175 | "Links/RelatedInterfaces", |
| 2176 | relatedInterfaces.size()); |
| 2177 | return; |
| 2178 | } |
| 2179 | |
| 2180 | std::string parentInterfaceUri; |
| 2181 | if (!json_util::readJson(relatedInterfaces[0], asyncResp->res, |
| 2182 | "@odata.id", parentInterfaceUri)) |
| 2183 | { |
| 2184 | messages::propertyMissing(asyncResp->res, |
| 2185 | "Links/RelatedInterfaces/0/@odata.id"); |
| 2186 | return; |
| 2187 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2188 | BMCWEB_LOG_INFO("Parent Interface URI: {}", parentInterfaceUri); |
Jiaqing Zhao | b5ca3fd | 2023-03-08 15:14:58 +0800 | [diff] [blame] | 2189 | |
Ed Tanous | 6fd2955 | 2023-10-04 09:40:14 -0700 | [diff] [blame] | 2190 | boost::system::result<boost::urls::url_view> parsedUri = |
Jiaqing Zhao | b5ca3fd | 2023-03-08 15:14:58 +0800 | [diff] [blame] | 2191 | boost::urls::parse_relative_ref(parentInterfaceUri); |
| 2192 | if (!parsedUri) |
| 2193 | { |
| 2194 | messages::propertyValueFormatError( |
| 2195 | asyncResp->res, parentInterfaceUri, |
| 2196 | "Links/RelatedInterfaces/0/@odata.id"); |
| 2197 | return; |
| 2198 | } |
| 2199 | |
| 2200 | std::string parentInterface; |
| 2201 | if (!crow::utility::readUrlSegments( |
| 2202 | *parsedUri, "redfish", "v1", "Managers", "bmc", |
| 2203 | "EthernetInterfaces", std::ref(parentInterface))) |
| 2204 | { |
| 2205 | messages::propertyValueNotInList( |
| 2206 | asyncResp->res, parentInterfaceUri, |
| 2207 | "Links/RelatedInterfaces/0/@odata.id"); |
| 2208 | return; |
| 2209 | } |
| 2210 | |
| 2211 | if (!vlanEnable) |
| 2212 | { |
| 2213 | // In OpenBMC implementation, VLANEnable cannot be false on |
| 2214 | // create |
| 2215 | messages::propertyValueIncorrect(asyncResp->res, "VLAN/VLANEnable", |
| 2216 | "false"); |
| 2217 | return; |
| 2218 | } |
| 2219 | |
| 2220 | std::string vlanInterface = parentInterface + "_" + |
| 2221 | std::to_string(vlanId); |
| 2222 | crow::connections::systemBus->async_method_call( |
| 2223 | [asyncResp, parentInterfaceUri, |
| 2224 | vlanInterface](const boost::system::error_code& ec, |
| 2225 | const sdbusplus::message_t& m) { |
| 2226 | afterVlanCreate(asyncResp, parentInterfaceUri, vlanInterface, ec, |
| 2227 | m); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 2228 | }, |
Jiaqing Zhao | b5ca3fd | 2023-03-08 15:14:58 +0800 | [diff] [blame] | 2229 | "xyz.openbmc_project.Network", "/xyz/openbmc_project/network", |
| 2230 | "xyz.openbmc_project.Network.VLAN.Create", "VLAN", parentInterface, |
| 2231 | vlanId); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 2232 | }); |
Jiaqing Zhao | b5ca3fd | 2023-03-08 15:14:58 +0800 | [diff] [blame] | 2233 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2234 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2235 | .privileges(redfish::privileges::getEthernetInterface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2236 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2237 | [&app](const crow::Request& req, |
| 2238 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2239 | const std::string& ifaceId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2240 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2241 | { |
| 2242 | return; |
| 2243 | } |
| 2244 | getEthernetIfaceData( |
| 2245 | ifaceId, |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 2246 | [asyncResp, |
| 2247 | ifaceId](const bool& success, const EthernetInterfaceData& ethData, |
| 2248 | const std::vector<IPv4AddressData>& ipv4Data, |
| 2249 | const std::vector<IPv6AddressData>& ipv6Data, |
| 2250 | const std::vector<StaticGatewayData>& ipv6GatewayData) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2251 | if (!success) |
| 2252 | { |
| 2253 | // TODO(Pawel)consider distinguish between non |
| 2254 | // existing object, and other errors |
| 2255 | messages::resourceNotFound(asyncResp->res, "EthernetInterface", |
| 2256 | ifaceId); |
| 2257 | return; |
| 2258 | } |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 2259 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2260 | asyncResp->res.jsonValue["@odata.type"] = |
Jiaqing Zhao | 93bbc95 | 2023-02-23 14:11:20 +0800 | [diff] [blame] | 2261 | "#EthernetInterface.v1_9_0.EthernetInterface"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2262 | asyncResp->res.jsonValue["Name"] = "Manager Ethernet Interface"; |
| 2263 | asyncResp->res.jsonValue["Description"] = |
| 2264 | "Management Network Interface"; |
Ratan Gupta | f476acb | 2019-03-02 16:46:57 +0530 | [diff] [blame] | 2265 | |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 2266 | parseInterfaceData(asyncResp, ifaceId, ethData, ipv4Data, ipv6Data, |
| 2267 | ipv6GatewayData); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2268 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 2269 | }); |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 2270 | |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2271 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2272 | .privileges(redfish::privileges::patchEthernetInterface) |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2273 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2274 | [&app](const crow::Request& req, |
| 2275 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2276 | const std::string& ifaceId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 2277 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2278 | { |
| 2279 | return; |
| 2280 | } |
| 2281 | std::optional<std::string> hostname; |
| 2282 | std::optional<std::string> fqdn; |
| 2283 | std::optional<std::string> macAddress; |
| 2284 | std::optional<std::string> ipv6DefaultGateway; |
Ed Tanous | ddd70dc | 2023-03-01 16:00:27 -0800 | [diff] [blame] | 2285 | std::optional<nlohmann::json::array_t> ipv4StaticAddresses; |
| 2286 | std::optional<nlohmann::json::array_t> ipv6StaticAddresses; |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 2287 | std::optional<nlohmann::json::array_t> ipv6StaticDefaultGateways; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2288 | std::optional<std::vector<std::string>> staticNameServers; |
| 2289 | std::optional<nlohmann::json> dhcpv4; |
| 2290 | std::optional<nlohmann::json> dhcpv6; |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 2291 | std::optional<bool> ipv6AutoConfigEnabled; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2292 | std::optional<bool> interfaceEnabled; |
| 2293 | std::optional<size_t> mtuSize; |
| 2294 | DHCPParameters v4dhcpParms; |
| 2295 | DHCPParameters v6dhcpParms; |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 2296 | // clang-format off |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2297 | if (!json_util::readJsonPatch( |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 2298 | req, asyncResp->res, |
| 2299 | "DHCPv4", dhcpv4, |
| 2300 | "DHCPv6", dhcpv6, |
| 2301 | "FQDN", fqdn, |
| 2302 | "HostName", hostname, |
| 2303 | "IPv4StaticAddresses", ipv4StaticAddresses, |
| 2304 | "IPv6DefaultGateway", ipv6DefaultGateway, |
| 2305 | "IPv6StaticAddresses", ipv6StaticAddresses, |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 2306 | "IPv6StaticDefaultGateways", ipv6StaticDefaultGateways, |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 2307 | "InterfaceEnabled", interfaceEnabled, |
| 2308 | "MACAddress", macAddress, |
| 2309 | "MTUSize", mtuSize, |
| 2310 | "StatelessAddressAutoConfig/IPv6AutoConfigEnabled", ipv6AutoConfigEnabled, |
| 2311 | "StaticNameServers", staticNameServers |
| 2312 | ) |
| 2313 | ) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2314 | { |
| 2315 | return; |
| 2316 | } |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 2317 | //clang-format on |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2318 | if (dhcpv4) |
| 2319 | { |
| 2320 | if (!json_util::readJson(*dhcpv4, asyncResp->res, "DHCPEnabled", |
| 2321 | v4dhcpParms.dhcpv4Enabled, "UseDNSServers", |
| 2322 | v4dhcpParms.useDnsServers, "UseNTPServers", |
| 2323 | v4dhcpParms.useNtpServers, "UseDomainName", |
| 2324 | v4dhcpParms.useDomainName)) |
| 2325 | { |
| 2326 | return; |
| 2327 | } |
| 2328 | } |
Johnathan Mantey | 0178482 | 2019-06-18 12:44:21 -0700 | [diff] [blame] | 2329 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2330 | if (dhcpv6) |
| 2331 | { |
| 2332 | if (!json_util::readJson(*dhcpv6, asyncResp->res, "OperatingMode", |
| 2333 | v6dhcpParms.dhcpv6OperatingMode, |
| 2334 | "UseDNSServers", v6dhcpParms.useDnsServers, |
| 2335 | "UseNTPServers", v6dhcpParms.useNtpServers, |
| 2336 | "UseDomainName", |
| 2337 | v6dhcpParms.useDomainName)) |
| 2338 | { |
| 2339 | return; |
| 2340 | } |
| 2341 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 2342 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2343 | // Get single eth interface data, and call the below callback |
| 2344 | // for JSON preparation |
| 2345 | getEthernetIfaceData( |
| 2346 | ifaceId, |
| 2347 | [asyncResp, ifaceId, hostname = std::move(hostname), |
| 2348 | fqdn = std::move(fqdn), macAddress = std::move(macAddress), |
| 2349 | ipv4StaticAddresses = std::move(ipv4StaticAddresses), |
| 2350 | ipv6DefaultGateway = std::move(ipv6DefaultGateway), |
| 2351 | ipv6StaticAddresses = std::move(ipv6StaticAddresses), |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 2352 | ipv6StaticDefaultGateway = std::move(ipv6StaticDefaultGateways), |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2353 | staticNameServers = std::move(staticNameServers), |
Ed Tanous | bc20089 | 2022-06-30 17:49:12 -0700 | [diff] [blame] | 2354 | dhcpv4 = std::move(dhcpv4), dhcpv6 = std::move(dhcpv6), mtuSize, |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 2355 | ipv6AutoConfigEnabled, v4dhcpParms = std::move(v4dhcpParms), |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2356 | v6dhcpParms = std::move(v6dhcpParms), interfaceEnabled]( |
| 2357 | const bool& success, const EthernetInterfaceData& ethData, |
Ed Tanous | 7717953 | 2023-02-28 10:45:28 -0800 | [diff] [blame] | 2358 | const std::vector<IPv4AddressData>& ipv4Data, |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 2359 | const std::vector<IPv6AddressData>& ipv6Data, |
| 2360 | const std::vector<StaticGatewayData>& ipv6GatewayData) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2361 | if (!success) |
| 2362 | { |
| 2363 | // ... otherwise return error |
| 2364 | // TODO(Pawel)consider distinguish between non |
| 2365 | // existing object, and other errors |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 2366 | messages::resourceNotFound(asyncResp->res, "EthernetInterface", |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2367 | ifaceId); |
| 2368 | return; |
| 2369 | } |
Ravi Teja | e48c0fc | 2019-04-16 08:37:20 -0500 | [diff] [blame] | 2370 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2371 | if (dhcpv4 || dhcpv6) |
| 2372 | { |
| 2373 | handleDHCPPatch(ifaceId, ethData, v4dhcpParms, v6dhcpParms, |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2374 | asyncResp); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2375 | } |
Tejas Patil | 35fb531 | 2021-09-20 15:35:20 +0530 | [diff] [blame] | 2376 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2377 | if (hostname) |
| 2378 | { |
| 2379 | handleHostnamePatch(*hostname, asyncResp); |
| 2380 | } |
| 2381 | |
Ravi Teja | b10d8db | 2022-05-24 09:04:12 -0500 | [diff] [blame] | 2382 | if (ipv6AutoConfigEnabled) |
| 2383 | { |
| 2384 | handleSLAACAutoConfigPatch(ifaceId, *ipv6AutoConfigEnabled, |
| 2385 | asyncResp); |
| 2386 | } |
| 2387 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2388 | if (fqdn) |
| 2389 | { |
| 2390 | handleFqdnPatch(ifaceId, *fqdn, asyncResp); |
| 2391 | } |
| 2392 | |
| 2393 | if (macAddress) |
| 2394 | { |
| 2395 | handleMACAddressPatch(ifaceId, *macAddress, asyncResp); |
| 2396 | } |
| 2397 | |
| 2398 | if (ipv4StaticAddresses) |
| 2399 | { |
| 2400 | // TODO(ed) for some reason the capture of |
| 2401 | // ipv4Addresses above is returning a const value, |
| 2402 | // not a non-const value. This doesn't really work |
| 2403 | // for us, as we need to be able to efficiently move |
| 2404 | // out the intermedia nlohmann::json objects. This |
| 2405 | // makes a copy of the structure, and operates on |
| 2406 | // that, but could be done more efficiently |
Ed Tanous | ddd70dc | 2023-03-01 16:00:27 -0800 | [diff] [blame] | 2407 | nlohmann::json::array_t ipv4Static = *ipv4StaticAddresses; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2408 | handleIPv4StaticPatch(ifaceId, ipv4Static, ipv4Data, asyncResp); |
| 2409 | } |
| 2410 | |
| 2411 | if (staticNameServers) |
| 2412 | { |
| 2413 | handleStaticNameServersPatch(ifaceId, *staticNameServers, |
| 2414 | asyncResp); |
| 2415 | } |
| 2416 | |
| 2417 | if (ipv6DefaultGateway) |
| 2418 | { |
| 2419 | messages::propertyNotWritable(asyncResp->res, |
| 2420 | "IPv6DefaultGateway"); |
| 2421 | } |
| 2422 | |
| 2423 | if (ipv6StaticAddresses) |
| 2424 | { |
Ed Tanous | ddd70dc | 2023-03-01 16:00:27 -0800 | [diff] [blame] | 2425 | handleIPv6StaticAddressesPatch(ifaceId, *ipv6StaticAddresses, |
| 2426 | ipv6Data, asyncResp); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
Sunitha Harish | ce73d5c | 2023-04-07 06:46:49 -0500 | [diff] [blame] | 2429 | if (ipv6StaticDefaultGateway) |
| 2430 | { |
| 2431 | handleIPv6DefaultGateway(ifaceId, *ipv6StaticDefaultGateway, |
| 2432 | ipv6GatewayData, asyncResp); |
| 2433 | } |
| 2434 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2435 | if (interfaceEnabled) |
| 2436 | { |
| 2437 | setEthernetInterfaceBoolProperty(ifaceId, "NICEnabled", |
| 2438 | *interfaceEnabled, asyncResp); |
| 2439 | } |
| 2440 | |
| 2441 | if (mtuSize) |
| 2442 | { |
| 2443 | handleMTUSizePatch(ifaceId, *mtuSize, asyncResp); |
| 2444 | } |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2445 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2446 | }); |
Jiaqing Zhao | e7caf25 | 2023-03-09 11:14:44 +0800 | [diff] [blame] | 2447 | |
| 2448 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/EthernetInterfaces/<str>/") |
| 2449 | .privileges(redfish::privileges::deleteEthernetInterface) |
| 2450 | .methods(boost::beast::http::verb::delete_)( |
| 2451 | [&app](const crow::Request& req, |
| 2452 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2453 | const std::string& ifaceId) { |
| 2454 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2455 | { |
| 2456 | return; |
| 2457 | } |
| 2458 | |
| 2459 | crow::connections::systemBus->async_method_call( |
| 2460 | [asyncResp, ifaceId](const boost::system::error_code& ec, |
| 2461 | const sdbusplus::message_t& m) { |
| 2462 | afterDelete(asyncResp, ifaceId, ec, m); |
| 2463 | }, |
| 2464 | "xyz.openbmc_project.Network", |
| 2465 | std::string("/xyz/openbmc_project/network/") + ifaceId, |
| 2466 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 2467 | }); |
Ed Tanous | bf648f7 | 2021-06-03 15:00:14 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2470 | } // namespace redfish |