1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #ifndef DNS_RDATASLAB_H
13 #define DNS_RDATASLAB_H 1
14 
15 /*! \file dns/rdataslab.h
16  * \brief
17  * Implements storage of rdatasets into slabs of memory.
18  *
19  * MP:
20  *\li	Clients of this module must impose any required synchronization.
21  *
22  * Reliability:
23  *\li	This module deals with low-level byte streams.  Errors in any of
24  *	the functions are likely to crash the server or corrupt memory.
25  *
26  *\li	If the caller passes invalid memory references, these functions are
27  *	likely to crash the server or corrupt memory.
28  *
29  * Resources:
30  *\li	None.
31  *
32  * Security:
33  *\li	None.
34  *
35  * Standards:
36  *\li	None.
37  */
38 
39 /***
40  *** Imports
41  ***/
42 
43 #include <stdbool.h>
44 
45 #include <isc/lang.h>
46 
47 #include <dns/types.h>
48 
49 ISC_LANG_BEGINDECLS
50 
51 #define DNS_RDATASLAB_FORCE 0x1
52 #define DNS_RDATASLAB_EXACT 0x2
53 
54 #define DNS_RDATASLAB_OFFLINE 0x01 /* RRSIG is for offline DNSKEY */
55 #define DNS_RDATASLAB_WARNMASK          \
56 	0x0E /*%< RRSIG(DNSKEY) expired \
57 	      * warnings number mask. */
58 #define DNS_RDATASLAB_WARNSHIFT               \
59 	1 /*%< How many bits to shift to find \
60 	   * remaining expired warning number. */
61 
62 /***
63  *** Functions
64  ***/
65 
66 isc_result_t
67 dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
68 			   isc_region_t *region, unsigned int reservelen);
69 /*%<
70  * Slabify a rdataset.  The slab area will be allocated and returned
71  * in 'region'.
72  *
73  * Requires:
74  *\li	'rdataset' is valid.
75  *
76  * Ensures:
77  *\li	'region' will have base pointing to the start of allocated memory,
78  *	with the slabified region beginning at region->base + reservelen.
79  *	region->length contains the total length allocated.
80  *
81  * Returns:
82  *\li	ISC_R_SUCCESS		- successful completion
83  *\li	ISC_R_NOMEMORY		- no memory.
84  *\li	XXX others
85  */
86 
87 unsigned int
88 dns_rdataslab_size(unsigned char *slab, unsigned int reservelen);
89 /*%<
90  * Return the total size of an rdataslab.
91  *
92  * Requires:
93  *\li	'slab' points to a slab.
94  *
95  * Returns:
96  *\li	The number of bytes in the slab, including the reservelen.
97  */
98 
99 unsigned int
100 dns_rdataslab_rdatasize(unsigned char *slab, unsigned int reservelen);
101 /*%<
102  * Return the size of the rdata in an rdataslab.
103  *
104  * Requires:
105  *\li	'slab' points to a slab.
106  */
107 
108 unsigned int
109 dns_rdataslab_count(unsigned char *slab, unsigned int reservelen);
110 /*%<
111  * Return the number of records in the rdataslab
112  *
113  * Requires:
114  *\li	'slab' points to a slab.
115  *
116  * Returns:
117  *\li	The number of records in the slab.
118  */
119 
120 isc_result_t
121 dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
122 		    unsigned int reservelen, isc_mem_t *mctx,
123 		    dns_rdataclass_t rdclass, dns_rdatatype_t type,
124 		    unsigned int flags, unsigned char **tslabp);
125 /*%<
126  * Merge 'oslab' and 'nslab'.
127  */
128 
129 isc_result_t
130 dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,
131 		       unsigned int reservelen, isc_mem_t *mctx,
132 		       dns_rdataclass_t rdclass, dns_rdatatype_t type,
133 		       unsigned int flags, unsigned char **tslabp);
134 /*%<
135  * Subtract 'sslab' from 'mslab'.  If 'exact' is true then all elements
136  * of 'sslab' must exist in 'mslab'.
137  *
138  * XXX
139  * valid flags are DNS_RDATASLAB_EXACT
140  */
141 
142 bool
143 dns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2,
144 		    unsigned int reservelen);
145 /*%<
146  * Compare two rdataslabs for equality.  This does _not_ do a full
147  * DNSSEC comparison.
148  *
149  * Requires:
150  *\li	'slab1' and 'slab2' point to slabs.
151  *
152  * Returns:
153  *\li	true if the slabs are equal, false otherwise.
154  */
155 bool
156 dns_rdataslab_equalx(unsigned char *slab1, unsigned char *slab2,
157 		     unsigned int reservelen, dns_rdataclass_t rdclass,
158 		     dns_rdatatype_t type);
159 /*%<
160  * Compare two rdataslabs for DNSSEC equality.
161  *
162  * Requires:
163  *\li	'slab1' and 'slab2' point to slabs.
164  *
165  * Returns:
166  *\li	true if the slabs are equal, #false otherwise.
167  */
168 
169 ISC_LANG_ENDDECLS
170 
171 #endif /* DNS_RDATASLAB_H */
172