interfaces: add a mapped newwanip event to avoid multiple reloads

Some services are global so calling them to reconfigure for each interface
is suboptimal.  We can move these to a mapped event with all the interfaces
to reload at once which avoids useless cycles and race conditions.
This commit is contained in:
Franco Fichtner 2024-08-22 16:44:13 +02:00
parent 87147a6e05
commit 364f938c02
3 changed files with 8 additions and 11 deletions

View File

@ -33,7 +33,7 @@ function webgui_configure()
return [
'early' => ['webgui_configure_do'],
'local' => ['webgui_configure_do'],
'newwanip' => ['webgui_configure_do:2'],
'newwanip_map' => ['webgui_configure_do:2'],
'webgui' => ['webgui_configure_do'],
];
}
@ -56,7 +56,7 @@ function webgui_configure_defer($verbose = false, $sleep = 3)
service_log("deferred.\n", $verbose);
}
function webgui_configure_do($verbose = false, $interface = '')
function webgui_configure_do($verbose = false, $interface_map = '')
{
global $config;
@ -67,15 +67,11 @@ function webgui_configure_do($verbose = false, $interface = '')
array_unshift($interfaces, 'lo0');
}
/* 'newwanip' configuration is the only event to take second argument */
if (!empty($interface)) {
if (in_array($interface, $interfaces)) {
/* funnel through configd to avoid race conditions */
webgui_configure_defer($verbose, 0);
/* 'newwanip_map' configuration is the only event to take second argument */
if (!empty($interface_map)) {
if (!count(array_intersect($interface_map, $interfaces)) {
return;
}
/* nothing else to do */
return;
}
service_log('Starting web GUI...', $verbose);

View File

@ -117,4 +117,5 @@ if (is_ipaddr($cacheip) && $ip != $cacheip) {
plugins_configure('vpn', false, [$interface]);
plugins_configure('newwanip', false, [$interface, 'inet']);
plugins_configure('newwanip_map', false, [$interface, 'inet']);
rrd_configure();

View File

@ -118,7 +118,6 @@ switch (isset($config['system']['ipv6allow']) ? ($config['interfaces'][$interfac
interfaces_restart_by_device(false, array_merge($greifs, $gififs));
/* XXX handling reloads for tracked interfaces is difficult, for now reload multiple times */
$interfaces = array_keys(link_interface_to_track6($interface, true));
array_unshift($interfaces, $interface);
@ -133,4 +132,5 @@ foreach ($interfaces as $interface) {
plugins_configure('newwanip', false, [$interface, 'inet6']);
}
plugins_configure('newwanip_map', false, [join(',' $interfaces), 'inet6']);
rrd_configure();