resolved-dns-rr.c revision ff3d6560bead6879a2fed1bf99bfe8273b3723f1
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering This file is part of systemd.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Copyright 2014 Lennart Poettering
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering (at your option) any later version.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is distributed in the hope that it will be useful, but
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Lesser General Public License for more details.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
d4fffc4b8beb86e77fd710c1f43913a490ed083aZbigniew Jędrzejewski-SzmekDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
96cde13ace6406582688028f3df5668a172ba628Zbigniew Jędrzejewski-Szmek k = malloc0(sizeof(DnsResourceKey) + l + 1);
cfeaa44a09756a93a881f786678973d9b1e382dbLennart Poettering strcpy((char*) k + sizeof(DnsResourceKey), name);
6c03089c32c251d823173bda4d809a9e643219f0Lennart PoetteringDnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name) {
cfeaa44a09756a93a881f786678973d9b1e382dbLennart PoetteringDnsResourceKey* dns_resource_key_ref(DnsResourceKey *k) {
d4fffc4b8beb86e77fd710c1f43913a490ed083aZbigniew Jędrzejewski-SzmekDnsResourceKey* dns_resource_key_unref(DnsResourceKey *k) {
cfeaa44a09756a93a881f786678973d9b1e382dbLennart Poetteringint dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
320814811417146cfa1e416f69f1101eed630c36Luke Shumaker r = dns_name_equal(DNS_RESOURCE_KEY_NAME(a), DNS_RESOURCE_KEY_NAME(b));
374ec6abf31ada6ca554cc8ea99b282373fac010Lennart Poetteringint dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr) {
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering if (rr->key->class != key->class && key->class != DNS_CLASS_ANY)
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering if (rr->key->type != key->type && key->type != DNS_TYPE_ANY)
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
374ec6abf31ada6ca554cc8ea99b282373fac010Lennart Poetteringint dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr) {
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering if (rr->key->class != key->class && key->class != DNS_CLASS_ANY)
8b0849e9710d721c5d0b775aaf0fd662eefa1449Lennart Poettering return dns_name_equal(DNS_RESOURCE_KEY_NAME(rr->key), DNS_RESOURCE_KEY_NAME(key));
8b0849e9710d721c5d0b775aaf0fd662eefa1449Lennart Poetteringunsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]) {
8b0849e9710d721c5d0b775aaf0fd662eefa1449Lennart Poettering unsigned long ul;
8b0849e9710d721c5d0b775aaf0fd662eefa1449Lennart Poettering ul = dns_name_hash_func(DNS_RESOURCE_KEY_NAME(k), hash_key);
329ac4bc5429cd86c4ac76b13e7e2784f3982760Lennart Poetteringint dns_resource_key_compare_func(const void *a, const void *b) {
329ac4bc5429cd86c4ac76b13e7e2784f3982760Lennart Poettering const DnsResourceKey *x = a, *y = b;
329ac4bc5429cd86c4ac76b13e7e2784f3982760Lennart Poettering ret = dns_name_compare_func(DNS_RESOURCE_KEY_NAME(x), DNS_RESOURCE_KEY_NAME(y));
329ac4bc5429cd86c4ac76b13e7e2784f3982760Lennart Poetteringint dns_resource_key_to_string(const DnsResourceKey *key, char **ret) {
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering char cbuf[DECIMAL_STR_MAX(uint16_t)], tbuf[DECIMAL_STR_MAX(uint16_t)];
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering const char *c, *t;
e9174f29c7e3ee45137537b126458718913a3ec5Lennart Poettering if (asprintf(&s, "%s %s %-5s", DNS_RESOURCE_KEY_NAME(key), c, t) < 0)
aff38e74bd776471f15ba54b305a24b0251eb865Lennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
aff38e74bd776471f15ba54b305a24b0251eb865Lennart PoetteringDnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name) {
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering key = dns_resource_key_new(class, type, name);
aff38e74bd776471f15ba54b305a24b0251eb865Lennart PoetteringDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
ae018d9bc900d6355dea4af05119b49c67945184Lennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
751bc6ac79320bc16e63e8c1bbb713c30a3b7bc9Lennart Poetteringint dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
751bc6ac79320bc16e63e8c1bbb713c30a3b7bc9Lennart Poettering _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
751bc6ac79320bc16e63e8c1bbb713c30a3b7bc9Lennart Poettering _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
5f4c5fef66581383ee852b301db67f687663004cLennart Poettering r = dns_name_reverse(family, address, &ptr);
5f4c5fef66581383ee852b301db67f687663004cLennart Poettering key = dns_resource_key_new_consume(DNS_CLASS_IN, DNS_TYPE_PTR, ptr);
assert(a);
assert(b);
case DNS_TYPE_SRV:
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
case DNS_TYPE_HINFO:
case DNS_TYPE_TXT: {
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
case DNS_TYPE_SOA:
case DNS_TYPE_MX:
case DNS_TYPE_LOC:
case DNS_TYPE_SSHFP:
case DNS_TYPE_DNSKEY:
NS,
EW,
return NULL;
case DNS_TYPE_SRV:
return -ENOMEM;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
return -ENOMEM;
case DNS_TYPE_HINFO:
return -ENOMEM;
case DNS_TYPE_TXT:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_A: {
return -ENOMEM;
case DNS_TYPE_AAAA:
return -ENOMEM;
case DNS_TYPE_SOA:
return -ENOMEM;
case DNS_TYPE_MX:
return -ENOMEM;
case DNS_TYPE_LOC:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_SSHFP:
return -ENOMEM;
return -ENOMEM;
case DNS_TYPE_DNSKEY: {
const char *alg;
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
*ret = s;
switch (class) {
case DNS_CLASS_IN:
case DNS_CLASS_ANY:
return NULL;
assert(s);
return -EINVAL;