interfaces: prefer GUAs over ULAs when returning addresses

The concept is a bit convoluted, but apparently better than
ignoring the fact that a ULA cannot replace a GUA ever.

PR: https://forum.opnsense.org/index.php?topic=36893.0
This commit is contained in:
Franco Fichtner 2023-11-10 13:37:08 +01:00
parent 2bff035b73
commit 0adf8a2bb0

View File

@ -4357,6 +4357,7 @@ function interfaces_addresses($interfaces, $as_subnet = false, $ifconfig_details
'key' => $key,
'name' => $realif,
'scope' => !empty($address['link-local']),
'unique' => ($proto == 'ipv4' || !empty($address['link-local'])) ? false : is_uniquelocal($address['ipaddr']),
];
}
}
@ -4397,6 +4398,11 @@ function interfaces_addresses($interfaces, $as_subnet = false, $ifconfig_details
}
}
/* move ULAs to the bottom to prefer GUA addresses */
usort($result, function ($a, $b) {
return $a['unique'] - $b['unique'];
});
return $result;
}
@ -4462,7 +4468,7 @@ function _interfaces_primary_address6($interface, $ifconfig_details = null, $all
if ($link_local && !$addr['scope']) {
continue;
} elseif (!$link_local && ($addr['scope'] || is_uniquelocal($addr['address']))) {
} elseif (!$link_local && $addr['scope']) {
continue;
}