Merge from vendor branch GDB:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / include / dns / rdata.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1998-2003  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: rdata.h,v 1.51.2.5 2004/03/09 06:11:20 marka Exp $ */
19
20 #ifndef DNS_RDATA_H
21 #define DNS_RDATA_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*
28  * DNS Rdata
29  *
30  * Provides facilities for manipulating DNS rdata, including conversions to
31  * and from wire format and text format.
32  *
33  * Given the large amount of rdata possible in a nameserver, it was important
34  * to come up with a very efficient way of storing rdata, but at the same
35  * time allow it to be manipulated.
36  *
37  * The decision was to store rdata in uncompressed wire format,
38  * and not to make it a fully abstracted object; i.e. certain parts of the
39  * server know rdata is stored that way.  This saves a lot of memory, and
40  * makes adding rdata to messages easy.  Having much of the server know
41  * the representation would be perilous, and we certainly don't want each
42  * user of rdata to be manipulating such a low-level structure.  This is
43  * where the rdata module comes in.  The module allows rdata handles to be
44  * created and attached to uncompressed wire format regions.  All rdata
45  * operations and conversions are done through these handles.
46  *
47  * Implementation Notes:
48  *
49  *      The routines in this module are expected to be synthesized by the
50  *      build process from a set of source files, one per rdata type.  For
51  *      portability, it's probably best that the building be done by a C
52  *      program.  Adding a new rdata type will be a simple matter of adding
53  *      a file to a directory and rebuilding the server.  *All* knowlege of
54  *      the format of a particular rdata type is in this file.
55  *
56  * MP:
57  *      Clients of this module must impose any required synchronization.
58  *
59  * Reliability:
60  *      This module deals with low-level byte streams.  Errors in any of
61  *      the functions are likely to crash the server or corrupt memory.
62  *
63  *      Rdata is typed, and the caller must know what type of rdata it has.
64  *      A caller that gets this wrong could crash the server.
65  *
66  *      The fromstruct() and tostruct() routines use a void * pointer to
67  *      represent the structure.  The caller must ensure that it passes a
68  *      pointer to the appropriate type, or the server could crash or memory
69  *      could be corrupted.
70  *
71  * Resources:
72  *      None.
73  *
74  * Security:
75  *
76  *      *** WARNING ***
77  *
78  *      dns_rdata_fromwire() deals with raw network data.  An error in
79  *      this routine could result in the failure or hijacking of the server.
80  *
81  * Standards:
82  *      RFC 1035
83  *      Draft EDNS0 (0)
84  *      Draft EDNS1 (0)
85  *      Draft Binary Labels (2)
86  *      Draft Local Compression (1)
87  *      <Various RFCs for particular types; these will be documented in the
88  *       sources files of the types.>
89  *
90  */
91
92 /***
93  *** Imports
94  ***/
95
96 #include <isc/lang.h>
97
98 #include <dns/types.h>
99
100 ISC_LANG_BEGINDECLS
101
102 /*****
103  ***** RData
104  *****
105  ***** An 'rdata' is a handle to a binary region.  The handle has an RR
106  ***** class and type, and the data in the binary region is in the format
107  ***** of the given class and type.
108  *****/
109
110 /***
111  *** Types
112  ***/
113
114 /*
115  * Clients are strongly discouraged from using this type directly, with
116  * the exception of the 'link' field which may be used directly for whatever
117  * purpose the client desires.
118  */
119 struct dns_rdata {
120         unsigned char *                 data;
121         unsigned int                    length;
122         dns_rdataclass_t                rdclass;
123         dns_rdatatype_t                 type;
124         unsigned int                    flags;
125         ISC_LINK(dns_rdata_t)           link;
126 };
127
128 #define DNS_RDATA_INIT { NULL, 0, 0, 0, 0, {(void*)(-1), (void *)(-1)}}
129
130 #define DNS_RDATA_UPDATE        0x0001          /* update pseudo record */
131
132 /*
133  * Flags affecting rdata formatting style.  Flags 0xFFFF0000
134  * are used by masterfile-level formatting and defined elsewhere.
135  * See additional comments at dns_rdata_tofmttext().
136  */
137
138 /* Split the rdata into multiple lines to try to keep it
139  within the "width". */
140 #define DNS_STYLEFLAG_MULTILINE         0x00000001U
141
142 /* Output explanatory comments. */
143 #define DNS_STYLEFLAG_COMMENT           0x00000002U
144
145 /***
146  *** Initialization
147  ***/
148
149 void
150 dns_rdata_init(dns_rdata_t *rdata);
151 /*
152  * Make 'rdata' empty.
153  *
154  * Requires:
155  *      'rdata' is a valid rdata (i.e. not NULL, points to a struct dns_rdata)
156  */
157
158 void
159 dns_rdata_reset(dns_rdata_t *rdata);
160 /*
161  * Make 'rdata' empty.
162  *
163  * Requires:
164  *      'rdata' is a previously initialized rdata and is not linked.
165  */
166
167 void
168 dns_rdata_clone(const dns_rdata_t *src, dns_rdata_t *target);
169 /*
170  * Clone 'target' from 'src'.
171  *
172  * Requires:
173  *      'src' to be initialized.
174  *      'target' to be initialized.
175  */
176
177 /***
178  *** Comparisons
179  ***/
180
181 int
182 dns_rdata_compare(const dns_rdata_t *rdata1, const dns_rdata_t *rdata2);
183 /*
184  * Determine the relative ordering under the DNSSEC order relation of
185  * 'rdata1' and 'rdata2'.
186  *
187  * Requires:
188  *
189  *      'rdata1' is a valid, non-empty rdata
190  *
191  *      'rdata2' is a valid, non-empty rdata
192  *
193  * Returns:
194  *      < 0             'rdata1' is less than 'rdata2'
195  *      0               'rdata1' is equal to 'rdata2'
196  *      > 0             'rdata1' is greater than 'rdata2'
197  */
198
199 /***
200  *** Conversions
201  ***/
202
203 void
204 dns_rdata_fromregion(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
205                      dns_rdatatype_t type, isc_region_t *r);
206 /*
207  * Make 'rdata' refer to region 'r'.
208  *
209  * Requires:
210  *
211  *      The data in 'r' is properly formatted for whatever type it is.
212  */
213
214 void
215 dns_rdata_toregion(const dns_rdata_t *rdata, isc_region_t *r);
216 /*
217  * Make 'r' refer to 'rdata'.
218  */
219
220 isc_result_t
221 dns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
222                    dns_rdatatype_t type, isc_buffer_t *source,
223                    dns_decompress_t *dctx,
224                    isc_boolean_t downcase,
225                    isc_buffer_t *target);
226 /*
227  * Copy the possibly-compressed rdata at source into the target region.
228  *
229  * Notes:
230  *      Name decompression policy is controlled by 'dctx'.
231  *
232  *      If 'downcase' is true, any uppercase letters in domain names in
233  *      'source' will be downcased when they are copied into 'target'.
234  *
235  * Requires:
236  *
237  *      'rdclass' and 'type' are valid.
238  *
239  *      'source' is a valid buffer, and the active region of 'source'
240  *      references the rdata to be processed.
241  *
242  *      'target' is a valid buffer.
243  *
244  *      'dctx' is a valid decompression context.
245  *
246  * Ensures:
247  *
248  *      If result is success:
249  *              If 'rdata' is not NULL, it is attached to the target.
250  *
251  *              The conditions dns_name_fromwire() ensures for names hold
252  *              for all names in the rdata.
253  *
254  *              The current location in source is advanced, and the used space
255  *              in target is updated.
256  *
257  * Result:
258  *      Success
259  *      <Any non-success status from dns_name_fromwire()>
260  *      <Various 'Bad Form' class failures depending on class and type>
261  *      Bad Form: Input too short
262  *      Resource Limit: Not enough space
263  */
264
265 isc_result_t
266 dns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx,
267                  isc_buffer_t *target);
268 /*
269  * Convert 'rdata' into wire format, compressing it as specified by the
270  * compression context 'cctx', and storing the result in 'target'.
271  *
272  * Notes:
273  *      If the compression context allows global compression, then the
274  *      global compression table may be updated.
275  *
276  * Requires:
277  *      'rdata' is a valid, non-empty rdata
278  *
279  *      target is a valid buffer
280  *
281  *      Any offsets specified in a global compression table are valid
282  *      for target.
283  *
284  * Ensures:
285  *      If the result is success:
286  *              The used space in target is updated.
287  *
288  * Returns:
289  *      Success
290  *      <Any non-success status from dns_name_towire()>
291  *      Resource Limit: Not enough space
292  */
293
294 isc_result_t
295 dns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
296                    dns_rdatatype_t type, isc_lex_t *lexer, dns_name_t *origin,
297                    isc_boolean_t downcase, isc_mem_t *mctx,
298                    isc_buffer_t *target, dns_rdatacallbacks_t *callbacks);
299 /*
300  * Convert the textual representation of a DNS rdata into uncompressed wire
301  * form stored in the target region.  Tokens constituting the text of the rdata
302  * are taken from 'lexer'.
303  *
304  * Notes:
305  *      Relative domain names in the rdata will have 'origin' appended to them.
306  *      A NULL origin implies "origin == dns_rootname".
307  *
308  *      If 'downcase' is true, any uppercase letters in domain names in
309  *      'source' will be downcased when they are copied into 'target'.
310  *
311  * Requires:
312  *
313  *      'rdclass' and 'type' are valid.
314  *
315  *      'lexer' is a valid isc_lex_t.
316  *
317  *      'mctx' is a valid isc_mem_t.
318  *
319  *      'target' is a valid region.
320  *
321  *      'origin' if non NULL it must be absolute.
322  *      
323  *      'callbacks' to be NULL or callbacks->warn and callbacks->error be
324  *      initialized.
325  *
326  * Ensures:
327  *      If result is success:
328  *              If 'rdata' is not NULL, it is attached to the target.
329  *
330  *              The conditions dns_name_fromtext() ensures for names hold
331  *              for all names in the rdata.
332  *
333  *              The used space in target is updated.
334  *
335  * Result:
336  *      Success
337  *      <Translated result codes from isc_lex_gettoken>
338  *      <Various 'Bad Form' class failures depending on class and type>
339  *      Bad Form: Input too short
340  *      Resource Limit: Not enough space
341  *      Resource Limit: Not enough memory
342  */
343
344 isc_result_t
345 dns_rdata_totext(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target);
346 /*
347  * Convert 'rdata' into text format, storing the result in 'target'.
348  * The text will consist of a single line, with fields separated by
349  * single spaces.
350  *
351  * Notes:
352  *      If 'origin' is not NULL, then any names in the rdata that are
353  *      subdomains of 'origin' will be made relative it.
354  *
355  *      XXX Do we *really* want to support 'origin'?  I'm inclined towards "no"
356  *      at the moment.
357  *
358  * Requires:
359  *
360  *      'rdata' is a valid, non-empty rdata
361  *
362  *      'origin' is NULL, or is a valid name
363  *
364  *      'target' is a valid text buffer
365  *
366  * Ensures:
367  *      If the result is success:
368  *
369  *              The used space in target is updated.
370  *
371  * Returns:
372  *      Success
373  *      <Any non-success status from dns_name_totext()>
374  *      Resource Limit: Not enough space
375  */
376
377 isc_result_t
378 dns_rdata_tofmttext(dns_rdata_t *rdata, dns_name_t *origin, unsigned int flags,
379                     unsigned int width, char *linebreak, isc_buffer_t *target);
380 /*
381  * Like dns_rdata_totext, but do formatted output suitable for
382  * database dumps.  This is intended for use by dns_db_dump();
383  * library users are discouraged from calling it directly.
384  *
385  * If (flags & DNS_STYLEFLAG_MULTILINE) != 0, attempt to stay
386  * within 'width' by breaking the text into multiple lines.
387  * The string 'linebreak' is inserted between lines, and parentheses
388  * are added when necessary.  Because RRs contain unbreakable elements
389  * such as domain names whose length is variable, unpredictable, and
390  * potentially large, there is no guarantee that the lines will
391  * not exceed 'width' anyway.
392  *
393  * If (flags & DNS_STYLEFLAG_MULTILINE) == 0, the rdata is always
394  * printed as a single line, and no parentheses are used.
395  * The 'width' and 'linebreak' arguments are ignored.
396  *
397  * If (flags & DNS_STYLEFLAG_COMMENT) != 0, output explanatory
398  * comments next to things like the SOA timer fields.  Some
399  * comments (e.g., the SOA ones) are only printed when multiline
400  * output is selected.
401  */
402
403 isc_result_t
404 dns_rdata_fromstruct(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
405                      dns_rdatatype_t type, void *source, isc_buffer_t *target);
406 /*
407  * Convert the C structure representation of an rdata into uncompressed wire
408  * format in 'target'.
409  *
410  * XXX  Should we have a 'size' parameter as a sanity check on target?
411  *
412  * Requires:
413  *
414  *      'rdclass' and 'type' are valid.
415  *
416  *      'source' points to a valid C struct for the class and type.
417  *
418  *      'target' is a valid buffer.
419  *
420  *      All structure pointers to memory blocks should be NULL if their
421  *      corresponding length values are zero.
422  *
423  * Ensures:
424  *      If result is success:
425  *              If 'rdata' is not NULL, it is attached to the target.
426  *
427  *              The used space in 'target' is updated.
428  *
429  * Result:
430  *      Success
431  *      <Various 'Bad Form' class failures depending on class and type>
432  *      Resource Limit: Not enough space
433  */
434
435 isc_result_t
436 dns_rdata_tostruct(dns_rdata_t *rdata, void *target, isc_mem_t *mctx);
437 /*
438  * Convert an rdata into its C structure representation.
439  *
440  * If 'mctx' is NULL then 'rdata' must persist while 'target' is being used.
441  *
442  * If 'mctx' is non NULL then memory will be allocated if required.
443  *
444  * Requires:
445  *
446  *      'rdata' is a valid, non-empty rdata.
447  *
448  *      'target' to point to a valid pointer for the type and class.
449  *
450  * Result:
451  *      Success
452  *      Resource Limit: Not enough memory
453  */
454
455 void
456 dns_rdata_freestruct(void *source);
457 /*
458  * Free dynamic memory attached to 'source' (if any).
459  *
460  * Requires:
461  *
462  *      'source' to point to the structure previously filled in by
463  *      dns_rdata_tostruct().
464  */
465
466 isc_boolean_t
467 dns_rdatatype_ismeta(dns_rdatatype_t type);
468 /*
469  * Return true iff the rdata type 'type' is a meta-type
470  * like ANY or AXFR.
471  */
472
473 isc_boolean_t
474 dns_rdatatype_issingleton(dns_rdatatype_t type);
475 /*
476  * Return true iff the rdata type 'type' is a singleton type,
477  * like CNAME or SOA.
478  *
479  * Requires:
480  *      'type' is a valid rdata type.
481  *
482  */
483
484 isc_boolean_t
485 dns_rdataclass_ismeta(dns_rdataclass_t rdclass);
486 /*
487  * Return true iff the rdata class 'rdclass' is a meta-class
488  * like ANY or NONE.
489  */
490
491 isc_boolean_t
492 dns_rdatatype_isdnssec(dns_rdatatype_t type);
493 /*
494  * Return true iff 'type' is one of the DNSSEC
495  * rdata types that may exist alongside a CNAME record.
496  *
497  * Requires:
498  *      'type' is a valid rdata type.
499  */
500
501 isc_boolean_t
502 dns_rdatatype_iszonecutauth(dns_rdatatype_t type);
503 /*
504  * Return true iff rdata of type 'type' is considered authoritative
505  * data (not glue) in the NXT chain when it occurs in the parent zone
506  * at a zone cut.
507  *
508  * Requires:
509  *      'type' is a valid rdata type.
510  *
511  */
512
513 isc_boolean_t
514 dns_rdatatype_isknown(dns_rdatatype_t type);
515 /*
516  * Return true iff the rdata type 'type' is known.
517  *
518  * Requires:
519  *      'type' is a valid rdata type.
520  *
521  */
522
523
524 isc_result_t
525 dns_rdata_additionaldata(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
526                          void *arg);
527 /*
528  * Call 'add' for each name and type from 'rdata' which is subject to
529  * additional section processing.
530  *
531  * Requires:
532  *
533  *      'rdata' is a valid, non-empty rdata.
534  *
535  *      'add' is a valid dns_additionalfunc_t.
536  *
537  * Ensures:
538  *
539  *      If successful, then add() will have been called for each name
540  *      and type subject to additional section processing.
541  *
542  *      If add() returns something other than ISC_R_SUCCESS, that result
543  *      will be returned as the result of dns_rdata_additionaldata().
544  *
545  * Returns:
546  *
547  *      ISC_R_SUCCESS
548  *
549  *      Many other results are possible if not successful.
550  */
551
552 isc_result_t
553 dns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg);
554 /*
555  * Send 'rdata' in DNSSEC canonical form to 'digest'.
556  *
557  * Note:
558  *      'digest' may be called more than once by dns_rdata_digest().  The
559  *      concatenation of all the regions, in the order they were given
560  *      to 'digest', will be the DNSSEC canonical form of 'rdata'.
561  *
562  * Requires:
563  *
564  *      'rdata' is a valid, non-empty rdata.
565  *
566  *      'digest' is a valid dns_digestfunc_t.
567  *
568  * Ensures:
569  *
570  *      If successful, then all of the rdata's data has been sent, in
571  *      DNSSEC canonical form, to 'digest'.
572  *
573  *      If digest() returns something other than ISC_R_SUCCESS, that result
574  *      will be returned as the result of dns_rdata_digest().
575  *
576  * Returns:
577  *
578  *      ISC_R_SUCCESS
579  *
580  *      Many other results are possible if not successful.
581  */
582
583 isc_boolean_t
584 dns_rdatatype_questiononly(dns_rdatatype_t type);
585 /*
586  * Return true iff rdata of type 'type' can only appear in the question
587  * section of a properly formatted message.
588  *
589  * Requires:
590  *      'type' is a valid rdata type.
591  *
592  */
593
594 isc_boolean_t
595 dns_rdatatype_notquestion(dns_rdatatype_t type);
596 /*
597  * Return true iff rdata of type 'type' can not appear in the question
598  * section of a properly formatted message.
599  *
600  * Requires:
601  *      'type' is a valid rdata type.
602  *
603  */
604
605 unsigned int
606 dns_rdatatype_attributes(dns_rdatatype_t rdtype);
607 /*
608  * Return attributes for the given type.
609  *
610  * Requires:
611  *      'rdtype' are known.
612  *
613  * Returns:
614  *      a bitmask consisting of the following flags.
615  */
616
617 /* only one may exist for a name */
618 #define DNS_RDATATYPEATTR_SINGLETON             0x00000001U
619 /* requires no other data be present */
620 #define DNS_RDATATYPEATTR_EXCLUSIVE             0x00000002U
621 /* Is a meta type */
622 #define DNS_RDATATYPEATTR_META                  0x00000004U
623 /* Is a DNSSEC type, like SIG or NXT */
624 #define DNS_RDATATYPEATTR_DNSSEC                0x00000008U
625 /* Is a zone cut authority type */
626 #define DNS_RDATATYPEATTR_ZONECUTAUTH           0x00000010U
627 /* Is reserved (unusable) */
628 #define DNS_RDATATYPEATTR_RESERVED              0x00000020U
629 /* Is an unknown type */
630 #define DNS_RDATATYPEATTR_UNKNOWN               0x00000040U
631 /* Is META, and can only be in a question section */
632 #define DNS_RDATATYPEATTR_QUESTIONONLY          0x00000080U
633 /* is META, and can NOT be in a question section */
634 #define DNS_RDATATYPEATTR_NOTQUESTION           0x00000100U
635
636 dns_rdatatype_t
637 dns_rdata_covers(dns_rdata_t *rdata);
638 /*
639  * Return the rdatatype that this type covers.
640  *
641  * Requires:
642  *      'rdata' is a valid, non-empty rdata.
643  *
644  *      'rdata' is a type that covers other rdata types.
645  *
646  * Returns:
647  *      The type covered.
648  */
649
650 ISC_LANG_ENDDECLS
651
652 #endif /* DNS_RDATA_H */