From 32c9ad3a4a41137c3a71326c84bcb5c5264315bc Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 25 Mar 2025 14:17:24 +0100 Subject: [PATCH] system: minor consolidation on previous --- src/etc/rc.routing_configure | 7 ++----- src/opnsense/scripts/routes/gateway_watcher.php | 9 ++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/etc/rc.routing_configure b/src/etc/rc.routing_configure index 6bf5322b4..6aafe19c2 100755 --- a/src/etc/rc.routing_configure +++ b/src/etc/rc.routing_configure @@ -37,6 +37,7 @@ exit_on_bootup(); /* when called with an argument we are in gateway switch mode */ $monitor_hook = !empty($argv[1]); +$monitor_gws = $argv[2] ?? ''; /* drop deleted routes */ foreach (glob("/tmp/delete_route_*.todo") as $filename) { @@ -50,11 +51,7 @@ foreach (glob("/tmp/delete_route_*.todo") as $filename) { system_routing_configure(true, null, !$monitor_hook); if ($monitor_hook) { - $cmd = ['/usr/local/etc/rc.syshook monitor']; - for ($i = 2; $i < count($argv); $i++) { - $cmd[] = escapeshellcmd($argv[$i]); - } - passthru(implode(' ', $cmd)); + passthru(exec_safe('/usr/local/etc/rc.syshook monitor %s', $monitor_gws)); } filter_configure_sync(true, false); diff --git a/src/opnsense/scripts/routes/gateway_watcher.php b/src/opnsense/scripts/routes/gateway_watcher.php index f3a06da85..c5db7979d 100755 --- a/src/opnsense/scripts/routes/gateway_watcher.php +++ b/src/opnsense/scripts/routes/gateway_watcher.php @@ -64,7 +64,7 @@ while (1) { continue; } - $alarm = false; + $alarm_gateways = []; /* clear known gateways in first step to flush unknown in second step */ $cleanup = $mode; @@ -76,7 +76,6 @@ while (1) { } /* run main watcher pass */ - $alarm_gateways = []; foreach ($status as $report) { $ralarm = false; @@ -118,9 +117,10 @@ while (1) { } if ($ralarm) { - $alarm = true; + $alarm_gateways[] = $report['name']; } + /* diagnostics block as we may have no $ralarm but still want to log the transition */ if ($mode[$report['name']] != $report['status']) { syslog(LOG_NOTICE, sprintf( "%s: %s (Addr: %s Alarm: %s RTT: %s RTTd: %s Loss: %s)", @@ -132,14 +132,13 @@ while (1) { $report['stddev'], $report['loss'] )); - $alarm_gateways[] = $report['name']; /* update cached state now */ $mode[$report['name']] = $report['status']; } } - if ($alarm && $action != null) { + if (count($alarm_gateways) && $action != null) { configdp_run($action, [implode(',', $alarm_gateways)]); }