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 $ */
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
48 * Clients of this module must impose any required synchronization.
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.
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.
67 * Draft Binary Labels (2)
77 #include <isc/boolean.h>
79 #include <isc/magic.h>
80 #include <isc/region.h> /* Required for storage size of dns_label_t. */
82 #include <dns/types.h>
89 ***** A 'label' is basically a region. It contains one DNS wire format
90 ***** label of either type 00 (ordinary) or type 01000001 (bitstring).
94 *** Extended Label Types
97 #define DNS_LABELTYPE_BITSTRING 0x41
104 dns_label_type(dns_label_t
*label
);
106 * Get the type of 'label'.
109 * 'label' is a valid label (i.e. not NULL, points to a
111 * 'label' is a type 00 or type 01000001 label (i.e. not compressed).
114 * dns_labeltype_ordinary type 00 label
115 * dns_labeltype_bitstring type 01000001 label
123 dns_label_countbits(dns_label_t
*label
);
125 * The number of bits in a bitstring label.
128 * 'label' is a valid label
130 * dns_label_type(label) == dns_labeltype_bitstring
136 * The number of bits in the bitstring label.
140 dns_label_getbit(dns_label_t
*label
, unsigned int n
);
142 * The 'n'th most significant bit of 'label'.
145 * Numbering starts at 0.
148 * n < dns_label_countbits(label)
151 * dns_bitlabel_0 The bit was 0.
152 * dns_bitlabel_1 The bit was 1.
158 *** Some provision still needs to be made for splitting bitstring labels.
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.
173 *** Compression pointer chaining limit
176 #define DNS_POINTER_MAXHOPS 16
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.
189 unsigned char * ndata
;
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
227 dns_name_init(dns_name_t
*name
, unsigned char *offsets
);
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.
237 * 'name' is not NULL and points to a struct dns_name.
239 * offsets == NULL or offsets is a dns_offsets_t.
242 * 'name' is a valid name.
243 * dns_name_countlabels(name) == 0
244 * dns_name_isabsolute(name) == ISC_FALSE
248 dns_name_reset(dns_name_t
*name
);
250 * Reinitialize 'name'.
253 * This function distinguishes itself from dns_name_init() in two
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.
264 * 'name' is a valid name.
267 * 'name' is a valid name.
268 * dns_name_countlabels(name) == 0
269 * dns_name_isabsolute(name) == ISC_FALSE
273 dns_name_invalidate(dns_name_t
*name
);
275 * Make 'name' invalid.
278 * 'name' is a valid name.
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.
289 *** Dedicated Buffers
293 dns_name_setbuffer(dns_name_t
*name
, isc_buffer_t
*buffer
);
295 * Dedicate a buffer for use with 'name'.
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.
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.
318 dns_name_hasbuffer(const dns_name_t
*name
);
320 * Does 'name' have a dedicated buffer?
323 * 'name' is a valid name.
326 * ISC_TRUE 'name' has a dedicated buffer.
327 * ISC_FALSE 'name' does not have a dedicated buffer.
336 dns_name_isabsolute(const dns_name_t
*name
);
338 * Does 'name' end in the root label?
341 * 'name' is a valid name
344 * TRUE The last label in 'name' is the root label.
345 * FALSE The last label in 'name' is not the root label.
349 dns_name_iswildcard(const dns_name_t
*name
);
351 * Is 'name' a wildcard name?
354 * 'name' is a valid name
356 * dns_name_countlabels(name) > 0
359 * TRUE The least significant label of 'name' is '*'.
360 * FALSE The least significant label of 'name' is not '*'.
364 dns_name_requiresedns(const dns_name_t
*name
);
366 * Does 'name' require EDNS for transmission?
369 * 'name' is a valid name
371 * dns_name_countlabels(name) > 0
374 * TRUE The name requires EDNS to be transmitted.
375 * FALSE The name does not require EDNS to be transmitted.
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.
387 * 'name' is a valid name
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.
403 * 'name' is a valid name
414 dns_name_fullcompare(const dns_name_t
*name1
, const dns_name_t
*name2
,
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
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.
442 * *orderp is < 0 if name1 < name2, 0 if name1 = name2, > 0 if
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.
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
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
474 * 'name1' is a valid name
476 * 'name2' is a valid name
478 * Either name1 is absolute and name2 is absolute, or neither is.
481 * < 0 'name1' is less than 'name2'
482 * 0 'name1' is equal to 'name2'
483 * > 0 'name1' is greater than 'name2'
487 dns_name_equal(const dns_name_t
*name1
, const dns_name_t
*name2
);
489 * Are 'name1' and 'name2' equal?
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
503 * 'name1' is a valid name
505 * 'name2' is a valid name
507 * Either name1 is absolute and name2 is absolute, or neither is.
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
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
530 * < 0 'name1' is less than 'name2'
531 * 0 'name1' is equal to 'name2'
532 * > 0 'name1' is greater than 'name2'
536 dns_name_issubdomain(const dns_name_t
*name1
, const dns_name_t
*name2
);
538 * Is 'name1' a subdomain of 'name2'?
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
550 * 'name1' is a valid name
552 * 'name2' is a valid name
554 * Either name1 is absolute and name2 is absolute, or neither is.
557 * TRUE 'name1' is a subdomain of 'name2'
558 * FALSE 'name1' is not a subdomain of 'name2'
562 dns_name_matcheswildcard(const dns_name_t
*name
, const dns_name_t
*wname
);
564 * Does 'name' match the wildcard specified in 'wname'?
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
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.
590 * TRUE 'name' matches the wildcard specified in 'wname'
591 * FALSE 'name' does not match the wildcard specified in 'wname'
595 dns_name_depth(const dns_name_t
*name
);
597 * The depth of 'name'.
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
605 * Depth is used when creating or validating DNSSEC signatures.
608 * 'name' is a valid name
611 * The depth of 'name'.
619 dns_name_countlabels(const dns_name_t
*name
);
621 * How many labels does 'name' have?
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().
629 * 'name' is a valid name
632 * The result is <= 128.
635 * The number of labels in 'name'.
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'.
644 * Numbering starts at 0.
646 * Given "rc.vix.com.", the label 0 is "rc", and label 3 is the
649 * 'label' refers to the same memory as 'name', so 'name' must not
650 * be changed while 'label' is still in use.
653 * n < dns_label_countlabels(name)
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'
664 * Numbering starts at 0.
666 * Given "rc.vix.com.", the label 0 is "rc", and label 3 is the
669 * 'target' refers to the same memory as 'source', so 'source'
670 * must not be changed while 'target' is still in use.
673 * 'source' and 'target' are valid names.
675 * first < dns_label_countlabels(name)
677 * first + n <= dns_label_countlabels(name)
682 dns_name_clone(dns_name_t
*source
, dns_name_t
*target
);
684 * Make 'target' refer to the same name as 'source'.
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),
697 * but is more efficient. Also, dns_name_clone() works even if 'source'
702 * 'source' is a valid name.
704 * 'target' is a valid name that is not read-only.
712 dns_name_fromregion(dns_name_t
*name
, isc_region_t
*r
);
714 * Make 'name' refer to region 'r'.
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.
722 * The data in 'r' is a sequence of one or more type 00 or type 01000001
727 dns_name_toregion(dns_name_t
*name
, isc_region_t
*r
);
729 * Make 'r' refer to 'name'.
733 * 'name' is a valid name.
735 * 'r' is a valid region.
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,
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'.
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.
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.
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
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.
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
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'.
805 * If the compression context allows global compression, then the
806 * global compression table may be updated.
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
822 * If the result is success:
824 * The used space in target is updated.
828 * Resource Limit: Not enough space in buffer
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.
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'.
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.
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
866 * The current location in source is advanced, and the used space
867 * in target is updated.
875 * DNS_R_BITSTRINGTOOLONG
876 * DNS_R_BADDOTTEDQUAD
878 * ISC_R_UNEXPECTEDEND
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'.
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.
898 * 'name' is a valid name
900 * 'target' is a valid buffer.
902 * if dns_name_isabsolute == FALSE, then omit_final_dot == FALSE
906 * If the result is success:
908 * The used space in target is updated.
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
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.
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.
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.
954 * 'name' is a valid absolute name
956 * 'target' is a valid buffer.
960 * If the result is success:
962 * The used space in target is updated.
970 dns_name_downcase(dns_name_t
*source
, dns_name_t
*name
,
971 isc_buffer_t
*target
);
977 * 'source' and 'name' are valid names.
979 * If source == name, then
981 * 'source' must not be read-only
985 * 'target' is a valid buffer or 'target' is NULL and
986 * 'name' has a dedicated buffer.
992 * Note: if source == name, then the result will always be ISC_R_SUCCESS.
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'.
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.
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.
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.
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.
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'.
1083 * If 'prefix' is not NULL it will contain the least significant
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.
1091 * Either 'prefix' or 'suffix' is invalidated (depending
1092 * on which one the problem was encountered with).
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.
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.
1108 * 'name' is a valid non-empty name.
1112 * depth <= dns_name_depth(name)
1114 * The preconditions of dns_name_split() apply to 'prefix' and 'suffix'.
1119 * If 'prefix' is not NULL it will contain the least significant
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.
1127 * Either 'prefix' or 'suffix' is invalidated (depending
1128 * on which one the problem was encountered with).
1131 * The possible result codes are the same as those of dns_name_split().
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'.
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.
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.
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.
1167 dns_name_free(dns_name_t
*name
, isc_mem_t
*mctx
);
1173 * 'name' is a valid name created previously in 'mctx' by dns_name_dup().
1175 * 'mctx' is a valid memory context.
1179 * All dynamic resources used by 'name' are freed and the name is
1184 dns_name_digest(dns_name_t
*name
, dns_digestfunc_t digest
, void *arg
);
1186 * Send 'name' in DNSSEC canonical form to 'digest'.
1190 * 'name' is a valid name.
1192 * 'digest' is a valid dns_digestfunc_t.
1196 * If successful, the DNSSEC canonical form of 'name' will have been
1199 * If digest() returns something other than ISC_R_SUCCESS, that result
1200 * will be returned as the result of dns_name_digest().
1206 * Many other results are possible if not successful.
1211 dns_name_dynamic(dns_name_t
*name
);
1213 * Returns whether there is dynamic memory associated with this name.
1217 * 'name' is a valid name.
1221 * 'ISC_TRUE' if the name is dynamic othewise 'ISC_FALSE'.
1225 dns_name_print(dns_name_t
*name
, FILE *stream
);
1227 * Print 'name' on 'stream'.
1231 * 'name' is a valid name.
1233 * 'stream' is a valid stream.
1239 * Any error that dns_name_totext() can return.
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
1251 * The formatted name will have a terminating dot only if it is
1254 * This function cannot fail, instead any errors are indicated
1255 * in the returned text.
1259 * 'name' is a valid name.
1261 * 'cp' points a valid character array of size 'size'.
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.
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'.
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.
1290 * On success, the used space in target is updated.
1300 *** High Peformance Macros
1304 * WARNING: Use of these macros by applications may require recompilation
1305 * of the application in some situations where calling the function
1308 * WARNING: No assertion checking is done for these macros.
1311 #define DNS_NAME_INIT(n, o) \
1313 (n)->magic = DNS_NAME_MAGIC; \
1314 (n)->ndata = NULL; \
1317 (n)->attributes = 0; \
1318 (n)->offsets = (o); \
1319 (n)->buffer = NULL; \
1320 ISC_LINK_INIT((n), link); \
1321 ISC_LIST_INIT((n)->list); \
1324 #define DNS_NAME_RESET(n) \
1326 (n)->ndata = NULL; \
1329 (n)->attributes &= ~DNS_NAMEATTR_ABSOLUTE; \
1330 if ((n)->buffer != NULL) \
1331 isc_buffer_clear((n)->buffer); \
1334 #define DNS_NAME_SETBUFFER(n, b) \
1337 #define DNS_NAME_ISABSOLUTE(n) \
1338 (((n)->attributes & DNS_NAMEATTR_ABSOLUTE) != 0 ? ISC_TRUE : ISC_FALSE)
1340 #define DNS_NAME_COUNTLABELS(n) \
1343 #define DNS_NAME_TOREGION(n, r) \
1345 (r)->base = (n)->ndata; \
1346 (r)->length = (n)->length; \
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 */