[ldns-users] ldns_rr_list_sort() sorts by which criterion?

Robert Edmonds edmonds at debian.org
Tue Aug 8 17:34:24 UTC 2017

Hi, Lars:

Lars Rohwedder wrote:
> It is not documented by which criterion this function sorts the list.

     * sorts an rr_list (canonical wire format). the sorting is done inband.
     * \param[in] unsorted the rr_list to be sorted
     * \return void
    void ldns_rr_list_sort(ldns_rr_list *unsorted);

"Canonical" DNS sorting is almost certainly the canonical ordering
defined for DNSSEC (RFC 4034 §6). From a quick look at the sort function
in ldns, I would guess that this is the ordering that ldns is using.

> I'd like it if the function would sort e.g. a list of MX records by
> descending priority, so I can just pick the entry with the highest
> priority via  ldns_rr_list_rr( rr, 0), than  ldns_rr_list_rr( rr, 1) and
> so on.

Since the MX 'PREFERENCE' field is stored at the beginning of the record
data as a 16-bit big endian integer, the most preferred (lowest) values
will be at the beginning of the list. But even if the RRs are sorted
correctly for SMTP purposes, you still need to randomize among MX
records with the same PREFERENCE, if you are going to make an SMTP
connection. (RFC 5321 says "MUST randomize".)

Robert Edmonds
edmonds at debian.org

More information about the ldns-users mailing list