1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2014 Lennart Poettering
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.
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.
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/>.
24 #include <netinet/in.h>
29 #include "in-addr-util.h"
32 typedef struct DnsResourceKey DnsResourceKey
;
33 typedef struct DnsResourceRecord DnsResourceRecord
;
34 typedef struct DnsTxtItem DnsTxtItem
;
36 /* DNS record classes, see RFC 1035 */
41 _DNS_CLASS_INVALID
= -1
45 #define DNSKEY_FLAG_ZONE_KEY (UINT16_C(1) << 8)
46 #define DNSKEY_FLAG_SEP (UINT16_C(1) << 0)
49 #define MDNS_RR_CACHE_FLUSH (UINT16_C(1) << 15)
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 */
55 DNSSEC_ALGORITHM_RSAMD5
= 1,
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
70 /* DNSSEC digest identifiers, see
71 * https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
73 DNSSEC_DIGEST_SHA1
= 1,
74 DNSSEC_DIGEST_SHA256
= 2,
75 _DNSSEC_DIGEST_MAX_DEFINED
78 struct DnsResourceKey
{
81 char *_name
; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
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) \
91 .n_ref = (unsigned) -1, \
100 LIST_FIELDS(DnsTxtItem
, items
);
104 struct DnsResourceRecord
{
109 bool wire_format_canonical
:1;
111 size_t wire_format_size
;
112 size_t wire_format_rdata_offset
;
128 } ptr
, ns
, cname
, dname
;
140 struct in_addr in_addr
;
144 struct in6_addr in6_addr
;
180 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
185 size_t fingerprint_size
;
188 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
197 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
199 uint16_t type_covered
;
202 uint32_t original_ttl
;
208 size_t signature_size
;
211 /* https://tools.ietf.org/html/rfc4034#section-4.1 */
213 char *next_domain_name
;
223 void *next_hashed_name
;
224 size_t next_hashed_name_size
;
230 static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey
*key
) {
231 if (_unlikely_(!key
))
237 return (char*) key
+ sizeof(DnsResourceKey
);
240 DnsResourceKey
* dns_resource_key_new(uint16_t class, uint16_t type
, const char *name
);
241 DnsResourceKey
* dns_resource_key_new_redirect(const DnsResourceKey
*key
, const DnsResourceRecord
*cname
);
242 int dns_resource_key_new_append_suffix(DnsResourceKey
**ret
, DnsResourceKey
*key
, char *name
);
243 DnsResourceKey
* dns_resource_key_new_consume(uint16_t class, uint16_t type
, char *name
);
244 DnsResourceKey
* dns_resource_key_ref(DnsResourceKey
*key
);
245 DnsResourceKey
* dns_resource_key_unref(DnsResourceKey
*key
);
246 bool dns_resource_key_is_address(const DnsResourceKey
*key
);
247 int dns_resource_key_equal(const DnsResourceKey
*a
, const DnsResourceKey
*b
);
248 int dns_resource_key_match_rr(const DnsResourceKey
*key
, const DnsResourceRecord
*rr
, const char *search_domain
);
249 int dns_resource_key_match_cname(const DnsResourceKey
*key
, const DnsResourceRecord
*rr
, const char *search_domain
);
250 int dns_resource_key_to_string(const DnsResourceKey
*key
, char **ret
);
251 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey
*, dns_resource_key_unref
);
253 static inline bool dns_key_is_shared(const DnsResourceKey
*key
) {
254 return IN_SET(key
->type
, DNS_TYPE_PTR
);
257 DnsResourceRecord
* dns_resource_record_new(DnsResourceKey
*key
);
258 DnsResourceRecord
* dns_resource_record_new_full(uint16_t class, uint16_t type
, const char *name
);
259 DnsResourceRecord
* dns_resource_record_ref(DnsResourceRecord
*rr
);
260 DnsResourceRecord
* dns_resource_record_unref(DnsResourceRecord
*rr
);
261 int dns_resource_record_new_reverse(DnsResourceRecord
**ret
, int family
, const union in_addr_union
*address
, const char *name
);
262 int dns_resource_record_new_address(DnsResourceRecord
**ret
, int family
, const union in_addr_union
*address
, const char *name
);
263 int dns_resource_record_equal(const DnsResourceRecord
*a
, const DnsResourceRecord
*b
);
264 int dns_resource_record_to_string(const DnsResourceRecord
*rr
, char **ret
);
265 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord
*, dns_resource_record_unref
);
267 int dns_resource_record_to_wire_format(DnsResourceRecord
*rr
, bool canonical
);
269 DnsTxtItem
*dns_txt_item_free_all(DnsTxtItem
*i
);
270 bool dns_txt_item_equal(DnsTxtItem
*a
, DnsTxtItem
*b
);
272 const char *dns_class_to_string(uint16_t type
);
273 int dns_class_from_string(const char *name
, uint16_t *class);
275 extern const struct hash_ops dns_resource_key_hash_ops
;
277 const char* dnssec_algorithm_to_string(int i
) _const_
;
278 int dnssec_algorithm_from_string(const char *s
) _pure_
;
280 const char *dnssec_digest_to_string(int i
) _const_
;
281 int dnssec_digest_from_string(const char *s
) _pure_
;