ipaddress: Refactor object creation
Change-Id: Icae934e3dc88d596812b75a31598636ae7b95823
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/ethernet_interface.hpp b/src/ethernet_interface.hpp
index 462937f..d7342a8 100644
--- a/src/ethernet_interface.hpp
+++ b/src/ethernet_interface.hpp
@@ -91,6 +91,12 @@
bool emitSignal = true,
std::optional<bool> enabled = std::nullopt);
+ /** @brief Network Manager object. */
+ Manager& manager;
+
+ /** @brief Persistent map of IPAddress dbus objects and their names */
+ std::unordered_map<IfAddr, std::unique_ptr<IPAddress>> addrs;
+
/** @brief Updates the interface information based on new InterfaceInfo */
void updateInfo(const system::InterfaceInfo& info);
@@ -120,11 +126,6 @@
/* @brief delete the dbus object of the given ipAddress.
* @param[in] ipAddress - IP address.
*/
- void deleteObject(std::string_view ipAddress);
-
- /* @brief delete the dbus object of the given ipAddress.
- * @param[in] ipAddress - IP address.
- */
void deleteStaticNeighborObject(std::string_view ipAddress);
/* @brief creates the dbus object(IPaddres) given in the address list.
@@ -137,14 +138,6 @@
*/
void createStaticNeighborObjects();
- /* @brief Gets all the ip addresses.
- * @returns the list of ipAddress.
- */
- inline const auto& getAddresses() const
- {
- return addrs;
- }
-
/* @brief Gets all the static neighbor entries.
* @returns Static neighbor map.
*/
@@ -161,6 +154,19 @@
using EthernetInterfaceIntf::dhcp6;
bool dhcp6(bool value) override;
+ inline bool dhcpIsEnabled(in_addr) const
+ {
+ return dhcp4();
+ }
+ inline bool dhcpIsEnabled(in6_addr) const
+ {
+ return dhcp6();
+ }
+ inline bool dhcpIsEnabled(InAddrAny addr) const
+ {
+ return std::visit([&](auto v) { return dhcpIsEnabled(v); }, addr);
+ }
+
/** Retrieve Link State */
bool linkUp() const override;
@@ -264,12 +270,6 @@
/** @brief Persistent sdbusplus DBus bus connection. */
sdbusplus::bus_t& bus;
- /** @brief Network Manager object. */
- Manager& manager;
-
- /** @brief Persistent map of IPAddress dbus objects and their names */
- string_umap<std::unique_ptr<IPAddress>> addrs;
-
/** @brief Persistent map of Neighbor dbus objects and their names */
string_umap<std::unique_ptr<Neighbor>> staticNeighbors;
@@ -299,12 +299,6 @@
const config::Parser& config, bool emitSignal,
std::optional<bool> enabled);
- /** @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(IP::Protocol protocol);
-
/** @brief Determines if the address is manually assigned
* @param[in] origin - The origin entry of the IP::Address
* @returns true/false value if the address is static