Commit fe372788 authored by Mark Andrews's avatar Mark Andrews
Browse files

in6_addr.s6_addr is *always* an array.

parent 56b04878
......@@ -424,8 +424,12 @@ query_simplefind(void *arg, dns_name_t *name, dns_rdatatype_t type,
zone = NULL;
db = NULL;
result = dns_zt_find(client->view->zonetable, name, NULL, &zone);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH)
result = dns_zone_getdb(zone, &db);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH) {
dns_result_t tresult;
tresult = dns_zone_getdb(zone, &db);
if (tresult != DNS_R_SUCCESS)
result = tresult;
}
if (result == ISC_R_NOTFOUND && USECACHE(client))
dns_db_attach(client->view->cachedb, &db);
......@@ -621,8 +625,12 @@ query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t qtype) {
* Find a database to answer the query.
*/
result = dns_zt_find(client->view->zonetable, name, NULL, &zone);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH)
result = dns_zone_getdb(zone, &db);
if (result == DNS_R_SUCCESS || result == DNS_R_PARTIALMATCH) {
dns_result_t tresult;
tresult = dns_zone_getdb(zone, &db);
if (tresult != DNS_R_SUCCESS)
result = tresult;
}
if (result == ISC_R_NOTFOUND && USECACHE(client))
dns_db_attach(client->view->cachedb, &db);
......
......@@ -2165,10 +2165,11 @@ update_action(isc_task_t *task, isc_event_t *event)
}
}
isc_log_write(UPDATE_DEBUG_LOGARGS, "writing journal");
isc_log_write(UPDATE_DEBUG_LOGARGS, "writing journal %s",
dns_zone_getjournal(zone));
journal = NULL;
result = dns_journal_open(mctx, dns_zone_getixfrlog(zone),
result = dns_journal_open(mctx, dns_zone_getjournal(zone),
ISC_TRUE, &journal);
if (result != DNS_R_SUCCESS)
FAILS(result, "journal open failed");
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: xfrout.c,v 1.20 1999/10/29 00:24:36 gson Exp $ */
/* $Id: xfrout.c,v 1.21 1999/10/29 06:36:00 marka Exp $ */
#include <config.h>
......@@ -919,7 +919,7 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype)
goto have_stream;
}
result = ixfr_rrstream_create(mctx,
dns_zone_getixfrlog(zone),
dns_zone_getjournal(zone),
begin_serial,
current_serial,
&data_stream);
......
......@@ -182,6 +182,9 @@ newrr::
rm -f code.h include/dns/enumtype.h include/dns/enumclass.h
rm -f include/dns/rdatastruct.h
${SUBDIRS}: include/dns/enumtype.h include/dns/enumclass.h
include/dns/rdatastruct.h
rdata.@O@: code.h
include/dns/enumtype.h: gen
......@@ -207,5 +210,5 @@ rbtdb64.@O@: rbtdb.c
depend: include/dns/enumtype.h include/dns/enumclass.h \
include/dns/rdatastruct.h code.h
sec: include/dns/enumtype.h include/dns/enumclass.h \
subdirs: include/dns/enumtype.h include/dns/enumclass.h \
include/dns/rdatastruct.h code.h
......@@ -154,7 +154,7 @@ dns_a6_init(dns_a6context_t *a6ctx, dns_findfunc_t find, dns_rrsetfunc_t rrset,
a6ctx->depth = 0;
a6ctx->prefixlen = 128;
isc_bitstring_init(&a6ctx->bitstring,
(unsigned char *)&a6ctx->in6addr.s6_addr,
(unsigned char *)a6ctx->in6addr.s6_addr,
128, 128, ISC_TRUE);
}
......@@ -181,7 +181,7 @@ dns_a6_copy(dns_a6context_t *source, dns_a6context_t *target) {
*target = *source;
isc_bitstring_init(&target->bitstring,
(unsigned char *)&target->in6addr.s6_addr,
(unsigned char *)target->in6addr.s6_addr,
128, 128, ISC_TRUE);
}
......
......@@ -137,32 +137,6 @@ dns_result_t dns_zone_setdatabase(dns_zone_t *zone, const char *database);
* DNS_R_SUCCESS
*/
dns_result_t dns_zone_setixfrlog(dns_zone_t *zone, const char *ixfrlog);
/*
* Sets the name of the IXFR log file.
*
* Require:
* 'zone' to be a valid initalised zone.
* 'ixfrlog' to be non NULL.
*
* Returns:
* DNS_R_NOMEMORY
* DNS_R_SUCCESS
*/
dns_result_t dns_zone_setupdatelog(dns_zone_t *zone, char *updatelog);
/*
* Sets the name of the UPDATE log file.
*
* Require:
* 'zone' to be a valid initalised zone.
* 'updatelog' to be non NULL.
*
* Returns:
* DNS_R_NOMEMORY
* DNS_R_SUCCESS
*/
dns_result_t dns_zone_load(dns_zone_t *zone);
/*
* Cause the database to be loaded from its backing store.
......@@ -588,8 +562,8 @@ dns_c_pubkey_t * dns_zone_getpubkey(dns_zone_t *zone);
* 'zone' to be initalised.
*/
void dns_zone_setixfrlogsize(dns_zone_t *zone, isc_int32_t size);
isc_int32_t dns_zone_getixfrlogsize(dns_zone_t *zone);
void dns_zone_setjournalsize(dns_zone_t *zone, isc_int32_t size);
isc_int32_t dns_zone_getjournalsize(dns_zone_t *zone);
void dns_zone_setmasterport(dns_zone_t *zone, isc_uint16_t port);
isc_uint16_t dns_zone_getmasterport(dns_zone_t *zone);
......@@ -696,14 +670,6 @@ const char *dns_zone_getdatabase(dns_zone_t *zone);
* 'zone' to be valid initialised zone.
*/
const char *dns_zone_getixfrlog(dns_zone_t *zone);
/*
* Gets the name of the IXFR log file.
*
* Requires:
* 'zone' to be valid initialised zone.
*/
void dns_zone_notify(dns_zone_t *zone);
/*
* Generate notify events for this zone.
......
......@@ -18,6 +18,7 @@
#include <config.h>
#include <ctype.h>
#include <string.h>
#include <isc/assertions.h>
#include <isc/error.h>
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: xfrin.c,v 1.22 1999/10/29 02:41:55 gson Exp $ */
/* $Id: xfrin.c,v 1.23 1999/10/29 06:36:02 marka Exp $ */
#include <config.h>
......@@ -292,7 +292,7 @@ ixfr_init(xfrin_ctx_t *xfr) {
xfr->is_ixfr = ISC_TRUE;
INSIST(xfr->db != NULL);
xfr->difflen = 0;
CHECK(dns_journal_open(xfr->mctx, dns_zone_getixfrlog(xfr->zone),
CHECK(dns_journal_open(xfr->mctx, dns_zone_getjournal(xfr->zone),
ISC_TRUE, &xfr->ixfr.journal));
result = DNS_R_SUCCESS;
failure:
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: zone.c,v 1.30 1999/10/29 02:41:56 gson Exp $ */
/* $Id: zone.c,v 1.31 1999/10/29 06:36:02 marka Exp $ */
#include <config.h>
......@@ -109,13 +109,8 @@ struct dns_zone {
unsigned int references;
dns_name_t origin;
char *database;
char *ixfrlog; /*
* XXX merge w/ updatelog to
* locate transaction log
*/
char *updatelog;
char *journal;
isc_int32_t ixfrlogsize;
isc_int32_t journalsize;
dns_rdataclass_t rdclass;
dns_zonetype_t type;
unsigned int flags;
......@@ -267,9 +262,7 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
zone->references = 1; /* Implicit attach. */
dns_name_init(&zone->origin, NULL);
zone->database = NULL;
zone->ixfrlog = NULL;
zone->ixfrlogsize = -1;
zone->updatelog = NULL;
zone->journalsize = -1;
zone->journal = NULL;
zone->rdclass = dns_rdataclass_none;
zone->type = dns_zone_none;
......@@ -348,13 +341,7 @@ zone_free(dns_zone_t *zone) {
if (zone->database != NULL)
isc_mem_free(zone->mctx, zone->database);
zone->database = NULL;
if (zone->ixfrlog != NULL)
isc_mem_free(zone->mctx, zone->ixfrlog);
zone->ixfrlog = NULL;
zone->ixfrlogsize = -1;
if (zone->updatelog != NULL)
isc_mem_free(zone->mctx, zone->updatelog);
zone->updatelog = NULL;
zone->journalsize = -1;
if (zone->journal != NULL)
isc_mem_free(zone->mctx, zone->journal);
zone->journal = NULL;
......@@ -521,41 +508,6 @@ dns_zone_getjournal(dns_zone_t *zone) {
return (zone->journal);
}
dns_result_t
dns_zone_setupdatelog(dns_zone_t *zone, char *updatelog) {
dns_result_t result = DNS_R_SUCCESS;
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(updatelog != NULL);
LOCK(&zone->lock);
if (zone->updatelog != NULL)
isc_mem_free(zone->mctx, zone->updatelog);
zone->updatelog = isc_mem_strdup(zone->mctx, updatelog);
if (zone->updatelog == NULL)
result = DNS_R_NOMEMORY;
UNLOCK(&zone->lock);
return (result);
}
dns_result_t
dns_zone_setixfrlog(dns_zone_t *zone, const char *ixfrlog) {
dns_result_t result = DNS_R_SUCCESS;
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(ixfrlog != NULL);
LOCK(&zone->lock);
if (zone->ixfrlog != NULL)
isc_mem_free(zone->mctx, zone->ixfrlog);
zone->ixfrlog = isc_mem_strdup(zone->mctx, ixfrlog);
if (zone->ixfrlog == NULL)
result = DNS_R_NOMEMORY;
UNLOCK(&zone->lock);
return (result);
}
void
dns_zone_validate(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
......@@ -648,8 +600,8 @@ dns_zone_load(dns_zone_t *zone) {
/*
* Apply update log, if any.
*/
if (zone->ixfrlog != NULL) {
result = dns_journal_rollforward(zone->mctx, db, zone->ixfrlog);
if (zone->journal != NULL) {
result = dns_journal_rollforward(zone->mctx, db, zone->journal);
if (result != DNS_R_SUCCESS && result != DNS_R_NOTFOUND &&
result != DNS_R_UPTODATE)
goto cleanup;
......@@ -2440,14 +2392,12 @@ dns_zone_copy(isc_log_t *lctx, dns_c_ctx_t *ctx, dns_c_zone_t *czone,
dns_result_t result;
isc_boolean_t boolean;
const char *filename = NULL;
const char *ixfr = NULL;
dns_c_ipmatchlist_t *acl = 0;
dns_c_severity_t severity;
dns_c_iplist_t *iplist = NULL;
dns_c_pubkey_t *pubkey = NULL;
isc_uint32_t i;
isc_sockaddr_t sockaddr;
isc_int32_t size;
isc_int32_t xfrtime;
in_port_t port;
const char *origin;
......@@ -2539,26 +2489,6 @@ dns_zone_copy(isc_log_t *lctx, dns_c_ctx_t *ctx, dns_c_zone_t *czone,
} else
dns_zone_clearnotify(zone);
iresult = dns_c_zone_getixfrbase(lctx, czone, &ixfr);
if (iresult == ISC_R_SUCCESS) {
result = dns_zone_setixfrlog(zone, ixfr);
if (result != DNS_R_SUCCESS)
return (result);
zone->diff_on_reload = ISC_TRUE;
} else
zone->diff_on_reload = ISC_FALSE;
czone->u.mzone.ixfr_tmp; /*XXX*/
iresult = dns_c_zone_getmaxixfrlog(lctx, czone, &size);
if (iresult == ISC_R_SUCCESS)
dns_zone_setixfrlogsize(zone, size);
iresult = dns_c_zone_getmaintixfrbase(lctx, czone, &boolean);
if (result == ISC_R_SUCCESS)
zone->diff_on_reload = boolean;
else
zone->diff_on_reload = ISC_TRUE;
iresult = dns_c_zone_getpubkey(lctx, czone, &pubkey);
if (iresult == ISC_R_SUCCESS)
dns_zone_setpubkey(zone, pubkey);
......@@ -2621,12 +2551,6 @@ dns_zone_copy(isc_log_t *lctx, dns_c_ctx_t *ctx, dns_c_zone_t *czone,
} else
dns_zone_clearmasters(zone);
iresult = dns_c_zone_getmaintixfrbase(lctx, czone, &boolean);
if (result == ISC_R_SUCCESS)
zone->diff_on_reload = boolean;
else
zone->diff_on_reload = ISC_FALSE;
iresult = dns_c_zone_getmaxtranstimein(lctx, czone, &xfrtime);
if (result == ISC_R_SUCCESS)
zone->xfrtime = xfrtime;
......@@ -2860,19 +2784,19 @@ dns_zone_getpubkey(dns_zone_t *zone) {
}
void
dns_zone_setixfrlogsize(dns_zone_t *zone, isc_int32_t size) {
dns_zone_setjournalsize(dns_zone_t *zone, isc_int32_t size) {
REQUIRE(DNS_ZONE_VALID(zone));
zone->ixfrlogsize = size;
zone->journalsize = size;
}
isc_int32_t
dns_zone_getixfrlogsize(dns_zone_t *zone) {
dns_zone_getjournalsize(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->ixfrlogsize);
return (zone->journalsize);
}
void
......@@ -3007,33 +2931,6 @@ dns_zone_getdatabase(dns_zone_t *zone) {
return (zone->database);
}
const char *
dns_zone_getixfrlog(dns_zone_t *zone) {
REQUIRE(DNS_ZONE_VALID(zone));
return (zone->ixfrlog);
}
#if 0
/*
* XXX should become isc_sockaddr_fromaddr() once dns_c_addr_t -> isc
*/
static void
sockaddr_fromaddr(isc_sockaddr_t *sockaddr, dns_c_addr_t *a,
in_port_t port) {
switch (a->type.sa.sa_family) {
case AF_INET:
isc_sockaddr_fromin(sockaddr, &a->type.sin.sin_addr, port);
break;
case AF_INET6:
isc_sockaddr_fromin6(sockaddr, &a->type.sin6.sin6_addr, port);
break;
default:
INSIST(0);
}
}
#endif
static void
record_serial() {
}
......@@ -3056,30 +2953,18 @@ dns_zone_equal(dns_zone_t *oldzone, dns_zone_t *newzone) {
oldzone->masterport != newzone->masterport ||
oldzone->check_names != newzone->check_names ||
oldzone->diff_on_reload != newzone->diff_on_reload ||
oldzone->ixfrlogsize != newzone->ixfrlogsize)
oldzone->journalsize != newzone->journalsize)
goto false;
if (!dns_name_equal(&oldzone->origin, &newzone->origin))
goto false;
if ((oldzone->updatelog == NULL && newzone->updatelog != NULL) ||
(oldzone->updatelog != NULL && newzone->updatelog == NULL) ||
(oldzone->updatelog != NULL &&
strcmp(oldzone->updatelog, newzone->updatelog) != 0))
goto false;
if ((oldzone->journal == NULL && newzone->journal != NULL) ||
(oldzone->journal != NULL && newzone->journal == NULL) ||
(oldzone->journal != NULL &&
strcmp(oldzone->journal, newzone->journal) != 0))
goto false;
if ((oldzone->ixfrlog == NULL && newzone->ixfrlog != NULL) ||
(oldzone->ixfrlog != NULL && newzone->ixfrlog == NULL) ||
(oldzone->ixfrlog != NULL &&
strcmp(oldzone->ixfrlog, newzone->ixfrlog) != 0))
goto false;
if ((oldzone->options & oldzone->setoptions) !=
(newzone->options & newzone->setoptions))
goto false;
......@@ -3157,13 +3042,13 @@ replacedb(dns_zone_t *zone, dns_db_t *db, isc_boolean_t dump) {
* subsequent versions may be journalled instead if this
* is enabled in the configuration.
*/
if (zone->top != NULL && zone->ixfrlog != NULL &&
if (zone->top != NULL && zone->journal != NULL &&
zone->diff_on_reload) {
printf("generating diffs\n");
result = dns_db_diff(zone->mctx,
db, ver,
zone->top, NULL /* XXX */,
zone->ixfrlog);
zone->journal);
if (result != DNS_R_SUCCESS)
goto fail;
} else {
......@@ -3174,9 +3059,9 @@ replacedb(dns_zone_t *zone, dns_db_t *db, isc_boolean_t dump) {
if (result != DNS_R_SUCCESS)
goto fail;
}
if (zone->ixfrlog != NULL) {
if (zone->journal != NULL) {
/* XXXRTH log instead: printf("unlinking journal\n"); */
(void) remove(zone->ixfrlog);
(void) remove(zone->journal);
}
}
dns_db_closeversion(db, &ver, ISC_FALSE);
......
......@@ -45,16 +45,18 @@ typedef void (*isc_memfree_t)(void *, void *);
#define isc_mempool_put(c, p) __isc_mempool_putdebug(c, p, \
__FILE__, __LINE__)
#else
#define isc_mem_get __isc_mem_get
#define isc_mem_put __isc_mem_put
#define isc_mem_get(c, s) __isc_mem_get(c, s, __FILE__, __LINE__)
#define isc_mem_put(c, p, s) __isc_mem_put(c, p, s, __FILE__, __LINE__)
#define isc_mempool_get __isc_mempool_get
#define isc_mempool_put __isc_mempool_put
#endif /* ISC_MEM_DEBUG */
isc_result_t isc_mem_create(size_t, size_t, isc_mem_t **);
void isc_mem_destroy(isc_mem_t **);
void * __isc_mem_get(isc_mem_t *, size_t);
void __isc_mem_put(isc_mem_t *, void *, size_t);
void * __isc_mem_get(isc_mem_t *, size_t,
const char *, int);
void __isc_mem_put(isc_mem_t *, void *, size_t,
const char *, int);
void * __isc_mem_getdebug(isc_mem_t *, size_t,
const char *, int);
void __isc_mem_putdebug(isc_mem_t *, void *,
......@@ -249,6 +251,10 @@ void isc_mempool_setfillcount(isc_mempool_t *mpctx,
* limit > 0
*/
void isc_mem_allocated(isc_mem_t *ctx, FILE *file);
/*
* Report allocated memory.
*/
ISC_LANG_ENDDECLS
#endif /* MEM_H */
......@@ -69,8 +69,10 @@
* Types.
*/
typedef struct {
typedef struct element {
void * next;
const char * file;
int line;
} element;
typedef struct {
......@@ -103,6 +105,7 @@ struct isc_mem {
size_t mem_target;
element ** freelists;
element * basic_blocks;
element ** allocated;
unsigned char ** basic_table;
unsigned int basic_table_count;
unsigned int basic_table_size;
......@@ -146,8 +149,10 @@ struct isc_mempool {
*/
static inline size_t quantize(size_t);
static inline void mem_putunlocked(isc_mem_t *, void *, size_t);
static inline void * mem_getunlocked(isc_mem_t *, size_t);
static inline void mem_putunlocked(isc_mem_t *, void *, size_t,
const char *, int);
static inline void * mem_getunlocked(isc_mem_t *, size_t,
const char *, int);
/*
* Private Inline-able.
......@@ -163,7 +168,7 @@ quantize(size_t size) {
* byte boundaries.
*/
temp = size + (ALIGNMENT_SIZE - 1);
temp = size + sizeof(element) + (ALIGNMENT_SIZE - 1);
return (temp - temp % ALIGNMENT_SIZE);
}
......@@ -214,17 +219,25 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->memfree = memfree;
ctx->arg = arg;
ctx->freelists = (memalloc)(arg, ctx->max_size * sizeof (element *));
if (ctx->freelists == NULL) {
ctx->allocated = (memalloc)(arg, ctx->max_size * sizeof (element *));
if (ctx->freelists == NULL || ctx->allocated == NULL) {
if (ctx->freelists != NULL)
(memfree)(arg, ctx->freelists);
if (ctx->allocated != NULL)
(memfree)(arg, ctx->allocated);
(memfree)(arg, ctx);
return (ISC_R_NOMEMORY);
}
ctx->checkfree = ISC_TRUE;
memset(ctx->freelists, 0,
ctx->max_size * sizeof (element *));
memset(ctx->allocated, 0,
ctx->max_size * sizeof (element *));
ctx->stats = (memalloc)(arg,
(ctx->max_size+1) * sizeof (struct stats));
if (ctx->stats == NULL) {
(memfree)(arg, ctx->freelists);
(memfree)(arg, ctx->allocated);
(memfree)(arg, ctx);
return (ISC_R_NOMEMORY);
}
......@@ -238,6 +251,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
if (isc_mutex_init(&ctx->lock) != ISC_R_SUCCESS) {
(memfree)(arg, ctx->stats);
(memfree)(arg, ctx->freelists);
(memfree)(arg, ctx->allocated);
(memfree)(arg, ctx);
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed");
......@@ -252,6 +266,31 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
return (ISC_R_SUCCESS);
}
void
isc_mem_allocated(isc_mem_t *ctx, FILE *file) {
unsigned int i;
element *el;
REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(file != NULL);
fflush(stdout);
fflush(stderr);
fflush(file);
for (i = 0 ; i <= ctx->max_size; i++) {
el = ctx->allocated[i];
while (el != NULL) {
fprintf(file,
"bytes %d: address %p: file %s: line %d\n",
i, el + 1,
(el->file != NULL) ? el->file : "<UNKNOWN>",
el->line);
el = el->next;
}
}
fflush(file);
}
isc_result_t
isc_mem_create(size_t init_max_size, size_t target_size,
isc_mem_t **ctxp)
......@@ -270,6 +309,8 @@ isc_mem_destroy(isc_mem_t **ctxp) {
ctx = *ctxp;
REQUIRE(VALID_CONTEXT(ctx));
isc_mem_allocated(ctx, stderr);
ctx->magic = 0;
INSIST(ISC_LIST_EMPTY(ctx->pools));
......@@ -289,6 +330,7 @@ isc_mem_destroy(isc_mem_t **ctxp) {
for (i = 0; i < ctx->basic_table_count; i++)
(ctx->memfree)(ctx->arg, ctx->basic_table[i]);
(ctx->memfree)(ctx->arg, ctx->freelists);
(ctx->memfree)(ctx->arg, ctx->allocated);
(ctx->memfree)(ctx->arg, ctx->stats);
(ctx->memfree)(ctx->arg, ctx->basic_table);
......@@ -374,7 +416,7 @@ more_basic_blocks(isc_mem_t *ctx) {
}
void *
__isc_mem_get(isc_mem_t *ctx, size_t size)
__isc_mem_get(isc_mem_t *ctx, size_t size, const char *file, int line)
{
void *ret;
......@@ -382,17 +424,18 @@ __isc_mem_get(isc_mem_t *ctx, size_t size)
REQUIRE(VALID_CONTEXT(ctx));
LOCK(&ctx->lock);
ret = mem_getunlocked(ctx, size);
ret = mem_getunlocked(ctx, size, file, line);
UNLOCK(&ctx->lock);