]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: make use of dns_{class|type}_is_{pseudo|valid_rr}() everywhere
authorLennart Poettering <lennart@poettering.net>
Fri, 18 Dec 2015 18:06:23 +0000 (19:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Dec 2015 18:06:23 +0000 (19:06 +0100)
src/resolve/dns-type.h
src/resolve/resolved-dns-cache.c
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dns-zone.c

index deb89e9b7e273be442ac7e09bcb4c61bbfb18d36..bea0adaa16f282c4df19e1f72d8eb1e477a7b260 100644 (file)
 
 #include "macro.h"
 
-const char *dns_type_to_string(int type);
-int dns_type_from_string(const char *s);
-
-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);
-
 /* DNS record types, taken from
  * http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml.
  */
@@ -127,12 +120,20 @@ assert_cc(DNS_TYPE_ANY == 255);
 enum {
         DNS_CLASS_IN   = 0x01,
         DNS_CLASS_ANY  = 0xFF,
+
         _DNS_CLASS_MAX,
         _DNS_CLASS_INVALID = -1
 };
 
+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_class_is_pseudo(uint16_t class);
 bool dns_class_is_valid_rr(uint16_t class);
 
+const char *dns_type_to_string(int type);
+int dns_type_from_string(const char *s);
+
 const char *dns_class_to_string(uint16_t type);
 int dns_class_from_string(const char *name);
index a8d612794cbbcc99e32e3382604ca77adc89fbff..9ad3c0e82b3220545b23cfe7ae2efb22232c8120 100644 (file)
@@ -282,6 +282,12 @@ static int dns_cache_put_positive(
         assert(rr);
         assert(owner_address);
 
+        /* Never cache pseudo RRs */
+        if (dns_class_is_pseudo(rr->key->class))
+                return 0;
+        if (dns_type_is_pseudo(rr->key->type))
+                return 0;
+
         /* New TTL is 0? Delete the entry... */
         if (rr->ttl <= 0) {
                 k = dns_cache_remove(c, rr->key);
@@ -300,11 +306,6 @@ static int dns_cache_put_positive(
                 return 0;
         }
 
-        if (rr->key->class == DNS_CLASS_ANY)
-                return 0;
-        if (dns_type_is_pseudo(rr->key->type))
-                return 0;
-
         /* Entry exists already? Update TTL and timestamp */
         existing = dns_cache_get(c, rr);
         if (existing) {
@@ -368,12 +369,15 @@ static int dns_cache_put_negative(
 
         dns_cache_remove(c, key);
 
-        if (key->class == DNS_CLASS_ANY)
+        /* Never cache pseudo RR keys */
+        if (dns_class_is_pseudo(key->class))
                 return 0;
         if (dns_type_is_pseudo(key->type))
-                /* ANY is particularly important to filter out as we
-                 * use this as a pseudo-type for NXDOMAIN entries */
+                /* DNS_TYPE_ANY is particularly important to filter
+                 * out as we use this as a pseudo-type for NXDOMAIN
+                 * entries */
                 return 0;
+
         if (soa_ttl <= 0) {
                 if (log_get_max_level() >= LOG_DEBUG) {
                         r = dns_resource_key_to_string(key, &key_str);
index e8f570555b6586af802f635c7f60ff42ee158072..bb299462a77c988a8453e4aab96ec8f8e5f0ed64 100644 (file)
@@ -1531,7 +1531,7 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start) {
         if (r < 0)
                 goto fail;
 
-        if (key->class == DNS_CLASS_ANY ||
+        if (!dns_class_is_valid_rr(key->class)||
             !dns_type_is_valid_rr(key->type)) {
                 r = -EBADMSG;
                 goto fail;
index 0ddf2be8b365d9b6f26fe22a656fe9f2fd29a995..20c8a4da902cd3ec2b56a3aeb568faa285ca421d 100644 (file)
@@ -223,9 +223,9 @@ int dns_zone_put(DnsZone *z, DnsScope *s, DnsResourceRecord *rr, bool probe) {
         assert(s);
         assert(rr);
 
-        if (rr->key->class == DNS_CLASS_ANY)
+        if (dns_class_is_pseudo(rr->key->class))
                 return -EINVAL;
-        if (rr->key->type == DNS_TYPE_ANY)
+        if (dns_type_is_pseudo(rr->key->type))
                 return -EINVAL;
 
         existing = dns_zone_get(z, rr);