Skip to content

Commit

Permalink
transporthandler: Synchronous get IP address and IP address source
Browse files Browse the repository at this point in the history
In case both DHCP and static IP addresses are assigned, the IPMI
code just returns one of them. The IPMI code always returns the
first object dbus on the interface by the fixed index, which is
always 0. That may cause a mismatch between the IP address and
IP address source.

This patch will check if the DHCP or static mode is enabling,
then return the IP address accordingly.

Tested:
1. Change to static source
ipmitool lan set 1 ipsrc static

2. Set a static IP address.
ipmitool lan set 1 ipaddr xx.xx.xx.xx

3. Back to DHCP source
ipmitool lan set 1 ipsrc dhcp

4. Check the IP Lan print.
Expect the IP address and IP source address report accordingly.

ipmitool lan print 1

Fixes #207

Change-Id: If1d2bcfb9e3ab79e02ebf78682e3ac5638c18b0c
Signed-off-by: Chanh Nguyen <[email protected]>
  • Loading branch information
chnguyen-ampere authored and vmauery committed Nov 15, 2024
1 parent 402024a commit 8bd9a9b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions transportconstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 30 additions & 1 deletion transporthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,36 @@ void createIfAddr(sdbusplus::bus_t& bus, const ChannelParams& params,
*/
auto getIfAddr4(sdbusplus::bus_t& bus, const ChannelParams& params)
{
return getIfAddr<AF_INET>(bus, params, 0, originsV4);
std::optional<IfAddr<AF_INET>> ifaddr4 = std::nullopt;
IP::AddressOrigin src;

try
{
src = std::get<bool>(
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<AF_INET>(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
Expand Down

0 comments on commit 8bd9a9b

Please sign in to comment.