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