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