From roker at pep-project.org Tue Aug 8 14:49:57 2017 From: roker at pep-project.org (Lars Rohwedder) Date: Tue, 8 Aug 2017 16:49:57 +0200 Subject: [ldns-users] ldns_rr_list_sort() sorts by which criterion? Message-ID: <8424de26-befb-6abe-1401-8b624356ceeb@pep-project.org> It is not documented by which criterion this function sorts the list. 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. Is this the case or do I have to do that manually? Greetings, Lars R. -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x88396C78.asc Type: application/pgp-keys Size: 3906 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From edmonds at debian.org Tue Aug 8 17:34:24 2017 From: edmonds at debian.org (Robert Edmonds) Date: Tue, 8 Aug 2017 13:34:24 -0400 Subject: [ldns-users] ldns_rr_list_sort() sorts by which criterion? In-Reply-To: <8424de26-befb-6abe-1401-8b624356ceeb@pep-project.org> References: <8424de26-befb-6abe-1401-8b624356ceeb@pep-project.org> Message-ID: <20170808173424.c7xylh2xgeb6hxmu@mycre.ws> 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 From roker at pep-project.org Tue Aug 8 18:06:45 2017 From: roker at pep-project.org (Lars Rohwedder) Date: Tue, 8 Aug 2017 20:06:45 +0200 Subject: [ldns-users] ldns_rr_list_sort() sorts by which criterion? In-Reply-To: <20170808173424.c7xylh2xgeb6hxmu@mycre.ws> References: <8424de26-befb-6abe-1401-8b624356ceeb@pep-project.org> <20170808173424.c7xylh2xgeb6hxmu@mycre.ws> Message-ID: <0e261124-8317-521c-3e0f-81aa8af67f16@pep-project.org> > 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".) Okay, so for MX and SRV records this ordering would work but is sub-optimal, because it would work but violates the RFC. Is there a function in LDNS library that does that "pick one at random" from an RR List or do I have to write my own (and parse all the RR members first and all that nasty PITA stuff)? :-o L. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: