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