Files
OpenBMC/meta-luxshare/recipes-phosphor/network/phosphor-network/0001-Fix-static-ip-still-exist-after-enable-dhcp.patch
T

74 lines
2.4 KiB
Diff
Raw Normal View History

2026-04-23 17:07:55 +08:00
From dc27450fcd8cd509d540afccb06974e92a117cd6 Mon Sep 17 00:00:00 2001
From: roly <Rolyli.Li@luxshare-ict.com>
Date: Fri, 8 Nov 2024 14:31:08 +0800
Subject: [PATCH] Fix static ip still exist after enable dhcp
---
src/ethernet_interface.cpp | 19 ++++++++++++++++++-
src/ethernet_interface.hpp | 12 ++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 2851a1b..126255c 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -266,6 +266,22 @@ ObjectPath EthernetInterface::ip(IP::Protocol protType, std::string ipaddress,
Argument::ARGUMENT_VALUE(ipaddress.c_str()));
}
std::optional<stdplus::SubnetAny> ifaddr;
+
+ if (dhcpIsEnabled(protType))
+ {
+ log<level::INFO>("DHCP enabled on the interface, disabling");
+ switch (protType)
+ {
+ case IP::Protocol::IPv4:
+ dhcp4(false);
+ break;
+ case IP::Protocol::IPv6:
+ dhcp6(false);
+ ipv6AcceptRA(false);
+ break;
+ }
+ }
+
try
{
if (prefixLength == 0)
@@ -702,7 +718,8 @@ void EthernetInterface::writeConfigurationFile()
auto& address = network["Address"];
for (const auto& addr : addrs)
{
- if (originIsManuallyAssigned(addr.second->origin()))
+ if (originIsManuallyAssigned(addr.second->origin()) &&
+ !dhcpIsEnabled(addr.second->type()))
{
address.emplace_back(stdplus::toStr(addr.first));
}
diff --git a/src/ethernet_interface.hpp b/src/ethernet_interface.hpp
index 0e9c536..b927e69 100644
--- a/src/ethernet_interface.hpp
+++ b/src/ethernet_interface.hpp
@@ -129,6 +129,18 @@ class EthernetInterface : public Ifaces
using EthernetInterfaceIntf::dhcp6;
bool dhcp6(bool value) override;
+ inline bool dhcpIsEnabled(IP::Protocol family) const
+ {
+ switch (family)
+ {
+ case IP::Protocol::IPv6:
+ return dhcp6();
+ case IP::Protocol::IPv4:
+ return dhcp4();
+ }
+ throw std::logic_error("Unreachable");
+ }
+
inline bool dhcpIsEnabled(stdplus::In4Addr) const
{
return dhcp4();
--
2.25.1