resolved-dns-rr.c revision ee3d6aff9bd73c1b23e29d1fa1fa6f7a1ef0533b
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <math.h>
#include "alloc-util.h"
#include "dns-domain.h"
#include "dns-type.h"
#include "hexdecoct.h"
#include "resolved-dns-packet.h"
#include "resolved-dns-rr.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
DnsResourceKey *k;
size_t l;
if (!k)
return NULL;
k->n_ref = 1;
return k;
}
DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname) {
int r;
else {
DnsResourceKey *k;
char *destination = NULL;
r = dns_name_change_suffix(DNS_RESOURCE_KEY_NAME(key), DNS_RESOURCE_KEY_NAME(cname->key), cname->dname.name, &destination);
if (r < 0)
return NULL;
if (r == 0)
if (!k) {
return NULL;
}
return k;
}
}
char *joined;
int r;
if (dns_name_is_root(name)) {
return 0;
}
if (r < 0)
return r;
if (!new_key) {
return -ENOMEM;
}
return 0;
}
DnsResourceKey *k;
if (!k)
return NULL;
k->n_ref = 1;
return k;
}
if (!k)
return NULL;
k->n_ref++;
return k;
}
if (!k)
return NULL;
if (k->n_ref == 1) {
free(k);
} else
k->n_ref--;
return NULL;
}
/* Check if this is an A or AAAA resource key */
}
int r;
if (a == b)
return 1;
if (r <= 0)
return r;
return 0;
return 0;
return 1;
}
int dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain) {
int r;
return 1;
/* Checks if an rr matches the specified key. If a search
* domain is specified, it will also be checked if the key
* with the search domain suffixed might match the RR. */
return 0;
return 0;
if (r != 0)
return r;
if (search_domain) {
if (r < 0)
return r;
}
return 0;
}
int dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain) {
int r;
return 0;
else
return 0;
if (r != 0)
return r;
if (search_domain) {
if (r < 0)
return r;
}
return 0;
}
/* Checks whether 'soa' is a SOA record for the specified key. */
return 0;
return 0;
}
const DnsResourceKey *k = i;
assert(k);
}
static int dns_resource_key_compare_func(const void *a, const void *b) {
const DnsResourceKey *x = a, *y = b;
int ret;
if (ret != 0)
return ret;
return -1;
return 1;
return -1;
return 1;
return 0;
}
const struct hash_ops dns_resource_key_hash_ops = {
};
char cbuf[strlen("CLASS") + DECIMAL_STR_MAX(uint16_t)], tbuf[strlen("TYPE") + DECIMAL_STR_MAX(uint16_t)];
const char *c, *t;
char *s;
if (!c) {
c = cbuf;
}
if (!t){
t = tbuf;
}
return -ENOMEM;
*ret = s;
return 0;
}
if (!rr)
return NULL;
return rr;
}
if (!key)
return NULL;
return dns_resource_record_new(key);
}
if (!rr)
return NULL;
return rr;
}
if (!rr)
return NULL;
return NULL;
}
case DNS_TYPE_SRV:
break;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
break;
case DNS_TYPE_HINFO:
break;
case DNS_TYPE_TXT:
case DNS_TYPE_SPF:
break;
case DNS_TYPE_SOA:
break;
case DNS_TYPE_MX:
break;
case DNS_TYPE_DS:
break;
case DNS_TYPE_SSHFP:
break;
case DNS_TYPE_DNSKEY:
break;
case DNS_TYPE_RRSIG:
break;
case DNS_TYPE_NSEC:
break;
case DNS_TYPE_NSEC3:
break;
case DNS_TYPE_LOC:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
break;
default:
}
}
return NULL;
}
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
int r;
if (r < 0)
return r;
if (!key)
return -ENOMEM;
if (!rr)
return -ENOMEM;
return -ENOMEM;
return 0;
}
int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name) {
if (!rr)
return -ENOMEM;
if (!rr)
return -ENOMEM;
} else
return -EAFNOSUPPORT;
return 0;
}
int r;
assert(a);
assert(b);
if (a == b)
return 1;
if (r <= 0)
return r;
if (a->unparseable != b->unparseable)
return 0;
case DNS_TYPE_SRV:
if (r <= 0)
return r;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
case DNS_TYPE_HINFO:
case DNS_TYPE_SPF: /* exactly the same as TXT */
case DNS_TYPE_TXT:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
case DNS_TYPE_SOA:
if (r <= 0)
return r;
if (r <= 0)
return r;
case DNS_TYPE_MX:
return 0;
case DNS_TYPE_LOC:
case DNS_TYPE_DS:
case DNS_TYPE_SSHFP:
case DNS_TYPE_DNSKEY:
case DNS_TYPE_RRSIG:
/* do the fast comparisons first */
return false;
case DNS_TYPE_NSEC:
case DNS_TYPE_NSEC3:
memcmp(a->nsec3.next_hashed_name, b->nsec3.next_hashed_name, a->nsec3.next_hashed_name_size) == 0 &&
default:
}
}
char *s;
if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
NS,
EW,
alt / 100.,
siz / 100.,
hor / 100.,
ver / 100.) < 0)
return NULL;
return s;
}
return -EINVAL;
return -EINVAL;
return 0;
}
Iterator i;
unsigned type;
int r;
if (dns_type_to_string(type)) {
if (r < 0)
return NULL;
} else {
char *t;
if (r < 0)
return NULL;
r = strv_consume(&strv, t);
if (r < 0)
return NULL;
}
}
if (!str)
return NULL;
}
DnsTxtItem *i;
size_t c = 1;
char *p, *s;
p = s = new(char, c);
if (!s)
return NULL;
size_t j;
if (i != first)
*(p++) = ' ';
*(p++) = '"';
for (j = 0; j < i->length; j++) {
*(p++) = '\\';
} else
*(p++) = i->data[j];
}
*(p++) = '"';
}
*p = 0;
return s;
}
char *s;
int r;
if (r < 0)
return NULL;
case DNS_TYPE_SRV:
r = asprintf(&s, "%s %u %u %u %s",
k,
if (r < 0)
return NULL;
break;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
if (!s)
return NULL;
break;
case DNS_TYPE_HINFO:
if (!s)
return NULL;
break;
case DNS_TYPE_SPF: /* exactly the same as TXT */
case DNS_TYPE_TXT:
if (!t)
return NULL;
if (!s)
return NULL;
break;
case DNS_TYPE_A: {
_cleanup_free_ char *x = NULL;
if (r < 0)
return NULL;
if (!s)
return NULL;
break;
}
case DNS_TYPE_AAAA:
if (r < 0)
return NULL;
if (!s)
return NULL;
break;
case DNS_TYPE_SOA:
r = asprintf(&s, "%s %s %s %u %u %u %u %u",
k,
if (r < 0)
return NULL;
break;
case DNS_TYPE_MX:
r = asprintf(&s, "%s %u %s",
k,
if (r < 0)
return NULL;
break;
case DNS_TYPE_LOC:
if (!t)
return NULL;
if (!s)
return NULL;
break;
case DNS_TYPE_DS:
if (!t)
return NULL;
r = asprintf(&s, "%s %u %u %u %s",
k,
t);
if (r < 0)
return NULL;
break;
case DNS_TYPE_SSHFP:
if (!t)
return NULL;
r = asprintf(&s, "%s %u %u %s",
k,
t);
if (r < 0)
return NULL;
break;
case DNS_TYPE_DNSKEY: {
const char *alg;
if (!t)
return NULL;
r = asprintf(&s, "%s %u %u %.*s%.*u %s",
k,
t);
if (r < 0)
return NULL;
break;
}
case DNS_TYPE_RRSIG: {
if (!t)
return NULL;
if (r < 0)
return NULL;
if (r < 0)
return NULL;
/* TYPE?? follows
* http://tools.ietf.org/html/rfc3597#section-5 */
r = asprintf(&s, "%s %s%.*u %.*s%.*u %u %u %s %s %u %s %s",
k,
type ?: "TYPE",
t);
if (r < 0)
return NULL;
break;
}
case DNS_TYPE_NSEC:
if (!t)
return NULL;
r = asprintf(&s, "%s %s %s",
k,
t);
if (r < 0)
return NULL;
break;
case DNS_TYPE_NSEC3: {
if (!salt)
return NULL;
}
if (!hash)
return NULL;
if (!t)
return NULL;
k,
hash,
t);
if (r < 0)
return NULL;
break;
}
default:
if (!t)
return NULL;
if (r < 0)
return NULL;
break;
}
return s;
}
.n_ref = 1,
.on_stack = true,
.refuse_compression = true,
};
int r;
/* Generates the RR in wire-format, optionally in the
* canonical form as discussed in the DNSSEC RFC 4034, Section
* 6.2. We allocate a throw-away DnsPacket object on the stack
* here, because we need some book-keeping for memory
* management, and can reuse the DnsPacket serializer, that
* can generate the canonical form, too, but also knows label
* compression and suchlike. */
return 0;
if (r < 0)
return r;
return 0;
}
DnsTxtItem *n;
if (!i)
return NULL;
n = i->items_next;
free(i);
return dns_txt_item_free_all(n);
}
if (a == b)
return true;
if (!a != !b)
return false;
if (!a)
return true;
return false;
return false;
}
static const char* const dnssec_algorithm_table[_DNSSEC_ALGORITHM_MAX_DEFINED] = {
[DNSSEC_ALGORITHM_RSAMD5] = "RSAMD5",
[DNSSEC_ALGORITHM_DH] = "DH",
[DNSSEC_ALGORITHM_DSA] = "DSA",
[DNSSEC_ALGORITHM_ECC] = "ECC",
[DNSSEC_ALGORITHM_RSASHA1] = "RSASHA1",
[DNSSEC_ALGORITHM_DSA_NSEC3_SHA1] = "DSA-NSEC3-SHA1",
[DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1] = "RSASHA1-NSEC3-SHA1",
[DNSSEC_ALGORITHM_RSASHA256] = "RSASHA256",
[DNSSEC_ALGORITHM_RSASHA512] = "RSASHA512",
[DNSSEC_ALGORITHM_INDIRECT] = "INDIRECT",
[DNSSEC_ALGORITHM_PRIVATEDNS] = "PRIVATEDNS",
[DNSSEC_ALGORITHM_PRIVATEOID] = "PRIVATEOID",
};
static const char* const dnssec_digest_table[_DNSSEC_DIGEST_MAX_DEFINED] = {
[DNSSEC_DIGEST_SHA1] = "SHA1",
[DNSSEC_DIGEST_SHA256] = "SHA256",
};