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