diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-11-05 13:33:52 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-02-14 15:42:56 +0100 |
commit | 5b2d8ffb5a1ebbd1e7c5359a9b924454f9dac031 (patch) | |
tree | 928a55f982b74d6553ba0a2b5b0004c9dc293e33 /src/resolve/resolved-dns-answer.c | |
parent | 5464c961865e049279dc696a93fbaf08b8bc39ce (diff) | |
download | systemd-5b2d8ffb5a1ebbd1e7c5359a9b924454f9dac031.tar.gz |
answer: add helper for randomizing RR of answers
Diffstat (limited to 'src/resolve/resolved-dns-answer.c')
-rw-r--r-- | src/resolve/resolved-dns-answer.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c index 051a2a0f25..8591ed0f3b 100644 --- a/src/resolve/resolved-dns-answer.c +++ b/src/resolve/resolved-dns-answer.c @@ -4,6 +4,7 @@ #include "alloc-util.h" #include "dns-domain.h" +#include "random-util.h" #include "resolved-dns-answer.h" #include "resolved-dns-dnssec.h" #include "string-util.h" @@ -898,3 +899,23 @@ int dns_answer_has_dname_for_cname(DnsAnswer *a, DnsResourceRecord *cname) { return 0; } + +void dns_answer_randomize(DnsAnswer *a) { + size_t n; + + /* Permutes the answer list randomly (Knuth shuffle) */ + + n = dns_answer_size(a); + if (n <= 1) + return; + + for (size_t i = 0; i < n; i++) { + size_t k; + + k = random_u64_range(n); + if (k == i) + continue; + + SWAP_TWO(a->items[i], a->items[k]); + } +} |