Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 3 | #include "network_manager.hpp" |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 4 | |
William A. Kennington III | 09f3a4a | 2022-10-25 02:59:16 -0700 | [diff] [blame] | 5 | #include "config_parser.hpp" |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 6 | #include "ipaddress.hpp" |
William A. Kennington III | 2e09d27 | 2022-10-14 17:15:00 -0700 | [diff] [blame] | 7 | #include "system_queries.hpp" |
William A. Kennington III | 3a70fa2 | 2018-09-20 18:48:20 -0700 | [diff] [blame] | 8 | #include "types.hpp" |
Ratan Gupta | 738a67f | 2017-04-21 10:38:05 +0530 | [diff] [blame] | 9 | |
Manojkiran Eda | cc099a8 | 2020-05-11 14:25:16 +0530 | [diff] [blame] | 10 | #include <filesystem> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 11 | #include <fstream> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 12 | #include <phosphor-logging/elog-errors.hpp> |
| 13 | #include <phosphor-logging/log.hpp> |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 14 | #include <sdbusplus/message.hpp> |
Patrick Venture | 189d44e | 2018-07-09 12:30:59 -0700 | [diff] [blame] | 15 | #include <xyz/openbmc_project/Common/error.hpp> |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 16 | |
William A. Kennington III | f1aa51c | 2019-02-12 19:58:11 -0800 | [diff] [blame] | 17 | constexpr char SYSTEMD_BUSNAME[] = "org.freedesktop.systemd1"; |
| 18 | constexpr char SYSTEMD_PATH[] = "/org/freedesktop/systemd1"; |
| 19 | constexpr char SYSTEMD_INTERFACE[] = "org.freedesktop.systemd1.Manager"; |
Manojkiran Eda | cc099a8 | 2020-05-11 14:25:16 +0530 | [diff] [blame] | 20 | constexpr auto FirstBootFile = "/var/lib/network/firstBoot_"; |
William A. Kennington III | f1aa51c | 2019-02-12 19:58:11 -0800 | [diff] [blame] | 21 | |
William A. Kennington III | 56ecc78 | 2021-10-07 18:44:50 -0700 | [diff] [blame] | 22 | constexpr char NETWORKD_BUSNAME[] = "org.freedesktop.network1"; |
| 23 | constexpr char NETWORKD_PATH[] = "/org/freedesktop/network1"; |
| 24 | constexpr char NETWORKD_INTERFACE[] = "org.freedesktop.network1.Manager"; |
| 25 | |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 26 | namespace phosphor |
| 27 | { |
| 28 | namespace network |
| 29 | { |
Ratan Gupta | 82549cc | 2017-04-21 08:45:23 +0530 | [diff] [blame] | 30 | |
William A. Kennington III | d41db38 | 2021-11-09 20:42:29 -0800 | [diff] [blame] | 31 | extern std::unique_ptr<Timer> refreshObjectTimer; |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 32 | extern std::unique_ptr<Timer> reloadTimer; |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 33 | using namespace phosphor::logging; |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 34 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Jiaqing Zhao | b685cb6 | 2022-04-12 22:57:34 +0800 | [diff] [blame] | 35 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 36 | |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 37 | static constexpr const char enabledMatch[] = |
| 38 | "type='signal',sender='org.freedesktop.network1',path_namespace='/org/" |
| 39 | "freedesktop/network1/" |
| 40 | "link',interface='org.freedesktop.DBus.Properties',member='" |
| 41 | "PropertiesChanged',arg0='org.freedesktop.network1.Link',"; |
| 42 | |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 43 | Manager::Manager(sdbusplus::bus_t& bus, const char* objPath, |
William A. Kennington III | be3bd2f | 2022-10-11 14:11:27 -0700 | [diff] [blame] | 44 | const fs::path& confDir) : |
Patrick Williams | 166b959 | 2022-03-30 16:09:16 -0500 | [diff] [blame] | 45 | details::VLANCreateIface(bus, objPath, |
| 46 | details::VLANCreateIface::action::defer_emit), |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 47 | bus(bus), objectPath(objPath), |
| 48 | systemdNetworkdEnabledMatch( |
| 49 | bus, enabledMatch, [&](sdbusplus::message_t& m) { |
| 50 | std::string intf; |
| 51 | std::unordered_map<std::string, std::variant<std::string>> values; |
| 52 | try |
| 53 | { |
| 54 | m.read(intf, values); |
| 55 | auto it = values.find("AdministrativeState"); |
| 56 | if (it == values.end()) |
| 57 | { |
| 58 | return; |
| 59 | } |
| 60 | const std::string_view obj = m.get_path(); |
| 61 | auto sep = obj.rfind('/'); |
| 62 | if (sep == obj.npos || sep + 3 > obj.size()) |
| 63 | { |
| 64 | throw std::invalid_argument("Invalid obj path"); |
| 65 | } |
| 66 | auto ifidx = DecodeInt<unsigned, 10>{}(obj.substr(sep + 3)); |
| 67 | const auto& state = std::get<std::string>(it->second); |
| 68 | handleAdminState(state, ifidx); |
| 69 | } |
| 70 | catch (const std::exception& e) |
| 71 | { |
| 72 | log<level::ERR>( |
| 73 | fmt::format("AdministrativeState match parsing failed: {}", |
| 74 | e.what()) |
| 75 | .c_str(), |
| 76 | entry("ERROR=%s", e.what())); |
| 77 | } |
| 78 | }) |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 79 | { |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 80 | setConfDir(confDir); |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 81 | std::vector< |
| 82 | std::tuple<int32_t, std::string, sdbusplus::message::object_path>> |
| 83 | links; |
| 84 | try |
| 85 | { |
| 86 | auto rsp = |
| 87 | bus.new_method_call("org.freedesktop.network1", |
| 88 | "/org/freedesktop/network1", |
| 89 | "org.freedesktop.network1.Manager", "ListLinks") |
| 90 | .call(); |
| 91 | rsp.read(links); |
| 92 | } |
| 93 | catch (const sdbusplus::exception::SdBusError& e) |
| 94 | { |
| 95 | // Any failures are systemd-network not being ready |
| 96 | } |
| 97 | for (const auto& link : links) |
| 98 | { |
| 99 | unsigned ifidx = std::get<0>(link); |
| 100 | auto obj = fmt::format("/org/freedesktop/network1/link/_3{}", ifidx); |
| 101 | auto req = |
| 102 | bus.new_method_call("org.freedesktop.network1", obj.c_str(), |
| 103 | "org.freedesktop.DBus.Properties", "Get"); |
| 104 | req.append("org.freedesktop.network1.Link", "AdministrativeState"); |
| 105 | auto rsp = req.call(); |
| 106 | std::variant<std::string> val; |
| 107 | rsp.read(val); |
| 108 | handleAdminState(std::get<std::string>(val), ifidx); |
| 109 | } |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | void Manager::setConfDir(const fs::path& dir) |
| 113 | { |
| 114 | confDir = dir; |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 115 | |
| 116 | if (!fs::exists(confDir)) |
| 117 | { |
| 118 | if (!fs::create_directories(confDir)) |
| 119 | { |
| 120 | log<level::ERR>("Unable to create the network conf dir", |
| 121 | entry("DIR=%s", confDir.c_str())); |
| 122 | elog<InternalFailure>(); |
| 123 | } |
| 124 | } |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 125 | } |
| 126 | |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame^] | 127 | void Manager::createInterface(const InterfaceInfo& info, bool enabled) |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 128 | { |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame^] | 129 | removeInterface(info); |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 130 | config::Parser config(config::pathForIntfConf(confDir, *info.name)); |
| 131 | auto intf = std::make_unique<EthernetInterface>( |
| 132 | bus, *this, info, objectPath, config, true, enabled); |
| 133 | intf->createIPAddressObjects(); |
| 134 | intf->createStaticNeighborObjects(); |
| 135 | intf->loadNameServers(config); |
| 136 | intf->loadNTPServers(config); |
| 137 | auto ptr = intf.get(); |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame^] | 138 | interfaces.emplace(*info.name, std::move(intf)); |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 139 | interfacesByIdx.emplace(info.idx, ptr); |
| 140 | } |
| 141 | |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame^] | 142 | void Manager::addInterface(const InterfaceInfo& info) |
| 143 | { |
| 144 | auto it = systemdNetworkdEnabled.find(info.idx); |
| 145 | if (it != systemdNetworkdEnabled.end()) |
| 146 | { |
| 147 | createInterface(info, it->second); |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | undiscoveredIntfInfo.insert_or_assign(info.idx, std::move(info)); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void Manager::removeInterface(const InterfaceInfo& info) |
| 156 | { |
| 157 | auto iit = interfacesByIdx.find(info.idx); |
| 158 | auto nit = interfaces.end(); |
| 159 | if (info.name) |
| 160 | { |
| 161 | nit = interfaces.find(*info.name); |
| 162 | if (nit != interfaces.end() && iit != interfacesByIdx.end() && |
| 163 | nit->second.get() != iit->second) |
| 164 | { |
| 165 | fmt::print(stderr, "Removed interface desync detected\n"); |
| 166 | fflush(stderr); |
| 167 | std::abort(); |
| 168 | } |
| 169 | } |
| 170 | else if (iit != interfacesByIdx.end()) |
| 171 | { |
| 172 | for (nit = interfaces.begin(); nit != interfaces.end(); ++nit) |
| 173 | { |
| 174 | if (nit->second.get() == iit->second) |
| 175 | { |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if (iit != interfacesByIdx.end()) |
| 182 | { |
| 183 | interfacesByIdx.erase(iit); |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | undiscoveredIntfInfo.erase(info.idx); |
| 188 | } |
| 189 | if (nit != interfaces.end()) |
| 190 | { |
| 191 | interfaces.erase(nit); |
| 192 | } |
| 193 | } |
| 194 | |
William A. Kennington III | ed5ff47 | 2022-11-12 16:24:02 -0800 | [diff] [blame] | 195 | inline void getIntfOrLog(const decltype(Manager::interfacesByIdx)& intfs, |
| 196 | unsigned idx, auto&& cb) |
| 197 | { |
| 198 | auto it = intfs.find(idx); |
| 199 | if (it == intfs.end()) |
| 200 | { |
| 201 | auto msg = fmt::format("Interface `{}` not found", idx); |
| 202 | log<level::ERR>(msg.c_str(), entry("IFIDX=%u", idx)); |
| 203 | return; |
| 204 | } |
| 205 | cb(*it->second); |
| 206 | } |
| 207 | |
| 208 | void Manager::addAddress(const AddressInfo& info) |
| 209 | { |
| 210 | getIntfOrLog(interfacesByIdx, info.ifidx, |
| 211 | [&](auto& intf) { intf.addAddr(info); }); |
| 212 | } |
| 213 | |
| 214 | void Manager::removeAddress(const AddressInfo& info) |
| 215 | { |
| 216 | getIntfOrLog(interfacesByIdx, info.ifidx, |
| 217 | [&](auto& intf) { intf.addrs.erase(info.ifaddr); }); |
| 218 | } |
| 219 | |
| 220 | void Manager::addNeighbor(const NeighborInfo& info) |
| 221 | { |
| 222 | getIntfOrLog(interfacesByIdx, info.ifidx, |
| 223 | [&](auto& intf) { intf.addStaticNeigh(info); }); |
| 224 | } |
| 225 | |
| 226 | void Manager::removeNeighbor(const NeighborInfo& info) |
| 227 | { |
| 228 | if (info.addr) |
| 229 | { |
| 230 | getIntfOrLog(interfacesByIdx, info.ifidx, [&](auto& intf) { |
| 231 | intf.staticNeighbors.erase(*info.addr); |
| 232 | }); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | void Manager::addDefGw(unsigned ifidx, InAddrAny addr) |
| 237 | { |
| 238 | getIntfOrLog(interfacesByIdx, ifidx, [&](auto& intf) { |
| 239 | std::visit( |
| 240 | [&](auto addr) { |
| 241 | if constexpr (std::is_same_v<in_addr, decltype(addr)>) |
| 242 | { |
| 243 | intf.EthernetInterfaceIntf::defaultGateway( |
| 244 | std::to_string(addr)); |
| 245 | } |
| 246 | else if constexpr (std::is_same_v<in6_addr, decltype(addr)>) |
| 247 | { |
| 248 | intf.EthernetInterfaceIntf::defaultGateway6( |
| 249 | std::to_string(addr)); |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | static_assert(!std::is_same_v<void, decltype(addr)>); |
| 254 | } |
| 255 | }, |
| 256 | addr); |
| 257 | }); |
| 258 | } |
| 259 | |
| 260 | void Manager::removeDefGw(unsigned ifidx, InAddrAny addr) |
| 261 | { |
| 262 | getIntfOrLog(interfacesByIdx, ifidx, [&](auto& intf) { |
| 263 | std::visit( |
| 264 | [&](auto addr) { |
| 265 | if constexpr (std::is_same_v<in_addr, decltype(addr)>) |
| 266 | { |
| 267 | if (intf.defaultGateway() == std::to_string(addr)) |
| 268 | { |
| 269 | intf.EthernetInterfaceIntf::defaultGateway(""); |
| 270 | } |
| 271 | } |
| 272 | else if constexpr (std::is_same_v<in6_addr, decltype(addr)>) |
| 273 | { |
| 274 | if (intf.defaultGateway6() == std::to_string(addr)) |
| 275 | { |
| 276 | intf.EthernetInterfaceIntf::defaultGateway6(""); |
| 277 | } |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | static_assert(!std::is_same_v<void, decltype(addr)>); |
| 282 | } |
| 283 | }, |
| 284 | addr); |
| 285 | }); |
| 286 | } |
| 287 | |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 288 | void Manager::createInterfaces() |
| 289 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 290 | // clear all the interfaces first |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 291 | interfaces.clear(); |
William A. Kennington III | 67b09da | 2022-10-31 14:09:53 -0700 | [diff] [blame] | 292 | interfacesByIdx.clear(); |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 293 | for (auto& info : system::getInterfaces()) |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 294 | { |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame^] | 295 | addInterface(info); |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 299 | void Manager::createChildObjects() |
| 300 | { |
William A. Kennington III | e056484 | 2021-10-23 16:02:22 -0700 | [diff] [blame] | 301 | routeTable.refresh(); |
| 302 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 303 | // creates the ethernet interface dbus object. |
| 304 | createInterfaces(); |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 305 | |
| 306 | systemConf.reset(nullptr); |
| 307 | dhcpConf.reset(nullptr); |
| 308 | |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 309 | fs::path objPath = objectPath; |
| 310 | objPath /= "config"; |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 311 | |
| 312 | // create the system conf object. |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 313 | systemConf = std::make_unique<phosphor::network::SystemConfiguration>( |
Jiaqing Zhao | 24b5a61 | 2022-04-11 16:46:16 +0800 | [diff] [blame] | 314 | bus, objPath.string()); |
Ratan Gupta | d16f88c | 2017-07-11 17:47:57 +0530 | [diff] [blame] | 315 | // create the dhcp conf object. |
| 316 | objPath /= "dhcp"; |
| 317 | dhcpConf = std::make_unique<phosphor::network::dhcp::Configuration>( |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 318 | bus, objPath.string(), *this); |
Ratan Gupta | ef85eb9 | 2017-06-15 08:57:54 +0530 | [diff] [blame] | 319 | } |
| 320 | |
William A. Kennington III | 085bbdc | 2022-10-05 02:45:37 -0700 | [diff] [blame] | 321 | ObjectPath Manager::vlan(std::string interfaceName, uint32_t id) |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 322 | { |
Jiaqing Zhao | b685cb6 | 2022-04-12 22:57:34 +0800 | [diff] [blame] | 323 | if (id == 0 || id >= 4095) |
| 324 | { |
| 325 | log<level::ERR>("VLAN ID is not valid", entry("VLANID=%u", id)); |
| 326 | elog<InvalidArgument>( |
| 327 | Argument::ARGUMENT_NAME("VLANId"), |
| 328 | Argument::ARGUMENT_VALUE(std::to_string(id).c_str())); |
| 329 | } |
| 330 | |
William A. Kennington III | 9644479 | 2022-10-05 15:16:22 -0700 | [diff] [blame] | 331 | auto it = interfaces.find(interfaceName); |
| 332 | if (it == interfaces.end()) |
| 333 | { |
| 334 | using ResourceErr = |
| 335 | phosphor::logging::xyz::openbmc_project::Common::ResourceNotFound; |
| 336 | elog<ResourceNotFound>(ResourceErr::RESOURCE(interfaceName.c_str())); |
| 337 | } |
| 338 | return it->second->createVLAN(id); |
Ratan Gupta | 6811f82 | 2017-04-14 16:34:56 +0530 | [diff] [blame] | 339 | } |
| 340 | |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 341 | void Manager::reset() |
| 342 | { |
William A. Kennington III | 9a1d9af | 2021-11-09 17:51:05 -0800 | [diff] [blame] | 343 | if (fs::is_directory(confDir)) |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 344 | { |
William A. Kennington III | 9a1d9af | 2021-11-09 17:51:05 -0800 | [diff] [blame] | 345 | for (const auto& file : fs::directory_iterator(confDir)) |
| 346 | { |
| 347 | fs::remove(file.path()); |
| 348 | } |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 349 | } |
William A. Kennington III | 9a1d9af | 2021-11-09 17:51:05 -0800 | [diff] [blame] | 350 | log<level::INFO>("Network Factory Reset queued."); |
Michael Tritz | 29f2fd6 | 2017-05-22 15:27:26 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 353 | // Need to merge the below function with the code which writes the |
| 354 | // config file during factory reset. |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 355 | // TODO openbmc/openbmc#1751 |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 356 | void Manager::writeToConfigurationFile() |
| 357 | { |
| 358 | // write all the static ip address in the systemd-network conf file |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 359 | for (const auto& intf : interfaces) |
| 360 | { |
Ratan Gupta | 2b10653 | 2017-07-25 16:05:02 +0530 | [diff] [blame] | 361 | intf.second->writeConfigurationFile(); |
Ratan Gupta | 4f1c18b | 2017-05-25 12:59:35 +0530 | [diff] [blame] | 362 | } |
Ratan Gupta | e05083a | 2017-09-16 07:12:11 +0530 | [diff] [blame] | 363 | } |
| 364 | |
William A. Kennington III | 6f39c5e | 2021-05-13 18:39:23 -0700 | [diff] [blame] | 365 | #ifdef SYNC_MAC_FROM_INVENTORY |
Manojkiran Eda | cc099a8 | 2020-05-11 14:25:16 +0530 | [diff] [blame] | 366 | void Manager::setFistBootMACOnInterface( |
| 367 | const std::pair<std::string, std::string>& inventoryEthPair) |
| 368 | { |
| 369 | for (const auto& interface : interfaces) |
| 370 | { |
| 371 | if (interface.first == inventoryEthPair.first) |
| 372 | { |
| 373 | auto returnMAC = |
Patrick Williams | 6aef769 | 2021-05-01 06:39:41 -0500 | [diff] [blame] | 374 | interface.second->macAddress(inventoryEthPair.second); |
Manojkiran Eda | cc099a8 | 2020-05-11 14:25:16 +0530 | [diff] [blame] | 375 | if (returnMAC == inventoryEthPair.second) |
| 376 | { |
| 377 | log<level::INFO>("Set the MAC on "), |
| 378 | entry("interface : ", interface.first.c_str()), |
| 379 | entry("MAC : ", inventoryEthPair.second.c_str()); |
| 380 | std::error_code ec; |
| 381 | if (std::filesystem::is_directory("/var/lib/network", ec)) |
| 382 | { |
| 383 | std::ofstream persistentFile(FirstBootFile + |
| 384 | interface.first); |
| 385 | } |
| 386 | break; |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | log<level::INFO>("MAC is Not Set on ethernet Interface"); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | #endif |
| 397 | |
William A. Kennington III | 85dc57a | 2022-11-07 16:53:24 -0800 | [diff] [blame] | 398 | void Manager::reloadConfigsNoRefresh() |
William A. Kennington III | 56ecc78 | 2021-10-07 18:44:50 -0700 | [diff] [blame] | 399 | { |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 400 | reloadTimer->restartOnce(reloadTimeout); |
William A. Kennington III | 85dc57a | 2022-11-07 16:53:24 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void Manager::reloadConfigs() |
| 404 | { |
| 405 | reloadConfigsNoRefresh(); |
William A. Kennington III | d41db38 | 2021-11-09 20:42:29 -0800 | [diff] [blame] | 406 | // Ensure that the next refresh happens after reconfiguration |
| 407 | refreshObjectTimer->setRemaining(reloadTimeout + refreshTimeout); |
William A. Kennington III | c7cf25f | 2021-11-09 16:16:59 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void Manager::doReloadConfigs() |
| 411 | { |
William A. Kennington III | 6ff633a | 2021-11-09 17:09:12 -0800 | [diff] [blame] | 412 | for (auto& hook : reloadPreHooks) |
| 413 | { |
| 414 | try |
| 415 | { |
| 416 | hook(); |
| 417 | } |
| 418 | catch (const std::exception& ex) |
| 419 | { |
| 420 | log<level::ERR>("Failed executing reload hook, ignoring", |
| 421 | entry("ERR=%s", ex.what())); |
| 422 | } |
| 423 | } |
| 424 | reloadPreHooks.clear(); |
William A. Kennington III | 56ecc78 | 2021-10-07 18:44:50 -0700 | [diff] [blame] | 425 | try |
| 426 | { |
| 427 | auto method = bus.new_method_call(NETWORKD_BUSNAME, NETWORKD_PATH, |
| 428 | NETWORKD_INTERFACE, "Reload"); |
| 429 | bus.call_noreply(method); |
| 430 | } |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 431 | catch (const sdbusplus::exception_t& ex) |
William A. Kennington III | 56ecc78 | 2021-10-07 18:44:50 -0700 | [diff] [blame] | 432 | { |
| 433 | log<level::ERR>("Failed to reload configuration", |
| 434 | entry("ERR=%s", ex.what())); |
| 435 | elog<InternalFailure>(); |
| 436 | } |
William A. Kennington III | d41db38 | 2021-11-09 20:42:29 -0800 | [diff] [blame] | 437 | // Ensure reconfiguration has enough time |
William A. Kennington III | 85dc57a | 2022-11-07 16:53:24 -0800 | [diff] [blame] | 438 | if (refreshObjectTimer->isEnabled()) |
| 439 | { |
| 440 | refreshObjectTimer->setRemaining(refreshTimeout); |
| 441 | } |
William A. Kennington III | 56ecc78 | 2021-10-07 18:44:50 -0700 | [diff] [blame] | 442 | } |
| 443 | |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 444 | void Manager::handleAdminState(std::string_view state, unsigned ifidx) |
| 445 | { |
| 446 | if (state == "initialized" || state == "linger") |
| 447 | { |
| 448 | systemdNetworkdEnabled.erase(ifidx); |
| 449 | } |
| 450 | else |
| 451 | { |
| 452 | bool managed = state != "unmanaged"; |
| 453 | systemdNetworkdEnabled.insert_or_assign(ifidx, managed); |
| 454 | if (auto it = undiscoveredIntfInfo.find(ifidx); |
| 455 | it != undiscoveredIntfInfo.end()) |
| 456 | { |
| 457 | auto info = std::move(it->second); |
| 458 | undiscoveredIntfInfo.erase(it); |
William A. Kennington III | 0813a24 | 2022-11-12 18:07:11 -0800 | [diff] [blame^] | 459 | createInterface(info, managed); |
William A. Kennington III | 80d2901 | 2022-11-12 02:31:40 -0800 | [diff] [blame] | 460 | } |
| 461 | else if (auto it = interfacesByIdx.find(ifidx); |
| 462 | it != interfacesByIdx.end()) |
| 463 | { |
| 464 | it->second->EthernetInterfaceIntf::nicEnabled(managed); |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 469 | } // namespace network |
| 470 | } // namespace phosphor |