Lines Matching refs:msg

51 hexdump(const char *msg, const char *msg2, void *base, size_t len) {
58 printf("*** %s [%s] (%u bytes @ %p)\n", msg, msg2, len, base);
265 newbuffer(dns_message_t *msg, unsigned int size) {
270 result = isc_buffer_allocate(msg->mctx, &dynbuf, size);
274 ISC_LIST_APPEND(msg->scratchpad, dynbuf, link);
279 currentbuffer(dns_message_t *msg) {
282 dynbuf = ISC_LIST_TAIL(msg->scratchpad);
289 releaserdata(dns_message_t *msg, dns_rdata_t *rdata) {
290 ISC_LIST_PREPEND(msg->freerdata, rdata, link);
294 newrdata(dns_message_t *msg) {
298 rdata = ISC_LIST_HEAD(msg->freerdata);
300 ISC_LIST_UNLINK(msg->freerdata, rdata, link);
304 msgblock = ISC_LIST_TAIL(msg->rdatas);
307 msgblock = msgblock_allocate(msg->mctx, sizeof(dns_rdata_t),
312 ISC_LIST_APPEND(msg->rdatas, msgblock, link);
322 releaserdatalist(dns_message_t *msg, dns_rdatalist_t *rdatalist) {
323 ISC_LIST_PREPEND(msg->freerdatalist, rdatalist, link);
327 newrdatalist(dns_message_t *msg) {
331 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
333 ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
337 msgblock = ISC_LIST_TAIL(msg->rdatalists);
340 msgblock = msgblock_allocate(msg->mctx,
346 ISC_LIST_APPEND(msg->rdatalists, msgblock, link);
355 newoffsets(dns_message_t *msg) {
359 msgblock = ISC_LIST_TAIL(msg->offsets);
362 msgblock = msgblock_allocate(msg->mctx,
368 ISC_LIST_APPEND(msg->offsets, msgblock, link);
443 msgresetnames(dns_message_t *msg, unsigned int first_section) {
452 name = ISC_LIST_HEAD(msg->sections[i]);
455 ISC_LIST_UNLINK(msg->sections[i], name, link);
464 isc_mempool_put(msg->rdspool, rds);
468 dns_name_free(name, msg->mctx);
469 isc_mempool_put(msg->namepool, name);
476 msgresetopt(dns_message_t *msg)
478 if (msg->opt != NULL) {
479 if (msg->opt_reserved > 0) {
480 dns_message_renderrelease(msg, msg->opt_reserved);
481 msg->opt_reserved = 0;
483 INSIST(dns_rdataset_isassociated(msg->opt));
484 dns_rdataset_disassociate(msg->opt);
485 isc_mempool_put(msg->rdspool, msg->opt);
486 msg->opt = NULL;
491 msgresetsigs(dns_message_t *msg, isc_boolean_t replying) {
492 if (msg->sig_reserved > 0) {
493 dns_message_renderrelease(msg, msg->sig_reserved);
494 msg->sig_reserved = 0;
496 if (msg->tsig != NULL) {
497 INSIST(dns_rdataset_isassociated(msg->tsig));
498 INSIST(msg->namepool != NULL);
500 INSIST(msg->querytsig == NULL);
501 msg->querytsig = msg->tsig;
503 dns_rdataset_disassociate(msg->tsig);
504 isc_mempool_put(msg->rdspool, msg->tsig);
505 if (msg->querytsig != NULL) {
506 dns_rdataset_disassociate(msg->querytsig);
507 isc_mempool_put(msg->rdspool, msg->querytsig);
510 if (dns_name_dynamic(msg->tsigname))
511 dns_name_free(msg->tsigname, msg->mctx);
512 isc_mempool_put(msg->namepool, msg->tsigname);
513 msg->tsig = NULL;
514 msg->tsigname = NULL;
515 } else if (msg->querytsig != NULL && !replying) {
516 dns_rdataset_disassociate(msg->querytsig);
517 isc_mempool_put(msg->rdspool, msg->querytsig);
518 msg->querytsig = NULL;
520 if (msg->sig0 != NULL) {
521 INSIST(dns_rdataset_isassociated(msg->sig0));
522 dns_rdataset_disassociate(msg->sig0);
523 isc_mempool_put(msg->rdspool, msg->sig0);
524 if (msg->sig0name != NULL) {
525 if (dns_name_dynamic(msg->sig0name))
526 dns_name_free(msg->sig0name, msg->mctx);
527 isc_mempool_put(msg->namepool, msg->sig0name);
529 msg->sig0 = NULL;
530 msg->sig0name = NULL;
539 msgreset(dns_message_t *msg, isc_boolean_t everything) {
545 msgresetnames(msg, 0);
546 msgresetopt(msg);
547 msgresetsigs(msg, ISC_FALSE);
558 rdata = ISC_LIST_HEAD(msg->freerdata);
560 ISC_LIST_UNLINK(msg->freerdata, rdata, link);
561 rdata = ISC_LIST_HEAD(msg->freerdata);
563 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
565 ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
566 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
569 dynbuf = ISC_LIST_HEAD(msg->scratchpad);
577 ISC_LIST_UNLINK(msg->scratchpad, dynbuf, link);
582 msgblock = ISC_LIST_HEAD(msg->rdatas);
589 ISC_LIST_UNLINK(msg->rdatas, msgblock, link);
590 msgblock_free(msg->mctx, msgblock, sizeof(dns_rdata_t));
598 msgblock = ISC_LIST_HEAD(msg->rdatalists);
605 ISC_LIST_UNLINK(msg->rdatalists, msgblock, link);
606 msgblock_free(msg->mctx, msgblock, sizeof(dns_rdatalist_t));
610 msgblock = ISC_LIST_HEAD(msg->offsets);
617 ISC_LIST_UNLINK(msg->offsets, msgblock, link);
618 msgblock_free(msg->mctx, msgblock, sizeof(dns_offsets_t));
622 if (msg->tsigkey != NULL) {
623 dns_tsigkey_detach(&msg->tsigkey);
624 msg->tsigkey = NULL;
627 if (msg->tsigctx != NULL)
628 dst_context_destroy(&msg->tsigctx);
630 if (msg->query.base != NULL) {
631 if (msg->free_query != 0)
632 isc_mem_put(msg->mctx, msg->query.base,
633 msg->query.length);
634 msg->query.base = NULL;
635 msg->query.length = 0;
638 if (msg->saved.base != NULL) {
639 if (msg->free_saved != 0)
640 isc_mem_put(msg->mctx, msg->saved.base,
641 msg->saved.length);
642 msg->saved.base = NULL;
643 msg->saved.length = 0;
649 dynbuf = ISC_LIST_HEAD(msg->cleanup);
652 ISC_LIST_UNLINK(msg->cleanup, dynbuf, link);
661 msginit(msg);
663 ENSURE(isc_mempool_getallocated(msg->namepool) == 0);
664 ENSURE(isc_mempool_getallocated(msg->rdspool) == 0);
755 isc_mempool_setname(m->namepool, "msg:names");
762 isc_mempool_setname(m->rdspool, "msg:rdataset");
795 dns_message_reset(dns_message_t *msg, unsigned int intent) {
796 REQUIRE(DNS_MESSAGE_VALID(msg));
800 msgreset(msg, ISC_FALSE);
801 msg->from_to_wire = intent;
806 dns_message_t *msg;
811 msg = *msgp;
814 msgreset(msg, ISC_TRUE);
815 isc_mempool_destroy(&msg->namepool);
816 isc_mempool_destroy(&msg->rdspool);
817 msg->magic = 0;
818 isc_mem_put(msg->mctx, msg, sizeof(dns_message_t));
893 getname(dns_name_t *name, isc_buffer_t *source, dns_message_t *msg,
900 scratch = currentbuffer(msg);
914 result = newbuffer(msg, SCRATCHPAD_SIZE);
918 scratch = currentbuffer(msg);
930 getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
939 scratch = currentbuffer(msg);
971 result = newbuffer(msg, trysize);
975 scratch = currentbuffer(msg);
993 getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
1011 section = &msg->sections[DNS_SECTION_QUESTION];
1020 for (count = 0; count < msg->counts[DNS_SECTION_QUESTION]; count++) {
1021 name = isc_mempool_get(msg->namepool);
1026 offsets = newoffsets(msg);
1038 result = getname(name, source, msg, dctx);
1066 isc_mempool_put(msg->namepool, name);
1087 if (msg->state == DNS_SECTION_ANY) {
1088 msg->state = DNS_SECTION_QUESTION;
1089 msg->rdclass = rdclass;
1090 } else if (msg->rdclass != rdclass)
1103 rdatalist = newrdatalist(msg);
1108 rdataset = isc_mempool_get(msg->rdspool);
1142 isc_mempool_put(msg->rdspool, rdataset);
1146 isc_mempool_put(msg->rdlpool, rdatalist);
1149 isc_mempool_put(msg->namepool, name);
1165 getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
1189 for (count = 0; count < msg->counts[sectionid]; count++) {
1193 section = &msg->sections[sectionid];
1199 name = isc_mempool_get(msg->namepool);
1204 offsets = newoffsets(msg);
1216 result = getname(name, source, msg, dctx);
1237 if (msg->state == DNS_SECTION_ANY &&
1241 msg->rdclass = rdclass;
1242 msg->state = DNS_SECTION_QUESTION;
1249 if (msg->opcode != dns_opcode_update
1255 && msg->rdclass != dns_rdataclass_any
1256 && msg->rdclass != rdclass)
1269 count != msg->counts[sectionid] - 1)
1271 msg->sigstart = recstart;
1281 msg->opt != NULL)
1295 if ((msg->flags & DNS_MESSAGEFLAG_QR) == 0)
1321 rdata = newrdata(msg);
1326 if (msg->opcode == dns_opcode_update &&
1346 msg->opcode == dns_opcode_update &&
1348 result = getrdata(source, msg, dctx, msg->rdclass,
1351 result = getrdata(source, msg, dctx, rdclass,
1367 count != msg->counts[sectionid] - 1)
1369 msg->sigstart = recstart;
1382 if (preserve_order || msg->opcode == dns_opcode_update ||
1404 isc_mempool_put(msg->namepool, name);
1416 if (preserve_order || msg->opcode == dns_opcode_update ||
1456 rdataset = isc_mempool_get(msg->rdspool);
1463 rdatalist = newrdatalist(msg);
1509 * the extended rcode. Note that msg->opt will only be set
1512 if (rdtype == dns_rdatatype_opt && msg->opt == NULL) {
1515 msg->opt = rdataset;
1519 ((msg->opt->ttl & DNS_MESSAGE_EDNSRCODE_MASK)
1521 msg->rcode |= ercode;
1522 isc_mempool_put(msg->namepool, name);
1528 * that msg->sig0 or msg->tsig will only be set if best-effort
1531 if (issigzero && msg->sig0 == NULL) {
1532 msg->sig0 = rdataset;
1533 msg->sig0name = name;
1537 } else if (rdtype == dns_rdatatype_tsig && msg->tsig == NULL) {
1538 msg->tsig = rdataset;
1539 msg->tsigname = name;
1541 msg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
1549 isc_mempool_put(msg->namepool, name);
1551 isc_mempool_put(msg->rdspool, rdataset);
1564 isc_mempool_put(msg->namepool, name);
1566 isc_mempool_put(msg->rdspool, rdataset);
1572 dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
1583 REQUIRE(DNS_MESSAGE_VALID(msg));
1585 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
1592 msg->header_ok = 0;
1593 msg->question_ok = 0;
1599 msg->id = isc_buffer_getuint16(source);
1601 msg->opcode = ((tmpflags & DNS_MESSAGE_OPCODE_MASK)
1603 msg->rcode = (dns_rcode_t)(tmpflags & DNS_MESSAGE_RCODE_MASK);
1604 msg->flags = (tmpflags & DNS_MESSAGE_FLAG_MASK);
1605 msg->counts[DNS_SECTION_QUESTION] = isc_buffer_getuint16(source);
1606 msg->counts[DNS_SECTION_ANSWER] = isc_buffer_getuint16(source);
1607 msg->counts[DNS_SECTION_AUTHORITY] = isc_buffer_getuint16(source);
1608 msg->counts[DNS_SECTION_ADDITIONAL] = isc_buffer_getuint16(source);
1610 msg->header_ok = 1;
1619 ret = getquestions(source, msg, &dctx, options);
1628 msg->question_ok = 1;
1630 ret = getsection(source, msg, &dctx, DNS_SECTION_ANSWER, options);
1640 ret = getsection(source, msg, &dctx, DNS_SECTION_AUTHORITY, options);
1650 ret = getsection(source, msg, &dctx, DNS_SECTION_ADDITIONAL, options);
1670 isc_buffer_usedregion(&origsource, &msg->saved);
1672 msg->saved.length = isc_buffer_usedlength(&origsource);
1673 msg->saved.base = isc_mem_get(msg->mctx, msg->saved.length);
1674 if (msg->saved.base == NULL)
1676 memmove(msg->saved.base, isc_buffer_base(&origsource),
1677 msg->saved.length);
1678 msg->free_saved = 1;
1689 dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx,
1694 REQUIRE(DNS_MESSAGE_VALID(msg));
1696 REQUIRE(msg->buffer == NULL);
1697 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
1699 msg->cctx = cctx;
1714 if (r.length < msg->reserved)
1722 msg->buffer = buffer;
1728 dns_message_renderchangebuffer(dns_message_t *msg, isc_buffer_t *buffer) {
1731 REQUIRE(DNS_MESSAGE_VALID(msg));
1733 REQUIRE(msg->buffer != NULL);
1742 isc_buffer_usedregion(msg->buffer, &r);
1751 msg->buffer = buffer;
1757 dns_message_renderrelease(dns_message_t *msg, unsigned int space) {
1758 REQUIRE(DNS_MESSAGE_VALID(msg));
1759 REQUIRE(space <= msg->reserved);
1761 msg->reserved -= space;
1765 dns_message_renderreserve(dns_message_t *msg, unsigned int space) {
1768 REQUIRE(DNS_MESSAGE_VALID(msg));
1770 if (msg->buffer != NULL) {
1771 isc_buffer_availableregion(msg->buffer, &r);
1772 if (r.length < (space + msg->reserved))
1776 msg->reserved += space;
1814 dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
1828 REQUIRE(DNS_MESSAGE_VALID(msg));
1829 REQUIRE(msg->buffer != NULL);
1832 section = &msg->sections[sectionid];
1855 msg->buffer->length -= msg->reserved;
1858 if (msg->reserved == 0 && (options & DNS_MESSAGERENDER_PARTIAL) != 0)
1870 const void *order_arg = msg->order_arg;
1871 st = *(msg->buffer);
1876 msg->cctx,
1877 msg->buffer,
1878 msg->order,
1886 msg->cctx,
1887 msg->buffer,
1888 msg->order,
1894 msg->flags |= DNS_MESSAGEFLAG_TC;
1895 msg->buffer->length += msg->reserved;
1896 msg->counts[sectionid] += total;
1900 msg->flags |= DNS_MESSAGEFLAG_TC;
1903 dns_compress_rollback(msg->cctx,
1905 *(msg->buffer) = st; /* rollback */
1906 msg->buffer->length += msg->reserved;
1907 msg->counts[sectionid] += total;
1917 msg->buffer->length += msg->reserved;
1918 msg->counts[sectionid] += total;
1940 st = *(msg->buffer);
1947 msg->cctx,
1948 msg->buffer,
1949 msg->order,
1950 msg->order_arg,
1958 msg->cctx,
1959 msg->buffer,
1960 msg->order,
1961 msg->order_arg,
1981 msg->buffer->length += msg->reserved;
1982 msg->counts[sectionid] += total;
1987 dns_compress_rollback(msg->cctx,
1989 *(msg->buffer) = st; /* rollback */
1990 msg->buffer->length += msg->reserved;
1991 msg->counts[sectionid] += total;
2002 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2004 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2017 msg->buffer->length += msg->reserved;
2018 msg->counts[sectionid] += total;
2024 dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target) {
2028 REQUIRE(DNS_MESSAGE_VALID(msg));
2034 isc_buffer_putuint16(target, msg->id);
2036 tmp = ((msg->opcode << DNS_MESSAGE_OPCODE_SHIFT)
2038 tmp |= (msg->rcode & DNS_MESSAGE_RCODE_MASK);
2039 tmp |= (msg->flags & DNS_MESSAGE_FLAG_MASK);
2041 INSIST(msg->counts[DNS_SECTION_QUESTION] < 65536 &&
2042 msg->counts[DNS_SECTION_ANSWER] < 65536 &&
2043 msg->counts[DNS_SECTION_AUTHORITY] < 65536 &&
2044 msg->counts[DNS_SECTION_ADDITIONAL] < 65536);
2048 (isc_uint16_t)msg->counts[DNS_SECTION_QUESTION]);
2050 (isc_uint16_t)msg->counts[DNS_SECTION_ANSWER]);
2052 (isc_uint16_t)msg->counts[DNS_SECTION_AUTHORITY]);
2054 (isc_uint16_t)msg->counts[DNS_SECTION_ADDITIONAL]);
2058 dns_message_renderend(dns_message_t *msg) {
2064 REQUIRE(DNS_MESSAGE_VALID(msg));
2065 REQUIRE(msg->buffer != NULL);
2067 if ((msg->rcode & ~DNS_MESSAGE_RCODE_MASK) != 0 && msg->opt == NULL) {
2080 if ((msg->tsigkey != NULL || msg->sig0key != NULL || msg->opt) &&
2081 (msg->flags & DNS_MESSAGEFLAG_TC) != 0)
2085 msgresetnames(msg, DNS_SECTION_ANSWER);
2086 buf = msg->buffer;
2087 dns_message_renderreset(msg);
2088 msg->buffer = buf;
2089 isc_buffer_clear(msg->buffer);
2090 isc_buffer_add(msg->buffer, DNS_MESSAGE_HEADERLEN);
2091 dns_compress_rollback(msg->cctx, 0);
2092 result = dns_message_rendersection(msg, DNS_SECTION_QUESTION,
2101 if (msg->opt != NULL) {
2102 dns_message_renderrelease(msg, msg->opt_reserved);
2103 msg->opt_reserved = 0;
2107 msg->opt->ttl &= ~DNS_MESSAGE_EDNSRCODE_MASK;
2108 msg->opt->ttl |= ((msg->rcode << 20) &
2114 result = dns_rdataset_towire(msg->opt, dns_rootname,
2115 msg->cctx, msg->buffer, 0,
2117 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2125 if (msg->tsigkey != NULL) {
2126 dns_message_renderrelease(msg, msg->sig_reserved);
2127 msg->sig_reserved = 0;
2128 result = dns_tsig_sign(msg);
2132 result = dns_rdataset_towire(msg->tsig, msg->tsigname,
2133 msg->cctx, msg->buffer, 0,
2135 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2143 if (msg->sig0key != NULL) {
2144 dns_message_renderrelease(msg, msg->sig_reserved);
2145 msg->sig_reserved = 0;
2146 result = dns_dnssec_signmessage(msg, msg->sig0key);
2151 * Note: dns_rootname is used here, not msg->sig0name, since
2155 result = dns_rdataset_towire(msg->sig0, dns_rootname,
2156 msg->cctx, msg->buffer, 0,
2158 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2163 isc_buffer_usedregion(msg->buffer, &r);
2166 dns_message_renderheader(msg, &tmpbuf);
2168 msg->buffer = NULL; /* forget about this buffer only on success XXX */
2174 dns_message_renderreset(dns_message_t *msg) {
2183 REQUIRE(DNS_MESSAGE_VALID(msg));
2184 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2186 msg->buffer = NULL;
2189 msg->cursors[i] = NULL;
2190 msg->counts[i] = 0;
2191 for (name = ISC_LIST_HEAD(msg->sections[i]);
2201 if (msg->tsigname != NULL)
2202 dns_message_puttempname(msg, &msg->tsigname);
2203 if (msg->tsig != NULL) {
2204 dns_rdataset_disassociate(msg->tsig);
2205 dns_message_puttemprdataset(msg, &msg->tsig);
2207 if (msg->sig0 != NULL) {
2208 dns_rdataset_disassociate(msg->sig0);
2209 dns_message_puttemprdataset(msg, &msg->sig0);
2214 dns_message_firstname(dns_message_t *msg, dns_section_t section) {
2215 REQUIRE(DNS_MESSAGE_VALID(msg));
2218 msg->cursors[section] = ISC_LIST_HEAD(msg->sections[section]);
2220 if (msg->cursors[section] == NULL)
2227 dns_message_nextname(dns_message_t *msg, dns_section_t section) {
2228 REQUIRE(DNS_MESSAGE_VALID(msg));
2230 REQUIRE(msg->cursors[section] != NULL);
2232 msg->cursors[section] = ISC_LIST_NEXT(msg->cursors[section], link);
2234 if (msg->cursors[section] == NULL)
2241 dns_message_currentname(dns_message_t *msg, dns_section_t section,
2244 REQUIRE(DNS_MESSAGE_VALID(msg));
2247 REQUIRE(msg->cursors[section] != NULL);
2249 *name = msg->cursors[section];
2253 dns_message_findname(dns_message_t *msg, dns_section_t section,
2267 REQUIRE(msg != NULL);
2280 &msg->sections[section]);
2304 dns_message_movename(dns_message_t *msg, dns_name_t *name,
2308 REQUIRE(msg != NULL);
2309 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2317 ISC_LIST_UNLINK(msg->sections[fromsection], name, link);
2318 ISC_LIST_APPEND(msg->sections[tosection], name, link);
2322 dns_message_addname(dns_message_t *msg, dns_name_t *name,
2325 REQUIRE(msg != NULL);
2326 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2330 ISC_LIST_APPEND(msg->sections[section], name, link);
2334 dns_message_removename(dns_message_t *msg, dns_name_t *name,
2337 REQUIRE(msg != NULL);
2338 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2342 ISC_LIST_UNLINK(msg->sections[section], name, link);
2346 dns_message_gettempname(dns_message_t *msg, dns_name_t **item) {
2347 REQUIRE(DNS_MESSAGE_VALID(msg));
2350 *item = isc_mempool_get(msg->namepool);
2359 dns_message_gettempoffsets(dns_message_t *msg, dns_offsets_t **item) {
2360 REQUIRE(DNS_MESSAGE_VALID(msg));
2363 *item = newoffsets(msg);
2371 dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item) {
2372 REQUIRE(DNS_MESSAGE_VALID(msg));
2375 *item = newrdata(msg);
2383 dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
2384 REQUIRE(DNS_MESSAGE_VALID(msg));
2387 *item = isc_mempool_get(msg->rdspool);
2397 dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2398 REQUIRE(DNS_MESSAGE_VALID(msg));
2401 *item = newrdatalist(msg);
2409 dns_message_puttempname(dns_message_t *msg, dns_name_t **item) {
2410 REQUIRE(DNS_MESSAGE_VALID(msg));
2414 dns_name_free(*item, msg->mctx);
2415 isc_mempool_put(msg->namepool, *item);
2420 dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item) {
2421 REQUIRE(DNS_MESSAGE_VALID(msg));
2424 releaserdata(msg, *item);
2429 dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
2430 REQUIRE(DNS_MESSAGE_VALID(msg));
2434 isc_mempool_put(msg->rdspool, *item);
2439 dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2440 REQUIRE(DNS_MESSAGE_VALID(msg));
2443 releaserdatalist(msg, *item);
2477 dns_message_reply(dns_message_t *msg, isc_boolean_t want_question_section) {
2481 REQUIRE(DNS_MESSAGE_VALID(msg));
2482 REQUIRE((msg->flags & DNS_MESSAGEFLAG_QR) == 0);
2484 if (!msg->header_ok)
2486 if (msg->opcode != dns_opcode_query &&
2487 msg->opcode != dns_opcode_notify)
2489 if (msg->opcode == dns_opcode_update)
2492 if (!msg->question_ok)
2497 msg->from_to_wire = DNS_MESSAGE_INTENTRENDER;
2498 msgresetnames(msg, clear_after);
2499 msgresetopt(msg);
2500 msgresetsigs(msg, ISC_TRUE);
2501 msginitprivate(msg);
2506 msg->flags &= DNS_MESSAGE_REPLYPRESERVE;
2507 msg->flags |= DNS_MESSAGEFLAG_QR;
2513 if (msg->tsigkey != NULL) {
2515 msg->querytsigstatus = msg->tsigstatus;
2516 msg->tsigstatus = dns_rcode_noerror;
2517 if (msg->querytsigstatus == dns_tsigerror_badtime)
2519 msg->sig_reserved = spacefortsig(msg->tsigkey, otherlen);
2520 result = dns_message_renderreserve(msg, msg->sig_reserved);
2522 msg->sig_reserved = 0;
2526 if (msg->saved.base != NULL) {
2527 msg->query.base = msg->saved.base;
2528 msg->query.length = msg->saved.length;
2529 msg->free_query = msg->free_saved;
2530 msg->saved.base = NULL;
2531 msg->saved.length = 0;
2532 msg->free_saved = 0;
2539 dns_message_getopt(dns_message_t *msg) {
2542 * Get the OPT record for 'msg'.
2545 REQUIRE(DNS_MESSAGE_VALID(msg));
2547 return (msg->opt);
2551 dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt) {
2556 * Set the OPT record for 'msg'.
2573 REQUIRE(DNS_MESSAGE_VALID(msg));
2575 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2576 REQUIRE(msg->state == DNS_SECTION_ANY);
2578 msgresetopt(msg);
2584 msg->opt_reserved = 11 + rdata.length;
2585 result = dns_message_renderreserve(msg, msg->opt_reserved);
2587 msg->opt_reserved = 0;
2591 msg->opt = opt;
2597 dns_message_puttemprdataset(msg, &opt);
2602 dns_message_gettsig(dns_message_t *msg, dns_name_t **owner) {
2605 * Get the TSIG record and owner for 'msg'.
2608 REQUIRE(DNS_MESSAGE_VALID(msg));
2612 *owner = msg->tsigname;
2613 return (msg->tsig);
2617 dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key) {
2621 * Set the TSIG key for 'msg'
2624 REQUIRE(DNS_MESSAGE_VALID(msg));
2625 REQUIRE(msg->state == DNS_SECTION_ANY);
2627 if (key == NULL && msg->tsigkey != NULL) {
2628 if (msg->sig_reserved != 0) {
2629 dns_message_renderrelease(msg, msg->sig_reserved);
2630 msg->sig_reserved = 0;
2632 dns_tsigkey_detach(&msg->tsigkey);
2635 REQUIRE(msg->tsigkey == NULL && msg->sig0key == NULL);
2636 dns_tsigkey_attach(key, &msg->tsigkey);
2637 if (msg->from_to_wire == DNS_MESSAGE_INTENTRENDER) {
2638 msg->sig_reserved = spacefortsig(msg->tsigkey, 0);
2639 result = dns_message_renderreserve(msg,
2640 msg->sig_reserved);
2642 dns_tsigkey_detach(&msg->tsigkey);
2643 msg->sig_reserved = 0;
2652 dns_message_gettsigkey(dns_message_t *msg) {
2655 * Get the TSIG key for 'msg'
2658 REQUIRE(DNS_MESSAGE_VALID(msg));
2660 return (msg->tsigkey);
2664 dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) {
2672 REQUIRE(DNS_MESSAGE_VALID(msg));
2673 REQUIRE(msg->querytsig == NULL);
2678 result = dns_message_gettemprdata(msg, &rdata);
2682 result = dns_message_gettemprdatalist(msg, &list);
2685 result = dns_message_gettemprdataset(msg, &set);
2690 result = isc_buffer_allocate(msg->mctx, &buf, r.length);
2697 dns_message_takebuffer(msg, &buf);
2704 msg->querytsig = set;
2710 dns_message_puttemprdata(msg, &rdata);
2712 dns_message_puttemprdatalist(msg, &list);
2714 dns_message_puttemprdataset(msg, &set);
2719 dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx,
2725 REQUIRE(DNS_MESSAGE_VALID(msg));
2729 if (msg->tsig == NULL)
2732 result = dns_rdataset_first(msg->tsig);
2735 dns_rdataset_current(msg->tsig, &rdata);
2746 dns_message_getsig0(dns_message_t *msg, dns_name_t **owner) {
2749 * Get the SIG(0) record for 'msg'.
2752 REQUIRE(DNS_MESSAGE_VALID(msg));
2755 if (msg->sig0 != NULL && owner != NULL) {
2760 if (msg->sig0name == NULL)
2763 *owner = msg->sig0name;
2765 return (msg->sig0);
2769 dns_message_setsig0key(dns_message_t *msg, dst_key_t *key) {
2775 * Set the SIG(0) key for 'msg'
2797 REQUIRE(DNS_MESSAGE_VALID(msg));
2798 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2799 REQUIRE(msg->state == DNS_SECTION_ANY);
2802 REQUIRE(msg->sig0key == NULL && msg->tsigkey == NULL);
2806 msg->sig_reserved = 0;
2809 msg->sig_reserved = 27 + r.length + x;
2810 result = dns_message_renderreserve(msg, msg->sig_reserved);
2812 msg->sig_reserved = 0;
2815 msg->sig0key = key;
2821 dns_message_getsig0key(dns_message_t *msg) {
2824 * Get the SIG(0) key for 'msg'
2827 REQUIRE(DNS_MESSAGE_VALID(msg));
2829 return (msg->sig0key);
2833 dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer) {
2834 REQUIRE(DNS_MESSAGE_VALID(msg));
2838 ISC_LIST_APPEND(msg->cleanup, *buffer, link);
2843 dns_message_signer(dns_message_t *msg, dns_name_t *signer) {
2847 REQUIRE(DNS_MESSAGE_VALID(msg));
2849 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
2851 if (msg->tsig == NULL && msg->sig0 == NULL)
2854 if (msg->verify_attempted == 0)
2859 result = isc_buffer_allocate(msg->mctx, &dynbuf, 512);
2863 dns_message_takebuffer(msg, &dynbuf);
2866 if (msg->sig0 != NULL) {
2869 result = dns_rdataset_first(msg->sig0);
2871 dns_rdataset_current(msg->sig0, &rdata);
2877 if (msg->verified_sig && msg->sig0status == dns_rcode_noerror)
2887 result = dns_rdataset_first(msg->tsig);
2889 dns_rdataset_current(msg->tsig, &rdata);
2893 if (msg->tsigstatus != dns_rcode_noerror)
2901 if (msg->tsigkey == NULL) {
2903 * If msg->tsigstatus & tsig.error are both
2905 * verified, which means msg->tsigkey will be
2910 identity = dns_tsigkey_identity(msg->tsigkey);
2914 identity = &msg->tsigkey->name;
2924 dns_message_resetsig(dns_message_t *msg) {
2925 REQUIRE(DNS_MESSAGE_VALID(msg));
2926 msg->verified_sig = 0;
2927 msg->verify_attempted = 0;
2928 msg->tsigstatus = dns_rcode_noerror;
2929 msg->sig0status = dns_rcode_noerror;
2930 msg->timeadjust = 0;
2931 if (msg->tsigkey != NULL) {
2932 dns_tsigkey_detach(&msg->tsigkey);
2933 msg->tsigkey = NULL;
2938 dns_message_rechecksig(dns_message_t *msg, dns_view_t *view) {
2939 dns_message_resetsig(msg);
2940 return (dns_message_checksig(msg, view));
2945 dns_message_dumpsig(dns_message_t *msg, char *txt1) {
2950 if (msg->tsig != NULL) {
2951 result = dns_rdataset_first(msg->tsig);
2953 dns_rdataset_current(msg->tsig, &querytsigrdata);
2960 if (msg->querytsig != NULL) {
2961 result = dns_rdataset_first(msg->querytsig);
2963 dns_rdataset_current(msg->querytsig, &querytsigrdata);
2973 dns_message_checksig(dns_message_t *msg, dns_view_t *view) {
2976 REQUIRE(DNS_MESSAGE_VALID(msg));
2978 if (msg->tsigkey == NULL && msg->tsig == NULL && msg->sig0 == NULL)
2981 INSIST(msg->saved.base != NULL);
2982 isc_buffer_init(&msgb, msg->saved.base, msg->saved.length);
2983 isc_buffer_add(&msgb, msg->saved.length);
2984 if (msg->tsigkey != NULL || msg->tsig != NULL) {
2986 dns_message_dumpsig(msg, "dns_message_checksig#1");
2989 return (dns_view_checksig(view, &msgb, msg));
2991 return (dns_tsig_verify(&msgb, msg, NULL, NULL));
2998 result = dns_rdataset_first(msg->sig0);
3000 dns_rdataset_current(msg->sig0, &rdata);
3012 result = dns_rdata_tostruct(&rdata, &sig, msg->mctx);
3057 result = dns_dnssec_verifymessage(&msgb, msg, key);
3074 dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
3082 REQUIRE(DNS_MESSAGE_VALID(msg));
3086 if (ISC_LIST_EMPTY(msg->sections[section]))
3091 if (msg->opcode != dns_opcode_update) {
3100 result = dns_message_firstname(msg, section);
3106 dns_message_currentname(msg, section, &name);
3125 result = dns_message_nextname(msg, section);
3136 dns_message_pseudosectiontotext(dns_message_t *msg,
3151 REQUIRE(DNS_MESSAGE_VALID(msg));
3157 ps = dns_message_getopt(msg);
3230 ps = dns_message_gettsig(msg, &name);
3241 ps = dns_message_getsig0(msg, &name);
3256 dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
3261 REQUIRE(DNS_MESSAGE_VALID(msg));
3266 ADD_STRING(target, opcodetext[msg->opcode]);
3268 if (msg->rcode < (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
3269 ADD_STRING(target, rcodetext[msg->rcode]);
3271 snprintf(buf, sizeof(buf), "%4u", msg->rcode);
3275 snprintf(buf, sizeof(buf), "%6u", msg->id);
3278 if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
3280 if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0)
3282 if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
3284 if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0)
3286 if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0)
3288 if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0)
3290 if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0)
3295 if ((msg->flags & 0x0040U) != 0)
3297 if (msg->opcode != dns_opcode_update) {
3303 msg->counts[DNS_SECTION_QUESTION]);
3305 if (msg->opcode != dns_opcode_update) {
3311 msg->counts[DNS_SECTION_ANSWER]);
3313 if (msg->opcode != dns_opcode_update) {
3319 msg->counts[DNS_SECTION_AUTHORITY]);
3323 msg->counts[DNS_SECTION_ADDITIONAL]);
3327 result = dns_message_pseudosectiontotext(msg,
3333 result = dns_message_sectiontotext(msg, DNS_SECTION_QUESTION,
3337 result = dns_message_sectiontotext(msg, DNS_SECTION_ANSWER,
3341 result = dns_message_sectiontotext(msg, DNS_SECTION_AUTHORITY,
3345 result = dns_message_sectiontotext(msg, DNS_SECTION_ADDITIONAL,
3350 result = dns_message_pseudosectiontotext(msg,
3356 result = dns_message_pseudosectiontotext(msg,
3366 dns_message_getrawmessage(dns_message_t *msg) {
3367 REQUIRE(DNS_MESSAGE_VALID(msg));
3368 return (&msg->saved);
3372 dns_message_setsortorder(dns_message_t *msg, dns_rdatasetorderfunc_t order,
3375 REQUIRE(DNS_MESSAGE_VALID(msg));
3376 msg->order = order;
3377 msg->order_arg = order_arg;
3381 dns_message_settimeadjust(dns_message_t *msg, int timeadjust) {
3382 REQUIRE(DNS_MESSAGE_VALID(msg));
3383 msg->timeadjust = timeadjust;
3387 dns_message_gettimeadjust(dns_message_t *msg) {
3388 REQUIRE(DNS_MESSAGE_VALID(msg));
3389 return (msg->timeadjust);