133744Sache/* 233548Sjkh * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC") 32893Sdfr * Copyright (C) 1999-2002 Internet Software Consortium. 433548Sjkh * 533548Sjkh * Permission to use, copy, modify, and/or distribute this software for any 633548Sjkh * purpose with or without fee is hereby granted, provided that the above 733548Sjkh * copyright notice and this permission notice appear in all copies. 833548Sjkh * 933548Sjkh * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 1033548Sjkh * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 1133548Sjkh * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 1233548Sjkh * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 1333548Sjkh * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 1433548Sjkh * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 1533548Sjkh * PERFORMANCE OF THIS SOFTWARE. 1633548Sjkh */ 1733548Sjkh 1833548Sjkh/* $Id: compress.h,v 1.42 2009/01/17 23:47:43 tbox Exp $ */ 1933548Sjkh 2033548Sjkh#ifndef DNS_COMPRESS_H 2133548Sjkh#define DNS_COMPRESS_H 1 2233548Sjkh 2333548Sjkh#include <isc/lang.h> 2433548Sjkh#include <isc/region.h> 2533548Sjkh 2633548Sjkh#include <dns/types.h> 2733548Sjkh 2833548SjkhISC_LANG_BEGINDECLS 2933548Sjkh 3033548Sjkh#define DNS_COMPRESS_NONE 0x00 /*%< no compression */ 3133548Sjkh#define DNS_COMPRESS_GLOBAL14 0x01 /*%< "normal" compression. */ 3233548Sjkh#define DNS_COMPRESS_ALL 0x01 /*%< all compression. */ 3333548Sjkh#define DNS_COMPRESS_CASESENSITIVE 0x02 /*%< case sensitive compression. */ 3433548Sjkh 352893Sdfr/*! \file dns/compress.h 362893Sdfr * Direct manipulation of the structures is strongly discouraged. 378876Srgrimes */ 382893Sdfr 392893Sdfr#define DNS_COMPRESS_TABLESIZE 64 408876Srgrimes#define DNS_COMPRESS_INITIALNODES 16 412893Sdfr 428876Srgrimestypedef struct dns_compressnode dns_compressnode_t; 432893Sdfr 442893Sdfrstruct dns_compressnode { 452893Sdfr isc_region_t r; 462893Sdfr isc_uint16_t offset; 478876Srgrimes isc_uint16_t count; 482893Sdfr isc_uint8_t labels; 492893Sdfr dns_compressnode_t *next; 502893Sdfr}; 512893Sdfr 522893Sdfrstruct dns_compress { 532893Sdfr unsigned int magic; /*%< Magic number. */ 542893Sdfr unsigned int allowed; /*%< Allowed methods. */ 552893Sdfr int edns; /*%< Edns version or -1. */ 562893Sdfr /*% Global compression table. */ 5733548Sjkh dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE]; 587465Sache /*% Preallocated nodes for the table. */ 5933548Sjkh dns_compressnode_t initialnodes[DNS_COMPRESS_INITIALNODES]; 602893Sdfr isc_uint16_t count; /*%< Number of nodes. */ 612893Sdfr isc_mem_t *mctx; /*%< Memory context. */ 622893Sdfr}; 632893Sdfr 642893Sdfrtypedef enum { 652893Sdfr DNS_DECOMPRESS_ANY, /*%< Any compression */ 662893Sdfr DNS_DECOMPRESS_STRICT, /*%< Allowed compression */ 677465Sache DNS_DECOMPRESS_NONE /*%< No compression */ 682893Sdfr} dns_decompresstype_t; 6912144Sphk 707465Sachestruct dns_decompress { 717465Sache unsigned int magic; /*%< Magic number. */ 722893Sdfr unsigned int allowed; /*%< Allowed methods. */ 732893Sdfr int edns; /*%< Edns version or -1. */ 742893Sdfr dns_decompresstype_t type; /*%< Strict checking */ 757465Sache}; 762893Sdfr 7712144Sphkisc_result_t 787465Sachedns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx); 797465Sache/*%< 802893Sdfr * Initialise the compression context structure pointed to by 'cctx'. 812893Sdfr * 822893Sdfr * Requires: 832893Sdfr * \li 'cctx' is a valid dns_compress_t structure. 842893Sdfr * \li 'mctx' is an initialized memory context. 852893Sdfr * Ensures: 8633181Seivind * \li cctx->global is initialized. 8733181Seivind * 8833181Seivind * Returns: 8933181Seivind * \li #ISC_R_SUCCESS 902893Sdfr * \li failures from dns_rbt_create() 912893Sdfr */ 922893Sdfr 932893Sdfrvoid 942893Sdfrdns_compress_invalidate(dns_compress_t *cctx); 952893Sdfr 9633548Sjkh/*%< 972893Sdfr * Invalidate the compression structure pointed to by cctx. 9833548Sjkh * 9933548Sjkh * Requires: 10033548Sjkh *\li 'cctx' to be initialized. 1012893Sdfr */ 1022893Sdfr 1032893Sdfrvoid 1042893Sdfrdns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed); 1052893Sdfr 1062893Sdfr/*%< 1072893Sdfr * Sets allowed compression methods. 1082893Sdfr * 1092893Sdfr * Requires: 1102893Sdfr *\li 'cctx' to be initialized. 1112893Sdfr */ 1122893Sdfr 11318397Snateunsigned int 11415055Sachedns_compress_getmethods(dns_compress_t *cctx); 11515053Sache 11633548Sjkh/*%< 1172893Sdfr * Gets allowed compression methods. 1182893Sdfr * 11933548Sjkh * Requires: 1202893Sdfr *\li 'cctx' to be initialized. 1212893Sdfr * 1222893Sdfr * Returns: 1232893Sdfr *\li allowed compression bitmap. 1242893Sdfr */ 1252893Sdfr 1262893Sdfrvoid 1272893Sdfrdns_compress_setsensitive(dns_compress_t *cctx, isc_boolean_t sensitive); 1282893Sdfr 1292893Sdfr/* 1302893Sdfr * Preserve the case of compressed domain names. 1312893Sdfr * 1322893Sdfr * Requires: 1332893Sdfr * 'cctx' to be initialized. 1342893Sdfr */ 1352893Sdfr 1362893Sdfrisc_boolean_t 1372893Sdfrdns_compress_getsensitive(dns_compress_t *cctx); 13820138Sbde/* 1397465Sache * Return whether case is to be preserved when compressing 1407465Sache * domain names. 1417465Sache * 1422893Sdfr * Requires: 1432893Sdfr * 'cctx' to be initialized. 1442893Sdfr */ 1452893Sdfr 1462893Sdfrint 1472893Sdfrdns_compress_getedns(dns_compress_t *cctx); 1482893Sdfr 1492893Sdfr/*%< 1502893Sdfr * Gets edns value. 1512893Sdfr * 1522893Sdfr * Requires: 1532893Sdfr *\li 'cctx' to be initialized. 15433548Sjkh * 15533548Sjkh * Returns: 15633548Sjkh *\li -1 .. 255 15733548Sjkh */ 15833548Sjkh 1592893Sdfrisc_boolean_t 1602893Sdfrdns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, 1612893Sdfr dns_name_t *prefix, isc_uint16_t *offset); 1622893Sdfr/*%< 1632893Sdfr * Finds longest possible match of 'name' in the global compression table. 1642893Sdfr * 1652893Sdfr * Requires: 1662893Sdfr *\li 'cctx' to be initialized. 1672893Sdfr *\li 'name' to be a absolute name. 16833181Seivind *\li 'prefix' to be initialized. 16933181Seivind *\li 'offset' to point to an isc_uint16_t. 1702893Sdfr * 1712893Sdfr * Ensures: 1722893Sdfr *\li 'prefix' and 'offset' are valid if ISC_TRUE is returned. 1732893Sdfr * 1742893Sdfr * Returns: 1752893Sdfr *\li #ISC_TRUE / #ISC_FALSE 1762893Sdfr */ 17733548Sjkh 17833548Sjkhvoid 17933548Sjkhdns_compress_add(dns_compress_t *cctx, const dns_name_t *name, 18033548Sjkh const dns_name_t *prefix, isc_uint16_t offset); 1812893Sdfr/*%< 1822893Sdfr * Add compression pointers for 'name' to the compression table, 1832893Sdfr * not replacing existing pointers. 18411921Sphk * 18511921Sphk * Requires: 1862893Sdfr *\li 'cctx' initialized 1872893Sdfr * 1882893Sdfr *\li 'name' must be initialized and absolute, and must remain 18933548Sjkh * valid until the message compression is complete. 19033548Sjkh * 19133548Sjkh *\li 'prefix' must be a prefix returned by 19233548Sjkh * dns_compress_findglobal(), or the same as 'name'. 19333548Sjkh */ 19433548Sjkh 19533548Sjkhvoid 19633548Sjkhdns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset); 1975083Sbde 1982893Sdfr/*%< 19933548Sjkh * Remove any compression pointers from global table >= offset. 20033548Sjkh * 2012893Sdfr * Requires: 2022893Sdfr *\li 'cctx' is initialized. 2032893Sdfr */ 2042893Sdfr 2052893Sdfrvoid 2062893Sdfrdns_decompress_init(dns_decompress_t *dctx, int edns, 2072893Sdfr dns_decompresstype_t type); 2082893Sdfr 2097465Sache/*%< 2107465Sache * Initializes 'dctx'. 2117465Sache * Records 'edns' and 'type' into the structure. 2127465Sache * 2132893Sdfr * Requires: 2142893Sdfr *\li 'dctx' to be a valid pointer. 2157465Sache */ 21633548Sjkh 2173152Sphkvoid 2182893Sdfrdns_decompress_invalidate(dns_decompress_t *dctx); 2192893Sdfr 2207465Sache/*%< 2217465Sache * Invalidates 'dctx'. 2222893Sdfr * 2232893Sdfr * Requires: 2242893Sdfr *\li 'dctx' to be initialized 22518397Snate */ 22615055Sache 22715053Sachevoid 22833548Sjkhdns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed); 2292893Sdfr 2302893Sdfr/*%< 23133548Sjkh * Sets 'dctx->allowed' to 'allowed'. 23233548Sjkh * 23333548Sjkh * Requires: 23433548Sjkh *\li 'dctx' to be initialized 23533548Sjkh */ 23633548Sjkh 23733548Sjkhunsigned int 23833548Sjkhdns_decompress_getmethods(dns_decompress_t *dctx); 23933548Sjkh 24033548Sjkh/*%< 24133548Sjkh * Returns 'dctx->allowed' 24233548Sjkh * 24333548Sjkh * Requires: 24433548Sjkh *\li 'dctx' to be initialized 24533548Sjkh */ 24633548Sjkh 24733548Sjkhint 24833548Sjkhdns_decompress_edns(dns_decompress_t *dctx); 24933548Sjkh 25033548Sjkh/*%< 25133548Sjkh * Returns 'dctx->edns' 25233548Sjkh * 25333548Sjkh * Requires: 25433548Sjkh *\li 'dctx' to be initialized 25533548Sjkh */ 25633548Sjkh 25733548Sjkhdns_decompresstype_t 25833548Sjkhdns_decompress_type(dns_decompress_t *dctx); 25933548Sjkh 26033548Sjkh/*%< 26133548Sjkh * Returns 'dctx->type' 26233548Sjkh * 26333548Sjkh * Requires: 26433548Sjkh *\li 'dctx' to be initialized 26533548Sjkh */ 2662893Sdfr 26733548SjkhISC_LANG_ENDDECLS 26833548Sjkh 26933548Sjkh#endif /* DNS_COMPRESS_H */ 27033548Sjkh