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