aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-03-18 16:10:26 +0000
committerMatthew Wild <mwild1@gmail.com>2022-03-18 16:10:26 +0000
commit3c5d7eaef1d3b6d9c93c6ae510317f671da33ceb (patch)
tree0187cae3d3bbd2e070db17283e7845c6b695e58b
parent668bd38c71bacc78bbd44154f3305be6450e0729 (diff)
downloadprosody-3c5d7eaef1d3b6d9c93c6ae510317f671da33ceb.tar.gz
prosody-3c5d7eaef1d3b6d9c93c6ae510317f671da33ceb.zip
net.resolvers.basic: Alternate IP address family targets, per RFC 8305
-rw-r--r--net/resolvers/basic.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/net/resolvers/basic.lua b/net/resolvers/basic.lua
index a5ea5dee..667015a0 100644
--- a/net/resolvers/basic.lua
+++ b/net/resolvers/basic.lua
@@ -42,8 +42,16 @@ end
local function merge_targets(ipv4_targets, ipv6_targets)
local result = { secure = ipv4_targets.secure and ipv6_targets.secure };
- t_move(ipv6_targets, 1, #ipv6_targets, 1, result);
- t_move(ipv4_targets, 1, #ipv4_targets, #result+1, result);
+ local common_length = math.min(#ipv4_targets, #ipv6_targets);
+ 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;
end