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.
This commit is contained in:
NOYB 2017-02-05 02:01:29 -08:00 committed by Renato Botelho
parent e90c506f3b
commit a822576e9b
2 changed files with 7 additions and 9 deletions

View File

@ -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;

View File

@ -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");
}