Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 92626
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: Nobody in particular
Requestors: cpan [...] askneil.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.74
Fixed in: (no value)



Subject: SRV rrsort is incorrect
The current SRV record sorting algorithm is this: my ( $a, $b ) = ( $Net::DNS::a, $Net::DNS::b ); $a->{priority} <=> $b->{priority} || $b->{weight} <=> $a->{weight}; Alas, this just makes weight a less significant priority. RFC2782 defines how to deal with SRV records. Here's the section on sorting SRV records by weight (it first says to sort by priority; this section is just for RRs of the same weight): To select a target to be contacted next, arrange all SRV RRs (that have not been ordered yet) in any order, except that all those with weight 0 are placed at the beginning of the list. Compute the sum of the weights of those RRs, and with each RR associate the running sum in the selected order. Then choose a uniform random number between 0 and the sum computed (inclusive), and select the RR whose running sum value is the first in the selected order which is greater than or equal to the random number selected. The target host specified in the selected SRV RR is the next one to be contacted by the client. Remove this SRV RR from the set of the unordered SRV RRs and apply the described algorithm to the unordered SRV RRs to select the next target host. Continue the ordering process until there are no unordered SRV RRs. This process is repeated for each Priority. This seems like an intrisically N^2 algorithm, but luckily the number of records is expected to be small. I'll take a stab as preparing a patch, but I wanted to see if already had thought about this issue. Thanks.
From: cpan [...] askneil.com
I looked at how to implement this today. Its less obvious than I thought. The actual sort isn't too hard. Patching it into rrsort is. Currently rrsort is hard coded to "own" the sort function, with only the comparator being customized. But to do the algorithm in rfc2782 it is much easier to do a two pass algorithm, where first you compute the sum of the weights and then compute which item matches. If you have a suggestion as to what you would find acceptable I would appreciate it. The idea I have is to add a call in Net::DNS::rrsort() for a function Net::DNS::RR::$rrtype::full_rrsort($attribute). By default this would call get_rrsort_func and then sort as before; but Net::DNS::RR::SRV could override this. This seems inelegant to me though, so I'd love to find a better way. The other question I have is how to test an intrinsically random process. My proposal is to split the tests into two parts. The first would be to test that priorities are the most significant part of the sort. The second would be "advisory" where a confidence would be printed that the results matched the expected distribution, but it would never fail (since any order is strictly legal with a priority, just with low probability, and downstream users really don't want random fails of their build).
From: rwfranks [...] acm.org
There is no suggestion in the documentation or the code that rrsort() orders SVR RRs in the sequence that connection attempts should be made. The responsibility for that remains with the user application and cannot be outsourced to Net::DNS. There are other situations where the sort ordering presently defined is more appropriate than some partially non-deterministic ordering. The only action I propose to take is to delete the sort by 'weight' comparator function from SVR.pm, which makes no sense at all, and to revise the descriptions in DNS.pm and RR.pm. On Sat Feb 01 16:01:00 2014, https://www.google.com/accounts/o8/id?id=AItOawkff5VLKxjRcTy06uHDgN2gc2z-ChWcpqs wrote: Show quoted text
> > I looked at how to implement this today. Its less obvious than I > thought. > > The actual sort isn't too hard. Patching it into rrsort is.
From: rwfranks [...] acm.org
I failed to point out that the weighted selection algorithm in RFC2782 is easily demonstrated to be incorrect.
Sorting of SRV records will is documented in the 0.75 release