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