Fix Validate default gateway

Prior to this patch we did't have any code in place to validate
the given dafault gateway.
We need to support multiple default gateways to support dual
stack(ipv4/ipv6).
Currently we only supports ipv4 so here we validate gw only for ipv4.
Opened new issue: https://github.com/openbmc/openbmc/issues/2570 to
support ipv6.

Resolves openbmc/openbmc#2520

Change-Id: Ia84cb185b28966e651597666ad71d58a67dd78b9
Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
diff --git a/system_configuration.cpp b/system_configuration.cpp
index 7913b96..562c88c 100644
--- a/system_configuration.cpp
+++ b/system_configuration.cpp
@@ -95,11 +95,19 @@
 
 std::string SystemConfiguration::defaultGateway(std::string gateway)
 {
-    if (SystemConfigIntf::defaultGateway() == gateway)
+    auto gw = SystemConfigIntf::defaultGateway();
+    if (gw == gateway)
     {
-        return gateway;
+        return gw;
     }
-    auto gw = SystemConfigIntf::defaultGateway(gateway);
+
+    if (!isValidIP(AF_INET, gateway))
+    {
+        log<level::ERR>("Not a valid Gateway",
+            entry("GATEWAY=%s", gateway.c_str()));
+        return gw;
+    }
+    gw = SystemConfigIntf::defaultGateway(gateway);
     manager.writeToConfigurationFile();
     return gw;
 }