Configure DHCP4 and DHCP6 parameters independently
At present, DHCP parameters like DNSEnabled, NTPEnabled etc. are
shared between DHCPv4 and DHCPv6 in the network configuration.
Hence any update on the ipv4 parameters impacts the ipv6 and get
applied to both the interfaces.
This change is to enable the possibility to configure DHCP attributes
independently, by having different dbus objects for dhcp4 and dhcp6
and moving the dhcp configuration from network level to ethernet
interface.
tested by:
Used the busctl command to set and get the parameter values
individually for both DHCPv4 and DHCPv6.
Verified the network configuration file is updated accordingly
Tree Structure:
busctl tree xyz.openbmc_project.Network
`-/xyz
`-/xyz/openbmc_project
`-/xyz/openbmc_project/network
|-/xyz/openbmc_project/network/config
|-/xyz/openbmc_project/network/eth0
| |-/xyz/openbmc_project/network/eth0/dhcp4
| `-/xyz/openbmc_project/network/eth0/dhcp6
`-/xyz/openbmc_project/network/eth1
|-/xyz/openbmc_project/network/eth1/dhcp4
`-/xyz/openbmc_project/network/eth1/dhcp6
Change-Id: If7dbbf596bdaf866ea459d631e716153f54302ec
Signed-off-by: Jishnu CM <jishnunambiarcm@duck.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index bac778f..65ea7ac 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -118,6 +118,7 @@
{
EthernetInterface::defaultGateway6(stdplus::toStr(*info.defgw6), true);
}
+ addDHCPConfigurations();
emit_object_added();
if (info.intf.vlan_id)
@@ -753,17 +754,27 @@
}
}
{
- auto& dhcp = config.map["DHCP"].emplace_back();
- dhcp["ClientIdentifier"].emplace_back("mac");
- const auto& conf = manager.get().getDHCPConf();
+ auto& dhcp4 = config.map["DHCPv4"].emplace_back();
+ dhcp4["ClientIdentifier"].emplace_back("mac");
+ const auto& conf = *dhcpConfigs[static_cast<int>(DHCPType::v4)];
auto dns_enabled = conf.dnsEnabled() ? "true" : "false";
- dhcp["UseDNS"].emplace_back(dns_enabled);
- dhcp["UseDomains"].emplace_back(dns_enabled);
- dhcp["UseNTP"].emplace_back(conf.ntpEnabled() ? "true" : "false");
- dhcp["UseHostname"].emplace_back(conf.hostNameEnabled() ? "true"
- : "false");
- dhcp["SendHostname"].emplace_back(conf.sendHostNameEnabled() ? "true"
- : "false");
+ dhcp4["UseDNS"].emplace_back(dns_enabled);
+ dhcp4["UseDomains"].emplace_back(dns_enabled);
+ dhcp4["UseNTP"].emplace_back(conf.ntpEnabled() ? "true" : "false");
+ dhcp4["UseHostname"].emplace_back(conf.hostNameEnabled() ? "true"
+ : "false");
+ dhcp4["SendHostname"].emplace_back(
+ conf.sendHostNameEnabled() ? "true" : "false");
+ }
+ {
+ auto& dhcp6 = config.map["DHCPv6"].emplace_back();
+ const auto& conf = *dhcpConfigs[static_cast<int>(DHCPType::v6)];
+ auto dns_enabled = conf.dnsEnabled() ? "true" : "false";
+ dhcp6["UseDNS"].emplace_back(dns_enabled);
+ dhcp6["UseDomains"].emplace_back(dns_enabled);
+ dhcp6["UseNTP"].emplace_back(conf.ntpEnabled() ? "true" : "false");
+ dhcp6["UseHostname"].emplace_back(conf.hostNameEnabled() ? "true"
+ : "false");
}
auto path = config::pathForIntfConf(manager.get().getConfDir(),
interfaceName());
@@ -957,5 +968,18 @@
eth.get().manager.get().reloadConfigs();
}
+void EthernetInterface::addDHCPConfigurations()
+{
+ this->dhcpConfigs.emplace_back(std::make_unique<dhcp::Configuration>(
+ bus, objPath + "/dhcp4", *this, DHCPType::v4));
+ this->dhcpConfigs.emplace_back(std::make_unique<dhcp::Configuration>(
+ bus, objPath + "/dhcp6", *this, DHCPType::v6));
+}
+
+void EthernetInterface::reloadConfigs()
+{
+ manager.get().reloadConfigs();
+}
+
} // namespace network
} // namespace phosphor