Fix for not updating invalid MAC to fw_printenv

Invalid MAC was written to the Firmware env on updates.

The current implementation fails to write the trimmed address
for the following testcases:
* AA:FF:FF:FF:FF:100
* AA:AA:AA:AA:AA:AA:BB

Tested-By:

AA:E2:84:14:28:79    -    Valid

AA:FF:FF:FF:FF:100   -    Out of Range MAC
    * This will be written as "AA:FF:FF:FF:FF:10"

AA:AA:AA:AA:AA:AA:BB -    MAC with more tha 6 bytes
    * This will be written as "AA:AA:AA:AA:AA:AA"

a:b:c:d:e:f          -    This will be written as
                          "0a:0b:0c:0d:0e:0f"

0a:0b:0c:0d:0e:0f    -    This will be written as
                          "0a:0b:0c:0d:0e:0f"

Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: I9141365590df05823f0d277a16e01132a3326267
diff --git a/ethernet_interface.cpp b/ethernet_interface.cpp
index eddcb7b..1375637 100644
--- a/ethernet_interface.cpp
+++ b/ethernet_interface.cpp
@@ -1007,6 +1007,7 @@
     }
 
     auto interface = interfaceName();
+    std::string validMAC = mac_address::toString(newMAC);
 
     // We don't need to update the system if the address is unchanged
     ether_addr oldMAC = mac_address::fromString(MacAddressIntf::mACAddress());
@@ -1015,9 +1016,9 @@
         // Update everything that depends on the MAC value
         for (const auto& [name, intf] : vlanInterfaces)
         {
-            intf->MacAddressIntf::mACAddress(value);
+            intf->MacAddressIntf::mACAddress(validMAC);
         }
-        MacAddressIntf::mACAddress(value);
+        MacAddressIntf::mACAddress(validMAC);
 
         // TODO: would remove the call below and
         //      just restart systemd-netwokd
@@ -1032,7 +1033,10 @@
     auto envVar = interfaceToUbootEthAddr(interface.c_str());
     if (envVar)
     {
-        execute("/sbin/fw_setenv", "fw_setenv", envVar->c_str(), value.c_str());
+        // Trimming MAC addresses that are out of range. eg: AA:FF:FF:FF:FF:100;
+        // and those having more than 6 bytes. eg: AA:AA:AA:AA:AA:AA:BB
+        execute("/sbin/fw_setenv", "fw_setenv", envVar->c_str(),
+                validMAC.c_str());
     }
 #endif // HAVE_UBOOT_ENV