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
44 struct DnsResourceKey
{
47 char *_name
; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
52 LIST_FIELDS(DnsTxtItem
, items
);
56 struct DnsResourceRecord
{
76 } ptr
, ns
, cname
, dname
;
88 struct in_addr in_addr
;
92 struct in6_addr in6_addr
;
128 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
133 size_t fingerprint_size
;
136 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
138 bool zone_key_flag
:1;
145 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
147 uint16_t type_covered
;
150 uint32_t original_ttl
;
156 size_t signature_size
;
160 char *next_domain_name
;
170 void *next_hashed_name
;
171 size_t next_hashed_name_size
;
177 static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey
*key
) {
178 if (_unlikely_(!key
))
184 return (char*) key
+ sizeof(DnsResourceKey
);
187 DnsResourceKey
* dns_resource_key_new(uint16_t class, uint16_t type
, const char *name
);
188 DnsResourceKey
* dns_resource_key_new_cname(const DnsResourceKey
*key
);
189 DnsResourceKey
* dns_resource_key_new_dname(const DnsResourceKey
*key
);
190 DnsResourceKey
* dns_resource_key_new_redirect(const DnsResourceKey
*key
, const DnsResourceRecord
*cname
);
191 int dns_resource_key_new_append_suffix(DnsResourceKey
**ret
, DnsResourceKey
*key
, char *name
);
192 DnsResourceKey
* dns_resource_key_new_consume(uint16_t class, uint16_t type
, char *name
);
193 DnsResourceKey
* dns_resource_key_ref(DnsResourceKey
*key
);
194 DnsResourceKey
* dns_resource_key_unref(DnsResourceKey
*key
);
195 int dns_resource_key_equal(const DnsResourceKey
*a
, const DnsResourceKey
*b
);
196 int dns_resource_key_match_rr(const DnsResourceKey
*key
, const DnsResourceRecord
*rr
, const char *search_domain
);
197 int dns_resource_key_match_cname(const DnsResourceKey
*key
, const DnsResourceRecord
*rr
, const char *search_domain
);
198 int dns_resource_key_to_string(const DnsResourceKey
*key
, char **ret
);
199 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey
*, dns_resource_key_unref
);
201 DnsResourceRecord
* dns_resource_record_new(DnsResourceKey
*key
);
202 DnsResourceRecord
* dns_resource_record_new_full(uint16_t class, uint16_t type
, const char *name
);
203 DnsResourceRecord
* dns_resource_record_ref(DnsResourceRecord
*rr
);
204 DnsResourceRecord
* dns_resource_record_unref(DnsResourceRecord
*rr
);
205 int dns_resource_record_new_reverse(DnsResourceRecord
**ret
, int family
, const union in_addr_union
*address
, const char *name
);
206 int dns_resource_record_new_address(DnsResourceRecord
**ret
, int family
, const union in_addr_union
*address
, const char *name
);
207 int dns_resource_record_equal(const DnsResourceRecord
*a
, const DnsResourceRecord
*b
);
208 int dns_resource_record_to_string(const DnsResourceRecord
*rr
, char **ret
);
209 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord
*, dns_resource_record_unref
);
211 DnsTxtItem
*dns_txt_item_free_all(DnsTxtItem
*i
);
212 bool dns_txt_item_equal(DnsTxtItem
*a
, DnsTxtItem
*b
);
214 const char *dns_class_to_string(uint16_t type
);
215 int dns_class_from_string(const char *name
, uint16_t *class);
217 extern const struct hash_ops dns_resource_key_hash_ops
;