/contrib/bind9/lib/dns/include/dns/compress.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 269 lines · 77 code · 43 blank · 149 comment · 0 complexity · 202af452851451770337d0e3f3d24ff7 MD5 · raw file

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