123 lines
4.6 KiB
Diff
Executable File
123 lines
4.6 KiB
Diff
Executable File
From 2070b4aaf3eab4f4478ef30881e55a685523263f Mon Sep 17 00:00:00 2001
|
|
From: roly <Rolyli.Li@luxshare-ict.com>
|
|
Date: Fri, 8 Nov 2024 14:38:24 +0800
|
|
Subject: [PATCH] Reset static ipv4 address when turn off dhcpv4
|
|
|
|
---
|
|
redfish-core/lib/ethernet.hpp | 71 +++++++++++++++++++++++++++++------
|
|
1 file changed, 59 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
|
|
index 57fe24c4..8de854f7 100644
|
|
--- a/redfish-core/lib/ethernet.hpp
|
|
+++ b/redfish-core/lib/ethernet.hpp
|
|
@@ -1044,10 +1044,51 @@ inline void
|
|
});
|
|
}
|
|
|
|
-inline void setDHCPEnabled(const std::string& ifaceId,
|
|
- const std::string& propertyName, const bool v4Value,
|
|
- const bool v6Value,
|
|
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
|
|
+inline void handleIPv4DHCPDisableKeepIp(
|
|
+ const std::string& ifaceId, const bool v4Value,
|
|
+ const std::vector<IPv4AddressData>& ipv4Data,
|
|
+ const std::optional<nlohmann::json::array_t> &
|
|
+ ipv4StaticAddresses,
|
|
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
|
|
+{
|
|
+ // If v4DHCP is disabled, and there is no incoming static address data,
|
|
+ // if have any existing DHCP addresses, change them to static addresses
|
|
+ if (!v4Value && !ipv4StaticAddresses)
|
|
+ {
|
|
+ auto it = std::find_if(
|
|
+ ipv4Data.begin(), ipv4Data.end(),
|
|
+ [](const IPv4AddressData& addr) { return addr.origin == "DHCP"; });
|
|
+
|
|
+ if (it == ipv4Data.end())
|
|
+ {
|
|
+ // Do nothing
|
|
+ BMCWEB_LOG_INFO("No DHCP addresses to convert to static");
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ uint8_t prefixLength = 0;
|
|
+ std::string address = it->address;
|
|
+ std::string gateway = it->gateway;
|
|
+ std::string netmask = it->netmask;
|
|
+
|
|
+ if (!ip_util::ipv4VerifyIpAndGetBitcount(netmask, &prefixLength))
|
|
+ {
|
|
+ messages::internalError(asyncResp->res);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ createIPv4(ifaceId, prefixLength, gateway, address, asyncResp);
|
|
+ }
|
|
+}
|
|
+
|
|
+inline void setDHCPEnabled(
|
|
+ const std::string& ifaceId,
|
|
+ const std::string& propertyName,const bool v4Value,
|
|
+ const bool v6Value,
|
|
+ const std::vector<IPv4AddressData>& ipv4Data,
|
|
+ const std::optional<nlohmann::json::array_t> &
|
|
+ ipv4StaticAddresses,
|
|
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
|
|
{
|
|
const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
|
|
sdbusplus::asio::setProperty(
|
|
@@ -1063,6 +1104,8 @@ inline void setDHCPEnabled(const std::string& ifaceId,
|
|
}
|
|
messages::success(asyncResp->res);
|
|
});
|
|
+ handleIPv4DHCPDisableKeepIp(ifaceId, v4Value, ipv4Data, ipv4StaticAddresses,
|
|
+ asyncResp);
|
|
}
|
|
|
|
inline void setEthernetInterfaceBoolProperty(
|
|
@@ -1122,11 +1165,15 @@ inline void handleSLAACAutoConfigPatch(
|
|
});
|
|
}
|
|
|
|
-inline void handleDHCPPatch(const std::string& ifaceId,
|
|
- const EthernetInterfaceData& ethData,
|
|
- const DHCPParameters& v4dhcpParms,
|
|
- const DHCPParameters& v6dhcpParms,
|
|
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
|
|
+inline void handleDHCPPatch(
|
|
+ const std::string& ifaceId,
|
|
+ const EthernetInterfaceData& ethData,
|
|
+ const std::optional<nlohmann::json::array_t> &
|
|
+ ipv4StaticAddresses,
|
|
+ const std::vector<IPv4AddressData>& ipv4Data,
|
|
+ const DHCPParameters& v4dhcpParms,
|
|
+ const DHCPParameters& v6dhcpParms,
|
|
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
|
|
{
|
|
bool ipv4Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
|
|
bool ipv6Active = translateDhcpEnabledToBool(ethData.dhcpEnabled, false);
|
|
@@ -1223,7 +1270,7 @@ inline void handleDHCPPatch(const std::string& ifaceId,
|
|
|
|
BMCWEB_LOG_DEBUG("set DHCPEnabled...");
|
|
setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
|
|
- asyncResp);
|
|
+ ipv4Data, ipv4StaticAddresses, asyncResp);
|
|
BMCWEB_LOG_DEBUG("set DNSEnabled...");
|
|
setDHCPv4Config("DNSEnabled", nextDNS, asyncResp);
|
|
BMCWEB_LOG_DEBUG("set NTPEnabled...");
|
|
@@ -2051,8 +2098,8 @@ inline void requestEthernetInterfacesRoutes(App& app)
|
|
|
|
if (dhcpv4 || dhcpv6)
|
|
{
|
|
- handleDHCPPatch(ifaceId, ethData, v4dhcpParms, v6dhcpParms,
|
|
- asyncResp);
|
|
+ handleDHCPPatch(ifaceId, ethData, ipv4StaticAddresses, ipv4Data,
|
|
+ v4dhcpParms, v6dhcpParms, asyncResp);
|
|
}
|
|
|
|
if (hostname)
|
|
--
|
|
2.25.1
|
|
|