]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-rr.h
shared: relax restrictions on valid domain name characters a bit
[thirdparty/systemd.git] / src / resolve / resolved-dns-rr.h
CommitLineData
74b2466e
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright 2014 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
74b2466e
LP
24#include <netinet/in.h>
25
50f1e641 26#include "bitmap.h"
71d35b6b 27#include "dns-type.h"
322345fd 28#include "hashmap.h"
623a4c97 29#include "in-addr-util.h"
2001c805 30#include "list.h"
74b2466e
LP
31
32typedef struct DnsResourceKey DnsResourceKey;
33typedef struct DnsResourceRecord DnsResourceRecord;
2001c805 34typedef struct DnsTxtItem DnsTxtItem;
74b2466e 35
8730bccf
LP
36/* DNSKEY RR flags */
37#define DNSKEY_FLAG_ZONE_KEY (UINT16_C(1) << 8)
38#define DNSKEY_FLAG_SEP (UINT16_C(1) << 0)
39
23502de3
DM
40/* mDNS RR flags */
41#define MDNS_RR_CACHE_FLUSH (UINT16_C(1) << 15)
42
8730bccf
LP
43/* DNSSEC algorithm identifiers, see
44 * http://tools.ietf.org/html/rfc4034#appendix-A.1 and
45 * https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
46enum {
47 DNSSEC_ALGORITHM_RSAMD5 = 1,
48 DNSSEC_ALGORITHM_DH,
49 DNSSEC_ALGORITHM_DSA,
50 DNSSEC_ALGORITHM_ECC,
51 DNSSEC_ALGORITHM_RSASHA1,
52 DNSSEC_ALGORITHM_DSA_NSEC3_SHA1,
53 DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1,
54 DNSSEC_ALGORITHM_RSASHA256 = 8, /* RFC 5702 */
55 DNSSEC_ALGORITHM_RSASHA512 = 10, /* RFC 5702 */
56 DNSSEC_ALGORITHM_INDIRECT = 252,
57 DNSSEC_ALGORITHM_PRIVATEDNS,
58 DNSSEC_ALGORITHM_PRIVATEOID,
59 _DNSSEC_ALGORITHM_MAX_DEFINED
60};
61
62/* DNSSEC digest identifiers, see
63 * https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
64enum {
65 DNSSEC_DIGEST_SHA1 = 1,
66 DNSSEC_DIGEST_SHA256 = 2,
af22c65b 67 DNSSEC_DIGEST_SHA384 = 4,
8730bccf
LP
68 _DNSSEC_DIGEST_MAX_DEFINED
69};
70
74b2466e 71struct DnsResourceKey {
faa133f3
LP
72 unsigned n_ref;
73 uint16_t class, type;
74 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
74b2466e
LP
75};
76
1b4f6e79
LP
77/* Creates a temporary resource key. This is only useful to quickly
78 * look up something, without allocating a full DnsResourceKey object
79 * for it. Note that it is not OK to take references to this kind of
80 * resource key object. */
81#define DNS_RESOURCE_KEY_CONST(c, t, n) \
82 ((DnsResourceKey) { \
83 .n_ref = (unsigned) -1, \
84 .class = c, \
85 .type = t, \
86 ._name = (char*) n, \
87 })
88
89
2001c805
LP
90struct DnsTxtItem {
91 size_t length;
92 LIST_FIELDS(DnsTxtItem, items);
93 uint8_t data[];
94};
95
74b2466e
LP
96struct DnsResourceRecord {
97 unsigned n_ref;
faa133f3 98 DnsResourceKey *key;
7b50eb2e 99 char *to_string;
74b2466e 100 uint32_t ttl;
a8812dd7
LP
101 bool unparseable:1;
102 bool wire_format_canonical:1;
103 void *wire_format;
104 size_t wire_format_size;
105 size_t wire_format_rdata_offset;
74b2466e
LP
106 union {
107 struct {
108 void *data;
f5430a3e 109 size_t size;
d75acfb0 110 } generic, opt;
74b2466e 111
9c92ce6d
LP
112 struct {
113 uint16_t priority;
114 uint16_t weight;
115 uint16_t port;
116 char *name;
117 } srv;
74b2466e
LP
118
119 struct {
120 char *name;
8ac4e9e1 121 } ptr, ns, cname, dname;
74b2466e
LP
122
123 struct {
124 char *cpu;
125 char *os;
126 } hinfo;
127
2e276efc 128 struct {
2001c805 129 DnsTxtItem *items;
c0eb11cf 130 } txt, spf;
74b2466e
LP
131
132 struct {
133 struct in_addr in_addr;
134 } a;
135
136 struct {
137 struct in6_addr in6_addr;
138 } aaaa;
7e8e0422
LP
139
140 struct {
141 char *mname;
142 char *rname;
143 uint32_t serial;
144 uint32_t refresh;
145 uint32_t retry;
146 uint32_t expire;
147 uint32_t minimum;
148 } soa;
946c7094
ZJS
149
150 struct {
151 uint16_t priority;
152 char *exchange;
153 } mx;
0dae31d4
ZJS
154
155 struct {
156 uint8_t version;
157 uint8_t size;
158 uint8_t horiz_pre;
159 uint8_t vert_pre;
160 uint32_t latitude;
161 uint32_t longitude;
162 uint32_t altitude;
163 } loc;
42cc2eeb 164
abf126a3
TG
165 struct {
166 uint16_t key_tag;
167 uint8_t algorithm;
168 uint8_t digest_type;
169 void *digest;
170 size_t digest_size;
171 } ds;
172
549c1a25 173 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
42cc2eeb
LP
174 struct {
175 uint8_t algorithm;
176 uint8_t fptype;
549c1a25
TG
177 void *fingerprint;
178 size_t fingerprint_size;
42cc2eeb 179 } sshfp;
8db0d2f5
ZJS
180
181 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
182 struct {
f91dc240
LP
183 uint16_t flags;
184 uint8_t protocol;
8db0d2f5
ZJS
185 uint8_t algorithm;
186 void* key;
187 size_t key_size;
188 } dnskey;
151226ab
ZJS
189
190 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
191 struct {
192 uint16_t type_covered;
193 uint8_t algorithm;
194 uint8_t labels;
195 uint32_t original_ttl;
196 uint32_t expiration;
197 uint32_t inception;
198 uint16_t key_tag;
199 char *signer;
200 void *signature;
201 size_t signature_size;
202 } rrsig;
50f1e641 203
9ead3519 204 /* https://tools.ietf.org/html/rfc4034#section-4.1 */
50f1e641
TG
205 struct {
206 char *next_domain_name;
207 Bitmap *types;
208 } nsec;
5d45a880
TG
209
210 struct {
211 uint8_t algorithm;
212 uint8_t flags;
213 uint16_t iterations;
214 void *salt;
215 size_t salt_size;
216 void *next_hashed_name;
217 size_t next_hashed_name_size;
218 Bitmap *types;
219 } nsec3;
74b2466e
LP
220 };
221};
222
faa133f3
LP
223static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
224 if (_unlikely_(!key))
225 return NULL;
226
227 if (key->_name)
228 return key->_name;
229
230 return (char*) key + sizeof(DnsResourceKey);
231}
74b2466e 232
faa133f3 233DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
36d9205d 234DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
801ad6a6 235int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
faa133f3
LP
236DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
237DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
238DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
28b9b764 239bool dns_resource_key_is_address(const DnsResourceKey *key);
faa133f3 240int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
105e1512 241int dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain);
5d27351f 242int dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain);
547973de 243int dns_resource_key_match_soa(const DnsResourceKey *key, const DnsResourceKey *soa);
2d4c5cbc 244int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
faa133f3 245DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fd 246
7778dfff
DM
247static inline bool dns_key_is_shared(const DnsResourceKey *key) {
248 return IN_SET(key->type, DNS_TYPE_PTR);
249}
250
faa133f3 251DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
8bf52d3d 252DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
74b2466e
LP
253DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
254DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
623a4c97 255int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
78c6a153 256int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
322345fd 257int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
7b50eb2e 258const char* dns_resource_record_to_string(DnsResourceRecord *rr);
faa133f3 259DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fd 260
a8812dd7
LP
261int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
262
2001c805
LP
263DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
264bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
265
d5099efc 266extern const struct hash_ops dns_resource_key_hash_ops;
8730bccf
LP
267
268const char* dnssec_algorithm_to_string(int i) _const_;
269int dnssec_algorithm_from_string(const char *s) _pure_;
270
271const char *dnssec_digest_to_string(int i) _const_;
272int dnssec_digest_from_string(const char *s) _pure_;