Fix the getLan config

We did the filtering during IPAddress parameter
to avoid link local address but left it for subnetMask
and vlan parameter.
With the introduction of zeroconfig IP we have
multiIPaddress can exist on the interface.
This commit introduces the filtering for subnetmask and
vlan parameter also.

Resolves openbmc/openbmc#2664

Change-Id: I244bfe8b9d7efbf55fc1b7051489a8a204182906
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/app/channel.cpp b/app/channel.cpp
index 72f1571..91d9987 100644
--- a/app/channel.cpp
+++ b/app/channel.cpp
@@ -97,10 +97,11 @@
 
                 // if the system is having ip object,then
                 // get the IP object.
-                ipObject = ipmi::getDbusObject(bus,
-                                               ipmi::network::IP_INTERFACE,
-                                               ipmi::network::ROOT,
-                                               ipmi::network::IP_TYPE);
+                ipObject = ipmi::getIPObject(
+                                bus,
+                                ipmi::network::IP_INTERFACE,
+                                ipmi::network::ROOT,
+                                ipmi::network::IP_TYPE);
 
                 // Get the parent interface of the IP object.
                 try
@@ -196,11 +197,8 @@
                             ipmi::network::IP_INTERFACE);
 
                     ipaddress = channelConfig.ipaddr.empty() ?
-                                ipmi::getIPAddress(bus,
-                                                   ipmi::network::IP_INTERFACE,
-                                                   ipmi::network::ROOT,
-                                                   ipmi::network::IP_TYPE) :
-                                channelConfig.ipaddr;
+                        properties["Address"].get<std::string>() :
+                        channelConfig.ipaddr;
 
                     prefix = channelConfig.netmask.empty() ?
                         properties["PrefixLength"].get<uint8_t>() :
diff --git a/transporthandler.cpp b/transporthandler.cpp
index a90891a..50bc473 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -49,10 +49,19 @@
                 {
                     try
                     {
-                        ipaddress = ipmi::getIPAddress(bus,
-                                                       ipmi::network::IP_INTERFACE,
-                                                       ipmi::network::ROOT,
-                                                       ipmi::network::IP_TYPE);
+                        auto ipObjectInfo = ipmi::getIPObject(
+                                bus,
+                                ipmi::network::IP_INTERFACE,
+                                ipmi::network::ROOT,
+                                ipmi::network::IP_TYPE);
+
+                        auto properties = ipmi::getAllDbusProperties(
+                                bus,
+                                ipObjectInfo.second,
+                                ipObjectInfo.first,
+                                ipmi::network::IP_INTERFACE);
+
+                        ipaddress = properties["Address"].get<std::string>();
 
                     }
                     // ignore the exception, as it is a valid condtion that
@@ -158,7 +167,7 @@
                 {
                     try
                     {
-                        auto ipObjectInfo = ipmi::getDbusObject(
+                        auto ipObjectInfo = ipmi::getIPObject(
                                 bus,
                                 ipmi::network::IP_INTERFACE,
                                 ipmi::network::ROOT,
@@ -273,7 +282,7 @@
                 {
                     try
                     {
-                        auto ipObjectInfo = ipmi::getDbusObject(
+                        auto ipObjectInfo = ipmi::getIPObject(
                                 bus,
                                 ipmi::network::IP_INTERFACE,
                                 ipmi::network::ROOT,
diff --git a/utils.cpp b/utils.cpp
index ea3a6aa..fa6bd04 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -96,10 +96,10 @@
 
 }
 
-std::string getIPAddress(sdbusplus::bus::bus& bus,
-                         const std::string& interface,
-                         const std::string& serviceRoot,
-                         const std::string& match)
+DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus,
+                           const std::string& interface,
+                           const std::string& serviceRoot,
+                           const std::string& match)
 {
     auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, match);
 
@@ -110,7 +110,7 @@
         elog<InternalFailure>();
     }
 
-    std::string ipaddress;
+    DbusObjectInfo objectInfo;
 
     for (auto& object : objectTree)
     {
@@ -121,10 +121,10 @@
                            ipmi::network::IP_INTERFACE,
                            "Address");
 
-        ipaddress = std::move(variant.get<std::string>());
+        objectInfo =  std::make_pair(object.first, object.second.begin()->first);
 
         // if LinkLocalIP found look for Non-LinkLocalIP
-        if (ipmi::network::isLinkLocalIP(ipaddress))
+        if (ipmi::network::isLinkLocalIP(variant.get<std::string>()))
         {
             continue;
         }
@@ -132,11 +132,8 @@
         {
             break;
         }
-
     }
-
-    return ipaddress;
-
+    return objectInfo;
 }
 
 Value getDbusProperty(sdbusplus::bus::bus& bus,
diff --git a/utils.hpp b/utils.hpp
index 0b2b2db..55978fb 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -45,19 +45,19 @@
                              const std::string& subtreePath = ROOT,
                              const std::string& match = {});
 
-/** @brief Gets the ipAddres of first dbus IP object of Non-LinkLocalIPAddress
+/** @brief Get the ipObject of first dbus IP object of Non-LinkLocalIPAddress
  *         type from the given subtree, if not available gets IP object of
  *         LinkLocalIPAddress type.
  *  @param[in] bus - DBUS Bus Object.
  *  @param[in] interface - Dbus interface.
  *  @param[in] subtreePath - subtree from where the search should start.
  *  @param[in] match - identifier for object.
- *  @return On success returns the ipAddress.
+ *  @return On success returns the object having objectpath and servicename.
  */
-std::string getIPAddress(sdbusplus::bus::bus& bus,
-                         const std::string& interface,
-                         const std::string& subtreePath,
-                         const std::string& match);
+DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus,
+                           const std::string& interface,
+                           const std::string& subtreePath,
+                           const std::string& match);
 
 /** @brief Gets the value associated with the given object
  *         and the interface.