blob: 060242c30805117ed3e714bb5cdc5c90a339a7d9 [file] [log] [blame]
Ratan Gupta6811f822017-04-14 16:34:56 +05301#include "network_manager.hpp"
Patrick Venture189d44e2018-07-09 12:30:59 -07002
William A. Kennington III09f3a4a2022-10-25 02:59:16 -07003#include "config_parser.hpp"
Ratan Gupta5978dd12017-07-25 13:47:13 +05304#include "ipaddress.hpp"
William A. Kennington III2e09d272022-10-14 17:15:00 -07005#include "system_queries.hpp"
William A. Kennington III3a70fa22018-09-20 18:48:20 -07006#include "types.hpp"
William A. Kennington IIIb8006122022-11-13 18:15:15 -08007#include "util.hpp"
8
William A. Kennington III57ca9612022-11-14 15:26:47 -08009#include <linux/if_addr.h>
William A. Kennington III7310ac72022-11-14 15:44:00 -080010#include <linux/neighbour.h>
William A. Kennington IIIb8006122022-11-13 18:15:15 -080011#include <net/if.h>
Ratan Gupta738a67f2017-04-21 10:38:05 +053012
Manojkiran Edacc099a82020-05-11 14:25:16 +053013#include <filesystem>
Patrick Venture189d44e2018-07-09 12:30:59 -070014#include <phosphor-logging/elog-errors.hpp>
15#include <phosphor-logging/log.hpp>
William A. Kennington III80d29012022-11-12 02:31:40 -080016#include <sdbusplus/message.hpp>
William A. Kennington III9ede1b72022-11-21 01:59:28 -080017#include <stdplus/pinned.hpp>
Patrick Venture189d44e2018-07-09 12:30:59 -070018#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta6811f822017-04-14 16:34:56 +053019
William A. Kennington IIIf1aa51c2019-02-12 19:58:11 -080020constexpr char SYSTEMD_BUSNAME[] = "org.freedesktop.systemd1";
21constexpr char SYSTEMD_PATH[] = "/org/freedesktop/systemd1";
22constexpr char SYSTEMD_INTERFACE[] = "org.freedesktop.systemd1.Manager";
23
William A. Kennington III56ecc782021-10-07 18:44:50 -070024constexpr char NETWORKD_BUSNAME[] = "org.freedesktop.network1";
25constexpr char NETWORKD_PATH[] = "/org/freedesktop/network1";
26constexpr char NETWORKD_INTERFACE[] = "org.freedesktop.network1.Manager";
27
Ratan Gupta6811f822017-04-14 16:34:56 +053028namespace phosphor
29{
30namespace network
31{
Ratan Gupta82549cc2017-04-21 08:45:23 +053032
Ratan Gupta6811f822017-04-14 16:34:56 +053033using namespace phosphor::logging;
Ratan Guptaef85eb92017-06-15 08:57:54 +053034using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Jiaqing Zhaob685cb62022-04-12 22:57:34 +080035using Argument = xyz::openbmc_project::Common::InvalidArgument;
Ratan Gupta6811f822017-04-14 16:34:56 +053036
William A. Kennington III80d29012022-11-12 02:31:40 -080037static 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
William A. Kennington III9ede1b72022-11-21 01:59:28 -080043Manager::Manager(stdplus::PinnedRef<sdbusplus::bus_t> bus,
44 DelayedExecutor& reload, stdplus::zstring_view objPath,
William A. Kennington III5b179382022-11-15 15:23:26 -080045 const std::filesystem::path& confDir) :
William A. Kennington IIIde70ccf2022-11-20 17:18:01 -080046 ManagerIface(bus, objPath.c_str(), ManagerIface::action::defer_emit),
47 reload(reload), bus(bus), objPath(std::string(objPath)), confDir(confDir),
William A. Kennington III80d29012022-11-12 02:31:40 -080048 systemdNetworkdEnabledMatch(
William A. Kennington III9ede1b72022-11-21 01:59:28 -080049 bus, enabledMatch,
50 [man = stdplus::PinnedRef(*this)](sdbusplus::message_t& m) {
William A. Kennington III80d29012022-11-12 02:31:40 -080051 std::string intf;
52 std::unordered_map<std::string, std::variant<std::string>> values;
53 try
54 {
55 m.read(intf, values);
56 auto it = values.find("AdministrativeState");
57 if (it == values.end())
58 {
59 return;
60 }
61 const std::string_view obj = m.get_path();
62 auto sep = obj.rfind('/');
63 if (sep == obj.npos || sep + 3 > obj.size())
64 {
65 throw std::invalid_argument("Invalid obj path");
66 }
67 auto ifidx = DecodeInt<unsigned, 10>{}(obj.substr(sep + 3));
68 const auto& state = std::get<std::string>(it->second);
William A. Kennington III9ede1b72022-11-21 01:59:28 -080069 man.get().handleAdminState(state, ifidx);
William A. Kennington III80d29012022-11-12 02:31:40 -080070 }
71 catch (const std::exception& e)
72 {
73 log<level::ERR>(
74 fmt::format("AdministrativeState match parsing failed: {}",
75 e.what())
76 .c_str(),
77 entry("ERROR=%s", e.what()));
78 }
79 })
Ratan Gupta6811f822017-04-14 16:34:56 +053080{
William A. Kennington IIIde70ccf2022-11-20 17:18:01 -080081 reload.setCallback([&]() {
82 for (auto& hook : reloadPreHooks)
83 {
84 try
85 {
86 hook();
87 }
88 catch (const std::exception& ex)
89 {
90 log<level::ERR>("Failed executing reload hook, ignoring",
91 entry("ERR=%s", ex.what()));
92 }
93 }
94 reloadPreHooks.clear();
95 try
96 {
William A. Kennington III9ede1b72022-11-21 01:59:28 -080097 bus.get()
98 .new_method_call(NETWORKD_BUSNAME, NETWORKD_PATH,
99 NETWORKD_INTERFACE, "Reload")
100 .call();
William A. Kennington IIIde70ccf2022-11-20 17:18:01 -0800101 log<level::INFO>("Reloaded systemd-networkd");
102 }
103 catch (const sdbusplus::exception_t& ex)
104 {
105 log<level::ERR>("Failed to reload configuration",
106 entry("ERR=%s", ex.what()));
107 reloadPostHooks.clear();
108 }
109 for (auto& hook : reloadPostHooks)
110 {
111 try
112 {
113 hook();
114 }
115 catch (const std::exception& ex)
116 {
117 log<level::ERR>("Failed executing reload hook, ignoring",
118 entry("ERR=%s", ex.what()));
119 }
120 }
121 reloadPostHooks.clear();
122 });
William A. Kennington III80d29012022-11-12 02:31:40 -0800123 std::vector<
124 std::tuple<int32_t, std::string, sdbusplus::message::object_path>>
125 links;
126 try
127 {
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800128 auto rsp = bus.get()
129 .new_method_call("org.freedesktop.network1",
130 "/org/freedesktop/network1",
131 "org.freedesktop.network1.Manager",
132 "ListLinks")
133 .call();
William A. Kennington III80d29012022-11-12 02:31:40 -0800134 rsp.read(links);
135 }
136 catch (const sdbusplus::exception::SdBusError& e)
137 {
138 // Any failures are systemd-network not being ready
139 }
140 for (const auto& link : links)
141 {
142 unsigned ifidx = std::get<0>(link);
143 auto obj = fmt::format("/org/freedesktop/network1/link/_3{}", ifidx);
144 auto req =
William A. Kennington III9ede1b72022-11-21 01:59:28 -0800145 bus.get().new_method_call("org.freedesktop.network1", obj.c_str(),
146 "org.freedesktop.DBus.Properties", "Get");
William A. Kennington III80d29012022-11-12 02:31:40 -0800147 req.append("org.freedesktop.network1.Link", "AdministrativeState");
148 auto rsp = req.call();
149 std::variant<std::string> val;
150 rsp.read(val);
151 handleAdminState(std::get<std::string>(val), ifidx);
152 }
Ratan Guptaef85eb92017-06-15 08:57:54 +0530153
William A. Kennington III5b179382022-11-15 15:23:26 -0800154 std::filesystem::create_directories(confDir);
155 systemConf = std::make_unique<phosphor::network::SystemConfiguration>(
156 bus, (this->objPath / "config").str);
157 dhcpConf = std::make_unique<phosphor::network::dhcp::Configuration>(
158 bus, (this->objPath / "dhcp").str, *this);
Ratan Gupta29b0e432017-05-25 12:51:40 +0530159}
160
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800161void Manager::createInterface(const AllIntfInfo& info, bool enabled)
William A. Kennington III80d29012022-11-12 02:31:40 -0800162{
William A. Kennington III93f5c6d2022-11-17 16:23:44 -0800163 if (ignoredIntf.find(info.intf.idx) != ignoredIntf.end())
164 {
165 return;
166 }
William A. Kennington III5b179382022-11-15 15:23:26 -0800167 if (auto it = interfacesByIdx.find(info.intf.idx);
168 it != interfacesByIdx.end())
169 {
William A. Kennington III5b179382022-11-15 15:23:26 -0800170 if (info.intf.name && *info.intf.name != it->second->interfaceName())
171 {
William A. Kennington IIIbf290462022-11-15 19:44:25 -0800172 interfaces.erase(it->second->interfaceName());
173 interfacesByIdx.erase(it);
William A. Kennington III5b179382022-11-15 15:23:26 -0800174 }
William A. Kennington IIIbf290462022-11-15 19:44:25 -0800175 else
176 {
177 it->second->updateInfo(info.intf);
178 return;
179 }
William A. Kennington III5b179382022-11-15 15:23:26 -0800180 }
William A. Kennington III876927c2022-11-17 16:20:15 -0800181 else if (info.intf.name)
182 {
183 auto it = interfaces.find(*info.intf.name);
184 if (it != interfaces.end())
185 {
186 it->second->updateInfo(info.intf);
187 return;
188 }
189 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800190 if (!info.intf.name)
191 {
192 auto msg = fmt::format("Can't create interface without name: {}",
193 info.intf.idx);
194 log<level::ERR>(msg.c_str(), entry("IFIDX=%u", info.intf.idx));
195 return;
196 }
William A. Kennington IIIf30d5602022-11-13 17:09:55 -0800197 config::Parser config(config::pathForIntfConf(confDir, *info.intf.name));
William A. Kennington III80d29012022-11-12 02:31:40 -0800198 auto intf = std::make_unique<EthernetInterface>(
William A. Kennington III13d665c2022-11-15 20:34:40 -0800199 bus, *this, info, objPath.str, config, enabled);
William A. Kennington III80d29012022-11-12 02:31:40 -0800200 intf->loadNameServers(config);
201 intf->loadNTPServers(config);
202 auto ptr = intf.get();
William A. Kennington IIIf30d5602022-11-13 17:09:55 -0800203 interfaces.insert_or_assign(*info.intf.name, std::move(intf));
204 interfacesByIdx.insert_or_assign(info.intf.idx, ptr);
William A. Kennington III80d29012022-11-12 02:31:40 -0800205}
206
William A. Kennington III0813a242022-11-12 18:07:11 -0800207void Manager::addInterface(const InterfaceInfo& info)
208{
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800209 if (info.flags & IFF_LOOPBACK)
210 {
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800211 ignoredIntf.emplace(info.idx);
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800212 return;
213 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800214 if (info.name)
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800215 {
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800216 const auto& ignored = internal::getIgnoredInterfaces();
217 if (ignored.find(*info.name) != ignored.end())
218 {
219 static std::unordered_set<std::string> ignored;
220 if (!ignored.contains(*info.name))
221 {
222 ignored.emplace(*info.name);
223 auto msg = fmt::format("Ignoring interface {}\n", *info.name);
224 log<level::INFO>(msg.c_str());
225 }
226 ignoredIntf.emplace(info.idx);
227 return;
228 }
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800229 }
230
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800231 auto infoIt = intfInfo.find(info.idx);
232 if (infoIt != intfInfo.end())
William A. Kennington III0813a242022-11-12 18:07:11 -0800233 {
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800234 infoIt->second.intf = info;
William A. Kennington III0813a242022-11-12 18:07:11 -0800235 }
236 else
237 {
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800238 infoIt = std::get<0>(intfInfo.emplace(info.idx, AllIntfInfo{info}));
239 }
240
241 if (auto it = systemdNetworkdEnabled.find(info.idx);
242 it != systemdNetworkdEnabled.end())
243 {
244 createInterface(infoIt->second, it->second);
William A. Kennington III0813a242022-11-12 18:07:11 -0800245 }
246}
247
248void Manager::removeInterface(const InterfaceInfo& info)
249{
250 auto iit = interfacesByIdx.find(info.idx);
251 auto nit = interfaces.end();
252 if (info.name)
253 {
254 nit = interfaces.find(*info.name);
255 if (nit != interfaces.end() && iit != interfacesByIdx.end() &&
256 nit->second.get() != iit->second)
257 {
258 fmt::print(stderr, "Removed interface desync detected\n");
259 fflush(stderr);
260 std::abort();
261 }
262 }
263 else if (iit != interfacesByIdx.end())
264 {
265 for (nit = interfaces.begin(); nit != interfaces.end(); ++nit)
266 {
267 if (nit->second.get() == iit->second)
268 {
269 break;
270 }
271 }
272 }
273
274 if (iit != interfacesByIdx.end())
275 {
276 interfacesByIdx.erase(iit);
277 }
278 else
279 {
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800280 ignoredIntf.erase(info.idx);
William A. Kennington III0813a242022-11-12 18:07:11 -0800281 }
282 if (nit != interfaces.end())
283 {
284 interfaces.erase(nit);
285 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800286 intfInfo.erase(info.idx);
William A. Kennington III0813a242022-11-12 18:07:11 -0800287}
288
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800289void Manager::addAddress(const AddressInfo& info)
290{
William A. Kennington III57ca9612022-11-14 15:26:47 -0800291 if (info.flags & IFA_F_DEPRECATED)
292 {
293 return;
294 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800295 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
William A. Kennington III57ca9612022-11-14 15:26:47 -0800296 {
297 it->second.addrs.insert_or_assign(info.ifaddr, info);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800298 if (auto it = interfacesByIdx.find(info.ifidx);
299 it != interfacesByIdx.end())
300 {
301 it->second->addAddr(info);
302 }
William A. Kennington III57ca9612022-11-14 15:26:47 -0800303 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800304 else if (!ignoredIntf.contains(info.ifidx))
William A. Kennington III57ca9612022-11-14 15:26:47 -0800305 {
306 throw std::runtime_error(
307 fmt::format("Interface `{}` not found for addr", info.ifidx));
308 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800309}
310
311void Manager::removeAddress(const AddressInfo& info)
312{
William A. Kennington III57ca9612022-11-14 15:26:47 -0800313 if (auto it = interfacesByIdx.find(info.ifidx); it != interfacesByIdx.end())
314 {
315 it->second->addrs.erase(info.ifaddr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800316 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
317 {
318 it->second.addrs.erase(info.ifaddr);
319 }
William A. Kennington III57ca9612022-11-14 15:26:47 -0800320 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800321}
322
323void Manager::addNeighbor(const NeighborInfo& info)
324{
William A. Kennington III7310ac72022-11-14 15:44:00 -0800325 if (!(info.state & NUD_PERMANENT) || !info.addr)
326 {
327 return;
328 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800329 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
William A. Kennington III7310ac72022-11-14 15:44:00 -0800330 {
331 it->second.staticNeighs.insert_or_assign(*info.addr, info);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800332 if (auto it = interfacesByIdx.find(info.ifidx);
333 it != interfacesByIdx.end())
334 {
335 it->second->addStaticNeigh(info);
336 }
William A. Kennington III7310ac72022-11-14 15:44:00 -0800337 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800338 else if (!ignoredIntf.contains(info.ifidx))
William A. Kennington III7310ac72022-11-14 15:44:00 -0800339 {
340 throw std::runtime_error(
341 fmt::format("Interface `{}` not found for neigh", info.ifidx));
342 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800343}
344
345void Manager::removeNeighbor(const NeighborInfo& info)
346{
William A. Kennington III7310ac72022-11-14 15:44:00 -0800347 if (!info.addr)
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800348 {
William A. Kennington III7310ac72022-11-14 15:44:00 -0800349 return;
350 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800351 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
William A. Kennington III7310ac72022-11-14 15:44:00 -0800352 {
353 it->second.staticNeighs.erase(*info.addr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800354 if (auto it = interfacesByIdx.find(info.ifidx);
355 it != interfacesByIdx.end())
356 {
357 it->second->staticNeighbors.erase(*info.addr);
358 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800359 }
360}
361
362void Manager::addDefGw(unsigned ifidx, InAddrAny addr)
363{
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800364 if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800365 {
366 std::visit(
367 [&](auto addr) {
368 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
369 {
370 it->second.defgw4.emplace(addr);
371 }
372 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
373 {
374 it->second.defgw6.emplace(addr);
375 }
376 else
377 {
378 static_assert(!std::is_same_v<void, decltype(addr)>);
379 }
380 },
381 addr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800382 if (auto it = interfacesByIdx.find(ifidx); it != interfacesByIdx.end())
383 {
384 std::visit(
385 [&](auto addr) {
386 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
387 {
388 it->second->EthernetInterfaceIntf::defaultGateway(
389 std::to_string(addr));
390 }
391 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
392 {
393 it->second->EthernetInterfaceIntf::defaultGateway6(
394 std::to_string(addr));
395 }
396 else
397 {
398 static_assert(!std::is_same_v<void, decltype(addr)>);
399 }
400 },
401 addr);
402 }
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800403 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800404 else if (!ignoredIntf.contains(ifidx))
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800405 {
406 auto msg = fmt::format("Interface `{}` not found for gw", ifidx);
407 log<level::ERR>(msg.c_str(), entry("IFIDX=%u", ifidx));
408 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800409}
410
411void Manager::removeDefGw(unsigned ifidx, InAddrAny addr)
412{
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800413 if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800414 {
415 std::visit(
416 [&](auto addr) {
417 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
418 {
419 if (it->second.defgw4 == addr)
420 {
421 it->second.defgw4.reset();
422 }
423 }
424 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
425 {
426 if (it->second.defgw6 == addr)
427 {
428 it->second.defgw6.reset();
429 }
430 }
431 else
432 {
433 static_assert(!std::is_same_v<void, decltype(addr)>);
434 }
435 },
436 addr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800437 if (auto it = interfacesByIdx.find(ifidx); it != interfacesByIdx.end())
438 {
439 std::visit(
440 [&](auto addr) {
441 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
442 {
443 if (it->second->defaultGateway() ==
444 std::to_string(addr))
445 {
446 it->second->EthernetInterfaceIntf::defaultGateway(
447 "");
448 }
449 }
450 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
451 {
452 if (it->second->defaultGateway6() ==
453 std::to_string(addr))
454 {
455 it->second->EthernetInterfaceIntf::defaultGateway6(
456 "");
457 }
458 }
459 else
460 {
461 static_assert(!std::is_same_v<void, decltype(addr)>);
462 }
463 },
464 addr);
465 }
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800466 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800467}
468
William A. Kennington III085bbdc2022-10-05 02:45:37 -0700469ObjectPath Manager::vlan(std::string interfaceName, uint32_t id)
Ratan Gupta6811f822017-04-14 16:34:56 +0530470{
Jiaqing Zhaob685cb62022-04-12 22:57:34 +0800471 if (id == 0 || id >= 4095)
472 {
473 log<level::ERR>("VLAN ID is not valid", entry("VLANID=%u", id));
474 elog<InvalidArgument>(
475 Argument::ARGUMENT_NAME("VLANId"),
476 Argument::ARGUMENT_VALUE(std::to_string(id).c_str()));
477 }
478
William A. Kennington III96444792022-10-05 15:16:22 -0700479 auto it = interfaces.find(interfaceName);
480 if (it == interfaces.end())
481 {
482 using ResourceErr =
483 phosphor::logging::xyz::openbmc_project::Common::ResourceNotFound;
484 elog<ResourceNotFound>(ResourceErr::RESOURCE(interfaceName.c_str()));
485 }
486 return it->second->createVLAN(id);
Ratan Gupta6811f822017-04-14 16:34:56 +0530487}
488
Michael Tritz29f2fd62017-05-22 15:27:26 -0500489void Manager::reset()
490{
William A. Kennington III5b179382022-11-15 15:23:26 -0800491 for (const auto& dirent : std::filesystem::directory_iterator(confDir))
Michael Tritz29f2fd62017-05-22 15:27:26 -0500492 {
William A. Kennington III5b179382022-11-15 15:23:26 -0800493 std::error_code ec;
494 std::filesystem::remove(dirent.path(), ec);
Michael Tritz29f2fd62017-05-22 15:27:26 -0500495 }
William A. Kennington III5b179382022-11-15 15:23:26 -0800496 log<level::INFO>("Network data purged.");
Michael Tritz29f2fd62017-05-22 15:27:26 -0500497}
498
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530499// Need to merge the below function with the code which writes the
500// config file during factory reset.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500501// TODO openbmc/openbmc#1751
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530502void Manager::writeToConfigurationFile()
503{
504 // write all the static ip address in the systemd-network conf file
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530505 for (const auto& intf : interfaces)
506 {
Ratan Gupta2b106532017-07-25 16:05:02 +0530507 intf.second->writeConfigurationFile();
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530508 }
Ratan Guptae05083a2017-09-16 07:12:11 +0530509}
510
William A. Kennington III80d29012022-11-12 02:31:40 -0800511void Manager::handleAdminState(std::string_view state, unsigned ifidx)
512{
513 if (state == "initialized" || state == "linger")
514 {
515 systemdNetworkdEnabled.erase(ifidx);
516 }
517 else
518 {
519 bool managed = state != "unmanaged";
520 systemdNetworkdEnabled.insert_or_assign(ifidx, managed);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800521 if (auto it = interfacesByIdx.find(ifidx); it != interfacesByIdx.end())
William A. Kennington III80d29012022-11-12 02:31:40 -0800522 {
523 it->second->EthernetInterfaceIntf::nicEnabled(managed);
524 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800525 else if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
526 {
527 createInterface(it->second, managed);
528 }
William A. Kennington III80d29012022-11-12 02:31:40 -0800529 }
530}
531
Gunnar Mills57d9c502018-09-14 14:42:34 -0500532} // namespace network
533} // namespace phosphor