]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-rr.h
resolved: add comments referencing various RFCs to various places
[thirdparty/systemd.git] / src / resolve / resolved-dns-rr.h
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
24 #include <netinet/in.h>
25
26 #include "bitmap.h"
27 #include "dns-type.h"
28 #include "hashmap.h"
29 #include "in-addr-util.h"
30 #include "list.h"
31
32 typedef struct DnsResourceKey DnsResourceKey;
33 typedef struct DnsResourceRecord DnsResourceRecord;
34 typedef struct DnsTxtItem DnsTxtItem;
35
36 /* DNSKEY RR flags */
37 #define DNSKEY_FLAG_ZONE_KEY (UINT16_C(1) << 8)
38 #define DNSKEY_FLAG_SEP (UINT16_C(1) << 0)
39
40 /* mDNS RR flags */
41 #define MDNS_RR_CACHE_FLUSH (UINT16_C(1) << 15)
42
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 */
46 enum {
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_ECC_GOST = 12, /* RFC 5933 */
57 DNSSEC_ALGORITHM_ECDSAP256SHA256 = 13, /* RFC 6605 */
58 DNSSEC_ALGORITHM_ECDSAP384SHA384 = 14, /* RFC 6605 */
59 DNSSEC_ALGORITHM_INDIRECT = 252,
60 DNSSEC_ALGORITHM_PRIVATEDNS,
61 DNSSEC_ALGORITHM_PRIVATEOID,
62 _DNSSEC_ALGORITHM_MAX_DEFINED
63 };
64
65 /* DNSSEC digest identifiers, see
66 * https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
67 enum {
68 DNSSEC_DIGEST_SHA1 = 1,
69 DNSSEC_DIGEST_SHA256 = 2, /* RFC 4509 */
70 DNSSEC_DIGEST_GOST_R_34_11_94 = 3, /* RFC 5933 */
71 DNSSEC_DIGEST_SHA384 = 4, /* RFC 6605 */
72 _DNSSEC_DIGEST_MAX_DEFINED
73 };
74
75 struct DnsResourceKey {
76 unsigned n_ref;
77 uint16_t class, type;
78 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
79 };
80
81 /* Creates a temporary resource key. This is only useful to quickly
82 * look up something, without allocating a full DnsResourceKey object
83 * for it. Note that it is not OK to take references to this kind of
84 * resource key object. */
85 #define DNS_RESOURCE_KEY_CONST(c, t, n) \
86 ((DnsResourceKey) { \
87 .n_ref = (unsigned) -1, \
88 .class = c, \
89 .type = t, \
90 ._name = (char*) n, \
91 })
92
93
94 struct DnsTxtItem {
95 size_t length;
96 LIST_FIELDS(DnsTxtItem, items);
97 uint8_t data[];
98 };
99
100 struct DnsResourceRecord {
101 unsigned n_ref;
102 DnsResourceKey *key;
103 char *to_string;
104 uint32_t ttl;
105 usec_t expiry; /* RRSIG signature expiry */
106 bool unparseable:1;
107 bool wire_format_canonical:1;
108 void *wire_format;
109 size_t wire_format_size;
110 size_t wire_format_rdata_offset;
111 union {
112 struct {
113 void *data;
114 size_t size;
115 } generic, opt;
116
117 struct {
118 uint16_t priority;
119 uint16_t weight;
120 uint16_t port;
121 char *name;
122 } srv;
123
124 struct {
125 char *name;
126 } ptr, ns, cname, dname;
127
128 struct {
129 char *cpu;
130 char *os;
131 } hinfo;
132
133 struct {
134 DnsTxtItem *items;
135 } txt, spf;
136
137 struct {
138 struct in_addr in_addr;
139 } a;
140
141 struct {
142 struct in6_addr in6_addr;
143 } aaaa;
144
145 struct {
146 char *mname;
147 char *rname;
148 uint32_t serial;
149 uint32_t refresh;
150 uint32_t retry;
151 uint32_t expire;
152 uint32_t minimum;
153 } soa;
154
155 struct {
156 uint16_t priority;
157 char *exchange;
158 } mx;
159
160 /* https://tools.ietf.org/html/rfc1876 */
161 struct {
162 uint8_t version;
163 uint8_t size;
164 uint8_t horiz_pre;
165 uint8_t vert_pre;
166 uint32_t latitude;
167 uint32_t longitude;
168 uint32_t altitude;
169 } loc;
170
171 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
172 struct {
173 uint8_t algorithm;
174 uint8_t fptype;
175 void *fingerprint;
176 size_t fingerprint_size;
177 } sshfp;
178
179 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
180 struct {
181 uint16_t flags;
182 uint8_t protocol;
183 uint8_t algorithm;
184 void* key;
185 size_t key_size;
186 } dnskey;
187
188 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
189 struct {
190 uint16_t type_covered;
191 uint8_t algorithm;
192 uint8_t labels;
193 uint32_t original_ttl;
194 uint32_t expiration;
195 uint32_t inception;
196 uint16_t key_tag;
197 char *signer;
198 void *signature;
199 size_t signature_size;
200 } rrsig;
201
202 /* https://tools.ietf.org/html/rfc4034#section-4.1 */
203 struct {
204 char *next_domain_name;
205 Bitmap *types;
206 } nsec;
207
208 /* https://tools.ietf.org/html/rfc4034#section-5.1 */
209 struct {
210 uint16_t key_tag;
211 uint8_t algorithm;
212 uint8_t digest_type;
213 void *digest;
214 size_t digest_size;
215 } ds;
216
217 struct {
218 uint8_t algorithm;
219 uint8_t flags;
220 uint16_t iterations;
221 void *salt;
222 size_t salt_size;
223 void *next_hashed_name;
224 size_t next_hashed_name_size;
225 Bitmap *types;
226 } nsec3;
227 };
228 };
229
230 static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
231 if (_unlikely_(!key))
232 return NULL;
233
234 if (key->_name)
235 return key->_name;
236
237 return (char*) key + sizeof(DnsResourceKey);
238 }
239
240 DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
241 DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
242 int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
243 DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
244 DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
245 DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
246 bool dns_resource_key_is_address(const DnsResourceKey *key);
247 int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
248 int dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain);
249 int dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain);
250 int dns_resource_key_match_soa(const DnsResourceKey *key, const DnsResourceKey *soa);
251 int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
252 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
253
254 static inline bool dns_key_is_shared(const DnsResourceKey *key) {
255 return IN_SET(key->type, DNS_TYPE_PTR);
256 }
257
258 DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
259 DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
260 DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
261 DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
262 int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
263 int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
264 int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
265 const char* dns_resource_record_to_string(DnsResourceRecord *rr);
266 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
267
268 int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
269
270 DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
271 bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
272
273 extern const struct hash_ops dns_resource_key_hash_ops;
274
275 const char* dnssec_algorithm_to_string(int i) _const_;
276 int dnssec_algorithm_from_string(const char *s) _pure_;
277
278 const char *dnssec_digest_to_string(int i) _const_;
279 int dnssec_digest_from_string(const char *s) _pure_;