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