packed_rrset.h revision 1.1.1.1.2.2 1 1.1.1.1.2.2 pgoyette /*
2 1.1.1.1.2.2 pgoyette * util/data/packed_rrset.h - data storage for a set of resource records.
3 1.1.1.1.2.2 pgoyette *
4 1.1.1.1.2.2 pgoyette * Copyright (c) 2007, NLnet Labs. All rights reserved.
5 1.1.1.1.2.2 pgoyette *
6 1.1.1.1.2.2 pgoyette * This software is open source.
7 1.1.1.1.2.2 pgoyette *
8 1.1.1.1.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
9 1.1.1.1.2.2 pgoyette * modification, are permitted provided that the following conditions
10 1.1.1.1.2.2 pgoyette * are met:
11 1.1.1.1.2.2 pgoyette *
12 1.1.1.1.2.2 pgoyette * Redistributions of source code must retain the above copyright notice,
13 1.1.1.1.2.2 pgoyette * this list of conditions and the following disclaimer.
14 1.1.1.1.2.2 pgoyette *
15 1.1.1.1.2.2 pgoyette * Redistributions in binary form must reproduce the above copyright notice,
16 1.1.1.1.2.2 pgoyette * this list of conditions and the following disclaimer in the documentation
17 1.1.1.1.2.2 pgoyette * and/or other materials provided with the distribution.
18 1.1.1.1.2.2 pgoyette *
19 1.1.1.1.2.2 pgoyette * Neither the name of the NLNET LABS nor the names of its contributors may
20 1.1.1.1.2.2 pgoyette * be used to endorse or promote products derived from this software without
21 1.1.1.1.2.2 pgoyette * specific prior written permission.
22 1.1.1.1.2.2 pgoyette *
23 1.1.1.1.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 1.1.1.1.2.2 pgoyette * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 1.1.1.1.2.2 pgoyette * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 1.1.1.1.2.2 pgoyette * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 1.1.1.1.2.2 pgoyette * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 1.1.1.1.2.2 pgoyette * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 1.1.1.1.2.2 pgoyette * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 1.1.1.1.2.2 pgoyette * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 1.1.1.1.2.2 pgoyette * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 1.1.1.1.2.2 pgoyette * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 1.1.1.1.2.2 pgoyette * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1.1.1.2.2 pgoyette */
35 1.1.1.1.2.2 pgoyette
36 1.1.1.1.2.2 pgoyette /**
37 1.1.1.1.2.2 pgoyette * \file
38 1.1.1.1.2.2 pgoyette *
39 1.1.1.1.2.2 pgoyette * This file contains the data storage for RRsets.
40 1.1.1.1.2.2 pgoyette */
41 1.1.1.1.2.2 pgoyette
42 1.1.1.1.2.2 pgoyette #ifndef UTIL_DATA_PACKED_RRSET_H
43 1.1.1.1.2.2 pgoyette #define UTIL_DATA_PACKED_RRSET_H
44 1.1.1.1.2.2 pgoyette #include "util/storage/lruhash.h"
45 1.1.1.1.2.2 pgoyette struct alloc_cache;
46 1.1.1.1.2.2 pgoyette struct regional;
47 1.1.1.1.2.2 pgoyette
48 1.1.1.1.2.2 pgoyette /** type used to uniquely identify rrsets. Cannot be reused without
49 1.1.1.1.2.2 pgoyette * clearing the cache. */
50 1.1.1.1.2.2 pgoyette typedef uint64_t rrset_id_t;
51 1.1.1.1.2.2 pgoyette
52 1.1.1.1.2.2 pgoyette /** this rrset is NSEC and is at zone apex (at child side of zonecut) */
53 1.1.1.1.2.2 pgoyette #define PACKED_RRSET_NSEC_AT_APEX 0x1
54 1.1.1.1.2.2 pgoyette /** this rrset is A/AAAA and is in-zone-glue (from parent side of zonecut) */
55 1.1.1.1.2.2 pgoyette #define PACKED_RRSET_PARENT_SIDE 0x2
56 1.1.1.1.2.2 pgoyette /** this rrset is SOA and has the negative ttl (from nxdomain or nodata),
57 1.1.1.1.2.2 pgoyette * this is set on SOA rrsets in the authority section, to keep its TTL separate
58 1.1.1.1.2.2 pgoyette * from the SOA in the answer section from a direct SOA query or ANY query. */
59 1.1.1.1.2.2 pgoyette #define PACKED_RRSET_SOA_NEG 0x4
60 1.1.1.1.2.2 pgoyette
61 1.1.1.1.2.2 pgoyette /** number of rrs and rrsets for integer overflow protection. More than
62 1.1.1.1.2.2 pgoyette * this is not really possible (64K packet has much less RRs and RRsets) in
63 1.1.1.1.2.2 pgoyette * a message. And this is small enough that also multiplied there is no
64 1.1.1.1.2.2 pgoyette * integer overflow. */
65 1.1.1.1.2.2 pgoyette #define RR_COUNT_MAX 0xffffff
66 1.1.1.1.2.2 pgoyette
67 1.1.1.1.2.2 pgoyette /**
68 1.1.1.1.2.2 pgoyette * The identifying information for an RRset.
69 1.1.1.1.2.2 pgoyette */
70 1.1.1.1.2.2 pgoyette struct packed_rrset_key {
71 1.1.1.1.2.2 pgoyette /**
72 1.1.1.1.2.2 pgoyette * The domain name. If not null (for id=0) it is allocated, and
73 1.1.1.1.2.2 pgoyette * contains the wireformat domain name.
74 1.1.1.1.2.2 pgoyette * This dname is not canonicalized.
75 1.1.1.1.2.2 pgoyette */
76 1.1.1.1.2.2 pgoyette uint8_t* dname;
77 1.1.1.1.2.2 pgoyette /**
78 1.1.1.1.2.2 pgoyette * Length of the domain name, including last 0 root octet.
79 1.1.1.1.2.2 pgoyette */
80 1.1.1.1.2.2 pgoyette size_t dname_len;
81 1.1.1.1.2.2 pgoyette /**
82 1.1.1.1.2.2 pgoyette * Flags. 32bit to be easy for hashing:
83 1.1.1.1.2.2 pgoyette * o PACKED_RRSET_NSEC_AT_APEX
84 1.1.1.1.2.2 pgoyette * o PACKED_RRSET_PARENT_SIDE
85 1.1.1.1.2.2 pgoyette * o PACKED_RRSET_SOA_NEG
86 1.1.1.1.2.2 pgoyette */
87 1.1.1.1.2.2 pgoyette uint32_t flags;
88 1.1.1.1.2.2 pgoyette /** the rrset type in network format */
89 1.1.1.1.2.2 pgoyette uint16_t type;
90 1.1.1.1.2.2 pgoyette /** the rrset class in network format */
91 1.1.1.1.2.2 pgoyette uint16_t rrset_class;
92 1.1.1.1.2.2 pgoyette };
93 1.1.1.1.2.2 pgoyette
94 1.1.1.1.2.2 pgoyette /**
95 1.1.1.1.2.2 pgoyette * This structure contains an RRset. A set of resource records that
96 1.1.1.1.2.2 pgoyette * share the same domain name, type and class.
97 1.1.1.1.2.2 pgoyette *
98 1.1.1.1.2.2 pgoyette * Due to memory management and threading, the key structure cannot be
99 1.1.1.1.2.2 pgoyette * deleted, although the data can be. The id can be set to 0 to store and the
100 1.1.1.1.2.2 pgoyette * structure can be recycled with a new id.
101 1.1.1.1.2.2 pgoyette */
102 1.1.1.1.2.2 pgoyette struct ub_packed_rrset_key {
103 1.1.1.1.2.2 pgoyette /**
104 1.1.1.1.2.2 pgoyette * entry into hashtable. Note the lock is never destroyed,
105 1.1.1.1.2.2 pgoyette * even when this key is retired to the cache.
106 1.1.1.1.2.2 pgoyette * the data pointer (if not null) points to a struct packed_rrset.
107 1.1.1.1.2.2 pgoyette */
108 1.1.1.1.2.2 pgoyette struct lruhash_entry entry;
109 1.1.1.1.2.2 pgoyette /**
110 1.1.1.1.2.2 pgoyette * the ID of this rrset. unique, based on threadid + sequenceno.
111 1.1.1.1.2.2 pgoyette * ids are not reused, except after flushing the cache.
112 1.1.1.1.2.2 pgoyette * zero is an unused entry, and never a valid id.
113 1.1.1.1.2.2 pgoyette * Check this value after getting entry.lock.
114 1.1.1.1.2.2 pgoyette * The other values in this struct may only be altered after changing
115 1.1.1.1.2.2 pgoyette * the id (which needs a writelock on entry.lock).
116 1.1.1.1.2.2 pgoyette */
117 1.1.1.1.2.2 pgoyette rrset_id_t id;
118 1.1.1.1.2.2 pgoyette /** key data: dname, type and class */
119 1.1.1.1.2.2 pgoyette struct packed_rrset_key rk;
120 1.1.1.1.2.2 pgoyette };
121 1.1.1.1.2.2 pgoyette
122 1.1.1.1.2.2 pgoyette /**
123 1.1.1.1.2.2 pgoyette * RRset trustworthiness. Bigger value is more trust. RFC 2181.
124 1.1.1.1.2.2 pgoyette * The rrset_trust_add_noAA, rrset_trust_auth_noAA, rrset_trust_add_AA,
125 1.1.1.1.2.2 pgoyette * are mentioned as the same trustworthiness in 2181, but split up here
126 1.1.1.1.2.2 pgoyette * for ease of processing.
127 1.1.1.1.2.2 pgoyette *
128 1.1.1.1.2.2 pgoyette * rrset_trust_nonauth_ans_AA, rrset_trust_ans_noAA
129 1.1.1.1.2.2 pgoyette * are also mentioned as the same trustworthiness in 2181, but split up here
130 1.1.1.1.2.2 pgoyette * for ease of processing.
131 1.1.1.1.2.2 pgoyette *
132 1.1.1.1.2.2 pgoyette * Added trust_none for a sane initial value, smaller than anything else.
133 1.1.1.1.2.2 pgoyette * Added validated and ultimate trust for keys and rrsig validated content.
134 1.1.1.1.2.2 pgoyette */
135 1.1.1.1.2.2 pgoyette enum rrset_trust {
136 1.1.1.1.2.2 pgoyette /** initial value for trust */
137 1.1.1.1.2.2 pgoyette rrset_trust_none = 0,
138 1.1.1.1.2.2 pgoyette /** Additional information from non-authoritative answers */
139 1.1.1.1.2.2 pgoyette rrset_trust_add_noAA,
140 1.1.1.1.2.2 pgoyette /** Data from the authority section of a non-authoritative answer */
141 1.1.1.1.2.2 pgoyette rrset_trust_auth_noAA,
142 1.1.1.1.2.2 pgoyette /** Additional information from an authoritative answer */
143 1.1.1.1.2.2 pgoyette rrset_trust_add_AA,
144 1.1.1.1.2.2 pgoyette /** non-authoritative data from the answer section of authoritative
145 1.1.1.1.2.2 pgoyette * answers */
146 1.1.1.1.2.2 pgoyette rrset_trust_nonauth_ans_AA,
147 1.1.1.1.2.2 pgoyette /** Data from the answer section of a non-authoritative answer */
148 1.1.1.1.2.2 pgoyette rrset_trust_ans_noAA,
149 1.1.1.1.2.2 pgoyette /** Glue from a primary zone, or glue from a zone transfer */
150 1.1.1.1.2.2 pgoyette rrset_trust_glue,
151 1.1.1.1.2.2 pgoyette /** Data from the authority section of an authoritative answer */
152 1.1.1.1.2.2 pgoyette rrset_trust_auth_AA,
153 1.1.1.1.2.2 pgoyette /** The authoritative data included in the answer section of an
154 1.1.1.1.2.2 pgoyette * authoritative reply */
155 1.1.1.1.2.2 pgoyette rrset_trust_ans_AA,
156 1.1.1.1.2.2 pgoyette /** Data from a zone transfer, other than glue */
157 1.1.1.1.2.2 pgoyette rrset_trust_sec_noglue,
158 1.1.1.1.2.2 pgoyette /** Data from a primary zone file, other than glue data */
159 1.1.1.1.2.2 pgoyette rrset_trust_prim_noglue,
160 1.1.1.1.2.2 pgoyette /** DNSSEC(rfc4034) validated with trusted keys */
161 1.1.1.1.2.2 pgoyette rrset_trust_validated,
162 1.1.1.1.2.2 pgoyette /** ultimately trusted, no more trust is possible;
163 1.1.1.1.2.2 pgoyette * trusted keys from the unbound configuration setup. */
164 1.1.1.1.2.2 pgoyette rrset_trust_ultimate
165 1.1.1.1.2.2 pgoyette };
166 1.1.1.1.2.2 pgoyette
167 1.1.1.1.2.2 pgoyette /**
168 1.1.1.1.2.2 pgoyette * Security status from validation for data.
169 1.1.1.1.2.2 pgoyette * The order is significant; more secure, more proven later.
170 1.1.1.1.2.2 pgoyette */
171 1.1.1.1.2.2 pgoyette enum sec_status {
172 1.1.1.1.2.2 pgoyette /** UNCHECKED means that object has yet to be validated. */
173 1.1.1.1.2.2 pgoyette sec_status_unchecked = 0,
174 1.1.1.1.2.2 pgoyette /** BOGUS means that the object (RRset or message) failed to validate
175 1.1.1.1.2.2 pgoyette * (according to local policy), but should have validated. */
176 1.1.1.1.2.2 pgoyette sec_status_bogus,
177 1.1.1.1.2.2 pgoyette /** INDETERMINATE means that the object is insecure, but not
178 1.1.1.1.2.2 pgoyette * authoritatively so. Generally this means that the RRset is not
179 1.1.1.1.2.2 pgoyette * below a configured trust anchor. */
180 1.1.1.1.2.2 pgoyette sec_status_indeterminate,
181 1.1.1.1.2.2 pgoyette /** INSECURE means that the object is authoritatively known to be
182 1.1.1.1.2.2 pgoyette * insecure. Generally this means that this RRset is below a trust
183 1.1.1.1.2.2 pgoyette * anchor, but also below a verified, insecure delegation. */
184 1.1.1.1.2.2 pgoyette sec_status_insecure,
185 1.1.1.1.2.2 pgoyette /** SECURE means that the object (RRset or message) validated
186 1.1.1.1.2.2 pgoyette * according to local policy. */
187 1.1.1.1.2.2 pgoyette sec_status_secure
188 1.1.1.1.2.2 pgoyette };
189 1.1.1.1.2.2 pgoyette
190 1.1.1.1.2.2 pgoyette /**
191 1.1.1.1.2.2 pgoyette * RRset data.
192 1.1.1.1.2.2 pgoyette *
193 1.1.1.1.2.2 pgoyette * The data is packed, stored contiguously in memory.
194 1.1.1.1.2.2 pgoyette * memory layout:
195 1.1.1.1.2.2 pgoyette * o base struct
196 1.1.1.1.2.2 pgoyette * o rr_len size_t array
197 1.1.1.1.2.2 pgoyette * o rr_data uint8_t* array
198 1.1.1.1.2.2 pgoyette * o rr_ttl time_t array (after size_t and ptrs because those may be
199 1.1.1.1.2.2 pgoyette * 64bit and this array before those would make them unaligned).
200 1.1.1.1.2.2 pgoyette * Since the stuff before is 32/64bit, rr_ttl is 32 bit aligned.
201 1.1.1.1.2.2 pgoyette * o rr_data rdata wireformats
202 1.1.1.1.2.2 pgoyette * o rrsig_data rdata wireformat(s)
203 1.1.1.1.2.2 pgoyette *
204 1.1.1.1.2.2 pgoyette * Rdata is stored in wireformat. The dname is stored in wireformat.
205 1.1.1.1.2.2 pgoyette * TTLs are stored as absolute values (and could be expired).
206 1.1.1.1.2.2 pgoyette *
207 1.1.1.1.2.2 pgoyette * RRSIGs are stored in the arrays after the regular rrs.
208 1.1.1.1.2.2 pgoyette *
209 1.1.1.1.2.2 pgoyette * You need the packed_rrset_key to know dname, type, class of the
210 1.1.1.1.2.2 pgoyette * resource records in this RRset. (if signed the rrsig gives the type too).
211 1.1.1.1.2.2 pgoyette *
212 1.1.1.1.2.2 pgoyette * On the wire an RR is:
213 1.1.1.1.2.2 pgoyette * name, type, class, ttl, rdlength, rdata.
214 1.1.1.1.2.2 pgoyette * So we need to send the following per RR:
215 1.1.1.1.2.2 pgoyette * key.dname, ttl, rr_data[i].
216 1.1.1.1.2.2 pgoyette * since key.dname ends with type and class.
217 1.1.1.1.2.2 pgoyette * and rr_data starts with the rdlength.
218 1.1.1.1.2.2 pgoyette * the ttl value to send changes due to time.
219 1.1.1.1.2.2 pgoyette */
220 1.1.1.1.2.2 pgoyette struct packed_rrset_data {
221 1.1.1.1.2.2 pgoyette /** TTL (in seconds like time()) of the rrset.
222 1.1.1.1.2.2 pgoyette * Same for all RRs see rfc2181(5.2). */
223 1.1.1.1.2.2 pgoyette time_t ttl;
224 1.1.1.1.2.2 pgoyette /** number of rrs. */
225 1.1.1.1.2.2 pgoyette size_t count;
226 1.1.1.1.2.2 pgoyette /** number of rrsigs, if 0 no rrsigs */
227 1.1.1.1.2.2 pgoyette size_t rrsig_count;
228 1.1.1.1.2.2 pgoyette /** the trustworthiness of the rrset data */
229 1.1.1.1.2.2 pgoyette enum rrset_trust trust;
230 1.1.1.1.2.2 pgoyette /** security status of the rrset data */
231 1.1.1.1.2.2 pgoyette enum sec_status security;
232 1.1.1.1.2.2 pgoyette /** length of every rr's rdata, rr_len[i] is size of rr_data[i]. */
233 1.1.1.1.2.2 pgoyette size_t* rr_len;
234 1.1.1.1.2.2 pgoyette /** ttl of every rr. rr_ttl[i] ttl of rr i. */
235 1.1.1.1.2.2 pgoyette time_t *rr_ttl;
236 1.1.1.1.2.2 pgoyette /**
237 1.1.1.1.2.2 pgoyette * Array of pointers to every rr's rdata.
238 1.1.1.1.2.2 pgoyette * The rr_data[i] rdata is stored in uncompressed wireformat.
239 1.1.1.1.2.2 pgoyette * The first uint16_t of rr_data[i] is network format rdlength.
240 1.1.1.1.2.2 pgoyette *
241 1.1.1.1.2.2 pgoyette * rr_data[count] to rr_data[count+rrsig_count] contain the rrsig data.
242 1.1.1.1.2.2 pgoyette */
243 1.1.1.1.2.2 pgoyette uint8_t** rr_data;
244 1.1.1.1.2.2 pgoyette };
245 1.1.1.1.2.2 pgoyette
246 1.1.1.1.2.2 pgoyette /**
247 1.1.1.1.2.2 pgoyette * An RRset can be represented using both key and data together.
248 1.1.1.1.2.2 pgoyette * Split into key and data structures to simplify implementation of
249 1.1.1.1.2.2 pgoyette * caching schemes.
250 1.1.1.1.2.2 pgoyette */
251 1.1.1.1.2.2 pgoyette struct packed_rrset {
252 1.1.1.1.2.2 pgoyette /** domain name, type and class */
253 1.1.1.1.2.2 pgoyette struct packed_rrset_key* k;
254 1.1.1.1.2.2 pgoyette /** ttl, count and rdatas (and rrsig) */
255 1.1.1.1.2.2 pgoyette struct packed_rrset_data* d;
256 1.1.1.1.2.2 pgoyette };
257 1.1.1.1.2.2 pgoyette
258 1.1.1.1.2.2 pgoyette /**
259 1.1.1.1.2.2 pgoyette * list of packed rrsets
260 1.1.1.1.2.2 pgoyette */
261 1.1.1.1.2.2 pgoyette struct packed_rrset_list {
262 1.1.1.1.2.2 pgoyette /** next in list */
263 1.1.1.1.2.2 pgoyette struct packed_rrset_list* next;
264 1.1.1.1.2.2 pgoyette /** rrset key and data */
265 1.1.1.1.2.2 pgoyette struct packed_rrset rrset;
266 1.1.1.1.2.2 pgoyette };
267 1.1.1.1.2.2 pgoyette
268 1.1.1.1.2.2 pgoyette /**
269 1.1.1.1.2.2 pgoyette * Delete packed rrset key and data, not entered in hashtables yet.
270 1.1.1.1.2.2 pgoyette * Used during parsing.
271 1.1.1.1.2.2 pgoyette * @param pkey: rrset key structure with locks, key and data pointers.
272 1.1.1.1.2.2 pgoyette * @param alloc: where to return the unfree-able key structure.
273 1.1.1.1.2.2 pgoyette */
274 1.1.1.1.2.2 pgoyette void ub_packed_rrset_parsedelete(struct ub_packed_rrset_key* pkey,
275 1.1.1.1.2.2 pgoyette struct alloc_cache* alloc);
276 1.1.1.1.2.2 pgoyette
277 1.1.1.1.2.2 pgoyette /**
278 1.1.1.1.2.2 pgoyette * Memory size of rrset data. RRset data must be filled in correctly.
279 1.1.1.1.2.2 pgoyette * @param data: data to examine.
280 1.1.1.1.2.2 pgoyette * @return size in bytes.
281 1.1.1.1.2.2 pgoyette */
282 1.1.1.1.2.2 pgoyette size_t packed_rrset_sizeof(struct packed_rrset_data* data);
283 1.1.1.1.2.2 pgoyette
284 1.1.1.1.2.2 pgoyette /**
285 1.1.1.1.2.2 pgoyette * Get TTL of rrset. RRset data must be filled in correctly.
286 1.1.1.1.2.2 pgoyette * @param key: rrset key, with data to examine.
287 1.1.1.1.2.2 pgoyette * @return ttl value.
288 1.1.1.1.2.2 pgoyette */
289 1.1.1.1.2.2 pgoyette time_t ub_packed_rrset_ttl(struct ub_packed_rrset_key* key);
290 1.1.1.1.2.2 pgoyette
291 1.1.1.1.2.2 pgoyette /**
292 1.1.1.1.2.2 pgoyette * Calculate memory size of rrset entry. For hash table usage.
293 1.1.1.1.2.2 pgoyette * @param key: struct ub_packed_rrset_key*.
294 1.1.1.1.2.2 pgoyette * @param data: struct packed_rrset_data*.
295 1.1.1.1.2.2 pgoyette * @return size in bytes.
296 1.1.1.1.2.2 pgoyette */
297 1.1.1.1.2.2 pgoyette size_t ub_rrset_sizefunc(void* key, void* data);
298 1.1.1.1.2.2 pgoyette
299 1.1.1.1.2.2 pgoyette /**
300 1.1.1.1.2.2 pgoyette * compares two rrset keys.
301 1.1.1.1.2.2 pgoyette * @param k1: struct ub_packed_rrset_key*.
302 1.1.1.1.2.2 pgoyette * @param k2: struct ub_packed_rrset_key*.
303 1.1.1.1.2.2 pgoyette * @return 0 if equal.
304 1.1.1.1.2.2 pgoyette */
305 1.1.1.1.2.2 pgoyette int ub_rrset_compare(void* k1, void* k2);
306 1.1.1.1.2.2 pgoyette
307 1.1.1.1.2.2 pgoyette /**
308 1.1.1.1.2.2 pgoyette * compare two rrset data structures.
309 1.1.1.1.2.2 pgoyette * Compared rdata and rrsigdata, not the trust or ttl value.
310 1.1.1.1.2.2 pgoyette * @param d1: data to compare.
311 1.1.1.1.2.2 pgoyette * @param d2: data to compare.
312 1.1.1.1.2.2 pgoyette * @return 1 if equal.
313 1.1.1.1.2.2 pgoyette */
314 1.1.1.1.2.2 pgoyette int rrsetdata_equal(struct packed_rrset_data* d1, struct packed_rrset_data* d2);
315 1.1.1.1.2.2 pgoyette
316 1.1.1.1.2.2 pgoyette /**
317 1.1.1.1.2.2 pgoyette * Old key to be deleted. RRset keys are recycled via alloc.
318 1.1.1.1.2.2 pgoyette * The id is set to 0. So that other threads, after acquiring a lock always
319 1.1.1.1.2.2 pgoyette * get the correct value, in this case the 0 deleted-special value.
320 1.1.1.1.2.2 pgoyette * @param key: struct ub_packed_rrset_key*.
321 1.1.1.1.2.2 pgoyette * @param userdata: alloc structure to use for recycling.
322 1.1.1.1.2.2 pgoyette */
323 1.1.1.1.2.2 pgoyette void ub_rrset_key_delete(void* key, void* userdata);
324 1.1.1.1.2.2 pgoyette
325 1.1.1.1.2.2 pgoyette /**
326 1.1.1.1.2.2 pgoyette * Old data to be deleted.
327 1.1.1.1.2.2 pgoyette * @param data: what to delete.
328 1.1.1.1.2.2 pgoyette * @param userdata: user data ptr.
329 1.1.1.1.2.2 pgoyette */
330 1.1.1.1.2.2 pgoyette void rrset_data_delete(void* data, void* userdata);
331 1.1.1.1.2.2 pgoyette
332 1.1.1.1.2.2 pgoyette /**
333 1.1.1.1.2.2 pgoyette * Calculate hash value for a packed rrset key.
334 1.1.1.1.2.2 pgoyette * @param key: the rrset key with name, type, class, flags.
335 1.1.1.1.2.2 pgoyette * @return hash value.
336 1.1.1.1.2.2 pgoyette */
337 1.1.1.1.2.2 pgoyette hashvalue_t rrset_key_hash(struct packed_rrset_key* key);
338 1.1.1.1.2.2 pgoyette
339 1.1.1.1.2.2 pgoyette /**
340 1.1.1.1.2.2 pgoyette * Fixup pointers in fixed data packed_rrset_data blob.
341 1.1.1.1.2.2 pgoyette * After a memcpy of the data for example. Will set internal pointers right.
342 1.1.1.1.2.2 pgoyette * @param data: rrset data structure. Otherwise correctly filled in.
343 1.1.1.1.2.2 pgoyette */
344 1.1.1.1.2.2 pgoyette void packed_rrset_ptr_fixup(struct packed_rrset_data* data);
345 1.1.1.1.2.2 pgoyette
346 1.1.1.1.2.2 pgoyette /**
347 1.1.1.1.2.2 pgoyette * Fixup TTLs in fixed data packed_rrset_data blob.
348 1.1.1.1.2.2 pgoyette * @param data: rrset data structure. Otherwise correctly filled in.
349 1.1.1.1.2.2 pgoyette * @param add: how many seconds to add, pass time(0) for example.
350 1.1.1.1.2.2 pgoyette */
351 1.1.1.1.2.2 pgoyette void packed_rrset_ttl_add(struct packed_rrset_data* data, time_t add);
352 1.1.1.1.2.2 pgoyette
353 1.1.1.1.2.2 pgoyette /**
354 1.1.1.1.2.2 pgoyette * Utility procedure to extract CNAME target name from its rdata.
355 1.1.1.1.2.2 pgoyette * Failsafes; it will change passed dname to a valid dname or do nothing.
356 1.1.1.1.2.2 pgoyette * @param rrset: the rrset structure. Must be a CNAME.
357 1.1.1.1.2.2 pgoyette * Only first RR is used (multiple RRs are technically illegal anyway).
358 1.1.1.1.2.2 pgoyette * Also works on type DNAME. Returns target name.
359 1.1.1.1.2.2 pgoyette * @param dname: this pointer is updated to point into the cname rdata.
360 1.1.1.1.2.2 pgoyette * If a failsafe fails, nothing happens to the pointer (such as the
361 1.1.1.1.2.2 pgoyette * rdata was not a valid dname, not a CNAME, ...).
362 1.1.1.1.2.2 pgoyette * @param dname_len: length of dname is returned.
363 1.1.1.1.2.2 pgoyette */
364 1.1.1.1.2.2 pgoyette void get_cname_target(struct ub_packed_rrset_key* rrset, uint8_t** dname,
365 1.1.1.1.2.2 pgoyette size_t* dname_len);
366 1.1.1.1.2.2 pgoyette
367 1.1.1.1.2.2 pgoyette /**
368 1.1.1.1.2.2 pgoyette * Get a printable string for a rrset trust value
369 1.1.1.1.2.2 pgoyette * @param s: rrset trust value
370 1.1.1.1.2.2 pgoyette * @return printable string.
371 1.1.1.1.2.2 pgoyette */
372 1.1.1.1.2.2 pgoyette const char* rrset_trust_to_string(enum rrset_trust s);
373 1.1.1.1.2.2 pgoyette
374 1.1.1.1.2.2 pgoyette /**
375 1.1.1.1.2.2 pgoyette * Get a printable string for a security status value
376 1.1.1.1.2.2 pgoyette * @param s: security status
377 1.1.1.1.2.2 pgoyette * @return printable string.
378 1.1.1.1.2.2 pgoyette */
379 1.1.1.1.2.2 pgoyette const char* sec_status_to_string(enum sec_status s);
380 1.1.1.1.2.2 pgoyette
381 1.1.1.1.2.2 pgoyette /**
382 1.1.1.1.2.2 pgoyette * Print string with neat domain name, type, class from rrset.
383 1.1.1.1.2.2 pgoyette * @param v: at what verbosity level to print this.
384 1.1.1.1.2.2 pgoyette * @param str: string of message.
385 1.1.1.1.2.2 pgoyette * @param rrset: structure with name, type and class.
386 1.1.1.1.2.2 pgoyette */
387 1.1.1.1.2.2 pgoyette void log_rrset_key(enum verbosity_value v, const char* str,
388 1.1.1.1.2.2 pgoyette struct ub_packed_rrset_key* rrset);
389 1.1.1.1.2.2 pgoyette
390 1.1.1.1.2.2 pgoyette /**
391 1.1.1.1.2.2 pgoyette * Convert RR from RRset to string.
392 1.1.1.1.2.2 pgoyette * @param rrset: structure with data.
393 1.1.1.1.2.2 pgoyette * @param i: index of rr or RRSIG.
394 1.1.1.1.2.2 pgoyette * @param now: time that is subtracted from ttl before printout. Can be 0.
395 1.1.1.1.2.2 pgoyette * @param dest: destination string buffer. Must be nonNULL.
396 1.1.1.1.2.2 pgoyette * @param dest_len: length of dest buffer (>0).
397 1.1.1.1.2.2 pgoyette * @return false on failure.
398 1.1.1.1.2.2 pgoyette */
399 1.1.1.1.2.2 pgoyette int packed_rr_to_string(struct ub_packed_rrset_key* rrset, size_t i,
400 1.1.1.1.2.2 pgoyette time_t now, char* dest, size_t dest_len);
401 1.1.1.1.2.2 pgoyette
402 1.1.1.1.2.2 pgoyette /**
403 1.1.1.1.2.2 pgoyette * Print the string with prefix, one rr per line.
404 1.1.1.1.2.2 pgoyette * @param v: at what verbosity level to print this.
405 1.1.1.1.2.2 pgoyette * @param str: string of message.
406 1.1.1.1.2.2 pgoyette * @param rrset: with name, and rdata, and rrsigs.
407 1.1.1.1.2.2 pgoyette */
408 1.1.1.1.2.2 pgoyette void log_packed_rrset(enum verbosity_value v, const char* str,
409 1.1.1.1.2.2 pgoyette struct ub_packed_rrset_key* rrset);
410 1.1.1.1.2.2 pgoyette
411 1.1.1.1.2.2 pgoyette /**
412 1.1.1.1.2.2 pgoyette * Allocate rrset in region - no more locks needed
413 1.1.1.1.2.2 pgoyette * @param key: a (just from rrset cache looked up) rrset key + valid,
414 1.1.1.1.2.2 pgoyette * packed data record.
415 1.1.1.1.2.2 pgoyette * @param region: where to alloc the copy
416 1.1.1.1.2.2 pgoyette * @param now: adjust the TTLs to be relative (subtract from all TTLs).
417 1.1.1.1.2.2 pgoyette * @return new region-alloced rrset key or NULL on alloc failure.
418 1.1.1.1.2.2 pgoyette */
419 1.1.1.1.2.2 pgoyette struct ub_packed_rrset_key* packed_rrset_copy_region(
420 1.1.1.1.2.2 pgoyette struct ub_packed_rrset_key* key, struct regional* region,
421 1.1.1.1.2.2 pgoyette time_t now);
422 1.1.1.1.2.2 pgoyette
423 1.1.1.1.2.2 pgoyette /**
424 1.1.1.1.2.2 pgoyette * Allocate rrset with malloc (from region or you are holding the lock).
425 1.1.1.1.2.2 pgoyette * @param key: key with data entry.
426 1.1.1.1.2.2 pgoyette * @param alloc: alloc_cache to create rrset_keys
427 1.1.1.1.2.2 pgoyette * @param now: adjust the TTLs to be absolute (add to all TTLs).
428 1.1.1.1.2.2 pgoyette * @return new region-alloced rrset key or NULL on alloc failure.
429 1.1.1.1.2.2 pgoyette */
430 1.1.1.1.2.2 pgoyette struct ub_packed_rrset_key* packed_rrset_copy_alloc(
431 1.1.1.1.2.2 pgoyette struct ub_packed_rrset_key* key, struct alloc_cache* alloc,
432 1.1.1.1.2.2 pgoyette time_t now);
433 1.1.1.1.2.2 pgoyette
434 1.1.1.1.2.2 pgoyette #endif /* UTIL_DATA_PACKED_RRSET_H */
435