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