Fix the same static IP setting from DHCP

When the BMC already has a DHCP IP address, and we set the same static
IP address, it fails.

It is because the AddressMap is a std::map and the code was using
emplace() to add the new created IP address. If the address is already
in the map, the emplace() does not replace the object but does nothing.

Change the emplace() to insert_or_assign(), so that the newly created IP
address is added into the map.

Resolves: openbmc/phosphor-networkd#38
Tested: Verify the static IP address could be set.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Ic6756c81c4981589c8bbe88e990304ed1df6b59a
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index 3e891c6..4f0ceab 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -232,11 +232,11 @@
         std::string ipAddressObjectPath = generateObjectPath(
             addressType, addr.ipaddress, addr.prefix, gateway);
 
-        this->addrs.emplace(addr.ipaddress,
-                            std::make_shared<phosphor::network::IPAddress>(
-                                bus, ipAddressObjectPath.c_str(), *this,
-                                addressType, addr.ipaddress, origin,
-                                addr.prefix, gateway));
+        this->addrs.insert_or_assign(
+            addr.ipaddress,
+            std::make_shared<phosphor::network::IPAddress>(
+                bus, ipAddressObjectPath.c_str(), *this, addressType,
+                addr.ipaddress, origin, addr.prefix, gateway));
     }
 }
 
@@ -278,7 +278,6 @@
 ObjectPath EthernetInterface::ip(IP::Protocol protType, std::string ipaddress,
                                  uint8_t prefixLength, std::string gateway)
 {
-
     if (dhcpIsEnabled(protType))
     {
         log<level::INFO>("DHCP enabled on the interface"),
@@ -312,10 +311,10 @@
 
     std::string objectPath =
         generateObjectPath(protType, ipaddress, prefixLength, gateway);
-    this->addrs.emplace(ipaddress,
-                        std::make_shared<phosphor::network::IPAddress>(
-                            bus, objectPath.c_str(), *this, protType, ipaddress,
-                            origin, prefixLength, gateway));
+    this->addrs.insert_or_assign(ipaddress,
+                                 std::make_shared<phosphor::network::IPAddress>(
+                                     bus, objectPath.c_str(), *this, protType,
+                                     ipaddress, origin, prefixLength, gateway));
 
     manager.writeToConfigurationFile();
     return objectPath;