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