Add LLDP configuration support
This commit implements EmitLLDP D-bus property to support configuration
of enable/disable LLDP of each ethernet interface.
Tested by:
Set EmitLLDP D-bus property on
xyz.openbmc_project.Network.EthernetInterface
Change-Id: I4ebedff9d3f914219f2f84c861fdee126584a94b
Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index fb3a801..75c759b 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -22,6 +22,7 @@
#include <filesystem>
#include <format>
+#include <fstream>
namespace phosphor
{
@@ -33,6 +34,12 @@
using Argument = xyz::openbmc_project::Common::InvalidArgument;
using std::literals::string_view_literals::operator""sv;
+constexpr auto systemdBusname = "org.freedesktop.systemd1";
+constexpr auto systemdObjPath = "/org/freedesktop/systemd1";
+constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
+constexpr auto lldpFilePath = "/etc/lldpd.conf";
+constexpr auto lldpService = "lldpd.service";
+
static constexpr const char enabledMatch[] =
"type='signal',sender='org.freedesktop.network1',path_namespace='/org/"
"freedesktop/network1/"
@@ -515,5 +522,45 @@
}
}
+void Manager::writeLLDPDConfigurationFile()
+{
+ std::ofstream lldpdConfig(lldpFilePath);
+
+ lldpdConfig << "configure system description BMC" << std::endl;
+ lldpdConfig << "configure system ip management pattern eth*" << std::endl;
+ for (const auto& intf : interfaces)
+ {
+ bool emitlldp = intf.second->emitLLDP();
+ if (emitlldp)
+ {
+ lldpdConfig << "configure ports " << intf.second->interfaceName()
+ << " lldp status tx-only" << std::endl;
+ }
+ else
+ {
+ lldpdConfig << "configure ports " << intf.second->interfaceName()
+ << " lldp status disabled" << std::endl;
+ }
+ }
+
+ lldpdConfig.close();
+}
+
+void Manager::reloadLLDPService()
+{
+ try
+ {
+ auto method = bus.get().new_method_call(
+ systemdBusname, systemdObjPath, systemdInterface, "RestartUnit");
+ method.append(lldpService, "replace");
+ bus.get().call_noreply(method);
+ }
+ catch (const sdbusplus::exception_t& ex)
+ {
+ lg2::error("Failed to restart service {SERVICE}: {ERR}", "SERVICE",
+ lldpService, "ERR", ex);
+ }
+}
+
} // namespace network
} // namespace phosphor