resolved-dns-rr.h revision 801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47dd
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering#pragma once
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering/***
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering This file is part of systemd.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Copyright 2014 Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering (at your option) any later version.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering systemd is distributed in the hope that it will be useful, but
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering Lesser General Public License for more details.
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen ***/
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen#include <netinet/in.h>
11c3a36649e5e5e77db499c92f3cdcbd619efd3aThomas Hindoe Paaboel Andersen
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "bitmap.h"
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering#include "dns-type.h"
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering#include "hashmap.h"
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering#include "in-addr-util.h"
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering#include "list.h"
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringtypedef struct DnsResourceKey DnsResourceKey;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagintypedef struct DnsResourceRecord DnsResourceRecord;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringtypedef struct DnsTxtItem DnsTxtItem;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering/* DNS record classes, see RFC 1035 */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringenum {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering DNS_CLASS_IN = 0x01,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering DNS_CLASS_ANY = 0xFF,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering _DNS_CLASS_MAX,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering _DNS_CLASS_INVALID = -1
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering};
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstruct DnsResourceKey {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering unsigned n_ref;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint16_t class, type;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering};
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstruct DnsTxtItem {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering size_t length;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering LIST_FIELDS(DnsTxtItem, items);
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t data[];
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering};
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poetteringstruct DnsResourceRecord {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering unsigned n_ref;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering DnsResourceKey *key;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t ttl;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering bool unparseable;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering union {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering void *data;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering size_t size;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } generic;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint16_t priority;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint16_t weight;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint16_t port;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *name;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } srv;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *name;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } ptr, ns, cname, dname;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *cpu;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *os;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } hinfo;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering DnsTxtItem *items;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } txt, spf;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct in_addr in_addr;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } a;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct in6_addr in6_addr;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } aaaa;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *mname;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *rname;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t serial;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t refresh;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t retry;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t expire;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t minimum;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } soa;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint16_t priority;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering char *exchange;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } mx;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t version;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t size;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t horiz_pre;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t vert_pre;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t latitude;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t longitude;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t altitude;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } loc;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint16_t key_tag;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t algorithm;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t digest_type;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering void *digest;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering size_t digest_size;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } ds;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* https://tools.ietf.org/html/rfc4255#section-3.1 */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t algorithm;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t fptype;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering void *fingerprint;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering size_t fingerprint_size;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } sshfp;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* http://tools.ietf.org/html/rfc4034#section-2.1 */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering bool zone_key_flag:1;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering bool sep_flag:1;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t algorithm;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering void* key;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering size_t key_size;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering } dnskey;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering /* http://tools.ietf.org/html/rfc4034#section-3.1 */
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering struct {
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint16_t type_covered;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint8_t algorithm;
934ae16baf543af03f3f521277d14524ca772d17Lennart Poettering uint8_t labels;
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering uint32_t original_ttl;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin uint32_t expiration;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin uint32_t inception;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin uint16_t key_tag;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin char *signer;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin void *signature;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin size_t signature_size;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin } rrsig;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin struct {
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin char *next_domain_name;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin Bitmap *types;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin } nsec;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin struct {
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin uint8_t algorithm;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin uint8_t flags;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin uint16_t iterations;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin void *salt;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin size_t salt_size;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin void *next_hashed_name;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin size_t next_hashed_name_size;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin Bitmap *types;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin } nsec3;
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin };
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin};
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchaginstatic inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
c573dcfeb1abd390cd4c4288056df97752ef18f0Evgeny Vereshchagin 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_cname(const DnsResourceKey *key);
DnsResourceKey* dns_resource_key_new_dname(const DnsResourceKey *key);
DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, 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, const char *search_domain);
int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr, const char *search_domain);
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_new_address(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);
DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
const char *dns_class_to_string(uint16_t type);
int dns_class_from_string(const char *name, uint16_t *class);
extern const struct hash_ops dns_resource_key_hash_ops;