]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-rr.h
resolved: implement query coalescing
[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
LP
35
36/* DNS record classes, see RFC 1035 */
37enum {
38 DNS_CLASS_IN = 0x01,
322345fd 39 DNS_CLASS_ANY = 0xFF,
b93312f5
ZJS
40 _DNS_CLASS_MAX,
41 _DNS_CLASS_INVALID = -1
74b2466e
LP
42};
43
8730bccf
LP
44/* DNSKEY RR flags */
45#define DNSKEY_FLAG_ZONE_KEY (UINT16_C(1) << 8)
46#define DNSKEY_FLAG_SEP (UINT16_C(1) << 0)
47
23502de3
DM
48/* mDNS RR flags */
49#define MDNS_RR_CACHE_FLUSH (UINT16_C(1) << 15)
50
8730bccf
LP
51/* DNSSEC algorithm identifiers, see
52 * http://tools.ietf.org/html/rfc4034#appendix-A.1 and
53 * https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
54enum {
55 DNSSEC_ALGORITHM_RSAMD5 = 1,
56 DNSSEC_ALGORITHM_DH,
57 DNSSEC_ALGORITHM_DSA,
58 DNSSEC_ALGORITHM_ECC,
59 DNSSEC_ALGORITHM_RSASHA1,
60 DNSSEC_ALGORITHM_DSA_NSEC3_SHA1,
61 DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1,
62 DNSSEC_ALGORITHM_RSASHA256 = 8, /* RFC 5702 */
63 DNSSEC_ALGORITHM_RSASHA512 = 10, /* RFC 5702 */
64 DNSSEC_ALGORITHM_INDIRECT = 252,
65 DNSSEC_ALGORITHM_PRIVATEDNS,
66 DNSSEC_ALGORITHM_PRIVATEOID,
67 _DNSSEC_ALGORITHM_MAX_DEFINED
68};
69
70/* DNSSEC digest identifiers, see
71 * https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
72enum {
73 DNSSEC_DIGEST_SHA1 = 1,
74 DNSSEC_DIGEST_SHA256 = 2,
75 _DNSSEC_DIGEST_MAX_DEFINED
76};
77
74b2466e 78struct DnsResourceKey {
faa133f3
LP
79 unsigned n_ref;
80 uint16_t class, type;
81 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
23502de3 82 bool cache_flush:1;
74b2466e
LP
83};
84
1b4f6e79
LP
85/* Creates a temporary resource key. This is only useful to quickly
86 * look up something, without allocating a full DnsResourceKey object
87 * for it. Note that it is not OK to take references to this kind of
88 * resource key object. */
89#define DNS_RESOURCE_KEY_CONST(c, t, n) \
90 ((DnsResourceKey) { \
91 .n_ref = (unsigned) -1, \
92 .class = c, \
93 .type = t, \
94 ._name = (char*) n, \
95 })
96
97
2001c805
LP
98struct DnsTxtItem {
99 size_t length;
100 LIST_FIELDS(DnsTxtItem, items);
101 uint8_t data[];
102};
103
74b2466e
LP
104struct DnsResourceRecord {
105 unsigned n_ref;
faa133f3 106 DnsResourceKey *key;
74b2466e 107 uint32_t ttl;
a8812dd7
LP
108 bool unparseable:1;
109 bool wire_format_canonical:1;
110 void *wire_format;
111 size_t wire_format_size;
112 size_t wire_format_rdata_offset;
74b2466e
LP
113 union {
114 struct {
115 void *data;
f5430a3e 116 size_t size;
74b2466e
LP
117 } generic;
118
9c92ce6d
LP
119 struct {
120 uint16_t priority;
121 uint16_t weight;
122 uint16_t port;
123 char *name;
124 } srv;
74b2466e
LP
125
126 struct {
127 char *name;
8ac4e9e1 128 } ptr, ns, cname, dname;
74b2466e
LP
129
130 struct {
131 char *cpu;
132 char *os;
133 } hinfo;
134
2e276efc 135 struct {
2001c805 136 DnsTxtItem *items;
c0eb11cf 137 } txt, spf;
74b2466e
LP
138
139 struct {
140 struct in_addr in_addr;
141 } a;
142
143 struct {
144 struct in6_addr in6_addr;
145 } aaaa;
7e8e0422
LP
146
147 struct {
148 char *mname;
149 char *rname;
150 uint32_t serial;
151 uint32_t refresh;
152 uint32_t retry;
153 uint32_t expire;
154 uint32_t minimum;
155 } soa;
946c7094
ZJS
156
157 struct {
158 uint16_t priority;
159 char *exchange;
160 } mx;
0dae31d4
ZJS
161
162 struct {
163 uint8_t version;
164 uint8_t size;
165 uint8_t horiz_pre;
166 uint8_t vert_pre;
167 uint32_t latitude;
168 uint32_t longitude;
169 uint32_t altitude;
170 } loc;
42cc2eeb 171
abf126a3
TG
172 struct {
173 uint16_t key_tag;
174 uint8_t algorithm;
175 uint8_t digest_type;
176 void *digest;
177 size_t digest_size;
178 } ds;
179
549c1a25 180 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
42cc2eeb
LP
181 struct {
182 uint8_t algorithm;
183 uint8_t fptype;
549c1a25
TG
184 void *fingerprint;
185 size_t fingerprint_size;
42cc2eeb 186 } sshfp;
8db0d2f5
ZJS
187
188 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
189 struct {
f91dc240
LP
190 uint16_t flags;
191 uint8_t protocol;
8db0d2f5
ZJS
192 uint8_t algorithm;
193 void* key;
194 size_t key_size;
195 } dnskey;
151226ab
ZJS
196
197 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
198 struct {
199 uint16_t type_covered;
200 uint8_t algorithm;
201 uint8_t labels;
202 uint32_t original_ttl;
203 uint32_t expiration;
204 uint32_t inception;
205 uint16_t key_tag;
206 char *signer;
207 void *signature;
208 size_t signature_size;
209 } rrsig;
50f1e641 210
9ead3519 211 /* https://tools.ietf.org/html/rfc4034#section-4.1 */
50f1e641
TG
212 struct {
213 char *next_domain_name;
214 Bitmap *types;
215 } nsec;
5d45a880
TG
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;
74b2466e
LP
227 };
228};
229
faa133f3
LP
230static 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}
74b2466e 239
faa133f3 240DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
36d9205d 241DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
801ad6a6 242int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
faa133f3
LP
243DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
244DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
245DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
28b9b764 246bool dns_resource_key_is_address(const DnsResourceKey *key);
faa133f3 247int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
801ad6a6
LP
248int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr, const char *search_domain);
249int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr, const char *search_domain);
2d4c5cbc 250int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
faa133f3 251DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fd 252
faa133f3 253DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
8bf52d3d 254DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
74b2466e
LP
255DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
256DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
623a4c97 257int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
78c6a153 258int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
322345fd 259int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
2d4c5cbc 260int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
faa133f3 261DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fd 262
a8812dd7
LP
263int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
264
2001c805
LP
265DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
266bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
267
322345fd 268const char *dns_class_to_string(uint16_t type);
2d4c5cbc 269int dns_class_from_string(const char *name, uint16_t *class);
d5099efc
MS
270
271extern const struct hash_ops dns_resource_key_hash_ops;
8730bccf
LP
272
273const char* dnssec_algorithm_to_string(int i) _const_;
274int dnssec_algorithm_from_string(const char *s) _pure_;
275
276const char *dnssec_digest_to_string(int i) _const_;
277int dnssec_digest_from_string(const char *s) _pure_;