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