]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-rr.h
resolved: make expiration error recognizable
[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
48/* DNSSEC algorithm identifiers, see
49 * http://tools.ietf.org/html/rfc4034#appendix-A.1 and
50 * https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
51enum {
52 DNSSEC_ALGORITHM_RSAMD5 = 1,
53 DNSSEC_ALGORITHM_DH,
54 DNSSEC_ALGORITHM_DSA,
55 DNSSEC_ALGORITHM_ECC,
56 DNSSEC_ALGORITHM_RSASHA1,
57 DNSSEC_ALGORITHM_DSA_NSEC3_SHA1,
58 DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1,
59 DNSSEC_ALGORITHM_RSASHA256 = 8, /* RFC 5702 */
60 DNSSEC_ALGORITHM_RSASHA512 = 10, /* RFC 5702 */
61 DNSSEC_ALGORITHM_INDIRECT = 252,
62 DNSSEC_ALGORITHM_PRIVATEDNS,
63 DNSSEC_ALGORITHM_PRIVATEOID,
64 _DNSSEC_ALGORITHM_MAX_DEFINED
65};
66
67/* DNSSEC digest identifiers, see
68 * https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
69enum {
70 DNSSEC_DIGEST_SHA1 = 1,
71 DNSSEC_DIGEST_SHA256 = 2,
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
2001c805
LP
81struct DnsTxtItem {
82 size_t length;
83 LIST_FIELDS(DnsTxtItem, items);
84 uint8_t data[];
85};
86
74b2466e
LP
87struct DnsResourceRecord {
88 unsigned n_ref;
faa133f3 89 DnsResourceKey *key;
74b2466e 90 uint32_t ttl;
a8812dd7
LP
91 bool unparseable:1;
92 bool wire_format_canonical:1;
93 void *wire_format;
94 size_t wire_format_size;
95 size_t wire_format_rdata_offset;
74b2466e
LP
96 union {
97 struct {
98 void *data;
f5430a3e 99 size_t size;
74b2466e
LP
100 } generic;
101
9c92ce6d
LP
102 struct {
103 uint16_t priority;
104 uint16_t weight;
105 uint16_t port;
106 char *name;
107 } srv;
74b2466e
LP
108
109 struct {
110 char *name;
8ac4e9e1 111 } ptr, ns, cname, dname;
74b2466e
LP
112
113 struct {
114 char *cpu;
115 char *os;
116 } hinfo;
117
2e276efc 118 struct {
2001c805 119 DnsTxtItem *items;
c0eb11cf 120 } txt, spf;
74b2466e
LP
121
122 struct {
123 struct in_addr in_addr;
124 } a;
125
126 struct {
127 struct in6_addr in6_addr;
128 } aaaa;
7e8e0422
LP
129
130 struct {
131 char *mname;
132 char *rname;
133 uint32_t serial;
134 uint32_t refresh;
135 uint32_t retry;
136 uint32_t expire;
137 uint32_t minimum;
138 } soa;
946c7094
ZJS
139
140 struct {
141 uint16_t priority;
142 char *exchange;
143 } mx;
0dae31d4
ZJS
144
145 struct {
146 uint8_t version;
147 uint8_t size;
148 uint8_t horiz_pre;
149 uint8_t vert_pre;
150 uint32_t latitude;
151 uint32_t longitude;
152 uint32_t altitude;
153 } loc;
42cc2eeb 154
abf126a3
TG
155 struct {
156 uint16_t key_tag;
157 uint8_t algorithm;
158 uint8_t digest_type;
159 void *digest;
160 size_t digest_size;
161 } ds;
162
549c1a25 163 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
42cc2eeb
LP
164 struct {
165 uint8_t algorithm;
166 uint8_t fptype;
549c1a25
TG
167 void *fingerprint;
168 size_t fingerprint_size;
42cc2eeb 169 } sshfp;
8db0d2f5
ZJS
170
171 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
172 struct {
f91dc240
LP
173 uint16_t flags;
174 uint8_t protocol;
8db0d2f5
ZJS
175 uint8_t algorithm;
176 void* key;
177 size_t key_size;
178 } dnskey;
151226ab
ZJS
179
180 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
181 struct {
182 uint16_t type_covered;
183 uint8_t algorithm;
184 uint8_t labels;
185 uint32_t original_ttl;
186 uint32_t expiration;
187 uint32_t inception;
188 uint16_t key_tag;
189 char *signer;
190 void *signature;
191 size_t signature_size;
192 } rrsig;
50f1e641 193
9ead3519 194 /* https://tools.ietf.org/html/rfc4034#section-4.1 */
50f1e641
TG
195 struct {
196 char *next_domain_name;
197 Bitmap *types;
198 } nsec;
5d45a880
TG
199
200 struct {
201 uint8_t algorithm;
202 uint8_t flags;
203 uint16_t iterations;
204 void *salt;
205 size_t salt_size;
206 void *next_hashed_name;
207 size_t next_hashed_name_size;
208 Bitmap *types;
209 } nsec3;
74b2466e
LP
210 };
211};
212
faa133f3
LP
213static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
214 if (_unlikely_(!key))
215 return NULL;
216
217 if (key->_name)
218 return key->_name;
219
220 return (char*) key + sizeof(DnsResourceKey);
221}
74b2466e 222
faa133f3 223DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
7c1ff6ac 224DnsResourceKey* dns_resource_key_new_cname(const DnsResourceKey *key);
58db254a 225DnsResourceKey* dns_resource_key_new_dname(const DnsResourceKey *key);
36d9205d 226DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
801ad6a6 227int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
faa133f3
LP
228DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
229DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
230DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
231int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
801ad6a6
LP
232int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr, const char *search_domain);
233int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr, const char *search_domain);
2d4c5cbc 234int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
faa133f3 235DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fd 236
faa133f3 237DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
8bf52d3d 238DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
74b2466e
LP
239DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
240DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
623a4c97 241int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
78c6a153 242int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
322345fd 243int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
2d4c5cbc 244int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
faa133f3 245DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fd 246
a8812dd7
LP
247int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
248
2001c805
LP
249DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
250bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
251
322345fd 252const char *dns_class_to_string(uint16_t type);
2d4c5cbc 253int dns_class_from_string(const char *name, uint16_t *class);
d5099efc
MS
254
255extern const struct hash_ops dns_resource_key_hash_ops;
8730bccf
LP
256
257const char* dnssec_algorithm_to_string(int i) _const_;
258int dnssec_algorithm_from_string(const char *s) _pure_;
259
260const char *dnssec_digest_to_string(int i) _const_;
261int dnssec_digest_from_string(const char *s) _pure_;