2014-07-16 00:26:02 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2014 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2015-07-13 01:51:03 +02:00
|
|
|
#include "bitmap.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "dns-type.h"
|
2014-07-17 19:38:37 +02:00
|
|
|
#include "hashmap.h"
|
2014-07-29 14:24:02 +02:00
|
|
|
#include "in-addr-util.h"
|
2015-11-20 19:01:43 +01:00
|
|
|
#include "list.h"
|
2014-07-16 00:26:02 +02:00
|
|
|
|
|
|
|
typedef struct DnsResourceKey DnsResourceKey;
|
|
|
|
typedef struct DnsResourceRecord DnsResourceRecord;
|
2015-11-20 19:01:43 +01:00
|
|
|
typedef struct DnsTxtItem DnsTxtItem;
|
2014-07-16 00:26:02 +02:00
|
|
|
|
|
|
|
/* DNS record classes, see RFC 1035 */
|
|
|
|
enum {
|
|
|
|
DNS_CLASS_IN = 0x01,
|
2014-07-17 19:38:37 +02:00
|
|
|
DNS_CLASS_ANY = 0xFF,
|
2014-08-01 02:06:30 +02:00
|
|
|
_DNS_CLASS_MAX,
|
|
|
|
_DNS_CLASS_INVALID = -1
|
2014-07-16 00:26:02 +02:00
|
|
|
};
|
|
|
|
|
2015-12-02 22:56:04 +01:00
|
|
|
/* DNSKEY RR flags */
|
|
|
|
#define DNSKEY_FLAG_ZONE_KEY (UINT16_C(1) << 8)
|
|
|
|
#define DNSKEY_FLAG_SEP (UINT16_C(1) << 0)
|
|
|
|
|
2015-11-24 15:45:15 +01:00
|
|
|
/* mDNS RR flags */
|
|
|
|
#define MDNS_RR_CACHE_FLUSH (UINT16_C(1) << 15)
|
|
|
|
|
2015-12-02 22:56:04 +01:00
|
|
|
/* DNSSEC algorithm identifiers, see
|
|
|
|
* http://tools.ietf.org/html/rfc4034#appendix-A.1 and
|
|
|
|
* https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
|
|
|
|
enum {
|
|
|
|
DNSSEC_ALGORITHM_RSAMD5 = 1,
|
|
|
|
DNSSEC_ALGORITHM_DH,
|
|
|
|
DNSSEC_ALGORITHM_DSA,
|
|
|
|
DNSSEC_ALGORITHM_ECC,
|
|
|
|
DNSSEC_ALGORITHM_RSASHA1,
|
|
|
|
DNSSEC_ALGORITHM_DSA_NSEC3_SHA1,
|
|
|
|
DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1,
|
|
|
|
DNSSEC_ALGORITHM_RSASHA256 = 8, /* RFC 5702 */
|
|
|
|
DNSSEC_ALGORITHM_RSASHA512 = 10, /* RFC 5702 */
|
|
|
|
DNSSEC_ALGORITHM_INDIRECT = 252,
|
|
|
|
DNSSEC_ALGORITHM_PRIVATEDNS,
|
|
|
|
DNSSEC_ALGORITHM_PRIVATEOID,
|
|
|
|
_DNSSEC_ALGORITHM_MAX_DEFINED
|
|
|
|
};
|
|
|
|
|
|
|
|
/* DNSSEC digest identifiers, see
|
|
|
|
* https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
|
|
|
|
enum {
|
|
|
|
DNSSEC_DIGEST_SHA1 = 1,
|
|
|
|
DNSSEC_DIGEST_SHA256 = 2,
|
|
|
|
_DNSSEC_DIGEST_MAX_DEFINED
|
|
|
|
};
|
|
|
|
|
2014-07-16 00:26:02 +02:00
|
|
|
struct DnsResourceKey {
|
2014-07-22 21:48:41 +02:00
|
|
|
unsigned n_ref;
|
|
|
|
uint16_t class, type;
|
|
|
|
char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
|
2015-11-24 15:45:15 +01:00
|
|
|
bool cache_flush:1;
|
2014-07-16 00:26:02 +02:00
|
|
|
};
|
|
|
|
|
2015-12-03 17:27:13 +01:00
|
|
|
/* Creates a temporary resource key. This is only useful to quickly
|
|
|
|
* look up something, without allocating a full DnsResourceKey object
|
|
|
|
* for it. Note that it is not OK to take references to this kind of
|
|
|
|
* resource key object. */
|
|
|
|
#define DNS_RESOURCE_KEY_CONST(c, t, n) \
|
|
|
|
((DnsResourceKey) { \
|
|
|
|
.n_ref = (unsigned) -1, \
|
|
|
|
.class = c, \
|
|
|
|
.type = t, \
|
|
|
|
._name = (char*) n, \
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2015-11-20 19:01:43 +01:00
|
|
|
struct DnsTxtItem {
|
|
|
|
size_t length;
|
|
|
|
LIST_FIELDS(DnsTxtItem, items);
|
|
|
|
uint8_t data[];
|
|
|
|
};
|
|
|
|
|
2014-07-16 00:26:02 +02:00
|
|
|
struct DnsResourceRecord {
|
|
|
|
unsigned n_ref;
|
2014-07-22 21:48:41 +02:00
|
|
|
DnsResourceKey *key;
|
2014-07-16 00:26:02 +02:00
|
|
|
uint32_t ttl;
|
2015-12-02 20:58:51 +01:00
|
|
|
bool unparseable:1;
|
|
|
|
bool wire_format_canonical:1;
|
|
|
|
void *wire_format;
|
|
|
|
size_t wire_format_size;
|
|
|
|
size_t wire_format_rdata_offset;
|
2014-07-16 00:26:02 +02:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
void *data;
|
2015-07-23 04:04:19 +02:00
|
|
|
size_t size;
|
2014-07-16 00:26:02 +02:00
|
|
|
} generic;
|
|
|
|
|
2014-07-31 18:23:00 +02:00
|
|
|
struct {
|
|
|
|
uint16_t priority;
|
|
|
|
uint16_t weight;
|
|
|
|
uint16_t port;
|
|
|
|
char *name;
|
|
|
|
} srv;
|
2014-07-16 00:26:02 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
char *name;
|
2014-07-31 18:02:24 +02:00
|
|
|
} ptr, ns, cname, dname;
|
2014-07-16 00:26:02 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
char *cpu;
|
|
|
|
char *os;
|
|
|
|
} hinfo;
|
|
|
|
|
2014-08-01 03:36:58 +02:00
|
|
|
struct {
|
2015-11-20 19:01:43 +01:00
|
|
|
DnsTxtItem *items;
|
2014-07-31 18:03:09 +02:00
|
|
|
} txt, spf;
|
2014-07-16 00:26:02 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct in_addr in_addr;
|
|
|
|
} a;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct in6_addr in6_addr;
|
|
|
|
} aaaa;
|
2014-07-23 00:57:25 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
char *mname;
|
|
|
|
char *rname;
|
|
|
|
uint32_t serial;
|
|
|
|
uint32_t refresh;
|
|
|
|
uint32_t retry;
|
|
|
|
uint32_t expire;
|
|
|
|
uint32_t minimum;
|
|
|
|
} soa;
|
2014-08-01 03:06:00 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
uint16_t priority;
|
|
|
|
char *exchange;
|
|
|
|
} mx;
|
2014-07-31 10:19:43 +02:00
|
|
|
|
|
|
|
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;
|
2014-07-31 18:41:41 +02:00
|
|
|
|
2015-07-13 01:51:03 +02:00
|
|
|
struct {
|
|
|
|
uint16_t key_tag;
|
|
|
|
uint8_t algorithm;
|
|
|
|
uint8_t digest_type;
|
|
|
|
void *digest;
|
|
|
|
size_t digest_size;
|
|
|
|
} ds;
|
|
|
|
|
2015-07-23 13:09:35 +02:00
|
|
|
/* https://tools.ietf.org/html/rfc4255#section-3.1 */
|
2014-07-31 18:41:41 +02:00
|
|
|
struct {
|
|
|
|
uint8_t algorithm;
|
|
|
|
uint8_t fptype;
|
2015-07-23 13:09:35 +02:00
|
|
|
void *fingerprint;
|
|
|
|
size_t fingerprint_size;
|
2014-07-31 18:41:41 +02:00
|
|
|
} sshfp;
|
2014-08-03 22:05:41 +02:00
|
|
|
|
|
|
|
/* http://tools.ietf.org/html/rfc4034#section-2.1 */
|
|
|
|
struct {
|
2015-12-02 20:53:10 +01:00
|
|
|
uint16_t flags;
|
|
|
|
uint8_t protocol;
|
2014-08-03 22:05:41 +02:00
|
|
|
uint8_t algorithm;
|
|
|
|
void* key;
|
|
|
|
size_t key_size;
|
|
|
|
} dnskey;
|
2014-08-04 00:17:22 +02:00
|
|
|
|
|
|
|
/* http://tools.ietf.org/html/rfc4034#section-3.1 */
|
|
|
|
struct {
|
|
|
|
uint16_t type_covered;
|
|
|
|
uint8_t algorithm;
|
|
|
|
uint8_t labels;
|
|
|
|
uint32_t original_ttl;
|
|
|
|
uint32_t expiration;
|
|
|
|
uint32_t inception;
|
|
|
|
uint16_t key_tag;
|
|
|
|
char *signer;
|
|
|
|
void *signature;
|
|
|
|
size_t signature_size;
|
|
|
|
} rrsig;
|
2015-07-13 01:51:03 +02:00
|
|
|
|
2015-11-27 19:22:35 +01:00
|
|
|
/* https://tools.ietf.org/html/rfc4034#section-4.1 */
|
2015-07-13 01:51:03 +02:00
|
|
|
struct {
|
|
|
|
char *next_domain_name;
|
|
|
|
Bitmap *types;
|
|
|
|
} nsec;
|
2015-07-13 01:51:03 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
uint8_t algorithm;
|
|
|
|
uint8_t flags;
|
|
|
|
uint16_t iterations;
|
|
|
|
void *salt;
|
|
|
|
size_t salt_size;
|
|
|
|
void *next_hashed_name;
|
|
|
|
size_t next_hashed_name_size;
|
|
|
|
Bitmap *types;
|
|
|
|
} nsec3;
|
2014-07-16 00:26:02 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-07-22 21:48:41 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-07-16 00:26:02 +02:00
|
|
|
|
2014-07-22 21:48:41 +02:00
|
|
|
DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
|
2015-09-04 01:56:23 +02:00
|
|
|
DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
|
2015-11-25 20:47:27 +01:00
|
|
|
int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
|
2014-07-22 21:48:41 +02:00
|
|
|
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);
|
2015-12-03 18:26:12 +01:00
|
|
|
bool dns_resource_key_is_address(const DnsResourceKey *key);
|
2014-07-22 21:48:41 +02:00
|
|
|
int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
|
2015-11-25 20:47:27 +01:00
|
|
|
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);
|
2014-07-30 19:23:27 +02:00
|
|
|
int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
|
2014-07-22 21:48:41 +02:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
|
2014-07-17 19:38:37 +02:00
|
|
|
|
2014-07-22 21:48:41 +02:00
|
|
|
DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
|
2014-07-30 16:30:25 +02:00
|
|
|
DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
|
2014-07-16 00:26:02 +02:00
|
|
|
DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
|
|
|
|
DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
|
2014-07-29 14:24:02 +02:00
|
|
|
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
|
2015-08-17 23:54:08 +02:00
|
|
|
int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
|
2014-07-17 19:38:37 +02:00
|
|
|
int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
|
2014-07-30 19:23:27 +02:00
|
|
|
int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
|
2014-07-22 21:48:41 +02:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
|
2014-07-17 19:38:37 +02:00
|
|
|
|
2015-12-02 20:58:51 +01:00
|
|
|
int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
|
|
|
|
|
2015-11-20 19:01:43 +01:00
|
|
|
DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
|
|
|
|
bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
|
|
|
|
|
2014-07-17 19:38:37 +02:00
|
|
|
const char *dns_class_to_string(uint16_t type);
|
2014-07-30 19:23:27 +02:00
|
|
|
int dns_class_from_string(const char *name, uint16_t *class);
|
2014-08-13 01:00:18 +02:00
|
|
|
|
|
|
|
extern const struct hash_ops dns_resource_key_hash_ops;
|
2015-12-02 22:56:04 +01:00
|
|
|
|
|
|
|
const char* dnssec_algorithm_to_string(int i) _const_;
|
|
|
|
int dnssec_algorithm_from_string(const char *s) _pure_;
|
|
|
|
|
|
|
|
const char *dnssec_digest_to_string(int i) _const_;
|
|
|
|
int dnssec_digest_from_string(const char *s) _pure_;
|