Skip to content

Commit

Permalink
interfaces: prefer GUAs over ULAs when returning addresses
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 0adf8a2)
(cherry picked from commit 29d456e)
  • Loading branch information
fichtner committed Nov 12, 2023
1 parent dd90cb5 commit cd808e3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4309,6 +4309,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']),
];
}
}
Expand Down Expand Up @@ -4349,6 +4350,11 @@ function interfaces_addresses($interfaces, $as_subnet = false, $ifconfig_details
}
}

/* move ULAs to the bottom to prefer GUA addresses */
uasort($result, function ($a, $b) {
return $a['unique'] - $b['unique'];
});

return $result;
}

Expand Down Expand Up @@ -4414,7 +4420,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;
}

Expand Down

0 comments on commit cd808e3

Please sign in to comment.