From b56e70f39943812287be1668874f9df7bc2e3422 Mon Sep 17 00:00:00 2001 From: "Wang.Bin" Date: Fri, 21 Mar 2025 09:12:49 +0800 Subject: [PATCH 4/4] Keep the current IP when setting ipsrc to static --- transporthandler.cpp | 60 ++++++++++++++++++++++++++++++++++++-------- transporthandler.hpp | 6 +++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/transporthandler.cpp b/transporthandler.cpp index 38faccc..bab465b 100644 --- a/transporthandler.cpp +++ b/transporthandler.cpp @@ -1,5 +1,11 @@ #include "transporthandler.hpp" +#include +#include +#include +#include +#include + using phosphor::logging::commit; using phosphor::logging::elog; using phosphor::logging::entry; @@ -162,6 +168,23 @@ auto logWithChannel(const std::optional& params, Args&&... args) return log(std::forward(args)...); } +/** @brief Get / Set the Property value from phosphor-networkd EthernetInterface + */ +template +static T getEthProp(sdbusplus::bus_t& bus, const ChannelParams& params, + const std::string& prop) +{ + return std::get(getDbusProperty(bus, params.service, params.logicalPath, + INTF_ETHERNET, prop)); +} +template +static void setEthProp(sdbusplus::bus_t& bus, const ChannelParams& params, + const std::string& prop, const T& t) +{ + return setDbusProperty(bus, params.service, params.logicalPath, + INTF_ETHERNET, prop, t); +} + EthernetInterface::DHCPConf getDHCPProperty(sdbusplus::bus_t& bus, const ChannelParams& params) { @@ -316,18 +339,25 @@ void deleteObjectIfExists(sdbusplus::bus_t& bus, const std::string& service, { auto req = bus.new_method_call(service.c_str(), path.c_str(), ipmi::DELETE_INTERFACE, "Delete"); - bus.call_noreply(req); + + bus.call_noreply(req); } catch (const sdbusplus::exception_t& e) { if (strcmp(e.name(), "xyz.openbmc_project.Common.Error.InternalFailure") != 0 && - strcmp(e.name(), "org.freedesktop.DBus.Error.UnknownObject") != 0) + strcmp(e.name(), "org.freedesktop.DBus.Error.UnknownObject") != 0 && + strcmp(e.name(), "xyz.openbmc_project.Common.Error.NotAllowed") != + 0) { // We want to rethrow real errors throw; } } + catch (...) + { + throw; + } } /** @brief Sets the address info configured for the interface @@ -383,18 +413,20 @@ void reconfigureIfAddr4(sdbusplus::bus_t& bus, const ChannelParams& params, elog(); } uint8_t fallbackPrefix = AddrFamily::defaultPrefix; + auto addr = address.value_or(ifaddr->address); + // if (!validIntfIP(addr)) + // { + // log("IPv4 not unicast"); + // elog(); + // } if (ifaddr) { fallbackPrefix = ifaddr->prefix; deleteObjectIfExists(bus, params.service, ifaddr->path); } - - if (struct in_addr nullIPv4{0}; - (address == std::nullopt && prefix != std::nullopt) || - (address != std::nullopt && - (address.value().s_addr != nullIPv4.s_addr))) + if (addr != stdplus::In4Addr{}) { - createIfAddr(bus, params, address.value_or(ifaddr->address), + createIfAddr(bus, params, addr, prefix.value_or(fallbackPrefix)); } } @@ -980,8 +1012,16 @@ RspType<> setLan(Context::ptr ctx, uint4_t channelBits, uint4_t reserved1, case IPSrc::Unspecified: case IPSrc::Static: { - channelCall( - channel, EthernetInterface::DHCPConf::none); + auto ifaddr = channelCall(channel); + + //channelCall(channel, EthernetInterface::DHCPConf::none); + channelCall>(channel, "DHCP4", false); + + if (ifaddr) + { + channelCall(channel, ifaddr->address, ifaddr->prefix); + } + return responseSuccess(); } case IPSrc::BIOS: diff --git a/transporthandler.hpp b/transporthandler.hpp index 8e1c4fb..a4e862b 100644 --- a/transporthandler.hpp +++ b/transporthandler.hpp @@ -17,6 +17,12 @@ #include #include #include + +#include +#include +#include +#include + #include #include #include -- 2.25.1