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