aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2013-04-30 18:34:03 +0200
committerFlorian Zeitz <florob@babelmonkeys.de>2013-04-30 18:34:03 +0200
commitf68149d12432a56266ff69ba088c6f43238939c2 (patch)
tree03f20342d2e906044736e9fae3b598bf4deaee89
parentddd84e8a663eda1c6b06e8f7b7adf51a48f42318 (diff)
downloadprosody-f68149d12432a56266ff69ba088c6f43238939c2.tar.gz
prosody-f68149d12432a56266ff69ba088c6f43238939c2.zip
util.rfc{3484,6724}: Update to RFC 6724
-rw-r--r--plugins/mod_s2s/s2sout.lib.lua6
-rw-r--r--util/ip.lua23
-rw-r--r--util/rfc6724.lua (renamed from util/rfc3484.lua)15
3 files changed, 33 insertions, 11 deletions
diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua
index a22846db..cb2f8be4 100644
--- a/plugins/mod_s2s/s2sout.lib.lua
+++ b/plugins/mod_s2s/s2sout.lib.lua
@@ -13,7 +13,7 @@ local wrapclient = require "net.server".wrapclient;
local initialize_filters = require "util.filters".initialize;
local idna_to_ascii = require "util.encodings".idna.to_ascii;
local new_ip = require "util.ip".new_ip;
-local rfc3484_dest = require "util.rfc3484".destination;
+local rfc6724_dest = require "util.rfc6724".destination;
local socket = require "socket";
local adns = require "net.adns";
local dns = require "net.dns";
@@ -191,7 +191,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err)
if have_other_result then
if #IPs > 0 then
- rfc3484_dest(host_session.ip_hosts, sources);
+ rfc6724_dest(host_session.ip_hosts, sources);
for i = 1, #IPs do
IPs[i] = {ip = IPs[i], port = connect_port};
end
@@ -227,7 +227,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err)
if have_other_result then
if #IPs > 0 then
- rfc3484_dest(host_session.ip_hosts, sources);
+ rfc6724_dest(host_session.ip_hosts, sources);
for i = 1, #IPs do
IPs[i] = {ip = IPs[i], port = connect_port};
end
diff --git a/util/ip.lua b/util/ip.lua
index 2f09c034..de287b16 100644
--- a/util/ip.lua
+++ b/util/ip.lua
@@ -64,9 +64,6 @@ local function v4scope(ip)
-- Link-local unicast:
elseif fields[1] == 169 and fields[2] == 254 then
return 0x2;
- -- Site-local unicast:
- elseif (fields[1] == 10) or (fields[1] == 192 and fields[2] == 168) or (fields[1] == 172 and (fields[2] >= 16 and fields[2] < 32)) then
- return 0x5;
-- Global unicast:
else
return 0xE;
@@ -97,6 +94,14 @@ local function label(ip)
return 0;
elseif commonPrefixLength(ip, new_ip("2002::", "IPv6")) >= 16 then
return 2;
+ elseif commonPrefixLength(ip, new_ip("2001::", "IPv6")) >= 32 then
+ return 5;
+ elseif commonPrefixLength(ip, new_ip("fc00::", "IPv6")) >= 7 then
+ return 13;
+ elseif commonPrefixLength(ip, new_ip("fec0::", "IPv6")) >= 10 then
+ return 11;
+ elseif commonPrefixLength(ip, new_ip("3ffe::", "IPv6")) >= 16 then
+ return 12;
elseif commonPrefixLength(ip, new_ip("::", "IPv6")) >= 96 then
return 3;
elseif commonPrefixLength(ip, new_ip("::ffff:0:0", "IPv6")) >= 96 then
@@ -111,10 +116,18 @@ local function precedence(ip)
return 50;
elseif commonPrefixLength(ip, new_ip("2002::", "IPv6")) >= 16 then
return 30;
+ elseif commonPrefixLength(ip, new_ip("2001::", "IPv6")) >= 32 then
+ return 5;
+ elseif commonPrefixLength(ip, new_ip("fc00::", "IPv6")) >= 7 then
+ return 3;
+ elseif commonPrefixLength(ip, new_ip("fec0::", "IPv6")) >= 10 then
+ return 1;
+ elseif commonPrefixLength(ip, new_ip("3ffe::", "IPv6")) >= 16 then
+ return 1;
elseif commonPrefixLength(ip, new_ip("::", "IPv6")) >= 96 then
- return 20;
+ return 1;
elseif commonPrefixLength(ip, new_ip("::ffff:0:0", "IPv6")) >= 96 then
- return 10;
+ return 35;
else
return 40;
end
diff --git a/util/rfc3484.lua b/util/rfc6724.lua
index 5ee572a0..c8aec631 100644
--- a/util/rfc3484.lua
+++ b/util/rfc6724.lua
@@ -1,13 +1,22 @@
-- Prosody IM
--- Copyright (C) 2008-2011 Florian Zeitz
+-- Copyright (C) 2011-2013 Florian Zeitz
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--
-local commonPrefixLength = require"util.ip".commonPrefixLength
+-- This is used to sort destination addresses by preference
+-- during S2S connections.
+-- We can't hand this off to getaddrinfo, since it blocks
+
+local ip_commonPrefixLength = require"util.ip".commonPrefixLength
local new_ip = require"util.ip".new_ip;
+local function commonPrefixLength(ipA, ipB)
+ local len = ip_commonPrefixLength(ipA, ipB);
+ return len < 64 and len or 64;
+end
+
local function t_sort(t, comp)
for i = 1, (#t - 1) do
for j = (i + 1), #t do
@@ -56,7 +65,7 @@ local function source(dest, candidates)
return false;
end
- -- Rule 7: Prefer public addresses (over temporary ones)
+ -- Rule 7: Prefer temporary addresses (over public ones)
-- XXX: No way to determine this
-- Rule 8: Use longest matching prefix
if commonPrefixLength(ipA, dest) > commonPrefixLength(ipB, dest) then