resolved-dns-rr.h revision abf126a355e2f2b62b6c51ab3bb37895d1e3eee7
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers#pragma once
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers/***
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers This file is part of systemd.
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers Copyright 2014 Lennart Poettering
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers systemd is free software; you can redistribute it and/or modify it
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers under the terms of the GNU Lesser General Public License as published by
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers the Free Software Foundation; either version 2.1 of the License, or
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers (at your option) any later version.
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers systemd is distributed in the hope that it will be useful, but
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers WITHOUT ANY WARRANTY; without even the implied warranty of
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers Lesser General Public License for more details.
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers You should have received a copy of the GNU Lesser General Public License
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers along with systemd; If not, see <http://www.gnu.org/licenses/>.
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers ***/
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers#include <netinet/in.h>
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers#include "hashmap.h"
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers#include "in-addr-util.h"
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers#include "dns-type.h"
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sieverstypedef struct DnsResourceKey DnsResourceKey;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sieverstypedef struct DnsResourceRecord DnsResourceRecord;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers/* DNS record classes, see RFC 1035 */
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sieversenum {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers DNS_CLASS_IN = 0x01,
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers DNS_CLASS_ANY = 0xFF,
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers _DNS_CLASS_MAX,
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers _DNS_CLASS_INVALID = -1
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers};
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sieversstruct DnsResourceKey {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers unsigned n_ref;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t class, type;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers};
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sieversstruct DnsResourceRecord {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers unsigned n_ref;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers DnsResourceKey *key;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t ttl;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers bool unparseable;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers union {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers void *data;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t size;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } generic;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t priority;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t weight;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t port;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *name;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } srv;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *name;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } ptr, ns, cname, dname;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *cpu;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *os;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } hinfo;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char **strings;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } txt, spf;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct in_addr in_addr;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } a;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct in6_addr in6_addr;
2c64a8d0caf84254e38f2e76528f2034d37da520Lennart Poettering } aaaa;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *mname;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *rname;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t serial;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t refresh;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t retry;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t expire;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t minimum;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } soa;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t priority;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *exchange;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } mx;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t version;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t size;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t horiz_pre;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t vert_pre;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t latitude;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t longitude;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t altitude;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } loc;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t key_tag;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t algorithm;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t digest_type;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers void *digest;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers size_t digest_size;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } ds;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t algorithm;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t fptype;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers void *key;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers size_t key_size;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } sshfp;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers /* http://tools.ietf.org/html/rfc4034#section-2.1 */
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers bool zone_key_flag:1;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers bool sep_flag:1;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t algorithm;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers void* key;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers size_t key_size;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } dnskey;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers /* http://tools.ietf.org/html/rfc4034#section-3.1 */
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers struct {
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t type_covered;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t algorithm;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint8_t labels;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t original_ttl;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t expiration;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint32_t inception;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers uint16_t key_tag;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers char *signer;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers void *signature;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers size_t signature_size;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers } rrsig;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers };
6c7980093c4e39d07bf06484f96f489e236c7c29Kay Sievers};
6c7980093c4e39d07bf06484f96f489e236c7c29Kay Sievers
6c7980093c4e39d07bf06484f96f489e236c7c29Kay Sieversstatic inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
6c7980093c4e39d07bf06484f96f489e236c7c29Kay Sievers if (_unlikely_(!key))
6c7980093c4e39d07bf06484f96f489e236c7c29Kay Sievers return NULL;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers if (key->_name)
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers return key->_name;
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers return (char*) key + sizeof(DnsResourceKey);
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers}
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers
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);
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_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;