diff --git a/transportconstants.hpp b/transportconstants.hpp index b9ce46be..3f865c6f 100644 --- a/transportconstants.hpp +++ b/transportconstants.hpp @@ -123,6 +123,9 @@ constexpr Cc ccParamReadOnly = 0x82; constexpr uint16_t VLAN_VALUE_MASK = 0x0fff; constexpr uint16_t VLAN_ENABLE_FLAG = 0x8000; +// Arbitrary v4 Address Limits +constexpr uint8_t MAX_IPV4_ADDRESSES = 2; + // Arbitrary v6 Address Limits to prevent too much output in ipmitool constexpr uint8_t MAX_IPV6_STATIC_ADDRESSES = 15; constexpr uint8_t MAX_IPV6_DYNAMIC_ADDRESSES = 15; diff --git a/transporthandler.cpp b/transporthandler.cpp index 6e7dae22..c7cca213 100644 --- a/transporthandler.cpp +++ b/transporthandler.cpp @@ -277,7 +277,36 @@ void createIfAddr(sdbusplus::bus_t& bus, const ChannelParams& params, */ auto getIfAddr4(sdbusplus::bus_t& bus, const ChannelParams& params) { - return getIfAddr(bus, params, 0, originsV4); + std::optional> ifaddr4 = std::nullopt; + IP::AddressOrigin src; + + try + { + src = std::get( + getDbusProperty(bus, params.service, params.logicalPath, + INTF_ETHERNET, "DHCP4")) + ? IP::AddressOrigin::DHCP + : IP::AddressOrigin::Static; + } + catch (const sdbusplus::exception_t& e) + { + lg2::error("Failed to get IPv4 source"); + return ifaddr4; + } + + for (uint8_t i = 0; i < MAX_IPV4_ADDRESSES; ++i) + { + ifaddr4 = getIfAddr(bus, params, i, originsV4); + if (src == ifaddr4->origin) + { + break; + } + else + { + ifaddr4 = std::nullopt; + } + } + return ifaddr4; } /** @brief Reconfigures the IPv4 address info configured for the interface