1 /* $NetBSD: compress.h,v 1.4 2014/12/10 04:37:58 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 1999-2002 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* Id: compress.h,v 1.42 2009/01/17 23:47:43 tbox Exp */ 21 22 #ifndef DNS_COMPRESS_H 23 #define DNS_COMPRESS_H 1 24 25 #include <isc/lang.h> 26 #include <isc/region.h> 27 28 #include <dns/types.h> 29 30 ISC_LANG_BEGINDECLS 31 32 #define DNS_COMPRESS_NONE 0x00 /*%< no compression */ 33 #define DNS_COMPRESS_GLOBAL14 0x01 /*%< "normal" compression. */ 34 #define DNS_COMPRESS_ALL 0x01 /*%< all compression. */ 35 #define DNS_COMPRESS_CASESENSITIVE 0x02 /*%< case sensitive compression. */ 36 37 /*! \file dns/compress.h 38 * Direct manipulation of the structures is strongly discouraged. 39 */ 40 41 #define DNS_COMPRESS_TABLESIZE 64 42 #define DNS_COMPRESS_INITIALNODES 16 43 44 typedef struct dns_compressnode dns_compressnode_t; 45 46 struct dns_compressnode { 47 isc_region_t r; 48 isc_uint16_t offset; 49 isc_uint16_t count; 50 isc_uint8_t labels; 51 dns_compressnode_t *next; 52 }; 53 54 struct dns_compress { 55 unsigned int magic; /*%< Magic number. */ 56 unsigned int allowed; /*%< Allowed methods. */ 57 int edns; /*%< Edns version or -1. */ 58 /*% Global compression table. */ 59 dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE]; 60 /*% Preallocated nodes for the table. */ 61 dns_compressnode_t initialnodes[DNS_COMPRESS_INITIALNODES]; 62 isc_uint16_t count; /*%< Number of nodes. */ 63 isc_mem_t *mctx; /*%< Memory context. */ 64 }; 65 66 typedef enum { 67 DNS_DECOMPRESS_ANY, /*%< Any compression */ 68 DNS_DECOMPRESS_STRICT, /*%< Allowed compression */ 69 DNS_DECOMPRESS_NONE /*%< No compression */ 70 } dns_decompresstype_t; 71 72 struct dns_decompress { 73 unsigned int magic; /*%< Magic number. */ 74 unsigned int allowed; /*%< Allowed methods. */ 75 int edns; /*%< Edns version or -1. */ 76 dns_decompresstype_t type; /*%< Strict checking */ 77 }; 78 79 isc_result_t 80 dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx); 81 /*%< 82 * Initialise the compression context structure pointed to by 'cctx'. 83 * 84 * Requires: 85 * \li 'cctx' is a valid dns_compress_t structure. 86 * \li 'mctx' is an initialized memory context. 87 * Ensures: 88 * \li cctx->global is initialized. 89 * 90 * Returns: 91 * \li #ISC_R_SUCCESS 92 * \li failures from dns_rbt_create() 93 */ 94 95 void 96 dns_compress_invalidate(dns_compress_t *cctx); 97 98 /*%< 99 * Invalidate the compression structure pointed to by cctx. 100 * 101 * Requires: 102 *\li 'cctx' to be initialized. 103 */ 104 105 void 106 dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed); 107 108 /*%< 109 * Sets allowed compression methods. 110 * 111 * Requires: 112 *\li 'cctx' to be initialized. 113 */ 114 115 unsigned int 116 dns_compress_getmethods(dns_compress_t *cctx); 117 118 /*%< 119 * Gets allowed compression methods. 120 * 121 * Requires: 122 *\li 'cctx' to be initialized. 123 * 124 * Returns: 125 *\li allowed compression bitmap. 126 */ 127 128 void 129 dns_compress_setsensitive(dns_compress_t *cctx, isc_boolean_t sensitive); 130 131 /* 132 * Preserve the case of compressed domain names. 133 * 134 * Requires: 135 * 'cctx' to be initialized. 136 */ 137 138 isc_boolean_t 139 dns_compress_getsensitive(dns_compress_t *cctx); 140 /* 141 * Return whether case is to be preserved when compressing 142 * domain names. 143 * 144 * Requires: 145 * 'cctx' to be initialized. 146 */ 147 148 int 149 dns_compress_getedns(dns_compress_t *cctx); 150 151 /*%< 152 * Gets edns value. 153 * 154 * Requires: 155 *\li 'cctx' to be initialized. 156 * 157 * Returns: 158 *\li -1 .. 255 159 */ 160 161 isc_boolean_t 162 dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, 163 dns_name_t *prefix, isc_uint16_t *offset); 164 /*%< 165 * Finds longest possible match of 'name' in the global compression table. 166 * 167 * Requires: 168 *\li 'cctx' to be initialized. 169 *\li 'name' to be a absolute name. 170 *\li 'prefix' to be initialized. 171 *\li 'offset' to point to an isc_uint16_t. 172 * 173 * Ensures: 174 *\li 'prefix' and 'offset' are valid if ISC_TRUE is returned. 175 * 176 * Returns: 177 *\li #ISC_TRUE / #ISC_FALSE 178 */ 179 180 void 181 dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, 182 const dns_name_t *prefix, isc_uint16_t offset); 183 /*%< 184 * Add compression pointers for 'name' to the compression table, 185 * not replacing existing pointers. 186 * 187 * Requires: 188 *\li 'cctx' initialized 189 * 190 *\li 'name' must be initialized and absolute, and must remain 191 * valid until the message compression is complete. 192 * 193 *\li 'prefix' must be a prefix returned by 194 * dns_compress_findglobal(), or the same as 'name'. 195 */ 196 197 void 198 dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset); 199 200 /*%< 201 * Remove any compression pointers from global table >= offset. 202 * 203 * Requires: 204 *\li 'cctx' is initialized. 205 */ 206 207 void 208 dns_decompress_init(dns_decompress_t *dctx, int edns, 209 dns_decompresstype_t type); 210 211 /*%< 212 * Initializes 'dctx'. 213 * Records 'edns' and 'type' into the structure. 214 * 215 * Requires: 216 *\li 'dctx' to be a valid pointer. 217 */ 218 219 void 220 dns_decompress_invalidate(dns_decompress_t *dctx); 221 222 /*%< 223 * Invalidates 'dctx'. 224 * 225 * Requires: 226 *\li 'dctx' to be initialized 227 */ 228 229 void 230 dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed); 231 232 /*%< 233 * Sets 'dctx->allowed' to 'allowed'. 234 * 235 * Requires: 236 *\li 'dctx' to be initialized 237 */ 238 239 unsigned int 240 dns_decompress_getmethods(dns_decompress_t *dctx); 241 242 /*%< 243 * Returns 'dctx->allowed' 244 * 245 * Requires: 246 *\li 'dctx' to be initialized 247 */ 248 249 int 250 dns_decompress_edns(dns_decompress_t *dctx); 251 252 /*%< 253 * Returns 'dctx->edns' 254 * 255 * Requires: 256 *\li 'dctx' to be initialized 257 */ 258 259 dns_decompresstype_t 260 dns_decompress_type(dns_decompress_t *dctx); 261 262 /*%< 263 * Returns 'dctx->type' 264 * 265 * Requires: 266 *\li 'dctx' to be initialized 267 */ 268 269 ISC_LANG_ENDDECLS 270 271 #endif /* DNS_COMPRESS_H */ 272