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