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/>.
25 #include <netinet/in.h>
29 #include "in-addr-util.h"
31 typedef struct DnsResourceKey DnsResourceKey;
32 typedef struct DnsResourceRecord DnsResourceRecord;
34 /* DNS record classes, see RFC 1035 */
40 /* DNS record types, see RFC 1035 */
45 DNS_TYPE_CNAME = 0x05,
48 DNS_TYPE_HINFO = 0x0D,
53 DNS_TYPE_DNAME = 0x27,
54 DNS_TYPE_SSHFP = 0x2C,
58 DNS_TYPE_OPT = 0x29, /* EDNS0 option */
65 struct DnsResourceKey {
68 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
71 struct DnsResourceRecord {
82 /* uint16_t priority; */
83 /* uint16_t weight; */
102 struct in_addr in_addr;
106 struct in6_addr in6_addr;
121 static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
122 if (_unlikely_(!key))
128 return (char*) key + sizeof(DnsResourceKey);
131 DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
132 DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
133 DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
134 DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
135 int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
136 int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr);
137 int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr);
138 unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]);
139 int dns_resource_key_compare_func(const void *a, const void *b);
140 int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
141 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
143 DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
144 DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
145 DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
146 DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
147 int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
148 int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
149 int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
150 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
152 const char *dns_type_to_string(uint16_t type);
153 int dns_type_from_string(const char *name, uint16_t *type);
155 const char *dns_class_to_string(uint16_t type);
156 int dns_class_from_string(const char *name, uint16_t *class);