]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: split out a new dns_type_may_redirect() call
authorLennart Poettering <lennart@poettering.net>
Mon, 21 Dec 2015 15:23:48 +0000 (16:23 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 26 Dec 2015 18:09:09 +0000 (19:09 +0100)
Let's abstract which RRs shall honour CNAMEs, and which ones should not.

src/resolve/dns-type.c
src/resolve/dns-type.h
src/resolve/resolved-dns-cache.c

index cc52ef9abe0ae76f75a28f922c23df6c64be65bc..0571d65f0ba0efc859701ebcd31a02a634711247 100644 (file)
@@ -95,6 +95,25 @@ bool dns_class_is_valid_rr(uint16_t class) {
         return class != DNS_CLASS_ANY;
 }
 
+bool dns_type_may_redirect(uint16_t type) {
+        /* The following record types should never be redirected using
+         * CNAME/DNAME RRs. See
+         * <https://tools.ietf.org/html/rfc4035#section-2.5>. */
+
+        if (dns_type_is_pseudo(type))
+                return false;
+
+        return !IN_SET(type,
+                       DNS_TYPE_CNAME,
+                       DNS_TYPE_DNAME,
+                       DNS_TYPE_NSEC3,
+                       DNS_TYPE_NSEC,
+                       DNS_TYPE_RRSIG,
+                       DNS_TYPE_NXT,
+                       DNS_TYPE_SIG,
+                       DNS_TYPE_KEY);
+}
+
 const char *dns_class_to_string(uint16_t class) {
 
         switch (class) {
index bea0adaa16f282c4df19e1f72d8eb1e477a7b260..c3bb26a5eef873bd5606bd22421813fe9c4c8e43 100644 (file)
@@ -128,6 +128,7 @@ enum {
 bool dns_type_is_pseudo(uint16_t type);
 bool dns_type_is_valid_query(uint16_t type);
 bool dns_type_is_valid_rr(uint16_t type);
+bool dns_type_may_redirect(uint16_t type);
 
 bool dns_class_is_pseudo(uint16_t class);
 bool dns_class_is_valid_rr(uint16_t class);
index f50d780ebbb9c99374031ac20e624f1cf5948d34..31154fbc771bf04b9a76a1d92a23acf0c0ac0c10 100644 (file)
@@ -672,11 +672,7 @@ static DnsCacheItem *dns_cache_get_by_key_follow_cname_dname_nsec(DnsCache *c, D
         if (i && i->type == DNS_CACHE_NXDOMAIN)
                 return i;
 
-        /* The following record types should never be redirected. See
-         * <https://tools.ietf.org/html/rfc4035#section-2.5>. */
-        if (!IN_SET(k->type, DNS_TYPE_CNAME, DNS_TYPE_DNAME,
-                            DNS_TYPE_NSEC3, DNS_TYPE_NSEC, DNS_TYPE_RRSIG,
-                            DNS_TYPE_NXT, DNS_TYPE_SIG, DNS_TYPE_KEY)) {
+        if (dns_type_may_redirect(k->type)) {
                 /* Check if we have a CNAME record instead */
                 i = hashmap_get(c->by_key, &DNS_RESOURCE_KEY_CONST(k->class, DNS_TYPE_CNAME, n));
                 if (i)