network_manager_main: add force-sync-mac option

For the platform has modulized flash (ex: Bletchley), the BMC flash is
not embedded on the board where the MAC address stored. When the
original board get replaced by service, BMC won't sync MAC address
again from new board because the first boot file is existed,and it
cause BMC continue using old MAC address form old board.

Add a force-sync-mac option to force check MAC address regardless first
boot file is exist or not.

Tested on Bletchley, MAC address updated after replacing chassis
controller board.

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I37785f25b3ce0d95d0dd7d9e2f1ad3cd731b83c7
diff --git a/meson.build b/meson.build
index 7b130ec..a38726d 100644
--- a/meson.build
+++ b/meson.build
@@ -21,6 +21,7 @@
   get_option('default-ipv6-accept-ra'))
 conf_data.set('SYNC_MAC_FROM_INVENTORY', get_option('sync-mac'))
 conf_data.set('PERSIST_MAC', get_option('persist-mac'))
+conf_data.set10('FORCE_SYNC_MAC_FROM_INVENTORY', get_option('force-sync-mac'))
 
 sdbusplus_dep = dependency('sdbusplus')
 sdbusplusplus_prog = find_program('sdbus++', native: true)
diff --git a/meson_options.txt b/meson_options.txt
index 83862af..56234e6 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -12,3 +12,6 @@
        description : 'ibm-oem: Enable the hypervisor network manager')
 option('persist-mac', type: 'boolean',
        description: 'Permit the MAC address to be written to the systemd.network config')
+option('force-sync-mac', type: 'boolean',
+       description: 'Force sync mac address no matter is first boot or not')
+
diff --git a/src/network_manager_main.cpp b/src/network_manager_main.cpp
index 8f8a89e..80276b3 100644
--- a/src/network_manager_main.cpp
+++ b/src/network_manager_main.cpp
@@ -218,12 +218,15 @@
     bool registeredSignals = false;
     for (const auto& interfaceString : configJson.items())
     {
-        if (!std::filesystem::exists(firstBootPath + interfaceString.key()) &&
+        if ((FORCE_SYNC_MAC_FROM_INVENTORY ||
+             !std::filesystem::exists(firstBootPath + interfaceString.key())) &&
             !registeredSignals)
         {
-
-            log<level::INFO>(
-                "First boot file is not present, check VPD for MAC");
+            auto msg = fmt::format("{}, check VPD for MAC",
+                                   (FORCE_SYNC_MAC_FROM_INVENTORY)
+                                       ? "Force sync enabled"
+                                       : "First boot file is not present");
+            log<level::INFO>(msg.c_str());
             EthInterfaceMatch = std::make_unique<sdbusplus::bus::match_t>(
                 bus,
                 "interface='org.freedesktop.DBus.ObjectManager',type='signal',"