]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-rr.h
resolved: add code to map DNSSEC digest types to strings and back
[thirdparty/systemd.git] / src / resolve / resolved-dns-rr.h
CommitLineData
74b2466e
LP
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
74b2466e
LP
24#include <netinet/in.h>
25
50f1e641 26#include "bitmap.h"
71d35b6b 27#include "dns-type.h"
322345fd 28#include "hashmap.h"
623a4c97 29#include "in-addr-util.h"
2001c805 30#include "list.h"
74b2466e
LP
31
32typedef struct DnsResourceKey DnsResourceKey;
33typedef struct DnsResourceRecord DnsResourceRecord;
2001c805 34typedef struct DnsTxtItem DnsTxtItem;
74b2466e
LP
35
36/* DNS record classes, see RFC 1035 */
37enum {
38 DNS_CLASS_IN = 0x01,
322345fd 39 DNS_CLASS_ANY = 0xFF,
b93312f5
ZJS
40 _DNS_CLASS_MAX,
41 _DNS_CLASS_INVALID = -1
74b2466e
LP
42};
43
74b2466e 44struct DnsResourceKey {
faa133f3
LP
45 unsigned n_ref;
46 uint16_t class, type;
47 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
74b2466e
LP
48};
49
2001c805
LP
50struct DnsTxtItem {
51 size_t length;
52 LIST_FIELDS(DnsTxtItem, items);
53 uint8_t data[];
54};
55
74b2466e
LP
56struct DnsResourceRecord {
57 unsigned n_ref;
faa133f3 58 DnsResourceKey *key;
74b2466e 59 uint32_t ttl;
0dae31d4 60 bool unparseable;
74b2466e
LP
61 union {
62 struct {
63 void *data;
f5430a3e 64 size_t size;
74b2466e
LP
65 } generic;
66
9c92ce6d
LP
67 struct {
68 uint16_t priority;
69 uint16_t weight;
70 uint16_t port;
71 char *name;
72 } srv;
74b2466e
LP
73
74 struct {
75 char *name;
8ac4e9e1 76 } ptr, ns, cname, dname;
74b2466e
LP
77
78 struct {
79 char *cpu;
80 char *os;
81 } hinfo;
82
2e276efc 83 struct {
2001c805 84 DnsTxtItem *items;
c0eb11cf 85 } txt, spf;
74b2466e
LP
86
87 struct {
88 struct in_addr in_addr;
89 } a;
90
91 struct {
92 struct in6_addr in6_addr;
93 } aaaa;
7e8e0422
LP
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;
946c7094
ZJS
104
105 struct {
106 uint16_t priority;
107 char *exchange;
108 } mx;
0dae31d4
ZJS
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;
42cc2eeb 119
abf126a3
TG
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
549c1a25 128 /* https://tools.ietf.org/html/rfc4255#section-3.1 */
42cc2eeb
LP
129 struct {
130 uint8_t algorithm;
131 uint8_t fptype;
549c1a25
TG
132 void *fingerprint;
133 size_t fingerprint_size;
42cc2eeb 134 } sshfp;
8db0d2f5
ZJS
135
136 /* http://tools.ietf.org/html/rfc4034#section-2.1 */
137 struct {
f91dc240
LP
138 uint16_t flags;
139 uint8_t protocol;
8db0d2f5
ZJS
140 uint8_t algorithm;
141 void* key;
142 size_t key_size;
143 } dnskey;
151226ab
ZJS
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;
50f1e641 158
9ead3519 159 /* https://tools.ietf.org/html/rfc4034#section-4.1 */
50f1e641
TG
160 struct {
161 char *next_domain_name;
162 Bitmap *types;
163 } nsec;
5d45a880
TG
164
165 struct {
166 uint8_t algorithm;
167 uint8_t flags;
168 uint16_t iterations;
169 void *salt;
170 size_t salt_size;
171 void *next_hashed_name;
172 size_t next_hashed_name_size;
173 Bitmap *types;
174 } nsec3;
74b2466e
LP
175 };
176};
177
faa133f3
LP
178static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
179 if (_unlikely_(!key))
180 return NULL;
181
182 if (key->_name)
183 return key->_name;
184
185 return (char*) key + sizeof(DnsResourceKey);
186}
74b2466e 187
faa133f3 188DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
7c1ff6ac 189DnsResourceKey* dns_resource_key_new_cname(const DnsResourceKey *key);
58db254a 190DnsResourceKey* dns_resource_key_new_dname(const DnsResourceKey *key);
36d9205d 191DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname);
801ad6a6 192int dns_resource_key_new_append_suffix(DnsResourceKey **ret, DnsResourceKey *key, char *name);
faa133f3
LP
193DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
194DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
195DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
196int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
801ad6a6
LP
197int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr, const char *search_domain);
198int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr, const char *search_domain);
2d4c5cbc 199int dns_resource_key_to_string(const DnsResourceKey *key, char **ret);
faa133f3 200DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fd 201
faa133f3 202DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
8bf52d3d 203DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
74b2466e
LP
204DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
205DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
623a4c97 206int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
78c6a153 207int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
322345fd 208int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
2d4c5cbc 209int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
faa133f3 210DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fd 211
2001c805
LP
212DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
213bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
214
322345fd 215const char *dns_class_to_string(uint16_t type);
2d4c5cbc 216int dns_class_from_string(const char *name, uint16_t *class);
d5099efc
MS
217
218extern const struct hash_ops dns_resource_key_hash_ops;