resolved-dns-rr.c revision 4ad7f2761da661853dcc29d542efb4727abb1101
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 "strv.h"
4ad7f2761da661853dcc29d542efb4727abb1101Nick Owens
7263f72499e962b3fd54cdb7c79d49ca72121edeZbigniew Jędrzejewski-Szmek#include "dns-domain.h"
e4e73a632524c382139034d4271f53b6089ab4cbLennart Poettering#include "resolved-dns-rr.h"
fc8eec10f6a95a7ebb0f88954b49f2ed731c3a15Zbigniew Jędrzejewski-Szmek#include "resolved-dns-packet.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "dns-type.h"
e4e73a632524c382139034d4271f53b6089ab4cbLennart Poettering
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart PoetteringDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering DnsResourceKey *k;
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering size_t l;
d7671a3efdaef690b4316a03011038f731f2eea9Zbigniew Jędrzejewski-Szmek
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering l = strlen(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k = malloc0(sizeof(DnsResourceKey) + l + 1);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart 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_consume(uint16_t class, uint16_t type, char *name) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DnsResourceKey *k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen k = new0(DnsResourceKey, 1);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (!k)
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return NULL;
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen k->n_ref = 1;
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen k->class = class;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k->type = type;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k->_name = name;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return k;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering}
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart PoetteringDnsResourceKey* dns_resource_key_ref(DnsResourceKey *k) {
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (!k)
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering assert(k->n_ref > 0);
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering k->n_ref++;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return k;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering}
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart PoetteringDnsResourceKey* dns_resource_key_unref(DnsResourceKey *k) {
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering if (!k)
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return NULL;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering assert(k->n_ref > 0);
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen
36d9205d669bcdcb04fa730d1f3549a9fc9a9001Tom Gundersen 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) {
dc477e7385e8ab29efb8fadb72ec994077a105c6Lennart Poettering int r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (r <= 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return r;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (a->class != b->class)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (a->type != b->type)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 0;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return 1;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poetteringint dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(key);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering assert(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
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart 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));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poetteringstatic unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering const DnsResourceKey *k = i;
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering unsigned long ul;
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering ul = dns_name_hash_func(DNS_RESOURCE_KEY_NAME(k), hash_key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering ul = ul * hash_key[0] + ul + k->class;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering ul = ul * hash_key[1] + ul + k->type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return ul;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic int dns_resource_key_compare_func(const void *a, const void *b) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering const DnsResourceKey *x = a, *y = b;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering int ret;
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering ret = dns_name_compare_func(DNS_RESOURCE_KEY_NAME(x), DNS_RESOURCE_KEY_NAME(y));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (ret != 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return ret;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (x->type < y->type)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (x->type > y->type)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (x->class < y->class)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return -1;
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering if (x->class > y->class)
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering return 1;
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering return 0;
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering}
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poetteringconst struct hash_ops dns_resource_key_hash_ops = {
28b9b7640603f88cb49f95609331fa5072715f15Lennart Poettering .hash = dns_resource_key_hash_func,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering .compare = dns_resource_key_compare_func
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering};
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poetteringint dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering char cbuf[DECIMAL_STR_MAX(uint16_t)], tbuf[DECIMAL_STR_MAX(uint16_t)];
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering const char *c, *t;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering char *s;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering c = dns_class_to_string(key->class);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!c) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering sprintf(cbuf, "%i", key->class);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering c = cbuf;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering }
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering t = dns_type_to_string(key->type);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!t){
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering sprintf(tbuf, "%i", key->type);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering t = tbuf;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering }
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (asprintf(&s, "%s %s %-5s", DNS_RESOURCE_KEY_NAME(key), c, t) < 0)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return -ENOMEM;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering *ret = s;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering}
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering DnsResourceRecord *rr;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering rr = new0(DnsResourceRecord, 1);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!rr)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering rr->n_ref = 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering rr->key = dns_resource_key_ref(key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return rr;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart PoetteringDnsResourceRecord* 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
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering key = dns_resource_key_new(class, type, name);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!key)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return NULL;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return dns_resource_record_new(key);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering}
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart PoetteringDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (!rr)
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(rr->n_ref > 0);
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen rr->n_ref++;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering return rr;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (!rr)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen assert(rr->n_ref > 0);
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen if (rr->n_ref > 1) {
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen rr->n_ref--;
58db254ade4fb2ef77de68f28c4f13814819f6a1Lennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering }
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering if (rr->key) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering switch(rr->key->type) {
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering case DNS_TYPE_SRV:
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering free(rr->srv.name);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering break;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering case DNS_TYPE_PTR:
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering case DNS_TYPE_NS:
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering case DNS_TYPE_CNAME:
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen case DNS_TYPE_DNAME:
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen free(rr->ptr.name);
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen break;
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering case DNS_TYPE_HINFO:
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering free(rr->hinfo.cpu);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering free(rr->hinfo.os);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering break;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_TXT:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_SPF:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering strv_free(rr->txt.strings);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering break;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_SOA:
65b200e70d01cb7c513114b602c9b5cf41348f77Lennart Poettering free(rr->soa.mname);
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering free(rr->soa.rname);
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering break;
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering case DNS_TYPE_MX:
547973dea7abd6c124ff6c79fe2bbe322a7314aeLennart Poettering free(rr->mx.exchange);
0936416a1cba187dc76903dae73246f4cbddf312Lennart Poettering break;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_SSHFP:
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen free(rr->sshfp.key);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen case DNS_TYPE_DNSKEY:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->dnskey.key);
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen break;
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen case DNS_TYPE_RRSIG:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->rrsig.signer);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->rrsig.signature);
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_LOC:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_A:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_AAAA:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering default:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr->generic.data);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering dns_resource_key_unref(rr->key);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering }
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering free(rr);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringint dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt _cleanup_free_ char *ptr = NULL;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt int r;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt assert(ret);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(address);
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen assert(hostname);
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = dns_name_reverse(family, address, &ptr);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering return r;
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering key = dns_resource_key_new_consume(DNS_CLASS_IN, DNS_TYPE_PTR, ptr);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!key)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering ptr = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr = dns_resource_record_new(key);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!rr)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
d23a27a964748967e1ad20e86de869a753af555bTom Gundersen
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->ptr.name = strdup(hostname);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!rr->ptr.name)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering
f2af5ea3cbf54998ed41d2d21a3448abb92ca7ffLennart Poettering *ret = rr;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return 0;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering}
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b) {
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering int r;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(a);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering assert(b);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering r = dns_resource_key_equal(a->key, b->key);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (r <= 0)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return r;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (a->unparseable != b->unparseable)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return 0;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering switch (a->unparseable ? _DNS_TYPE_INVALID : a->key->type) {
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_SRV:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering r = dns_name_equal(a->srv.name, b->srv.name);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering if (r <= 0)
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return r;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return a->srv.priority == b->srv.priority &&
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering a->srv.weight == b->srv.weight &&
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering a->srv.port == b->srv.port;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_PTR:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_NS:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_CNAME:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_DNAME:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return dns_name_equal(a->ptr.name, b->ptr.name);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_HINFO:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return strcaseeq(a->hinfo.cpu, b->hinfo.cpu) &&
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering strcaseeq(a->hinfo.os, b->hinfo.os);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_SPF: /* exactly the same as TXT */
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_TXT:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return strv_equal(a->txt.strings, b->txt.strings);
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering case DNS_TYPE_A:
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering return memcmp(&a->a.in_addr, &b->a.in_addr, sizeof(struct in_addr)) == 0;
f57e3cd5fa709ec0f52531eccba909ac0851927cLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_AAAA:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return memcmp(&a->aaaa.in6_addr, &b->aaaa.in6_addr, sizeof(struct in6_addr)) == 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_SOA:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = dns_name_equal(a->soa.mname, b->soa.mname);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (r <= 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return r;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = dns_name_equal(a->soa.rname, b->soa.rname);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (r <= 0)
ee3d6aff9bd73c1b23e29d1fa1fa6f7a1ef0533bLennart Poettering return r;
97c67192eadaffe67b803ec5b991a92bb1137d0bLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return a->soa.serial == b->soa.serial &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->soa.refresh == b->soa.refresh &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->soa.retry == b->soa.retry &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->soa.expire == b->soa.expire &&
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering a->soa.minimum == b->soa.minimum;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering case DNS_TYPE_MX:
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering if (a->mx.priority != b->mx.priority)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return 0;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return dns_name_equal(a->mx.exchange, b->mx.exchange);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering case DNS_TYPE_LOC:
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering assert(a->loc.version == b->loc.version);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return a->loc.size == b->loc.size &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->loc.horiz_pre == b->loc.horiz_pre &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->loc.vert_pre == b->loc.vert_pre &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->loc.latitude == b->loc.latitude &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->loc.longitude == b->loc.longitude &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->loc.altitude == b->loc.altitude;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_SSHFP:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return a->sshfp.algorithm == b->sshfp.algorithm &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->sshfp.fptype == b->sshfp.fptype &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->sshfp.key_size == b->sshfp.key_size &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering memcmp(a->sshfp.key, b->sshfp.key, a->sshfp.key_size) == 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_DNSKEY:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return a->dnskey.zone_key_flag == b->dnskey.zone_key_flag &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->dnskey.sep_flag == b->dnskey.sep_flag &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->dnskey.algorithm == b->dnskey.algorithm &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering a->dnskey.key_size == b->dnskey.key_size &&
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering memcmp(a->dnskey.key, b->dnskey.key, a->dnskey.key_size) == 0;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_RRSIG:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek /* do the fast comparisons first */
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (a->rrsig.type_covered != b->rrsig.type_covered ||
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering a->rrsig.algorithm != b->rrsig.algorithm ||
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering a->rrsig.labels != b->rrsig.labels ||
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering a->rrsig.original_ttl != b->rrsig.original_ttl ||
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering a->rrsig.expiration != b->rrsig.expiration ||
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->rrsig.inception != b->rrsig.inception ||
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->rrsig.key_tag != b->rrsig.key_tag ||
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek a->rrsig.signature_size != b->rrsig.signature_size ||
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering memcmp(a->rrsig.signature, b->rrsig.signature, a->rrsig.signature_size) != 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return false;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return dns_name_equal(a->rrsig.signer, b->rrsig.signer);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering default:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return a->generic.size == b->generic.size &&
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek memcmp(a->generic.data, b->generic.data, a->generic.size) == 0;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering }
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek}
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringstatic char* format_location(uint32_t latitude, uint32_t longitude, uint32_t altitude,
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek uint8_t size, uint8_t horiz_pre, uint8_t vert_pre) {
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering char *s;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek char NS = latitude >= 1U<<31 ? 'N' : 'S';
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering char EW = longitude >= 1U<<31 ? 'E' : 'W';
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek int lat = latitude >= 1U<<31 ? (int) (latitude - (1U<<31)) : (int) ((1U<<31) - latitude);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering int lon = longitude >= 1U<<31 ? (int) (longitude - (1U<<31)) : (int) ((1U<<31) - longitude);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek double alt = altitude >= 10000000u ? altitude - 10000000u : -(double)(10000000u - altitude);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek double siz = (size >> 4) * exp10((double) (size & 0xF));
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek double hor = (horiz_pre >> 4) * exp10((double) (horiz_pre & 0xF));
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering double ver = (vert_pre >> 4) * exp10((double) (vert_pre & 0xF));
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen (lat / 60000 / 60),
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen (lat / 60000) % 60,
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering (lat % 60000) / 1000.,
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen NS,
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering (lon / 60000 / 60),
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering (lon / 60000) % 60,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek (lon % 60000) / 1000.,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek EW,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek alt / 100.,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek siz / 100.,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek hor / 100.,
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek ver / 100.) < 0)
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return NULL;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return s;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen}
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersenint dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen _cleanup_free_ char *k = NULL, *t = NULL;
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen char *s;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen int r;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen assert(rr);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen r = dns_resource_key_to_string(rr->key, &k);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (r < 0)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return r;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SRV:
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u %u %u %s",
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek k,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek rr->srv.priority,
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek rr->srv.weight,
d93a16b81f8baa0e6a16310b210f225129347322Zbigniew Jędrzejewski-Szmek rr->srv.port,
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek strna(rr->srv.name));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (r < 0)
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek return -ENOMEM;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_PTR:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_NS:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_CNAME:
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering case DNS_TYPE_DNAME:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering s = strjoin(k, " ", rr->ptr.name, NULL);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!s)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -ENOMEM;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering case DNS_TYPE_HINFO:
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering s = strjoin(k, " ", rr->hinfo.cpu, " ", rr->hinfo.os, NULL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!s)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering break;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering case DNS_TYPE_SPF: /* exactly the same as TXT */
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering case DNS_TYPE_TXT:
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering t = strv_join_quoted(rr->txt.strings);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!t)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering s = strjoin(k, " ", t, NULL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!s)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering break;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering case DNS_TYPE_A: {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering _cleanup_free_ char *x = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = in_addr_to_string(AF_INET, (const union in_addr_union*) &rr->a.in_addr, &x);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return r;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering s = strjoin(k, " ", x, NULL);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!s)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering break;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering }
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering case DNS_TYPE_AAAA:
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = in_addr_to_string(AF_INET6, (const union in_addr_union*) &rr->aaaa.in6_addr, &t);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (r < 0)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return r;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering s = strjoin(k, " ", t, NULL);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (!s)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering break;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering case DNS_TYPE_SOA:
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering r = asprintf(&s, "%s %s %s %u %u %u %u %u",
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering k,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering strna(rr->soa.mname),
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering strna(rr->soa.rname),
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->soa.serial,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->soa.refresh,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->soa.retry,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->soa.expire,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->soa.minimum);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (r < 0)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering break;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering case DNS_TYPE_MX:
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering r = asprintf(&s, "%s %u %s",
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering k,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->mx.priority,
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering rr->mx.exchange);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering if (r < 0)
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering return -ENOMEM;
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_LOC:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(rr->loc.version == 0);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering t = format_location(rr->loc.latitude,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->loc.longitude,
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering rr->loc.altitude,
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering rr->loc.size,
4d247a6cd3f69acbc5a09e8ac7e4fbb50eaa3228Lennart Poettering rr->loc.horiz_pre,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering rr->loc.vert_pre);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!t)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -ENOMEM;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering s = strjoin(k, " ", t, NULL);
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering if (!s)
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering return -ENOMEM;
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering break;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SSHFP:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering t = hexmem(rr->sshfp.key, rr->sshfp.key_size);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (!t)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return -ENOMEM;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = asprintf(&s, "%s %u %u %s",
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering k,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering rr->sshfp.algorithm,
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering rr->sshfp.fptype,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering t);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_DNSKEY: {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering const char *alg;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering alg = dnssec_algorithm_to_string(rr->dnskey.algorithm);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek t = hexmem(rr->dnskey.key, rr->dnskey.key_size);
0f84a72e3c0f58d71cff2121e6df1611eaf9c9eaDavid Herrmann if (!t)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering return -ENOMEM;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = asprintf(&s, "%s %u 3 %.*s%.*u %s",
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering k,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering dnskey_to_flags(rr),
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering alg ? -1 : 0, alg,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering alg ? 0 : 1, alg ? 0u : (unsigned) rr->dnskey.algorithm,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering t);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return -ENOMEM;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering break;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering }
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering case DNS_TYPE_RRSIG: {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering const char *type, *alg;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering type = dns_type_to_string(rr->rrsig.type_covered);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering alg = dnssec_algorithm_to_string(rr->rrsig.algorithm);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering t = hexmem(rr->rrsig.signature, rr->rrsig.signature_size);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (!t)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return -ENOMEM;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek /* TYPE?? follows
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek * http://tools.ietf.org/html/rfc3597#section-5 */
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %s%.*u %.*s%.*u %u %u %u %u %u %s %s",
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek k,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek type ?: "TYPE",
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek type ? 0 : 1, type ? 0u : (unsigned) rr->rrsig.type_covered,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek alg ? -1 : 0, alg,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek alg ? 0 : 1, alg ? 0u : (unsigned) rr->rrsig.algorithm,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->rrsig.labels,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->rrsig.original_ttl,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->rrsig.expiration,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->rrsig.inception,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->rrsig.key_tag,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->rrsig.signer,
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen t);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen if (r < 0)
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen return -ENOMEM;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen break;
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen }
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen default:
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering t = hexmem(rr->generic.data, rr->generic.size);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (!t)
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering return -ENOMEM;
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen s = strjoin(k, " ", t, NULL);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (!s)
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return -ENOMEM;
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering break;
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering }
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek *ret = s;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return 0;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek}
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmekconst char *dns_class_to_string(uint16_t class) {
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn switch (class) {
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn case DNS_CLASS_IN:
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn return "IN";
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn case DNS_CLASS_ANY:
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return "ANY";
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return NULL;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek}
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersenint dns_class_from_string(const char *s, uint16_t *class) {
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen assert(s);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen assert(class);
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen if (strcaseeq(s, "IN"))
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen *class = DNS_CLASS_IN;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen else if (strcaseeq(s, "ANY"))
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen *class = DNS_TYPE_ANY;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen else
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen return -EINVAL;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen return 0;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen}
48d45d2b49d2adb870cd5f1bc7cb389b33655f1cZbigniew Jędrzejewski-Szmek