diff --git a/lib/dns/Makefile.in b/lib/dns/Makefile.in index 32c2f57005..b392f74251 100644 --- a/lib/dns/Makefile.in +++ b/lib/dns/Makefile.in @@ -13,7 +13,7 @@ CDEFINES = CWARNINGS = OBJS = name.o rbt.o rdata.o rdatalist.o rdataset.o \ - result.o version.o + result.o version.o rdataslab.o SUBDIRS = include TARGETS = timestamp diff --git a/lib/dns/include/dns/rdataslab.h b/lib/dns/include/dns/rdataslab.h new file mode 100644 index 0000000000..02502a4165 --- /dev/null +++ b/lib/dns/include/dns/rdataslab.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 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. + */ + +#ifndef DNS_RDATASLAB_H +#define DNS_RDATASLAB_H 1 + +/* + * DNS Rdata Slab + * + * Implements storage of rdatasets into slabs of memory. + * + * MP: + * Clients of this module must impose any required synchronization. + * + * Reliability: + * This module deals with low-level byte streams. Errors in any of + * the functions are likely to crash the server or corrupt memory. + * + * Resources: + * None. + * + * Security: + * + * Very little range checking is done in these functions for rdata + * copied in or out. It is assumed that the caller knows what is + * going on. + * + * Standards: + * None. + */ + +/*** + *** Imports + ***/ + +#include + +#include +#include + +/*** + *** Functions + ***/ + +dns_result_t +dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, + isc_region_t *region, unsigned int reservelen); +/* + * Slabify a rdataset. The slab area will be allocated and returned + * in 'region'. + * + * Requires: + * 'rdataset' is valid. + * + * Ensures: + * 'region' will have base pointing to the start of allocated memory, + * with the slabified region beginning at region->base + reservelen. + * region->length contains the total length allocated. + * + * Returns: + * DNS_R_SUCCESS - successful completion + * DNS_R_NOMEM - no memory. + * + */ + + +dns_result_t +dns_rdataslab_tordataset(dns_rdataset_t *rdataset, isc_region_t *region, + unsigned int reservelen); +/* + * Unslabify a rdataset. The slab is not deallocated. + * + * Requires: + * 'rdataset' is valid. + * + * 'region' points to a region of memory that contains the slabified + * data at offset 'reservelen'. + * + * Ensures: + * 'rdataset' contains the structure version of data in 'region'. + * + * Returns: + * DNS_R_SUCCESS - successful completion + * DNS_R_NOMEM - no memory. + * + */ + +#endif /* DNS_RDATADLAB_H */ diff --git a/lib/dns/rdataslab.c b/lib/dns/rdataslab.c new file mode 100644 index 0000000000..b34f63f894 --- /dev/null +++ b/lib/dns/rdataslab.c @@ -0,0 +1,117 @@ +/* + * Copyright (C) 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. + */ + +/* $Id: rdataslab.c,v 1.1 1999/01/27 08:44:10 explorer Exp $ */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +dns_result_t +dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, + isc_region_t *region, unsigned int reservelen) +{ + dns_rdata_t rdata; + unsigned char *rawbuf; + unsigned int buflen; + dns_result_t result; + unsigned int nitems; + + result = dns_rdataset_first(rdataset); + REQUIRE(result == DNS_R_SUCCESS); + + buflen = reservelen + 2; + nitems = 0; + + /* + * Run through the rdataset list once, counting up the size + * of all the rdata members within it. We do not store the + * class, type, etc, just the rdata, so our overhead is 2 bytes + * for the number of records, and 2 for each rdata length, and + * then the rdata itself. + */ + do { + dns_rdataset_current(rdataset, &rdata); + buflen += (2 + rdata.length); + + nitems++; + + result = dns_rdataset_next(rdataset); + } while (result == DNS_R_SUCCESS); + + if (result != DNS_R_NOMORE) + return (result); + + /* + * Allocate the memory, set up a buffer, start copying in + * data. + */ + rawbuf = isc_mem_get(mctx, buflen); + if (rawbuf == NULL) + return (DNS_R_NOMEMORY); + + region->base = rawbuf; + region->length = buflen; + + rawbuf += reservelen; + + *rawbuf++ = (nitems & 0xff00) >> 8; + *rawbuf++ = (nitems & 0x00ff); + result = dns_rdataset_first(rdataset); + REQUIRE(result == DNS_R_SUCCESS); + do { + dns_rdataset_current(rdataset, &rdata); + *rawbuf++ = (rdata.length & 0xff00) >> 8; + *rawbuf++ = (rdata.length & 0x00ff); + memcpy(rawbuf, rdata.data, rdata.length); + rawbuf += rdata.length; + + result = dns_rdataset_next(rdataset); + } while (result == DNS_R_SUCCESS); + + if (result != DNS_R_NOMORE) { + isc_mem_put(mctx, region->base, region->length); + region->base = NULL; + region->length = 0; + + return (result); + } + + return (DNS_R_SUCCESS); +} + +dns_result_t +dns_rdataslab_tordataset(dns_rdataset_t *rdataset, isc_region_t *region, + unsigned int reservelen) +{ + /* XXX shut up compiler */ + rdataset = rdataset; + region = region; + reservelen = reservelen; + + return (DNS_R_NOTIMPLEMENTED); +}