00001 /* 00002 * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC") 00003 * Copyright (C) 1999-2002 Internet Software Consortium. 00004 * 00005 * Permission to use, copy, modify, and/or distribute this software for any 00006 * purpose with or without fee is hereby granted, provided that the above 00007 * copyright notice and this permission notice appear in all copies. 00008 * 00009 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00010 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00011 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00012 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00013 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00014 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00015 * PERFORMANCE OF THIS SOFTWARE. 00016 */ 00017 00018 /* $Id: compress.h,v 1.42 2009/01/17 23:47:43 tbox Exp $ */ 00019 00020 #ifndef DNS_COMPRESS_H 00021 #define DNS_COMPRESS_H 1 00022 00023 #include <isc/lang.h> 00024 #include <isc/region.h> 00025 00026 #include <dns/types.h> 00027 00028 ISC_LANG_BEGINDECLS 00029 00030 #define DNS_COMPRESS_NONE 0x00 /*%< no compression */ 00031 #define DNS_COMPRESS_GLOBAL14 0x01 /*%< "normal" compression. */ 00032 #define DNS_COMPRESS_ALL 0x01 /*%< all compression. */ 00033 #define DNS_COMPRESS_CASESENSITIVE 0x02 /*%< case sensitive compression. */ 00034 00035 /*! \file dns/compress.h 00036 * Direct manipulation of the structures is strongly discouraged. 00037 */ 00038 00039 #define DNS_COMPRESS_TABLESIZE 64 00040 #define DNS_COMPRESS_INITIALNODES 16 00041 00042 typedef struct dns_compressnode dns_compressnode_t; 00043 00044 struct dns_compressnode { 00045 isc_region_t r; 00046 isc_uint16_t offset; 00047 isc_uint16_t count; 00048 isc_uint8_t labels; 00049 dns_compressnode_t *next; 00050 }; 00051 00052 struct dns_compress { 00053 unsigned int magic; /*%< Magic number. */ 00054 unsigned int allowed; /*%< Allowed methods. */ 00055 int edns; /*%< Edns version or -1. */ 00056 /*% Global compression table. */ 00057 dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE]; 00058 /*% Preallocated nodes for the table. */ 00059 dns_compressnode_t initialnodes[DNS_COMPRESS_INITIALNODES]; 00060 isc_uint16_t count; /*%< Number of nodes. */ 00061 isc_mem_t *mctx; /*%< Memory context. */ 00062 }; 00063 00064 typedef enum { 00065 DNS_DECOMPRESS_ANY, /*%< Any compression */ 00066 DNS_DECOMPRESS_STRICT, /*%< Allowed compression */ 00067 DNS_DECOMPRESS_NONE /*%< No compression */ 00068 } dns_decompresstype_t; 00069 00070 struct dns_decompress { 00071 unsigned int magic; /*%< Magic number. */ 00072 unsigned int allowed; /*%< Allowed methods. */ 00073 int edns; /*%< Edns version or -1. */ 00074 dns_decompresstype_t type; /*%< Strict checking */ 00075 }; 00076 00077 isc_result_t 00078 dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx); 00079 /*%< 00080 * Initialise the compression context structure pointed to by 'cctx'. 00081 * 00082 * Requires: 00083 * \li 'cctx' is a valid dns_compress_t structure. 00084 * \li 'mctx' is an initialized memory context. 00085 * Ensures: 00086 * \li cctx->global is initialized. 00087 * 00088 * Returns: 00089 * \li #ISC_R_SUCCESS 00090 * \li failures from dns_rbt_create() 00091 */ 00092 00093 void 00094 dns_compress_invalidate(dns_compress_t *cctx); 00095 00096 /*%< 00097 * Invalidate the compression structure pointed to by cctx. 00098 * 00099 * Requires: 00100 *\li 'cctx' to be initialized. 00101 */ 00102 00103 void 00104 dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed); 00105 00106 /*%< 00107 * Sets allowed compression methods. 00108 * 00109 * Requires: 00110 *\li 'cctx' to be initialized. 00111 */ 00112 00113 unsigned int 00114 dns_compress_getmethods(dns_compress_t *cctx); 00115 00116 /*%< 00117 * Gets allowed compression methods. 00118 * 00119 * Requires: 00120 *\li 'cctx' to be initialized. 00121 * 00122 * Returns: 00123 *\li allowed compression bitmap. 00124 */ 00125 00126 void 00127 dns_compress_setsensitive(dns_compress_t *cctx, isc_boolean_t sensitive); 00128 00129 /* 00130 * Preserve the case of compressed domain names. 00131 * 00132 * Requires: 00133 * 'cctx' to be initialized. 00134 */ 00135 00136 isc_boolean_t 00137 dns_compress_getsensitive(dns_compress_t *cctx); 00138 /* 00139 * Return whether case is to be preserved when compressing 00140 * domain names. 00141 * 00142 * Requires: 00143 * 'cctx' to be initialized. 00144 */ 00145 00146 int 00147 dns_compress_getedns(dns_compress_t *cctx); 00148 00149 /*%< 00150 * Gets edns value. 00151 * 00152 * Requires: 00153 *\li 'cctx' to be initialized. 00154 * 00155 * Returns: 00156 *\li -1 .. 255 00157 */ 00158 00159 isc_boolean_t 00160 dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, 00161 dns_name_t *prefix, isc_uint16_t *offset); 00162 /*%< 00163 * Finds longest possible match of 'name' in the global compression table. 00164 * 00165 * Requires: 00166 *\li 'cctx' to be initialized. 00167 *\li 'name' to be a absolute name. 00168 *\li 'prefix' to be initialized. 00169 *\li 'offset' to point to an isc_uint16_t. 00170 * 00171 * Ensures: 00172 *\li 'prefix' and 'offset' are valid if ISC_TRUE is returned. 00173 * 00174 * Returns: 00175 *\li #ISC_TRUE / #ISC_FALSE 00176 */ 00177 00178 void 00179 dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, 00180 const dns_name_t *prefix, isc_uint16_t offset); 00181 /*%< 00182 * Add compression pointers for 'name' to the compression table, 00183 * not replacing existing pointers. 00184 * 00185 * Requires: 00186 *\li 'cctx' initialized 00187 * 00188 *\li 'name' must be initialized and absolute, and must remain 00189 * valid until the message compression is complete. 00190 * 00191 *\li 'prefix' must be a prefix returned by 00192 * dns_compress_findglobal(), or the same as 'name'. 00193 */ 00194 00195 void 00196 dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset); 00197 00198 /*%< 00199 * Remove any compression pointers from global table >= offset. 00200 * 00201 * Requires: 00202 *\li 'cctx' is initialized. 00203 */ 00204 00205 void 00206 dns_decompress_init(dns_decompress_t *dctx, int edns, 00207 dns_decompresstype_t type); 00208 00209 /*%< 00210 * Initializes 'dctx'. 00211 * Records 'edns' and 'type' into the structure. 00212 * 00213 * Requires: 00214 *\li 'dctx' to be a valid pointer. 00215 */ 00216 00217 void 00218 dns_decompress_invalidate(dns_decompress_t *dctx); 00219 00220 /*%< 00221 * Invalidates 'dctx'. 00222 * 00223 * Requires: 00224 *\li 'dctx' to be initialized 00225 */ 00226 00227 void 00228 dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed); 00229 00230 /*%< 00231 * Sets 'dctx->allowed' to 'allowed'. 00232 * 00233 * Requires: 00234 *\li 'dctx' to be initialized 00235 */ 00236 00237 unsigned int 00238 dns_decompress_getmethods(dns_decompress_t *dctx); 00239 00240 /*%< 00241 * Returns 'dctx->allowed' 00242 * 00243 * Requires: 00244 *\li 'dctx' to be initialized 00245 */ 00246 00247 int 00248 dns_decompress_edns(dns_decompress_t *dctx); 00249 00250 /*%< 00251 * Returns 'dctx->edns' 00252 * 00253 * Requires: 00254 *\li 'dctx' to be initialized 00255 */ 00256 00257 dns_decompresstype_t 00258 dns_decompress_type(dns_decompress_t *dctx); 00259 00260 /*%< 00261 * Returns 'dctx->type' 00262 * 00263 * Requires: 00264 *\li 'dctx' to be initialized 00265 */ 00266 00267 ISC_LANG_ENDDECLS 00268 00269 #endif /* DNS_COMPRESS_H */