From 188d06be2b0102d77be5372fc8a977bbfe7e2cb3 Mon Sep 17 00:00:00 2001 From: Nikolaos Chatzikonstantinou Date: Sat, 28 Dec 2024 03:28:18 -0500 Subject: [PATCH] docs: elaborate on sortlist order --- docs/ares_set_sortlist.3 | 5 ++++- src/lib/ares_gethostbyname.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/ares_set_sortlist.3 b/docs/ares_set_sortlist.3 index eb7bf6dc..07df16ee 100644 --- a/docs/ares_set_sortlist.3 +++ b/docs/ares_set_sortlist.3 @@ -20,7 +20,10 @@ sortlist. The provided .IR sortstr string that holds a space separated list of IP-address-netmask pairs. The netmask is optional but follows the address after a slash if present. For example, -"130.155.160.0/255.255.240.0 130.155.0.0". +"130.155.160.0/255.255.240.0 130.155.0.0" will sort IPs in ascending +order of appearance in the sortlist subnets, with those IPs that do +not match any subnets coming last. There is no particular order +amongst IPs that tie in this sorting scheme. This function replaces any potentially previously configured address sortlist with the ones given in the configuration string. diff --git a/src/lib/ares_gethostbyname.c b/src/lib/ares_gethostbyname.c index d451b468..5e1134b2 100644 --- a/src/lib/ares_gethostbyname.c +++ b/src/lib/ares_gethostbyname.c @@ -140,6 +140,11 @@ static void sort_addresses(const struct hostent *host, * through the address list, with the loop invariant that everything * to the left of i1 is sorted. In the loop body, the value at i1 is moved * back through the list (via i2) until it is in sorted order. + * + * The IPs are sorted in ascending order of corresponding sortlist + * indices, with those that don't match the subnets in the sortlist + * coming last. There is no particular order amongst IPs that tie + * in this sorting scheme. */ for (i1 = 0; host->h_addr_list[i1]; i1++) { memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr)); @@ -196,6 +201,11 @@ static void sort6_addresses(const struct hostent *host, * through the address list, with the loop invariant that everything * to the left of i1 is sorted. In the loop body, the value at i1 is moved * back through the list (via i2) until it is in sorted order. + * + * The IPv6s are sorted in ascending order of corresponding sortlist + * indices, with those that don't match the subnets in the sortlist + * coming last. There is no particular order amongst IPs that tie + * in this sorting scheme. */ for (i1 = 0; host->h_addr_list[i1]; i1++) { memcpy(&a1, host->h_addr_list[i1], sizeof(struct ares_in6_addr));