]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-rr.h
resolved: include GOST in list of DNSSEC algorithms
[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
74b2466e 75struct DnsResourceKey {
faa133f3
LP
76 unsigned n_ref;
77 uint16_t class, type;
78 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
74b2466e
LP
79};
80
1b4f6e79
LP
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
2001c805
LP
94struct DnsTxtItem {
95 size_t length;
96 LIST_FIELDS(DnsTxtItem, items);
97 uint8_t data[];
98};
99
74b2466e
LP
100struct DnsResourceRecord {
101 unsigned n_ref;
faa133f3 102 DnsResourceKey *key;
7b50eb2e 103 char *to_string;
74b2466e 104 uint32_t ttl;
ee3d6aff 105 usec_t expiry; /* RRSIG signature expiry */
a8812dd7
LP
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;
74b2466e
LP
111 union {
112 struct {
113 void *data;
f5430a3e 114 size_t size;
d75acfb0 115 } generic, opt;
74b2466e 116
9c92ce6d
LP
117 struct {
118 uint16_t priority;
119 uint16_t weight;
120 uint16_t port;
121 char *name;
122 } srv;
74b2466e
LP
123
124 struct {
125 char *name;
8ac4e9e1 126 } ptr, ns, cname, dname;
74b2466e
LP
127
128 struct {
129 char *cpu;
130 char *os;
131 } hinfo;
132
2e276efc 133 struct {
2001c805 134 DnsTxtItem *items;
c0eb11cf 135 } txt, spf;
74b2466e
LP
136
137 struct {
138 struct in_addr in_addr;
139 } a;
140
141 struct {
142 struct in6_addr in6_addr;
143 } aaaa;
7e8e0422
LP
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;
946c7094
ZJS
154
155 struct {
156 uint16_t priority;
157 char *exchange;
158 } mx;
0dae31d4
ZJS
159
160 struct {
161 uint8_t version;
162 uint8_t size;
163 uint8_t horiz_pre;
164 uint8_t vert_pre;
165 uint32_t latitude;
166 uint32_t longitude;
167 uint32_t altitude;
168 } loc;
42cc2eeb 169
abf126a3
TG
170 struct {
171 uint16_t key_tag;
172 uint8_t algorithm;
173 uint8_t digest_type;
174 void *digest;
175 size_t digest_size;
176 } ds;
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
TG
214
215 struct {
216 uint8_t algorithm;
217 uint8_t flags;
218 uint16_t iterations;
219 void *salt;
220 size_t salt_size;
221 void *next_hashed_name;
222 size_t next_hashed_name_size;
223 Bitmap *types;
224 } nsec3;
74b2466e
LP
225 };
226};
227
faa133f3
LP
228static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
229 if (_unlikely_(!key))
230 return NULL;
231
232 if (key->_name)
233 return key->_name;
234
235 return (char*) key + sizeof(DnsResourceKey);
236}
74b2466e 237
faa133f3 238DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
36d9205d 239DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
801ad6a6 240int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
faa133f3
LP
241DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
242DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
243DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
28b9b764 244bool dns_resource_key_is_address(const DnsResourceKey *key);
faa133f3 245int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
105e1512 246int dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain);
5d27351f 247int dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain);
547973de 248int dns_resource_key_match_soa(const DnsResourceKey *key, const DnsResourceKey *soa);
2d4c5cbc 249int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
faa133f3 250DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fd 251
7778dfff
DM
252static inline bool dns_key_is_shared(const DnsResourceKey *key) {
253 return IN_SET(key->type, DNS_TYPE_PTR);
254}
255
faa133f3 256DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
8bf52d3d 257DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
74b2466e
LP
258DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
259DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
623a4c97 260int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
78c6a153 261int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
322345fd 262int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
7b50eb2e 263const char* dns_resource_record_to_string(DnsResourceRecord *rr);
faa133f3 264DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fd 265
a8812dd7
LP
266int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
267
2001c805
LP
268DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
269bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
270
d5099efc 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_;