resolved-dns-rr.c revision 78c6a153c47f8d597c827bdcaf8c4e42ac87f738
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering This file is part of systemd.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Copyright 2014 Lennart Poettering
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering (at your option) any later version.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is distributed in the hope that it will be useful, but
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Lesser General Public License for more details.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
7027ff61a34a12487712b382a061c654acc3a679Lennart PoetteringDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
d7bd3de0654669e65b9642c248c5fa6d1d9a9f61Lennart Poettering k = malloc0(sizeof(DnsResourceKey) + l + 1);
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering strcpy((char*) k + sizeof(DnsResourceKey), name);
6c03089c32c251d823173bda4d809a9e643219f0Lennart PoetteringDnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name) {
6c03089c32c251d823173bda4d809a9e643219f0Lennart PoetteringDnsResourceKey* dns_resource_key_ref(DnsResourceKey *k) {
d7bd3de0654669e65b9642c248c5fa6d1d9a9f61Lennart PoetteringDnsResourceKey* dns_resource_key_unref(DnsResourceKey *k) {
374ec6abf31ada6ca554cc8ea99b282373fac010Lennart Poetteringint dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poetteringint dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr) {
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering if (rr->key->class != key->class && key->class != DNS_CLASS_ANY)
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering if (rr->key->type != key->type && key->type != DNS_TYPE_ANY)
374ec6abf31ada6ca554cc8ea99b282373fac010Lennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
374ec6abf31ada6ca554cc8ea99b282373fac010Lennart Poetteringint dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr) {
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering if (rr->key->class != key->class && key->class != DNS_CLASS_ANY)
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poetteringstatic unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering unsigned long ul;
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering ul = dns_name_hash_func(DNS_RESOURCE_KEY_NAME(k), hash_key);
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poetteringstatic int dns_resource_key_compare_func(const void *a, const void *b) {
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering const DnsResourceKey *x = a, *y = b;
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering ret = dns_name_compare_func(DNS_RESOURCE_KEY_NAME(x), DNS_RESOURCE_KEY_NAME(y));
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poetteringconst struct hash_ops dns_resource_key_hash_ops = {
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poetteringint dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering char cbuf[strlen("CLASS") + DECIMAL_STR_MAX(uint16_t)], tbuf[strlen("TYPE") + DECIMAL_STR_MAX(uint16_t)];
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering const char *c, *t;
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering if (asprintf(&s, "%s %s %-5s", DNS_RESOURCE_KEY_NAME(key), c, t) < 0)
ae018d9bc900d6355dea4af05119b49c67945184Lennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart PoetteringDnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name) {
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart Poettering key = dns_resource_key_new(class, type, name);
a016b9228f338cb9b380ce7e00826ef462767d98Lennart PoetteringDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
a016b9228f338cb9b380ce7e00826ef462767d98Lennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
case DNS_TYPE_DNAME:
case DNS_TYPE_HINFO:
case DNS_TYPE_TXT:
case DNS_TYPE_SPF:
case DNS_TYPE_SOA:
case DNS_TYPE_MX:
case DNS_TYPE_DS:
case DNS_TYPE_SSHFP:
case DNS_TYPE_DNSKEY:
case DNS_TYPE_RRSIG:
case DNS_TYPE_NSEC:
case DNS_TYPE_NSEC3:
case DNS_TYPE_LOC:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
return NULL;
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
if (!key)
return -ENOMEM;
if (!rr)
return -ENOMEM;
return -ENOMEM;
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;
return -EAFNOSUPPORT;
assert(a);
assert(b);
case DNS_TYPE_SRV:
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
case DNS_TYPE_HINFO:
case DNS_TYPE_TXT:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
case DNS_TYPE_SOA:
case DNS_TYPE_MX:
case DNS_TYPE_LOC:
case DNS_TYPE_DS:
case DNS_TYPE_SSHFP:
case DNS_TYPE_DNSKEY:
case DNS_TYPE_RRSIG:
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 &&
NS,
EW,
return NULL;
return -EINVAL;
return -EINVAL;
Iterator i;
unsigned type;
return NULL;
return NULL;
return NULL;
if (!str)
return NULL;
case DNS_TYPE_SRV:
return -ENOMEM;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
return -ENOMEM;
case DNS_TYPE_HINFO:
return -ENOMEM;
case DNS_TYPE_TXT:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_A: {
return -ENOMEM;
case DNS_TYPE_AAAA:
return -ENOMEM;
case DNS_TYPE_SOA:
return -ENOMEM;
case DNS_TYPE_MX:
return -ENOMEM;
case DNS_TYPE_LOC:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_DS:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_SSHFP:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_DNSKEY: {
const char *alg;
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_RRSIG: {
return -ENOMEM;
* http://tools.ietf.org/html/rfc3597#section-5 */
return -ENOMEM;
case DNS_TYPE_NSEC:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_NSEC3: {
if (!salt)
return -ENOMEM;
if (!hash)
return -ENOMEM;
return -ENOMEM;
hash,
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
*ret = s;
switch (class) {
case DNS_CLASS_IN:
case DNS_CLASS_ANY:
return NULL;
assert(s);
return -EINVAL;