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);
445 msgresetnames(dns_message_t *msg, unsigned int first_section) {
454 name = ISC_LIST_HEAD(msg->sections[i]);
457 ISC_LIST_UNLINK(msg->sections[i], name, link);
466 isc_mempool_put(msg->rdspool, rds);
470 dns_name_free(name, msg->mctx);
471 isc_mempool_put(msg->namepool, name);
478 msgresetopt(dns_message_t *msg)
480 if (msg->opt != NULL) {
481 if (msg->opt_reserved > 0) {
482 dns_message_renderrelease(msg, msg->opt_reserved);
483 msg->opt_reserved = 0;
485 INSIST(dns_rdataset_isassociated(msg->opt));
486 dns_rdataset_disassociate(msg->opt);
487 isc_mempool_put(msg->rdspool, msg->opt);
488 msg->opt = NULL;
493 msgresetsigs(dns_message_t *msg, isc_boolean_t replying) {
494 if (msg->sig_reserved > 0) {
495 dns_message_renderrelease(msg, msg->sig_reserved);
496 msg->sig_reserved = 0;
498 if (msg->tsig != NULL) {
499 INSIST(dns_rdataset_isassociated(msg->tsig));
500 INSIST(msg->namepool != NULL);
502 INSIST(msg->querytsig == NULL);
503 msg->querytsig = msg->tsig;
505 dns_rdataset_disassociate(msg->tsig);
506 isc_mempool_put(msg->rdspool, msg->tsig);
507 if (msg->querytsig != NULL) {
508 dns_rdataset_disassociate(msg->querytsig);
509 isc_mempool_put(msg->rdspool, msg->querytsig);
512 if (dns_name_dynamic(msg->tsigname))
513 dns_name_free(msg->tsigname, msg->mctx);
514 isc_mempool_put(msg->namepool, msg->tsigname);
515 msg->tsig = NULL;
516 msg->tsigname = NULL;
517 } else if (msg->querytsig != NULL && !replying) {
518 dns_rdataset_disassociate(msg->querytsig);
519 isc_mempool_put(msg->rdspool, msg->querytsig);
520 msg->querytsig = NULL;
522 if (msg->sig0 != NULL) {
523 INSIST(dns_rdataset_isassociated(msg->sig0));
524 dns_rdataset_disassociate(msg->sig0);
525 isc_mempool_put(msg->rdspool, msg->sig0);
526 if (msg->sig0name != NULL) {
527 if (dns_name_dynamic(msg->sig0name))
528 dns_name_free(msg->sig0name, msg->mctx);
529 isc_mempool_put(msg->namepool, msg->sig0name);
531 msg->sig0 = NULL;
532 msg->sig0name = NULL;
541 msgreset(dns_message_t *msg, isc_boolean_t everything) {
547 msgresetnames(msg, 0);
548 msgresetopt(msg);
549 msgresetsigs(msg, ISC_FALSE);
560 rdata = ISC_LIST_HEAD(msg->freerdata);
562 ISC_LIST_UNLINK(msg->freerdata, rdata, link);
563 rdata = ISC_LIST_HEAD(msg->freerdata);
565 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
567 ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
568 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
571 dynbuf = ISC_LIST_HEAD(msg->scratchpad);
579 ISC_LIST_UNLINK(msg->scratchpad, dynbuf, link);
584 msgblock = ISC_LIST_HEAD(msg->rdatas);
591 ISC_LIST_UNLINK(msg->rdatas, msgblock, link);
592 msgblock_free(msg->mctx, msgblock, sizeof(dns_rdata_t));
600 msgblock = ISC_LIST_HEAD(msg->rdatalists);
607 ISC_LIST_UNLINK(msg->rdatalists, msgblock, link);
608 msgblock_free(msg->mctx, msgblock, sizeof(dns_rdatalist_t));
612 msgblock = ISC_LIST_HEAD(msg->offsets);
619 ISC_LIST_UNLINK(msg->offsets, msgblock, link);
620 msgblock_free(msg->mctx, msgblock, sizeof(dns_offsets_t));
624 if (msg->tsigkey != NULL) {
625 dns_tsigkey_detach(&msg->tsigkey);
626 msg->tsigkey = NULL;
629 if (msg->tsigctx != NULL)
630 dst_context_destroy(&msg->tsigctx);
632 if (msg->query.base != NULL) {
633 if (msg->free_query != 0)
634 isc_mem_put(msg->mctx, msg->query.base,
635 msg->query.length);
636 msg->query.base = NULL;
637 msg->query.length = 0;
640 if (msg->saved.base != NULL) {
641 if (msg->free_saved != 0)
642 isc_mem_put(msg->mctx, msg->saved.base,
643 msg->saved.length);
644 msg->saved.base = NULL;
645 msg->saved.length = 0;
651 dynbuf = ISC_LIST_HEAD(msg->cleanup);
654 ISC_LIST_UNLINK(msg->cleanup, dynbuf, link);
663 msginit(msg);
665 ENSURE(isc_mempool_getallocated(msg->namepool) == 0);
666 ENSURE(isc_mempool_getallocated(msg->rdspool) == 0);
759 isc_mempool_setname(m->namepool, "msg:names");
766 isc_mempool_setname(m->rdspool, "msg:rdataset");
799 dns_message_reset(dns_message_t *msg, unsigned int intent) {
800 REQUIRE(DNS_MESSAGE_VALID(msg));
804 msgreset(msg, ISC_FALSE);
805 msg->from_to_wire = intent;
810 dns_message_t *msg;
815 msg = *msgp;
818 msgreset(msg, ISC_TRUE);
819 isc_mempool_destroy(&msg->namepool);
820 isc_mempool_destroy(&msg->rdspool);
821 msg->magic = 0;
822 isc_mem_putanddetach(&msg->mctx, msg, sizeof(dns_message_t));
897 getname(dns_name_t *name, isc_buffer_t *source, dns_message_t *msg,
904 scratch = currentbuffer(msg);
918 result = newbuffer(msg, SCRATCHPAD_SIZE);
922 scratch = currentbuffer(msg);
934 getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
943 scratch = currentbuffer(msg);
975 result = newbuffer(msg, trysize);
979 scratch = currentbuffer(msg);
997 getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
1015 section = &msg->sections[DNS_SECTION_QUESTION];
1024 for (count = 0; count < msg->counts[DNS_SECTION_QUESTION]; count++) {
1025 name = isc_mempool_get(msg->namepool);
1030 offsets = newoffsets(msg);
1042 result = getname(name, source, msg, dctx);
1070 isc_mempool_put(msg->namepool, name);
1091 if (msg->rdclass_set == 0) {
1092 msg->rdclass = rdclass;
1093 msg->rdclass_set = 1;
1094 } else if (msg->rdclass != rdclass)
1101 msg->tkey = 1;
1113 rdatalist = newrdatalist(msg);
1118 rdataset = isc_mempool_get(msg->rdspool);
1152 isc_mempool_put(msg->rdspool, rdataset);
1156 isc_mempool_put(msg->rdlpool, rdatalist);
1159 isc_mempool_put(msg->namepool, name);
1175 getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
1199 for (count = 0; count < msg->counts[sectionid]; count++) {
1203 section = &msg->sections[sectionid];
1209 name = isc_mempool_get(msg->namepool);
1214 offsets = newoffsets(msg);
1226 result = getname(name, source, msg, dctx);
1247 if (msg->rdclass_set == 0 &&
1251 msg->rdclass = rdclass;
1252 msg->rdclass_set = 1;
1259 if (msg->opcode != dns_opcode_update
1265 && msg->rdclass != dns_rdataclass_any
1266 && msg->rdclass != rdclass)
1273 if (msg->opcode != dns_opcode_update && !msg->tkey &&
1275 msg->rdclass != dns_rdataclass_any &&
1276 msg->rdclass != rdclass)
1289 count != msg->counts[sectionid] - 1)
1291 msg->sigstart = recstart;
1301 msg->opt != NULL)
1315 if ((msg->flags & DNS_MESSAGEFLAG_QR) == 0)
1341 rdata = newrdata(msg);
1346 if (msg->opcode == dns_opcode_update &&
1366 msg->opcode == dns_opcode_update &&
1368 result = getrdata(source, msg, dctx, msg->rdclass,
1371 result = getrdata(source, msg, dctx, rdclass,
1387 count != msg->counts[sectionid] - 1)
1389 msg->sigstart = recstart;
1394 if (msg->rdclass != dns_rdataclass_any &&
1395 msg->rdclass != rdclass)
1406 if (preserve_order || msg->opcode == dns_opcode_update ||
1428 isc_mempool_put(msg->namepool, name);
1440 if (preserve_order || msg->opcode == dns_opcode_update ||
1480 rdataset = isc_mempool_get(msg->rdspool);
1487 rdatalist = newrdatalist(msg);
1533 * the extended rcode. Note that msg->opt will only be set
1536 if (rdtype == dns_rdatatype_opt && msg->opt == NULL) {
1539 msg->opt = rdataset;
1543 ((msg->opt->ttl & DNS_MESSAGE_EDNSRCODE_MASK)
1545 msg->rcode |= ercode;
1546 isc_mempool_put(msg->namepool, name);
1552 * that msg->sig0 or msg->tsig will only be set if best-effort
1555 if (issigzero && msg->sig0 == NULL) {
1556 msg->sig0 = rdataset;
1557 msg->sig0name = name;
1561 } else if (rdtype == dns_rdatatype_tsig && msg->tsig == NULL) {
1562 msg->tsig = rdataset;
1563 msg->tsigname = name;
1565 msg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
1573 isc_mempool_put(msg->namepool, name);
1575 isc_mempool_put(msg->rdspool, rdataset);
1588 isc_mempool_put(msg->namepool, name);
1590 isc_mempool_put(msg->rdspool, rdataset);
1596 dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
1607 REQUIRE(DNS_MESSAGE_VALID(msg));
1609 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
1616 msg->header_ok = 0;
1617 msg->question_ok = 0;
1623 msg->id = isc_buffer_getuint16(source);
1625 msg->opcode = ((tmpflags & DNS_MESSAGE_OPCODE_MASK)
1627 msg->rcode = (dns_rcode_t)(tmpflags & DNS_MESSAGE_RCODE_MASK);
1628 msg->flags = (tmpflags & DNS_MESSAGE_FLAG_MASK);
1629 msg->counts[DNS_SECTION_QUESTION] = isc_buffer_getuint16(source);
1630 msg->counts[DNS_SECTION_ANSWER] = isc_buffer_getuint16(source);
1631 msg->counts[DNS_SECTION_AUTHORITY] = isc_buffer_getuint16(source);
1632 msg->counts[DNS_SECTION_ADDITIONAL] = isc_buffer_getuint16(source);
1634 msg->header_ok = 1;
1635 msg->state = DNS_SECTION_QUESTION;
1644 ret = getquestions(source, msg, &dctx, options);
1653 msg->question_ok = 1;
1655 ret = getsection(source, msg, &dctx, DNS_SECTION_ANSWER, options);
1665 ret = getsection(source, msg, &dctx, DNS_SECTION_AUTHORITY, options);
1675 ret = getsection(source, msg, &dctx, DNS_SECTION_ADDITIONAL, options);
1695 isc_buffer_usedregion(&origsource, &msg->saved);
1697 msg->saved.length = isc_buffer_usedlength(&origsource);
1698 msg->saved.base = isc_mem_get(msg->mctx, msg->saved.length);
1699 if (msg->saved.base == NULL)
1701 memmove(msg->saved.base, isc_buffer_base(&origsource),
1702 msg->saved.length);
1703 msg->free_saved = 1;
1714 dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx,
1719 REQUIRE(DNS_MESSAGE_VALID(msg));
1721 REQUIRE(msg->buffer == NULL);
1722 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
1724 msg->cctx = cctx;
1739 if (r.length - DNS_MESSAGE_HEADERLEN < msg->reserved)
1747 msg->buffer = buffer;
1753 dns_message_renderchangebuffer(dns_message_t *msg, isc_buffer_t *buffer) {
1756 REQUIRE(DNS_MESSAGE_VALID(msg));
1758 REQUIRE(msg->buffer != NULL);
1767 isc_buffer_usedregion(msg->buffer, &r);
1776 msg->buffer = buffer;
1782 dns_message_renderrelease(dns_message_t *msg, unsigned int space) {
1783 REQUIRE(DNS_MESSAGE_VALID(msg));
1784 REQUIRE(space <= msg->reserved);
1786 msg->reserved -= space;
1790 dns_message_renderreserve(dns_message_t *msg, unsigned int space) {
1793 REQUIRE(DNS_MESSAGE_VALID(msg));
1795 if (msg->buffer != NULL) {
1796 isc_buffer_availableregion(msg->buffer, &r);
1797 if (r.length < (space + msg->reserved))
1801 msg->reserved += space;
1890 dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
1904 REQUIRE(DNS_MESSAGE_VALID(msg));
1905 REQUIRE(msg->buffer != NULL);
1908 section = &msg->sections[sectionid];
1931 if (msg->buffer->length - msg->buffer->used < msg->reserved)
1933 msg->buffer->length -= msg->reserved;
1936 if (msg->reserved == 0 && (options & DNS_MESSAGERENDER_PARTIAL) != 0)
1948 const void *order_arg = msg->order_arg;
1949 st = *(msg->buffer);
1954 msg->cctx,
1955 msg->buffer,
1956 msg->order,
1964 msg->cctx,
1965 msg->buffer,
1966 msg->order,
1972 msg->flags |= DNS_MESSAGEFLAG_TC;
1973 msg->buffer->length += msg->reserved;
1974 msg->counts[sectionid] += total;
1978 msg->flags |= DNS_MESSAGEFLAG_TC;
1981 dns_compress_rollback(msg->cctx,
1983 *(msg->buffer) = st; /* rollback */
1984 msg->buffer->length += msg->reserved;
1985 msg->counts[sectionid] += total;
1995 msg->buffer->length += msg->reserved;
1996 msg->counts[sectionid] += total;
2028 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2030 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2035 st = *(msg->buffer);
2042 msg->cctx,
2043 msg->buffer,
2044 msg->order,
2045 msg->order_arg,
2053 msg->cctx,
2054 msg->buffer,
2055 msg->order,
2056 msg->order_arg,
2076 msg->buffer->length += msg->reserved;
2077 msg->counts[sectionid] += total;
2082 dns_compress_rollback(msg->cctx,
2084 *(msg->buffer) = st; /* rollback */
2085 msg->buffer->length += msg->reserved;
2086 msg->counts[sectionid] += total;
2097 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2099 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2112 msg->buffer->length += msg->reserved;
2113 msg->counts[sectionid] += total;
2119 dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target) {
2123 REQUIRE(DNS_MESSAGE_VALID(msg));
2129 isc_buffer_putuint16(target, msg->id);
2131 tmp = ((msg->opcode << DNS_MESSAGE_OPCODE_SHIFT)
2133 tmp |= (msg->rcode & DNS_MESSAGE_RCODE_MASK);
2134 tmp |= (msg->flags & DNS_MESSAGE_FLAG_MASK);
2136 INSIST(msg->counts[DNS_SECTION_QUESTION] < 65536 &&
2137 msg->counts[DNS_SECTION_ANSWER] < 65536 &&
2138 msg->counts[DNS_SECTION_AUTHORITY] < 65536 &&
2139 msg->counts[DNS_SECTION_ADDITIONAL] < 65536);
2143 (isc_uint16_t)msg->counts[DNS_SECTION_QUESTION]);
2145 (isc_uint16_t)msg->counts[DNS_SECTION_ANSWER]);
2147 (isc_uint16_t)msg->counts[DNS_SECTION_AUTHORITY]);
2149 (isc_uint16_t)msg->counts[DNS_SECTION_ADDITIONAL]);
2153 dns_message_renderend(dns_message_t *msg) {
2159 REQUIRE(DNS_MESSAGE_VALID(msg));
2160 REQUIRE(msg->buffer != NULL);
2162 if ((msg->rcode & ~DNS_MESSAGE_RCODE_MASK) != 0 && msg->opt == NULL) {
2175 if ((msg->tsigkey != NULL || msg->sig0key != NULL || msg->opt) &&
2176 (msg->flags & DNS_MESSAGEFLAG_TC) != 0)
2180 msgresetnames(msg, DNS_SECTION_ANSWER);
2181 buf = msg->buffer;
2182 dns_message_renderreset(msg);
2183 msg->buffer = buf;
2184 isc_buffer_clear(msg->buffer);
2185 isc_buffer_add(msg->buffer, DNS_MESSAGE_HEADERLEN);
2186 dns_compress_rollback(msg->cctx, 0);
2187 result = dns_message_rendersection(msg, DNS_SECTION_QUESTION,
2196 if (msg->opt != NULL) {
2197 dns_message_renderrelease(msg, msg->opt_reserved);
2198 msg->opt_reserved = 0;
2202 msg->opt->ttl &= ~DNS_MESSAGE_EDNSRCODE_MASK;
2203 msg->opt->ttl |= ((msg->rcode << 20) &
2209 result = renderset(msg->opt, dns_rootname, msg->cctx,
2210 msg->buffer, msg->reserved, 0, &count);
2211 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2219 if (msg->tsigkey != NULL) {
2220 dns_message_renderrelease(msg, msg->sig_reserved);
2221 msg->sig_reserved = 0;
2222 result = dns_tsig_sign(msg);
2226 result = renderset(msg->tsig, msg->tsigname, msg->cctx,
2227 msg->buffer, msg->reserved, 0, &count);
2228 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2236 if (msg->sig0key != NULL) {
2237 dns_message_renderrelease(msg, msg->sig_reserved);
2238 msg->sig_reserved = 0;
2239 result = dns_dnssec_signmessage(msg, msg->sig0key);
2244 * Note: dns_rootname is used here, not msg->sig0name, since
2248 result = renderset(msg->sig0, dns_rootname, msg->cctx,
2249 msg->buffer, msg->reserved, 0, &count);
2250 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2255 isc_buffer_usedregion(msg->buffer, &r);
2258 dns_message_renderheader(msg, &tmpbuf);
2260 msg->buffer = NULL; /* forget about this buffer only on success XXX */
2266 dns_message_renderreset(dns_message_t *msg) {
2275 REQUIRE(DNS_MESSAGE_VALID(msg));
2276 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2278 msg->buffer = NULL;
2281 msg->cursors[i] = NULL;
2282 msg->counts[i] = 0;
2283 for (name = ISC_LIST_HEAD(msg->sections[i]);
2293 if (msg->tsigname != NULL)
2294 dns_message_puttempname(msg, &msg->tsigname);
2295 if (msg->tsig != NULL) {
2296 dns_rdataset_disassociate(msg->tsig);
2297 dns_message_puttemprdataset(msg, &msg->tsig);
2299 if (msg->sig0 != NULL) {
2300 dns_rdataset_disassociate(msg->sig0);
2301 dns_message_puttemprdataset(msg, &msg->sig0);
2306 dns_message_firstname(dns_message_t *msg, dns_section_t section) {
2307 REQUIRE(DNS_MESSAGE_VALID(msg));
2310 msg->cursors[section] = ISC_LIST_HEAD(msg->sections[section]);
2312 if (msg->cursors[section] == NULL)
2319 dns_message_nextname(dns_message_t *msg, dns_section_t section) {
2320 REQUIRE(DNS_MESSAGE_VALID(msg));
2322 REQUIRE(msg->cursors[section] != NULL);
2324 msg->cursors[section] = ISC_LIST_NEXT(msg->cursors[section], link);
2326 if (msg->cursors[section] == NULL)
2333 dns_message_currentname(dns_message_t *msg, dns_section_t section,
2336 REQUIRE(DNS_MESSAGE_VALID(msg));
2339 REQUIRE(msg->cursors[section] != NULL);
2341 *name = msg->cursors[section];
2345 dns_message_findname(dns_message_t *msg, dns_section_t section,
2359 REQUIRE(msg != NULL);
2372 &msg->sections[section]);
2396 dns_message_movename(dns_message_t *msg, dns_name_t *name,
2400 REQUIRE(msg != NULL);
2401 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2409 ISC_LIST_UNLINK(msg->sections[fromsection], name, link);
2410 ISC_LIST_APPEND(msg->sections[tosection], name, link);
2414 dns_message_addname(dns_message_t *msg, dns_name_t *name,
2417 REQUIRE(msg != NULL);
2418 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2422 ISC_LIST_APPEND(msg->sections[section], name, link);
2426 dns_message_removename(dns_message_t *msg, dns_name_t *name,
2429 REQUIRE(msg != NULL);
2430 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2434 ISC_LIST_UNLINK(msg->sections[section], name, link);
2438 dns_message_gettempname(dns_message_t *msg, dns_name_t **item) {
2439 REQUIRE(DNS_MESSAGE_VALID(msg));
2442 *item = isc_mempool_get(msg->namepool);
2451 dns_message_gettempoffsets(dns_message_t *msg, dns_offsets_t **item) {
2452 REQUIRE(DNS_MESSAGE_VALID(msg));
2455 *item = newoffsets(msg);
2463 dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item) {
2464 REQUIRE(DNS_MESSAGE_VALID(msg));
2467 *item = newrdata(msg);
2475 dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
2476 REQUIRE(DNS_MESSAGE_VALID(msg));
2479 *item = isc_mempool_get(msg->rdspool);
2489 dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2490 REQUIRE(DNS_MESSAGE_VALID(msg));
2493 *item = newrdatalist(msg);
2501 dns_message_puttempname(dns_message_t *msg, dns_name_t **item) {
2502 REQUIRE(DNS_MESSAGE_VALID(msg));
2506 dns_name_free(*item, msg->mctx);
2507 isc_mempool_put(msg->namepool, *item);
2512 dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item) {
2513 REQUIRE(DNS_MESSAGE_VALID(msg));
2516 releaserdata(msg, *item);
2521 dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
2522 REQUIRE(DNS_MESSAGE_VALID(msg));
2526 isc_mempool_put(msg->rdspool, *item);
2531 dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2532 REQUIRE(DNS_MESSAGE_VALID(msg));
2535 releaserdatalist(msg, *item);
2569 dns_message_reply(dns_message_t *msg, isc_boolean_t want_question_section) {
2573 REQUIRE(DNS_MESSAGE_VALID(msg));
2574 REQUIRE((msg->flags & DNS_MESSAGEFLAG_QR) == 0);
2576 if (!msg->header_ok)
2578 if (msg->opcode != dns_opcode_query &&
2579 msg->opcode != dns_opcode_notify)
2581 if (msg->opcode == dns_opcode_update)
2584 if (!msg->question_ok)
2589 msg->from_to_wire = DNS_MESSAGE_INTENTRENDER;
2590 msgresetnames(msg, clear_after);
2591 msgresetopt(msg);
2592 msgresetsigs(msg, ISC_TRUE);
2593 msginitprivate(msg);
2598 msg->flags &= DNS_MESSAGE_REPLYPRESERVE;
2599 msg->flags |= DNS_MESSAGEFLAG_QR;
2605 if (msg->tsigkey != NULL) {
2607 msg->querytsigstatus = msg->tsigstatus;
2608 msg->tsigstatus = dns_rcode_noerror;
2609 if (msg->querytsigstatus == dns_tsigerror_badtime)
2611 msg->sig_reserved = spacefortsig(msg->tsigkey, otherlen);
2612 result = dns_message_renderreserve(msg, msg->sig_reserved);
2614 msg->sig_reserved = 0;
2618 if (msg->saved.base != NULL) {
2619 msg->query.base = msg->saved.base;
2620 msg->query.length = msg->saved.length;
2621 msg->free_query = msg->free_saved;
2622 msg->saved.base = NULL;
2623 msg->saved.length = 0;
2624 msg->free_saved = 0;
2631 dns_message_getopt(dns_message_t *msg) {
2634 * Get the OPT record for 'msg'.
2637 REQUIRE(DNS_MESSAGE_VALID(msg));
2639 return (msg->opt);
2643 dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt) {
2648 * Set the OPT record for 'msg'.
2665 REQUIRE(DNS_MESSAGE_VALID(msg));
2667 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2668 REQUIRE(msg->state == DNS_SECTION_ANY);
2670 msgresetopt(msg);
2676 msg->opt_reserved = 11 + rdata.length;
2677 result = dns_message_renderreserve(msg, msg->opt_reserved);
2679 msg->opt_reserved = 0;
2683 msg->opt = opt;
2689 dns_message_puttemprdataset(msg, &opt);
2694 dns_message_gettsig(dns_message_t *msg, dns_name_t **owner) {
2697 * Get the TSIG record and owner for 'msg'.
2700 REQUIRE(DNS_MESSAGE_VALID(msg));
2704 *owner = msg->tsigname;
2705 return (msg->tsig);
2709 dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key) {
2713 * Set the TSIG key for 'msg'
2716 REQUIRE(DNS_MESSAGE_VALID(msg));
2717 REQUIRE(msg->state == DNS_SECTION_ANY);
2719 if (key == NULL && msg->tsigkey != NULL) {
2720 if (msg->sig_reserved != 0) {
2721 dns_message_renderrelease(msg, msg->sig_reserved);
2722 msg->sig_reserved = 0;
2724 dns_tsigkey_detach(&msg->tsigkey);
2727 REQUIRE(msg->tsigkey == NULL && msg->sig0key == NULL);
2728 dns_tsigkey_attach(key, &msg->tsigkey);
2729 if (msg->from_to_wire == DNS_MESSAGE_INTENTRENDER) {
2730 msg->sig_reserved = spacefortsig(msg->tsigkey, 0);
2731 result = dns_message_renderreserve(msg,
2732 msg->sig_reserved);
2734 dns_tsigkey_detach(&msg->tsigkey);
2735 msg->sig_reserved = 0;
2744 dns_message_gettsigkey(dns_message_t *msg) {
2747 * Get the TSIG key for 'msg'
2750 REQUIRE(DNS_MESSAGE_VALID(msg));
2752 return (msg->tsigkey);
2756 dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) {
2764 REQUIRE(DNS_MESSAGE_VALID(msg));
2765 REQUIRE(msg->querytsig == NULL);
2770 result = dns_message_gettemprdata(msg, &rdata);
2774 result = dns_message_gettemprdatalist(msg, &list);
2777 result = dns_message_gettemprdataset(msg, &set);
2782 result = isc_buffer_allocate(msg->mctx, &buf, r.length);
2789 dns_message_takebuffer(msg, &buf);
2796 msg->querytsig = set;
2802 dns_message_puttemprdata(msg, &rdata);
2804 dns_message_puttemprdatalist(msg, &list);
2806 dns_message_puttemprdataset(msg, &set);
2811 dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx,
2817 REQUIRE(DNS_MESSAGE_VALID(msg));
2821 if (msg->tsig == NULL)
2824 result = dns_rdataset_first(msg->tsig);
2827 dns_rdataset_current(msg->tsig, &rdata);
2838 dns_message_getsig0(dns_message_t *msg, dns_name_t **owner) {
2841 * Get the SIG(0) record for 'msg'.
2844 REQUIRE(DNS_MESSAGE_VALID(msg));
2847 if (msg->sig0 != NULL && owner != NULL) {
2852 if (msg->sig0name == NULL)
2855 *owner = msg->sig0name;
2857 return (msg->sig0);
2861 dns_message_setsig0key(dns_message_t *msg, dst_key_t *key) {
2867 * Set the SIG(0) key for 'msg'
2889 REQUIRE(DNS_MESSAGE_VALID(msg));
2890 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2891 REQUIRE(msg->state == DNS_SECTION_ANY);
2894 REQUIRE(msg->sig0key == NULL && msg->tsigkey == NULL);
2898 msg->sig_reserved = 0;
2901 msg->sig_reserved = 27 + r.length + x;
2902 result = dns_message_renderreserve(msg, msg->sig_reserved);
2904 msg->sig_reserved = 0;
2907 msg->sig0key = key;
2913 dns_message_getsig0key(dns_message_t *msg) {
2916 * Get the SIG(0) key for 'msg'
2919 REQUIRE(DNS_MESSAGE_VALID(msg));
2921 return (msg->sig0key);
2925 dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer) {
2926 REQUIRE(DNS_MESSAGE_VALID(msg));
2930 ISC_LIST_APPEND(msg->cleanup, *buffer, link);
2935 dns_message_signer(dns_message_t *msg, dns_name_t *signer) {
2939 REQUIRE(DNS_MESSAGE_VALID(msg));
2941 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
2943 if (msg->tsig == NULL && msg->sig0 == NULL)
2946 if (msg->verify_attempted == 0)
2951 result = isc_buffer_allocate(msg->mctx, &dynbuf, 512);
2955 dns_message_takebuffer(msg, &dynbuf);
2958 if (msg->sig0 != NULL) {
2961 result = dns_rdataset_first(msg->sig0);
2963 dns_rdataset_current(msg->sig0, &rdata);
2969 if (msg->verified_sig && msg->sig0status == dns_rcode_noerror)
2979 result = dns_rdataset_first(msg->tsig);
2981 dns_rdataset_current(msg->tsig, &rdata);
2985 if (msg->tsigstatus != dns_rcode_noerror)
2993 if (msg->tsigkey == NULL) {
2995 * If msg->tsigstatus & tsig.error are both
2997 * verified, which means msg->tsigkey will be
3002 identity = dns_tsigkey_identity(msg->tsigkey);
3006 identity = &msg->tsigkey->name;
3016 dns_message_resetsig(dns_message_t *msg) {
3017 REQUIRE(DNS_MESSAGE_VALID(msg));
3018 msg->verified_sig = 0;
3019 msg->verify_attempted = 0;
3020 msg->tsigstatus = dns_rcode_noerror;
3021 msg->sig0status = dns_rcode_noerror;
3022 msg->timeadjust = 0;
3023 if (msg->tsigkey != NULL) {
3024 dns_tsigkey_detach(&msg->tsigkey);
3025 msg->tsigkey = NULL;
3030 dns_message_rechecksig(dns_message_t *msg, dns_view_t *view) {
3031 dns_message_resetsig(msg);
3032 return (dns_message_checksig(msg, view));
3037 dns_message_dumpsig(dns_message_t *msg, char *txt1) {
3042 if (msg->tsig != NULL) {
3043 result = dns_rdataset_first(msg->tsig);
3045 dns_rdataset_current(msg->tsig, &querytsigrdata);
3052 if (msg->querytsig != NULL) {
3053 result = dns_rdataset_first(msg->querytsig);
3055 dns_rdataset_current(msg->querytsig, &querytsigrdata);
3065 dns_message_checksig(dns_message_t *msg, dns_view_t *view) {
3068 REQUIRE(DNS_MESSAGE_VALID(msg));
3070 if (msg->tsigkey == NULL && msg->tsig == NULL && msg->sig0 == NULL)
3073 INSIST(msg->saved.base != NULL);
3074 isc_buffer_init(&msgb, msg->saved.base, msg->saved.length);
3075 isc_buffer_add(&msgb, msg->saved.length);
3076 if (msg->tsigkey != NULL || msg->tsig != NULL) {
3078 dns_message_dumpsig(msg, "dns_message_checksig#1");
3081 return (dns_view_checksig(view, &msgb, msg));
3083 return (dns_tsig_verify(&msgb, msg, NULL, NULL));
3090 result = dns_rdataset_first(msg->sig0);
3092 dns_rdataset_current(msg->sig0, &rdata);
3104 result = dns_rdata_tostruct(&rdata, &sig, msg->mctx);
3149 result = dns_dnssec_verifymessage(&msgb, msg, key);
3166 dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
3175 REQUIRE(DNS_MESSAGE_VALID(msg));
3179 if (ISC_LIST_EMPTY(msg->sections[section]))
3184 if (msg->opcode != dns_opcode_update) {
3193 result = dns_message_firstname(msg, section);
3199 dns_message_currentname(msg, section, &name);
3227 result = dns_message_nextname(msg, section);
3238 dns_message_pseudosectiontotext(dns_message_t *msg,
3253 REQUIRE(DNS_MESSAGE_VALID(msg));
3259 ps = dns_message_getopt(msg);
3332 ps = dns_message_gettsig(msg, &name);
3343 ps = dns_message_getsig0(msg, &name);
3358 dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
3363 REQUIRE(DNS_MESSAGE_VALID(msg));
3368 ADD_STRING(target, opcodetext[msg->opcode]);
3370 if (msg->rcode < (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
3371 ADD_STRING(target, rcodetext[msg->rcode]);
3373 snprintf(buf, sizeof(buf), "%4u", msg->rcode);
3377 snprintf(buf, sizeof(buf), "%6u", msg->id);
3380 if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
3382 if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0)
3384 if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
3386 if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0)
3388 if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0)
3390 if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0)
3392 if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0)
3397 if ((msg->flags & 0x0040U) != 0)
3399 if (msg->opcode != dns_opcode_update) {
3405 msg->counts[DNS_SECTION_QUESTION]);
3407 if (msg->opcode != dns_opcode_update) {
3413 msg->counts[DNS_SECTION_ANSWER]);
3415 if (msg->opcode != dns_opcode_update) {
3421 msg->counts[DNS_SECTION_AUTHORITY]);
3425 msg->counts[DNS_SECTION_ADDITIONAL]);
3429 result = dns_message_pseudosectiontotext(msg,
3435 result = dns_message_sectiontotext(msg, DNS_SECTION_QUESTION,
3439 result = dns_message_sectiontotext(msg, DNS_SECTION_ANSWER,
3443 result = dns_message_sectiontotext(msg, DNS_SECTION_AUTHORITY,
3447 result = dns_message_sectiontotext(msg, DNS_SECTION_ADDITIONAL,
3452 result = dns_message_pseudosectiontotext(msg,
3458 result = dns_message_pseudosectiontotext(msg,
3468 dns_message_getrawmessage(dns_message_t *msg) {
3469 REQUIRE(DNS_MESSAGE_VALID(msg));
3470 return (&msg->saved);
3474 dns_message_setsortorder(dns_message_t *msg, dns_rdatasetorderfunc_t order,
3477 REQUIRE(DNS_MESSAGE_VALID(msg));
3478 msg->order = order;
3479 msg->order_arg = order_arg;
3483 dns_message_settimeadjust(dns_message_t *msg, int timeadjust) {
3484 REQUIRE(DNS_MESSAGE_VALID(msg));
3485 msg->timeadjust = timeadjust;
3489 dns_message_gettimeadjust(dns_message_t *msg) {
3490 REQUIRE(DNS_MESSAGE_VALID(msg));
3491 return (msg->timeadjust);
3598 dns_message_setclass(dns_message_t *msg, dns_rdataclass_t rdclass) {
3600 REQUIRE(DNS_MESSAGE_VALID(msg));
3601 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
3602 REQUIRE(msg->state == DNS_SECTION_ANY);
3603 REQUIRE(msg->rdclass_set == 0);
3605 msg->rdclass = rdclass;
3606 msg->rdclass_set = 1;