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