summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-answer.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-30 00:48:59 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-30 00:48:59 +0200
commitaf93291cc4cbd2fe2fb4af7d3c56138fb39f31dc (patch)
tree18600359a8412751275aa86b607f0b35c21e0b3a /src/resolve/resolved-dns-answer.c
parent2442b93d15f5523aba0c5dc56a42757af889c483 (diff)
resolved: when answer A or AAAA questions, order responses by whether addresses are link-local or not
Diffstat (limited to 'src/resolve/resolved-dns-answer.c')
-rw-r--r--src/resolve/resolved-dns-answer.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c
index d90766452..93e51fc24 100644
--- a/src/resolve/resolved-dns-answer.c
+++ b/src/resolve/resolved-dns-answer.c
@@ -175,3 +175,34 @@ DnsAnswer *dns_answer_merge(DnsAnswer *a, DnsAnswer *b) {
return k;
}
+
+void dns_answer_order_by_scope(DnsAnswer *a, bool prefer_link_local) {
+ DnsResourceRecord **rrs;
+ unsigned i, start, end;
+ assert(a);
+
+ if (a->n_rrs <= 1)
+ return;
+
+ start = 0;
+ end = a->n_rrs-1;
+
+ /* RFC 4795, Section 2.6 suggests we should order entries
+ * depending on whether the sender is a link-local address. */
+
+ rrs = newa(DnsResourceRecord*, a->n_rrs);
+ for (i = 0; i < a->n_rrs; i++) {
+
+ if (a->rrs[i]->key->class == DNS_CLASS_IN &&
+ ((a->rrs[i]->key->type == DNS_TYPE_A && in_addr_is_link_local(AF_INET, (union in_addr_union*) &a->rrs[i]->a.in_addr) != prefer_link_local) ||
+ (a->rrs[i]->key->type == DNS_TYPE_AAAA && in_addr_is_link_local(AF_INET6, (union in_addr_union*) &a->rrs[i]->aaaa.in6_addr) != prefer_link_local)))
+ /* Order address records that are are not preferred to the end of the array */
+ rrs[end--] = a->rrs[i];
+ else
+ /* Order all other records to the beginning of the array */
+ rrs[start++] = a->rrs[i];
+ }
+
+ assert(start == end+1);
+ memcpy(a->rrs, rrs, sizeof(DnsResourceRecord*) * a->n_rrs);
+}