Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 1 | #include <chrono> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <stdint.h> |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 5 | #include <arpa/inet.h> |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 6 | #include <string> |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 7 | #include <experimental/filesystem> |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 8 | |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 9 | #include "host-ipmid/ipmid-api.h" |
Patrick Williams | 53a360e | 2016-08-12 22:01:02 -0500 | [diff] [blame] | 10 | #include "ipmid.hpp" |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 11 | #include "timer.hpp" |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 12 | #include "transporthandler.hpp" |
| 13 | #include "utils.hpp" |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 14 | #include "net.hpp" |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 15 | |
| 16 | #include <phosphor-logging/log.hpp> |
| 17 | #include <phosphor-logging/elog-errors.hpp> |
| 18 | #include "xyz/openbmc_project/Common/error.hpp" |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 19 | |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 20 | #define SYSTEMD_NETWORKD_DBUS 1 |
| 21 | |
| 22 | #ifdef SYSTEMD_NETWORKD_DBUS |
| 23 | #include <systemd/sd-bus.h> |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 24 | #include <mapper.h> |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 25 | #endif |
| 26 | |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 27 | extern std::unique_ptr<phosphor::ipmi::Timer> networkTimer; |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 28 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 29 | const int SIZE_MAC = 18; //xx:xx:xx:xx:xx:xx |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 30 | constexpr auto ipv4Protocol = "xyz.openbmc_project.Network.IP.Protocol.IPv4"; |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 31 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 32 | std::map<int, std::unique_ptr<struct ChannelConfig_t>> channelConfig; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 33 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 34 | using namespace phosphor::logging; |
| 35 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 36 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 37 | namespace fs = std::experimental::filesystem; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 38 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 39 | void register_netfn_transport_functions() __attribute__((constructor)); |
| 40 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 41 | struct ChannelConfig_t* getChannelConfig(int channel) |
| 42 | { |
| 43 | auto item = channelConfig.find(channel); |
| 44 | if (item == channelConfig.end()) |
| 45 | { |
| 46 | channelConfig[channel] = std::make_unique<struct ChannelConfig_t>(); |
| 47 | } |
| 48 | |
| 49 | return channelConfig[channel].get(); |
| 50 | } |
| 51 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 52 | // Helper Function to get IP Address/NetMask/Gateway/MAC Address from Network Manager or |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 53 | // Cache based on Set-In-Progress State |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 54 | ipmi_ret_t getNetworkData(uint8_t lan_param, uint8_t* data, int channel) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 55 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 56 | ipmi_ret_t rc = IPMI_CC_OK; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 57 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 58 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 59 | auto ethdevice = ipmi::network::ChanneltoEthernet(channel); |
| 60 | // if ethdevice is an empty string they weren't expecting this channel. |
| 61 | if (ethdevice.empty()) |
| 62 | { |
| 63 | // TODO: return error from getNetworkData() |
| 64 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 65 | } |
| 66 | auto ethIP = ethdevice + "/" + ipmi::network::IP_TYPE; |
| 67 | auto channelConf = getChannelConfig(channel); |
| 68 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 69 | try |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 70 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 71 | switch (lan_param) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 72 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 73 | case LAN_PARM_IP: |
| 74 | { |
| 75 | std::string ipaddress; |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 76 | if (channelConf->lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 77 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 78 | try |
| 79 | { |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 80 | auto ipObjectInfo = ipmi::getIPObject( |
| 81 | bus, |
| 82 | ipmi::network::IP_INTERFACE, |
| 83 | ipmi::network::ROOT, |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 84 | ethIP); |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 85 | |
| 86 | auto properties = ipmi::getAllDbusProperties( |
| 87 | bus, |
| 88 | ipObjectInfo.second, |
| 89 | ipObjectInfo.first, |
| 90 | ipmi::network::IP_INTERFACE); |
| 91 | |
| 92 | ipaddress = properties["Address"].get<std::string>(); |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 93 | } |
| 94 | // ignore the exception, as it is a valid condtion that |
| 95 | // system is not confiured with any ip. |
| 96 | catch (InternalFailure& e) |
| 97 | { |
| 98 | // nothing to do. |
| 99 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 100 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 101 | else if (channelConf->lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 102 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 103 | ipaddress = channelConf->ipaddr; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | inet_pton(AF_INET, ipaddress.c_str(), |
| 107 | reinterpret_cast<void*>(data)); |
| 108 | } |
| 109 | break; |
| 110 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 111 | case LAN_PARM_IPSRC: |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 112 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 113 | std::string networkInterfacePath; |
| 114 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 115 | if (channelConf->lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 116 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 117 | try |
| 118 | { |
| 119 | ipmi::ObjectTree ancestorMap; |
| 120 | // if the system is having ip object,then |
| 121 | // get the IP object. |
| 122 | auto ipObject = ipmi::getDbusObject( |
| 123 | bus, |
| 124 | ipmi::network::IP_INTERFACE, |
| 125 | ipmi::network::ROOT, |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 126 | ethIP); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 127 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 128 | // Get the parent interface of the IP object. |
| 129 | try |
| 130 | { |
| 131 | ipmi::InterfaceList interfaces; |
| 132 | interfaces.emplace_back( |
| 133 | ipmi::network::ETHERNET_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 134 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 135 | ancestorMap = ipmi::getAllAncestors( |
| 136 | bus, |
| 137 | ipObject.first, |
| 138 | std::move(interfaces)); |
| 139 | } |
| 140 | catch (InternalFailure& e) |
| 141 | { |
| 142 | // if unable to get the parent interface |
| 143 | // then commit the error and return. |
| 144 | log<level::ERR>("Unable to get the parent interface", |
| 145 | entry("PATH=%s", ipObject.first.c_str()), |
| 146 | entry("INTERFACE=%s", |
| 147 | ipmi::network::ETHERNET_INTERFACE)); |
| 148 | break; |
| 149 | |
| 150 | } |
| 151 | // for an ip object there would be single parent |
| 152 | // interface. |
| 153 | networkInterfacePath = ancestorMap.begin()->first; |
| 154 | } |
| 155 | catch (InternalFailure& e) |
| 156 | { |
| 157 | // if there is no ip configured on the system,then |
| 158 | // get the network interface object. |
| 159 | auto networkInterfaceObject = ipmi::getDbusObject( |
| 160 | bus, |
| 161 | ipmi::network::ETHERNET_INTERFACE, |
| 162 | ipmi::network::ROOT, |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 163 | ethdevice); |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 164 | |
| 165 | networkInterfacePath = networkInterfaceObject.first; |
| 166 | } |
| 167 | |
| 168 | auto variant = ipmi::getDbusProperty( |
| 169 | bus, |
| 170 | ipmi::network::SERVICE, |
| 171 | networkInterfacePath, |
| 172 | ipmi::network::ETHERNET_INTERFACE, |
| 173 | "DHCPEnabled"); |
| 174 | |
| 175 | auto dhcpEnabled = variant.get<bool>(); |
| 176 | // As per IPMI spec 2=>DHCP, 1=STATIC |
| 177 | auto ipsrc = dhcpEnabled ? ipmi::network::IPOrigin::DHCP : |
| 178 | ipmi::network::IPOrigin::STATIC; |
| 179 | |
| 180 | memcpy(data, &ipsrc, ipmi::network::IPSRC_SIZE_BYTE); |
| 181 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 182 | else if (channelConf->lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 183 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 184 | memcpy(data, &(channelConf->ipsrc), |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 185 | ipmi::network::IPSRC_SIZE_BYTE); |
| 186 | } |
| 187 | } |
| 188 | break; |
| 189 | |
| 190 | case LAN_PARM_SUBNET: |
| 191 | { |
| 192 | unsigned long mask {}; |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 193 | if (channelConf->lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 194 | { |
| 195 | try |
| 196 | { |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 197 | auto ipObjectInfo = ipmi::getIPObject( |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 198 | bus, |
| 199 | ipmi::network::IP_INTERFACE, |
| 200 | ipmi::network::ROOT, |
| 201 | ipmi::network::IP_TYPE); |
| 202 | |
| 203 | auto properties = ipmi::getAllDbusProperties( |
| 204 | bus, |
| 205 | ipObjectInfo.second, |
| 206 | ipObjectInfo.first, |
| 207 | ipmi::network::IP_INTERFACE); |
| 208 | |
| 209 | auto prefix = properties["PrefixLength"].get<uint8_t>(); |
| 210 | mask = ipmi::network::MASK_32_BIT; |
| 211 | mask = htonl(mask << (ipmi::network::BITS_32 - prefix)); |
| 212 | } |
| 213 | // ignore the exception, as it is a valid condtion that |
| 214 | // system is not confiured with any ip. |
| 215 | catch (InternalFailure& e) |
| 216 | { |
| 217 | // nothing to do |
| 218 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 219 | memcpy(data, &mask, ipmi::network::IPV4_ADDRESS_SIZE_BYTE); |
| 220 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 221 | else if (channelConf->lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 222 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 223 | inet_pton(AF_INET, channelConf->netmask.c_str(), |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 224 | reinterpret_cast<void*>(data)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | } |
| 228 | break; |
| 229 | |
| 230 | case LAN_PARM_GATEWAY: |
| 231 | { |
| 232 | std::string gateway; |
| 233 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 234 | if (channelConf->lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 235 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 236 | try |
| 237 | { |
| 238 | auto systemObject = ipmi::getDbusObject( |
| 239 | bus, |
| 240 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 241 | ipmi::network::ROOT); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 242 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 243 | auto systemProperties = ipmi::getAllDbusProperties( |
| 244 | bus, |
| 245 | systemObject.second, |
| 246 | systemObject.first, |
| 247 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 248 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 249 | gateway = systemProperties["DefaultGateway"].get< |
| 250 | std::string>(); |
| 251 | } |
| 252 | // ignore the exception, as it is a valid condtion that |
| 253 | // system is not confiured with any ip. |
| 254 | catch (InternalFailure& e) |
| 255 | { |
| 256 | // nothing to do |
| 257 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 258 | |
| 259 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 260 | else if (channelConf->lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 261 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 262 | gateway = channelConf->gateway; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | inet_pton(AF_INET, gateway.c_str(), |
| 266 | reinterpret_cast<void*>(data)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 267 | } |
| 268 | break; |
| 269 | |
| 270 | case LAN_PARM_MAC: |
| 271 | { |
| 272 | std::string macAddress; |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 273 | if (channelConf->lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 274 | { |
| 275 | auto macObjectInfo = ipmi::getDbusObject( |
| 276 | bus, |
| 277 | ipmi::network::MAC_INTERFACE, |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 278 | ipmi::network::ROOT, |
| 279 | ethdevice); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 280 | |
| 281 | auto variant = ipmi::getDbusProperty( |
| 282 | bus, |
| 283 | macObjectInfo.second, |
| 284 | macObjectInfo.first, |
| 285 | ipmi::network::MAC_INTERFACE, |
| 286 | "MACAddress"); |
| 287 | |
| 288 | macAddress = variant.get<std::string>(); |
| 289 | |
| 290 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 291 | else if (channelConf->lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 292 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 293 | macAddress = channelConf->macAddress; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT, |
| 297 | (data), |
| 298 | (data + 1), |
| 299 | (data + 2), |
| 300 | (data + 3), |
| 301 | (data + 4), |
| 302 | (data + 5)); |
| 303 | } |
| 304 | break; |
| 305 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 306 | case LAN_PARM_VLAN: |
| 307 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 308 | uint16_t vlanID {}; |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 309 | if (channelConf->lan_set_in_progress == SET_COMPLETE) |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 310 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 311 | try |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 312 | { |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 313 | auto ipObjectInfo = ipmi::getIPObject( |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 314 | bus, |
| 315 | ipmi::network::IP_INTERFACE, |
| 316 | ipmi::network::ROOT, |
| 317 | ipmi::network::IP_TYPE); |
| 318 | |
| 319 | vlanID = static_cast<uint16_t>( |
| 320 | ipmi::network::getVLAN(ipObjectInfo.first)); |
| 321 | |
| 322 | vlanID = htole16(vlanID); |
| 323 | |
| 324 | if (vlanID) |
| 325 | { |
| 326 | //Enable the 16th bit |
| 327 | vlanID |= htole16(ipmi::network::VLAN_ENABLE_MASK); |
| 328 | } |
| 329 | } |
| 330 | // ignore the exception, as it is a valid condtion that |
| 331 | // system is not confiured with any ip. |
| 332 | catch (InternalFailure& e) |
| 333 | { |
| 334 | // nothing to do |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | memcpy(data, &vlanID, ipmi::network::VLAN_SIZE_BYTE); |
| 338 | } |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 339 | else if (channelConf->lan_set_in_progress == SET_IN_PROGRESS) |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 340 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 341 | memcpy(data, &(channelConf->vlanID), |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 342 | ipmi::network::VLAN_SIZE_BYTE); |
| 343 | } |
| 344 | } |
| 345 | break; |
| 346 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 347 | default: |
| 348 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 349 | } |
| 350 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 351 | catch (InternalFailure& e) |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 352 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 353 | commit<InternalFailure>(); |
| 354 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 355 | return rc; |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 356 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 357 | return rc; |
| 358 | } |
| 359 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 360 | ipmi_ret_t ipmi_transport_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 361 | ipmi_request_t request, ipmi_response_t response, |
| 362 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 363 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 364 | // Status code. |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 365 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 366 | *data_len = 0; |
| 367 | return rc; |
| 368 | } |
| 369 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 370 | struct set_lan_t |
| 371 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 372 | uint8_t channel; |
| 373 | uint8_t parameter; |
| 374 | uint8_t data[8]; // Per IPMI spec, not expecting more than this size |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 375 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 376 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 377 | ipmi_ret_t ipmi_transport_set_lan(ipmi_netfn_t netfn, |
| 378 | ipmi_cmd_t cmd, |
| 379 | ipmi_request_t request, |
| 380 | ipmi_response_t response, |
| 381 | ipmi_data_len_t data_len, |
| 382 | ipmi_context_t context) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 383 | { |
| 384 | ipmi_ret_t rc = IPMI_CC_OK; |
| 385 | *data_len = 0; |
Nan Li | 3d0df91 | 2016-10-18 19:51:41 +0800 | [diff] [blame] | 386 | |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 387 | using namespace std::chrono_literals; |
| 388 | |
| 389 | // time to wait before applying the network changes. |
| 390 | constexpr auto networkTimeout = 10000000us; // 10 sec |
| 391 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 392 | char ipaddr[INET_ADDRSTRLEN]; |
| 393 | char netmask[INET_ADDRSTRLEN]; |
| 394 | char gateway[INET_ADDRSTRLEN]; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 395 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 396 | auto reqptr = reinterpret_cast<const set_lan_t*>(request); |
| 397 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 398 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 399 | // channel number is the lower nibble |
| 400 | int channel = reqptr->channel & CHANNEL_MASK; |
| 401 | auto ethdevice = ipmi::network::ChanneltoEthernet(channel); |
| 402 | if (ethdevice.empty()) |
| 403 | { |
| 404 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 405 | } |
| 406 | auto channelConf = getChannelConfig(channel); |
| 407 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 408 | switch (reqptr->parameter) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 409 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 410 | case LAN_PARM_IP: |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 411 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 412 | snprintf(ipaddr, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 413 | reqptr->data[0], reqptr->data[1], |
| 414 | reqptr->data[2], reqptr->data[3]); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 415 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 416 | channelConf->ipaddr.assign(ipaddr); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 417 | } |
| 418 | break; |
| 419 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 420 | case LAN_PARM_IPSRC: |
| 421 | { |
| 422 | uint8_t ipsrc{}; |
| 423 | memcpy(&ipsrc, reqptr->data, ipmi::network::IPSRC_SIZE_BYTE); |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 424 | channelConf->ipsrc = static_cast<ipmi::network::IPOrigin>(ipsrc); |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 425 | } |
| 426 | break; |
| 427 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 428 | case LAN_PARM_MAC: |
| 429 | { |
| 430 | char mac[SIZE_MAC]; |
| 431 | |
| 432 | snprintf(mac, SIZE_MAC, ipmi::network::MAC_ADDRESS_FORMAT, |
| 433 | reqptr->data[0], |
| 434 | reqptr->data[1], |
| 435 | reqptr->data[2], |
| 436 | reqptr->data[3], |
| 437 | reqptr->data[4], |
| 438 | reqptr->data[5]); |
| 439 | |
| 440 | auto macObjectInfo = ipmi::getDbusObject( |
| 441 | bus, |
| 442 | ipmi::network::MAC_INTERFACE, |
| 443 | ipmi::network::ROOT, |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 444 | ethdevice); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 445 | |
| 446 | ipmi::setDbusProperty(bus, |
| 447 | macObjectInfo.second, |
| 448 | macObjectInfo.first, |
| 449 | ipmi::network::MAC_INTERFACE, |
| 450 | "MACAddress", |
| 451 | std::string(mac)); |
| 452 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 453 | channelConf->macAddress = mac; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 454 | } |
| 455 | break; |
| 456 | |
| 457 | case LAN_PARM_SUBNET: |
| 458 | { |
| 459 | snprintf(netmask, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 460 | reqptr->data[0], reqptr->data[1], |
| 461 | reqptr->data[2], reqptr->data[3]); |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 462 | channelConf->netmask.assign(netmask); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 463 | } |
| 464 | break; |
| 465 | |
| 466 | case LAN_PARM_GATEWAY: |
| 467 | { |
| 468 | snprintf(gateway, INET_ADDRSTRLEN, ipmi::network::IP_ADDRESS_FORMAT, |
| 469 | reqptr->data[0], reqptr->data[1], |
| 470 | reqptr->data[2], reqptr->data[3]); |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 471 | channelConf->gateway.assign(gateway); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 472 | } |
| 473 | break; |
| 474 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 475 | case LAN_PARM_VLAN: |
| 476 | { |
| 477 | uint16_t vlan {}; |
| 478 | memcpy(&vlan, reqptr->data, ipmi::network::VLAN_SIZE_BYTE); |
| 479 | // We are not storing the enable bit |
| 480 | // We assume that ipmitool always send enable |
| 481 | // bit as 1. |
| 482 | vlan = le16toh(vlan); |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 483 | channelConf->vlanID = vlan; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 484 | } |
| 485 | break; |
| 486 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 487 | case LAN_PARM_INPROGRESS: |
| 488 | { |
| 489 | if (reqptr->data[0] == SET_COMPLETE) |
| 490 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 491 | channelConf->lan_set_in_progress = SET_COMPLETE; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 492 | |
| 493 | log<level::INFO>("Network data from Cache", |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 494 | entry("PREFIX=%s", channelConf->netmask.c_str()), |
| 495 | entry("ADDRESS=%s", channelConf->ipaddr.c_str()), |
| 496 | entry("GATEWAY=%s", channelConf->gateway.c_str()), |
| 497 | entry("VLAN=%d", channelConf->vlanID)); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 498 | |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 499 | if (!networkTimer) |
| 500 | { |
| 501 | log<level::ERR>("Network timer is not instantiated"); |
| 502 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 503 | } |
| 504 | |
| 505 | // start/restart the timer |
| 506 | networkTimer->startTimer(networkTimeout); |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 507 | } |
| 508 | else if (reqptr->data[0] == SET_IN_PROGRESS) // Set In Progress |
| 509 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 510 | channelConf->lan_set_in_progress = SET_IN_PROGRESS; |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 511 | channelConf->flush = true; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 512 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 513 | } |
| 514 | break; |
| 515 | |
| 516 | default: |
| 517 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 518 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
| 519 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 520 | } |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 521 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 522 | return rc; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 525 | struct get_lan_t |
| 526 | { |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 527 | uint8_t rev_channel; |
| 528 | uint8_t parameter; |
| 529 | uint8_t parameter_set; |
| 530 | uint8_t parameter_block; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 531 | } __attribute__((packed)); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 532 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 533 | ipmi_ret_t ipmi_transport_get_lan(ipmi_netfn_t netfn, |
| 534 | ipmi_cmd_t cmd, |
| 535 | ipmi_request_t request, |
| 536 | ipmi_response_t response, |
| 537 | ipmi_data_len_t data_len, |
| 538 | ipmi_context_t context) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 539 | { |
| 540 | ipmi_ret_t rc = IPMI_CC_OK; |
| 541 | *data_len = 0; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 542 | const uint8_t current_revision = 0x11; // Current rev per IPMI Spec 2.0 |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 543 | |
| 544 | get_lan_t *reqptr = (get_lan_t*) request; |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 545 | // channel number is the lower nibble |
| 546 | int channel = reqptr->rev_channel & CHANNEL_MASK; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 547 | |
| 548 | if (reqptr->rev_channel & 0x80) // Revision is bit 7 |
| 549 | { |
| 550 | // Only current revision was requested |
| 551 | *data_len = sizeof(current_revision); |
| 552 | memcpy(response, ¤t_revision, *data_len); |
| 553 | return IPMI_CC_OK; |
| 554 | } |
| 555 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 556 | auto ethdevice = ipmi::network::ChanneltoEthernet(channel); |
| 557 | if (ethdevice.empty()) |
| 558 | { |
| 559 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 560 | } |
| 561 | auto channelConf = getChannelConfig(channel); |
| 562 | |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 563 | if (reqptr->parameter == LAN_PARM_INPROGRESS) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 564 | { |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 565 | uint8_t buf[] = {current_revision, channelConf->lan_set_in_progress}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 566 | *data_len = sizeof(buf); |
| 567 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 568 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 569 | else if (reqptr->parameter == LAN_PARM_AUTHSUPPORT) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 570 | { |
| 571 | uint8_t buf[] = {current_revision,0x04}; |
| 572 | *data_len = sizeof(buf); |
| 573 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 574 | } |
Adriana Kobylak | e08fbc6 | 2016-02-09 16:17:23 -0600 | [diff] [blame] | 575 | else if (reqptr->parameter == LAN_PARM_AUTHENABLES) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 576 | { |
| 577 | uint8_t buf[] = {current_revision,0x04,0x04,0x04,0x04,0x04}; |
| 578 | *data_len = sizeof(buf); |
| 579 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 580 | } |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 581 | else if ((reqptr->parameter == LAN_PARM_IP) || |
| 582 | (reqptr->parameter == LAN_PARM_SUBNET) || |
| 583 | (reqptr->parameter == LAN_PARM_GATEWAY) || |
| 584 | (reqptr->parameter == LAN_PARM_MAC)) |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 585 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 586 | uint8_t buf[ipmi::network::MAC_ADDRESS_SIZE_BYTE + 1] = {}; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 587 | |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 588 | *data_len = sizeof(current_revision); |
| 589 | memcpy(buf, ¤t_revision, *data_len); |
| 590 | |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 591 | if (getNetworkData(reqptr->parameter, &buf[1], channel) == IPMI_CC_OK) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 592 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 593 | if (reqptr->parameter == LAN_PARM_MAC) |
| 594 | { |
| 595 | *data_len = sizeof(buf); |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | *data_len = ipmi::network::IPV4_ADDRESS_SIZE_BYTE + 1; |
| 600 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 601 | memcpy(response, &buf, *data_len); |
Adriana Kobylak | 342df10 | 2016-02-10 13:48:16 -0600 | [diff] [blame] | 602 | } |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 603 | else |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 604 | { |
tomjose | 26e1773 | 2016-03-03 08:52:51 -0600 | [diff] [blame] | 605 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
Hariharasubramanian R | 8395191 | 2016-01-20 07:06:36 -0600 | [diff] [blame] | 606 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 607 | } |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 608 | else if (reqptr->parameter == LAN_PARM_VLAN) |
| 609 | { |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 610 | uint8_t buf[ipmi::network::VLAN_SIZE_BYTE + 1] = {}; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 611 | |
| 612 | *data_len = sizeof(current_revision); |
| 613 | memcpy(buf, ¤t_revision, *data_len); |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 614 | if (getNetworkData(reqptr->parameter, &buf[1], channel) == IPMI_CC_OK) |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 615 | { |
| 616 | *data_len = sizeof(buf); |
| 617 | memcpy(response, &buf, *data_len); |
| 618 | } |
| 619 | } |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 620 | else if (reqptr->parameter == LAN_PARM_IPSRC) |
| 621 | { |
| 622 | uint8_t buff[ipmi::network::IPSRC_SIZE_BYTE + 1] = {}; |
| 623 | *data_len = sizeof(current_revision); |
| 624 | memcpy(buff, ¤t_revision, *data_len); |
Patrick Venture | c7c1c3c | 2017-11-15 14:29:18 -0800 | [diff] [blame] | 625 | if (getNetworkData(reqptr->parameter, &buff[1], channel) == IPMI_CC_OK) |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 626 | { |
| 627 | *data_len = sizeof(buff); |
| 628 | memcpy(response, &buff, *data_len); |
| 629 | } |
| 630 | } |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 631 | else |
| 632 | { |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 633 | log<level::ERR>("Unsupported parameter", |
| 634 | entry("PARAMETER=0x%x", reqptr->parameter)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 635 | rc = IPMI_CC_PARM_NOT_SUPPORTED; |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | return rc; |
| 639 | } |
| 640 | |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 641 | void applyChanges(int channel) |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 642 | { |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 643 | std::string ipaddress; |
| 644 | std::string gateway; |
| 645 | uint8_t prefix {}; |
| 646 | uint32_t vlanID {}; |
| 647 | std::string networkInterfacePath; |
| 648 | ipmi::DbusObjectInfo ipObject; |
| 649 | ipmi::DbusObjectInfo systemObject; |
| 650 | |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 651 | auto ethdevice = ipmi::network::ChanneltoEthernet(channel); |
| 652 | if (ethdevice.empty()) |
| 653 | { |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 654 | log<level::ERR>("Unable to get the interface name", |
| 655 | entry("CHANNEL=%d", channel)); |
| 656 | return; |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 657 | } |
| 658 | auto ethIp = ethdevice + "/" + ipmi::network::IP_TYPE; |
| 659 | auto channelConf = getChannelConfig(channel); |
| 660 | |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 661 | try |
| 662 | { |
| 663 | sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection()); |
| 664 | |
| 665 | log<level::INFO>("Network data from Cache", |
| 666 | entry("PREFIX=%s", channelConf->netmask.c_str()), |
| 667 | entry("ADDRESS=%s", channelConf->ipaddr.c_str()), |
| 668 | entry("GATEWAY=%s", channelConf->gateway.c_str()), |
| 669 | entry("VLAN=%d", channelConf->vlanID), |
| 670 | entry("IPSRC=%d", channelConf->ipsrc)); |
| 671 | if (channelConf->vlanID != ipmi::network::VLAN_ID_MASK) |
| 672 | { |
| 673 | //get the first twelve bits which is vlan id |
| 674 | //not interested in rest of the bits. |
| 675 | channelConf->vlanID = le32toh(channelConf->vlanID); |
| 676 | vlanID = channelConf->vlanID & ipmi::network::VLAN_ID_MASK; |
| 677 | } |
| 678 | |
| 679 | // if the asked ip src is DHCP then not interested in |
| 680 | // any given data except vlan. |
| 681 | if (channelConf->ipsrc != ipmi::network::IPOrigin::DHCP) |
| 682 | { |
| 683 | // always get the system object |
| 684 | systemObject = ipmi::getDbusObject( |
| 685 | bus, |
| 686 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 687 | ipmi::network::ROOT); |
| 688 | |
| 689 | // the below code is to determine the mode of the interface |
| 690 | // as the handling is same, if the system is configured with |
| 691 | // DHCP or user has given all the data. |
| 692 | try |
| 693 | { |
| 694 | ipmi::ObjectTree ancestorMap; |
| 695 | |
| 696 | ipmi::InterfaceList interfaces { |
| 697 | ipmi::network::ETHERNET_INTERFACE }; |
| 698 | |
| 699 | // if the system is having ip object,then |
| 700 | // get the IP object. |
Ratan Gupta | df53d22 | 2018-03-18 23:13:39 +0530 | [diff] [blame] | 701 | ipObject = ipmi::getIPObject(bus, |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 702 | ipmi::network::IP_INTERFACE, |
| 703 | ipmi::network::ROOT, |
| 704 | ethIp); |
| 705 | |
| 706 | // Get the parent interface of the IP object. |
| 707 | try |
| 708 | { |
| 709 | ancestorMap = ipmi::getAllAncestors(bus, |
| 710 | ipObject.first, |
| 711 | std::move(interfaces)); |
| 712 | } |
| 713 | catch (InternalFailure& e) |
| 714 | { |
| 715 | // if unable to get the parent interface |
| 716 | // then commit the error and return. |
| 717 | log<level::ERR>("Unable to get the parent interface", |
| 718 | entry("PATH=%s", ipObject.first.c_str()), |
| 719 | entry("INTERFACE=%s", |
| 720 | ipmi::network::ETHERNET_INTERFACE)); |
| 721 | commit<InternalFailure>(); |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 722 | channelConf->clear(); |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 723 | return; |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | networkInterfacePath = ancestorMap.begin()->first; |
| 727 | } |
| 728 | catch (InternalFailure& e) |
| 729 | { |
| 730 | // TODO Currently IPMI supports single interface,need to handle |
| 731 | // Multiple interface through |
| 732 | // https://github.com/openbmc/openbmc/issues/2138 |
| 733 | |
| 734 | // if there is no ip configured on the system,then |
| 735 | // get the network interface object. |
| 736 | auto networkInterfaceObject = ipmi::getDbusObject( |
| 737 | bus, |
| 738 | ipmi::network::ETHERNET_INTERFACE, |
| 739 | ipmi::network::ROOT, |
| 740 | ethdevice); |
| 741 | |
| 742 | networkInterfacePath = std::move(networkInterfaceObject.first); |
| 743 | } |
| 744 | |
| 745 | // get the configured mode on the system. |
| 746 | auto enableDHCP = ipmi::getDbusProperty( |
| 747 | bus, |
| 748 | ipmi::network::SERVICE, |
| 749 | networkInterfacePath, |
| 750 | ipmi::network::ETHERNET_INTERFACE, |
| 751 | "DHCPEnabled").get<bool>(); |
| 752 | |
| 753 | // if ip address source is not given then get the ip source mode |
| 754 | // from the system so that it can be applied later. |
| 755 | if (channelConf->ipsrc == ipmi::network::IPOrigin::UNSPECIFIED) |
| 756 | { |
| 757 | channelConf->ipsrc = (enableDHCP) ? |
| 758 | ipmi::network::IPOrigin::DHCP : |
| 759 | ipmi::network::IPOrigin::STATIC; |
| 760 | } |
| 761 | |
| 762 | // check whether user has given all the data |
| 763 | // or the configured system interface is dhcp enabled, |
| 764 | // in both of the cases get the values from the cache. |
| 765 | if ((!channelConf->ipaddr.empty() && |
| 766 | !channelConf->netmask.empty() && |
| 767 | !channelConf->gateway.empty()) || |
| 768 | (enableDHCP)) // configured system interface mode = DHCP |
| 769 | { |
| 770 | //convert mask into prefix |
| 771 | ipaddress = channelConf->ipaddr; |
| 772 | prefix = ipmi::network::toPrefix(AF_INET, channelConf->netmask); |
| 773 | gateway = channelConf->gateway; |
| 774 | } |
| 775 | else // asked ip src = static and configured system src = static |
| 776 | // or partially given data. |
| 777 | { |
| 778 | // We have partial filled cache so get the remaining |
| 779 | // info from the system. |
| 780 | |
| 781 | // Get the network data from the system as user has |
| 782 | // not given all the data then use the data fetched from the |
| 783 | // system but it is implementation dependent,IPMI spec doesn't |
| 784 | // force it. |
| 785 | |
| 786 | // if system is not having any ip object don't throw error, |
| 787 | try |
| 788 | { |
| 789 | auto properties = ipmi::getAllDbusProperties( |
| 790 | bus, |
| 791 | ipObject.second, |
| 792 | ipObject.first, |
| 793 | ipmi::network::IP_INTERFACE); |
| 794 | |
| 795 | ipaddress = channelConf->ipaddr.empty() ? |
| 796 | properties["Address"].get<std::string>() : |
| 797 | channelConf->ipaddr; |
| 798 | |
| 799 | prefix = channelConf->netmask.empty() ? |
| 800 | properties["PrefixLength"].get<uint8_t>() : |
| 801 | ipmi::network::toPrefix(AF_INET, |
| 802 | channelConf->netmask); |
| 803 | } |
| 804 | catch (InternalFailure& e) |
| 805 | { |
| 806 | log<level::INFO>("Failed to get IP object which matches", |
| 807 | entry("INTERFACE=%s", ipmi::network::IP_INTERFACE), |
| 808 | entry("MATCH=%s", ethIp)); |
| 809 | } |
| 810 | |
| 811 | auto systemProperties = ipmi::getAllDbusProperties( |
| 812 | bus, |
| 813 | systemObject.second, |
| 814 | systemObject.first, |
| 815 | ipmi::network::SYSTEMCONFIG_INTERFACE); |
| 816 | |
| 817 | gateway = channelConf->gateway.empty() ? |
| 818 | systemProperties["DefaultGateway"].get<std::string>() : |
| 819 | channelConf->gateway; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | // Currently network manager doesn't support purging of all the |
| 824 | // ip addresses and the vlan interfaces from the parent interface, |
| 825 | // TODO once the support is there, will make the change here. |
| 826 | // https://github.com/openbmc/openbmc/issues/2141. |
| 827 | |
| 828 | // TODO Currently IPMI supports single interface,need to handle |
| 829 | // Multiple interface through |
| 830 | // https://github.com/openbmc/openbmc/issues/2138 |
| 831 | |
| 832 | // instead of deleting all the vlan interfaces and |
| 833 | // all the ipv4 address,we will call reset method. |
| 834 | //delete all the vlan interfaces |
| 835 | |
| 836 | ipmi::deleteAllDbusObjects(bus, |
| 837 | ipmi::network::ROOT, |
| 838 | ipmi::network::VLAN_INTERFACE); |
| 839 | |
| 840 | // set the interface mode to static |
| 841 | auto networkInterfaceObject = ipmi::getDbusObject( |
| 842 | bus, |
| 843 | ipmi::network::ETHERNET_INTERFACE, |
| 844 | ipmi::network::ROOT, |
| 845 | ethdevice); |
| 846 | |
| 847 | // setting the physical interface mode to static. |
| 848 | ipmi::setDbusProperty(bus, |
| 849 | ipmi::network::SERVICE, |
| 850 | networkInterfaceObject.first, |
| 851 | ipmi::network::ETHERNET_INTERFACE, |
| 852 | "DHCPEnabled", |
| 853 | false); |
| 854 | |
| 855 | networkInterfacePath = networkInterfaceObject.first; |
| 856 | |
| 857 | //delete all the ipv4 addresses |
| 858 | ipmi::deleteAllDbusObjects(bus, |
| 859 | ipmi::network::ROOT, |
| 860 | ipmi::network::IP_INTERFACE, |
| 861 | ethIp); |
| 862 | |
| 863 | if (vlanID) |
| 864 | { |
| 865 | ipmi::network::createVLAN(bus, |
| 866 | ipmi::network::SERVICE, |
| 867 | ipmi::network::ROOT, |
| 868 | ethdevice, |
| 869 | vlanID); |
| 870 | |
| 871 | auto networkInterfaceObject = ipmi::getDbusObject( |
| 872 | bus, |
| 873 | ipmi::network::VLAN_INTERFACE, |
| 874 | ipmi::network::ROOT); |
| 875 | |
| 876 | networkInterfacePath = networkInterfaceObject.first; |
| 877 | } |
| 878 | |
| 879 | if (channelConf->ipsrc == ipmi::network::IPOrigin::DHCP) |
| 880 | { |
| 881 | ipmi::setDbusProperty(bus, |
| 882 | ipmi::network::SERVICE, |
| 883 | networkInterfacePath, |
| 884 | ipmi::network::ETHERNET_INTERFACE, |
| 885 | "DHCPEnabled", |
| 886 | true); |
| 887 | } |
| 888 | else |
| 889 | { |
| 890 | //change the mode to static |
| 891 | ipmi::setDbusProperty(bus, |
| 892 | ipmi::network::SERVICE, |
| 893 | networkInterfacePath, |
| 894 | ipmi::network::ETHERNET_INTERFACE, |
| 895 | "DHCPEnabled", |
| 896 | false); |
| 897 | |
| 898 | if (!ipaddress.empty()) |
| 899 | { |
| 900 | ipmi::network::createIP(bus, |
| 901 | ipmi::network::SERVICE, |
| 902 | networkInterfacePath, |
| 903 | ipv4Protocol, |
| 904 | ipaddress, |
| 905 | prefix); |
| 906 | } |
| 907 | |
| 908 | if (!gateway.empty()) |
| 909 | { |
| 910 | ipmi::setDbusProperty(bus, |
| 911 | systemObject.second, |
| 912 | systemObject.first, |
| 913 | ipmi::network::SYSTEMCONFIG_INTERFACE, |
| 914 | "DefaultGateway", |
| 915 | std::string(gateway)); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | } |
| 920 | catch (InternalFailure& e) |
| 921 | { |
| 922 | log<level::ERR>("Failed to set network data", |
| 923 | entry("PREFIX=%d", prefix), |
| 924 | entry("ADDRESS=%s", ipaddress.c_str()), |
| 925 | entry("GATEWAY=%s", gateway.c_str()), |
| 926 | entry("VLANID=%d", vlanID), |
| 927 | entry("IPSRC=%d", channelConf->ipsrc)); |
| 928 | |
| 929 | commit<InternalFailure>(); |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | channelConf->clear(); |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | void commitNetworkChanges() |
| 936 | { |
| 937 | for (const auto &channel : channelConfig) |
| 938 | { |
| 939 | if (channel.second->flush) |
| 940 | { |
| 941 | applyChanges(channel.first); |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | void createNetworkTimer() |
| 947 | { |
| 948 | if (!networkTimer) |
| 949 | { |
| 950 | std::function<void()> networkTimerCallback( |
| 951 | std::bind(&commitNetworkChanges)); |
| 952 | |
| 953 | networkTimer = |
| 954 | std::make_unique<phosphor::ipmi::Timer>( |
| 955 | ipmid_get_sd_event_connection(), |
| 956 | networkTimerCallback); |
| 957 | } |
| 958 | |
Ratan Gupta | 1247e0b | 2018-03-07 10:47:25 +0530 | [diff] [blame] | 959 | } |
| 960 | |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 961 | void register_netfn_transport_functions() |
| 962 | { |
Ratan Gupta | 7a7f012 | 2018-03-07 12:31:05 +0530 | [diff] [blame] | 963 | // As this timer is only for transport handler |
| 964 | // so creating it here. |
| 965 | createNetworkTimer(); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 966 | // <Wildcard Command> |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 967 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_WILDCARD, NULL, ipmi_transport_wildcard, |
| 968 | PRIVILEGE_USER); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 969 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 970 | // <Set LAN Configuration Parameters> |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 971 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_SET_LAN, NULL, ipmi_transport_set_lan, |
| 972 | PRIVILEGE_ADMIN); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 973 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 974 | // <Get LAN Configuration Parameters> |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 975 | ipmi_register_callback(NETFUN_TRANSPORT, IPMI_CMD_GET_LAN, NULL, ipmi_transport_get_lan, |
| 976 | PRIVILEGE_OPERATOR); |
Adriana Kobylak | 5d6481f | 2015-10-29 21:44:55 -0500 | [diff] [blame] | 977 | |
| 978 | return; |
| 979 | } |