resolved: make use of dns_{class|type}_is_{pseudo|valid_rr}() everywhere
This commit is contained in:
@@ -23,13 +23,6 @@
|
||||
|
||||
#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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user