aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2024-02-22 19:46:52 +0100
committerKim Alvefur <zash@zash.se>2024-02-22 19:46:52 +0100
commitddd479afe2cd93fde00b6966c54b83e2bf3bcaff (patch)
tree0d796024ad58160a49fb3edc11f5d879830696ae
parentb9f0c3c0ec0fff23bbb17998814cbf244b4502b5 (diff)
downloadprosody-ddd479afe2cd93fde00b6966c54b83e2bf3bcaff.tar.gz
prosody-ddd479afe2cd93fde00b6966c54b83e2bf3bcaff.zip
util.rfc6724: Remove, unused since introduction of Happy Eyeballs
It was mainly used to determine whether to try IPv6 or IPv4 first, following the rules for this in the RFC. Now we always try IPv6 and IPv4 at roughly the same time, thus there no need to carry these rules.
-rw-r--r--.luacheckrc1
-rw-r--r--CHANGES1
-rw-r--r--spec/util_rfc6724_spec.lua97
-rw-r--r--util/rfc6724.lua141
4 files changed, 1 insertions, 239 deletions
diff --git a/.luacheckrc b/.luacheckrc
index 6eb4c526..90e18ce5 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -161,7 +161,6 @@ if os.getenv("PROSODY_STRICT_LINT") ~= "1" then
"spec/util_http_spec.lua";
"spec/util_ip_spec.lua";
"spec/util_multitable_spec.lua";
- "spec/util_rfc6724_spec.lua";
"spec/util_throttle_spec.lua";
"tools/ejabberd2prosody.lua";
diff --git a/CHANGES b/CHANGES
index 8167efb4..4d85d331 100644
--- a/CHANGES
+++ b/CHANGES
@@ -71,6 +71,7 @@ TRUNK
- Lua 5.1 support
- XEP-0090 support removed from mod_time
+- util.rfc6724
0.12.0
======
diff --git a/spec/util_rfc6724_spec.lua b/spec/util_rfc6724_spec.lua
deleted file mode 100644
index 30e935b6..00000000
--- a/spec/util_rfc6724_spec.lua
+++ /dev/null
@@ -1,97 +0,0 @@
-
-local rfc6724 = require "util.rfc6724";
-local new_ip = require"util.ip".new_ip;
-
-describe("util.rfc6724", function()
- describe("#source()", function()
- it("should work", function()
- assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
- {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr,
- "2001:db8:3::1",
- "prefer appropriate scope");
- assert.are.equal(rfc6724.source(new_ip("ff05::1", "IPv6"),
- {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr,
- "2001:db8:3::1",
- "prefer appropriate scope");
- assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
- {new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:2::1", "IPv6")}).addr,
- "2001:db8:1::1",
- "prefer same address"); -- "2001:db8:1::1" should be marked "deprecated" here, we don't handle that right now
- assert.are.equal(rfc6724.source(new_ip("fe80::1", "IPv6"),
- {new_ip("fe80::2", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}).addr,
- "fe80::2",
- "prefer appropriate scope"); -- "fe80::2" should be marked "deprecated" here, we don't handle that right now
- assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr,
- "2001:db8:1::2",
- "longest matching prefix");
- --[[ "2001:db8:1::2" should be a care-of address and "2001:db8:3::2" a home address, we can't handle this and would fail
- assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr,
- "2001:db8:3::2",
- "prefer home address");
- ]]
- assert.are.equal(rfc6724.source(new_ip("2002:c633:6401::1", "IPv6"),
- {new_ip("2002:c633:6401::d5e3:7953:13eb:22e8", "IPv6"), new_ip("2001:db8:1::2", "IPv6")}).addr,
- "2002:c633:6401::d5e3:7953:13eb:22e8",
- "prefer matching label"); -- "2002:c633:6401::d5e3:7953:13eb:22e8" should be marked "temporary" here, we don't handle that right now
- assert.are.equal(rfc6724.source(new_ip("2001:db8:1::d5e3:0:0:1", "IPv6"),
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:1::d5e3:7953:13eb:22e8", "IPv6")}).addr,
- "2001:db8:1::d5e3:7953:13eb:22e8",
- "prefer temporary address") -- "2001:db8:1::2" should be marked "public" and "2001:db8:1::d5e3:7953:13eb:22e8" should be marked "temporary" here, we don't handle that right now
- end);
- end);
- describe("#destination()", function()
- it("should work", function()
- local order;
- order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")},
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("169.254.13.78", "IPv4")})
- assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer matching scope");
- assert.are.equal(order[2].addr, "198.51.100.121", "prefer matching scope");
-
- order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")},
- {new_ip("fe80::1", "IPv6"), new_ip("198.51.100.117", "IPv4")})
- assert.are.equal(order[1].addr, "198.51.100.121", "prefer matching scope");
- assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer matching scope");
-
- order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("10.1.2.3", "IPv4")},
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("10.1.2.4", "IPv4")})
- assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence");
- assert.are.equal(order[2].addr, "10.1.2.3", "prefer higher precedence");
-
- order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
- assert.are.equal(order[1].addr, "fe80::1", "prefer smaller scope");
- assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer smaller scope");
-
- --[[ "2001:db8:1::2" and "fe80::2" should be marked "care-of address", while "2001:db8:3::1" should be marked "home address", we can't currently handle this and would fail the test
- order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::2", "IPv6")})
- assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer home address");
- assert.are.equal(order[2].addr, "fe80::1", "prefer home address");
- ]]
-
- --[[ "fe80::2" should be marked "deprecated", we can't currently handle this and would fail the test
- order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
- assert.are.equal(order[1].addr, "2001:db8:1::1", "avoid deprecated addresses");
- assert.are.equal(order[2].addr, "fe80::1", "avoid deprecated addresses");
- ]]
-
- order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:3ffe::1", "IPv6")},
- {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3f44::2", "IPv6"), new_ip("fe80::2", "IPv6")})
- assert.are.equal(order[1].addr, "2001:db8:1::1", "longest matching prefix");
- assert.are.equal(order[2].addr, "2001:db8:3ffe::1", "longest matching prefix");
-
- order = rfc6724.destination({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")},
- {new_ip("2002:c633:6401::2", "IPv6"), new_ip("fe80::2", "IPv6")})
- assert.are.equal(order[1].addr, "2002:c633:6401::1", "prefer matching label");
- assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer matching label");
-
- order = rfc6724.destination({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")},
- {new_ip("2002:c633:6401::2", "IPv6"), new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
- assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence");
- assert.are.equal(order[2].addr, "2002:c633:6401::1", "prefer higher precedence");
- end);
- end);
-end);
diff --git a/util/rfc6724.lua b/util/rfc6724.lua
deleted file mode 100644
index 33477ed7..00000000
--- a/util/rfc6724.lua
+++ /dev/null
@@ -1,141 +0,0 @@
--- Prosody IM
--- Copyright (C) 2011-2013 Florian Zeitz
---
--- This project is MIT/X11 licensed. Please see the
--- COPYING file in the source package for more information.
---
-
--- 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"prosody.util.ip".commonPrefixLength
-
-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
- local a, b = t[i], t[j];
- if not comp(a,b) then
- t[i], t[j] = b, a;
- end
- end
- end
-end
-
-local function source(dest, candidates)
- local function comp(ipA, ipB)
- -- Rule 1: Prefer same address
- if dest == ipA then
- return true;
- elseif dest == ipB then
- return false;
- end
-
- -- Rule 2: Prefer appropriate scope
- if ipA.scope < ipB.scope then
- if ipA.scope < dest.scope then
- return false;
- else
- return true;
- end
- elseif ipA.scope > ipB.scope then
- if ipB.scope < dest.scope then
- return true;
- else
- return false;
- end
- end
-
- -- Rule 3: Avoid deprecated addresses
- -- XXX: No way to determine this
- -- Rule 4: Prefer home addresses
- -- XXX: Mobility Address related, no way to determine this
- -- Rule 5: Prefer outgoing interface
- -- XXX: Interface to address relation. No way to determine this
- -- Rule 6: Prefer matching label
- if ipA.label == dest.label and ipB.label ~= dest.label then
- return true;
- elseif ipB.label == dest.label and ipA.label ~= dest.label then
- return false;
- end
-
- -- 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
- return true;
- else
- return false;
- end
- end
-
- t_sort(candidates, comp);
- return candidates[1];
-end
-
-local function destination(candidates, sources)
- local sourceAddrs = {};
- local function comp(ipA, ipB)
- local ipAsource = sourceAddrs[ipA];
- local ipBsource = sourceAddrs[ipB];
- -- Rule 1: Avoid unusable destinations
- -- XXX: No such information
- -- Rule 2: Prefer matching scope
- if ipA.scope == ipAsource.scope and ipB.scope ~= ipBsource.scope then
- return true;
- elseif ipA.scope ~= ipAsource.scope and ipB.scope == ipBsource.scope then
- return false;
- end
-
- -- Rule 3: Avoid deprecated addresses
- -- XXX: No way to determine this
- -- Rule 4: Prefer home addresses
- -- XXX: Mobility Address related, no way to determine this
- -- Rule 5: Prefer matching label
- if ipAsource.label == ipA.label and ipBsource.label ~= ipB.label then
- return true;
- elseif ipBsource.label == ipB.label and ipAsource.label ~= ipA.label then
- return false;
- end
-
- -- Rule 6: Prefer higher precedence
- if ipA.precedence > ipB.precedence then
- return true;
- elseif ipA.precedence < ipB.precedence then
- return false;
- end
-
- -- Rule 7: Prefer native transport
- -- XXX: No way to determine this
- -- Rule 8: Prefer smaller scope
- if ipA.scope < ipB.scope then
- return true;
- elseif ipA.scope > ipB.scope then
- return false;
- end
-
- -- Rule 9: Use longest matching prefix
- if commonPrefixLength(ipA, ipAsource) > commonPrefixLength(ipB, ipBsource) then
- return true;
- elseif commonPrefixLength(ipA, ipAsource) < commonPrefixLength(ipB, ipBsource) then
- return false;
- end
-
- -- Rule 10: Otherwise, leave order unchanged
- return true;
- end
- for _, ip in ipairs(candidates) do
- sourceAddrs[ip] = source(ip, sources);
- end
-
- t_sort(candidates, comp);
- return candidates;
-end
-
-return {source = source,
- destination = destination};