Fix unexpected change of ipsrc of ipv6
Issue: The initial ipsrc of ipv6 is dhcp. When setting different static
ipv4 twice, ipv6 will become static.
Fix: Rewrite the if condition. setDHCPv4Property is only for IPv4
management. It should not modify IPv6 state.
Tested: Verified step as below:
1. Get dbus property 'DHCPEnabled' via
busctl get-property xyz.openbmc_project.Network
/xyz/openbmc_project/network/eth1
xyz.openbmc_project.Network.EthernetInterface DHCPEnabled
s "xyz.openbmc_project.Network.EthernetInterface.DHCPConf.both"
2. Set an static ipv4.
3. Set another static ipv4.
4. Check 'DHCPEnabled' is still v6 via dbus. And check the config
in 00-bmc-eth1.network without ipv6 static address.
Change-Id: I8b55c01a61e568555983fc462d4508f2860217be
Signed-off-by: Tony Lee <tony.lee@quantatw.com>
diff --git a/transporthandler.cpp b/transporthandler.cpp
index f1b733e..f674865 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -186,29 +186,28 @@
EthernetInterface::DHCPConf currentDhcp = getDHCPProperty(bus, params);
EthernetInterface::DHCPConf nextDhcp = EthernetInterface::DHCPConf::none;
- if ((currentDhcp == EthernetInterface::DHCPConf::v6) &&
- (requestedDhcp == EthernetInterface::DHCPConf::v4))
+ // When calling setDHCPv4Property, requestedDhcp only has "v4" and "none".
+ // setDHCPv4Property is only for IPv4 management. It should not modify
+ // IPv6 state.
+ if (requestedDhcp == EthernetInterface::DHCPConf::v4)
{
- nextDhcp = EthernetInterface::DHCPConf::both;
- }
- else if ((currentDhcp == EthernetInterface::DHCPConf::none) &&
- (requestedDhcp == EthernetInterface::DHCPConf::v4))
-
- {
- nextDhcp = requestedDhcp;
+ if ((currentDhcp == EthernetInterface::DHCPConf::v6) ||
+ (currentDhcp == EthernetInterface::DHCPConf::both))
+ nextDhcp = EthernetInterface::DHCPConf::both;
+ else if ((currentDhcp == EthernetInterface::DHCPConf::v4) ||
+ (currentDhcp == EthernetInterface::DHCPConf::none))
+ nextDhcp = EthernetInterface::DHCPConf::v4;
}
else if (requestedDhcp == EthernetInterface::DHCPConf::none)
{
- if (currentDhcp == EthernetInterface::DHCPConf::both)
- {
+ if ((currentDhcp == EthernetInterface::DHCPConf::v6) ||
+ (currentDhcp == EthernetInterface::DHCPConf::both))
nextDhcp = EthernetInterface::DHCPConf::v6;
- }
- else if (currentDhcp == EthernetInterface::DHCPConf::v4)
- {
+ else if ((currentDhcp == EthernetInterface::DHCPConf::v4) ||
+ (currentDhcp == EthernetInterface::DHCPConf::none))
nextDhcp = EthernetInterface::DHCPConf::none;
- }
}
- else
+ else // Stay the same.
{
nextDhcp = currentDhcp;
}