name.c revision 77efdc854b2ec50641e4b9e428326ad71f662b25
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1998-2001 Internet Software Consortium.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * copyright notice and this permission notice appear in all copies.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
fc8a6561cbb0a1fea849950a3217aacd3b8f1eacDavid Lawrence/* $Id: name.c,v 1.126 2001/06/21 01:30:22 gson Exp $ */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#define VALID_NAME(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC)
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic unsigned char maptolower[] = {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#define INIT_OFFSETS(name, var, default) \
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#define SETUP_OFFSETS(name, var, default) \
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson * Note: If additional attributes are added that should not be set for
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson * empty names, MAKE_EMPTY() must be changed so it clears them.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; \
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * A name is "bindable" if it can be set to point to a new value, i.e.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * name->ndata and name->length may be changed.
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson ((name->attributes & (DNS_NAMEATTR_READONLY|DNS_NAMEATTR_DYNAMIC)) \
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Note that the name data must be a char array, not a string
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * literal, to avoid compiler warnings about discarding
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the const attribute of a string.
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafssonstatic unsigned char root_ndata[] = { '\0' };
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graffstatic unsigned char root_offsets[] = { 0 };
7618f0551eb745354ee695907e568b0be1f2c8f5Andreas Gustafsson DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
f80ea74e1984e0b1dbe48dd86ecdd3a2380393cbBob Halley/* XXXDCL make const? */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic unsigned char wild_ndata[] = { '\001', '*' };
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic unsigned char wild_offsets[] = { 0 };
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson/* XXXDCL make const? */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonset_offsets(const dns_name_t *name, unsigned char *offsets,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssoncompact(dns_name_t *name, unsigned char *offsets);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Yes, get_bit and set_bit are lame. We define them here so they can
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * be inlined by smart compilers.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic inline unsigned int
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic inline void
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonset_bit(unsigned char *array, unsigned int idx, unsigned int bit) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Get the type of 'label'.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson label->base[0] == DNS_LABELTYPE_BITSTRING);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * The number of bits in a bitstring label.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson REQUIRE(label->base[0] == DNS_LABELTYPE_BITSTRING);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_label_getbit(dns_label_t *label, unsigned int n) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * The 'n'th most significant bit of 'label'.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Numbering starts at 0.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson REQUIRE(label->base[0] == DNS_LABELTYPE_BITSTRING);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_name_init(dns_name_t *name, unsigned char *offsets) {
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson * Initialize 'name'.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Make 'name' invalid.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_name_setbuffer(dns_name_t *name, isc_buffer_t *buffer) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Dedicate a buffer for use with 'name'.
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson REQUIRE((buffer != NULL && name->buffer == NULL) ||
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_name_hasbuffer(const dns_name_t *name) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Does 'name' have a dedicated buffer?
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafssondns_name_isabsolute(const dns_name_t *name) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Does 'name' end in the root label?
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson if ((name->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_name_iswildcard(const dns_name_t *name) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson unsigned char *ndata;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Is 'name' a wildcard name?
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafssondns_name_requiresedns(const dns_name_t *name) {
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson unsigned char *ndata;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * Does 'name' require EDNS for transmission?
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson INSIST(count == DNS_LABELTYPE_BITSTRING);
a243aeb92b5937c22d578deb0f98d3501bf86f4aAndreas Gustafssondns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) {
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson const unsigned char *s;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson unsigned int h = 0;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson unsigned char c;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * Provide a hash value for 'name'.
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * This hash function is similar to the one Ousterhout
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * uses in Tcl.
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson h += ( h << 3 ) + *s;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson h += ( h << 3 ) + c;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafssondns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2,
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson unsigned int *nlabelsp, unsigned int *nbitsp)
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson unsigned int l1, l2, l, count1, count2, count;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson dns_namereln_t namereln = dns_namereln_none;
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * Determine the relative ordering under the DNSSEC order relation of
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff * 'name1' and 'name2', and also determine the hierarchical
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff * relationship of the names.
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff * Note: It makes no sense for one of the names to be relative and the
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * other absolute. If both names are relative, then to be meaningfully
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * compared the caller must ensure that they are both relative to the
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * same domain.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Either name1 is absolute and name2 is absolute, or neither is.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) ==
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson (name2->attributes & DNS_NAMEATTR_ABSOLUTE));
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson while (l > 0) {
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson } else if (count1 == DNS_LABELTYPE_BITSTRING && count2 <= 63) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson } else if (count2 == DNS_LABELTYPE_BITSTRING && count1 <= 63) {
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson INSIST(count1 == DNS_LABELTYPE_BITSTRING &&
7618f0551eb745354ee695907e568b0be1f2c8f5Andreas Gustafsson /* Yes, this loop is really slow! */
7618f0551eb745354ee695907e568b0be1f2c8f5Andreas Gustafsson for (n = 0; n < count; n++) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If we're here, then we have two bitstrings
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * of differing length.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * If the name with the shorter bitstring
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * has any labels, then it must be greater
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * than the longer bitstring. This is a bit
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff * counterintuitive. If the name with the
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * shorter bitstring has any more labels, then
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff * the next label must be an ordinary label.
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * It can't be a bitstring label because if it
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff * were, then there would be room for it in
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the current bitstring label (since all
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * bitstrings are canonicalized). Since
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff * there's at least one more bit in the
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * name with the longer bitstring, and since
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * a bitlabel sorts before any ordinary label,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * the name with the longer bitstring must
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * be lexically before the one with the shorter
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * On the other hand, if there are no more
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * labels in the name with the shorter
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson * bitstring, then that name contains the
namereln =
goto done;
nbits = 0;
if (ldiff < 0)
else if (ldiff > 0)
done:
return (namereln);
int order;
return (order);
unsigned int l, count;
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
while (count > 0) {
count--;
return (ISC_FALSE);
return (ISC_FALSE);
if (count == 0)
while (count > 0) {
count--;
c = *label1++;
if (c != *label2++)
return (ISC_FALSE);
return (ISC_TRUE);
while (count > 0) {
count--;
if (count1 == 0)
if (count2 == 0)
while (count > 0) {
count--;
int order;
&nbits);
return (ISC_TRUE);
return (ISC_FALSE);
int order;
return (ISC_TRUE);
return (ISC_FALSE);
unsigned char *ndata;
depth = 0;
while (nrem > 0) {
nrem--;
n = *ndata++;
nrem--;
depth += n;
count++;
depth++;
if (count == 0)
return (depth);
unsigned char *offsets;
unsigned int first, unsigned int n,
unsigned char *offsets;
unsigned char *offsets;
unsigned int len;
if (r->length > 0)
char *tdata;
unsigned char *offsets;
offsets[0] = 0;
n1 = 0;
n2 = 0;
vlen = 0;
digits = 0;
value = 0;
count = 0;
tbcount = 0;
bitlength = 0;
maxlength = 0;
tused = 0;
nused = 0;
labels = 0;
c = *tdata++;
tlen--;
tused++;
switch (state) {
case ft_init:
if (tlen != 0)
return (DNS_R_EMPTYLABEL);
labels++;
*ndata++ = 0;
nrem--;
nused++;
case ft_start:
ndata++;
nrem--;
nused++;
count = 0;
case ft_ordinary:
if (count == 0)
return (DNS_R_EMPTYLABEL);
labels++;
if (tlen == 0) {
labels++;
*ndata++ = 0;
nrem--;
nused++;
return (DNS_R_LABELTOOLONG);
count++;
CONVERTTOASCII(c);
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
nrem--;
nused++;
case ft_initialescape:
ndata++;
nrem--;
nused++;
case ft_escape:
return (DNS_R_LABELTOOLONG);
count++;
CONVERTTOASCII(c);
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
nrem--;
nused++;
digits = 0;
value = 0;
case ft_escdecimal:
return (DNS_R_BADESCAPE);
digits++;
return (DNS_R_BADESCAPE);
return (DNS_R_LABELTOOLONG);
count++;
if (downcase)
nrem--;
nused++;
case ft_bitstring:
tbcount = 0;
value = 0;
n1 = 0;
n2 = 0;
digits = 0;
goto no_read;
return (DNS_R_BADBITSTRING);
case ft_binary:
goto no_read;
count++;
tbcount++;
return (DNS_R_BITSTRINGTOOLONG);
nrem--;
nused++;
count = 0;
case ft_octal:
goto no_read;
return (DNS_R_BITSTRINGTOOLONG);
nrem--;
nused++;
count = 0;
nrem--;
nused++;
nrem--;
nused++;
case ft_hex:
goto no_read;
return (DNS_R_BITSTRINGTOOLONG);
nrem--;
nused++;
count = 0;
case ft_dottedquad:
return (DNS_R_BADDOTTEDQUAD);
n1++;
goto no_read;
value = 0;
digits = 0;
case ft_dqdecimal:
return (DNS_R_BADDOTTEDQUAD);
goto no_read;
digits++;
return (DNS_R_BADDOTTEDQUAD);
case ft_maybeslash:
bitlength = 0;
case ft_finishbitstring:
if (tbcount == 0)
return (DNS_R_BADBITSTRING);
if (count > 0) {
if (n1 != 0)
if (bitlength != 0) {
return (DNS_R_BADBITSTRING);
return (DNS_R_BADBITSTRING);
n1++;
return (DNS_R_BADBITSTRING);
if (value != 0)
count = 0;
n1++;
return (DNS_R_BADBITSTRING);
if (n1 != 0) {
if ((value &
return (DNS_R_BADBITSTRING);
return (DNS_R_BADBITSTRING);
if (count > 0) {
nrem--;
nused++;
n1++;
return (ISC_R_NOSPACE);
nrem--;
nused++;
*label = 0;
labels++;
return (DNS_R_BADBITSTRING);
case ft_bitlength:
if (bitlength == 0)
return (DNS_R_BADBITSTRING);
goto no_read;
return (DNS_R_BADBITSTRING);
case ft_eatdot:
return (DNS_R_BADBITSTRING);
if (tlen == 0) {
labels++;
*ndata++ = 0;
nrem--;
nused++;
if (!done) {
if (nrem == 0)
return (ISC_R_NOSPACE);
return (ISC_R_UNEXPECTEDEND);
labels++;
return (ISC_R_NOSPACE);
while (n1 > 0) {
while (n2 > 0) {
c = *label++;
if (downcase)
c = maptolower[(int)c];
*ndata++ = c;
n2--;
if (bitlength == 0)
n2++;
while (n2 > 0) {
n2--;
labels++;
if (n1 > 0) {
if (saw_bitstring)
return (ISC_R_SUCCESS);
unsigned char *ndata;
char *tdata;
unsigned int labels;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
nlen = 0;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
nlen = 0;
labels--;
nlen--;
if (count == 0) {
while (count > 0) {
c = *ndata;
return (ISC_R_NOSPACE);
CONVERTFROMASCII(c);
*tdata++ = c;
ndata++;
nlen--;
if (trem == 0)
return (ISC_R_NOSPACE);
CONVERTFROMASCII(c);
*tdata++ = c;
ndata++;
trem--;
nlen--;
return (ISC_R_NOSPACE);
ndata++;
nlen--;
count--;
return (ISC_R_NOSPACE);
if (count == 0)
nlen--;
bytes++;
nibbles++;
return (ISC_R_NOSPACE);
while (nibbles > 0) {
c = *ndata++;
nibbles--;
if (nibbles != 0) {
nibbles--;
return (ISC_R_NOSPACE);
for (i = 0; i < len; i++)
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
return (ISC_R_NOSPACE);
trem++;
return (ISC_R_SUCCESS);
unsigned char *ndata;
char *tdata;
unsigned int labels;
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
nlen = 0;
labels--;
nlen--;
if (count == 0)
while (count > 0) {
c = *ndata;
if (trem == 0)
return (ISC_R_NOSPACE);
CONVERTFROMASCII(c);
*tdata++ = c;
ndata++;
trem--;
nlen--;
return (ISC_R_NOSPACE);
ndata++;
nlen--;
count--;
return (ISC_R_NOSPACE);
if (count == 0)
nlen--;
bytes++;
nibbles++;
return (ISC_R_NOSPACE);
while (nibbles > 0) {
c = *ndata++;
nibbles--;
if (nibbles != 0) {
nibbles--;
return (ISC_R_NOSPACE);
for (i = 0; i < len; i++)
if (trem == 0)
return (ISC_R_NOSPACE);
trem--;
return (ISC_R_NOSPACE);
if (omit_final_dot)
trem++;
return (ISC_R_SUCCESS);
return (ISC_R_NOSPACE);
labels--;
nlen--;
while (count > 0) {
nlen--;
count--;
if (count == 0)
nlen--;
bytes++;
while (bytes > 0) {
bytes--;
return (ISC_R_SUCCESS);
unsigned char *ndata;
offset = 0;
nlabels = 0;
offset++;
if (count == 0) {
n = *ndata++;
offset++;
count++;
if (absolute)
if (currbits == 0)
currindex = 0;
if (headbits == 0)
if (headrem != 0)
if (headrem != 0) {
bit);
currindex++;
headindex++;
headbits++;
count--;
headrem--;
} while (headrem != 0);
tailindex = 0;
tailbits = 0;
while (count > 0) {
currindex++;
tailindex++;
tailbits++;
count--;
newbits = 0;
newindex = 0;
bit);
currindex++;
newindex++;
newbits++;
if (newrem != 0) {
count++;
while (newrem > 0) {
newrem--;
newindex++;
count++;
while (count > 0) {
count--;
count++;
while (count > 0) {
count--;
goto again;
unsigned char *offsets;
new_current = 0;
labels = 0;
hops = 0;
nused = 0;
cused = 0;
c = *cdata++;
current++;
if (hops == 0)
cused++;
switch (state) {
case fw_start:
labels++;
goto full;
*ndata++ = c;
return (DNS_R_BADLABELTYPE);
return (DNS_R_DISALLOWED);
} else if (c == DNS_LABELTYPE_BITSTRING) {
labels++;
goto full;
nused++;
*ndata++ = c;
return (DNS_R_BADLABELTYPE);
case fw_ordinary:
if (downcase)
c = maptolower[c];
case fw_copy:
*ndata++ = c;
case fw_bitstring:
goto full;
*ndata++ = c;
case fw_newcurrent:
new_current += c;
return (DNS_R_BADPOINTER);
hops++;
return (DNS_R_TOOMANYHOPS);
if (!done)
return (ISC_R_UNEXPECTEDEND);
if (saw_bitstring)
return (ISC_R_SUCCESS);
full:
return (DNS_R_NAMETOOLONG);
return (ISC_R_NOSPACE);
unsigned int methods;
if (gf) {
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
if (copy_prefix &&
length = 0;
prefix_length = 0;
labels = 0;
if (copy_prefix) {
if (copy_suffix) {
return (DNS_R_NAMETOOLONG);
return (ISC_R_NOSPACE);
if (copy_suffix) {
if (copy_prefix &&
if (absolute)
if (saw_bitstring)
return (ISC_R_SUCCESS);
(*p == 0 || *p > nbits)));
if (nbits > 0) {
*p = *p - nbits;
return (ISC_R_NOSPACE);
if (mod == 0) {
while (len--) {
if (src <= p)
*dst++ |=
prefix);
if (nbits > 0) {
src++;
return (ISC_R_NOSPACE);
if (len > 0) {
src = p;
if (len > 0) {
if (mod != 0)
return (result);
suffixlabels = 0;
nbits = 0;
label--;
n = *ndata++;
suffixlabels++;
if (n <= depth) {
depth -= n;
depth = 0;
suffixlabels++;
depth--;
if (depth != 0) {
INSIST(0);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
isc_region_t r;
return (result);
isc_buffer_t b;
isc_region_t r;
isc_buffer_init(&b, t, sizeof(t));
return (result);
isc_buffer_usedregion(&b, &r);
return (ISC_R_SUCCESS);
isc_region_t r;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);