net.resolvers.basic: Alternate IP address family targets, per RFC 8305

This commit is contained in:
Matthew Wild 2022-03-18 16:10:26 +00:00
parent 668bd38c71
commit 3c5d7eaef1

View file

@ -42,8 +42,16 @@ end
local function merge_targets(ipv4_targets, ipv6_targets) local function merge_targets(ipv4_targets, ipv6_targets)
local result = { secure = ipv4_targets.secure and ipv6_targets.secure }; local result = { secure = ipv4_targets.secure and ipv6_targets.secure };
t_move(ipv6_targets, 1, #ipv6_targets, 1, result); local common_length = math.min(#ipv4_targets, #ipv6_targets);
t_move(ipv4_targets, 1, #ipv4_targets, #result+1, result); for i = 1, common_length do
table.insert(result, ipv6_targets[i]);
table.insert(result, ipv4_targets[i]);
end
if common_length < #ipv4_targets then
t_move(ipv4_targets, common_length+1, #ipv4_targets, common_length+1, result);
elseif common_length < #ipv6_targets then
t_move(ipv6_targets, common_length+1, #ipv6_targets, common_length+1, result);
end
return result; return result;
end end