Add DHCP functionalities to hypervisor eth interfaces
This commit adds methods that provides dhcp functionalities on
the ethernet interface like - disable dhcp on an ethernet interface,
to check if dhcp is enabled on an interface.
Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: Ic713782d48c4c3cc1e1d029212b3ecf7ff5f39ad
diff --git a/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.cpp b/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.cpp
index 84c9598..8f5aac9 100644
--- a/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.cpp
+++ b/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.cpp
@@ -14,5 +14,81 @@
return manager.getBIOSTableAttrs();
}
+bool HypEthInterface::ipv6AcceptRA(bool value)
+{
+ auto currValue = ipv6AcceptRA();
+ if (currValue != value)
+ {
+ HypEthernetIntf::ipv6AcceptRA(value);
+ }
+ return value;
+}
+
+bool HypEthInterface::dhcp4(bool value)
+{
+ auto currValue = dhcp4();
+ if (currValue != value)
+ {
+ HypEthernetIntf::dhcp4(value);
+ }
+ return value;
+}
+
+bool HypEthInterface::dhcp6(bool value)
+{
+ auto currValue = dhcp6();
+ if (currValue != value)
+ {
+ HypEthernetIntf::dhcp6(value);
+ }
+ return value;
+}
+
+bool HypEthInterface::dhcpIsEnabled(HypIP::Protocol family)
+{
+ switch (family)
+ {
+ case HypIP::Protocol::IPv6:
+ return dhcp6();
+ case HypIP::Protocol::IPv4:
+ return dhcp4();
+ }
+ throw std::logic_error("Unreachable");
+}
+
+HypEthInterface::DHCPConf HypEthInterface::dhcpEnabled(DHCPConf value)
+{
+ auto old4 = HypEthernetIntf::dhcp4();
+ auto new4 = HypEthernetIntf::dhcp4(value == DHCPConf::v4 ||
+ value == DHCPConf::v4v6stateless ||
+ value == DHCPConf::both);
+ auto old6 = HypEthernetIntf::dhcp6();
+ auto new6 = HypEthernetIntf::dhcp6(value == DHCPConf::v6 ||
+ value == DHCPConf::both);
+ auto oldra = HypEthernetIntf::ipv6AcceptRA();
+ auto newra = HypEthernetIntf::ipv6AcceptRA(
+ value == DHCPConf::v6stateless || value == DHCPConf::v4v6stateless ||
+ value == DHCPConf::v6 || value == DHCPConf::both);
+
+ if (old4 != new4 || old6 != new6 || oldra != newra)
+ {
+ HypEthernetIntf::dhcpEnabled(value);
+ }
+ return value;
+}
+
+HypEthInterface::DHCPConf HypEthInterface::dhcpEnabled() const
+{
+ if (dhcp6())
+ {
+ return dhcp4() ? DHCPConf::both : DHCPConf::v6;
+ }
+ else if (dhcp4())
+ {
+ return ipv6AcceptRA() ? DHCPConf::v4v6stateless : DHCPConf::v4;
+ }
+ return ipv6AcceptRA() ? DHCPConf::v6stateless : DHCPConf::none;
+}
+
} // namespace network
} // namespace phosphor
diff --git a/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.hpp b/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.hpp
index d2e3b8b..557db96 100644
--- a/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.hpp
+++ b/src/ibm/hypervisor-network-mgr-src/hyp_ethernet_interface.hpp
@@ -77,6 +77,26 @@
*/
biosTableType getBiosAttrsMap();
+ /* @brief Returns the dhcp enabled property
+ * @param[in] protocol - ipv4/ipv6
+ * @return bool - true if dhcpEnabled
+ */
+ bool isDHCPEnabled(HypIP::Protocol protocol);
+
+ /** Set value of DHCPEnabled */
+ HypEthernetIntf::DHCPConf dhcpEnabled() const override;
+ HypEthernetIntf::DHCPConf dhcpEnabled(DHCPConf value) override;
+ using HypEthernetIntf::dhcp4;
+ bool dhcp4(bool value) override;
+ using HypEthernetIntf::dhcp6;
+ bool dhcp6(bool value) override;
+
+ /** @brief check conf file for Router Advertisements
+ *
+ */
+ bool ipv6AcceptRA(bool value) override;
+ using HypEthernetIntf::ipv6AcceptRA;
+
using HypEthernetIntf::interfaceName;
protected:
@@ -88,6 +108,13 @@
/** @brief Parent of this object */
HypNetworkMgr& manager;
+
+ private:
+ /** @brief Determines if DHCP is active for the IP::Protocol supplied.
+ * @param[in] protocol - Either IPv4 or IPv6
+ * @returns true/false value if DHCP is active for the input protocol
+ */
+ bool dhcpIsEnabled(HypIP::Protocol protocol);
};
} // namespace network