Merge branch 'vendor/LIBPCAP' (early part)
[dragonfly.git] / contrib / bind-9.3 / lib / dns / include / dns / compress.h
1 /*
2  * Copyright (C) 2004, 2006  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and 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
18 /* $Id: compress.h,v 1.29.2.2.8.3 2006/03/02 00:37:20 marka Exp $ */
19
20 #ifndef DNS_COMPRESS_H
21 #define DNS_COMPRESS_H 1
22
23 #include <isc/lang.h>
24 #include <isc/region.h>
25
26 #include <dns/types.h>
27
28 ISC_LANG_BEGINDECLS
29
30 #define DNS_COMPRESS_NONE               0x00    /* no compression */
31 #define DNS_COMPRESS_GLOBAL14           0x01    /* "normal" compression. */
32 #define DNS_COMPRESS_ALL                0x01    /* all compression. */
33
34 /*
35  *      Direct manipulation of the structures is strongly discouraged.
36  */
37
38 #define DNS_COMPRESS_TABLESIZE 64
39 #define DNS_COMPRESS_INITIALNODES 16
40
41 typedef struct dns_compressnode dns_compressnode_t;
42
43 struct dns_compressnode {
44         isc_region_t            r;
45         isc_uint16_t            offset;
46         isc_uint16_t            count;
47         isc_uint8_t             labels;
48         dns_compressnode_t      *next;
49 };
50
51 struct dns_compress {
52         unsigned int            magic;          /* Magic number. */
53         unsigned int            allowed;        /* Allowed methods. */
54         int                     edns;           /* Edns version or -1. */
55         /* Global compression table. */
56         dns_compressnode_t      *table[DNS_COMPRESS_TABLESIZE];
57         /* Preallocated nodes for the table. */
58         dns_compressnode_t      initialnodes[DNS_COMPRESS_INITIALNODES];
59         isc_uint16_t            count;          /* Number of nodes. */
60         isc_mem_t               *mctx;          /* Memory context. */
61 };
62
63 typedef enum {
64         DNS_DECOMPRESS_ANY,                     /* Any compression */
65         DNS_DECOMPRESS_STRICT,                  /* Allowed compression */
66         DNS_DECOMPRESS_NONE                     /* No compression */
67 } dns_decompresstype_t;
68
69 struct dns_decompress {
70         unsigned int            magic;          /* Magic number. */
71         unsigned int            allowed;        /* Allowed methods. */
72         int                     edns;           /* Edns version or -1. */
73         dns_decompresstype_t    type;           /* Strict checking */
74 };
75
76 isc_result_t
77 dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx);
78 /*
79  *      Inialise the compression context structure pointed to by 'cctx'.
80  *
81  *      Requires:
82  *              'cctx' is a valid dns_compress_t structure.
83  *              'mctx' is an initialized memory context.
84  *      Ensures:
85  *              cctx->global is initialized.
86  *
87  *      Returns:
88  *              ISC_R_SUCCESS
89  *              failures from dns_rbt_create()
90  */
91
92 void
93 dns_compress_invalidate(dns_compress_t *cctx);
94
95 /*
96  *      Invalidate the compression structure pointed to by cctx.
97  *
98  *      Requires:
99  *              'cctx' to be initialized.
100  */
101
102 void
103 dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed);
104
105 /*
106  *      Sets allowed compression methods.
107  *
108  *      Requires:
109  *              'cctx' to be initialized.
110  */
111
112 unsigned int
113 dns_compress_getmethods(dns_compress_t *cctx);
114
115 /*
116  *      Gets allowed compression methods.
117  *
118  *      Requires:
119  *              'cctx' to be initialized.
120  *
121  *      Returns:
122  *              allowed compression bitmap.
123  */
124
125 int
126 dns_compress_getedns(dns_compress_t *cctx);
127
128 /*
129  *      Gets edns value.
130  *
131  *      Requires:
132  *              'cctx' to be initialized.
133  *
134  *      Returns:
135  *              -1 .. 255
136  */
137
138 isc_boolean_t
139 dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name,
140                         dns_name_t *prefix, isc_uint16_t *offset);
141 /*
142  *      Finds longest possible match of 'name' in the global compression table.
143  *
144  *      Requires:
145  *              'cctx' to be initialized.
146  *              'name' to be a absolute name.
147  *              'prefix' to be initialized.
148  *              'offset' to point to an isc_uint16_t.
149  *
150  *      Ensures:
151  *              'prefix' and 'offset' are valid if ISC_TRUE is  returned.
152  *
153  *      Returns:
154  *              ISC_TRUE / ISC_FALSE
155  */
156
157 void
158 dns_compress_add(dns_compress_t *cctx, const dns_name_t *name,
159                  const dns_name_t *prefix, isc_uint16_t offset);
160 /*
161  *      Add compression pointers for 'name' to the compression table,
162  *      not replacing existing pointers.
163  *
164  *      Requires:
165  *              'cctx' initialized
166  *
167  *              'name' must be initialized and absolute, and must remain
168  *              valid until the message compression is complete.
169  *
170  *              'prefix' must be a prefix returned by
171  *              dns_compress_findglobal(), or the same as 'name'.
172  */
173
174 void
175 dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset);
176
177 /*
178  *      Remove any compression pointers from global table >= offset.
179  *
180  *      Requires:
181  *              'cctx' is initialized.
182  */
183
184 void
185 dns_decompress_init(dns_decompress_t *dctx, int edns,
186                     dns_decompresstype_t type);
187
188 /*
189  *      Initializes 'dctx'.
190  *      Records 'edns' and 'type' into the structure.
191  *
192  *      Requires:
193  *              'dctx' to be a valid pointer.
194  */
195
196 void
197 dns_decompress_invalidate(dns_decompress_t *dctx);
198
199 /*
200  *      Invalidates 'dctx'.
201  *
202  *      Requires:
203  *              'dctx' to be initialized
204  */
205
206 void
207 dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed);
208
209 /*
210  *      Sets 'dctx->allowed' to 'allowed'.
211  *
212  *      Requires:
213  *              'dctx' to be initialized
214  */
215
216 unsigned int
217 dns_decompress_getmethods(dns_decompress_t *dctx);
218
219 /*
220  *      Returns 'dctx->allowed'
221  *
222  *      Requires:
223  *              'dctx' to be initialized
224  */
225
226 int
227 dns_decompress_edns(dns_decompress_t *dctx);
228
229 /*
230  *      Returns 'dctx->edns'
231  *
232  *      Requires:
233  *              'dctx' to be initialized
234  */
235
236 dns_decompresstype_t
237 dns_decompress_type(dns_decompress_t *dctx);
238
239 /*
240  *      Returns 'dctx->type'
241  *
242  *      Requires:
243  *              'dctx' to be initialized
244  */
245
246 ISC_LANG_ENDDECLS
247
248 #endif /* DNS_COMPRESS_H */