chiark / gitweb /
resolved: properly set TTL in SOA records
authorLennart Poettering <lennart@poettering.net>
Wed, 30 Jul 2014 17:34:50 +0000 (19:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 30 Jul 2014 17:34:50 +0000 (19:34 +0200)
src/resolve/resolved-dns-answer.c
src/resolve/resolved-dns-answer.h
src/resolve/resolved-dns-zone.c
src/resolve/resolved-dns-zone.h
src/resolve/resolved-link.c

index b6883a3..7c4ab18 100644 (file)
@@ -97,13 +97,15 @@ int dns_answer_add(DnsAnswer *a, DnsResourceRecord *rr) {
         return 1;
 }
 
-int dns_answer_add_soa(DnsAnswer *a, const char *name) {
+int dns_answer_add_soa(DnsAnswer *a, const char *name, uint32_t ttl) {
         _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *soa = NULL;
 
         soa = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_SOA, name);
         if (!soa)
                 return -ENOMEM;
 
+        soa->ttl = ttl;
+
         soa->soa.mname = strdup(name);
         if (!soa->soa.mname)
                 return -ENOMEM;
@@ -116,7 +118,7 @@ int dns_answer_add_soa(DnsAnswer *a, const char *name) {
         soa->soa.refresh = 1;
         soa->soa.retry = 1;
         soa->soa.expire = 1;
-        soa->soa.minimum = 1;
+        soa->soa.minimum = ttl;
 
         return dns_answer_add(a, soa);
 }
index 917bfce..af3e462 100644 (file)
@@ -38,7 +38,7 @@ DnsAnswer *dns_answer_ref(DnsAnswer *a);
 DnsAnswer *dns_answer_unref(DnsAnswer *a);
 
 int dns_answer_add(DnsAnswer *a, DnsResourceRecord *rr);
-int dns_answer_add_soa(DnsAnswer *a, const char *name);
+int dns_answer_add_soa(DnsAnswer *a, const char *name, uint32_t ttl);
 int dns_answer_contains(DnsAnswer *a, DnsResourceKey *key);
 int dns_answer_find_soa(DnsAnswer *a, DnsResourceKey *key, DnsResourceRecord **ret);
 
index b51f503..99ea420 100644 (file)
@@ -275,7 +275,7 @@ int dns_zone_lookup(DnsZone *z, DnsQuestion *q, DnsAnswer **ret_answer, DnsAnswe
                                 if (k < 0)
                                         return k;
                                 if (k == 0)
-                                        r = dns_answer_add_soa(soa, DNS_RESOURCE_KEY_NAME(q->keys[i]));
+                                        r = dns_answer_add_soa(soa, DNS_RESOURCE_KEY_NAME(q->keys[i]), LLMNR_DEFAULT_TTL);
                                 else
                                         r = dns_answer_add(answer, j->rr);
                                 if (r < 0)
@@ -292,7 +292,7 @@ int dns_zone_lookup(DnsZone *z, DnsQuestion *q, DnsAnswer **ret_answer, DnsAnswe
                                 }
                         } else {
                                 if (hashmap_get(z->by_name, DNS_RESOURCE_KEY_NAME(q->keys[i]))) {
-                                        r = dns_answer_add_soa(soa, DNS_RESOURCE_KEY_NAME(q->keys[i]));
+                                        r = dns_answer_add_soa(soa, DNS_RESOURCE_KEY_NAME(q->keys[i]), LLMNR_DEFAULT_TTL);
                                         if (r < 0)
                                                 return r;
                                 }
index 5e7a1f7..b2af028 100644 (file)
@@ -38,3 +38,6 @@ int dns_zone_put(DnsZone *z, DnsResourceRecord *rr);
 void dns_zone_remove_rr(DnsZone *z, DnsResourceRecord *rr);
 
 int dns_zone_lookup(DnsZone *z, DnsQuestion *q, DnsAnswer **answer, DnsAnswer **soa);
+
+/* RFC 4795 Section 2.8. suggests a TTL of 30s by default */
+#define LLMNR_DEFAULT_TTL (30)
index cd6e4ba..a4c23ba 100644 (file)
@@ -25,9 +25,6 @@
 #include "strv.h"
 #include "resolved-link.h"
 
-/* RFC 4795 Section 2.8. suggests a TTL of 30s by default */
-#define LLMNR_DEFAULT_TTL (30)
-
 static void link_address_add_rrs(LinkAddress *a);
 
 int link_new(Manager *m, Link **ret, int ifindex) {