ncache.c revision 948eabe2a254a8a278ef6325f3790e75329ee656
/*
* 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.
*/
#include <config.h>
#include <isc/assertions.h>
#include <dns/compress.h>
#include <dns/rdataset.h>
#include <dns/rdatalist.h>
/*
* The format of an ncache rdata is a sequence of one or more records of
* the following format:
*
* owner name
* type
* rdata count
* rdata length These two occur 'rdata count'
* rdata times.
*
*/
static inline isc_result_t
unsigned int count;
isc_region_t ar, r;
/*
* Copy the rdataset count to the buffer.
*/
return (ISC_R_NOSPACE);
while (result == ISC_R_SUCCESS) {
dns_rdata_toregion(&rdata, &r);
return (ISC_R_NOSPACE);
/*
* Copy the rdata length to the buffer.
*/
/*
* Copy the rdata to the buffer.
*/
if (result != ISC_R_SUCCESS)
return (result);
}
if (result != ISC_R_NOMORE)
return (result);
return (ISC_R_SUCCESS);
}
{
isc_region_t r;
char *data[4096];
/*
* Convert the authority data from 'message' into a negative cache
* rdataset, and store it in 'cache' at 'node'.
*/
/*
* We assume that all data in the authority section has been
* validated by the caller.
*/
/*
* First, build an ncache rdata in buffer.
*/
ttl = 0xffffffff;
while (result == ISC_R_SUCCESS) {
&name);
/*
* XXXRTH check for ignore bit here?
*/
if (type == dns_rdatatype_sig)
if (type == dns_rdatatype_soa ||
type == dns_rdatatype_nxt) {
/*
* Copy the owner name to the buffer.
*/
dns_name_toregion(name, &r);
&r);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Copy the type to the buffer.
*/
isc_buffer_available(&buffer, &r);
if (r.length < 2)
return (ISC_R_NOSPACE);
/*
* Copy the rdataset into the buffer.
*/
if (result != ISC_R_SUCCESS)
return (result);
}
}
}
if (result != ISC_R_NOMORE)
return (result);
/*
* Now, turn 'buffer' into an ncache rdataset and add it to
* the cache.
*/
isc_buffer_available(&buffer, &r);
ncrdatalist.type = 0;
return (result);
}
{
/*
* Convert the negative caching rdataset 'rdataset' to wire format,
* compressing names as specified in 'cctx', and storing the result in
* 'target'.
*/
if (result != ISC_R_SUCCESS)
return (result);
else
savedbuffer = *target;
count = 0;
do {
for (i = 0; i < rcount; i++) {
/*
* Get the length of this rdata and set up an
* rdata structure for it.
*/
/*
* Write the name.
*/
if (result != DNS_R_SUCCESS)
goto rollback;
/*
* See if we have space for type, class, ttl, and
* rdata length. Write the type, class, and ttl.
*/
goto rollback;
}
/*
* Save space for rdata length.
*/
/*
* Write the rdata.
*/
if (result != DNS_R_SUCCESS)
goto rollback;
if (result != DNS_R_SUCCESS)
goto rollback;
/*
* Set the rdata length field to the compressed
* length.
*/
count++;
}
return (ISC_R_SUCCESS);
*countp = 0;
*target = savedbuffer;
return (result);
}