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) ...@@ -179,7 +179,7 @@ function write_config($desc = '', $backup = true)
if (function_exists('plugins_interfaces')) { if (function_exists('plugins_interfaces')) {
/* only pull plugins if plugins.inc was included before */ /* only pull plugins if plugins.inc was included before */
plugins_interfaces(false); plugins_interfaces();
} }
$cnf = OPNsense\Core\Config::getInstance(); $cnf = OPNsense\Core\Config::getInstance();
......
...@@ -94,11 +94,20 @@ function plugins_syslog() ...@@ -94,11 +94,20 @@ function plugins_syslog()
* Every <plugin>_interface should return a named array containing the interface unique identifier and properties. * 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; 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 // register / update interfaces
foreach (plugins_scan() as $name => $path) { foreach (plugins_scan() as $name => $path) {
...@@ -107,8 +116,9 @@ function plugins_interfaces($write_allowed = true) ...@@ -107,8 +116,9 @@ function plugins_interfaces($write_allowed = true)
if (function_exists($func)) { if (function_exists($func)) {
foreach ($func() as $intf_ref => $intf_data) { foreach ($func() as $intf_ref => $intf_data) {
if (is_array($intf_data)) { if (is_array($intf_data)) {
if (!in_array($intf_ref, $registered_interfaces)) { // mark interface used
$registered_interfaces[] = $intf_ref; if (isset($stale_interfaces[$intf_ref])) {
unset($stale_interfaces[$intf_ref]);
} }
if (empty($config['interfaces'][$intf_ref])) { if (empty($config['interfaces'][$intf_ref])) {
$config['interfaces'][$intf_ref] = array(); $config['interfaces'][$intf_ref] = array();
...@@ -124,9 +134,6 @@ function plugins_interfaces($write_allowed = true) ...@@ -124,9 +134,6 @@ function plugins_interfaces($write_allowed = true)
foreach ($intf_data as $prop_name => $prop_value) { foreach ($intf_data as $prop_name => $prop_value) {
if ((empty($intf_config[$prop_name]) && !empty($prop_value)) || $intf_config[$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; $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) ...@@ -135,19 +142,11 @@ function plugins_interfaces($write_allowed = true)
} }
// cleanup registrations // cleanup registrations
if (isset($config['interfaces'])) { foreach ($stale_interfaces as $intf_ref => $no_data) {
foreach ($config['interfaces'] as $intf => $intf_data) { if (isset($config['interfaces'][$intf_ref])) {
if ((!empty($intf_data['internal_dynamic']) || !empty($intf_data[0]['internal_dynamic'])) && !in_array($intf, $registered_interfaces)) { unset($config['interfaces'][$intf_ref]);
$changed_interfaces[] = $intf;
unset($config['interfaces'][$intf]);
}
} }
} }
// configuration changed, materialize
if ($write_allowed && count($changed_interfaces) > 0) {
write_config();
}
} }
function plugins_configure() function plugins_configure()
......
...@@ -193,7 +193,6 @@ echo "done.\n"; ...@@ -193,7 +193,6 @@ echo "done.\n";
system_resolvconf_generate(); system_resolvconf_generate();
/* setup pf */ /* setup pf */
plugins_interfaces();
filter_configure_sync(); filter_configure_sync();
/* start pflog */ /* start pflog */
......
...@@ -36,5 +36,4 @@ require_once("interfaces.inc"); ...@@ -36,5 +36,4 @@ require_once("interfaces.inc");
require_once("services.inc"); require_once("services.inc");
require_once("plugins.inc"); require_once("plugins.inc");
plugins_interfaces();
filter_configure_sync(); filter_configure_sync();
...@@ -222,5 +222,4 @@ if (!is_ipaddr($oldip) || $curwanip != $oldip || !is_ipaddrv4($config['interface ...@@ -222,5 +222,4 @@ if (!is_ipaddr($oldip) || $curwanip != $oldip || !is_ipaddrv4($config['interface
} }
/* reload filter, don't try to sync to carp slave */ /* reload filter, don't try to sync to carp slave */
plugins_interfaces();
filter_configure_sync(); filter_configure_sync();
...@@ -60,5 +60,4 @@ mwexec_bg('/usr/local/etc/rc.sshd'); ...@@ -60,5 +60,4 @@ mwexec_bg('/usr/local/etc/rc.sshd');
mwexec_bg('/usr/local/etc/rc.restart_webgui'); mwexec_bg('/usr/local/etc/rc.restart_webgui');
log_error("rc.reload_all: Reloading filter configuration."); log_error("rc.reload_all: Reloading filter configuration.");
plugins_interfaces();
filter_configure_sync(); 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