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