Configure DHCP4 and DHCP6 parameters independently
At present, DHCP parameters like DNSEnabled, NTPEnabled and
HostNameEnabled are at the system level at the network backend. It is
common across both IPv4 and IPv6 network types. Thus when a redfish
command is sent to enable the DNSEnabled property for IPv4 on eth0
interface, it internally sets the DNSEnabled to true for both IPv4 and
IPv6 on eth0 and eth1.
Here the change in parameter value for a non-requested network type in
the non-requested interface might be an unexpected behaviour for the
user. Also, with the current implementation in bmcweb and networkd, the
user has no option to configure DHCP parameters differently for
different interfaces and network types though it is supported by the
redfish.
With this change, the Redfish query for updating DHCP parameters will
only modify the requested parameter for the specified network type and
interface. User must make separate requests to modify the DHCP
parameters as per the DMTF schema
Current behavior: Request: curl -k -H "X-Auth-Token: $bmc_token" -X
PATCH -d '{"DHCPv4":{"UseDNSServers":false}}'
https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/eth0
Result: UseDNSServers value is set to false for DHCPv4 and DHCPv6 for
all interfaces.
After this commit: Request: curl -k -H "X-Auth-Token: $bmc_token" -X
PATCH -d '{"DHCPv4":{"UseDNSServers":false}}'
https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/eth0
Result: UseDNSServers value is set to false only for DHCPv4 only in eth0
as mentioned in the redfish request.
The DHCP configuration was in the network manager level earlier, it has
been moved to interface level with
https://gerrit.openbmc.org/c/openbmc/phosphor-networkd/+/63124. This
bmcweb change is to separate out the values for IPv4 and IPv6 and to
move the dbus object to the interface level.
Tested by:
Patching the DHCP parameters with redfish request:
curl -k -H "X-Auth-Token: $bmc_token" -X PATCH -d
'{"<network_type>":{"<DHCP_param>":<value>}}'
https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/<interface_id>
Verify the value is updated in the network configuration.
Retrieve the DHCP parametrer value with the Get Request: curl -k -H
"X-Auth-Token: $bmc_token" -X GET
https://${bmc}/redfish/v1/Managers/bmc/EthernetInterfaces/<interface_id>
Change-Id: I5db29b6dfc8966ff5af51041da11e5b79da7d1dd
Signed-off-by: Jishnu CM <jishnunambiarcm@duck.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 390efbc..03b23e1 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -80,9 +80,12 @@
uint32_t speed;
size_t mtuSize;
bool autoNeg;
- bool dnsEnabled;
- bool ntpEnabled;
- bool hostNameEnabled;
+ bool dnsv4Enabled;
+ bool dnsv6Enabled;
+ bool ntpv4Enabled;
+ bool ntpv6Enabled;
+ bool hostNamev4Enabled;
+ bool hostNamev6Enabled;
bool linkUp;
bool nicEnabled;
bool ipv6AcceptRa;
@@ -366,7 +369,12 @@
}
}
- if (objpath.first == "/xyz/openbmc_project/network/dhcp")
+ sdbusplus::message::object_path path(
+ "/xyz/openbmc_project/network");
+ sdbusplus::message::object_path dhcp4Path = path / ethifaceId /
+ "dhcp4";
+
+ if (sdbusplus::message::object_path(objpath.first) == dhcp4Path)
{
if (ifacePair.first ==
"xyz.openbmc_project.Network.DHCPConfiguration")
@@ -379,7 +387,7 @@
std::get_if<bool>(&propertyPair.second);
if (dnsEnabled != nullptr)
{
- ethData.dnsEnabled = *dnsEnabled;
+ ethData.dnsv4Enabled = *dnsEnabled;
}
}
else if (propertyPair.first == "NTPEnabled")
@@ -388,7 +396,7 @@
std::get_if<bool>(&propertyPair.second);
if (ntpEnabled != nullptr)
{
- ethData.ntpEnabled = *ntpEnabled;
+ ethData.ntpv4Enabled = *ntpEnabled;
}
}
else if (propertyPair.first == "HostNameEnabled")
@@ -397,7 +405,48 @@
std::get_if<bool>(&propertyPair.second);
if (hostNameEnabled != nullptr)
{
- ethData.hostNameEnabled = *hostNameEnabled;
+ ethData.hostNamev4Enabled = *hostNameEnabled;
+ }
+ }
+ }
+ }
+ }
+
+ sdbusplus::message::object_path dhcp6Path = path / ethifaceId /
+ "dhcp6";
+
+ if (sdbusplus::message::object_path(objpath.first) == dhcp6Path)
+ {
+ if (ifacePair.first ==
+ "xyz.openbmc_project.Network.DHCPConfiguration")
+ {
+ for (const auto& propertyPair : ifacePair.second)
+ {
+ if (propertyPair.first == "DNSEnabled")
+ {
+ const bool* dnsEnabled =
+ std::get_if<bool>(&propertyPair.second);
+ if (dnsEnabled != nullptr)
+ {
+ ethData.dnsv6Enabled = *dnsEnabled;
+ }
+ }
+ else if (propertyPair.first == "NTPEnabled")
+ {
+ const bool* ntpEnabled =
+ std::get_if<bool>(&propertyPair.second);
+ if (ntpEnabled != nullptr)
+ {
+ ethData.ntpv6Enabled = *ntpEnabled;
+ }
+ }
+ else if (propertyPair.first == "HostNameEnabled")
+ {
+ const bool* hostNameEnabled =
+ std::get_if<bool>(&propertyPair.second);
+ if (hostNameEnabled != nullptr)
+ {
+ ethData.hostNamev6Enabled = *hostNameEnabled;
}
}
}
@@ -1079,13 +1128,31 @@
});
}
-inline void setDHCPv4Config(const std::string& propertyName, const bool& value,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+enum class NetworkType
+{
+ dhcp4,
+ dhcp6
+};
+
+inline void setDHCPConfig(const std::string& propertyName, const bool& value,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& ethifaceId, NetworkType type)
{
BMCWEB_LOG_DEBUG("{} = {}", propertyName, value);
+ sdbusplus::message::object_path path("/xyz/openbmc_project/network/");
+ path /= ethifaceId;
+
+ if (type == NetworkType::dhcp4)
+ {
+ path /= "dhcp4";
+ }
+ else
+ {
+ path /= "dhcp6";
+ }
+
sdbusplus::asio::setProperty(
- *crow::connections::systemBus, "xyz.openbmc_project.Network",
- "/xyz/openbmc_project/network/dhcp",
+ *crow::connections::systemBus, "xyz.openbmc_project.Network", path,
"xyz.openbmc_project.Network.DHCPConfiguration", propertyName, value,
[asyncResp](const boost::system::error_code& ec) {
if (ec)
@@ -1148,84 +1215,60 @@
nextv6DHCPState = ipv6Active;
}
- bool nextDNS{};
- if (v4dhcpParms.useDnsServers && v6dhcpParms.useDnsServers)
+ bool nextDNSv4 = ethData.dnsv4Enabled;
+ bool nextDNSv6 = ethData.dnsv6Enabled;
+ if (v4dhcpParms.useDnsServers)
{
- if (*v4dhcpParms.useDnsServers != *v6dhcpParms.useDnsServers)
- {
- messages::generalError(asyncResp->res);
- return;
- }
- nextDNS = *v4dhcpParms.useDnsServers;
+ nextDNSv4 = *v4dhcpParms.useDnsServers;
}
- else if (v4dhcpParms.useDnsServers)
+ if (v6dhcpParms.useDnsServers)
{
- nextDNS = *v4dhcpParms.useDnsServers;
- }
- else if (v6dhcpParms.useDnsServers)
- {
- nextDNS = *v6dhcpParms.useDnsServers;
- }
- else
- {
- nextDNS = ethData.dnsEnabled;
+ nextDNSv6 = *v6dhcpParms.useDnsServers;
}
- bool nextNTP{};
- if (v4dhcpParms.useNtpServers && v6dhcpParms.useNtpServers)
+ bool nextNTPv4 = ethData.ntpv4Enabled;
+ bool nextNTPv6 = ethData.ntpv6Enabled;
+ if (v4dhcpParms.useNtpServers)
{
- if (*v4dhcpParms.useNtpServers != *v6dhcpParms.useNtpServers)
- {
- messages::generalError(asyncResp->res);
- return;
- }
- nextNTP = *v4dhcpParms.useNtpServers;
+ nextNTPv4 = *v4dhcpParms.useNtpServers;
}
- else if (v4dhcpParms.useNtpServers)
+ if (v6dhcpParms.useNtpServers)
{
- nextNTP = *v4dhcpParms.useNtpServers;
- }
- else if (v6dhcpParms.useNtpServers)
- {
- nextNTP = *v6dhcpParms.useNtpServers;
- }
- else
- {
- nextNTP = ethData.ntpEnabled;
+ nextNTPv6 = *v6dhcpParms.useNtpServers;
}
- bool nextUseDomain{};
- if (v4dhcpParms.useDomainName && v6dhcpParms.useDomainName)
+ bool nextUsev4Domain = ethData.hostNamev4Enabled;
+ bool nextUsev6Domain = ethData.hostNamev6Enabled;
+ if (v4dhcpParms.useDomainName)
{
- if (*v4dhcpParms.useDomainName != *v6dhcpParms.useDomainName)
- {
- messages::generalError(asyncResp->res);
- return;
- }
- nextUseDomain = *v4dhcpParms.useDomainName;
+ nextUsev4Domain = *v4dhcpParms.useDomainName;
}
- else if (v4dhcpParms.useDomainName)
+ if (v6dhcpParms.useDomainName)
{
- nextUseDomain = *v4dhcpParms.useDomainName;
- }
- else if (v6dhcpParms.useDomainName)
- {
- nextUseDomain = *v6dhcpParms.useDomainName;
- }
- else
- {
- nextUseDomain = ethData.hostNameEnabled;
+ nextUsev6Domain = *v6dhcpParms.useDomainName;
}
BMCWEB_LOG_DEBUG("set DHCPEnabled...");
setDHCPEnabled(ifaceId, "DHCPEnabled", nextv4DHCPState, nextv6DHCPState,
asyncResp);
BMCWEB_LOG_DEBUG("set DNSEnabled...");
- setDHCPv4Config("DNSEnabled", nextDNS, asyncResp);
+ setDHCPConfig("DNSEnabled", nextDNSv4, asyncResp, ifaceId,
+ NetworkType::dhcp4);
BMCWEB_LOG_DEBUG("set NTPEnabled...");
- setDHCPv4Config("NTPEnabled", nextNTP, asyncResp);
+ setDHCPConfig("NTPEnabled", nextNTPv4, asyncResp, ifaceId,
+ NetworkType::dhcp4);
BMCWEB_LOG_DEBUG("set HostNameEnabled...");
- setDHCPv4Config("HostNameEnabled", nextUseDomain, asyncResp);
+ setDHCPConfig("HostNameEnabled", nextUsev4Domain, asyncResp, ifaceId,
+ NetworkType::dhcp4);
+ BMCWEB_LOG_DEBUG("set DNSEnabled for dhcp6...");
+ setDHCPConfig("DNSEnabled", nextDNSv6, asyncResp, ifaceId,
+ NetworkType::dhcp6);
+ BMCWEB_LOG_DEBUG("set NTPEnabled for dhcp6...");
+ setDHCPConfig("NTPEnabled", nextNTPv6, asyncResp, ifaceId,
+ NetworkType::dhcp6);
+ BMCWEB_LOG_DEBUG("set HostNameEnabled for dhcp6...");
+ setDHCPConfig("HostNameEnabled", nextUsev6Domain, asyncResp, ifaceId,
+ NetworkType::dhcp6);
}
inline std::vector<IPv4AddressData>::const_iterator getNextStaticIpEntry(
@@ -1595,16 +1638,15 @@
jsonResponse["MACAddress"] = ethData.macAddress;
jsonResponse["DHCPv4"]["DHCPEnabled"] =
translateDhcpEnabledToBool(ethData.dhcpEnabled, true);
- jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpEnabled;
- jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsEnabled;
- jsonResponse["DHCPv4"]["UseDomainName"] = ethData.hostNameEnabled;
-
+ jsonResponse["DHCPv4"]["UseNTPServers"] = ethData.ntpv4Enabled;
+ jsonResponse["DHCPv4"]["UseDNSServers"] = ethData.dnsv4Enabled;
+ jsonResponse["DHCPv4"]["UseDomainName"] = ethData.hostNamev4Enabled;
jsonResponse["DHCPv6"]["OperatingMode"] =
translateDhcpEnabledToBool(ethData.dhcpEnabled, false) ? "Enabled"
: "Disabled";
- jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpEnabled;
- jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsEnabled;
- jsonResponse["DHCPv6"]["UseDomainName"] = ethData.hostNameEnabled;
+ jsonResponse["DHCPv6"]["UseNTPServers"] = ethData.ntpv6Enabled;
+ jsonResponse["DHCPv6"]["UseDNSServers"] = ethData.dnsv6Enabled;
+ jsonResponse["DHCPv6"]["UseDomainName"] = ethData.hostNamev6Enabled;
jsonResponse["StatelessAddressAutoConfig"]["IPv6AutoConfigEnabled"] =
ethData.ipv6AcceptRa;