Commit 69be7837 authored by Michael Graff's avatar Michael Graff
Browse files

teach dns_rdataset_towire() about the no-rdata-or-ttl trick so it will work

for rendering the questions as well as the other sections.
parent a920f559
......@@ -216,7 +216,8 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
dns_name_t *owner_name,
dns_compress_t *cctx,
isc_buffer_t *target,
unsigned int *countp);
unsigned int *countp,
isc_boolean_t no_rdata_or_ttl);
/*
* Convert 'rdataset' to wire format, compressing names as specified
* in cctx, and storing the result in 'target'.
......@@ -224,6 +225,10 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
* Notes:
* The rdata cursor position will be changed.
*
* The no_rdata_or_ttl should normally be ISC_FALSE. If it is ISC_TRUE
* the ttl and rdata fields are not printed. This is mainly for use
* in the question section.
*
* The number of RRs added to target will be added to *countp.
*
* Requires:
......
......@@ -282,7 +282,8 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
dns_name_t *owner_name,
dns_compress_t *cctx,
isc_buffer_t *target,
unsigned int *countp)
unsigned int *countp,
isc_boolean_t no_rdata_or_ttl)
{
dns_rdata_t rdata;
isc_region_t r;
......@@ -290,6 +291,7 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
unsigned int count;
isc_buffer_t st;
isc_buffer_t rdlen;
unsigned int headlen;
/*
* Convert 'rdataset' to wire format, compressing names as specified
......@@ -298,6 +300,11 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
REQUIRE(DNS_RDATASET_VALID(rdataset));
result = dns_rdataset_first(rdataset);
if (no_rdata_or_ttl) {
REQUIRE(result == DNS_R_NOMORE);
} else {
REQUIRE(result == DNS_R_SUCCESS);
}
REQUIRE(result == DNS_R_SUCCESS);
REQUIRE(countp != NULL);
......@@ -317,43 +324,48 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
*target = st;
return (result);
}
headlen = sizeof(dns_rdataclass_t) + sizeof(dns_rdatatype_t);
if (!no_rdata_or_ttl)
headlen += sizeof(dns_ttl_t)
+ 2; /* XXX 2 for rdata len */
isc_buffer_available(target, &r);
if (r.length < (sizeof(dns_rdataclass_t)
+ sizeof(dns_rdatatype_t)
+ sizeof(dns_ttl_t)
+ 2)) { /* XXX 2? it's for the rdata length */
if (r.length < headlen) {
dns_compress_backout(cctx, st.used);
*target = st;
return (DNS_R_NOSPACE);
}
isc_buffer_putuint16(target, rdataset->type);
isc_buffer_putuint16(target, rdataset->rdclass);
isc_buffer_putuint32(target, rdataset->ttl);
/*
* Save space for rdlen.
*/
rdlen = *target;
isc_buffer_add(target, 2);
/*
* copy out the rdata
*/
dns_rdataset_current(rdataset, &rdata);
result = dns_compress_localinit(cctx, owner_name, target);
if (result != DNS_R_SUCCESS) {
dns_compress_backout(cctx, st.used);
*target = st;
return (result);
}
result = dns_rdata_towire(&rdata, cctx, target);
dns_compress_localinvalidate(cctx);
if (result != DNS_R_SUCCESS) {
dns_compress_backout(cctx, st.used);
*target = st;
return (result);
if (!no_rdata_or_ttl) {
isc_buffer_putuint32(target, rdataset->ttl);
/*
* Save space for rdlen.
*/
rdlen = *target;
isc_buffer_add(target, 2);
/*
* copy out the rdata
*/
dns_rdataset_current(rdataset, &rdata);
result = dns_compress_localinit(cctx, owner_name,
target);
if (result != DNS_R_SUCCESS) {
dns_compress_backout(cctx, st.used);
*target = st;
return (result);
}
result = dns_rdata_towire(&rdata, cctx, target);
dns_compress_localinvalidate(cctx);
if (result != DNS_R_SUCCESS) {
dns_compress_backout(cctx, st.used);
*target = st;
return (result);
}
isc_buffer_putuint16(&rdlen,
target->used - rdlen.used - 2);
}
isc_buffer_putuint16(&rdlen, target->used - rdlen.used - 2);
count++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment