VPN: WireGuard - support carp vhid reuse on different interfaces, closes https://github.com/opnsense/core/issues/7773

Although all our examples always use vhid as a unique key per firewall, it is possible to add the same vhid to different interfaces.
When "disable preempt" is not selected, eventually all of them will switch between master/backup at the same time anyway, so we can assume all virtual ips switch simultaneously.

If preempt is disabled, our vhid matching might not be perfect, but likely better than before.
This commit is contained in:
Ad Schellevis 2024-08-14 21:44:45 +02:00
parent ef5a59f5e4
commit f477fa13b8

View File

@ -39,18 +39,18 @@ require_once('system.inc');
function get_vhid_status()
{
$vhids = [];
$uuids = [];
foreach ((new OPNsense\Interfaces\Vip())->vip->iterateItems() as $id => $item) {
if ($item->mode == 'carp') {
$uuids[(string)$item->vhid] = $id;
$vhids[$id] = ['status' => 'DISABLED', 'vhid' => (string)$item->vhid];
}
}
foreach (legacy_interfaces_details() as $ifdata) {
if (!empty($ifdata['carp'])) {
foreach ($ifdata['carp'] as $data) {
if (isset($uuids[$data['vhid']])) {
$vhids[$uuids[$data['vhid']]] = ['status' => $data['status'], 'vhid' => $data['vhid']];
foreach ($vhids as $id => &$item) {
if ($item['vhid'] == $data['vhid']) {
$item['status'] = $data['status'];
}
}
}
}