diff --git a/bin/named/zone.c b/bin/named/zone.c new file mode 100644 index 0000000000..95708c46cd --- /dev/null +++ b/bin/named/zone.c @@ -0,0 +1,391 @@ +/* + * Copyright (C) 1998, 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +#include + +#include + +#include +#include + +#include "zone.h" + +/* + + NOTES + + - This needs to be fixed for threads. + - + + - we do not 'realloc' to keep all the zones in contiguous memory. + + */ + +#define ZONECHUNK 50 /* how many zone structs we make at once.*/ +#define ZONE_USED_MAGIC 0x7fffffff +#define ZONE_FREE_MAGIC 0x0 + + + +/* This structure contains all the run-time information about a zone. */ +struct zoneinfo +{ + char *origin; /* name of zone */ + time_t filemodtime; /* mod time of zone file */ + char *source; /* where zone data came from */ + +#if 0 + dns_db_t what_am_i; /* XXX unknown thing... */ +#endif + + time_t lastupdate; /* time last soa serial increment */ + u_int32_t refresh; /* refresh interval */ + u_int32_t retry; /* refresh retry interval */ + u_int32_t expire; /* expiration time for cached info */ + u_int32_t minimum; /* minimum TTL value */ + u_int32_t serial; /* SOA serial number */ + + u_int options; /* zone specific options */ + int zoneclass; /* zone class type */ + + int32_t magic; /* private magic stamp for valid'ng */ + + struct zonectx *zctx; /* contect zone came from. */ + + ISC_LINK(struct zoneinfo) chainlink; +}; + + +/* This structure contains context information about a set of + zones. Presumamable there'd only be one of these passed around the + various threads, but separating out zones might be useful in some way */ +struct zonectx +{ + ISC_LIST(zoneinfo_t) freezones; + ISC_LIST(zoneinfo_t) usedzones; + + isc_mem_t *memctx; /* where we get all our memory from */ +}; + + + + +isc_result_t +new_zonecontext(isc_mem_t *memctx, zonectx_t **zctx) { + zonectx_t *zc ; + + INSIST(zctx != NULL); + INSIST(memctx != NULL); + + zc = isc_mem_get(memctx, sizeof *zc); + INSIST(zc != NULL); + + memset(zc, 0x0, sizeof *zc); + zc->memctx = memctx; + + *zctx = zc; + + return ISC_R_SUCCESS; +} + + +isc_result_t +new_zone(zonectx_t *zctx, zoneinfo_t **zone) { + struct zoneinfo *zp; + + INSIST(zctx != NULL); + INSIST(zone != NULL); + + if (ISC_LIST_EMPTY(zctx->freezones)) { + int bytes = sizeof (*zp) * ZONECHUNK; + int idx; + + zp = isc_mem_get(zctx->memctx, bytes); + INSIST(zp != NULL); + + memset(zp, 0x0, bytes); + zp->magic = ZONE_FREE_MAGIC; + + for (idx = 0 ; idx < ZONECHUNK ; idx++) { + zp[idx].magic = ZONE_FREE_MAGIC; + ISC_LIST_APPEND(zctx->freezones, &zp[idx], chainlink); + } + } + + INSIST(!ISC_LIST_EMPTY(zctx->freezones)); + + zp = ISC_LIST_HEAD(zctx->freezones); + ISC_LIST_UNLINK(zctx->freezones, zp, chainlink); + ISC_LIST_APPEND(zctx->usedzones, zp, chainlink); + + zp->magic = ZONE_USED_MAGIC; + zp->zctx = zctx; + + *zone = zp; + + return ISC_R_SUCCESS; +} + + +isc_result_t +free_zone(zoneinfo_t *zone) { + INSIST(zone != NULL); + INSIST(zone->magic == ZONE_USED_MAGIC); + INSIST(zone->zctx != NULL); + + ISC_LIST_UNLINK(zone->zctx->usedzones, zone, chainlink); + zone->magic = ZONE_FREE_MAGIC; + ISC_LIST_APPEND(zone->zctx->freezones, zone, chainlink); + + return ISC_R_SUCCESS; +} + + + +isc_result_t zone_setorigin(zoneinfo_t *zone, char *origin) +{ + (void) zone; + (void) origin; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getorigin(zoneinfo_t *zone, char **origin) +{ + (void) zone; + (void) origin; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setfilemodtime(zoneinfo_t *zone, time_t ftime) +{ + (void) zone; + (void) ftime; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getfilemodtime(zoneinfo_t *zone, time_t *ftime) +{ + (void) zone; + (void) ftime; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setsource(zoneinfo_t *zone, char *source) +{ + (void) zone; + (void) source; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getsource(zoneinfo_t *zone, char **source) +{ + (void) zone; + (void) source; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setlastupdate(zoneinfo_t *zone, time_t lastupdate) +{ + (void) zone; + (void) lastupdate; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getlastupdate(zoneinfo_t *zone, time_t *lastupdate) +{ + (void) zone; + (void) lastupdate; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setrefresh(zoneinfo_t *zone, u_int32_t refresh) +{ + (void) zone; + (void) refresh; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getrefresh(zoneinfo_t *zone, u_int32_t *refresh) +{ + (void) zone; + (void) refresh; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setretry(zoneinfo_t *zone, u_int32_t retry) +{ + (void) zone; + (void) retry; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getretry(zoneinfo_t *zone, u_int32_t *retry) +{ + (void) zone; + (void) retry; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setexpire(zoneinfo_t *zone, u_int32_t expire) +{ + (void) zone; + (void) expire; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getexpire(zoneinfo_t *zone, u_int32_t *expire) +{ + (void) zone; + (void) expire; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setminimum(zoneinfo_t *zone, u_int32_t minimum) +{ + (void) zone; + (void) minimum; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getminimum(zoneinfo_t *zone, u_int32_t *minimum) +{ + (void) zone; + (void) minimum; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setserial(zoneinfo_t *zone, u_int32_t serial) +{ + (void) zone; + (void) serial; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getserial(zoneinfo_t *zone, u_int32_t *serial) +{ + (void) zone; + (void) serial; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setoptions(zoneinfo_t *zone, u_int options) +{ + (void) zone; + (void) options; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getoptions(zoneinfo_t *zone, u_int *options) +{ + (void) zone; + (void) options; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + +isc_result_t zone_setzoneclass(zoneinfo_t *zone, int zclass) +{ + (void) zone; + (void) zclass; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + +isc_result_t zone_getzoneclass(zoneinfo_t *zone, int *zclass) +{ + (void) zone; + (void) zclass; + + /* XXX fill this in */ + + return ISC_R_SUCCESS; +} + + diff --git a/bin/named/zone.h b/bin/named/zone.h new file mode 100644 index 0000000000..20ec4d0221 --- /dev/null +++ b/bin/named/zone.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 1998, 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +#include + +#include +#include +#include + +/* Zone context structures contain a set of zones and related information + (like isc_mem_t contexts to allocate memory from). */ +typedef struct zonectx zonectx_t; + +/* The zone. All access is through function API */ +typedef struct zoneinfo zoneinfo_t; + + +/* Allocate a zone context from the memctx pool. All zone-private data + * structures will be will be made from that same pool. + */ +isc_result_t new_zonecontext(isc_mem_t *memctx, zonectx_t **ctx); + +/* Allocate a zone from the give zone context. */ +isc_result_t new_zone(zonectx_t *zctx, zoneinfo_t **zone); + +/* Free up a zone and all associated data structures. The zone knows which + *zone context to go back to +*/ +isc_result_t free_zone(zoneinfo_t *zone); + + +/* Misc accessor routines. All returned data is through the parameter + * lists. Function return values indicates success (or not). All the set + * functions copy their arguments so the caller retains ownership of any + * pointers passed through the API. All pointers that come back through + * the API in the get functions (e.g. getorigin and getsource) are still + * owned by the zoneinfo_t structure and the data they point to must be + * copied by the caller + */ +isc_result_t zone_setorigin(zoneinfo_t *zone, char *origin); +isc_result_t zone_getorigin(zoneinfo_t *zone, char **origin); + +isc_result_t zone_setfilemodtime(zoneinfo_t *zone, time_t ftime); +isc_result_t zone_getfilemodtime(zoneinfo_t *zone, time_t *ftime); + +isc_result_t zone_setsource(zoneinfo_t *zone, char *source); +isc_result_t zone_getsource(zoneinfo_t *zone, char **source); + +isc_result_t zone_setlastupdate(zoneinfo_t *zone, time_t lastupdate); +isc_result_t zone_getlastupdate(zoneinfo_t *zone, time_t *lastupdate); + +isc_result_t zone_setrefresh(zoneinfo_t *zone, u_int32_t refresh); +isc_result_t zone_getrefresh(zoneinfo_t *zone, u_int32_t *refresh); + +isc_result_t zone_setretry(zoneinfo_t *zone, u_int32_t retry); +isc_result_t zone_getretry(zoneinfo_t *zone, u_int32_t *retry); + +isc_result_t zone_setexpire(zoneinfo_t *zone, u_int32_t expire); +isc_result_t zone_getexpire(zoneinfo_t *zone, u_int32_t *expire); + +isc_result_t zone_setminimum(zoneinfo_t *zone, u_int32_t minimum); +isc_result_t zone_getminimum(zoneinfo_t *zone, u_int32_t *minimum); + +isc_result_t zone_setserial(zoneinfo_t *zone, u_int32_t serial); +isc_result_t zone_getserial(zoneinfo_t *zone, u_int32_t *serial); + +isc_result_t zone_setoptions(zoneinfo_t *zone, u_int options); +isc_result_t zone_getoptions(zoneinfo_t *zone, u_int *options); + +isc_result_t zone_setzoneclass(zoneinfo_t *zone, int zclass); +isc_result_t zone_getzoneclass(zoneinfo_t *zone, int *zclass); + diff --git a/bin/tests/testzones.c b/bin/tests/testzones.c new file mode 100644 index 0000000000..f00774d79b --- /dev/null +++ b/bin/tests/testzones.c @@ -0,0 +1,17 @@ +#include + +#include "zone.h" + +int +main (int argc, char **argv) { + isc_mem_t *memctx = NULL; + zonectx_t *zonectx = NULL; + zoneinfo_t *zone = NULL; + + RUNTIME_CHECK(isc_mem_create(0, 0, &memctx) == ISC_R_SUCCESS); + + RUNTIME_CHECK(new_zonecontext(memctx, &zonectx) == ISC_R_SUCCESS); + + RUNTIME_CHECK(new_zone(zonectx, &zone) == ISC_R_SUCCESS); +} +