resolved-dns-rr.c revision 8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939
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
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek#include "strv.h"
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering#include "resolved-dns-domain.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "resolved-dns-rr.h"
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek#include "resolved-dns-packet.h"
7263f72499e962b3fd54cdb7c79d49ca72121edeZbigniew Jędrzejewski-Szmek#include "dns-type.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DnsResourceKey *k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering size_t l;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering l = strlen(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k = malloc0(sizeof(DnsResourceKey) + l + 1);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref = 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->class = class;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->type = type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering strcpy((char*) k + sizeof(DnsResourceKey), name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DnsResourceKey *k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k = new0(DnsResourceKey, 1);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref = 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->class = class;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->type = type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->_name = name;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_ref(DnsResourceKey *k) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(k->n_ref > 0);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref++;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return k;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_unref(DnsResourceKey *k) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (!k)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering assert(k->n_ref > 0);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (k->n_ref == 1) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(k->_name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(k);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering } else
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k->n_ref--;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering int r;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (r <= 0)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return r;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (a->class != b->class)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (a->type != b->type)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 0;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return 1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
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
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));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtunsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering const DnsResourceKey *k = i;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering unsigned long ul;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering ul = dns_name_hash_func(DNS_RESOURCE_KEY_NAME(k), hash_key);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering ul = ul * hash_key[0] + ul + k->class;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering ul = ul * hash_key[1] + ul + k->type;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return ul;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtint dns_resource_key_compare_func(const void *a, const void *b) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering const DnsResourceKey *x = a, *y = b;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering int ret;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering ret = dns_name_compare_func(DNS_RESOURCE_KEY_NAME(x), DNS_RESOURCE_KEY_NAME(y));
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (ret != 0)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return ret;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->type < y->type)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->type > y->type)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return 1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->class < y->class)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return -1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (x->class > y->class)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return 1;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return 0;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering}
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtint dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt char cbuf[DECIMAL_STR_MAX(uint16_t)], tbuf[DECIMAL_STR_MAX(uint16_t)];
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt const char *c, *t;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt char *s;
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering c = dns_class_to_string(key->class);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!c) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering sprintf(cbuf, "%i", key->class);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering c = cbuf;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering t = dns_type_to_string(key->type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!t){
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering sprintf(tbuf, "%i", key->type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering t = tbuf;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (asprintf(&s, "%s %s %-5s", DNS_RESOURCE_KEY_NAME(key), c, t) < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering *ret = s;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return 0;
23432a1c249b9c513e438bffe9778a7ce2ee74feZbigniew Jędrzejewski-Szmek}
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering DnsResourceRecord *rr;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr = new0(DnsResourceRecord, 1);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!rr)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->n_ref = 1;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->key = dns_resource_key_ref(key);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return rr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering key = dns_resource_key_new(class, type, name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!key)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return NULL;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return dns_resource_record_new(key);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering}
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart PoetteringDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering if (!rr)
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering return NULL;
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart Poettering assert(rr->n_ref > 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->n_ref++;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return rr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!rr)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(rr->n_ref > 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (rr->n_ref > 1) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering rr->n_ref--;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (rr->key) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering switch(rr->key->type) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering case DNS_TYPE_SRV:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering free(rr->srv.name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering break;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_PTR:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_NS:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_CNAME:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_DNAME:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering free(rr->ptr.name);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_HINFO:
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering free(rr->hinfo.cpu);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering free(rr->hinfo.os);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_TXT:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering case DNS_TYPE_SPF:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering strv_free(rr->txt.strings);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_SOA:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering free(rr->soa.mname);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek free(rr->soa.rname);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_MX:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering free(rr->mx.exchange);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering break;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SSHFP:
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek free(rr->sshfp.key);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek break;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_DNSKEY:
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering free(rr->dnskey.key);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering break;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering case DNS_TYPE_LOC:
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_A:
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_AAAA:
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek break;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek default:
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek free(rr->generic.data);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek dns_resource_key_unref(rr->key);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek }
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek free(rr);
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return NULL;
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek}
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmekint 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;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering _cleanup_free_ char *ptr = NULL;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering int r;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(ret);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(address);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering assert(hostname);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = dns_name_reverse(family, address, &ptr);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r < 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return r;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering key = dns_resource_key_new_consume(DNS_CLASS_IN, DNS_TYPE_PTR, ptr);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!key)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering ptr = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering rr = dns_resource_record_new(key);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!rr)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering rr->ptr.name = strdup(hostname);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (!rr->ptr.name)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return -ENOMEM;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering *ret = rr;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering rr = NULL;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return 0;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering}
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b) {
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering int r;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert(a);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering assert(b);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering r = dns_resource_key_equal(a->key, b->key);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering if (r <= 0)
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering return r;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (a->unparseable != b->unparseable)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return 0;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering switch (a->unparseable ? _DNS_TYPE_INVALID : a->key->type) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_SRV:
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering r = dns_name_equal(a->srv.name, b->srv.name);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (r <= 0)
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering return r;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering return a->srv.priority == b->srv.priority &&
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering a->srv.weight == b->srv.weight &&
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering a->srv.port == b->srv.port;
fd0b4602f6332c3f1660eb208c8f5c719709a009Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_PTR:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_NS:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_CNAME:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_DNAME:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering 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
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_SPF: /* exactly the same as TXT */
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_TXT: {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering int i;
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering for (i = 0; a->txt.strings[i] || b->txt.strings[i]; i++)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!streq_ptr(a->txt.strings[i], b->txt.strings[i]))
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return false;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return true;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek case DNS_TYPE_A:
0f84a72e3c0f58d71cff2121e6df1611eaf9c9eaDavid Herrmann return memcmp(&a->a.in_addr, &b->a.in_addr, sizeof(struct in_addr)) == 0;
0f84a72e3c0f58d71cff2121e6df1611eaf9c9eaDavid Herrmann
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek case DNS_TYPE_AAAA:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return memcmp(&a->aaaa.in6_addr, &b->aaaa.in6_addr, sizeof(struct in6_addr)) == 0;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_SOA:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = dns_name_equal(a->soa.mname, b->soa.mname);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (r <= 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return r;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = dns_name_equal(a->soa.rname, b->soa.rname);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (r <= 0)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return r;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return a->soa.serial == b->soa.serial &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.refresh == b->soa.refresh &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.retry == b->soa.retry &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.expire == b->soa.expire &&
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering a->soa.minimum == b->soa.minimum;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering case DNS_TYPE_MX:
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering if (a->mx.priority != b->mx.priority)
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering return 0;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return dns_name_equal(a->mx.exchange, b->mx.exchange);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek case DNS_TYPE_LOC:
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek assert(a->loc.version == b->loc.version);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return a->loc.size == b->loc.size &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.horiz_pre == b->loc.horiz_pre &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.vert_pre == b->loc.vert_pre &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.latitude == b->loc.latitude &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.longitude == b->loc.longitude &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->loc.altitude == b->loc.altitude;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_SSHFP:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return a->sshfp.algorithm == b->sshfp.algorithm &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->sshfp.fptype == b->sshfp.fptype &&
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek a->sshfp.key_size == b->sshfp.key_size &&
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering memcmp(a->sshfp.key, b->sshfp.key, a->sshfp.key_size) == 0;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering case DNS_TYPE_DNSKEY:
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering return a->dnskey.zone_key_flag == b->dnskey.zone_key_flag &&
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering a->dnskey.sep_flag == b->dnskey.sep_flag &&
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering a->dnskey.algorithm == b->dnskey.algorithm &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek a->dnskey.key_size == b->dnskey.key_size &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek memcmp(a->dnskey.key, b->dnskey.key, a->dnskey.key_size) == 0;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek default:
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return a->generic.size == b->generic.size &&
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek memcmp(a->generic.data, b->generic.data, a->generic.size) == 0;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek}
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykrynstatic char* format_location(uint32_t latitude, uint32_t longitude, uint32_t altitude,
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn uint8_t size, uint8_t horiz_pre, uint8_t vert_pre) {
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn char *s;
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn char NS = latitude >= 1U<<31 ? 'N' : 'S';
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn char EW = longitude >= 1U<<31 ? 'E' : 'W';
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn
03664a62914782dbd8f069bbcf8a0c8ca1df7010Lukas Nykryn int lat = latitude >= 1U<<31 ? (int) (latitude - (1U<<31)) : (int) ((1U<<31) - latitude);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek int lon = longitude >= 1U<<31 ? (int) (longitude - (1U<<31)) : (int) ((1U<<31) - longitude);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek double alt = altitude >= 10000000u ? altitude - 10000000u : -(double)(10000000u - altitude);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek double siz = (size >> 4) * exp10((double) (size & 0xF));
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek double hor = (horiz_pre >> 4) * exp10((double) (horiz_pre & 0xF));
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek double ver = (vert_pre >> 4) * exp10((double) (vert_pre & 0xF));
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering (lat / 60000 / 60),
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering (lat / 60000) % 60,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering (lat % 60000) / 1000.,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering NS,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering (lon / 60000 / 60),
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lon / 60000) % 60,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek (lon % 60000) / 1000.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek EW,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek alt / 100.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek siz / 100.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek hor / 100.,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek ver / 100.) < 0)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return NULL;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return s;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek}
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmekint dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek _cleanup_free_ char *k = NULL, *t = NULL;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek char *s;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek int r;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek assert(rr);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek r = dns_resource_key_to_string(rr->key, &k);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (r < 0)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return r;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek switch (rr->unparseable ? _DNS_TYPE_INVALID : rr->key->type) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek case DNS_TYPE_SRV:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u %u %u %s",
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek k,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->srv.priority,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->srv.weight,
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek rr->srv.port,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering strna(rr->srv.name));
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_PTR:
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_NS:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_CNAME:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_DNAME:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering s = strjoin(k, " ", rr->ptr.name, NULL);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering if (!s)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_HINFO:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering s = strjoin(k, " ", rr->hinfo.cpu, " ", rr->hinfo.os, NULL);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (!s)
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return -ENOMEM;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering break;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_SPF: /* exactly the same as TXT */
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering case DNS_TYPE_TXT:
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering t = strv_join_quoted(rr->txt.strings);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!t)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
8ac4e9e1e54397f6d1745c2a7a806132418c7da2Lennart Poettering s = strjoin(k, " ", t, NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!s)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering case DNS_TYPE_A: {
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering _cleanup_free_ char *x = NULL;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = in_addr_to_string(AF_INET, (const union in_addr_union*) &rr->a.in_addr, &x);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return r;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
9de3e3294065e8697ff10130b53f274319cdcf6fZbigniew Jędrzejewski-Szmek s = strjoin(k, " ", x, NULL);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!s)
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek return -ENOMEM;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek break;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek }
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek case DNS_TYPE_AAAA:
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek r = in_addr_to_string(AF_INET6, (const union in_addr_union*) &rr->aaaa.in6_addr, &t);
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek if (r < 0)
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek return r;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!s)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering break;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_SOA:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = asprintf(&s, "%s %s %s %u %u %u %u %u",
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering k,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering strna(rr->soa.mname),
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering strna(rr->soa.rname),
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.serial,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.refresh,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->soa.retry,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->soa.expire,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->soa.minimum);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_MX:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering r = asprintf(&s, "%s %u %s",
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering k,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->mx.priority,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering rr->mx.exchange);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (r < 0)
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering return -ENOMEM;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering break;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering case DNS_TYPE_LOC:
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering assert(rr->loc.version == 0);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering t = format_location(rr->loc.latitude,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->loc.longitude,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->loc.altitude,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->loc.size,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->loc.horiz_pre,
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering rr->loc.vert_pre);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering if (!t)
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return -ENOMEM;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek if (!s)
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek return -ENOMEM;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek break;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek case DNS_TYPE_SSHFP:
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek t = hexmem(rr->sshfp.key, rr->sshfp.key_size);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (!t)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u %u %s",
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek k,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->sshfp.algorithm,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek rr->sshfp.fptype,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek t);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek if (r < 0)
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek break;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_TYPE_DNSKEY:
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek t = hexmem(rr->dnskey.key, rr->dnskey.key_size);
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek if (!t)
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek return -ENOMEM;
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek r = asprintf(&s, "%s %u 3 %u %s",
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek k,
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek dnskey_to_flags(rr),
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering rr->dnskey.algorithm,
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering t);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (r < 0)
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering return -ENOMEM;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering break;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek default:
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering t = hexmem(rr->generic.data, rr->generic.size);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering if (!t)
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering return -ENOMEM;
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek s = strjoin(k, " ", t, NULL);
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek if (!s)
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek return -ENOMEM;
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek break;
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek }
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek *ret = s;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return 0;
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering}
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmekconst char *dns_class_to_string(uint16_t class) {
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek switch (class) {
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_CLASS_IN:
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return "IN";
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek case DNS_CLASS_ANY:
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek return "ANY";
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering }
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return NULL;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek}
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmekint dns_class_from_string(const char *s, uint16_t *class) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek assert(s);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek assert(class);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek if (strcaseeq(s, "IN"))
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek *class = DNS_CLASS_IN;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek else if (strcaseeq(s, "ANY"))
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek *class = DNS_TYPE_ANY;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek else
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return -EINVAL;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return 0;
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek}
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek