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