2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2003 Internet Software Consortium.
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.
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.
18 /* $Id: rdata.h,v 1.51.2.5 2004/03/09 06:11:20 marka Exp $ */
30 * Provides facilities for manipulating DNS rdata, including conversions to
31 * and from wire format and text format.
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.
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.
47 * Implementation Notes:
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.
57 * Clients of this module must impose any required synchronization.
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.
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.
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
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.
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.>
98 #include <dns/types.h>
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.
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.
120 unsigned char * data;
122 dns_rdataclass_t rdclass;
123 dns_rdatatype_t type;
125 ISC_LINK(dns_rdata_t) link;
128 #define DNS_RDATA_INIT { NULL, 0, 0, 0, 0, {(void*)(-1), (void *)(-1)}}
130 #define DNS_RDATA_UPDATE 0x0001 /* update pseudo record */
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().
138 /* Split the rdata into multiple lines to try to keep it
139 within the "width". */
140 #define DNS_STYLEFLAG_MULTILINE 0x00000001U
142 /* Output explanatory comments. */
143 #define DNS_STYLEFLAG_COMMENT 0x00000002U
150 dns_rdata_init(dns_rdata_t *rdata);
152 * Make 'rdata' empty.
155 * 'rdata' is a valid rdata (i.e. not NULL, points to a struct dns_rdata)
159 dns_rdata_reset(dns_rdata_t *rdata);
161 * Make 'rdata' empty.
164 * 'rdata' is a previously initialized rdata and is not linked.
168 dns_rdata_clone(const dns_rdata_t *src, dns_rdata_t *target);
170 * Clone 'target' from 'src'.
173 * 'src' to be initialized.
174 * 'target' to be initialized.
182 dns_rdata_compare(const dns_rdata_t *rdata1, const dns_rdata_t *rdata2);
184 * Determine the relative ordering under the DNSSEC order relation of
185 * 'rdata1' and 'rdata2'.
189 * 'rdata1' is a valid, non-empty rdata
191 * 'rdata2' is a valid, non-empty rdata
194 * < 0 'rdata1' is less than 'rdata2'
195 * 0 'rdata1' is equal to 'rdata2'
196 * > 0 'rdata1' is greater than 'rdata2'
204 dns_rdata_fromregion(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
205 dns_rdatatype_t type, isc_region_t *r);
207 * Make 'rdata' refer to region 'r'.
211 * The data in 'r' is properly formatted for whatever type it is.
215 dns_rdata_toregion(const dns_rdata_t *rdata, isc_region_t *r);
217 * Make 'r' refer to 'rdata'.
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);
227 * Copy the possibly-compressed rdata at source into the target region.
230 * Name decompression policy is controlled by 'dctx'.
232 * If 'downcase' is true, any uppercase letters in domain names in
233 * 'source' will be downcased when they are copied into 'target'.
237 * 'rdclass' and 'type' are valid.
239 * 'source' is a valid buffer, and the active region of 'source'
240 * references the rdata to be processed.
242 * 'target' is a valid buffer.
244 * 'dctx' is a valid decompression context.
248 * If result is success:
249 * If 'rdata' is not NULL, it is attached to the target.
251 * The conditions dns_name_fromwire() ensures for names hold
252 * for all names in the rdata.
254 * The current location in source is advanced, and the used space
255 * in target is updated.
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
266 dns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx,
267 isc_buffer_t *target);
269 * Convert 'rdata' into wire format, compressing it as specified by the
270 * compression context 'cctx', and storing the result in 'target'.
273 * If the compression context allows global compression, then the
274 * global compression table may be updated.
277 * 'rdata' is a valid, non-empty rdata
279 * target is a valid buffer
281 * Any offsets specified in a global compression table are valid
285 * If the result is success:
286 * The used space in target is updated.
290 * <Any non-success status from dns_name_towire()>
291 * Resource Limit: Not enough space
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);
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'.
305 * Relative domain names in the rdata will have 'origin' appended to them.
306 * A NULL origin implies "origin == dns_rootname".
308 * If 'downcase' is true, any uppercase letters in domain names in
309 * 'source' will be downcased when they are copied into 'target'.
313 * 'rdclass' and 'type' are valid.
315 * 'lexer' is a valid isc_lex_t.
317 * 'mctx' is a valid isc_mem_t.
319 * 'target' is a valid region.
321 * 'origin' if non NULL it must be absolute.
323 * 'callbacks' to be NULL or callbacks->warn and callbacks->error be
327 * If result is success:
328 * If 'rdata' is not NULL, it is attached to the target.
330 * The conditions dns_name_fromtext() ensures for names hold
331 * for all names in the rdata.
333 * The used space in target is updated.
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
345 dns_rdata_totext(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target);
347 * Convert 'rdata' into text format, storing the result in 'target'.
348 * The text will consist of a single line, with fields separated by
352 * If 'origin' is not NULL, then any names in the rdata that are
353 * subdomains of 'origin' will be made relative it.
355 * XXX Do we *really* want to support 'origin'? I'm inclined towards "no"
360 * 'rdata' is a valid, non-empty rdata
362 * 'origin' is NULL, or is a valid name
364 * 'target' is a valid text buffer
367 * If the result is success:
369 * The used space in target is updated.
373 * <Any non-success status from dns_name_totext()>
374 * Resource Limit: Not enough space
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);
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.
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.
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.
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.
404 dns_rdata_fromstruct(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
405 dns_rdatatype_t type, void *source, isc_buffer_t *target);
407 * Convert the C structure representation of an rdata into uncompressed wire
408 * format in 'target'.
410 * XXX Should we have a 'size' parameter as a sanity check on target?
414 * 'rdclass' and 'type' are valid.
416 * 'source' points to a valid C struct for the class and type.
418 * 'target' is a valid buffer.
420 * All structure pointers to memory blocks should be NULL if their
421 * corresponding length values are zero.
424 * If result is success:
425 * If 'rdata' is not NULL, it is attached to the target.
427 * The used space in 'target' is updated.
431 * <Various 'Bad Form' class failures depending on class and type>
432 * Resource Limit: Not enough space
436 dns_rdata_tostruct(dns_rdata_t *rdata, void *target, isc_mem_t *mctx);
438 * Convert an rdata into its C structure representation.
440 * If 'mctx' is NULL then 'rdata' must persist while 'target' is being used.
442 * If 'mctx' is non NULL then memory will be allocated if required.
446 * 'rdata' is a valid, non-empty rdata.
448 * 'target' to point to a valid pointer for the type and class.
452 * Resource Limit: Not enough memory
456 dns_rdata_freestruct(void *source);
458 * Free dynamic memory attached to 'source' (if any).
462 * 'source' to point to the structure previously filled in by
463 * dns_rdata_tostruct().
467 dns_rdatatype_ismeta(dns_rdatatype_t type);
469 * Return true iff the rdata type 'type' is a meta-type
474 dns_rdatatype_issingleton(dns_rdatatype_t type);
476 * Return true iff the rdata type 'type' is a singleton type,
480 * 'type' is a valid rdata type.
485 dns_rdataclass_ismeta(dns_rdataclass_t rdclass);
487 * Return true iff the rdata class 'rdclass' is a meta-class
492 dns_rdatatype_isdnssec(dns_rdatatype_t type);
494 * Return true iff 'type' is one of the DNSSEC
495 * rdata types that may exist alongside a CNAME record.
498 * 'type' is a valid rdata type.
502 dns_rdatatype_iszonecutauth(dns_rdatatype_t type);
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
509 * 'type' is a valid rdata type.
514 dns_rdatatype_isknown(dns_rdatatype_t type);
516 * Return true iff the rdata type 'type' is known.
519 * 'type' is a valid rdata type.
525 dns_rdata_additionaldata(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
528 * Call 'add' for each name and type from 'rdata' which is subject to
529 * additional section processing.
533 * 'rdata' is a valid, non-empty rdata.
535 * 'add' is a valid dns_additionalfunc_t.
539 * If successful, then add() will have been called for each name
540 * and type subject to additional section processing.
542 * If add() returns something other than ISC_R_SUCCESS, that result
543 * will be returned as the result of dns_rdata_additionaldata().
549 * Many other results are possible if not successful.
553 dns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg);
555 * Send 'rdata' in DNSSEC canonical form to 'digest'.
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'.
564 * 'rdata' is a valid, non-empty rdata.
566 * 'digest' is a valid dns_digestfunc_t.
570 * If successful, then all of the rdata's data has been sent, in
571 * DNSSEC canonical form, to 'digest'.
573 * If digest() returns something other than ISC_R_SUCCESS, that result
574 * will be returned as the result of dns_rdata_digest().
580 * Many other results are possible if not successful.
584 dns_rdatatype_questiononly(dns_rdatatype_t type);
586 * Return true iff rdata of type 'type' can only appear in the question
587 * section of a properly formatted message.
590 * 'type' is a valid rdata type.
595 dns_rdatatype_notquestion(dns_rdatatype_t type);
597 * Return true iff rdata of type 'type' can not appear in the question
598 * section of a properly formatted message.
601 * 'type' is a valid rdata type.
606 dns_rdatatype_attributes(dns_rdatatype_t rdtype);
608 * Return attributes for the given type.
611 * 'rdtype' are known.
614 * a bitmask consisting of the following flags.
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
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
637 dns_rdata_covers(dns_rdata_t *rdata);
639 * Return the rdatatype that this type covers.
642 * 'rdata' is a valid, non-empty rdata.
644 * 'rdata' is a type that covers other rdata types.
652 #endif /* DNS_RDATA_H */