]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-rr.h
Merge pull request #586 from teg/resolved-rrs-3
[thirdparty/systemd.git] / src / resolve / resolved-dns-rr.h
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
24 #include <netinet/in.h>
25
26 #include "hashmap.h"
27 #include "in-addr-util.h"
28 #include "dns-type.h"
29
30 typedef struct DnsResourceKey DnsResourceKey;
31 typedef struct DnsResourceRecord DnsResourceRecord;
32
33 /* DNS record classes, see RFC 1035 */
34 enum {
35 DNS_CLASS_IN = 0x01,
36 DNS_CLASS_ANY = 0xFF,
37 _DNS_CLASS_MAX,
38 _DNS_CLASS_INVALID = -1
39 };
40
41 struct DnsResourceKey {
42 unsigned n_ref;
43 uint16_t class, type;
44 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
45 };
46
47 struct DnsResourceRecord {
48 unsigned n_ref;
49 DnsResourceKey *key;
50 uint32_t ttl;
51 bool unparseable;
52 union {
53 struct {
54 void *data;
55 uint16_t size;
56 } generic;
57
58 struct {
59 uint16_t priority;
60 uint16_t weight;
61 uint16_t port;
62 char *name;
63 } srv;
64
65 struct {
66 char *name;
67 } ptr, ns, cname, dname;
68
69 struct {
70 char *cpu;
71 char *os;
72 } hinfo;
73
74 struct {
75 char **strings;
76 } txt, spf;
77
78 struct {
79 struct in_addr in_addr;
80 } a;
81
82 struct {
83 struct in6_addr in6_addr;
84 } aaaa;
85
86 struct {
87 char *mname;
88 char *rname;
89 uint32_t serial;
90 uint32_t refresh;
91 uint32_t retry;
92 uint32_t expire;
93 uint32_t minimum;
94 } soa;
95
96 struct {
97 uint16_t priority;
98 char *exchange;
99 } mx;
100
101 struct {
102 uint8_t version;
103 uint8_t size;
104 uint8_t horiz_pre;
105 uint8_t vert_pre;
106 uint32_t latitude;
107 uint32_t longitude;
108 uint32_t altitude;
109 } loc;
110
111 struct {
112 uint16_t key_tag;
113 uint8_t algorithm;
114 uint8_t digest_type;
115 void *digest;
116 size_t digest_size;
117 } ds;
118
119 struct {
120 uint8_t algorithm;
121 uint8_t fptype;
122 void *key;
123 size_t key_size;
124 } sshfp;
125
126 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
127 struct {
128 bool zone_key_flag:1;
129 bool sep_flag:1;
130 uint8_t algorithm;
131 void* key;
132 size_t key_size;
133 } dnskey;
134
135 /* http://tools.ietf.org/html/rfc4034#section-3.1 */
136 struct {
137 uint16_t type_covered;
138 uint8_t algorithm;
139 uint8_t labels;
140 uint32_t original_ttl;
141 uint32_t expiration;
142 uint32_t inception;
143 uint16_t key_tag;
144 char *signer;
145 void *signature;
146 size_t signature_size;
147 } rrsig;
148 };
149 };
150
151 static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
152 if (_unlikely_(!key))
153 return NULL;
154
155 if (key->_name)
156 return key->_name;
157
158 return (char*) key + sizeof(DnsResourceKey);
159 }
160
161 DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
162 DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
163 DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
164 DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
165 int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
166 int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr);
167 int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr);
168 int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
169 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
170
171 DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
172 DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
173 DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
174 DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
175 int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
176 int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
177 int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
178 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
179
180 const char *dns_class_to_string(uint16_t type);
181 int dns_class_from_string(const char *name, uint16_t *class);
182
183 extern const struct hash_ops dns_resource_key_hash_ops;