name.c revision c1bb41fa730c1ace908dadb7f808b279a0ae58ab
a90aca78aa7847ba65d27def47f69339987869c8Automatic Updater * Copyright (C) 1998, 1999 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉#define NAME_MAGIC 0x444E536EU /* DNSn. */
5a17fe2916ce37793c12b243ab08c16095a59cf7Evan Hunttypedef enum {
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
5a17fe2916ce37793c12b243ab08c16095a59cf7Evan Hunt -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
5a17fe2916ce37793c12b243ab08c16095a59cf7Evan Huntstatic unsigned char maptolower[] = {
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
11156f82bab19b2e7f5d4df6184ae0c99518442fAutomatic Updater 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
5a17fe2916ce37793c12b243ab08c16095a59cf7Evan Hunt var = default; \
5a17fe2916ce37793c12b243ab08c16095a59cf7Evan Hunt set_offsets(name, var, ISC_FALSE, ISC_FALSE, ISC_FALSE); \
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt (unsigned char *)"", 1, 1, DNS_NAMEATTR_ABSOLUTE, NULL,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonstatic void set_offsets(dns_name_t *name, unsigned char *offsets,
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington isc_boolean_t set_labels, isc_boolean_t set_length,
7b68fa6229f1edadac44c7ec459c9ed77a8368c8Mark Andrewsstatic void compact(dns_name_t *name, unsigned char *offsets);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Yes, get_bit and set_bit are lame. We define them here so they can
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * be inlined by smart compilers.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssonstatic unsigned int
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtonget_bit(unsigned char *array, unsigned int index) {
5a17fe2916ce37793c12b243ab08c16095a59cf7Evan Huntset_bit(unsigned char *array, unsigned int index, unsigned int bit) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Get the type of 'label'.
08f860f800d32007a0c9bf456f6c35fbb2ecbc81Evan Hunt unsigned int count;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * The number of bits in a bitstring label.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(label->base[0] == DNS_LABELTYPE_BITSTRING);
0015ab097438e041197b19b9de2ba48f6bfd1c6cDavid Lawrencedns_label_getbit(dns_label_t *label, unsigned int n) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * The 'n'th most significant bit of 'label'.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Numbering starts at 0.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington REQUIRE(label->base[0] == DNS_LABELTYPE_BITSTRING);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsdns_name_init(dns_name_t *name, unsigned char *offsets) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * Make 'name' empty.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Make 'name' invalid.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * Does 'name' end in the root label?
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if ((name->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
351b62535d4c4f89883bfdba025999dd32490266Evan Huntdns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt unsigned int length;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt const unsigned char *s;
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt unsigned int h = 0;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington unsigned int g;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington unsigned char c;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Provide a hash value for 'name'.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * P. J. Weinberger's hash function, adapted from p. 436 of
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * _Compilers: Principles, Techniques, and Tools_, Aho, Sethi
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * and Ullman, Addison-Wesley, 1986, ISBN 0-201-10088-6.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington h = ( h << 4 ) + *s;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if ((g = ( h & 0xf0000000 )) != 0) {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews h = h ^ (g >> 24);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington h = ( h << 4 ) + c;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if ((g = ( h & 0xf0000000 )) != 0) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington h = h ^ (g >> 24);
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellingtondns_name_compare(dns_name_t *name1, dns_name_t *name2) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt * Determine the relative ordering under the DNSSEC order relation of
08f860f800d32007a0c9bf456f6c35fbb2ecbc81Evan Hunt * 'name1' and 'name2'.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington while (l > 0) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 } else if (count1 == DNS_LABELTYPE_BITSTRING && count2 <= 63) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 } else if (count2 == DNS_LABELTYPE_BITSTRING && count1 <= 63) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 INSIST(count1 == DNS_LABELTYPE_BITSTRING &&
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 /* Yes, this loop is really slow! */
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 for (n = 0; n < count; n++) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉dns_name_issubdomain(dns_name_t *name1, dns_name_t *name2) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Is 'name1' a subdomain of 'name2'?
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Note: It makes no sense for one of the names to be relative and the
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * other absolute. If both names are relative, then to be meaningfully
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * compared the caller must ensure that they are both relative to the
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * same domain.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Either name1 is absolute and name2 is absolute, or neither is.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 REQUIRE(((name1->ndata[offsets1[name1->labels - 1]] == 0 ? 1 : 0) ^
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 (name2->ndata[offsets2[name2->labels - 1]] == 0 ? 1 : 0))
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 while (l2 > 0) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 INSIST(count1 == DNS_LABELTYPE_BITSTRING &&
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 /* Yes, this loop is really slow! */
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 for (n = 0; n < count2; n++) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * How many labels does 'name' have?
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉dns_name_getlabel(dns_name_t *name, unsigned int n, dns_label_t *label) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 unsigned char *offsets;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Make 'label' refer to the 'n'th least significant label of 'name'.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 label->length = name->length - offsets[n];
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 label->length = offsets[n + 1] - offsets[n];
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉dns_name_getlabelsequence(dns_name_t *source,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 unsigned int first, unsigned int n,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 unsigned char *offsets;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Make 'target' refer to the 'n' labels including and following
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * 'first' in 'source'.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 REQUIRE((target->attributes & DNS_NAMEATTR_READONLY) == 0);
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 target->ndata = &source->ndata[offsets[first]];
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 target->length = source->length - offsets[first];
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 target->attributes |= DNS_NAMEATTR_ABSOLUTE;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 target->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 target->length = offsets[first + n] - offsets[first];
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 target->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 set_offsets(target, target->offsets, ISC_FALSE, ISC_FALSE,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉dns_name_fromregion(dns_name_t *name, isc_region_t *r) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 unsigned char *offsets;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Make 'name' refer to region 'r'.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0);
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 set_offsets(name, offsets, ISC_TRUE, ISC_TRUE, ISC_TRUE);
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉dns_name_toregion(dns_name_t *name, isc_region_t *r) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Make 'r' refer to 'name'.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 dns_name_t *origin, isc_boolean_t downcase,
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 unsigned int value, count, tbcount, bitlength, maxlength;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 unsigned int n1, n2, vlen, tlen, nrem, nused, digits, labels, tused;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 unsigned char *offsets;
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Convert the textual representation of a DNS name at source
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * into uncompressed wire form stored in target.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Relative domain names will have 'origin' appended to them
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * unless 'origin' is NULL, in which case relative domain names
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * will remain relative.
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 REQUIRE(isc_buffer_type(source) == ISC_BUFFERTYPE_TEXT);
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 REQUIRE(isc_buffer_type(target) == ISC_BUFFERTYPE_BINARY);
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0);
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * Initialize things to make the compiler happy; they're not required.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * Invalidate 'name'.
6889d57aabc5f48eaee78894e20054215319b461Andreas Gustafsson * Set up the state machine.
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson ndata = (unsigned char *)target->base + target->used;
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson * Is this the root name?
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson if (c == '.') {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson /* FALLTHROUGH */
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (c == '\\') {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews /* FALLTHROUGH */
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (c == '.') {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews } else if (c == '\\') {
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson if (c == '[') {
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉 /* FALLTHROUGH */
de9833be77ef92c17b35c02d138a0ad8df34dd91Mark Andrews /* FALLTHROUGH */
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington /* count is zero */
886b96ebfd555cfeaf37ae46fc08421a41c61392Andreas Gustafsson if (c == 'b') {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews } else if (c == 'o') {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrews } else if (c == 'x') {
8249eee42adc8c9c06c6ff9aaecc7437e259c687Mark Andrews } else if (isdigit(c)) {
c75523bcb30c2b8426ee7cb226d9b429c337325bMark Andrews if (c == '1')
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (c == '/') {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington /* FALLTHROUGH */
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (c == ']') {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Figure out correct number
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * of octal digits for the
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * bitlength, and compare to
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * what was given.
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington /* tbcount % 3 == 0 */
ca84283333d22c64abfbcb87872dd5e6d9172c5aMark Andrews * Figure out correct number
ca84283333d22c64abfbcb87872dd5e6d9172c5aMark Andrews * of hex digits for the
ca84283333d22c64abfbcb87872dd5e6d9172c5aMark Andrews * bitlength, and compare to
ca84283333d22c64abfbcb87872dd5e6d9172c5aMark Andrews * what was given.
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson /* tbcount % 4 == 0 */
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * Are the pad bits in the
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * last 'vlen' bits zero?
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (c != '.')
48f929d315bafeeffe0a37082ab4c9661a928c39Mark Andrews /* Does not return. */
a1bc94109313bf4ebb6e6ff655d71d45582d2e43Mark Andrews if (state != ft_ordinary && state != ft_eatdot &&
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson while (n1 > 0) {
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson while (n2 > 0) {
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrews while (n2 > 0) {
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrews if ((origin->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
a5c077e40c784cf9e25c95a1ab94db2faab04ae9Brian Wellington name->ndata = (unsigned char *)target->base + target->used;
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrewsdns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrews unsigned char *ndata;
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrews unsigned char c;
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrews unsigned int labels;
8e4f3f1cbceef520ba889270c993de0ac376a2a7Evan Hunt * This function assumes the name is in proper uncompressed
3727725bb7d63605b68a644060857013d563b67fEvan Hunt * wire format.
3f42cf2f3e4dc7e740b4609ba7d7430292348f2bMark Andrews REQUIRE(isc_buffer_type(target) == ISC_BUFFERTYPE_TEXT);
77b8f88f144928eddcca144c348d6ef53e7d5c43Evan Hunt /* Special handling for root label. */
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews while (count > 0) {
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews switch (c) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews /* Special modifiers in zone files. */
97639003b0992b5f30ce82bdcc2fcd9d621ff09cAutomatic Updater for (i = 0; i < len; i++)
1adb2e87a20a480e640385609c9652dac04c7dffAndreas Gustafsson /* Does not return. */
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews * The following assumes names are absolute. If not, we
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * fix things up later. Note that this means that in some
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * cases one more byte of text buffer is required than is
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington * needed in the final output.
87f4715d6c0a22f3449eb3291c91aa45ba86c955Mark Andrewsset_offsets(dns_name_t *name, unsigned char *offsets, isc_boolean_t set_labels,
87f4715d6c0a22f3449eb3291c91aa45ba86c955Mark Andrews isc_boolean_t set_length, isc_boolean_t set_absolute)
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington unsigned int offset, count, nlabels, nrem, n;
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington unsigned char *ndata;
17dba29ba5db791976e505114baee53a1dde88aaBrian Wellington while (nrem > 0) {
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington if (n % 8 != 0)
bb60abb44549428414cd55a022f2b8cc4488f7adAndreas Gustafsson name->attributes |= DNS_NAMEATTR_ABSOLUTE;
476386968b1f287a695f73c48862e961011af99bMark Andrewscompact(dns_name_t *name, unsigned char *offsets) {
476386968b1f287a695f73c48862e961011af99bMark Andrews unsigned int headbits, currbits, tailbits, newbits;
476386968b1f287a695f73c48862e961011af99bMark Andrews unsigned int headindex, currindex, tailindex, newindex;
476386968b1f287a695f73c48862e961011af99bMark Andrews * The caller MUST ensure that all bitstrings are correctly formatted
476386968b1f287a695f73c48862e961011af99bMark Andrews * and that the offsets table is valid.
a45a6ea2b03448751d7c44931e8ac7666e7cc2ceMark Andrews while (n > 0) {
a45a6ea2b03448751d7c44931e8ac7666e7cc2ceMark Andrews if (head[0] == DNS_LABELTYPE_BITSTRING && head[1] != 0) {
a45a6ea2b03448751d7c44931e8ac7666e7cc2ceMark Andrews if (n != 0) {
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * We have consecutive bitstrings labels, and
743bbdc18f839499862e4fb28ec32f607b1632dcTatuya JINMEI 神明達哉 * the more significant label ('head') has
90c099e88e9f16bfee9edee3ac1a51fc98843772Brian Wellington } while (headrem != 0);
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++;
return (DNS_R_NOSPACE);
*ndata++ = c;
return (DNS_R_DISALLOWED);
} else if (c == DNS_LABELTYPE_BITSTRING) {
labels++;
if (nrem == 0)
return (DNS_R_NOSPACE);
nrem--;
nused++;
*ndata++ = c;
} else if (c == DNS_LABELTYPE_GLOBALCOMP16) {
return (DNS_R_DISALLOWED);
new_current = 0;
} else if (c == DNS_LABELTYPE_LOCALCOMP) {
return (DNS_R_DISALLOWED);
return (DNS_R_NOTIMPLEMENTED);
return (DNS_R_BADLABELTYPE);
case fw_ordinary:
if (downcase)
c = maptolower[c];
case fw_copy:
*ndata++ = c;
case fw_bitstring:
return (DNS_R_NOSPACE);
*ndata++ = c;
case fw_newcurrent:
new_current += c;
return (DNS_R_BADPOINTER);
hops++;
return (DNS_R_TOOMANYHOPS);
if (!done)
return (DNS_R_UNEXPECTEDEND);
if (saw_bitstring)
return (DNS_R_SUCCESS);
return (DNS_R_NOSPACE);
return (DNS_R_SUCCESS);