]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: add new helper dns_answer_min_ttl()
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Mar 2021 19:47:28 +0000 (20:47 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 15 Mar 2021 20:21:37 +0000 (21:21 +0100)
src/resolve/resolved-dns-answer.c
src/resolve/resolved-dns-answer.h

index a667ab5ede431a43e4821c2594727f6f7f4e65ae..5fbff81c255ea7cdd18daeca6882d713c6f409bd 100644 (file)
@@ -963,3 +963,22 @@ void dns_answer_randomize(DnsAnswer *a) {
                 SWAP_TWO(a->items[i], a->items[k]);
         }
 }
+
+uint32_t dns_answer_min_ttl(DnsAnswer *a) {
+        uint32_t ttl = UINT32_MAX;
+        DnsResourceRecord *rr;
+
+        /* Return the smallest TTL of all RRs in this answer */
+
+        DNS_ANSWER_FOREACH(rr, a) {
+                /* Don't consider OPT (where the TTL field is used for other purposes than an actual TTL) */
+
+                if (dns_type_is_pseudo(rr->key->type) ||
+                    dns_class_is_pseudo(rr->key->class))
+                        continue;
+
+                ttl = MIN(ttl, rr->ttl);
+        }
+
+        return ttl;
+}
index 7d19eee4e2bb5d434726f22fdaaae3b8234c0ab0..447da5d6cc3437e282c6cd7265ab8d78b27a7cad 100644 (file)
@@ -87,6 +87,8 @@ void dns_answer_dump(DnsAnswer *answer, FILE *f);
 
 void dns_answer_randomize(DnsAnswer *a);
 
+uint32_t dns_answer_min_ttl(DnsAnswer *a);
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref);
 
 #define _DNS_ANSWER_FOREACH(q, kk, a)                                   \