#define RDATASET_ATTR_PREFETCH 0x0200
#define RDATASET_ATTR_CASESET 0x0400
#define RDATASET_ATTR_ZEROTTL 0x0800
+#define RDATASET_ATTR_CASEFULLYLOWER 0x1000
typedef struct acache_cbarg {
dns_rdatasetadditional_t type;
(((header)->attributes & RDATASET_ATTR_CASESET) != 0)
#define ZEROTTL(header) \
(((header)->attributes & RDATASET_ATTR_ZEROTTL) != 0)
+#define CASEFULLYLOWER(header) \
+ (((header)->attributes & RDATASET_ATTR_CASEFULLYLOWER) != 0)
+
#define ACTIVE(header, now) \
(((header)->rdh_ttl > (now)) || \
newh->node = (dns_rbtnode_t *)p;
}
if (CASESET(old)) {
+ uint16_t attr;
+
memmove(newh->upper, old->upper, sizeof(old->upper));
- newh->attributes |= RDATASET_ATTR_CASESET;
+ attr = old->attributes & (RDATASET_ATTR_CASESET |
+ RDATASET_ATTR_CASEFULLYLOWER);
+ newh->attributes |= attr;
}
}
static void
setownercase(rdatasetheader_t *header, const dns_name_t *name) {
unsigned int i;
+ isc_boolean_t fully_lower;
/*
* We do not need to worry about label lengths as they are all
* less than or equal to 63.
*/
memset(header->upper, 0, sizeof(header->upper));
+ fully_lower = ISC_TRUE;
for (i = 0; i < name->length; i++)
- if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a)
+ if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a) {
header->upper[i/8] |= 1 << (i%8);
+ fully_lower = ISC_FALSE;
+ }
header->attributes |= RDATASET_ATTR_CASESET;
+ if (ISC_LIKELY(fully_lower))
+ header->attributes |= RDATASET_ATTR_CASEFULLYLOWER;
}
static void
setownercase(header, name);
}
+static const unsigned char charmask[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+static unsigned char maptolower[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+};
+
static void
rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) {
const unsigned char *raw = rdataset->private3; /* RDATASLAB */
const rdatasetheader_t *header;
- unsigned int i;
+ unsigned int i, j;
+ unsigned char bits;
+ unsigned char c, flip;
header = (const struct rdatasetheader *)(raw - sizeof(*header));
if (!CASESET(header))
return;
+#if 0
+ /*
+ * This was the original code, and is implemented differently in
+ * the #else block that follows.
+ */
for (i = 0; i < name->length; i++) {
/*
* Set the case bit if it does not match the recorded bit.
(header->upper[i/8] & (1 << (i%8))) == 0)
name->ndata[i] |= 0x20; /* set the lower case bit */
}
+#else
+ if (ISC_LIKELY(CASEFULLYLOWER(header))) {
+ unsigned char *bp, *be;
+ bp = name->ndata;
+ be = bp + name->length;
+
+ while (bp <= be - 4) {
+ c = bp[0];
+ bp[0] = maptolower[c];
+ c = bp[1];
+ bp[1] = maptolower[c];
+ c = bp[2];
+ bp[2] = maptolower[c];
+ c = bp[3];
+ bp[3] = maptolower[c];
+ bp += 4;
+ }
+ while (bp < be) {
+ c = *bp;
+ *bp++ = maptolower[c];
+ }
+ return;
+ }
+
+ i = 0;
+ for (j = 0; j < (name->length >> 3); j++) {
+ unsigned int k;
+
+ bits = ~(header->upper[j]);
+
+ for (k = 0; k < 8; k++) {
+ c = name->ndata[i];
+ flip = (bits & 1) << 5;
+ flip ^= c;
+ flip &= charmask[c];
+ name->ndata[i] ^= flip;
+
+ i++;
+ bits >>= 1;
+ }
+ }
+
+ if (ISC_UNLIKELY(i == name->length))
+ return;
+
+ bits = ~(header->upper[j]);
+
+ for (; i < name->length; i++) {
+ c = name->ndata[i];
+ flip = (bits & 1) << 5;
+ flip ^= c;
+ flip &= charmask[c];
+ name->ndata[i] ^= flip;
+
+ bits >>= 1;
+ }
+#endif
}
/*%
#define DELETE_TRACE(a, b, c, d, e)
#define ISC_MEMFUNC_SCOPE
#else
+#define TRACE_OR_RECORD (ISC_MEM_DEBUGTRACE|ISC_MEM_DEBUGRECORD)
#define ADD_TRACE(a, b, c, d, e) \
do { \
- if ((isc_mem_debugging & (ISC_MEM_DEBUGTRACE | \
- ISC_MEM_DEBUGRECORD)) != 0 && \
+ if ((isc_mem_debugging & TRACE_OR_RECORD) != 0 && \
b != NULL) \
add_trace_entry(a, b, c, d, e); \
} while (0)
-#define DELETE_TRACE(a, b, c, d, e) delete_trace_entry(a, b, c, d, e)
+#define DELETE_TRACE(a, b, c, d, e) \
+ do { \
+ if ((isc_mem_debugging & TRACE_OR_RECORD) != 0 && \
+ b != NULL) \
+ delete_trace_entry(a, b, c, d, e); \
+ } while(0)
static void
print_active(isc__mem_t *ctx, FILE *out);
if (((ctx->flags & ISC_MEMFLAG_INTERNAL) == 0) && (si != NULL))
mem_getstats(ctx, si[-1].u.size);
-#if ISC_MEM_TRACKLINES
ADD_TRACE(ctx, si, si[-1].u.size, file, line);
-#endif
if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water &&
!ctx->is_overmem) {
ctx->is_overmem = ISC_TRUE;
UNLOCK(mpctx->lock);
#if ISC_MEM_TRACKLINES
- if (item != NULL) {
+ if (((isc_mem_debugging & TRACE_OR_RECORD) != 0) && item != NULL) {
MCTXLOCK(mctx, &mctx->lock);
ADD_TRACE(mctx, item, mpctx->size, file, line);
MCTXUNLOCK(mctx, &mctx->lock);
mpctx->allocated--;
#if ISC_MEM_TRACKLINES
- MCTXLOCK(mctx, &mctx->lock);
- DELETE_TRACE(mctx, mem, mpctx->size, file, line);
- MCTXUNLOCK(mctx, &mctx->lock);
+ if ((isc_mem_debugging & TRACE_OR_RECORD) != 0) {
+ MCTXLOCK(mctx, &mctx->lock);
+ DELETE_TRACE(mctx, mem, mpctx->size, file, line);
+ MCTXUNLOCK(mctx, &mctx->lock);
+ }
#endif /* ISC_MEM_TRACKLINES */
/*
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
LOCK(&contextslock);
- if (!ISC_LIST_EMPTY(contexts)) {
+ if (!ISC_LIST_EMPTY(contexts)) {
#if ISC_MEM_TRACKLINES
- isc__mem_t *ctx;
-
- for (ctx = ISC_LIST_HEAD(contexts);
- ctx != NULL;
- ctx = ISC_LIST_NEXT(ctx, link)) {
- fprintf(file, "context: %p\n", ctx);
- print_active(ctx, file);
+ if ((isc_mem_debugging & TRACE_OR_RECORD) != 0) {
+ isc__mem_t *ctx;
+
+ for (ctx = ISC_LIST_HEAD(contexts);
+ ctx != NULL;
+ ctx = ISC_LIST_NEXT(ctx, link)) {
+ fprintf(file, "context: %p\n", ctx);
+ print_active(ctx, file);
+ }
+ fflush(file);
}
- fflush(file);
#endif
INSIST(0);
}