resolved-dns-rr.h revision 2e276efc7b0398a3086629a52970bdd4ab7252f9
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#pragma once
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
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <inttypes.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <netinet/in.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "util.h"
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering#include "hashmap.h"
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering#include "in-addr-util.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringtypedef struct DnsResourceKey DnsResourceKey;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringtypedef struct DnsResourceRecord DnsResourceRecord;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/* DNS record classes, see RFC 1035 */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringenum {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_CLASS_IN = 0x01,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering DNS_CLASS_ANY = 0xFF,
b93312f5960b276bae915906ccde36f545bae3e0Zbigniew Jędrzejewski-Szmek _DNS_CLASS_MAX,
b93312f5960b276bae915906ccde36f545bae3e0Zbigniew Jędrzejewski-Szmek _DNS_CLASS_INVALID = -1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/* DNS record types, see RFC 1035 */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringenum {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Normal records */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_A = 0x01,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_NS = 0x02,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_CNAME = 0x05,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_SOA = 0x06,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_PTR = 0x0C,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_HINFO = 0x0D,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_MX = 0x0F,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_TXT = 0x10,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_AAAA = 0x1C,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_SRV = 0x21,
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering DNS_TYPE_DNAME = 0x27,
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering DNS_TYPE_SSHFP = 0x2C,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Special records */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_ANY = 0xFF,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_OPT = 0x29, /* EDNS0 option */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_TKEY = 0xF9,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_TSIG = 0xFA,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_IXFR = 0xFB,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DNS_TYPE_AXFR = 0xFC,
b93312f5960b276bae915906ccde36f545bae3e0Zbigniew Jędrzejewski-Szmek _DNS_TYPE_MAX,
b93312f5960b276bae915906ccde36f545bae3e0Zbigniew Jędrzejewski-Szmek _DNS_TYPE_INVALID = -1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstruct DnsResourceKey {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering unsigned n_ref;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering uint16_t class, type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstruct DnsResourceRecord {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering unsigned n_ref;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering DnsResourceKey *key;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint32_t ttl;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering union {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering void *data;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering uint16_t size;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } generic;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* struct { */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* uint16_t priority; */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* uint16_t weight; */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* uint16_t port; */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* char *name; */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* } srv; */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *name;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } ptr, ns, cname;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *cpu;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *os;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } hinfo;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek struct {
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek char **strings;
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek } txt;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct in_addr in_addr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } a;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering struct in6_addr in6_addr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } aaaa;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering struct {
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering char *mname;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering char *rname;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering uint32_t serial;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering uint32_t refresh;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering uint32_t retry;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering uint32_t expire;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering uint32_t minimum;
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering } soa;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek struct {
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek uint16_t priority;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek char *exchange;
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek } mx;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering };
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstatic inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (_unlikely_(!key))
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return NULL;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering if (key->_name)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return key->_name;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering return (char*) key + sizeof(DnsResourceKey);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringunsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringint dns_resource_key_compare_func(const void *a, const void *b);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
8bf52d3d17d364438191077d0750b8b80b5dc53aLennart PoetteringDnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart PoetteringDnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart PoetteringDnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poetteringint dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringint dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringconst char *dns_type_to_string(uint16_t type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_type_from_string(const char *name, uint16_t *type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringconst char *dns_class_to_string(uint16_t type);
2d4c5cbc0ed3ccb09dc086a040088b454c22c644Lennart Poetteringint dns_class_from_string(const char *name, uint16_t *class);