resolved-dns-rr.c revision b5efdb8af40ea759a1ea584c1bc44ecc81dd00ce
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
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"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "resolved-dns-packet.h"
e4e73a632524c382139034d4271f53b6089ab4cbLennart Poettering#include "resolved-dns-rr.h"
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering#include "string-util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "strv.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-SzmekDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DnsResourceKey *k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering size_t l;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart 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
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_new_cname(const DnsResourceKey *key) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(key);
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return dns_resource_key_new(key->class, DNS_TYPE_CNAME, DNS_RESOURCE_KEY_NAME(key));
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering}
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom GundersenDnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname) {
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen assert(key);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering assert(cname);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return dns_resource_key_new(key->class, key->type, cname->cname.name);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering}
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart PoetteringDnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name) {
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering DnsResourceKey *k;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering assert(name);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k = new0(DnsResourceKey, 1);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (!k)
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k->n_ref = 1;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k->class = class;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k->type = type;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k->_name = name;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return k;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering}
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom GundersenDnsResourceKey* dns_resource_key_ref(DnsResourceKey *k) {
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!k)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(k->n_ref > 0);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering k->n_ref++;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return k;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
dc477e7385e8ab29efb8fadb72ec994077a105c6Lennart PoetteringDnsResourceKey* dns_resource_key_unref(DnsResourceKey *k) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!k)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(k->n_ref > 0);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (k->n_ref == 1) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering free(k->_name);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering free(k);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering } else
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering k->n_ref--;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poetteringint dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering int r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart 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
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(rr);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart 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
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering}
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poetteringint dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(rr);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart 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 != DNS_TYPE_CNAME)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic void dns_resource_key_hash_func(const void *i, struct siphash *state) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering const DnsResourceKey *k = i;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(k);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering dns_name_hash_func(DNS_RESOURCE_KEY_NAME(k), state);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering siphash24_compress(&k->class, sizeof(k->class), state);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering siphash24_compress(&k->type, sizeof(k->type), state);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poetteringstatic int dns_resource_key_compare_func(const void *a, const void *b) {
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering const DnsResourceKey *x = a, *y = b;
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering int ret;
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering ret = dns_name_compare_func(DNS_RESOURCE_KEY_NAME(x), DNS_RESOURCE_KEY_NAME(y));
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering if (ret != 0)
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering return ret;
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (x->type < y->type)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (x->type > y->type)
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering return 1;
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering if (x->class < y->class)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (x->class > y->class)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringconst struct hash_ops dns_resource_key_hash_ops = {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering .hash = dns_resource_key_hash_func,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering .compare = dns_resource_key_compare_func
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering};
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering char cbuf[strlen("CLASS") + DECIMAL_STR_MAX(uint16_t)], tbuf[strlen("TYPE") + DECIMAL_STR_MAX(uint16_t)];
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering const char *c, *t;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering char *s;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering c = dns_class_to_string(key->class);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!c) {
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering sprintf(cbuf, "CLASS%u", key->class);
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering c = cbuf;
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering }
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering t = dns_type_to_string(key->type);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!t){
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering sprintf(tbuf, "TYPE%u", key->type);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering t = tbuf;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering }
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (asprintf(&s, "%s %s %-5s", DNS_RESOURCE_KEY_NAME(key), c, t) < 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -ENOMEM;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering *ret = s;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering DnsResourceRecord *rr;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering rr = new0(DnsResourceRecord, 1);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!rr)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering rr->n_ref = 1;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering rr->key = dns_resource_key_ref(key);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return rr;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
5d27351f8546530cf779847b0b04b0172c09f9d0Tom GundersenDnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering key = dns_resource_key_new(class, type, name);
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (!key)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return dns_resource_record_new(key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen
5d27351f8546530cf779847b0b04b0172c09f9d0Tom GundersenDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (!rr)
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen return NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(rr->n_ref > 0);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering rr->n_ref++;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return rr;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!rr)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(rr->n_ref > 0);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (rr->n_ref > 1) {
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen rr->n_ref--;
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen return NULL;
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen }
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (rr->key) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering switch(rr->key->type) {
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_SRV:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering free(rr->srv.name);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering break;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_PTR:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_NS:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_CNAME:
65b200e70d01cb7c513114b602c9b5cf41348f77Lennart Poettering case DNS_TYPE_DNAME:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering free(rr->ptr.name);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering break;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_HINFO:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering free(rr->hinfo.cpu);
0936416a1cba187dc76903dae73246f4cbddf312Lennart Poettering free(rr->hinfo.os);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering break;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen case DNS_TYPE_TXT:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_SPF:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering strv_free(rr->txt.strings);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen case DNS_TYPE_SOA:
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen free(rr->soa.mname);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen free(rr->soa.rname);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt case DNS_TYPE_MX:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->mx.exchange);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_DS:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->ds.digest);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_SSHFP:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->sshfp.fingerprint);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_DNSKEY:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->dnskey.key);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_RRSIG:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->rrsig.signer);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->rrsig.signature);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt case DNS_TYPE_NSEC:
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt free(rr->nsec.next_domain_name);
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt bitmap_free(rr->nsec.types);
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt break;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_NSEC3:
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen free(rr->nsec3.next_hashed_name);
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering free(rr->nsec3.salt);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering bitmap_free(rr->nsec3.types);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering case DNS_TYPE_LOC:
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering case DNS_TYPE_A:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_AAAA:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering default:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering free(rr->generic.data);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dns_resource_key_unref(rr->key);
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering free(rr);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering return NULL;
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering}
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering _cleanup_free_ char *ptr = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering int r;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(ret);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(address);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(hostname);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering r = dns_name_reverse(family, address, &ptr);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (r < 0)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return r;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering key = dns_resource_key_new_consume(DNS_CLASS_IN, DNS_TYPE_PTR, ptr);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (!key)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return -ENOMEM;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering ptr = NULL;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering rr = dns_resource_record_new(key);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (!rr)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return -ENOMEM;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering rr->ptr.name = strdup(hostname);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (!rr->ptr.name)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return -ENOMEM;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering *ret = rr;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering rr = NULL;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return 0;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering}
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poetteringint dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name) {
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering DnsResourceRecord *rr;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(ret);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(address);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(family);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (family == AF_INET) {
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, name);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (!rr)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->a.in_addr = address->in;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (family == AF_INET6) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_AAAA, name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!rr)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -ENOMEM;
ee3d6aff9bd73c1b23e29d1fa1fa6f7a1ef0533bLennart Poettering
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering rr->aaaa.in6_addr = address->in6;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering } else
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return -EAFNOSUPPORT;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering *ret = rr;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return 0;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering}
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poetteringint dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b) {
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering int r;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering assert(a);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering assert(b);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = dns_resource_key_equal(a->key, b->key);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (r <= 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (a->unparseable != b->unparseable)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering switch (a->unparseable ? _DNS_TYPE_INVALID : a->key->type) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_SRV:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = dns_name_equal(a->srv.name, b->srv.name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (r <= 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return a->srv.priority == b->srv.priority &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->srv.weight == b->srv.weight &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->srv.port == b->srv.port;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_PTR:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_NS:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_CNAME:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_DNAME:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek return dns_name_equal(a->ptr.name, b->ptr.name);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_HINFO:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return strcaseeq(a->hinfo.cpu, b->hinfo.cpu) &&
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering strcaseeq(a->hinfo.os, b->hinfo.os);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_SPF: /* exactly the same as TXT */
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_TXT:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek return strv_equal(a->txt.strings, b->txt.strings);
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_A:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek return memcmp(&a->a.in_addr, &b->a.in_addr, sizeof(struct in_addr)) == 0;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_AAAA:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return memcmp(&a->aaaa.in6_addr, &b->aaaa.in6_addr, sizeof(struct in6_addr)) == 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_SOA:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = dns_name_equal(a->soa.mname, b->soa.mname);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek if (r <= 0)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return r;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering r = dns_name_equal(a->soa.rname, b->soa.rname);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek if (r <= 0)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return r;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return a->soa.serial == b->soa.serial &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.refresh == b->soa.refresh &&
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->soa.retry == b->soa.retry &&
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering a->soa.expire == b->soa.expire &&
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->soa.minimum == b->soa.minimum;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_MX:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (a->mx.priority != b->mx.priority)
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return 0;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return dns_name_equal(a->mx.exchange, b->mx.exchange);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering case DNS_TYPE_LOC:
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen assert(a->loc.version == b->loc.version);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering return a->loc.size == b->loc.size &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek a->loc.horiz_pre == b->loc.horiz_pre &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek a->loc.vert_pre == b->loc.vert_pre &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek a->loc.latitude == b->loc.latitude &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek a->loc.longitude == b->loc.longitude &&
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek a->loc.altitude == b->loc.altitude;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek case DNS_TYPE_DS:
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return a->ds.key_tag == b->ds.key_tag &&
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek a->ds.algorithm == b->ds.algorithm &&
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen a->ds.digest_type == b->ds.digest_type &&
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen a->ds.digest_size == b->ds.digest_size &&
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen memcmp(a->ds.digest, b->ds.digest, a->ds.digest_size) == 0;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen case DNS_TYPE_SSHFP:
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen return a->sshfp.algorithm == b->sshfp.algorithm &&
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen a->sshfp.fptype == b->sshfp.fptype &&
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen a->sshfp.fingerprint_size == b->sshfp.fingerprint_size &&
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen memcmp(a->sshfp.fingerprint, b->sshfp.fingerprint, a->sshfp.fingerprint_size) == 0;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen case DNS_TYPE_DNSKEY:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return a->dnskey.zone_key_flag == b->dnskey.zone_key_flag &&
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->dnskey.sep_flag == b->dnskey.sep_flag &&
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->dnskey.algorithm == b->dnskey.algorithm &&
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->dnskey.key_size == b->dnskey.key_size &&
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering memcmp(a->dnskey.key, b->dnskey.key, a->dnskey.key_size) == 0;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek case DNS_TYPE_RRSIG:
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek /* do the fast comparisons first */
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek if (a->rrsig.type_covered != b->rrsig.type_covered ||
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek a->rrsig.algorithm != b->rrsig.algorithm ||
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->rrsig.labels != b->rrsig.labels ||
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering a->rrsig.original_ttl != b->rrsig.original_ttl ||
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->rrsig.expiration != b->rrsig.expiration ||
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering a->rrsig.inception != b->rrsig.inception ||
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering a->rrsig.key_tag != b->rrsig.key_tag ||
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering a->rrsig.signature_size != b->rrsig.signature_size ||
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering memcmp(a->rrsig.signature, b->rrsig.signature, a->rrsig.signature_size) != 0)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return false;
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return dns_name_equal(a->rrsig.signer, b->rrsig.signer);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_NSEC:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return dns_name_equal(a->nsec.next_domain_name, b->nsec.next_domain_name) &&
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering bitmap_equal(a->nsec.types, b->nsec.types);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering case DNS_TYPE_NSEC3:
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return a->nsec3.algorithm == b->nsec3.algorithm &&
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering a->nsec3.flags == b->nsec3.flags &&
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering a->nsec3.iterations == b->nsec3.iterations &&
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering a->nsec3.salt_size == b->nsec3.salt_size &&
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering memcmp(a->nsec3.salt, b->nsec3.salt, a->nsec3.salt_size) == 0 &&
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering memcmp(a->nsec3.next_hashed_name, b->nsec3.next_hashed_name, a->nsec3.next_hashed_name_size) == 0 &&
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering bitmap_equal(a->nsec3.types, b->nsec3.types);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering default:
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return a->generic.size == b->generic.size &&
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering memcmp(a->generic.data, b->generic.data, a->generic.size) == 0;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering}
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringstatic char* format_location(uint32_t latitude, uint32_t longitude, uint32_t altitude,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering uint8_t size, uint8_t horiz_pre, uint8_t vert_pre) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering char *s;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering char NS = latitude >= 1U<<31 ? 'N' : 'S';
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering char EW = longitude >= 1U<<31 ? 'E' : 'W';
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering int lat = latitude >= 1U<<31 ? (int) (latitude - (1U<<31)) : (int) ((1U<<31) - latitude);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering int lon = longitude >= 1U<<31 ? (int) (longitude - (1U<<31)) : (int) ((1U<<31) - longitude);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering double alt = altitude >= 10000000u ? altitude - 10000000u : -(double)(10000000u - altitude);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering double siz = (size >> 4) * exp10((double) (size & 0xF));
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering double hor = (horiz_pre >> 4) * exp10((double) (horiz_pre & 0xF));
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering double ver = (vert_pre >> 4) * exp10((double) (vert_pre & 0xF));
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering (lat / 60000 / 60),
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering (lat / 60000) % 60,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering (lat % 60000) / 1000.,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering NS,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering (lon / 60000 / 60),
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering (lon / 60000) % 60,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering (lon % 60000) / 1000.,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering EW,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering alt / 100.,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering siz / 100.,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering hor / 100.,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering ver / 100.) < 0)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return NULL;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return s;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering}
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poetteringstatic int format_timestamp_dns(char *buf, size_t l, time_t sec) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering struct tm tm;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering assert(buf);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering assert(l > strlen("YYYYMMDDHHmmSS"));
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!gmtime_r(&sec, &tm))
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -EINVAL;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (strftime(buf, l, "%Y%m%d%H%M%S", &tm) <= 0)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -EINVAL;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return 0;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering}
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poetteringstatic char *format_types(Bitmap *types) {
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering _cleanup_strv_free_ char **strv = NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering _cleanup_free_ char *str = NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering Iterator i;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering unsigned type;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering int r;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering BITMAP_FOREACH(type, types, i) {
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering if (dns_type_to_string(type)) {
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering r = strv_extend(&strv, dns_type_to_string(type));
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering if (r < 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering } else {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering char *t;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering r = asprintf(&t, "TYPE%u", type);
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering if (r < 0)
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering return NULL;
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = strv_consume(&strv, t);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (r < 0)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return NULL;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering }
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering }
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering str = strv_join(strv, " ");
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (!str)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return NULL;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return strjoin("( ", str, " )", NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering}
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poetteringint dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering _cleanup_free_ char *k = NULL, *t = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering char *s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering int r;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(rr);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek r = dns_resource_key_to_string(rr->key, &k);
0f84a72e3c0f58d71cff2121e6df1611eaf9c9eaDavid Herrmann if (r < 0)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return r;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_SRV:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = asprintf(&s, "%s %u %u %u %s",
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering k,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->srv.priority,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->srv.weight,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering rr->srv.port,
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering strna(rr->srv.name));
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (r < 0)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return -ENOMEM;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering break;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering case DNS_TYPE_PTR:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering case DNS_TYPE_NS:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering case DNS_TYPE_CNAME:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering case DNS_TYPE_DNAME:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering s = strjoin(k, " ", rr->ptr.name, NULL);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (!s)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return -ENOMEM;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek break;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek case DNS_TYPE_HINFO:
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", rr->hinfo.cpu, " ", rr->hinfo.os, NULL);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek if (!s)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek break;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_SPF: /* exactly the same as TXT */
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_TXT:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek t = strv_join_quoted(rr->txt.strings);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!t)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (!s)
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return -ENOMEM;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen break;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen case DNS_TYPE_A: {
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen _cleanup_free_ char *x = NULL;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering r = in_addr_to_string(AF_INET, (const union in_addr_union*) &rr->a.in_addr, &x);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (r < 0)
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen return r;
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering s = strjoin(k, " ", x, NULL);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!s)
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering return -ENOMEM;
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering break;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek }
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
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);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (r < 0)
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return r;
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn s = strjoin(k, " ", t, NULL);
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn if (!s)
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn return -ENOMEM;
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn break;
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn case DNS_TYPE_SOA:
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %s %s %u %u %u %u %u",
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek k,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek strna(rr->soa.mname),
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek strna(rr->soa.rname),
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek rr->soa.serial,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek rr->soa.refresh,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen rr->soa.retry,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen rr->soa.expire,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen rr->soa.minimum);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen return -ENOMEM;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen break;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen case DNS_TYPE_MX:
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen r = asprintf(&s, "%s %u %s",
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen k,
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen rr->mx.priority,
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen rr->mx.exchange);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (r < 0)
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek return -ENOMEM;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek break;
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek case DNS_TYPE_LOC:
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek assert(rr->loc.version == 0);
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek t = format_location(rr->loc.latitude,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->loc.longitude,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->loc.altitude,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->loc.size,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->loc.horiz_pre,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->loc.vert_pre);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!t)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!s)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek break;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_DS:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek t = hexmem(rr->ds.digest, rr->ds.digest_size);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!t)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u %u %u %s",
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek k,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->ds.key_tag,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->ds.algorithm,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->ds.digest_type,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek t);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (r < 0)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek break;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_SSHFP:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek t = hexmem(rr->sshfp.fingerprint, rr->sshfp.fingerprint_size);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!t)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u %u %s",
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek k,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->sshfp.algorithm,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->sshfp.fptype,
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen t);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (r < 0)
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen return -ENOMEM;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen break;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen case DNS_TYPE_DNSKEY: {
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen const char *alg;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen alg = dnssec_algorithm_to_string(rr->dnskey.algorithm);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen t = base64mem(rr->dnskey.key, rr->dnskey.key_size);
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen if (!t)
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen return -ENOMEM;
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen
7c6423e19136a7b7b6ef3fe06b94822e582dda27Tom Gundersen r = asprintf(&s, "%s %u 3 %.*s%.*u %s",
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen k,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen dnskey_to_flags(rr),
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen alg ? -1 : 0, alg,
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersen alg ? 0 : 1, alg ? 0u : (unsigned) rr->dnskey.algorithm,
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen t);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return -ENOMEM;
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersen break;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen }
2c1fb4f71206bf970d493294208c5d7597194856Lennart Poettering
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen case DNS_TYPE_RRSIG: {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen const char *type, *alg;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen char expiration[strlen("YYYYMMDDHHmmSS") + 1], inception[strlen("YYYYMMDDHHmmSS") + 1];
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen type = dns_type_to_string(rr->rrsig.type_covered);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen alg = dnssec_algorithm_to_string(rr->rrsig.algorithm);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen t = base64mem(rr->rrsig.signature, rr->rrsig.signature_size);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (!t)
2c1fb4f71206bf970d493294208c5d7597194856Lennart Poettering return -ENOMEM;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen r = format_timestamp_dns(expiration, sizeof(expiration), rr->rrsig.expiration);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return r;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen r = format_timestamp_dns(inception, sizeof(inception), rr->rrsig.inception);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen if (r < 0)
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen return r;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen /* TYPE?? follows
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen * http://tools.ietf.org/html/rfc3597#section-5 */
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering r = asprintf(&s, "%s %s%.*u %.*s%.*u %u %u %s %s %u %s %s",
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering k,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering type ?: "TYPE",
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering type ? 0 : 1, type ? 0u : (unsigned) rr->rrsig.type_covered,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering alg ? -1 : 0, alg,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering alg ? 0 : 1, alg ? 0u : (unsigned) rr->rrsig.algorithm,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering rr->rrsig.labels,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering rr->rrsig.original_ttl,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering expiration,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering inception,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering rr->rrsig.key_tag,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering rr->rrsig.signer,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering t);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (r < 0)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return -ENOMEM;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering break;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering }
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering case DNS_TYPE_NSEC:
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering t = format_types(rr->nsec.types);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!t)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return -ENOMEM;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering r = asprintf(&s, "%s %s %s",
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering k,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering rr->nsec.next_domain_name,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering t);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (r < 0)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return -ENOMEM;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering break;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering case DNS_TYPE_NSEC3: {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering _cleanup_free_ char *salt = NULL, *hash = NULL;
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (rr->nsec3.salt_size > 0) {
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering salt = hexmem(rr->nsec3.salt, rr->nsec3.salt_size);
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering if (!salt)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return -ENOMEM;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering hash = base32hexmem(rr->nsec3.next_hashed_name, rr->nsec3.next_hashed_name_size, false);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!hash)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering t = format_types(rr->nsec3.types);
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering if (!t)
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = asprintf(&s, "%s %"PRIu8" %"PRIu8" %"PRIu16" %s %s %s",
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering k,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->nsec3.algorithm,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->nsec3.flags,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->nsec3.iterations,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering rr->nsec3.salt_size > 0 ? salt : "-",
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering hash,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering t);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (r < 0)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return -ENOMEM;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering }
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering default:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering t = hexmem(rr->generic.data, rr->generic.size);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!t)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering r = asprintf(&s, "%s \\# %zu %s", k, rr->generic.size, t);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering *ret = s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return 0;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering}
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poetteringconst char *dns_class_to_string(uint16_t class) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering switch (class) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_CLASS_IN:
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return "IN";
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering case DNS_CLASS_ANY:
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek return "ANY";
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek }
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return NULL;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek}
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_class_from_string(const char *s, uint16_t *class) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(s);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(class);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (strcaseeq(s, "IN"))
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering *class = DNS_CLASS_IN;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering else if (strcaseeq(s, "ANY"))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering *class = DNS_CLASS_ANY;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering else
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering return -EINVAL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return 0;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek