Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / include / dns / name.h
blob41cc59958dfd9388ffea9224e822d885328fabbb
1 /*
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: name.h,v 1.95.2.7 2004/08/10 00:41:49 marka Exp $ */
20 #ifndef DNS_NAME_H
21 #define DNS_NAME_H 1
23 /*****
24 ***** Module Info
25 *****/
28 * DNS Names and Labels
30 * Provides facilities for manipulating DNS names and labels, including
31 * conversions to and from wire format and text format.
33 * Given the large number of names possible in a nameserver, and because
34 * names occur in rdata, it was important to come up with a very efficient
35 * way of storing name data, but at the same time allow names to be
36 * manipulated. The decision was to store names in uncompressed wire format,
37 * and not to make them fully abstracted objects; i.e. certain parts of the
38 * server know names are stored that way. This saves a lot of memory, and
39 * makes adding names to messages easy. Having much of the server know
40 * the representation would be perilous, and we certainly don't want each
41 * user of names to be manipulating such a low-level structure. This is
42 * where the Names and Labels module comes in. The module allows name or
43 * label handles to be created and attached to uncompressed wire format
44 * regions. All name operations and conversions are done through these
45 * handles.
47 * MP:
48 * Clients of this module must impose any required synchronization.
50 * Reliability:
51 * This module deals with low-level byte streams. Errors in any of
52 * the functions are likely to crash the server or corrupt memory.
54 * Resources:
55 * None.
57 * Security:
59 * *** WARNING ***
61 * dns_name_fromwire() deals with raw network data. An error in
62 * this routine could result in the failure or hijacking of the server.
64 * Standards:
65 * RFC 1035
66 * Draft EDNS0 (0)
67 * Draft Binary Labels (2)
71 /***
72 *** Imports
73 ***/
75 #include <stdio.h>
77 #include <isc/boolean.h>
78 #include <isc/lang.h>
79 #include <isc/magic.h>
80 #include <isc/region.h> /* Required for storage size of dns_label_t. */
82 #include <dns/types.h>
84 ISC_LANG_BEGINDECLS
86 /*****
87 ***** Labels
88 *****
89 ***** A 'label' is basically a region. It contains one DNS wire format
90 ***** label of either type 00 (ordinary) or type 01000001 (bitstring).
91 *****/
93 /***
94 *** Extended Label Types
95 ***/
97 #define DNS_LABELTYPE_BITSTRING 0x41
99 /***
100 *** Properties
101 ***/
103 dns_labeltype_t
104 dns_label_type(dns_label_t *label);
106 * Get the type of 'label'.
108 * Requires:
109 * 'label' is a valid label (i.e. not NULL, points to a
110 * struct dns_label)
111 * 'label' is a type 00 or type 01000001 label (i.e. not compressed).
113 * Returns:
114 * dns_labeltype_ordinary type 00 label
115 * dns_labeltype_bitstring type 01000001 label
118 /***
119 *** Bitstring Labels
120 ***/
122 unsigned int
123 dns_label_countbits(dns_label_t *label);
125 * The number of bits in a bitstring label.
127 * Requires:
128 * 'label' is a valid label
130 * dns_label_type(label) == dns_labeltype_bitstring
132 * Ensures:
133 * Result is <= 256.
135 * Returns:
136 * The number of bits in the bitstring label.
139 dns_bitlabel_t
140 dns_label_getbit(dns_label_t *label, unsigned int n);
142 * The 'n'th most significant bit of 'label'.
144 * Notes:
145 * Numbering starts at 0.
147 * Require:
148 * n < dns_label_countbits(label)
150 * Returns:
151 * dns_bitlabel_0 The bit was 0.
152 * dns_bitlabel_1 The bit was 1.
155 /***
156 *** Note
158 *** Some provision still needs to be made for splitting bitstring labels.
159 ***/
163 /*****
164 ***** Names
165 *****
166 ***** A 'name' is a handle to a binary region. It contains a sequence of one
167 ***** or more DNS wire format labels of either type 00 (ordinary) or type
168 ***** 01000001 (bitstring). Note that all names are not required to end
169 ***** with the root label, as they are in the actual DNS wire protocol.
170 *****/
172 /***
173 *** Compression pointer chaining limit
174 ***/
176 #define DNS_POINTER_MAXHOPS 16
178 /***
179 *** Types
180 ***/
183 * Clients are strongly discouraged from using this type directly, with
184 * the exception of the 'link' and 'list' fields which may be used directly
185 * for whatever purpose the client desires.
187 struct dns_name {
188 unsigned int magic;
189 unsigned char * ndata;
190 unsigned int length;
191 unsigned int labels;
192 unsigned int attributes;
193 unsigned char * offsets;
194 isc_buffer_t * buffer;
195 ISC_LINK(dns_name_t) link;
196 ISC_LIST(dns_rdataset_t) list;
199 #define DNS_NAME_MAGIC ISC_MAGIC('D','N','S','n')
201 #define DNS_NAMEATTR_ABSOLUTE 0x0001
202 #define DNS_NAMEATTR_READONLY 0x0002
203 #define DNS_NAMEATTR_DYNAMIC 0x0004
204 #define DNS_NAMEATTR_DYNOFFSETS 0x0008
206 * Attributes below 0x0100 reserved for name.c usage.
208 #define DNS_NAMEATTR_CACHE 0x0100 /* Used by resolver. */
209 #define DNS_NAMEATTR_ANSWER 0x0200 /* Used by resolver. */
210 #define DNS_NAMEATTR_NCACHE 0x0400 /* Used by resolver. */
211 #define DNS_NAMEATTR_CHAINING 0x0800 /* Used by resolver. */
212 #define DNS_NAMEATTR_CHASE 0x1000 /* Used by resolver. */
214 LIBDNS_EXTERNAL_DATA extern dns_name_t *dns_rootname;
215 extern dns_name_t *dns_wildcardname;
218 * Standard size of a wire format name
220 #define DNS_NAME_MAXWIRE 255
222 /***
223 *** Initialization
224 ***/
226 void
227 dns_name_init(dns_name_t *name, unsigned char *offsets);
229 * Initialize 'name'.
231 * Notes:
232 * 'offsets' is never required to be non-NULL, but specifying a
233 * dns_offsets_t for 'offsets' will improve the performance of most
234 * name operations if the name is used more than once.
236 * Requires:
237 * 'name' is not NULL and points to a struct dns_name.
239 * offsets == NULL or offsets is a dns_offsets_t.
241 * Ensures:
242 * 'name' is a valid name.
243 * dns_name_countlabels(name) == 0
244 * dns_name_isabsolute(name) == ISC_FALSE
247 void
248 dns_name_reset(dns_name_t *name);
250 * Reinitialize 'name'.
252 * Notes:
253 * This function distinguishes itself from dns_name_init() in two
254 * key ways:
256 * + If any buffer is associated with 'name' (via dns_name_setbuffer()
257 * or by being part of a dns_fixedname_t) the link to the buffer
258 * is retained but the buffer itself is cleared.
260 * + Of the attributes associated with 'name', all are retained except
261 * DNS_NAMEATTR_ABSOLUTE.
263 * Requires:
264 * 'name' is a valid name.
266 * Ensures:
267 * 'name' is a valid name.
268 * dns_name_countlabels(name) == 0
269 * dns_name_isabsolute(name) == ISC_FALSE
272 void
273 dns_name_invalidate(dns_name_t *name);
275 * Make 'name' invalid.
277 * Requires:
278 * 'name' is a valid name.
280 * Ensures:
281 * If assertion checking is enabled, future attempts to use 'name'
282 * without initializing it will cause an assertion failure.
284 * If the name had a dedicated buffer, that association is ended.
288 /***
289 *** Dedicated Buffers
290 ***/
292 void
293 dns_name_setbuffer(dns_name_t *name, isc_buffer_t *buffer);
295 * Dedicate a buffer for use with 'name'.
297 * Notes:
298 * Specification of a target buffer in dns_name_fromwire(),
299 * dns_name_fromtext(), and dns_name_concatentate() is optional if
300 * 'name' has a dedicated buffer.
302 * The caller must not write to buffer until the name has been
303 * invalidated or is otherwise known not to be in use.
305 * If buffer is NULL and the name previously had a dedicated buffer,
306 * than that buffer is no longer dedicated to use with this name.
307 * The caller is responsible for ensuring that the storage used by
308 * the name remains valid.
310 * Requires:
311 * 'name' is a valid name.
313 * 'buffer' is a valid binary buffer and 'name' doesn't have a
314 * dedicated buffer already, or 'buffer' is NULL.
317 isc_boolean_t
318 dns_name_hasbuffer(const dns_name_t *name);
320 * Does 'name' have a dedicated buffer?
322 * Requires:
323 * 'name' is a valid name.
325 * Returns:
326 * ISC_TRUE 'name' has a dedicated buffer.
327 * ISC_FALSE 'name' does not have a dedicated buffer.
331 /***
332 *** Properties
333 ***/
335 isc_boolean_t
336 dns_name_isabsolute(const dns_name_t *name);
338 * Does 'name' end in the root label?
340 * Requires:
341 * 'name' is a valid name
343 * Returns:
344 * TRUE The last label in 'name' is the root label.
345 * FALSE The last label in 'name' is not the root label.
348 isc_boolean_t
349 dns_name_iswildcard(const dns_name_t *name);
351 * Is 'name' a wildcard name?
353 * Requires:
354 * 'name' is a valid name
356 * dns_name_countlabels(name) > 0
358 * Returns:
359 * TRUE The least significant label of 'name' is '*'.
360 * FALSE The least significant label of 'name' is not '*'.
363 isc_boolean_t
364 dns_name_requiresedns(const dns_name_t *name);
366 * Does 'name' require EDNS for transmission?
368 * Requires:
369 * 'name' is a valid name
371 * dns_name_countlabels(name) > 0
373 * Returns:
374 * TRUE The name requires EDNS to be transmitted.
375 * FALSE The name does not require EDNS to be transmitted.
378 unsigned int
379 dns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive);
381 * Provide a hash value for 'name'.
383 * Note: if 'case_sensitive' is ISC_FALSE, then names which differ only in
384 * case will have the same hash value.
386 * Requires:
387 * 'name' is a valid name
389 * Returns:
390 * A hash value
393 unsigned int
394 dns_fullname_hash(dns_name_t *name, isc_boolean_t case_sensitive);
396 * Provide a hash value for 'name'. Unlike dns_name_hash(), this function
397 * always takes into account of the entire name to calculate the hash value.
399 * Note: if 'case_sensitive' is ISC_FALSE, then names which differ only in
400 * case will have the same hash value.
402 * Requires:
403 * 'name' is a valid name
405 * Returns:
406 * A hash value
409 /***
410 *** Comparisons
411 ***/
413 dns_namereln_t
414 dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2,
415 int *orderp,
416 unsigned int *nlabelsp, unsigned int *nbitsp);
418 * Determine the relative ordering under the DNSSEC order relation of
419 * 'name1' and 'name2', and also determine the hierarchical
420 * relationship of the names.
422 * Note: It makes no sense for one of the names to be relative and the
423 * other absolute. If both names are relative, then to be meaningfully
424 * compared the caller must ensure that they are both relative to the
425 * same domain.
427 * Requires:
428 * 'name1' is a valid name
430 * dns_name_countlabels(name1) > 0
432 * 'name2' is a valid name
434 * dns_name_countlabels(name2) > 0
436 * orderp, nlabelsp, and nbitsp are valid pointers.
438 * Either name1 is absolute and name2 is absolute, or neither is.
440 * Ensures:
442 * *orderp is < 0 if name1 < name2, 0 if name1 = name2, > 0 if
443 * name1 > name2.
445 * *nlabelsp is the number of common significant labels.
447 * If *nbitsp is non-zero, then the least-signficant of the
448 * common significant labels is a bitstring label, and the
449 * two names have *nbitsp significant bits in common.
451 * Returns:
452 * dns_namereln_none There's no hierarchical relationship
453 * between name1 and name2.
454 * dns_namereln_contains name1 properly contains name2; i.e.
455 * name2 is a proper subdomain of name1.
456 * dns_namereln_subdomain name1 is a proper subdomain of name2.
457 * dns_namereln_equal name1 and name2 are equal.
458 * dns_namereln_commonancestor name1 and name2 share a common
459 * ancestor.
463 dns_name_compare(const dns_name_t *name1, const dns_name_t *name2);
465 * Determine the relative ordering under the DNSSEC order relation of
466 * 'name1' and 'name2'.
468 * Note: It makes no sense for one of the names to be relative and the
469 * other absolute. If both names are relative, then to be meaningfully
470 * compared the caller must ensure that they are both relative to the
471 * same domain.
473 * Requires:
474 * 'name1' is a valid name
476 * 'name2' is a valid name
478 * Either name1 is absolute and name2 is absolute, or neither is.
480 * Returns:
481 * < 0 'name1' is less than 'name2'
482 * 0 'name1' is equal to 'name2'
483 * > 0 'name1' is greater than 'name2'
486 isc_boolean_t
487 dns_name_equal(const dns_name_t *name1, const dns_name_t *name2);
489 * Are 'name1' and 'name2' equal?
491 * Notes:
492 * Because it only needs to test for equality, dns_name_equal() can be
493 * significantly faster than dns_name_fullcompare() or dns_name_compare().
495 * Offsets tables are not used in the comparision.
497 * It makes no sense for one of the names to be relative and the
498 * other absolute. If both names are relative, then to be meaningfully
499 * compared the caller must ensure that they are both relative to the
500 * same domain.
502 * Requires:
503 * 'name1' is a valid name
505 * 'name2' is a valid name
507 * Either name1 is absolute and name2 is absolute, or neither is.
509 * Returns:
510 * ISC_TRUE 'name1' and 'name2' are equal
511 * ISC_FALSE 'name1' and 'name2' are not equal
515 dns_name_rdatacompare(const dns_name_t *name1, const dns_name_t *name2);
517 * Compare two names as if they are part of rdata in DNSSEC canonical
518 * form.
520 * Requires:
521 * 'name1' is a valid absolute name
523 * dns_name_countlabels(name1) > 0
525 * 'name2' is a valid absolute name
527 * dns_name_countlabels(name2) > 0
529 * Returns:
530 * < 0 'name1' is less than 'name2'
531 * 0 'name1' is equal to 'name2'
532 * > 0 'name1' is greater than 'name2'
535 isc_boolean_t
536 dns_name_issubdomain(const dns_name_t *name1, const dns_name_t *name2);
538 * Is 'name1' a subdomain of 'name2'?
540 * Notes:
541 * name1 is a subdomain of name2 if name1 is contained in name2, or
542 * name1 equals name2.
544 * It makes no sense for one of the names to be relative and the
545 * other absolute. If both names are relative, then to be meaningfully
546 * compared the caller must ensure that they are both relative to the
547 * same domain.
549 * Requires:
550 * 'name1' is a valid name
552 * 'name2' is a valid name
554 * Either name1 is absolute and name2 is absolute, or neither is.
556 * Returns:
557 * TRUE 'name1' is a subdomain of 'name2'
558 * FALSE 'name1' is not a subdomain of 'name2'
561 isc_boolean_t
562 dns_name_matcheswildcard(const dns_name_t *name, const dns_name_t *wname);
564 * Does 'name' match the wildcard specified in 'wname'?
566 * Notes:
567 * name matches the wildcard specified in wname if all labels
568 * following the wildcard in wname are identical to the same number
569 * of labels at the end of name.
571 * It makes no sense for one of the names to be relative and the
572 * other absolute. If both names are relative, then to be meaningfully
573 * compared the caller must ensure that they are both relative to the
574 * same domain.
576 * Requires:
577 * 'name' is a valid name
579 * dns_name_countlabels(name) > 0
581 * 'wname' is a valid name
583 * dns_name_countlabels(wname) > 0
585 * dns_name_iswildcard(wname) is true
587 * Either name is absolute and wname is absolute, or neither is.
589 * Returns:
590 * TRUE 'name' matches the wildcard specified in 'wname'
591 * FALSE 'name' does not match the wildcard specified in 'wname'
594 unsigned int
595 dns_name_depth(const dns_name_t *name);
597 * The depth of 'name'.
599 * Notes:
600 * The "depth" of a name represents how far down the DNS tree of trees
601 * the name is. For each wire-encoding label in name, the depth is
602 * increased by 1 for an ordinary label, and by the number of bits in
603 * a bitstring label.
605 * Depth is used when creating or validating DNSSEC signatures.
607 * Requires:
608 * 'name' is a valid name
610 * Returns:
611 * The depth of 'name'.
614 /***
615 *** Labels
616 ***/
618 unsigned int
619 dns_name_countlabels(const dns_name_t *name);
621 * How many labels does 'name' have?
623 * Notes:
624 * In this case, as in other places, a 'label' is an ordinary label
625 * or a bitstring label. The term is not meant to refer to individual
626 * bit labels. For that purpose, use dns_name_depth().
628 * Requires:
629 * 'name' is a valid name
631 * Ensures:
632 * The result is <= 128.
634 * Returns:
635 * The number of labels in 'name'.
638 void
639 dns_name_getlabel(const dns_name_t *name, unsigned int n, dns_label_t *label);
641 * Make 'label' refer to the 'n'th least significant label of 'name'.
643 * Notes:
644 * Numbering starts at 0.
646 * Given "rc.vix.com.", the label 0 is "rc", and label 3 is the
647 * root label.
649 * 'label' refers to the same memory as 'name', so 'name' must not
650 * be changed while 'label' is still in use.
652 * Requires:
653 * n < dns_label_countlabels(name)
656 void
657 dns_name_getlabelsequence(const dns_name_t *source, unsigned int first,
658 unsigned int n, dns_name_t *target);
660 * Make 'target' refer to the 'n' labels including and following 'first'
661 * in 'source'.
663 * Notes:
664 * Numbering starts at 0.
666 * Given "rc.vix.com.", the label 0 is "rc", and label 3 is the
667 * root label.
669 * 'target' refers to the same memory as 'source', so 'source'
670 * must not be changed while 'target' is still in use.
672 * Requires:
673 * 'source' and 'target' are valid names.
675 * first < dns_label_countlabels(name)
677 * first + n <= dns_label_countlabels(name)
681 void
682 dns_name_clone(dns_name_t *source, dns_name_t *target);
684 * Make 'target' refer to the same name as 'source'.
686 * Notes:
688 * 'target' refers to the same memory as 'source', so 'source'
689 * must not be changed while 'target' is still in use.
691 * This call is functionally equivalent to:
693 * dns_name_getlabelsequence(source, 0,
694 * dns_label_countlabels(source),
695 * target);
697 * but is more efficient. Also, dns_name_clone() works even if 'source'
698 * is empty.
700 * Requires:
702 * 'source' is a valid name.
704 * 'target' is a valid name that is not read-only.
707 /***
708 *** Conversions
709 ***/
711 void
712 dns_name_fromregion(dns_name_t *name, isc_region_t *r);
714 * Make 'name' refer to region 'r'.
716 * Note:
717 * If the conversion encounters a root label before the end of the
718 * region the conversion stops and the length is set to the length
719 * so far converted. A maximum of 255 bytes is converted.
721 * Requires:
722 * The data in 'r' is a sequence of one or more type 00 or type 01000001
723 * labels.
726 void
727 dns_name_toregion(dns_name_t *name, isc_region_t *r);
729 * Make 'r' refer to 'name'.
731 * Requires:
733 * 'name' is a valid name.
735 * 'r' is a valid region.
738 isc_result_t
739 dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
740 dns_decompress_t *dctx, isc_boolean_t downcase,
741 isc_buffer_t *target);
743 * Copy the possibly-compressed name at source (active region) into target,
744 * decompressing it.
746 * Notes:
747 * Decompression policy is controlled by 'dctx'.
749 * If 'downcase' is true, any uppercase letters in 'source' will be
750 * downcased when they are copied into 'target'.
752 * Security:
754 * *** WARNING ***
756 * This routine will often be used when 'source' contains raw network
757 * data. A programming error in this routine could result in a denial
758 * of service, or in the hijacking of the server.
760 * Requires:
762 * 'name' is a valid name.
764 * 'source' is a valid buffer and the first byte of the active
765 * region should be the first byte of a DNS wire format domain name.
767 * 'target' is a valid buffer or 'target' is NULL and 'name' has
768 * a dedicated buffer.
770 * 'dctx' is a valid decompression context.
772 * Ensures:
774 * If result is success:
775 * If 'target' is not NULL, 'name' is attached to it.
777 * Uppercase letters are downcased in the copy iff. 'downcase' is
778 * true.
780 * Any bitstring labels in source are canonicalized.
781 * (i.e. maximally packed and any padding bits zeroed.)
783 * The current location in source is advanced, and the used space
784 * in target is updated.
786 * Result:
787 * Success
788 * Bad Form: Label Length
789 * Bad Form: Unknown Label Type
790 * Bad Form: Name Length
791 * Bad Form: Compression type not allowed
792 * Bad Form: Bad compression pointer
793 * Bad Form: Input too short
794 * Resource Limit: Too many compression pointers
795 * Resource Limit: Not enough space in buffer
798 isc_result_t
799 dns_name_towire(dns_name_t *name, dns_compress_t *cctx, isc_buffer_t *target);
801 * Convert 'name' into wire format, compressing it as specified by the
802 * compression context 'cctx', and storing the result in 'target'.
804 * Notes:
805 * If the compression context allows global compression, then the
806 * global compression table may be updated.
808 * Requires:
809 * 'name' is a valid name
811 * dns_name_countlabels(name) > 0
813 * dns_name_isabsolute(name) == TRUE
815 * target is a valid buffer.
817 * Any offsets specified in a global compression table are valid
818 * for buffer.
820 * Ensures:
822 * If the result is success:
824 * The used space in target is updated.
826 * Returns:
827 * Success
828 * Resource Limit: Not enough space in buffer
831 isc_result_t
832 dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
833 dns_name_t *origin, isc_boolean_t downcase,
834 isc_buffer_t *target);
836 * Convert the textual representation of a DNS name at source
837 * into uncompressed wire form stored in target.
839 * Notes:
840 * Relative domain names will have 'origin' appended to them
841 * unless 'origin' is NULL, in which case relative domain names
842 * will remain relative.
844 * If 'downcase' is true, any uppercase letters in 'source' will be
845 * downcased when they are copied into 'target'.
847 * Requires:
849 * 'name' is a valid name.
851 * 'source' is a valid buffer.
853 * 'target' is a valid buffer or 'target' is NULL and 'name' has
854 * a dedicated buffer.
856 * Ensures:
858 * If result is success:
859 * If 'target' is not NULL, 'name' is attached to it.
861 * Any bitstring labels in source are canonicalized.
863 * Uppercase letters are downcased in the copy iff. 'downcase' is
864 * true.
866 * The current location in source is advanced, and the used space
867 * in target is updated.
869 * Result:
870 * ISC_R_SUCCESS
871 * DNS_R_EMPTYLABEL
872 * DNS_R_LABELTOOLONG
873 * DNS_R_BADESCAPE
874 * DNS_R_BADBITSTRING
875 * DNS_R_BITSTRINGTOOLONG
876 * DNS_R_BADDOTTEDQUAD
877 * ISC_R_NOSPACE
878 * ISC_R_UNEXPECTEDEND
881 isc_result_t
882 dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
883 isc_buffer_t *target);
885 * Convert 'name' into text format, storing the result in 'target'.
887 * Notes:
888 * If 'omit_final_dot' is true, then the final '.' in absolute
889 * names other than the root name will be omitted.
891 * If dns_name_countlabels == 0, the name will be "@", representing the
892 * current origin as described by RFC 1035.
894 * The name is not NUL terminated.
896 * Requires:
898 * 'name' is a valid name
900 * 'target' is a valid buffer.
902 * if dns_name_isabsolute == FALSE, then omit_final_dot == FALSE
904 * Ensures:
906 * If the result is success:
908 * The used space in target is updated.
910 * Returns:
911 * ISC_R_SUCCESS
912 * ISC_R_NOSPACE
915 #define DNS_NAME_MAXTEXT 1023
917 * The maximum length of the text representation of a domain
918 * name as generated by dns_name_totext(). This does not
919 * include space for a terminating NULL.
921 * This definition is conservative - the actual maximum
922 * is 1004, derived as follows:
924 * A backslash-decimal escaped character takes 4 bytes.
925 * A wire-encoded name can be up to 255 bytes and each
926 * label is one length byte + at most 63 bytes of data.
927 * Maximizing the label lengths gives us a name of
928 * three 63-octet labels, one 61-octet label, and the
929 * root label:
931 * 1 + 63 + 1 + 63 + 1 + 63 + 1 + 61 + 1 = 255
933 * When printed, this is (3 * 63 + 61) * 4
934 * bytes for the escaped label data + 4 bytes for the
935 * dot terminating each label = 1004 bytes total.
938 isc_result_t
939 dns_name_tofilenametext(dns_name_t *name, isc_boolean_t omit_final_dot,
940 isc_buffer_t *target);
942 * Convert 'name' into an alternate text format appropriate for filenames,
943 * storing the result in 'target'. The name data is downcased, guaranteeing
944 * that the filename does not depend on the case of the converted name.
946 * Notes:
947 * If 'omit_final_dot' is true, then the final '.' in absolute
948 * names other than the root name will be omitted.
950 * The name is not NUL terminated.
952 * Requires:
954 * 'name' is a valid absolute name
956 * 'target' is a valid buffer.
958 * Ensures:
960 * If the result is success:
962 * The used space in target is updated.
964 * Returns:
965 * ISC_R_SUCCESS
966 * ISC_R_NOSPACE
969 isc_result_t
970 dns_name_downcase(dns_name_t *source, dns_name_t *name,
971 isc_buffer_t *target);
973 * Downcase 'source'.
975 * Requires:
977 * 'source' and 'name' are valid names.
979 * If source == name, then
981 * 'source' must not be read-only
983 * Otherwise,
985 * 'target' is a valid buffer or 'target' is NULL and
986 * 'name' has a dedicated buffer.
988 * Returns:
989 * ISC_R_SUCCESS
990 * ISC_R_NOSPACE
992 * Note: if source == name, then the result will always be ISC_R_SUCCESS.
995 isc_result_t
996 dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix,
997 dns_name_t *name, isc_buffer_t *target);
999 * Concatenate 'prefix' and 'suffix'.
1001 * Requires:
1003 * 'prefix' is a valid name or NULL.
1005 * 'suffix' is a valid name or NULL.
1007 * 'name' is a valid name or NULL.
1009 * 'target' is a valid buffer or 'target' is NULL and 'name' has
1010 * a dedicated buffer.
1012 * If 'prefix' is absolute, 'suffix' must be NULL or the empty name.
1014 * Ensures:
1016 * On success,
1017 * If 'target' is not NULL and 'name' is not NULL, then 'name'
1018 * is attached to it.
1020 * Any bitstring labels are in canonical form.
1022 * The used space in target is updated.
1024 * Returns:
1025 * ISC_R_SUCCESS
1026 * ISC_R_NOSPACE
1027 * DNS_R_NAMETOOLONG
1030 isc_result_t
1031 dns_name_split(dns_name_t *name,
1032 unsigned int suffixlabels, unsigned int nbits,
1033 dns_name_t *prefix, dns_name_t *suffix);
1036 * Split 'name' into two pieces on a label or bitlabel boundary.
1038 * Notes:
1039 * 'name' is split such that 'suffix' holds the most significant
1040 * 'suffixlabels' labels, except that if the least significant
1041 * suffix label is a bitstring label, then only the 'nbits' most
1042 * significant bits of that label are included in 'suffix'. All
1043 * other labels and bits are stored in 'prefix'.
1045 * Copying name data is avoided as much as possible, so 'prefix'
1046 * and 'suffix' will usually end up pointing at the data for 'name',
1047 * except when 'nbits' > 0. The name data is copied to the
1048 * the dedicated buffers when splitting on bitlabel boundaries
1049 * because of the bit fiddling that must be done.
1051 * It is legitimate to pass a 'prefix' or 'suffix' that has
1052 * its name data stored someplace other than the dedicated buffer.
1053 * This is useful to avoid name copying in the calling function.
1055 * It is also legitimate to pass a 'prefix' or 'suffix' that is
1056 * the same dns_name_t as 'name', but note well the requirement
1057 * below if splitting on a bitlabel boundary.
1059 * Requires:
1060 * 'name' is a valid name.
1062 * 'suffixlabels' cannot exceed the number of labels in 'name'.
1064 * 'nbits' can be greater than zero only when the least significant
1065 * label of 'suffix' is a bitstring label.
1067 * 'nbits' cannot exceed the number of bits in the bitstring label.
1069 * 'prefix' is a valid name or NULL, and cannot be read-only.
1071 * 'suffix' is a valid name or NULL, and cannot be read-only.
1073 * If non-NULL, 'prefix' and 'suffix' must have dedicated buffers.
1075 * 'prefix' and 'suffix' cannot point to the same buffer.
1077 * If 'nbits' > 0 and 'prefix' and 'suffix' are both non-NULL,
1078 * the buffer for 'prefix' cannot be storing the labels for 'name'.
1080 * Ensures:
1082 * On success:
1083 * If 'prefix' is not NULL it will contain the least significant
1084 * labels and bits.
1086 * If 'suffix' is not NULL it will contain the most significant
1087 * labels and bits. dns_name_countlabels(suffix) will be
1088 * equal to suffixlabels.
1090 * On failure:
1091 * Either 'prefix' or 'suffix' is invalidated (depending
1092 * on which one the problem was encountered with).
1094 * Returns:
1095 * ISC_R_SUCCESS No worries.
1096 * ISC_R_NOSPACE An attempt was made to split a name on a bitlabel
1097 * boundary but either 'prefix' or 'suffix' did not
1098 * have enough room to receive the split name.
1101 isc_result_t
1102 dns_name_splitatdepth(dns_name_t *name, unsigned int depth,
1103 dns_name_t *prefix, dns_name_t *suffix);
1105 * Split 'name' into two pieces at a certain depth.
1107 * Requires:
1108 * 'name' is a valid non-empty name.
1110 * depth > 0
1112 * depth <= dns_name_depth(name)
1114 * The preconditions of dns_name_split() apply to 'prefix' and 'suffix'.
1116 * Ensures:
1118 * On success:
1119 * If 'prefix' is not NULL it will contain the least significant
1120 * labels and bits.
1122 * If 'suffix' is not NULL it will contain the most significant
1123 * labels and bits. dns_name_countlabels(suffix) will be
1124 * equal to suffixlabels.
1126 * On failure:
1127 * Either 'prefix' or 'suffix' is invalidated (depending
1128 * on which one the problem was encountered with).
1130 * Returns:
1131 * The possible result codes are the same as those of dns_name_split().
1134 isc_result_t
1135 dns_name_dup(dns_name_t *source, isc_mem_t *mctx, dns_name_t *target);
1137 * Make 'target' a dynamically allocated copy of 'source'.
1139 * Requires:
1141 * 'source' is a valid non-empty name.
1143 * 'target' is a valid name that is not read-only.
1145 * 'mctx' is a valid memory context.
1148 isc_result_t
1149 dns_name_dupwithoffsets(dns_name_t *source, isc_mem_t *mctx,
1150 dns_name_t *target);
1152 * Make 'target' a read-only dynamically allocated copy of 'source'.
1153 * 'target' will also have a dynamically allocated offsets table.
1155 * Requires:
1157 * 'source' is a valid non-empty name.
1159 * 'target' is a valid name that is not read-only.
1161 * 'target' has no offsets table.
1163 * 'mctx' is a valid memory context.
1166 void
1167 dns_name_free(dns_name_t *name, isc_mem_t *mctx);
1169 * Free 'name'.
1171 * Requires:
1173 * 'name' is a valid name created previously in 'mctx' by dns_name_dup().
1175 * 'mctx' is a valid memory context.
1177 * Ensures:
1179 * All dynamic resources used by 'name' are freed and the name is
1180 * invalidated.
1183 isc_result_t
1184 dns_name_digest(dns_name_t *name, dns_digestfunc_t digest, void *arg);
1186 * Send 'name' in DNSSEC canonical form to 'digest'.
1188 * Requires:
1190 * 'name' is a valid name.
1192 * 'digest' is a valid dns_digestfunc_t.
1194 * Ensures:
1196 * If successful, the DNSSEC canonical form of 'name' will have been
1197 * sent to 'digest'.
1199 * If digest() returns something other than ISC_R_SUCCESS, that result
1200 * will be returned as the result of dns_name_digest().
1202 * Returns:
1204 * ISC_R_SUCCESS
1206 * Many other results are possible if not successful.
1210 isc_boolean_t
1211 dns_name_dynamic(dns_name_t *name);
1213 * Returns whether there is dynamic memory associated with this name.
1215 * Requires:
1217 * 'name' is a valid name.
1219 * Returns:
1221 * 'ISC_TRUE' if the name is dynamic othewise 'ISC_FALSE'.
1224 isc_result_t
1225 dns_name_print(dns_name_t *name, FILE *stream);
1227 * Print 'name' on 'stream'.
1229 * Requires:
1231 * 'name' is a valid name.
1233 * 'stream' is a valid stream.
1235 * Returns:
1237 * ISC_R_SUCCESS
1239 * Any error that dns_name_totext() can return.
1242 void
1243 dns_name_format(dns_name_t *name, char *cp, unsigned int size);
1245 * Format 'name' as text appropriate for use in log messages.
1247 * Store the formatted name at 'cp', writing no more than
1248 * 'size' bytes. The resulting string is guaranteed to be
1249 * null terminated.
1251 * The formatted name will have a terminating dot only if it is
1252 * the root.
1254 * This function cannot fail, instead any errors are indicated
1255 * in the returned text.
1257 * Requires:
1259 * 'name' is a valid name.
1261 * 'cp' points a valid character array of size 'size'.
1263 * 'size' > 0.
1267 #define DNS_NAME_FORMATSIZE (DNS_NAME_MAXTEXT + 1)
1269 * Suggested size of buffer passed to dns_name_format().
1270 * Includes space for the terminating NULL.
1273 isc_result_t
1274 dns_name_copy(dns_name_t *source, dns_name_t *dest, isc_buffer_t *target);
1276 * Makes 'dest' refer to a copy of the name in 'source'. The data are
1277 * either copied to 'target' or the dedicated buffer in 'dest'.
1279 * Requires:
1280 * 'source' is a valid name.
1282 * 'dest' is an initialized name with a dedicated buffer.
1284 * 'target' is NULL or an initialized buffer.
1286 * Either dest has a dedicated buffer or target != NULL.
1288 * Ensures:
1290 * On success, the used space in target is updated.
1292 * Returns:
1293 * ISC_R_SUCCESS
1294 * ISC_R_NOSPACE
1297 ISC_LANG_ENDDECLS
1299 /***
1300 *** High Peformance Macros
1301 ***/
1304 * WARNING: Use of these macros by applications may require recompilation
1305 * of the application in some situations where calling the function
1306 * would not.
1308 * WARNING: No assertion checking is done for these macros.
1311 #define DNS_NAME_INIT(n, o) \
1312 do { \
1313 (n)->magic = DNS_NAME_MAGIC; \
1314 (n)->ndata = NULL; \
1315 (n)->length = 0; \
1316 (n)->labels = 0; \
1317 (n)->attributes = 0; \
1318 (n)->offsets = (o); \
1319 (n)->buffer = NULL; \
1320 ISC_LINK_INIT((n), link); \
1321 ISC_LIST_INIT((n)->list); \
1322 } while (0)
1324 #define DNS_NAME_RESET(n) \
1325 do { \
1326 (n)->ndata = NULL; \
1327 (n)->length = 0; \
1328 (n)->labels = 0; \
1329 (n)->attributes &= ~DNS_NAMEATTR_ABSOLUTE; \
1330 if ((n)->buffer != NULL) \
1331 isc_buffer_clear((n)->buffer); \
1332 } while (0)
1334 #define DNS_NAME_SETBUFFER(n, b) \
1335 (n)->buffer = (b)
1337 #define DNS_NAME_ISABSOLUTE(n) \
1338 (((n)->attributes & DNS_NAMEATTR_ABSOLUTE) != 0 ? ISC_TRUE : ISC_FALSE)
1340 #define DNS_NAME_COUNTLABELS(n) \
1341 ((n)->labels)
1343 #define DNS_NAME_TOREGION(n, r) \
1344 do { \
1345 (r)->base = (n)->ndata; \
1346 (r)->length = (n)->length; \
1347 } while (0)
1350 #ifdef DNS_NAME_USEINLINE
1352 #define dns_name_init(n, o) DNS_NAME_INIT(n, o)
1353 #define dns_name_reset(n) DNS_NAME_RESET(n)
1354 #define dns_name_setbuffer(n, b) DNS_NAME_SETBUFFER(n, b)
1355 #define dns_name_countlabels(n) DNS_NAME_COUNTLABELS(n)
1356 #define dns_name_isabsolute(n) DNS_NAME_ISABSOLUTE(n)
1357 #define dns_name_toregion(n, r) DNS_NAME_TOREGION(n, r)
1359 #endif /* DNS_NAME_USEINLINE */
1361 #endif /* DNS_NAME_H */