blob: cdb65512118b69f194d8dc42856b3677fe0f0da0 [file] [log] [blame]
Qiang XUe28d1fa2019-02-27 13:50:56 +08001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
Andrew Jefferye73bd0a2023-01-25 10:39:57 +103017#include "ChassisIntrusionSensor.hpp"
18#include "Utils.hpp"
19
Ed Tanous1f978632023-02-28 18:16:39 -080020#include <boost/asio/io_context.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070021#include <boost/container/flat_map.hpp>
Patrick Williams0c42f402021-08-27 16:05:45 -050022#include <phosphor-logging/lg2.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +080023#include <sdbusplus/asio/connection.hpp>
24#include <sdbusplus/asio/object_server.hpp>
25#include <sdbusplus/asio/sd_event.hpp>
26#include <sdbusplus/bus.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070027#include <sdbusplus/bus/match.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +080028#include <sdbusplus/exception.hpp>
29#include <sdbusplus/server.hpp>
30#include <sdbusplus/timer.hpp>
James Feist38fb5982020-05-28 10:09:54 -070031
32#include <array>
Ed Tanous8a57ec02020-10-09 12:46:52 -070033#include <charconv>
James Feist38fb5982020-05-28 10:09:54 -070034#include <chrono>
35#include <ctime>
36#include <fstream>
37#include <functional>
38#include <iostream>
39#include <memory>
Patrick Venture96e97db2019-10-31 13:44:38 -070040#include <stdexcept>
41#include <string>
42#include <utility>
43#include <vector>
Qiang XUe28d1fa2019-02-27 13:50:56 +080044
Ed Tanous8a57ec02020-10-09 12:46:52 -070045static constexpr bool debug = false;
Qiang XUe28d1fa2019-02-27 13:50:56 +080046
Zev Weiss054aad82022-08-18 01:37:34 -070047static constexpr const char* sensorType = "ChassisIntrusionSensor";
48static constexpr const char* nicType = "NIC";
Brandon Kim66558232021-11-09 16:53:08 -080049static constexpr auto nicTypes{std::to_array<const char*>({nicType})};
Qiang XUe28d1fa2019-02-27 13:50:56 +080050
Qiang XU88b7f282019-08-14 22:51:43 +080051namespace fs = std::filesystem;
52
Qiang XUe28d1fa2019-02-27 13:50:56 +080053static bool getIntrusionSensorConfig(
Lei YUba637932021-03-17 10:35:00 +080054 const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080055 IntrusionSensorType* pType, int* pBusId, int* pSlaveAddr,
Qiang XUe28d1fa2019-02-27 13:50:56 +080056 bool* pGpioInverted)
57{
58 // find matched configuration according to sensor type
59 ManagedObjectType sensorConfigurations;
60 bool useCache = false;
61
62 if (!getSensorConfiguration(sensorType, dbusConnection,
63 sensorConfigurations, useCache))
64 {
65 std::cerr << "error communicating to entity manager\n";
66 return false;
67 }
68
69 const SensorData* sensorData = nullptr;
Zev Weissafd15042022-07-18 12:28:40 -070070 const std::pair<std::string, SensorBaseConfigMap>* baseConfiguration =
71 nullptr;
Qiang XUe28d1fa2019-02-27 13:50:56 +080072
73 // Get bus and addr of matched configuration
Zev Weissf343b8a2022-08-12 18:21:01 -070074 for (const auto& [path, cfgData] : sensorConfigurations)
Qiang XUe28d1fa2019-02-27 13:50:56 +080075 {
76 baseConfiguration = nullptr;
Zev Weissf343b8a2022-08-12 18:21:01 -070077 sensorData = &cfgData;
Qiang XUe28d1fa2019-02-27 13:50:56 +080078
79 // match sensor type
Zev Weiss054aad82022-08-18 01:37:34 -070080 auto sensorBase = sensorData->find(configInterfaceName(sensorType));
Qiang XUe28d1fa2019-02-27 13:50:56 +080081 if (sensorBase == sensorData->end())
82 {
83 std::cerr << "error finding base configuration \n";
84 continue;
85 }
86
87 baseConfiguration = &(*sensorBase);
88
89 // judge class, "Gpio" or "I2C"
90 auto findClass = baseConfiguration->second.find("Class");
91 if (findClass != baseConfiguration->second.end() &&
Patrick Williams94733252020-05-13 11:44:58 -050092 std::get<std::string>(findClass->second) == "Gpio")
Qiang XUe28d1fa2019-02-27 13:50:56 +080093 {
94 *pType = IntrusionSensorType::gpio;
95 }
96 else
97 {
98 *pType = IntrusionSensorType::pch;
99 }
100
101 // case to find GPIO info
102 if (*pType == IntrusionSensorType::gpio)
103 {
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800104 auto findGpioPolarity =
105 baseConfiguration->second.find("GpioPolarity");
Qiang XUe28d1fa2019-02-27 13:50:56 +0800106
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800107 if (findGpioPolarity == baseConfiguration->second.end())
Qiang XUe28d1fa2019-02-27 13:50:56 +0800108 {
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800109 std::cerr << "error finding gpio polarity in configuration \n";
Qiang XUe28d1fa2019-02-27 13:50:56 +0800110 continue;
111 }
112
113 try
114 {
Qiang XUe28d1fa2019-02-27 13:50:56 +0800115 *pGpioInverted =
Patrick Williams94733252020-05-13 11:44:58 -0500116 (std::get<std::string>(findGpioPolarity->second) == "Low");
Qiang XUe28d1fa2019-02-27 13:50:56 +0800117 }
118 catch (const std::bad_variant_access& e)
119 {
120 std::cerr << "invalid value for gpio info in config. \n";
121 continue;
122 }
123
Ed Tanous8a57ec02020-10-09 12:46:52 -0700124 if (debug)
Qiang XUe28d1fa2019-02-27 13:50:56 +0800125 {
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800126 std::cout << "find chassis intrusion sensor polarity inverted "
127 "flag is "
128 << *pGpioInverted << "\n";
Qiang XUe28d1fa2019-02-27 13:50:56 +0800129 }
130
131 return true;
132 }
133
134 // case to find I2C info
Ed Tanous8a57ec02020-10-09 12:46:52 -0700135 if (*pType == IntrusionSensorType::pch)
Qiang XUe28d1fa2019-02-27 13:50:56 +0800136 {
137 auto findBus = baseConfiguration->second.find("Bus");
138 auto findAddress = baseConfiguration->second.find("Address");
139 if (findBus == baseConfiguration->second.end() ||
140 findAddress == baseConfiguration->second.end())
141 {
142 std::cerr << "error finding bus or address in configuration \n";
143 continue;
144 }
145
146 try
147 {
Patrick Williams94733252020-05-13 11:44:58 -0500148 *pBusId = std::get<uint64_t>(findBus->second);
149 *pSlaveAddr = std::get<uint64_t>(findAddress->second);
Qiang XUe28d1fa2019-02-27 13:50:56 +0800150 }
151 catch (const std::bad_variant_access& e)
152 {
153 std::cerr << "invalid value for bus or address in config. \n";
154 continue;
155 }
156
Ed Tanous8a57ec02020-10-09 12:46:52 -0700157 if (debug)
Qiang XUe28d1fa2019-02-27 13:50:56 +0800158 {
159 std::cout << "find matched bus " << *pBusId
160 << ", matched slave addr " << *pSlaveAddr << "\n";
161 }
162 return true;
163 }
164 }
165
Qiang XU74ddf862019-09-12 17:12:13 +0800166 std::cerr << "can't find matched I2C or GPIO configuration for intrusion "
167 "sensor. \n";
Qiang XUe28d1fa2019-02-27 13:50:56 +0800168 *pBusId = -1;
169 *pSlaveAddr = -1;
Qiang XUe28d1fa2019-02-27 13:50:56 +0800170 return false;
171}
172
Qiang XU88b7f282019-08-14 22:51:43 +0800173static constexpr bool debugLanLeash = false;
174boost::container::flat_map<int, bool> lanStatusMap;
Qiang XU74ddf862019-09-12 17:12:13 +0800175boost::container::flat_map<int, std::string> lanInfoMap;
Qiang XU88b7f282019-08-14 22:51:43 +0800176boost::container::flat_map<std::string, int> pathSuffixMap;
177
Lei YUba637932021-03-17 10:35:00 +0800178static void getNicNameInfo(
179 const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
Qiang XU74ddf862019-09-12 17:12:13 +0800180{
181 auto getter = std::make_shared<GetSensorConfiguration>(
Zev Weissafd15042022-07-18 12:28:40 -0700182 dbusConnection, [](const ManagedObjectType& sensorConfigurations) {
183 // Get NIC name and save to map
184 lanInfoMap.clear();
Zev Weissf343b8a2022-08-12 18:21:01 -0700185 for (const auto& [path, cfgData] : sensorConfigurations)
Qiang XU74ddf862019-09-12 17:12:13 +0800186 {
Zev Weissafd15042022-07-18 12:28:40 -0700187 const std::pair<std::string, SensorBaseConfigMap>*
188 baseConfiguration = nullptr;
Qiang XU74ddf862019-09-12 17:12:13 +0800189
Zev Weissafd15042022-07-18 12:28:40 -0700190 // find base configuration
Zev Weiss054aad82022-08-18 01:37:34 -0700191 auto sensorBase = cfgData.find(configInterfaceName(nicType));
Zev Weissf343b8a2022-08-12 18:21:01 -0700192 if (sensorBase == cfgData.end())
Qiang XU74ddf862019-09-12 17:12:13 +0800193 {
Zev Weissafd15042022-07-18 12:28:40 -0700194 continue;
195 }
196 baseConfiguration = &(*sensorBase);
197
198 auto findEthIndex = baseConfiguration->second.find("EthIndex");
199 auto findName = baseConfiguration->second.find("Name");
200
201 if (findEthIndex != baseConfiguration->second.end() &&
202 findName != baseConfiguration->second.end())
203 {
204 const auto* pEthIndex =
205 std::get_if<uint64_t>(&findEthIndex->second);
206 const auto* pName =
207 std::get_if<std::string>(&findName->second);
208 if (pEthIndex != nullptr && pName != nullptr)
Qiang XU74ddf862019-09-12 17:12:13 +0800209 {
Zev Weissafd15042022-07-18 12:28:40 -0700210 lanInfoMap[*pEthIndex] = *pName;
211 if (debugLanLeash)
212 {
213 std::cout << "find name of eth" << *pEthIndex
214 << " is " << *pName << "\n";
215 }
Qiang XU74ddf862019-09-12 17:12:13 +0800216 }
217 }
218 }
219
Zev Weissafd15042022-07-18 12:28:40 -0700220 if (lanInfoMap.empty())
221 {
222 std::cerr << "can't find matched NIC name. \n";
223 }
Ed Tanous8a17c302021-09-02 15:07:11 -0700224 });
Qiang XU74ddf862019-09-12 17:12:13 +0800225
226 getter->getConfiguration(
227 std::vector<std::string>{nicTypes.begin(), nicTypes.end()});
228}
229
Patrick Williams92f8f512022-07-22 19:26:55 -0500230static void processLanStatusChange(sdbusplus::message_t& message)
Qiang XU88b7f282019-08-14 22:51:43 +0800231{
232 const std::string& pathName = message.get_path();
233 std::string interfaceName;
Zev Weissafd15042022-07-18 12:28:40 -0700234 SensorBaseConfigMap properties;
Qiang XU88b7f282019-08-14 22:51:43 +0800235 message.read(interfaceName, properties);
236
237 auto findStateProperty = properties.find("OperationalState");
238 if (findStateProperty == properties.end())
239 {
240 return;
241 }
Qiang XU74ddf862019-09-12 17:12:13 +0800242 std::string* pState =
243 std::get_if<std::string>(&(findStateProperty->second));
Qiang XU88b7f282019-08-14 22:51:43 +0800244 if (pState == nullptr)
245 {
246 std::cerr << "invalid OperationalState \n";
247 return;
248 }
249
250 bool newLanConnected = (*pState == "routable" || *pState == "carrier" ||
251 *pState == "degraded");
252
253 // get ethNum from path. /org/freedesktop/network1/link/_32 for eth0
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500254 size_t pos = pathName.find("/_");
Qiang XU88b7f282019-08-14 22:51:43 +0800255 if (pos == std::string::npos || pathName.length() <= pos + 2)
256 {
257 std::cerr << "unexpected path name " << pathName << "\n";
258 return;
259 }
260 std::string suffixStr = pathName.substr(pos + 2);
261
262 auto findEthNum = pathSuffixMap.find(suffixStr);
263 if (findEthNum == pathSuffixMap.end())
264 {
265 std::cerr << "unexpected eth for suffixStr " << suffixStr << "\n";
266 return;
267 }
268 int ethNum = findEthNum->second;
Qiang XU74ddf862019-09-12 17:12:13 +0800269
270 // get lan status from map
Qiang XU88b7f282019-08-14 22:51:43 +0800271 auto findLanStatus = lanStatusMap.find(ethNum);
272 if (findLanStatus == lanStatusMap.end())
273 {
274 std::cerr << "unexpected eth " << ethNum << " in lanStatusMap \n";
275 return;
276 }
277 bool oldLanConnected = findLanStatus->second;
278
Qiang XU74ddf862019-09-12 17:12:13 +0800279 // get lan info from map
Ed Tanous2049bd22022-07-09 07:20:26 -0700280 std::string lanInfo;
281 if (!lanInfoMap.empty())
Qiang XU74ddf862019-09-12 17:12:13 +0800282 {
283 auto findLanInfo = lanInfoMap.find(ethNum);
284 if (findLanInfo == lanInfoMap.end())
285 {
286 std::cerr << "unexpected eth " << ethNum << " in lanInfoMap \n";
287 }
288 else
289 {
290 lanInfo = "(" + findLanInfo->second + ")";
291 }
292 }
293
Qiang XU88b7f282019-08-14 22:51:43 +0800294 if (debugLanLeash)
295 {
296 std::cout << "ethNum = " << ethNum << ", state = " << *pState
297 << ", oldLanConnected = "
298 << (oldLanConnected ? "true" : "false")
299 << ", newLanConnected = "
300 << (newLanConnected ? "true" : "false") << "\n";
301 }
302
303 if (oldLanConnected != newLanConnected)
304 {
Qiang XU74ddf862019-09-12 17:12:13 +0800305 std::string strEthNum = "eth" + std::to_string(ethNum) + lanInfo;
Ed Tanous2049bd22022-07-09 07:20:26 -0700306 const auto* strState = newLanConnected ? "connected" : "lost";
307 const auto* strMsgId =
Qiang XU74ddf862019-09-12 17:12:13 +0800308 newLanConnected ? "OpenBMC.0.1.LanRegained" : "OpenBMC.0.1.LanLost";
Patrick Williams0c42f402021-08-27 16:05:45 -0500309
310 lg2::info("{ETHDEV} LAN leash {STATE}", "ETHDEV", strEthNum, "STATE",
311 strState, "REDFISH_MESSAGE_ID", strMsgId,
312 "REDFISH_MESSAGE_ARGS", strEthNum);
313
Qiang XU88b7f282019-08-14 22:51:43 +0800314 lanStatusMap[ethNum] = newLanConnected;
Qiang XU88b7f282019-08-14 22:51:43 +0800315 }
316}
317
Lei YUdd68d4a2021-03-16 22:17:23 +0800318/** @brief Initialize the lan status.
319 *
320 * @return true on success and false on failure
321 */
Lei YUba637932021-03-17 10:35:00 +0800322static bool initializeLanStatus(
323 const std::shared_ptr<sdbusplus::asio::connection>& conn)
Qiang XU88b7f282019-08-14 22:51:43 +0800324{
Qiang XU74ddf862019-09-12 17:12:13 +0800325 // init lan port name from configuration
326 getNicNameInfo(conn);
327
328 // get eth info from sysfs
Qiang XU88b7f282019-08-14 22:51:43 +0800329 std::vector<fs::path> files;
330 if (!findFiles(fs::path("/sys/class/net/"), R"(eth\d+/ifindex)", files))
331 {
332 std::cerr << "No eth in system\n";
Lei YUdd68d4a2021-03-16 22:17:23 +0800333 return false;
Qiang XU88b7f282019-08-14 22:51:43 +0800334 }
335
336 // iterate through all found eth files, and save ifindex
Ed Tanous8a57ec02020-10-09 12:46:52 -0700337 for (const fs::path& fileName : files)
Qiang XU88b7f282019-08-14 22:51:43 +0800338 {
339 if (debugLanLeash)
340 {
341 std::cout << "Reading " << fileName << "\n";
342 }
343 std::ifstream sysFile(fileName);
344 if (!sysFile.good())
345 {
346 std::cerr << "Failure reading " << fileName << "\n";
347 continue;
348 }
349 std::string line;
350 getline(sysFile, line);
351 const uint8_t ifindex = std::stoi(line);
352 // pathSuffix is ASCII of ifindex
353 const std::string& pathSuffix = std::to_string(ifindex + 30);
354
355 // extract ethNum
356 const std::string& fileStr = fileName.string();
357 const int pos = fileStr.find("eth");
358 const std::string& ethNumStr = fileStr.substr(pos + 3);
359 int ethNum = 0;
Ed Tanous8a57ec02020-10-09 12:46:52 -0700360 std::from_chars_result r = std::from_chars(
361 ethNumStr.data(), ethNumStr.data() + ethNumStr.size(), ethNum);
362 if (r.ec != std::errc())
Qiang XU88b7f282019-08-14 22:51:43 +0800363 {
364 std::cerr << "invalid ethNum string: " << ethNumStr << "\n";
365 continue;
366 }
367
368 // save pathSuffix
369 pathSuffixMap[pathSuffix] = ethNum;
370 if (debugLanLeash)
371 {
372 std::cout << "ethNum = " << std::to_string(ethNum)
373 << ", ifindex = " << line
374 << ", pathSuffix = " << pathSuffix << "\n";
375 }
376
Qiang XU74ddf862019-09-12 17:12:13 +0800377 // init lan connected status from networkd
Qiang XU88b7f282019-08-14 22:51:43 +0800378 conn->async_method_call(
379 [ethNum](boost::system::error_code ec,
380 const std::variant<std::string>& property) {
Ed Tanousbb679322022-05-16 16:10:00 -0700381 lanStatusMap[ethNum] = false;
382 if (ec)
383 {
384 std::cerr << "Error reading init status of eth" << ethNum
385 << "\n";
386 return;
387 }
388 const std::string* pState = std::get_if<std::string>(&property);
389 if (pState == nullptr)
390 {
391 std::cerr << "Unable to read lan status value\n";
392 return;
393 }
394 bool isLanConnected =
395 (*pState == "routable" || *pState == "carrier" ||
396 *pState == "degraded");
397 if (debugLanLeash)
398 {
399 std::cout << "ethNum = " << std::to_string(ethNum)
400 << ", init LAN status = "
401 << (isLanConnected ? "true" : "false") << "\n";
402 }
403 lanStatusMap[ethNum] = isLanConnected;
Qiang XU88b7f282019-08-14 22:51:43 +0800404 },
405 "org.freedesktop.network1",
406 "/org/freedesktop/network1/link/_" + pathSuffix,
407 "org.freedesktop.DBus.Properties", "Get",
408 "org.freedesktop.network1.Link", "OperationalState");
409 }
Lei YUdd68d4a2021-03-16 22:17:23 +0800410 return true;
Qiang XU88b7f282019-08-14 22:51:43 +0800411}
412
Qiang XUe28d1fa2019-02-27 13:50:56 +0800413int main()
414{
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800415 int busId = -1;
416 int slaveAddr = -1;
Qiang XUe28d1fa2019-02-27 13:50:56 +0800417 bool gpioInverted = false;
418 IntrusionSensorType type = IntrusionSensorType::gpio;
419
420 // setup connection to dbus
Ed Tanous1f978632023-02-28 18:16:39 -0800421 boost::asio::io_context io;
Qiang XUe28d1fa2019-02-27 13:50:56 +0800422 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
Qiang XUe28d1fa2019-02-27 13:50:56 +0800423
424 // setup object server, define interface
425 systemBus->request_name("xyz.openbmc_project.IntrusionSensor");
426
Ed Tanous14ed5e92022-07-12 15:50:23 -0700427 sdbusplus::asio::object_server objServer(systemBus, true);
428
429 objServer.add_manager("/xyz/openbmc_project/sensors");
430
Qiang XUe28d1fa2019-02-27 13:50:56 +0800431 std::shared_ptr<sdbusplus::asio::dbus_interface> ifaceChassis =
432 objServer.add_interface(
433 "/xyz/openbmc_project/Intrusion/Chassis_Intrusion",
434 "xyz.openbmc_project.Chassis.Intrusion");
435
436 ChassisIntrusionSensor chassisIntrusionSensor(io, ifaceChassis);
437
438 if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800439 &gpioInverted))
Qiang XUe28d1fa2019-02-27 13:50:56 +0800440 {
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800441 chassisIntrusionSensor.start(type, busId, slaveAddr, gpioInverted);
Qiang XUe28d1fa2019-02-27 13:50:56 +0800442 }
443
444 // callback to handle configuration change
Patrick Williams92f8f512022-07-22 19:26:55 -0500445 std::function<void(sdbusplus::message_t&)> eventHandler =
446 [&](sdbusplus::message_t& message) {
Ed Tanousbb679322022-05-16 16:10:00 -0700447 if (message.is_method_error())
448 {
449 std::cerr << "callback method error\n";
450 return;
451 }
Qiang XUe28d1fa2019-02-27 13:50:56 +0800452
Ed Tanousbb679322022-05-16 16:10:00 -0700453 std::cout << "rescan due to configuration change \n";
454 if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
455 &gpioInverted))
456 {
457 chassisIntrusionSensor.start(type, busId, slaveAddr, gpioInverted);
458 }
459 };
Qiang XUe28d1fa2019-02-27 13:50:56 +0800460
Zev Weiss214d9712022-08-12 12:54:31 -0700461 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
462 setupPropertiesChangedMatches(
463 *systemBus, std::to_array<const char*>({sensorType}), eventHandler);
Qiang XUe28d1fa2019-02-27 13:50:56 +0800464
Lei YUdd68d4a2021-03-16 22:17:23 +0800465 if (initializeLanStatus(systemBus))
466 {
467 // add match to monitor lan status change
Patrick Williams92f8f512022-07-22 19:26:55 -0500468 sdbusplus::bus::match_t lanStatusMatch(
469 static_cast<sdbusplus::bus_t&>(*systemBus),
Lei YUdd68d4a2021-03-16 22:17:23 +0800470 "type='signal', member='PropertiesChanged',"
471 "arg0namespace='org.freedesktop.network1.Link'",
Patrick Williams92f8f512022-07-22 19:26:55 -0500472 [](sdbusplus::message_t& msg) { processLanStatusChange(msg); });
Lei YUdd68d4a2021-03-16 22:17:23 +0800473
474 // add match to monitor entity manager signal about nic name config
475 // change
Patrick Williams92f8f512022-07-22 19:26:55 -0500476 sdbusplus::bus::match_t lanConfigMatch(
477 static_cast<sdbusplus::bus_t&>(*systemBus),
Lei YUdd68d4a2021-03-16 22:17:23 +0800478 "type='signal', member='PropertiesChanged',path_namespace='" +
Zev Weiss054aad82022-08-18 01:37:34 -0700479 std::string(inventoryPath) + "',arg0namespace='" +
480 configInterfaceName(nicType) + "'",
Patrick Williams92f8f512022-07-22 19:26:55 -0500481 [&systemBus](sdbusplus::message_t& msg) {
Ed Tanousbb679322022-05-16 16:10:00 -0700482 if (msg.is_method_error())
483 {
484 std::cerr << "callback method error\n";
485 return;
486 }
487 getNicNameInfo(systemBus);
Lei YUdd68d4a2021-03-16 22:17:23 +0800488 });
489 }
Qiang XU88b7f282019-08-14 22:51:43 +0800490
Qiang XUe28d1fa2019-02-27 13:50:56 +0800491 io.run();
492
493 return 0;
494}