resolved-dns-rr.h revision 42cc2eebb01056beb7acd3ecfe8e533558237f84
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#pragma once
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering/***
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering This file is part of systemd.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering Copyright 2014 Lennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering systemd is free software; you can redistribute it and/or modify it
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering under the terms of the GNU Lesser General Public License as published by
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering (at your option) any later version.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering systemd is distributed in the hope that it will be useful, but
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering Lesser General Public License for more details.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering You should have received a copy of the GNU Lesser General Public License
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering ***/
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#include <inttypes.h>
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#include <netinet/in.h>
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#include "util.h"
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#include "hashmap.h"
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#include "in-addr-util.h"
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringtypedef struct DnsResourceKey DnsResourceKey;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringtypedef struct DnsResourceRecord DnsResourceRecord;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering/* DNS record classes, see RFC 1035 */
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringenum {
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_CLASS_IN = 0x01,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_CLASS_ANY = 0xFF,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering _DNS_CLASS_MAX,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering _DNS_CLASS_INVALID = -1
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering};
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering/* DNS record types, see RFC 1035 */
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringenum {
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering /* Normal records */
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_A = 0x01,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_NS = 0x02,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_CNAME = 0x05,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_SOA = 0x06,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_PTR = 0x0C,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_HINFO = 0x0D,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_MX = 0x0F,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_TXT = 0x10,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_AAAA = 0x1C,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_LOC = 0x1D,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_SRV = 0x21,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_DNAME = 0x27,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_SSHFP = 0x2C,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_SPF = 0x63,
f0213e3796b4dd66e546e2de4d677db319f9171bTom Gundersen
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering /* Special records */
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_ANY = 0xFF,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_OPT = 0x29, /* EDNS0 option */
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_TKEY = 0xF9,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_TSIG = 0xFA,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_IXFR = 0xFB,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering DNS_TYPE_AXFR = 0xFC,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering _DNS_TYPE_MAX,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering _DNS_TYPE_INVALID = -1
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering};
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringstruct DnsResourceKey {
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering unsigned n_ref;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering uint16_t class, type;
char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
};
struct DnsResourceRecord {
unsigned n_ref;
DnsResourceKey *key;
uint32_t ttl;
bool unparseable;
union {
struct {
void *data;
uint16_t size;
} generic;
struct {
uint16_t priority;
uint16_t weight;
uint16_t port;
char *name;
} srv;
struct {
char *name;
} ptr, ns, cname, dname;
struct {
char *cpu;
char *os;
} hinfo;
struct {
char **strings;
} txt, spf;
struct {
struct in_addr in_addr;
} a;
struct {
struct in6_addr in6_addr;
} aaaa;
struct {
char *mname;
char *rname;
uint32_t serial;
uint32_t refresh;
uint32_t retry;
uint32_t expire;
uint32_t minimum;
} soa;
struct {
uint16_t priority;
char *exchange;
} mx;
struct {
uint8_t version;
uint8_t size;
uint8_t horiz_pre;
uint8_t vert_pre;
uint32_t latitude;
uint32_t longitude;
uint32_t altitude;
} loc;
struct {
uint8_t algorithm;
uint8_t fptype;
void *key;
size_t key_size;
} sshfp;
};
};
static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
if (_unlikely_(!key))
return NULL;
if (key->_name)
return key->_name;
return (char*) key + sizeof(DnsResourceKey);
}
DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr);
int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr);
unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]);
int dns_resource_key_compare_func(const void *a, const void *b);
int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
const char *dns_type_to_string(uint16_t type);
int dns_type_from_string(const char *name, uint16_t *type);
const char *dns_class_to_string(uint16_t type);
int dns_class_from_string(const char *name, uint16_t *class);