74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/***
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2014 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering***/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek#include <math.h>
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
4ad7f2761da661853dcc29d542efb4727abb1101Nick Owens#include "dns-domain.h"
7263f72499e962b3fd54cdb7c79d49ca72121edeZbigniew Jędrzejewski-Szmek#include "dns-type.h"
e4e73a632524c382139034d4271f53b6089ab4cbLennart Poettering#include "hexdecoct.h"
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek#include "resolved-dns-dnssec.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "resolved-dns-packet.h"
e4e73a632524c382139034d4271f53b6089ab4cbLennart Poettering#include "resolved-dns-rr.h"
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering#include "string-table.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "string-util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "strv.h"
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek#include "terminal-util.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DnsResourceKey *k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering size_t l;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering l = strlen(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k = malloc0(sizeof(DnsResourceKey) + l + 1);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref = 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->class = class;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->type = type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering strcpy((char*) k + sizeof(DnsResourceKey), name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom GundersenDnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname) {
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering int r;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen assert(key);
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen assert(cname);
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering assert(IN_SET(cname->key->type, DNS_TYPE_CNAME, DNS_TYPE_DNAME));
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (cname->key->type == DNS_TYPE_CNAME)
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return dns_resource_key_new(key->class, key->type, cname->cname.name);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering else {
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering DnsResourceKey *k;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering char *destination = NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering r = dns_name_change_suffix(DNS_RESOURCE_KEY_NAME(key), DNS_RESOURCE_KEY_NAME(cname->key), cname->dname.name, &destination);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (r < 0)
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (r == 0)
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return dns_resource_key_ref((DnsResourceKey*) key);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k = dns_resource_key_new_consume(key->class, key->type, destination);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (!k) {
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering free(destination);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering }
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return k;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering }
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen}
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poetteringint dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering DnsResourceKey *new_key;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering char *joined;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering int r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(ret);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(key);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(name);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
dc477e7385e8ab29efb8fadb72ec994077a105c6Lennart Poettering if (dns_name_is_root(name)) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering *ret = dns_resource_key_ref(key);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering }
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering r = dns_name_concat(DNS_RESOURCE_KEY_NAME(key), name, &joined);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (r < 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering new_key = dns_resource_key_new_consume(key->class, key->type, joined);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!new_key) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering free(joined);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return -ENOMEM;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering }
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering *ret = new_key;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DnsResourceKey *k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k = new0(DnsResourceKey, 1);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref = 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->class = class;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->type = type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->_name = name;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_ref(DnsResourceKey *k) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering /* Static/const keys created with DNS_RESOURCE_KEY_CONST will
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering * set this to -1, they should not be reffed/unreffed */
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering assert(k->n_ref != (unsigned) -1);
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(k->n_ref > 0);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref++;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_unref(DnsResourceKey *k) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering assert(k->n_ref != (unsigned) -1);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(k->n_ref > 0);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (k->n_ref == 1) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(k->_name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(k);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering } else
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref--;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poetteringbool dns_resource_key_is_address(const DnsResourceKey *key) {
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering assert(key);
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering /* Check if this is an A or AAAA resource key */
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering return key->class == DNS_CLASS_IN && IN_SET(key->type, DNS_TYPE_A, DNS_TYPE_AAAA);
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering}
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering int r;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering if (a == b)
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering return 1;
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (r <= 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return r;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (a->class != b->class)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (a->type != b->type)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poetteringint dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering int r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(rr);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering if (key == rr->key)
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering return 1;
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering /* Checks if an rr matches the specified key. If a search
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering * domain is specified, it will also be checked if the key
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering * with the search domain suffixed might match the RR. */
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (rr->key->class != key->class && key->class != DNS_CLASS_ANY)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (rr->key->type != key->type && key->type != DNS_TYPE_ANY)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (r != 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (search_domain) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering _cleanup_free_ char *joined = NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering r = dns_name_concat(DNS_RESOURCE_KEY_NAME(key), search_domain, &joined);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (r < 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), joined);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering }
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersenint dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering int r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(key);
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen assert(cname);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (cname->class != key->class && key->class != DNS_CLASS_ANY)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (cname->type == DNS_TYPE_CNAME)
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen r = dns_name_equal(DNS_RESOURCE_KEY_NAME(key), DNS_RESOURCE_KEY_NAME(cname));
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen else if (cname->type == DNS_TYPE_DNAME)
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen r = dns_name_endswith(DNS_RESOURCE_KEY_NAME(key), DNS_RESOURCE_KEY_NAME(cname));
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering else
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (r != 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (search_domain) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering _cleanup_free_ char *joined = NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering r = dns_name_concat(DNS_RESOURCE_KEY_NAME(key), search_domain, &joined);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (r < 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (cname->type == DNS_TYPE_CNAME)
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen return dns_name_equal(joined, DNS_RESOURCE_KEY_NAME(cname));
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen else if (cname->type == DNS_TYPE_DNAME)
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen return dns_name_endswith(joined, DNS_RESOURCE_KEY_NAME(cname));
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering }
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering}
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poetteringint dns_resource_key_match_soa(const DnsResourceKey *key, const DnsResourceKey *soa) {
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering assert(soa);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering assert(key);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering /* Checks whether 'soa' is a SOA record for the specified key. */
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
65b200e70d01cb7c513114b602c9b5cf41348f77Lennart Poettering if (soa->class != key->class)
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering if (soa->type != DNS_TYPE_SOA)
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering return 0;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
0936416a1cba187dc76903dae73246f4cbddf312Lennart Poettering return dns_name_endswith(DNS_RESOURCE_KEY_NAME(key), DNS_RESOURCE_KEY_NAME(soa));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersenstatic void dns_resource_key_hash_func(const void *i, struct siphash *state) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering const DnsResourceKey *k = i;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen assert(k);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen dns_name_hash_func(DNS_RESOURCE_KEY_NAME(k), state);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen siphash24_compress(&k->class, sizeof(k->class), state);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen siphash24_compress(&k->type, sizeof(k->type), state);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtstatic int dns_resource_key_compare_func(const void *a, const void *b) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering const DnsResourceKey *x = a, *y = b;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering int ret;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering ret = dns_name_compare_func(DNS_RESOURCE_KEY_NAME(x), DNS_RESOURCE_KEY_NAME(y));
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (ret != 0)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return ret;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->type < y->type)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->type > y->type)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return 1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->class < y->class)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->class > y->class)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return 1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return 0;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtconst struct hash_ops dns_resource_key_hash_ops = {
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt .hash = dns_resource_key_hash_func,
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt .compare = dns_resource_key_compare_func
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt};
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen char cbuf[strlen("CLASS") + DECIMAL_STR_MAX(uint16_t)], tbuf[strlen("TYPE") + DECIMAL_STR_MAX(uint16_t)];
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering const char *c, *t, *n;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering char *s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering /* If we cannot convert the CLASS/TYPE into a known string,
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering use the format recommended by RFC 3597, Section 5. */
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering c = dns_class_to_string(key->class);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!c) {
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen sprintf(cbuf, "CLASS%u", key->class);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering c = cbuf;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering t = dns_type_to_string(key->type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!t){
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen sprintf(tbuf, "TYPE%u", key->type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering t = tbuf;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering n = DNS_RESOURCE_KEY_NAME(key);
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering if (asprintf(&s, "%s%s %s %-5s", n, endswith(n, ".") ? "" : ".", c, t) < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering *ret = s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return 0;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering}
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poetteringbool dns_resource_key_reduce(DnsResourceKey **a, DnsResourceKey **b) {
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(a);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(b);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering /* Try to replace one RR key by another if they are identical, thus saving a bit of memory. Note that we do
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering * this only for RR keys, not for RRs themselves, as they carry a lot of additional metadata (where they come
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering * from, validity data, and suchlike), and cannot be replaced so easily by other RRs that have the same
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering * superficial data. */
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (!*a)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return false;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (!*b)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return false;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering /* We refuse merging const keys */
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if ((*a)->n_ref == (unsigned) -1)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return false;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if ((*b)->n_ref == (unsigned) -1)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return false;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering /* Already the same? */
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (*a == *b)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return true;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering /* Are they really identical? */
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (dns_resource_key_equal(*a, *b) <= 0)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return false;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering /* Keep the one which already has more references. */
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if ((*a)->n_ref > (*b)->n_ref) {
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering dns_resource_key_unref(*b);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering *b = dns_resource_key_ref(*a);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering } else {
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering dns_resource_key_unref(*a);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering *a = dns_resource_key_ref(*b);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering }
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return true;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering}
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DnsResourceRecord *rr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr = new0(DnsResourceRecord, 1);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!rr)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->n_ref = 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering rr->key = dns_resource_key_ref(key);
ee3d6aff9bd73c1b23e29d1fa1fa6f7a1ef0533bLennart Poettering rr->expiry = USEC_INFINITY;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering rr->n_skip_labels_signer = rr->n_skip_labels_source = (unsigned) -1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return rr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart PoetteringDnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name) {
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering key = dns_resource_key_new(class, type, name);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering if (!key)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return NULL;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return dns_resource_record_new(key);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering}
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart PoetteringDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!rr)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(rr->n_ref > 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->n_ref++;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return rr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!rr)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(rr->n_ref > 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (rr->n_ref > 1) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->n_ref--;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (rr->key) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek switch(rr->key->type) {
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SRV:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering free(rr->srv.name);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_PTR:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_NS:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_CNAME:
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering case DNS_TYPE_DNAME:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(rr->ptr.name);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_HINFO:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(rr->hinfo.cpu);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(rr->hinfo.os);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_TXT:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SPF:
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering dns_txt_item_free_all(rr->txt.items);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_SOA:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering free(rr->soa.mname);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering free(rr->soa.rname);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_MX:
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek free(rr->mx.exchange);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen case DNS_TYPE_DS:
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen free(rr->ds.digest);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen break;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering case DNS_TYPE_SSHFP:
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen free(rr->sshfp.fingerprint);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering break;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_DNSKEY:
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek free(rr->dnskey.key);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek break;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek case DNS_TYPE_RRSIG:
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek free(rr->rrsig.signer);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek free(rr->rrsig.signature);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek break;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen case DNS_TYPE_NSEC:
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen free(rr->nsec.next_domain_name);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen bitmap_free(rr->nsec.types);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen break;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen case DNS_TYPE_NSEC3:
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen free(rr->nsec3.next_hashed_name);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen free(rr->nsec3.salt);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen bitmap_free(rr->nsec3.types);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen break;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_LOC:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_A:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_AAAA:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek case DNS_TYPE_TLSA:
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek free(rr->tlsa.data);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek break;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek case DNS_TYPE_OPENPGPKEY:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek default:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(rr->generic.data);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering free(rr->wire_format);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering dns_resource_key_unref(rr->key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering free(rr->to_string);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(rr);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering _cleanup_free_ char *ptr = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering int r;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert(ret);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert(address);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert(hostname);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = dns_name_reverse(family, address, &ptr);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return r;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering key = dns_resource_key_new_consume(DNS_CLASS_IN, DNS_TYPE_PTR, ptr);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!key)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering ptr = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering rr = dns_resource_record_new(key);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!rr)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering rr->ptr.name = strdup(hostname);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!rr->ptr.name)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering *ret = rr;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering rr = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return 0;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering}
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poetteringint dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering DnsResourceRecord *rr;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering assert(ret);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering assert(address);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering assert(family);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (family == AF_INET) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, name);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!rr)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->a.in_addr = address->in;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering } else if (family == AF_INET6) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_AAAA, name);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!rr)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->aaaa.in6_addr = address->in6;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering } else
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -EAFNOSUPPORT;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering *ret = rr;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return 0;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering}
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek#define FIELD_EQUAL(a, b, field) \
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek ((a).field ## _size == (b).field ## _size && \
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek memcmp((a).field, (b).field, (a).field ## _size) == 0)
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringint dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering int r;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(a);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(b);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering if (a == b)
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering return 1;
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering r = dns_resource_key_equal(a->key, b->key);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (r <= 0)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return r;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering if (a->unparseable != b->unparseable)
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering return 0;
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering switch (a->unparseable ? _DNS_TYPE_INVALID : a->key->type) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SRV:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = dns_name_equal(a->srv.name, b->srv.name);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (r <= 0)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return r;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return a->srv.priority == b->srv.priority &&
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering a->srv.weight == b->srv.weight &&
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering a->srv.port == b->srv.port;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_PTR:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_NS:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_CNAME:
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering case DNS_TYPE_DNAME:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return dns_name_equal(a->ptr.name, b->ptr.name);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_HINFO:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return strcaseeq(a->hinfo.cpu, b->hinfo.cpu) &&
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering strcaseeq(a->hinfo.os, b->hinfo.os);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_SPF: /* exactly the same as TXT */
0f84a72e3c0f58d71cff2121e6df1611eaf9c9eaDavid Herrmann case DNS_TYPE_TXT:
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return dns_txt_item_equal(a->txt.items, b->txt.items);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_A:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return memcmp(&a->a.in_addr, &b->a.in_addr, sizeof(struct in_addr)) == 0;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_AAAA:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return memcmp(&a->aaaa.in6_addr, &b->aaaa.in6_addr, sizeof(struct in6_addr)) == 0;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_SOA:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering r = dns_name_equal(a->soa.mname, b->soa.mname);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (r <= 0)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return r;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering r = dns_name_equal(a->soa.rname, b->soa.rname);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (r <= 0)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return r;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return a->soa.serial == b->soa.serial &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.refresh == b->soa.refresh &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.retry == b->soa.retry &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.expire == b->soa.expire &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.minimum == b->soa.minimum;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek case DNS_TYPE_MX:
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek if (a->mx.priority != b->mx.priority)
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return 0;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return dns_name_equal(a->mx.exchange, b->mx.exchange);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_LOC:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert(a->loc.version == b->loc.version);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return a->loc.size == b->loc.size &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.horiz_pre == b->loc.horiz_pre &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.vert_pre == b->loc.vert_pre &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.latitude == b->loc.latitude &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.longitude == b->loc.longitude &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.altitude == b->loc.altitude;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen case DNS_TYPE_DS:
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return a->ds.key_tag == b->ds.key_tag &&
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen a->ds.algorithm == b->ds.algorithm &&
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen a->ds.digest_type == b->ds.digest_type &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek FIELD_EQUAL(a->ds, b->ds, digest);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering case DNS_TYPE_SSHFP:
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering return a->sshfp.algorithm == b->sshfp.algorithm &&
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering a->sshfp.fptype == b->sshfp.fptype &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek FIELD_EQUAL(a->sshfp, b->sshfp, fingerprint);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_DNSKEY:
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering return a->dnskey.flags == b->dnskey.flags &&
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering a->dnskey.protocol == b->dnskey.protocol &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek a->dnskey.algorithm == b->dnskey.algorithm &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek FIELD_EQUAL(a->dnskey, b->dnskey, key);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek case DNS_TYPE_RRSIG:
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek /* do the fast comparisons first */
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek return a->rrsig.type_covered == b->rrsig.type_covered &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->rrsig.algorithm == b->rrsig.algorithm &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->rrsig.labels == b->rrsig.labels &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->rrsig.original_ttl == b->rrsig.original_ttl &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->rrsig.expiration == b->rrsig.expiration &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->rrsig.inception == b->rrsig.inception &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->rrsig.key_tag == b->rrsig.key_tag &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek FIELD_EQUAL(a->rrsig, b->rrsig, signature) &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek dns_name_equal(a->rrsig.signer, b->rrsig.signer);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen case DNS_TYPE_NSEC:
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return dns_name_equal(a->nsec.next_domain_name, b->nsec.next_domain_name) &&
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen bitmap_equal(a->nsec.types, b->nsec.types);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen case DNS_TYPE_NSEC3:
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen return a->nsec3.algorithm == b->nsec3.algorithm &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->nsec3.flags == b->nsec3.flags &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek a->nsec3.iterations == b->nsec3.iterations &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek FIELD_EQUAL(a->nsec3, b->nsec3, salt) &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek FIELD_EQUAL(a->nsec3, b->nsec3, next_hashed_name) &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek bitmap_equal(a->nsec3.types, b->nsec3.types);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek case DNS_TYPE_TLSA:
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek return a->tlsa.cert_usage == b->tlsa.cert_usage &&
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek a->tlsa.selector == b->tlsa.selector &&
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek a->tlsa.matching_type == b->tlsa.matching_type &&
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek FIELD_EQUAL(a->tlsa, b->tlsa, data);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering default:
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek return FIELD_EQUAL(a->generic, b->generic, data);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekstatic char* format_location(uint32_t latitude, uint32_t longitude, uint32_t altitude,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek uint8_t size, uint8_t horiz_pre, uint8_t vert_pre) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek char *s;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek char NS = latitude >= 1U<<31 ? 'N' : 'S';
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek char EW = longitude >= 1U<<31 ? 'E' : 'W';
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek int lat = latitude >= 1U<<31 ? (int) (latitude - (1U<<31)) : (int) ((1U<<31) - latitude);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek int lon = longitude >= 1U<<31 ? (int) (longitude - (1U<<31)) : (int) ((1U<<31) - longitude);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek double alt = altitude >= 10000000u ? altitude - 10000000u : -(double)(10000000u - altitude);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek double siz = (size >> 4) * exp10((double) (size & 0xF));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek double hor = (horiz_pre >> 4) * exp10((double) (horiz_pre & 0xF));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek double ver = (vert_pre >> 4) * exp10((double) (vert_pre & 0xF));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lat / 60000 / 60),
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lat / 60000) % 60,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lat % 60000) / 1000.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek NS,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lon / 60000 / 60),
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lon / 60000) % 60,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lon % 60000) / 1000.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek EW,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek alt / 100.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek siz / 100.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek hor / 100.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek ver / 100.) < 0)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return NULL;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return s;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek}
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersenstatic int format_timestamp_dns(char *buf, size_t l, time_t sec) {
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen struct tm tm;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen assert(buf);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen assert(l > strlen("YYYYMMDDHHmmSS"));
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (!gmtime_r(&sec, &tm))
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen return -EINVAL;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (strftime(buf, l, "%Y%m%d%H%M%S", &tm) <= 0)
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen return -EINVAL;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen return 0;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen}
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersenstatic char *format_types(Bitmap *types) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen _cleanup_strv_free_ char **strv = NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen _cleanup_free_ char *str = NULL;
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersen Iterator i;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen unsigned type;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen int r;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersen BITMAP_FOREACH(type, types, i) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (dns_type_to_string(type)) {
2c1fb4f71206bf970d493294208c5d7597194856Lennart Poettering r = strv_extend(&strv, dns_type_to_string(type));
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen } else {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen char *t;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen r = asprintf(&t, "TYPE%u", type);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
2c1fb4f71206bf970d493294208c5d7597194856Lennart Poettering r = strv_consume(&strv, t);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen }
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen }
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen str = strv_join(strv, " ");
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!str)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return strjoin("( ", str, " )", NULL);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen}
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringstatic char *format_txt(DnsTxtItem *first) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering DnsTxtItem *i;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering size_t c = 1;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering char *p, *s;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering LIST_FOREACH(items, i, first)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering c += i->length * 4 + 3;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering p = s = new(char, c);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!s)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return NULL;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering LIST_FOREACH(items, i, first) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering size_t j;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (i != first)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = ' ';
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = '"';
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering for (j = 0; j < i->length; j++) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (i->data[j] < ' ' || i->data[j] == '"' || i->data[j] >= 127) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = '\\';
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = '0' + (i->data[j] / 100);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = '0' + ((i->data[j] / 10) % 10);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = '0' + (i->data[j] % 10);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering } else
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = i->data[j];
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering }
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *(p++) = '"';
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering }
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering *p = 0;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return s;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering}
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poetteringconst char *dns_resource_record_to_string(DnsResourceRecord *rr) {
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek _cleanup_free_ char *k = NULL, *t = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering char *s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering int r;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(rr);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering if (rr->to_string)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return rr->to_string;
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = dns_resource_key_to_string(rr->key, &k);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SRV:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = asprintf(&s, "%s %u %u %u %s",
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering k,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering rr->srv.priority,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering rr->srv.weight,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering rr->srv.port,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering strna(rr->srv.name));
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_PTR:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_NS:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_CNAME:
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering case DNS_TYPE_DNAME:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering s = strjoin(k, " ", rr->ptr.name, NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!s)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_HINFO:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering s = strjoin(k, " ", rr->hinfo.cpu, " ", rr->hinfo.os, NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!s)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_SPF: /* exactly the same as TXT */
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_TXT:
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering t = format_txt(rr->txt.items);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek if (!s)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek break;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_A: {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering _cleanup_free_ char *x = NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = in_addr_to_string(AF_INET, (const union in_addr_union*) &rr->a.in_addr, &x);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering s = strjoin(k, " ", x, NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!s)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_AAAA:
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek r = in_addr_to_string(AF_INET6, (const union in_addr_union*) &rr->aaaa.in6_addr, &t);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!s)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_SOA:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = asprintf(&s, "%s %s %s %u %u %u %u %u",
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering k,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering strna(rr->soa.mname),
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering strna(rr->soa.rname),
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.serial,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.refresh,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.retry,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.expire,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.minimum);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek case DNS_TYPE_MX:
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u %s",
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek k,
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek rr->mx.priority,
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek rr->mx.exchange);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek break;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_LOC:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert(rr->loc.version == 0);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek t = format_location(rr->loc.latitude,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->loc.longitude,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->loc.altitude,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->loc.size,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->loc.horiz_pre,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->loc.vert_pre);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!s)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek break;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen case DNS_TYPE_DS:
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen t = hexmem(rr->ds.digest, rr->ds.digest_size);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen r = asprintf(&s, "%s %u %u %u %s",
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen k,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen rr->ds.key_tag,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen rr->ds.algorithm,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen rr->ds.digest_type,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen t);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen break;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_SSHFP:
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen t = hexmem(rr->sshfp.fingerprint, rr->sshfp.fingerprint_size);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering r = asprintf(&s, "%s %u %u %s",
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering k,
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering rr->sshfp.algorithm,
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering rr->sshfp.fptype,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek t);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering break;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek case DNS_TYPE_DNSKEY: {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering _cleanup_free_ char *alg = NULL;
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek char *ss;
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek int n, n1;
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek uint16_t key_tag;
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek key_tag = dnssec_keytag(rr, true);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering r = dnssec_algorithm_to_string_alloc(rr->dnskey.algorithm, &alg);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering if (r < 0)
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return NULL;
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %n%u %u %s %n",
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek k,
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek &n1,
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering rr->dnskey.flags,
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering rr->dnskey.protocol,
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering alg,
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek &n);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek r = base64_append(&s, n,
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek rr->dnskey.key, rr->dnskey.key_size,
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek 8, columns());
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek if (r < 0)
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek return NULL;
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek r = asprintf(&ss, "%s\n"
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek "%*s-- Flags:%s%s%s\n"
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek "%*s-- Key tag: %u",
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek s,
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek n1, "",
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek rr->dnskey.flags & DNSKEY_FLAG_SEP ? " SEP" : "",
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek rr->dnskey.flags & DNSKEY_FLAG_REVOKE ? " REVOKE" : "",
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek rr->dnskey.flags & DNSKEY_FLAG_ZONE_KEY ? " ZONE_KEY" : "",
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek n1, "",
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek key_tag);
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek if (r < 0)
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek return NULL;
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek free(s);
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek s = ss;
99e5ca6d8bf140444a15c0588fe797b27da5538cZbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek break;
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek case DNS_TYPE_RRSIG: {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering _cleanup_free_ char *alg = NULL;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen char expiration[strlen("YYYYMMDDHHmmSS") + 1], inception[strlen("YYYYMMDDHHmmSS") + 1];
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering const char *type;
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek int n;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek type = dns_type_to_string(rr->rrsig.type_covered);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering r = dnssec_algorithm_to_string_alloc(rr->rrsig.algorithm, &alg);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering if (r < 0)
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering return NULL;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen r = format_timestamp_dns(expiration, sizeof(expiration), rr->rrsig.expiration);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen r = format_timestamp_dns(inception, sizeof(inception), rr->rrsig.inception);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek /* TYPE?? follows
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek * http://tools.ietf.org/html/rfc3597#section-5 */
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %s%.*u %s %u %u %s %s %u %s %n",
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek k,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek type ?: "TYPE",
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek type ? 0 : 1, type ? 0u : (unsigned) rr->rrsig.type_covered,
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering alg,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek rr->rrsig.labels,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek rr->rrsig.original_ttl,
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen expiration,
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen inception,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek rr->rrsig.key_tag,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek rr->rrsig.signer,
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek &n);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek r = base64_append(&s, n,
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek rr->rrsig.signature, rr->rrsig.signature_size,
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek 8, columns());
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek if (r < 0)
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek return NULL;
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek break;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen case DNS_TYPE_NSEC:
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen t = format_types(rr->nsec.types);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen r = asprintf(&s, "%s %s %s",
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen k,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen rr->nsec.next_domain_name,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen t);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen break;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen case DNS_TYPE_NSEC3: {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen _cleanup_free_ char *salt = NULL, *hash = NULL;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
f5430a3ef308f3a102899fcaf7fbece757082f2aLennart Poettering if (rr->nsec3.salt_size > 0) {
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen salt = hexmem(rr->nsec3.salt, rr->nsec3.salt_size);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!salt)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen }
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen hash = base32hexmem(rr->nsec3.next_hashed_name, rr->nsec3.next_hashed_name_size, false);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!hash)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen t = format_types(rr->nsec3.types);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen r = asprintf(&s, "%s %"PRIu8" %"PRIu8" %"PRIu16" %s %s %s",
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen k,
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen rr->nsec3.algorithm,
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen rr->nsec3.flags,
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen rr->nsec3.iterations,
f5430a3ef308f3a102899fcaf7fbece757082f2aLennart Poettering rr->nsec3.salt_size > 0 ? salt : "-",
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen hash,
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen t);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen break;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen }
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek case DNS_TYPE_TLSA: {
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek const char *cert_usage, *selector, *matching_type;
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek char *ss;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek int n;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek cert_usage = tlsa_cert_usage_to_string(rr->tlsa.cert_usage);
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek selector = tlsa_selector_to_string(rr->tlsa.selector);
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek matching_type = tlsa_matching_type_to_string(rr->tlsa.matching_type);
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u %u %u %n",
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek k,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek rr->tlsa.cert_usage,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek rr->tlsa.selector,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek rr->tlsa.matching_type,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek &n);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek if (r < 0)
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek return NULL;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek r = base64_append(&s, n,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek rr->tlsa.data, rr->tlsa.data_size,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek 8, columns());
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek if (r < 0)
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek return NULL;
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek r = asprintf(&ss, "%s\n"
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek "%*s-- Cert. usage: %s\n"
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek "%*s-- Selector: %s\n"
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek "%*s-- Matching type: %s",
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek s,
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek n - 6, "", cert_usage,
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek n - 6, "", selector,
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek n - 6, "", matching_type);
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek if (r < 0)
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek return NULL;
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek free(s);
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek s = ss;
cfb90da3dc579e2f9408bc0e04a71c82dd28ac71Zbigniew Jędrzejewski-Szmek
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek break;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek }
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek case DNS_TYPE_OPENPGPKEY: {
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek int n;
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %n",
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek k,
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek &n);
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek if (r < 0)
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek return NULL;
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek r = base64_append(&s, n,
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek rr->generic.data, rr->generic.data_size,
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek 8, columns());
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek if (r < 0)
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek return NULL;
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek break;
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek }
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek default:
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek t = hexmem(rr->generic.data, rr->generic.data_size);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering /* Format as documented in RFC 3597, Section 5 */
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s \\# %zu %s", k, rr->generic.data_size, t);
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen if (r < 0)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering rr->to_string = s;
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poetteringint dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical) {
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering DnsPacket packet = {
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering .n_ref = 1,
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering .protocol = DNS_PROTOCOL_DNS,
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering .on_stack = true,
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering .refuse_compression = true,
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering .canonical_form = canonical,
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering };
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering size_t start, rds;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering int r;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering assert(rr);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering /* Generates the RR in wire-format, optionally in the
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * canonical form as discussed in the DNSSEC RFC 4034, Section
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * 6.2. We allocate a throw-away DnsPacket object on the stack
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * here, because we need some book-keeping for memory
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * management, and can reuse the DnsPacket serializer, that
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * can generate the canonical form, too, but also knows label
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * compression and suchlike. */
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering if (rr->wire_format && rr->wire_format_canonical == canonical)
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering return 0;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering r = dns_packet_append_rr(&packet, rr, &start, &rds);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering if (r < 0)
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering return r;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering assert(start == 0);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering assert(packet._data);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering free(rr->wire_format);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering rr->wire_format = packet._data;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering rr->wire_format_size = packet.size;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering rr->wire_format_rdata_offset = rds;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering rr->wire_format_canonical = canonical;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering packet._data = NULL;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering dns_packet_unref(&packet);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering return 0;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering}
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poetteringint dns_resource_record_signer(DnsResourceRecord *rr, const char **ret) {
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering const char *n;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering int r;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering assert(rr);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering assert(ret);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering /* Returns the RRset's signer, if it is known. */
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering if (rr->n_skip_labels_signer == (unsigned) -1)
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return -ENODATA;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering n = DNS_RESOURCE_KEY_NAME(rr->key);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering r = dns_name_skip(n, rr->n_skip_labels_signer, &n);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering if (r < 0)
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return r;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering if (r == 0)
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return -EINVAL;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering *ret = n;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return 0;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering}
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poetteringint dns_resource_record_source(DnsResourceRecord *rr, const char **ret) {
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering const char *n;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering int r;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering assert(rr);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering assert(ret);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering /* Returns the RRset's synthesizing source, if it is known. */
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering if (rr->n_skip_labels_source == (unsigned) -1)
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return -ENODATA;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering n = DNS_RESOURCE_KEY_NAME(rr->key);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering r = dns_name_skip(n, rr->n_skip_labels_source, &n);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering if (r < 0)
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return r;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering if (r == 0)
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return -EINVAL;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering *ret = n;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return 0;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering}
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poetteringint dns_resource_record_is_signer(DnsResourceRecord *rr, const char *zone) {
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering const char *signer;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering int r;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering assert(rr);
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering r = dns_resource_record_signer(rr, &signer);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering if (r < 0)
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return r;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering return dns_name_equal(zone, signer);
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering}
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poetteringint dns_resource_record_is_synthetic(DnsResourceRecord *rr) {
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering int r;
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering assert(rr);
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering /* Returns > 0 if the RR is generated from a wildcard, and is not the asterisk name itself */
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering if (rr->n_skip_labels_source == (unsigned) -1)
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering return -ENODATA;
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering if (rr->n_skip_labels_source == 0)
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering return 0;
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering if (rr->n_skip_labels_source > 1)
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering return 1;
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering r = dns_name_startswith(DNS_RESOURCE_KEY_NAME(rr->key), "*");
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering if (r < 0)
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering return r;
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering return !r;
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering}
ab481675f98d3d3f12e7e48ba6d2159123b9c7bfLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poetteringstatic void dns_resource_record_hash_func(const void *i, struct siphash *state) {
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering const DnsResourceRecord *rr = i;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering assert(rr);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_resource_key_hash_func(rr->key, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_SRV:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->srv.priority, sizeof(rr->srv.priority), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->srv.weight, sizeof(rr->srv.weight), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->srv.port, sizeof(rr->srv.port), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_name_hash_func(rr->srv.name, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_PTR:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_NS:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_CNAME:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_DNAME:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_name_hash_func(rr->ptr.name, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_HINFO:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering string_hash_func(rr->hinfo.cpu, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering string_hash_func(rr->hinfo.os, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_TXT:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_SPF: {
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering DnsTxtItem *j;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering LIST_FOREACH(items, j, rr->txt.items) {
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(j->data, j->length, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
d51155663a0a95659bd8a02a6cba51359ff416dbLennart Poettering /* Add an extra NUL byte, so that "a" followed by "b" doesn't result in the same hash as "ab"
d51155663a0a95659bd8a02a6cba51359ff416dbLennart Poettering * followed by "". */
d51155663a0a95659bd8a02a6cba51359ff416dbLennart Poettering siphash24_compress_byte(0, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering }
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering }
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_A:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->a.in_addr, sizeof(rr->a.in_addr), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_AAAA:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->aaaa.in6_addr, sizeof(rr->aaaa.in6_addr), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_SOA:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_name_hash_func(rr->soa.mname, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_name_hash_func(rr->soa.rname, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->soa.serial, sizeof(rr->soa.serial), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->soa.refresh, sizeof(rr->soa.refresh), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->soa.retry, sizeof(rr->soa.retry), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->soa.expire, sizeof(rr->soa.expire), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->soa.minimum, sizeof(rr->soa.minimum), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_MX:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->mx.priority, sizeof(rr->mx.priority), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_name_hash_func(rr->mx.exchange, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_LOC:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->loc.version, sizeof(rr->loc.version), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->loc.size, sizeof(rr->loc.size), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->loc.horiz_pre, sizeof(rr->loc.horiz_pre), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->loc.vert_pre, sizeof(rr->loc.vert_pre), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->loc.latitude, sizeof(rr->loc.latitude), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->loc.longitude, sizeof(rr->loc.longitude), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->loc.altitude, sizeof(rr->loc.altitude), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_SSHFP:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->sshfp.algorithm, sizeof(rr->sshfp.algorithm), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->sshfp.fptype, sizeof(rr->sshfp.fptype), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(rr->sshfp.fingerprint, rr->sshfp.fingerprint_size, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_DNSKEY:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->dnskey.flags, sizeof(rr->dnskey.flags), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->dnskey.protocol, sizeof(rr->dnskey.protocol), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->dnskey.algorithm, sizeof(rr->dnskey.algorithm), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(rr->dnskey.key, rr->dnskey.key_size, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_RRSIG:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->rrsig.type_covered, sizeof(rr->rrsig.type_covered), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->rrsig.algorithm, sizeof(rr->rrsig.algorithm), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->rrsig.labels, sizeof(rr->rrsig.labels), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->rrsig.original_ttl, sizeof(rr->rrsig.original_ttl), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->rrsig.expiration, sizeof(rr->rrsig.expiration), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->rrsig.inception, sizeof(rr->rrsig.inception), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->rrsig.key_tag, sizeof(rr->rrsig.key_tag), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_name_hash_func(rr->rrsig.signer, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(rr->rrsig.signature, rr->rrsig.signature_size, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_NSEC:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering dns_name_hash_func(rr->nsec.next_domain_name, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering /* FIXME: we leave out the type bitmap here. Hash
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering * would be better if we'd take it into account
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering * too. */
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_DS:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->ds.key_tag, sizeof(rr->ds.key_tag), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->ds.algorithm, sizeof(rr->ds.algorithm), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->ds.digest_type, sizeof(rr->ds.digest_type), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(rr->ds.digest, rr->ds.digest_size, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering case DNS_TYPE_NSEC3:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->nsec3.algorithm, sizeof(rr->nsec3.algorithm), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->nsec3.flags, sizeof(rr->nsec3.flags), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(&rr->nsec3.iterations, sizeof(rr->nsec3.iterations), state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(rr->nsec3.salt, rr->nsec3.salt_size, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering siphash24_compress(rr->nsec3.next_hashed_name, rr->nsec3.next_hashed_name_size, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering /* FIXME: We leave the bitmaps out */
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek case DNS_TYPE_TLSA:
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek siphash24_compress(&rr->tlsa.cert_usage, sizeof(rr->tlsa.cert_usage), state);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek siphash24_compress(&rr->tlsa.selector, sizeof(rr->tlsa.selector), state);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek siphash24_compress(&rr->tlsa.matching_type, sizeof(rr->tlsa.matching_type), state);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek siphash24_compress(&rr->tlsa.data, rr->tlsa.data_size, state);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek case DNS_TYPE_OPENPGPKEY:
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering default:
a43a068a30f7a47aba39f8b48d5db0c4d39fd21dZbigniew Jędrzejewski-Szmek siphash24_compress(rr->generic.data, rr->generic.data_size, state);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering break;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering }
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering}
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poetteringstatic int dns_resource_record_compare_func(const void *a, const void *b) {
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering const DnsResourceRecord *x = a, *y = b;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering int ret;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering ret = dns_resource_key_compare_func(x->key, y->key);
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering if (ret != 0)
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering return ret;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering if (dns_resource_record_equal(x, y))
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering return 0;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
1f133e0d538305edfce55198abadaa9a32ab23abTorstein Husebø /* This is a bit dirty, we don't implement proper ordering, but
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering * the hashtable doesn't need ordering anyway, hence we don't
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering * care. */
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering return x < y ? -1 : 1;
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering}
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poetteringconst struct hash_ops dns_resource_record_hash_ops = {
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering .hash = dns_resource_record_hash_func,
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering .compare = dns_resource_record_compare_func,
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering};
c9c72065419e6595131a6fe1e663e2184a843f7cLennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart PoetteringDnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering DnsTxtItem *n;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!i)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return NULL;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering n = i->items_next;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering free(i);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return dns_txt_item_free_all(n);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering}
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringbool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering if (a == b)
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering return true;
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!a != !b)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return false;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!a)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return true;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (a->length != b->length)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return false;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (memcmp(a->data, b->data, a->length) != 0)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return false;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return dns_txt_item_equal(a->items_next, b->items_next);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering}
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringstatic const char* const dnssec_algorithm_table[_DNSSEC_ALGORITHM_MAX_DEFINED] = {
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering /* Mnemonics as listed on https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_RSAMD5] = "RSAMD5",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_DH] = "DH",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_DSA] = "DSA",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_ECC] = "ECC",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_RSASHA1] = "RSASHA1",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_DSA_NSEC3_SHA1] = "DSA-NSEC3-SHA1",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1] = "RSASHA1-NSEC3-SHA1",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_RSASHA256] = "RSASHA256",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_RSASHA512] = "RSASHA512",
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering [DNSSEC_ALGORITHM_ECC_GOST] = "ECC-GOST",
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering [DNSSEC_ALGORITHM_ECDSAP256SHA256] = "ECDSAP256SHA256",
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering [DNSSEC_ALGORITHM_ECDSAP384SHA384] = "ECDSAP384SHA384",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_INDIRECT] = "INDIRECT",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_PRIVATEDNS] = "PRIVATEDNS",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering [DNSSEC_ALGORITHM_PRIVATEOID] = "PRIVATEOID",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering};
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart PoetteringDEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(dnssec_algorithm, int, 255);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringstatic const char* const dnssec_digest_table[_DNSSEC_DIGEST_MAX_DEFINED] = {
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering /* Names as listed on https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering [DNSSEC_DIGEST_SHA1] = "SHA-1",
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering [DNSSEC_DIGEST_SHA256] = "SHA-256",
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering [DNSSEC_DIGEST_GOST_R_34_11_94] = "GOST_R_34.11-94",
6f717d0817573a76c3e586eae02793d8b23a0581Lennart Poettering [DNSSEC_DIGEST_SHA384] = "SHA-384",
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering};
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart PoetteringDEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(dnssec_digest, int, 255);