Annotate

util/rfc6724.lua @ 5924:f44c1dabd4e9

Makefile, certs: Generate example certificates on build, remove the old static one
author Kim Alvefur <zash@zash.se>
date Fri, 22 Nov 2013 15:27:21 +0100
parent 5552:40e7a6cf15ff
child 7259:d8300985f2bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 -- Prosody IM
5552
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
2 -- Copyright (C) 2011-2013 Florian Zeitz
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 --
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 --
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7
5552
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
8 -- This is used to sort destination addresses by preference
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
9 -- during S2S connections.
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
10 -- We can't hand this off to getaddrinfo, since it blocks
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
11
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
12 local ip_commonPrefixLength = require"util.ip".commonPrefixLength
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 local new_ip = require"util.ip".new_ip;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14
5552
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
15 local function commonPrefixLength(ipA, ipB)
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
16 local len = ip_commonPrefixLength(ipA, ipB);
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
17 return len < 64 and len or 64;
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
18 end
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
19
4423
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
20 local function t_sort(t, comp)
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
21 for i = 1, (#t - 1) do
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
22 for j = (i + 1), #t do
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
23 local a, b = t[i], t[j];
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
24 if not comp(a,b) then
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
25 t[i], t[j] = b, a;
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
26 end
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
27 end
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
28 end
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
29 end
ded726418b16 util.rfc3484: Use a stable sorting algorithm
Florian Zeitz <florob@babelmonkeys.de>
parents: 4420
diff changeset
30
4830
ea907059a90e util.rfc3484: Don't pollute the global scope.
Kim Alvefur <zash@zash.se>
parents: 4423
diff changeset
31 local function source(dest, candidates)
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
32 local function comp(ipA, ipB)
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
33 -- Rule 1: Prefer same address
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
34 if dest == ipA then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
35 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
36 elseif dest == ipB then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
37 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
38 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
39
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
40 -- Rule 2: Prefer appropriate scope
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
41 if ipA.scope < ipB.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
42 if ipA.scope < dest.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 else
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 elseif ipA.scope > ipB.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 if ipB.scope < dest.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
50 else
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
51 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
52 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
54
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
55 -- Rule 3: Avoid deprecated addresses
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
56 -- XXX: No way to determine this
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 -- Rule 4: Prefer home addresses
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
58 -- XXX: Mobility Address related, no way to determine this
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
59 -- Rule 5: Prefer outgoing interface
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
60 -- XXX: Interface to address relation. No way to determine this
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
61 -- Rule 6: Prefer matching label
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
62 if ipA.label == dest.label and ipB.label ~= dest.label then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
63 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
64 elseif ipB.label == dest.label and ipA.label ~= dest.label then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
65 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
66 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
67
5552
40e7a6cf15ff util.rfc{3484,6724}: Update to RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 4830
diff changeset
68 -- Rule 7: Prefer temporary addresses (over public ones)
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69 -- XXX: No way to determine this
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
70 -- Rule 8: Use longest matching prefix
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
71 if commonPrefixLength(ipA, dest) > commonPrefixLength(ipB, dest) then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
72 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73 else
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
74 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
75 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
76 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
77
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 t_sort(candidates, comp);
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
79 return candidates[1];
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
81
4830
ea907059a90e util.rfc3484: Don't pollute the global scope.
Kim Alvefur <zash@zash.se>
parents: 4423
diff changeset
82 local function destination(candidates, sources)
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
83 local sourceAddrs = {};
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 local function comp(ipA, ipB)
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 local ipAsource = sourceAddrs[ipA];
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
86 local ipBsource = sourceAddrs[ipB];
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
87 -- Rule 1: Avoid unusable destinations
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
88 -- XXX: No such information
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
89 -- Rule 2: Prefer matching scope
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90 if ipA.scope == ipAsource.scope and ipB.scope ~= ipBsource.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
91 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 elseif ipA.scope ~= ipAsource.scope and ipB.scope == ipBsource.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
93 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
94 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96 -- Rule 3: Avoid deprecated addresses
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97 -- XXX: No way to determine this
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 -- Rule 4: Prefer home addresses
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 -- XXX: Mobility Address related, no way to determine this
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
100 -- Rule 5: Prefer matching label
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
101 if ipAsource.label == ipA.label and ipBsource.label ~= ipB.label then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103 elseif ipBsource.label == ipB.label and ipAsource.label ~= ipA.label then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
104 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
105 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
106
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 -- Rule 6: Prefer higher precedence
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108 if ipA.precedence > ipB.precedence then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110 elseif ipA.precedence < ipB.precedence then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 -- Rule 7: Prefer native transport
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115 -- XXX: No way to determine this
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 -- Rule 8: Prefer smaller scope
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 if ipA.scope < ipB.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119 elseif ipA.scope > ipB.scope then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
120 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 -- Rule 9: Use longest matching prefix
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 if commonPrefixLength(ipA, ipAsource) > commonPrefixLength(ipB, ipBsource) then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
126 elseif commonPrefixLength(ipA, ipAsource) < commonPrefixLength(ipB, ipBsource) then
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127 return false;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130 -- Rule 10: Otherwise, leave order unchanged
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131 return true;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 for _, ip in ipairs(candidates) do
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 sourceAddrs[ip] = source(ip, sources);
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
135 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
136
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 t_sort(candidates, comp);
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
138 return candidates;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
139 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
140
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141 return {source = source,
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
142 destination = destination};