]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-rr.h
resolved: print a log message when we ignore an NSEC3 RR with an excessive amount...
[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,
6f717d08
LP
54 DNSSEC_ALGORITHM_RSASHA256 = 8, /* RFC 5702 */
55 DNSSEC_ALGORITHM_RSASHA512 = 10, /* RFC 5702 */
56 DNSSEC_ALGORITHM_ECC_GOST = 12, /* RFC 5933 */
e0240c64
LP
57 DNSSEC_ALGORITHM_ECDSAP256SHA256 = 13, /* RFC 6605 */
58 DNSSEC_ALGORITHM_ECDSAP384SHA384 = 14, /* RFC 6605 */
8730bccf
LP
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 */
67enum {
68 DNSSEC_DIGEST_SHA1 = 1,
6f717d08
LP
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 */
8730bccf
LP
72 _DNSSEC_DIGEST_MAX_DEFINED
73};
74
d15ad742
LP
75/* DNSSEC NSEC3 hash algorithms, see
76 * https://www.iana.org/assignments/dnssec-nsec3-parameters/dnssec-nsec3-parameters.xhtml */
77enum {
78 NSEC3_ALGORITHM_SHA1 = 1,
79 _NSEC3_ALGORITHM_MAX_DEFINED
80};
81
74b2466e 82struct DnsResourceKey {
faa133f3
LP
83 unsigned n_ref;
84 uint16_t class, type;
85 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
74b2466e
LP
86};
87
1b4f6e79
LP
88/* Creates a temporary resource key. This is only useful to quickly
89 * look up something, without allocating a full DnsResourceKey object
90 * for it. Note that it is not OK to take references to this kind of
91 * resource key object. */
92#define DNS_RESOURCE_KEY_CONST(c, t, n) \
93 ((DnsResourceKey) { \
94 .n_ref = (unsigned) -1, \
95 .class = c, \
96 .type = t, \
97 ._name = (char*) n, \
98 })
99
100
2001c805
LP
101struct DnsTxtItem {
102 size_t length;
103 LIST_FIELDS(DnsTxtItem, items);
104 uint8_t data[];
105};
106
74b2466e
LP
107struct DnsResourceRecord {
108 unsigned n_ref;
faa133f3 109 DnsResourceKey *key;
7b50eb2e 110 char *to_string;
74b2466e 111 uint32_t ttl;
ee3d6aff 112 usec_t expiry; /* RRSIG signature expiry */
a8812dd7
LP
113 bool unparseable:1;
114 bool wire_format_canonical:1;
115 void *wire_format;
116 size_t wire_format_size;
117 size_t wire_format_rdata_offset;
74b2466e
LP
118 union {
119 struct {
120 void *data;
f5430a3e 121 size_t size;
d75acfb0 122 } generic, opt;
74b2466e 123
9c92ce6d
LP
124 struct {
125 uint16_t priority;
126 uint16_t weight;
127 uint16_t port;
128 char *name;
129 } srv;
74b2466e
LP
130
131 struct {
132 char *name;
8ac4e9e1 133 } ptr, ns, cname, dname;
74b2466e
LP
134
135 struct {
136 char *cpu;
137 char *os;
138 } hinfo;
139
2e276efc 140 struct {
2001c805 141 DnsTxtItem *items;
c0eb11cf 142 } txt, spf;
74b2466e
LP
143
144 struct {
145 struct in_addr in_addr;
146 } a;
147
148 struct {
149 struct in6_addr in6_addr;
150 } aaaa;
7e8e0422
LP
151
152 struct {
153 char *mname;
154 char *rname;
155 uint32_t serial;
156 uint32_t refresh;
157 uint32_t retry;
158 uint32_t expire;
159 uint32_t minimum;
160 } soa;
946c7094
ZJS
161
162 struct {
163 uint16_t priority;
164 char *exchange;
165 } mx;
0dae31d4 166
6af47493 167 /* https://tools.ietf.org/html/rfc1876 */
0dae31d4
ZJS
168 struct {
169 uint8_t version;
170 uint8_t size;
171 uint8_t horiz_pre;
172 uint8_t vert_pre;
173 uint32_t latitude;
174 uint32_t longitude;
175 uint32_t altitude;
176 } loc;
42cc2eeb 177
549c1a25 178 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
42cc2eeb
LP
179 struct {
180 uint8_t algorithm;
181 uint8_t fptype;
549c1a25
TG
182 void *fingerprint;
183 size_t fingerprint_size;
42cc2eeb 184 } sshfp;
8db0d2f5
ZJS
185
186 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
187 struct {
f91dc240
LP
188 uint16_t flags;
189 uint8_t protocol;
8db0d2f5
ZJS
190 uint8_t algorithm;
191 void* key;
192 size_t key_size;
193 } dnskey;
151226ab
ZJS
194
195 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
196 struct {
197 uint16_t type_covered;
198 uint8_t algorithm;
199 uint8_t labels;
200 uint32_t original_ttl;
201 uint32_t expiration;
202 uint32_t inception;
203 uint16_t key_tag;
204 char *signer;
205 void *signature;
206 size_t signature_size;
207 } rrsig;
50f1e641 208
9ead3519 209 /* https://tools.ietf.org/html/rfc4034#section-4.1 */
50f1e641
TG
210 struct {
211 char *next_domain_name;
212 Bitmap *types;
213 } nsec;
5d45a880 214
6af47493
LP
215 /* https://tools.ietf.org/html/rfc4034#section-5.1 */
216 struct {
217 uint16_t key_tag;
218 uint8_t algorithm;
219 uint8_t digest_type;
220 void *digest;
221 size_t digest_size;
222 } ds;
223
5d45a880
TG
224 struct {
225 uint8_t algorithm;
226 uint8_t flags;
227 uint16_t iterations;
228 void *salt;
229 size_t salt_size;
230 void *next_hashed_name;
231 size_t next_hashed_name_size;
232 Bitmap *types;
233 } nsec3;
74b2466e
LP
234 };
235};
236
faa133f3
LP
237static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
238 if (_unlikely_(!key))
239 return NULL;
240
241 if (key->_name)
242 return key->_name;
243
244 return (char*) key + sizeof(DnsResourceKey);
245}
74b2466e 246
faa133f3 247DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
36d9205d 248DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
801ad6a6 249int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
faa133f3
LP
250DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
251DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
252DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
28b9b764 253bool dns_resource_key_is_address(const DnsResourceKey *key);
faa133f3 254int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
105e1512 255int dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain);
5d27351f 256int dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain);
547973de 257int dns_resource_key_match_soa(const DnsResourceKey *key, const DnsResourceKey *soa);
2d4c5cbc 258int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
faa133f3 259DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fd 260
7778dfff
DM
261static inline bool dns_key_is_shared(const DnsResourceKey *key) {
262 return IN_SET(key->type, DNS_TYPE_PTR);
263}
264
faa133f3 265DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
8bf52d3d 266DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
74b2466e
LP
267DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
268DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
623a4c97 269int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
78c6a153 270int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
322345fd 271int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
7b50eb2e 272const char* dns_resource_record_to_string(DnsResourceRecord *rr);
faa133f3 273DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fd 274
a8812dd7
LP
275int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
276
2001c805
LP
277DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
278bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
279
d5099efc 280extern const struct hash_ops dns_resource_key_hash_ops;
8730bccf 281
8e54f5d9 282int dnssec_algorithm_to_string_alloc(int i, char **ret);
8730bccf
LP
283int dnssec_algorithm_from_string(const char *s) _pure_;
284
8e54f5d9 285int dnssec_digest_to_string_alloc(int i, char **ret);
8730bccf 286int dnssec_digest_from_string(const char *s) _pure_;