resolved-dns-rr.c revision 0f84a72e3c0f58d71cff2121e6df1611eaf9c9ea
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering/***
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering This file is part of systemd.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering Copyright 2014 Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering (at your option) any later version.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering systemd is distributed in the hope that it will be useful, but
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering Lesser General Public License for more details.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering***/
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering#include <math.h>
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering#include "strv.h"
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering#include "resolved-dns-domain.h"
96115cdfe0241ae9b4e7177cd3874c0a93d00b39Thomas Hindoe Paaboel Andersen#include "resolved-dns-rr.h"
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering#include "resolved-dns-packet.h"
4b357e15876b730343db08719c877fdb45b6ad42Michael Marineau#include "dns-type.h"
4b357e15876b730343db08719c877fdb45b6ad42Michael Marineau
4b357e15876b730343db08719c877fdb45b6ad42Michael MarineauDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
4b357e15876b730343db08719c877fdb45b6ad42Michael Marineau DnsResourceKey *k;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering size_t l;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(name);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering l = strlen(name);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k = malloc0(sizeof(DnsResourceKey) + l + 1);
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek if (!k)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64cZbigniew Jędrzejewski-Szmek k->n_ref = 1;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering k->class = class;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering k->type = type;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering strcpy((char*) k + sizeof(DnsResourceKey), name);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return k;
14bf2c9d375db6a4670bc0ef0e521e35a939a498Lennart Poettering}
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-SzmekDnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name) {
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering DnsResourceKey *k;
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(name);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k = new0(DnsResourceKey, 1);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!k)
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering return NULL;
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek k->n_ref = 1;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k->class = class;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k->type = type;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k->_name = name;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return k;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart PoetteringDnsResourceKey* dns_resource_key_ref(DnsResourceKey *k) {
b94801803417c23d099cb7e508754181ecd27f9cZbigniew Jędrzejewski-Szmek
b94801803417c23d099cb7e508754181ecd27f9cZbigniew Jędrzejewski-Szmek if (!k)
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek return NULL;
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(k->n_ref > 0);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k->n_ref++;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek return k;
091526ab20485492124852dcf629787f35816df8Zbigniew Jędrzejewski-Szmek}
091526ab20485492124852dcf629787f35816df8Zbigniew Jędrzejewski-Szmek
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart PoetteringDnsResourceKey* dns_resource_key_unref(DnsResourceKey *k) {
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek if (!k)
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek return NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(k->n_ref > 0);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (k->n_ref == 1) {
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek free(k->_name);
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek free(k);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering } else
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k->n_ref--;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringint dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering int r;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek if (r <= 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return r;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (a->class != b->class)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (a->type != b->type)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 1;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringint dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(key);
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek assert(rr);
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (rr->key->class != key->class && key->class != DNS_CLASS_ANY)
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek return 0;
7384146530ac083efbef62b9ef5bb82c56565cd4Zbigniew Jędrzejewski-Szmek
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (rr->key->type != key->type && key->type != DNS_TYPE_ANY)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringint dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(key);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(rr);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (rr->key->class != key->class && key->class != DNS_CLASS_ANY)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (rr->key->type != DNS_TYPE_CNAME)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringstatic unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering const DnsResourceKey *k = i;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering unsigned long ul;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering ul = dns_name_hash_func(DNS_RESOURCE_KEY_NAME(k), hash_key);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering ul = ul * hash_key[0] + ul + k->class;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering ul = ul * hash_key[1] + ul + k->type;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return ul;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1ebab691c7749779072741f71865bd0e055b7ecfLennart Poetteringstatic int dns_resource_key_compare_func(const void *a, const void *b) {
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poettering const DnsResourceKey *x = a, *y = b;
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poettering int ret;
ee530d8b73246f29781bd54a707ca75c7ef5a6cbLennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering ret = dns_name_compare_func(DNS_RESOURCE_KEY_NAME(x), DNS_RESOURCE_KEY_NAME(y));
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (ret != 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return ret;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (x->type < y->type)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -1;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (x->type > y->type)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 1;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (x->class < y->class)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -1;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (x->class > y->class)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 1;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poetteringconst struct hash_ops dns_resource_key_hash_ops = {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering .hash = dns_resource_key_hash_func,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering .compare = dns_resource_key_compare_func
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering};
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poetteringint dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering char cbuf[DECIMAL_STR_MAX(uint16_t)], tbuf[DECIMAL_STR_MAX(uint16_t)];
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering const char *c, *t;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering char *s;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering c = dns_class_to_string(key->class);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (!c) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering sprintf(cbuf, "%i", key->class);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering c = cbuf;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering }
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering t = dns_type_to_string(key->type);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (!t){
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering sprintf(tbuf, "%i", key->type);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering t = tbuf;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering }
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (asprintf(&s, "%s %s %-5s", DNS_RESOURCE_KEY_NAME(key), c, t) < 0)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return -ENOMEM;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering *ret = s;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return 0;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering}
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering DnsResourceRecord *rr;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering rr = new0(DnsResourceRecord, 1);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (!rr)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering rr->n_ref = 1;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering rr->key = dns_resource_key_ref(key);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return rr;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering}
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart PoetteringDnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering key = dns_resource_key_new(class, type, name);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (!key)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return dns_resource_record_new(key);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering}
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart PoetteringDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (!rr)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert(rr->n_ref > 0);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering rr->n_ref++;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return rr;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering}
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (!rr)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert(rr->n_ref > 0);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (rr->n_ref > 1) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering rr->n_ref--;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering }
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (rr->key) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering switch(rr->key->type) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_SRV:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->srv.name);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_PTR:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_NS:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_CNAME:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_DNAME:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->ptr.name);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_HINFO:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->hinfo.cpu);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->hinfo.os);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_TXT:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_SPF:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering strv_free(rr->txt.strings);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_SOA:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->soa.mname);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->soa.rname);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_MX:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->mx.exchange);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_SSHFP:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->sshfp.key);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_DNSKEY:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->dnskey.key);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_RRSIG:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->rrsig.signer);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr->rrsig.signature);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_LOC:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_A:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_AAAA:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering break;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering default:
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering free(rr->generic.data);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering }
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering dns_resource_key_unref(rr->key);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering }
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering free(rr);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering return NULL;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering}
4b1b14a6a6acb1640596d5e9542829d32989d385Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poetteringint dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
4b1b14a6a6acb1640596d5e9542829d32989d385Lennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering _cleanup_free_ char *ptr = NULL;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering int r;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert(ret);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert(address);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering assert(hostname);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering r = dns_name_reverse(family, address, &ptr);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (r < 0)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return r;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering key = dns_resource_key_new_consume(DNS_CLASS_IN, DNS_TYPE_PTR, ptr);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!key)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering ptr = NULL;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering rr = dns_resource_record_new(key);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering if (!rr)
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->ptr.name = strdup(hostname);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!rr->ptr.name)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering *ret = rr;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr = NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poettering return 0;
c3834f9b881f2b1a68dc7d797c134f0b66b47b57Lennart Poettering}
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poetteringint dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b) {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering int r;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering assert(a);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering assert(b);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering r = dns_resource_key_equal(a->key, b->key);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r <= 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return r;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering if (a->unparseable != b->unparseable)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return 0;
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering switch (a->unparseable ? _DNS_TYPE_INVALID : a->key->type) {
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering case DNS_TYPE_SRV:
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering r = dns_name_equal(a->srv.name, b->srv.name);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r <= 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return r;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return a->srv.priority == b->srv.priority &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->srv.weight == b->srv.weight &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->srv.port == b->srv.port;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering case DNS_TYPE_PTR:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_NS:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_CNAME:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_DNAME:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return dns_name_equal(a->ptr.name, b->ptr.name);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_HINFO:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return strcaseeq(a->hinfo.cpu, b->hinfo.cpu) &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering strcaseeq(a->hinfo.os, b->hinfo.os);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_SPF: /* exactly the same as TXT */
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_TXT:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return strv_equal(a->txt.strings, b->txt.strings);
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek case DNS_TYPE_A:
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek return memcmp(&a->a.in_addr, &b->a.in_addr, sizeof(struct in_addr)) == 0;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering case DNS_TYPE_AAAA:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return memcmp(&a->aaaa.in6_addr, &b->aaaa.in6_addr, sizeof(struct in6_addr)) == 0;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_SOA:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = dns_name_equal(a->soa.mname, b->soa.mname);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r <= 0)
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek return r;
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek r = dns_name_equal(a->soa.rname, b->soa.rname);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r <= 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return r;
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek return a->soa.serial == b->soa.serial &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->soa.refresh == b->soa.refresh &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->soa.retry == b->soa.retry &&
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek a->soa.expire == b->soa.expire &&
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek a->soa.minimum == b->soa.minimum;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_MX:
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek if (a->mx.priority != b->mx.priority)
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek return 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return dns_name_equal(a->mx.exchange, b->mx.exchange);
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek case DNS_TYPE_LOC:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(a->loc.version == b->loc.version);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return a->loc.size == b->loc.size &&
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering a->loc.horiz_pre == b->loc.horiz_pre &&
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek a->loc.vert_pre == b->loc.vert_pre &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->loc.latitude == b->loc.latitude &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->loc.longitude == b->loc.longitude &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->loc.altitude == b->loc.altitude;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering case DNS_TYPE_SSHFP:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return a->sshfp.algorithm == b->sshfp.algorithm &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->sshfp.fptype == b->sshfp.fptype &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->sshfp.key_size == b->sshfp.key_size &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering memcmp(a->sshfp.key, b->sshfp.key, a->sshfp.key_size) == 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_DNSKEY:
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek return a->dnskey.zone_key_flag == b->dnskey.zone_key_flag &&
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek a->dnskey.sep_flag == b->dnskey.sep_flag &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->dnskey.algorithm == b->dnskey.algorithm &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->dnskey.key_size == b->dnskey.key_size &&
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek memcmp(a->dnskey.key, b->dnskey.key, a->dnskey.key_size) == 0;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_RRSIG:
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek /* do the fast comparisons first */
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (a->rrsig.type_covered != b->rrsig.type_covered ||
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->rrsig.algorithm != b->rrsig.algorithm ||
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek a->rrsig.labels != b->rrsig.labels ||
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek a->rrsig.original_ttl != b->rrsig.original_ttl ||
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->rrsig.expiration != b->rrsig.expiration ||
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering a->rrsig.inception != b->rrsig.inception ||
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering a->rrsig.key_tag != b->rrsig.key_tag ||
843f737ade9c73609a2280dd3dd16e18222a5dcbŁukasz Stelmach a->rrsig.signature_size != b->rrsig.signature_size ||
b94801803417c23d099cb7e508754181ecd27f9cZbigniew Jędrzejewski-Szmek memcmp(a->rrsig.signature, b->rrsig.signature, a->rrsig.signature_size) != 0)
843f737ade9c73609a2280dd3dd16e18222a5dcbŁukasz Stelmach return false;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek return dns_name_equal(a->rrsig.signer, b->rrsig.signer);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering default:
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek return a->generic.size == b->generic.size &&
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering memcmp(a->generic.data, b->generic.data, a->generic.size) == 0;
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek }
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering}
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmekstatic char* format_location(uint32_t latitude, uint32_t longitude, uint32_t altitude,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering uint8_t size, uint8_t horiz_pre, uint8_t vert_pre) {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering char *s;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering char NS = latitude >= 1U<<31 ? 'N' : 'S';
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering char EW = longitude >= 1U<<31 ? 'E' : 'W';
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering int lat = latitude >= 1U<<31 ? (int) (latitude - (1U<<31)) : (int) ((1U<<31) - latitude);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering int lon = longitude >= 1U<<31 ? (int) (longitude - (1U<<31)) : (int) ((1U<<31) - longitude);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering double alt = altitude >= 10000000u ? altitude - 10000000u : -(double)(10000000u - altitude);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering double siz = (size >> 4) * exp10((double) (size & 0xF));
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering double hor = (horiz_pre >> 4) * exp10((double) (horiz_pre & 0xF));
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering double ver = (vert_pre >> 4) * exp10((double) (vert_pre & 0xF));
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering (lat / 60000 / 60),
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering (lat / 60000) % 60,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering (lat % 60000) / 1000.,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering NS,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering (lon / 60000 / 60),
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering (lon / 60000) % 60,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering (lon % 60000) / 1000.,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering EW,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering alt / 100.,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering siz / 100.,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering hor / 100.,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering ver / 100.) < 0)
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering return NULL;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering return s;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering}
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poetteringint dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering _cleanup_free_ char *k = NULL, *t = NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering char *s;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering int r;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering assert(rr);
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering r = dns_resource_key_to_string(rr->key, &k);
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering if (r < 0)
1af7211984a8dba3c5ba40fae794c4c55f5e6bd3Lennart Poettering return r;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_SRV:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = asprintf(&s, "%s %u %u %u %s",
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek k,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->srv.priority,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->srv.weight,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->srv.port,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering strna(rr->srv.name));
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r < 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering break;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_PTR:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_NS:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_CNAME:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_DNAME:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering s = strjoin(k, " ", rr->ptr.name, NULL);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!s)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering break;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek case DNS_TYPE_HINFO:
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek s = strjoin(k, " ", rr->hinfo.cpu, " ", rr->hinfo.os, NULL);
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek if (!s)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering break;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_SPF: /* exactly the same as TXT */
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_TXT:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering t = strv_join_quoted(rr->txt.strings);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!t)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering s = strjoin(k, " ", t, NULL);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!s)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering break;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_A: {
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering _cleanup_free_ char *x = NULL;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = in_addr_to_string(AF_INET, (const union in_addr_union*) &rr->a.in_addr, &x);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r < 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return r;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering s = strjoin(k, " ", x, NULL);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!s)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering break;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering }
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_AAAA:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = in_addr_to_string(AF_INET6, (const union in_addr_union*) &rr->aaaa.in6_addr, &t);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r < 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return r;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering s = strjoin(k, " ", t, NULL);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!s)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering break;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering case DNS_TYPE_SOA:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = asprintf(&s, "%s %s %s %u %u %u %u %u",
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering k,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering strna(rr->soa.mname),
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering strna(rr->soa.rname),
c51cf05646a11c65daf65c1123c77efb068f4f7bZbigniew Jędrzejewski-Szmek rr->soa.serial,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->soa.refresh,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->soa.retry,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->soa.expire,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->soa.minimum);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r < 0)
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering return -ENOMEM;
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek break;
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering case DNS_TYPE_MX:
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering r = asprintf(&s, "%s %u %s",
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering k,
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek rr->mx.priority,
b47d419c25ecc735615a1088060c1ec8bef1e41fZbigniew Jędrzejewski-Szmek rr->mx.exchange);
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering if (r < 0)
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering return -ENOMEM;
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek break;
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering case DNS_TYPE_LOC:
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering assert(rr->loc.version == 0);
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek t = format_location(rr->loc.latitude,
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering rr->loc.longitude,
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering rr->loc.altitude,
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek rr->loc.size,
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering rr->loc.horiz_pre,
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering rr->loc.vert_pre);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!t)
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek return -ENOMEM;
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering s = strjoin(k, " ", t, NULL);
1ca208fb4f93e5869704af1812cbff7130a2fc03Zbigniew Jędrzejewski-Szmek if (!s)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering break;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering case DNS_TYPE_SSHFP:
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering t = hexmem(rr->sshfp.key, rr->sshfp.key_size);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!t)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = asprintf(&s, "%s %u %u %s",
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->sshfp.algorithm,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->sshfp.fptype,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering t);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r < 0)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering break;
9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64cZbigniew Jędrzejewski-Szmek
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering case DNS_TYPE_DNSKEY: {
9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64cZbigniew Jędrzejewski-Szmek const char *alg;
9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64cZbigniew Jędrzejewski-Szmek
9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64cZbigniew Jędrzejewski-Szmek alg = dnssec_algorithm_to_string(rr->dnskey.algorithm);
9a5cb1371b6d8b0a04bd08665bcf9b06cb40c64cZbigniew Jędrzejewski-Szmek
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering t = hexmem(rr->dnskey.key, rr->dnskey.key_size);
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering if (!t)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering r = asprintf(&s, "%s %u 3 %.*s%.*u %s",
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering k,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering dnskey_to_flags(rr),
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering alg ? -1 : 0, alg,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering alg ? 0 : 1, alg ? 0u : (unsigned) rr->dnskey.algorithm,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering t);
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering if (r < 0)
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering return -ENOMEM;
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering break;
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering }
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering case DNS_TYPE_RRSIG: {
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering const char *type, *alg;
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering type = dns_type_to_string(rr->rrsig.type_covered);
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering alg = dnssec_algorithm_to_string(rr->rrsig.algorithm);
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering t = hexmem(rr->rrsig.signature, rr->rrsig.signature_size);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (!t)
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering return -ENOMEM;
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering /* TYPE?? follows
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering * http://tools.ietf.org/html/rfc3597#section-5 */
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering r = asprintf(&s, "%s %s%.*u %.*s%.*u %u %u %u %u %u %s %s",
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering k,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering type ?: "TYPE",
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering type ? 0 : 1, type ? 0u : (unsigned) rr->rrsig.type_covered,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering alg ? -1 : 0, alg,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering alg ? 0 : 1, alg ? 0u : (unsigned) rr->rrsig.algorithm,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->rrsig.labels,
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering rr->rrsig.original_ttl,
3db604b907323b8df0fc810216f6112056d26a02Lennart Poettering rr->rrsig.expiration,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering rr->rrsig.inception,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering rr->rrsig.key_tag,
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering rr->rrsig.signer,
e48fdd84432bbf9c2ecc339183258c7c33116032Lennart Poettering t);
1a14a53cfded6e78c6e8dfb73fdff0039971d642Lennart Poettering if (r < 0)
return -ENOMEM;
break;
}
default:
t = hexmem(rr->generic.data, rr->generic.size);
if (!t)
return -ENOMEM;
s = strjoin(k, " ", t, NULL);
if (!s)
return -ENOMEM;
break;
}
*ret = s;
return 0;
}
const char *dns_class_to_string(uint16_t class) {
switch (class) {
case DNS_CLASS_IN:
return "IN";
case DNS_CLASS_ANY:
return "ANY";
}
return NULL;
}
int dns_class_from_string(const char *s, uint16_t *class) {
assert(s);
assert(class);
if (strcaseeq(s, "IN"))
*class = DNS_CLASS_IN;
else if (strcaseeq(s, "ANY"))
*class = DNS_TYPE_ANY;
else
return -EINVAL;
return 0;
}