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