mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
snapshot
This commit is contained in:
@@ -309,10 +309,6 @@ main(int argc, char *argv[]) {
|
|||||||
if (need_close)
|
if (need_close)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
f = fopen("foo", "w");
|
|
||||||
fwrite(b, bp - b, 1, f);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
isc_buffer_init(&source, b, sizeof b, ISC_BUFFERTYPE_BINARY);
|
isc_buffer_init(&source, b, sizeof b, ISC_BUFFERTYPE_BINARY);
|
||||||
isc_buffer_add(&source, bp - b);
|
isc_buffer_add(&source, bp - b);
|
||||||
|
|
||||||
@@ -325,6 +321,64 @@ main(int argc, char *argv[]) {
|
|||||||
result = printmessage(message);
|
result = printmessage(message);
|
||||||
CHECKRESULT(result, "printmessage() failed");
|
CHECKRESULT(result, "printmessage() failed");
|
||||||
|
|
||||||
|
isc_mem_stats(mctx, stdout);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXXMLG
|
||||||
|
* Changing this here is a hack, and should not be done in reasonable
|
||||||
|
* application code, ever.
|
||||||
|
*/
|
||||||
|
message->from_to_wire = DNS_MESSAGE_INTENT_RENDER;
|
||||||
|
memset(&b, 0, sizeof(b));
|
||||||
|
isc_buffer_clear(&source);
|
||||||
|
|
||||||
|
result = dns_message_renderbegin(message, &source);
|
||||||
|
CHECKRESULT(result, "dns_message_renderbegin() failed");
|
||||||
|
|
||||||
|
result = dns_message_rendersection(message, DNS_SECTION_QUESTION,
|
||||||
|
0, 0);
|
||||||
|
CHECKRESULT(result, "dns_message_rendersection(QUESTION) failed");
|
||||||
|
|
||||||
|
result = dns_message_rendersection(message, DNS_SECTION_ANSWER,
|
||||||
|
0, 0);
|
||||||
|
CHECKRESULT(result, "dns_message_rendersection(ANSWER) failed");
|
||||||
|
|
||||||
|
result = dns_message_rendersection(message, DNS_SECTION_AUTHORITY,
|
||||||
|
0, 0);
|
||||||
|
CHECKRESULT(result, "dns_message_rendersection(AUTHORITY) failed");
|
||||||
|
|
||||||
|
result = dns_message_rendersection(message, DNS_SECTION_ADDITIONAL,
|
||||||
|
0, 0);
|
||||||
|
CHECKRESULT(result, "dns_message_rendersection(ADDITIONAL) failed");
|
||||||
|
|
||||||
|
result = dns_message_rendersection(message, DNS_SECTION_OPT,
|
||||||
|
0, 0);
|
||||||
|
CHECKRESULT(result, "dns_message_rendersection(OPT) failed");
|
||||||
|
|
||||||
|
result = dns_message_rendersection(message, DNS_SECTION_TSIG,
|
||||||
|
0, 0);
|
||||||
|
CHECKRESULT(result, "dns_message_rendersection(TSIG) failed");
|
||||||
|
|
||||||
|
dns_message_renderend(message);
|
||||||
|
|
||||||
|
message->from_to_wire = DNS_MESSAGE_INTENT_PARSE;
|
||||||
|
dns_message_destroy(&message);
|
||||||
|
|
||||||
|
isc_mem_stats(mctx, stdout);
|
||||||
|
|
||||||
|
for (i = 0 ; i < source.used ; i++)
|
||||||
|
printf("%02x%c ", b[i], (isprint(b[i]) ? b[i] : ' '));
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
result = dns_message_create(mctx, &message, DNS_MESSAGE_INTENT_PARSE);
|
||||||
|
CHECKRESULT(result, "dns_message_create failed");
|
||||||
|
|
||||||
|
result = dns_message_parse(message, &source);
|
||||||
|
CHECKRESULT(result, "dns_message_parse failed");
|
||||||
|
|
||||||
|
result = printmessage(message);
|
||||||
|
CHECKRESULT(result, "printmessage() failed");
|
||||||
|
|
||||||
dns_message_destroy(&message);
|
dns_message_destroy(&message);
|
||||||
|
|
||||||
isc_mem_stats(mctx, stdout);
|
isc_mem_stats(mctx, stdout);
|
||||||
|
@@ -433,9 +433,15 @@ msgreset(dns_message_t *msg, isc_boolean_t everything)
|
|||||||
msgblock = next_msgblock;
|
msgblock = next_msgblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg->from_to_wire == DNS_MESSAGE_INTENT_PARSE) {
|
/*
|
||||||
|
* "rdatalists" is special, since it is possible (but not recommended)
|
||||||
|
* that the message could be switched from parse into render mode.
|
||||||
|
*
|
||||||
|
* Note that the reverse is not possible -- switching to parse after
|
||||||
|
* render will not work, and should not.
|
||||||
|
*/
|
||||||
|
|
||||||
msgblock = ISC_LIST_HEAD(msg->rdatalists);
|
msgblock = ISC_LIST_HEAD(msg->rdatalists);
|
||||||
INSIST(msgblock != NULL);
|
|
||||||
if (everything == ISC_FALSE) {
|
if (everything == ISC_FALSE) {
|
||||||
msgblock_reset(msgblock, RDATALIST_COUNT);
|
msgblock_reset(msgblock, RDATALIST_COUNT);
|
||||||
msgblock = ISC_LIST_NEXT(msgblock, link);
|
msgblock = ISC_LIST_NEXT(msgblock, link);
|
||||||
@@ -446,7 +452,6 @@ msgreset(dns_message_t *msg, isc_boolean_t everything)
|
|||||||
msgblock_free(msg->mctx, msgblock);
|
msgblock_free(msg->mctx, msgblock);
|
||||||
msgblock = next_msgblock;
|
msgblock = next_msgblock;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (msg->need_cctx_cleanup)
|
if (msg->need_cctx_cleanup)
|
||||||
dns_compress_invalidate(&msg->cctx);
|
dns_compress_invalidate(&msg->cctx);
|
||||||
@@ -1021,6 +1026,8 @@ dns_message_renderbegin(dns_message_t *msg, isc_buffer_t *buffer)
|
|||||||
*/
|
*/
|
||||||
isc_buffer_add(buffer, DNS_MESSAGE_HEADER_LEN);
|
isc_buffer_add(buffer, DNS_MESSAGE_HEADER_LEN);
|
||||||
|
|
||||||
|
msg->buffer = buffer;
|
||||||
|
|
||||||
return (DNS_R_SUCCESS);
|
return (DNS_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1137,10 +1144,8 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
|
|||||||
|
|
||||||
result = dns_name_towire(name, &msg->cctx, &subbuffer);
|
result = dns_name_towire(name, &msg->cctx, &subbuffer);
|
||||||
if (result != DNS_R_SUCCESS) {
|
if (result != DNS_R_SUCCESS) {
|
||||||
subbuffer.used = used;
|
|
||||||
msg->counts[sectionid] += total;
|
msg->counts[sectionid] += total;
|
||||||
isc_buffer_used(&subbuffer, &r);
|
isc_buffer_add(msg->buffer, used);
|
||||||
isc_buffer_add(msg->buffer, r.length);
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1159,10 +1164,8 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
|
|||||||
* so far, and return that status.
|
* so far, and return that status.
|
||||||
*/
|
*/
|
||||||
if (result != DNS_R_SUCCESS) {
|
if (result != DNS_R_SUCCESS) {
|
||||||
subbuffer.used = used;
|
|
||||||
msg->counts[sectionid] += total;
|
msg->counts[sectionid] += total;
|
||||||
isc_buffer_used(&subbuffer, &r);
|
isc_buffer_add(msg->buffer, used);
|
||||||
isc_buffer_add(msg->buffer, r.length);
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1176,15 +1179,42 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
|
|||||||
name = next_name;
|
name = next_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msg->counts[sectionid] += total;
|
||||||
|
isc_buffer_used(&subbuffer, &r);
|
||||||
|
isc_buffer_add(msg->buffer, r.length);
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_result_t
|
dns_result_t
|
||||||
dns_message_renderend(dns_message_t *msg)
|
dns_message_renderend(dns_message_t *msg)
|
||||||
{
|
{
|
||||||
|
isc_buffer_t tmpbuf;
|
||||||
|
isc_region_t r;
|
||||||
|
isc_uint16_t tmpflags;
|
||||||
|
|
||||||
REQUIRE(VALID_MESSAGE(msg));
|
REQUIRE(VALID_MESSAGE(msg));
|
||||||
REQUIRE(msg->buffer != NULL);
|
REQUIRE(msg->buffer != NULL);
|
||||||
|
|
||||||
|
isc_buffer_used(msg->buffer, &r);
|
||||||
|
if (r.length < DNS_MESSAGE_HEADER_LEN)
|
||||||
|
return (DNS_R_NOSPACE); /* this is slightly bogus... XXX */
|
||||||
|
|
||||||
|
isc_buffer_init(&tmpbuf, r.base, r.length, ISC_BUFFERTYPE_BINARY);
|
||||||
|
|
||||||
|
isc_buffer_putuint16(&tmpbuf, msg->id);
|
||||||
|
|
||||||
|
tmpflags = ((msg->opcode << DNS_MESSAGE_OPCODE_SHIFT)
|
||||||
|
& DNS_MESSAGE_OPCODE_MASK);
|
||||||
|
tmpflags |= (msg->rcode & DNS_MESSAGE_RCODE_MASK); /* XXX edns? */
|
||||||
|
tmpflags |= (msg->flags & DNS_MESSAGE_FLAG_MASK);
|
||||||
|
|
||||||
|
isc_buffer_putuint16(&tmpbuf, tmpflags);
|
||||||
|
isc_buffer_putuint16(&tmpbuf, msg->counts[DNS_SECTION_QUESTION]);
|
||||||
|
isc_buffer_putuint16(&tmpbuf, msg->counts[DNS_SECTION_ANSWER]);
|
||||||
|
isc_buffer_putuint16(&tmpbuf, msg->counts[DNS_SECTION_AUTHORITY]);
|
||||||
|
isc_buffer_putuint16(&tmpbuf, msg->counts[DNS_SECTION_ADDITIONAL]);
|
||||||
|
|
||||||
msg->buffer = NULL; /* forget about this buffer only on success XXX */
|
msg->buffer = NULL; /* forget about this buffer only on success XXX */
|
||||||
|
|
||||||
dns_compress_invalidate(&msg->cctx);
|
dns_compress_invalidate(&msg->cctx);
|
||||||
|
Reference in New Issue
Block a user