diff options
author | Simon Rettberg | 2022-03-23 17:05:25 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-03-23 17:05:25 +0100 |
commit | bd72cb3a16f1697491250e714694125e306c813c (patch) | |
tree | d759f96ac624a38c60216faa5fdc3ea4d856f422 /modules-available/rebootcontrol/inc | |
parent | [passthrough] Fix #hash highlighting of devices (diff) | |
download | slx-admin-bd72cb3a16f1697491250e714694125e306c813c.tar.gz slx-admin-bd72cb3a16f1697491250e714694125e306c813c.tar.xz slx-admin-bd72cb3a16f1697491250e714694125e306c813c.zip |
[rebootcontrol] Add option to override destination broadcast address
Diffstat (limited to 'modules-available/rebootcontrol/inc')
-rw-r--r-- | modules-available/rebootcontrol/inc/rebootcontrol.inc.php | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php index 99e8a4cf..b5f47c1d 100644 --- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php +++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php @@ -11,6 +11,8 @@ class RebootControl const KEY_UDP_PORT = 'rebootcontrol.port'; + const KEY_BROADCAST_ADDRESS = 'rebootcontrol.broadcast-addr'; + const REBOOT = 'REBOOT'; const KEXEC_REBOOT = 'KEXEC_REBOOT'; const SHUTDOWN = 'SHUTDOWN'; @@ -332,6 +334,10 @@ class RebootControl // Determine method for all clients $taskClients = []; // array of arrays with keys [ip, mac, methods] $taskSsh = []; // SSH configs for task, array of arrays with keys [username, sshkey, ip, port, command] + $overrideBroadcast = Property::get(self::KEY_BROADCAST_ADDRESS); + if (empty($overrideBroadcast)) { + $overrideBroadcast = false; + } foreach ($clientList as $client) { $ip = sprintf('%u', ip2long($client['clientip'])); // 32Bit snprintf unset($subnet); @@ -351,6 +357,12 @@ class RebootControl 'mac' => $client['macaddr'], 'methods' => [], ]; + // If we have an override broadcast address, unconditionally add this as the + // first method + if ($overrideBroadcast !== false) { + $c['ip'] = $overrideBroadcast; + $c['methods'][] = 'DIRECT'; + } self::findMachinesForSubnet($subnet); // Highest priority - clients in same subnet, no directed broadcast // required, should be most reliable @@ -361,8 +373,9 @@ class RebootControl self::addSshMethodUsingClient($subnet['iclients'], $c['methods'], $taskSsh); // Jumphosts in other subnets, determined to be able to reach destination subnet self::addSshMethodUsingJumphost($subnet['ijumphosts'], true, $c['methods'], $taskSsh); - // If directly reachable from server, prefer this now - if ($subnet['isdirect']) { + // If directly reachable from server, prefer this now over the questionable approaches below, + // but only if we didn't already add this above because of override + if ($overrideBroadcast === false && $subnet['isdirect']) { $c['methods'][] = 'DIRECT'; } if (empty($c['methods'])) { @@ -370,7 +383,7 @@ class RebootControl } else { // TODO: Remember WOL was attempted } - // Only other fallback is jumphosts that were not reachable when last checked, this is really a last resort + // Last fallback is jumphosts that were not reachable when last checked, this is really a last resort self::addSshMethodUsingJumphost($subnet['djumphosts'], false, $c['methods'], $taskSsh); self::addSshMethodUsingJumphost($subnet['ijumphosts'], false, $c['methods'], $taskSsh); |