Commit de06bf97 authored by Franco Fichtner's avatar Franco Fichtner

plugins: do not call write_config() in plugins_interfaces()

Since we weaved the latter into the former, we can now get rid of
the transition code.  The behaviour doesn't change.

(cherry picked from commit 927f4e0e)
(cherry picked from commit 0b119652)
parent 45f04f5f
......@@ -179,7 +179,7 @@ function write_config($desc = '', $backup = true)
if (function_exists('plugins_interfaces')) {
/* only pull plugins if plugins.inc was included before */
plugins_interfaces(false);
plugins_interfaces();
}
$cnf = OPNsense\Core\Config::getInstance();
......
......@@ -94,11 +94,20 @@ function plugins_syslog()
* Every <plugin>_interface should return a named array containing the interface unique identifier and properties.
*
*/
function plugins_interfaces($write_allowed = true)
function plugins_interfaces()
{
global $config;
$changed_interfaces = array();
$registered_interfaces = array();
$stale_interfaces = array();
// mark previous dynamic registrations stale
if (isset($config['interfaces'])) {
foreach ($config['interfaces'] as $intf_ref => $intf_data) {
if (isset($intf_data[0]['internal_dynamic']) || isset($intf_data['internal_dynamic'])) {
$stale_interfaces[$intf_ref] = 1;
}
}
}
// register / update interfaces
foreach (plugins_scan() as $name => $path) {
......@@ -107,8 +116,9 @@ function plugins_interfaces($write_allowed = true)
if (function_exists($func)) {
foreach ($func() as $intf_ref => $intf_data) {
if (is_array($intf_data)) {
if (!in_array($intf_ref, $registered_interfaces)) {
$registered_interfaces[] = $intf_ref;
// mark interface used
if (isset($stale_interfaces[$intf_ref])) {
unset($stale_interfaces[$intf_ref]);
}
if (empty($config['interfaces'][$intf_ref])) {
$config['interfaces'][$intf_ref] = array();
......@@ -124,9 +134,6 @@ function plugins_interfaces($write_allowed = true)
foreach ($intf_data as $prop_name => $prop_value) {
if ((empty($intf_config[$prop_name]) && !empty($prop_value)) || $intf_config[$prop_name] != $prop_value) {
$intf_config[$prop_name] = $prop_value;
if (!in_array($intf_ref, $changed_interfaces)) {
$changed_interfaces[] = $intf_ref;
}
}
}
}
......@@ -135,19 +142,11 @@ function plugins_interfaces($write_allowed = true)
}
// cleanup registrations
if (isset($config['interfaces'])) {
foreach ($config['interfaces'] as $intf => $intf_data) {
if ((!empty($intf_data['internal_dynamic']) || !empty($intf_data[0]['internal_dynamic'])) && !in_array($intf, $registered_interfaces)) {
$changed_interfaces[] = $intf;
unset($config['interfaces'][$intf]);
}
foreach ($stale_interfaces as $intf_ref => $no_data) {
if (isset($config['interfaces'][$intf_ref])) {
unset($config['interfaces'][$intf_ref]);
}
}
// configuration changed, materialize
if ($write_allowed && count($changed_interfaces) > 0) {
write_config();
}
}
function plugins_configure()
......
......@@ -193,7 +193,6 @@ echo "done.\n";
system_resolvconf_generate();
/* setup pf */
plugins_interfaces();
filter_configure_sync();
/* start pflog */
......
......@@ -36,5 +36,4 @@ require_once("interfaces.inc");
require_once("services.inc");
require_once("plugins.inc");
plugins_interfaces();
filter_configure_sync();
......@@ -222,5 +222,4 @@ if (!is_ipaddr($oldip) || $curwanip != $oldip || !is_ipaddrv4($config['interface
}
/* reload filter, don't try to sync to carp slave */
plugins_interfaces();
filter_configure_sync();
......@@ -60,5 +60,4 @@ mwexec_bg('/usr/local/etc/rc.sshd');
mwexec_bg('/usr/local/etc/rc.restart_webgui');
log_error("rc.reload_all: Reloading filter configuration.");
plugins_interfaces();
filter_configure_sync();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment