ethernet: Add origin to generateId()

Currently the code uses the ip address, prefix, and gateway to generate
the ID of the DBus object.
This results in the same DBus object path for the same IPs while they
have different address origin.
E.g. if we have the DHCP address and assign the same static address, the
DBus object paths are the same and it gets
`org.freedesktop.DBus.Error.FileExists` exception while creating the new
object.

Add origin to generateId() so they generate the two different object
paths and the above issue could be fixed.

Tested: Verify in QEMU that setting static IP is OK from DHCP.

Fixes openbmc/phosphor-networkd#41

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Iafe94cedff7e39490386be7777f3d975f1cf6b3f
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 0f8a3c0..0be63b0 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -235,7 +235,7 @@
         std::string gateway = "";
 
         std::string ipAddressObjectPath = generateObjectPath(
-            addressType, addr.ipaddress, addr.prefix, gateway);
+            addressType, addr.ipaddress, addr.prefix, gateway, origin);
 
         this->addrs.insert_or_assign(
             addr.ipaddress,
@@ -315,7 +315,7 @@
     }
 
     std::string objectPath =
-        generateObjectPath(protType, ipaddress, prefixLength, gateway);
+        generateObjectPath(protType, ipaddress, prefixLength, gateway, origin);
     this->addrs.insert_or_assign(ipaddress,
                                  std::make_shared<phosphor::network::IPAddress>(
                                      bus, objectPath.c_str(), *this, protType,
@@ -426,12 +426,14 @@
 
 std::string EthernetInterface::generateId(const std::string& ipaddress,
                                           uint8_t prefixLength,
-                                          const std::string& gateway)
+                                          const std::string& gateway,
+                                          const std::string& origin)
 {
     std::stringstream hexId;
     std::string hashString = ipaddress;
     hashString += std::to_string(prefixLength);
     hashString += gateway;
+    hashString += origin;
 
     // Only want 8 hex digits.
     hexId << std::hex << ((std::hash<std::string>{}(hashString)) & 0xFFFFFFFF);
@@ -528,7 +530,8 @@
 
 std::string EthernetInterface::generateObjectPath(
     IP::Protocol addressType, const std::string& ipaddress,
-    uint8_t prefixLength, const std::string& gateway) const
+    uint8_t prefixLength, const std::string& gateway,
+    IP::AddressOrigin origin) const
 {
     std::string type = convertForMessage(addressType);
     type = type.substr(type.rfind('.') + 1);
@@ -537,7 +540,8 @@
     std::filesystem::path objectPath;
     objectPath /= objPath;
     objectPath /= type;
-    objectPath /= generateId(ipaddress, prefixLength, gateway);
+    objectPath /=
+        generateId(ipaddress, prefixLength, gateway, convertForMessage(origin));
     return objectPath.string();
 }