From a822576e9b3d563eff0791c9d43350e0feef9442 Mon Sep 17 00:00:00 2001 From: NOYB Date: Sun, 5 Feb 2017 02:01:29 -0800 Subject: [PATCH] Vendor MAC Retention File Consolidate Use a single file for vendor MAC retention (vendor_mac). a) Writes only one file during boot up rather than a file for each interface. b) More efficient than numerous tiny files. c) Friendlier to write cycle sensitive media in a RAM disk disabled system. --- src/etc/inc/interfaces.inc | 8 +++----- src/etc/rc.bootup | 8 ++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index a1a6d3b422..277f98bfb3 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -5862,12 +5862,10 @@ function get_interface_vendor_mac($interface) { global $g; $mac = ""; - $mac_file = "{$g['vardb_path']}/vendor_mac_($interface)"; + $mac_file = "{$g['vardb_path']}/vendor_mac"; if (file_exists($mac_file)) { - $mac = file_get_contents($mac_file); - if (!is_macaddr($mac)) { - $mac = ""; - } + $vendor_mac_arr = json_decode(file_get_contents($mac_file), true); + $mac = (is_macaddr($vendor_mac_arr[$interface])) ? $vendor_mac_arr[$interface] : ''; } return $mac; diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index c084e890ba..c175214543 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -190,7 +190,7 @@ echo "done.\n"; if (mwexec("/bin/kenv -q pfSense.boot 2>/dev/null") != 0) { /* Collect vendor MAC address for all interfaces */ $ifs = pfSense_interface_listget(); - unlink_if_exists("{$g['vardb_path']}/vendor_mac_*"); + unlink_if_exists("{$g['vardb_path']}/vendor_mac"); foreach ($ifs as $if) { $if_details = pfSense_get_interface_addresses($if); if (isset($if_details['iftype']) && @@ -203,10 +203,10 @@ if (mwexec("/bin/kenv -q pfSense.boot 2>/dev/null") != 0) { continue; } - @file_put_contents("{$g['vardb_path']}/vendor_mac_{$if}", - $if_details['macaddr']); + $vendor_mac_arr[$if] = $if_details['macaddr']; } - unset($ifs, $if); + @file_put_contents("{$g['vardb_path']}/vendor_mac", json_encode($vendor_mac_arr)); + unset($ifs, $if, $vendor_mac_arr); mwexec("/bin/kenv pfSense.boot=1"); }