blob: 557e8269c8a11fd0d7dd8a296effbfca7a0d23e6 [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>
Patrick Venture189d44e2018-07-09 12:30:59 -070017#include <xyz/openbmc_project/Common/error.hpp>
Ratan Gupta6811f822017-04-14 16:34:56 +053018
William A. Kennington IIIf1aa51c2019-02-12 19:58:11 -080019constexpr char SYSTEMD_BUSNAME[] = "org.freedesktop.systemd1";
20constexpr char SYSTEMD_PATH[] = "/org/freedesktop/systemd1";
21constexpr char SYSTEMD_INTERFACE[] = "org.freedesktop.systemd1.Manager";
22
William A. Kennington III56ecc782021-10-07 18:44:50 -070023constexpr char NETWORKD_BUSNAME[] = "org.freedesktop.network1";
24constexpr char NETWORKD_PATH[] = "/org/freedesktop/network1";
25constexpr char NETWORKD_INTERFACE[] = "org.freedesktop.network1.Manager";
26
Ratan Gupta6811f822017-04-14 16:34:56 +053027namespace phosphor
28{
29namespace network
30{
Ratan Gupta82549cc2017-04-21 08:45:23 +053031
Ratan Gupta6811f822017-04-14 16:34:56 +053032using namespace phosphor::logging;
Ratan Guptaef85eb92017-06-15 08:57:54 +053033using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Jiaqing Zhaob685cb62022-04-12 22:57:34 +080034using Argument = xyz::openbmc_project::Common::InvalidArgument;
Ratan Gupta6811f822017-04-14 16:34:56 +053035
William A. Kennington III80d29012022-11-12 02:31:40 -080036static constexpr const char enabledMatch[] =
37 "type='signal',sender='org.freedesktop.network1',path_namespace='/org/"
38 "freedesktop/network1/"
39 "link',interface='org.freedesktop.DBus.Properties',member='"
40 "PropertiesChanged',arg0='org.freedesktop.network1.Link',";
41
William A. Kennington IIIde70ccf2022-11-20 17:18:01 -080042Manager::Manager(sdbusplus::bus_t& bus, DelayedExecutor& reload,
43 stdplus::zstring_view objPath,
William A. Kennington III5b179382022-11-15 15:23:26 -080044 const std::filesystem::path& confDir) :
William A. Kennington IIIde70ccf2022-11-20 17:18:01 -080045 ManagerIface(bus, objPath.c_str(), ManagerIface::action::defer_emit),
46 reload(reload), bus(bus), objPath(std::string(objPath)), confDir(confDir),
William A. Kennington III80d29012022-11-12 02:31:40 -080047 systemdNetworkdEnabledMatch(
48 bus, enabledMatch, [&](sdbusplus::message_t& m) {
49 std::string intf;
50 std::unordered_map<std::string, std::variant<std::string>> values;
51 try
52 {
53 m.read(intf, values);
54 auto it = values.find("AdministrativeState");
55 if (it == values.end())
56 {
57 return;
58 }
59 const std::string_view obj = m.get_path();
60 auto sep = obj.rfind('/');
61 if (sep == obj.npos || sep + 3 > obj.size())
62 {
63 throw std::invalid_argument("Invalid obj path");
64 }
65 auto ifidx = DecodeInt<unsigned, 10>{}(obj.substr(sep + 3));
66 const auto& state = std::get<std::string>(it->second);
67 handleAdminState(state, ifidx);
68 }
69 catch (const std::exception& e)
70 {
71 log<level::ERR>(
72 fmt::format("AdministrativeState match parsing failed: {}",
73 e.what())
74 .c_str(),
75 entry("ERROR=%s", e.what()));
76 }
77 })
Ratan Gupta6811f822017-04-14 16:34:56 +053078{
William A. Kennington IIIde70ccf2022-11-20 17:18:01 -080079 reload.setCallback([&]() {
80 for (auto& hook : reloadPreHooks)
81 {
82 try
83 {
84 hook();
85 }
86 catch (const std::exception& ex)
87 {
88 log<level::ERR>("Failed executing reload hook, ignoring",
89 entry("ERR=%s", ex.what()));
90 }
91 }
92 reloadPreHooks.clear();
93 try
94 {
95 auto method = bus.new_method_call(NETWORKD_BUSNAME, NETWORKD_PATH,
96 NETWORKD_INTERFACE, "Reload");
97 bus.call_noreply(method);
98 log<level::INFO>("Reloaded systemd-networkd");
99 }
100 catch (const sdbusplus::exception_t& ex)
101 {
102 log<level::ERR>("Failed to reload configuration",
103 entry("ERR=%s", ex.what()));
104 reloadPostHooks.clear();
105 }
106 for (auto& hook : reloadPostHooks)
107 {
108 try
109 {
110 hook();
111 }
112 catch (const std::exception& ex)
113 {
114 log<level::ERR>("Failed executing reload hook, ignoring",
115 entry("ERR=%s", ex.what()));
116 }
117 }
118 reloadPostHooks.clear();
119 });
William A. Kennington III80d29012022-11-12 02:31:40 -0800120 std::vector<
121 std::tuple<int32_t, std::string, sdbusplus::message::object_path>>
122 links;
123 try
124 {
125 auto rsp =
126 bus.new_method_call("org.freedesktop.network1",
127 "/org/freedesktop/network1",
128 "org.freedesktop.network1.Manager", "ListLinks")
129 .call();
130 rsp.read(links);
131 }
132 catch (const sdbusplus::exception::SdBusError& e)
133 {
134 // Any failures are systemd-network not being ready
135 }
136 for (const auto& link : links)
137 {
138 unsigned ifidx = std::get<0>(link);
139 auto obj = fmt::format("/org/freedesktop/network1/link/_3{}", ifidx);
140 auto req =
141 bus.new_method_call("org.freedesktop.network1", obj.c_str(),
142 "org.freedesktop.DBus.Properties", "Get");
143 req.append("org.freedesktop.network1.Link", "AdministrativeState");
144 auto rsp = req.call();
145 std::variant<std::string> val;
146 rsp.read(val);
147 handleAdminState(std::get<std::string>(val), ifidx);
148 }
Ratan Guptaef85eb92017-06-15 08:57:54 +0530149
William A. Kennington III5b179382022-11-15 15:23:26 -0800150 std::filesystem::create_directories(confDir);
151 systemConf = std::make_unique<phosphor::network::SystemConfiguration>(
152 bus, (this->objPath / "config").str);
153 dhcpConf = std::make_unique<phosphor::network::dhcp::Configuration>(
154 bus, (this->objPath / "dhcp").str, *this);
Ratan Gupta29b0e432017-05-25 12:51:40 +0530155}
156
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800157void Manager::createInterface(const AllIntfInfo& info, bool enabled)
William A. Kennington III80d29012022-11-12 02:31:40 -0800158{
William A. Kennington III93f5c6d2022-11-17 16:23:44 -0800159 if (ignoredIntf.find(info.intf.idx) != ignoredIntf.end())
160 {
161 return;
162 }
William A. Kennington III5b179382022-11-15 15:23:26 -0800163 if (auto it = interfacesByIdx.find(info.intf.idx);
164 it != interfacesByIdx.end())
165 {
William A. Kennington III5b179382022-11-15 15:23:26 -0800166 if (info.intf.name && *info.intf.name != it->second->interfaceName())
167 {
William A. Kennington IIIbf290462022-11-15 19:44:25 -0800168 interfaces.erase(it->second->interfaceName());
169 interfacesByIdx.erase(it);
William A. Kennington III5b179382022-11-15 15:23:26 -0800170 }
William A. Kennington IIIbf290462022-11-15 19:44:25 -0800171 else
172 {
173 it->second->updateInfo(info.intf);
174 return;
175 }
William A. Kennington III5b179382022-11-15 15:23:26 -0800176 }
William A. Kennington III876927c2022-11-17 16:20:15 -0800177 else if (info.intf.name)
178 {
179 auto it = interfaces.find(*info.intf.name);
180 if (it != interfaces.end())
181 {
182 it->second->updateInfo(info.intf);
183 return;
184 }
185 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800186 if (!info.intf.name)
187 {
188 auto msg = fmt::format("Can't create interface without name: {}",
189 info.intf.idx);
190 log<level::ERR>(msg.c_str(), entry("IFIDX=%u", info.intf.idx));
191 return;
192 }
William A. Kennington IIIf30d5602022-11-13 17:09:55 -0800193 config::Parser config(config::pathForIntfConf(confDir, *info.intf.name));
William A. Kennington III80d29012022-11-12 02:31:40 -0800194 auto intf = std::make_unique<EthernetInterface>(
William A. Kennington III13d665c2022-11-15 20:34:40 -0800195 bus, *this, info, objPath.str, config, enabled);
William A. Kennington III80d29012022-11-12 02:31:40 -0800196 intf->loadNameServers(config);
197 intf->loadNTPServers(config);
198 auto ptr = intf.get();
William A. Kennington IIIf30d5602022-11-13 17:09:55 -0800199 interfaces.insert_or_assign(*info.intf.name, std::move(intf));
200 interfacesByIdx.insert_or_assign(info.intf.idx, ptr);
William A. Kennington III80d29012022-11-12 02:31:40 -0800201}
202
William A. Kennington III0813a242022-11-12 18:07:11 -0800203void Manager::addInterface(const InterfaceInfo& info)
204{
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800205 if (info.flags & IFF_LOOPBACK)
206 {
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800207 ignoredIntf.emplace(info.idx);
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800208 return;
209 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800210 if (info.name)
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800211 {
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800212 const auto& ignored = internal::getIgnoredInterfaces();
213 if (ignored.find(*info.name) != ignored.end())
214 {
215 static std::unordered_set<std::string> ignored;
216 if (!ignored.contains(*info.name))
217 {
218 ignored.emplace(*info.name);
219 auto msg = fmt::format("Ignoring interface {}\n", *info.name);
220 log<level::INFO>(msg.c_str());
221 }
222 ignoredIntf.emplace(info.idx);
223 return;
224 }
William A. Kennington IIIb8006122022-11-13 18:15:15 -0800225 }
226
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800227 auto infoIt = intfInfo.find(info.idx);
228 if (infoIt != intfInfo.end())
William A. Kennington III0813a242022-11-12 18:07:11 -0800229 {
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800230 infoIt->second.intf = info;
William A. Kennington III0813a242022-11-12 18:07:11 -0800231 }
232 else
233 {
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800234 infoIt = std::get<0>(intfInfo.emplace(info.idx, AllIntfInfo{info}));
235 }
236
237 if (auto it = systemdNetworkdEnabled.find(info.idx);
238 it != systemdNetworkdEnabled.end())
239 {
240 createInterface(infoIt->second, it->second);
William A. Kennington III0813a242022-11-12 18:07:11 -0800241 }
242}
243
244void Manager::removeInterface(const InterfaceInfo& info)
245{
246 auto iit = interfacesByIdx.find(info.idx);
247 auto nit = interfaces.end();
248 if (info.name)
249 {
250 nit = interfaces.find(*info.name);
251 if (nit != interfaces.end() && iit != interfacesByIdx.end() &&
252 nit->second.get() != iit->second)
253 {
254 fmt::print(stderr, "Removed interface desync detected\n");
255 fflush(stderr);
256 std::abort();
257 }
258 }
259 else if (iit != interfacesByIdx.end())
260 {
261 for (nit = interfaces.begin(); nit != interfaces.end(); ++nit)
262 {
263 if (nit->second.get() == iit->second)
264 {
265 break;
266 }
267 }
268 }
269
270 if (iit != interfacesByIdx.end())
271 {
272 interfacesByIdx.erase(iit);
273 }
274 else
275 {
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800276 ignoredIntf.erase(info.idx);
William A. Kennington III0813a242022-11-12 18:07:11 -0800277 }
278 if (nit != interfaces.end())
279 {
280 interfaces.erase(nit);
281 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800282 intfInfo.erase(info.idx);
William A. Kennington III0813a242022-11-12 18:07:11 -0800283}
284
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800285void Manager::addAddress(const AddressInfo& info)
286{
William A. Kennington III57ca9612022-11-14 15:26:47 -0800287 if (info.flags & IFA_F_DEPRECATED)
288 {
289 return;
290 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800291 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
William A. Kennington III57ca9612022-11-14 15:26:47 -0800292 {
293 it->second.addrs.insert_or_assign(info.ifaddr, info);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800294 if (auto it = interfacesByIdx.find(info.ifidx);
295 it != interfacesByIdx.end())
296 {
297 it->second->addAddr(info);
298 }
William A. Kennington III57ca9612022-11-14 15:26:47 -0800299 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800300 else if (!ignoredIntf.contains(info.ifidx))
William A. Kennington III57ca9612022-11-14 15:26:47 -0800301 {
302 throw std::runtime_error(
303 fmt::format("Interface `{}` not found for addr", info.ifidx));
304 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800305}
306
307void Manager::removeAddress(const AddressInfo& info)
308{
William A. Kennington III57ca9612022-11-14 15:26:47 -0800309 if (auto it = interfacesByIdx.find(info.ifidx); it != interfacesByIdx.end())
310 {
311 it->second->addrs.erase(info.ifaddr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800312 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
313 {
314 it->second.addrs.erase(info.ifaddr);
315 }
William A. Kennington III57ca9612022-11-14 15:26:47 -0800316 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800317}
318
319void Manager::addNeighbor(const NeighborInfo& info)
320{
William A. Kennington III7310ac72022-11-14 15:44:00 -0800321 if (!(info.state & NUD_PERMANENT) || !info.addr)
322 {
323 return;
324 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800325 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
William A. Kennington III7310ac72022-11-14 15:44:00 -0800326 {
327 it->second.staticNeighs.insert_or_assign(*info.addr, info);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800328 if (auto it = interfacesByIdx.find(info.ifidx);
329 it != interfacesByIdx.end())
330 {
331 it->second->addStaticNeigh(info);
332 }
William A. Kennington III7310ac72022-11-14 15:44:00 -0800333 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800334 else if (!ignoredIntf.contains(info.ifidx))
William A. Kennington III7310ac72022-11-14 15:44:00 -0800335 {
336 throw std::runtime_error(
337 fmt::format("Interface `{}` not found for neigh", info.ifidx));
338 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800339}
340
341void Manager::removeNeighbor(const NeighborInfo& info)
342{
William A. Kennington III7310ac72022-11-14 15:44:00 -0800343 if (!info.addr)
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800344 {
William A. Kennington III7310ac72022-11-14 15:44:00 -0800345 return;
346 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800347 if (auto it = intfInfo.find(info.ifidx); it != intfInfo.end())
William A. Kennington III7310ac72022-11-14 15:44:00 -0800348 {
349 it->second.staticNeighs.erase(*info.addr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800350 if (auto it = interfacesByIdx.find(info.ifidx);
351 it != interfacesByIdx.end())
352 {
353 it->second->staticNeighbors.erase(*info.addr);
354 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800355 }
356}
357
358void Manager::addDefGw(unsigned ifidx, InAddrAny addr)
359{
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800360 if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800361 {
362 std::visit(
363 [&](auto addr) {
364 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
365 {
366 it->second.defgw4.emplace(addr);
367 }
368 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
369 {
370 it->second.defgw6.emplace(addr);
371 }
372 else
373 {
374 static_assert(!std::is_same_v<void, decltype(addr)>);
375 }
376 },
377 addr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800378 if (auto it = interfacesByIdx.find(ifidx); it != interfacesByIdx.end())
379 {
380 std::visit(
381 [&](auto addr) {
382 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
383 {
384 it->second->EthernetInterfaceIntf::defaultGateway(
385 std::to_string(addr));
386 }
387 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
388 {
389 it->second->EthernetInterfaceIntf::defaultGateway6(
390 std::to_string(addr));
391 }
392 else
393 {
394 static_assert(!std::is_same_v<void, decltype(addr)>);
395 }
396 },
397 addr);
398 }
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800399 }
William A. Kennington III3ee5b7e2022-11-15 15:04:37 -0800400 else if (!ignoredIntf.contains(ifidx))
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800401 {
402 auto msg = fmt::format("Interface `{}` not found for gw", ifidx);
403 log<level::ERR>(msg.c_str(), entry("IFIDX=%u", ifidx));
404 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800405}
406
407void Manager::removeDefGw(unsigned ifidx, InAddrAny addr)
408{
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800409 if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800410 {
411 std::visit(
412 [&](auto addr) {
413 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
414 {
415 if (it->second.defgw4 == addr)
416 {
417 it->second.defgw4.reset();
418 }
419 }
420 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
421 {
422 if (it->second.defgw6 == addr)
423 {
424 it->second.defgw6.reset();
425 }
426 }
427 else
428 {
429 static_assert(!std::is_same_v<void, decltype(addr)>);
430 }
431 },
432 addr);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800433 if (auto it = interfacesByIdx.find(ifidx); it != interfacesByIdx.end())
434 {
435 std::visit(
436 [&](auto addr) {
437 if constexpr (std::is_same_v<in_addr, decltype(addr)>)
438 {
439 if (it->second->defaultGateway() ==
440 std::to_string(addr))
441 {
442 it->second->EthernetInterfaceIntf::defaultGateway(
443 "");
444 }
445 }
446 else if constexpr (std::is_same_v<in6_addr, decltype(addr)>)
447 {
448 if (it->second->defaultGateway6() ==
449 std::to_string(addr))
450 {
451 it->second->EthernetInterfaceIntf::defaultGateway6(
452 "");
453 }
454 }
455 else
456 {
457 static_assert(!std::is_same_v<void, decltype(addr)>);
458 }
459 },
460 addr);
461 }
William A. Kennington IIIbb9e9092022-11-14 15:58:02 -0800462 }
William A. Kennington IIIed5ff472022-11-12 16:24:02 -0800463}
464
William A. Kennington III085bbdc2022-10-05 02:45:37 -0700465ObjectPath Manager::vlan(std::string interfaceName, uint32_t id)
Ratan Gupta6811f822017-04-14 16:34:56 +0530466{
Jiaqing Zhaob685cb62022-04-12 22:57:34 +0800467 if (id == 0 || id >= 4095)
468 {
469 log<level::ERR>("VLAN ID is not valid", entry("VLANID=%u", id));
470 elog<InvalidArgument>(
471 Argument::ARGUMENT_NAME("VLANId"),
472 Argument::ARGUMENT_VALUE(std::to_string(id).c_str()));
473 }
474
William A. Kennington III96444792022-10-05 15:16:22 -0700475 auto it = interfaces.find(interfaceName);
476 if (it == interfaces.end())
477 {
478 using ResourceErr =
479 phosphor::logging::xyz::openbmc_project::Common::ResourceNotFound;
480 elog<ResourceNotFound>(ResourceErr::RESOURCE(interfaceName.c_str()));
481 }
482 return it->second->createVLAN(id);
Ratan Gupta6811f822017-04-14 16:34:56 +0530483}
484
Michael Tritz29f2fd62017-05-22 15:27:26 -0500485void Manager::reset()
486{
William A. Kennington III5b179382022-11-15 15:23:26 -0800487 for (const auto& dirent : std::filesystem::directory_iterator(confDir))
Michael Tritz29f2fd62017-05-22 15:27:26 -0500488 {
William A. Kennington III5b179382022-11-15 15:23:26 -0800489 std::error_code ec;
490 std::filesystem::remove(dirent.path(), ec);
Michael Tritz29f2fd62017-05-22 15:27:26 -0500491 }
William A. Kennington III5b179382022-11-15 15:23:26 -0800492 log<level::INFO>("Network data purged.");
Michael Tritz29f2fd62017-05-22 15:27:26 -0500493}
494
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530495// Need to merge the below function with the code which writes the
496// config file during factory reset.
Gunnar Mills57d9c502018-09-14 14:42:34 -0500497// TODO openbmc/openbmc#1751
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530498void Manager::writeToConfigurationFile()
499{
500 // write all the static ip address in the systemd-network conf file
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530501 for (const auto& intf : interfaces)
502 {
Ratan Gupta2b106532017-07-25 16:05:02 +0530503 intf.second->writeConfigurationFile();
Ratan Gupta4f1c18b2017-05-25 12:59:35 +0530504 }
Ratan Guptae05083a2017-09-16 07:12:11 +0530505}
506
William A. Kennington III80d29012022-11-12 02:31:40 -0800507void Manager::handleAdminState(std::string_view state, unsigned ifidx)
508{
509 if (state == "initialized" || state == "linger")
510 {
511 systemdNetworkdEnabled.erase(ifidx);
512 }
513 else
514 {
515 bool managed = state != "unmanaged";
516 systemdNetworkdEnabled.insert_or_assign(ifidx, managed);
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800517 if (auto it = interfacesByIdx.find(ifidx); it != interfacesByIdx.end())
William A. Kennington III80d29012022-11-12 02:31:40 -0800518 {
519 it->second->EthernetInterfaceIntf::nicEnabled(managed);
520 }
William A. Kennington III2fb0c872022-11-15 19:35:39 -0800521 else if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
522 {
523 createInterface(it->second, managed);
524 }
William A. Kennington III80d29012022-11-12 02:31:40 -0800525 }
526}
527
Gunnar Mills57d9c502018-09-14 14:42:34 -0500528} // namespace network
529} // namespace phosphor