Use ActivationPolicy to enable/disable network interfaces
The systemd.network "Unmanaged" control, used to cause a network
interface to prevent a NIC from being configured by systemd is too
aggressive. The goal is to control the IFF_UP/IFF_DOWN
state of the NIC.
The systemd-networkd developers, as part of discussions around
"Unmanaged", created an alternate control to perform the required
action. The control is called ActivationPolicy.
Switch from using Unmanaged to ActivationPolicy in order to manage
IFF_UP/IFF_DOWN conditions.
Tested:
The systemd-network.service initial state has no ActivationPolicy
entry. The default state is for ActivationPolicy to be enabled.
Issued a Redfish request:
PATCH :url/redfish/v1/Managers/bmc/EthernetInterfaces/eth1
{
"InterfaceEnabled": false
}
to assign "ActivationPolicy=down", and causing the link to stay down
until another request re-enables it. Confirmed the NIC is IFF_DOWN,
and the systemd.network configuration file contains
ActivationPolicy=down.
Sending another request to set InterfaceEanbled: "true" causes the
entry to be removed from the systemd.network file, and the NIC enters
the IFF_UP state.
Change-Id: I8b5bb4d30a1c7282494526169f65e0eda26e04cf
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 6a34492..c1433a7 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -448,14 +448,6 @@
EthernetInterfaceIntf::nicEnabled(value);
writeConfigurationFile();
- if (!value)
- {
- // We only need to bring down the interface, networkd will always bring
- // up managed interfaces
- manager.get().addReloadPreHook([ifname = interfaceName()]() {
- system::setNICUp(ifname, false);
- });
- }
manager.get().reloadConfigs();
return value;
@@ -707,7 +699,7 @@
#endif
if (!EthernetInterfaceIntf::nicEnabled())
{
- link["Unmanaged"].emplace_back("yes");
+ link["ActivationPolicy"].emplace_back("down");
}
}
{
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index c412923..fb3a801 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -508,11 +508,7 @@
{
bool managed = state != "unmanaged";
systemdNetworkdEnabled.insert_or_assign(ifidx, managed);
- if (auto it = interfacesByIdx.find(ifidx); it != interfacesByIdx.end())
- {
- it->second->EthernetInterfaceIntf::nicEnabled(managed);
- }
- else if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
+ if (auto it = intfInfo.find(ifidx); it != intfInfo.end())
{
createInterface(it->second, managed);
}