plugins: tweak interface plugging

PPPoE wasn't removed, which led to some refactoring to find
out why.  The outcome is the same, but works a little bit
different now.  While there, make it possible to omit the
config write in case we are going to call write_config()
shortly after anyway.

This will also be necessary for the legacy VPN plugins.
This commit is contained in:
Franco Fichtner 2016-08-08 09:04:51 +02:00
parent 7e69508177
commit ecdcc4b736
3 changed files with 24 additions and 17 deletions

View File

@ -94,11 +94,21 @@ function plugins_syslog()
* Every <plugin>_interface should return a named array containing the interface unique identifier and properties.
*
*/
function plugins_interfaces()
function plugins_interfaces($write_config = true)
{
global $config;
$changed_interfaces = array();
$registered_interfaces = array();
$stale_interfaces = array();
$write_required = false;
// 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 +117,9 @@ function plugins_interfaces()
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 +135,7 @@ function plugins_interfaces()
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;
}
$write_required = true;
}
}
}
@ -135,17 +144,15 @@ function plugins_interfaces()
}
// cleanup registrations
if (isset($config['interfaces'])) {
foreach ($config['interfaces'] as $intf => $intf_data) {
if (!empty($intf_data['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]);
$write_required = true;
}
}
// configuration changed, materialize
if (count($changed_interfaces) > 0) {
if ($write_config && $write_required) {
write_config();
}
}

View File

@ -53,8 +53,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
unset($a_ifgroups[$id]);
plugins_interfaces(false);
write_config();
plugins_interfaces();
header("Location: interfaces_groups.php");
exit;
}

View File

@ -125,9 +125,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// add new item
$a_ifgroups[] = $ifgroupentry;
}
plugins_interfaces(false);
write_config();
interface_group_setup($ifgroupentry);
plugins_interfaces();
header("Location: interfaces_groups.php");
exit;
}