Lines Matching defs:msg
57 hexdump(const char *msg, const char *msg2, void *base, size_t len) {
64 printf("*** %s [%s] (%u bytes @ %p)\n", msg, msg2, (unsigned int)len,
195 dns_message_t *msg;
208 dns__message_putassociatedrdataset(dns_message_t *msg,
292 newbuffer(dns_message_t *msg, unsigned int size) {
296 isc_buffer_allocate(msg->mctx, &dynbuf, size);
298 ISC_LIST_APPEND(msg->scratchpad, dynbuf, link);
303 currentbuffer(dns_message_t *msg) {
306 dynbuf = ISC_LIST_TAIL(msg->scratchpad);
313 releaserdata(dns_message_t *msg, dns_rdata_t *rdata) {
314 ISC_LIST_PREPEND(msg->freerdata, rdata, link);
318 newrdata(dns_message_t *msg) {
322 rdata = ISC_LIST_HEAD(msg->freerdata);
324 ISC_LIST_UNLINK(msg->freerdata, rdata, link);
328 msgblock = ISC_LIST_TAIL(msg->rdatas);
331 msgblock = msgblock_allocate(msg->mctx, sizeof(dns_rdata_t),
333 ISC_LIST_APPEND(msg->rdatas, msgblock, link);
343 releaserdatalist(dns_message_t *msg, dns_rdatalist_t *rdatalist) {
344 ISC_LIST_PREPEND(msg->freerdatalist, rdatalist, link);
348 newrdatalist(dns_message_t *msg) {
352 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
354 ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
358 msgblock = ISC_LIST_TAIL(msg->rdatalists);
361 msgblock = msgblock_allocate(msg->mctx, sizeof(dns_rdatalist_t),
363 ISC_LIST_APPEND(msg->rdatalists, msgblock, link);
373 newoffsets(dns_message_t *msg) {
377 msgblock = ISC_LIST_TAIL(msg->offsets);
380 msgblock = msgblock_allocate(msg->mctx, sizeof(dns_offsets_t),
382 ISC_LIST_APPEND(msg->offsets, msgblock, link);
467 msgresetname(dns_message_t *msg, dns_name_t *name) {
473 dns__message_putassociatedrdataset(msg, &rds);
478 msgresetnames(dns_message_t *msg, unsigned int first_section) {
483 ISC_LIST_FOREACH_SAFE (msg->sections[i], name, link, next_name)
485 ISC_LIST_UNLINK(msg->sections[i], name, link);
487 msgresetname(msg, name);
489 dns_message_puttempname(msg, &name);
495 msgresetopt(dns_message_t *msg) {
496 if (msg->opt != NULL) {
497 if (msg->opt_reserved > 0) {
498 dns_message_renderrelease(msg, msg->opt_reserved);
499 msg->opt_reserved = 0;
501 dns__message_putassociatedrdataset(msg, &msg->opt);
502 msg->opt = NULL;
503 msg->cc_ok = 0;
504 msg->cc_bad = 0;
509 msgresetsigs(dns_message_t *msg, bool replying) {
510 if (msg->sig_reserved > 0) {
511 dns_message_renderrelease(msg, msg->sig_reserved);
512 msg->sig_reserved = 0;
514 if (msg->tsig != NULL) {
515 INSIST(dns_rdataset_isassociated(msg->tsig));
516 INSIST(msg->namepool != NULL);
518 INSIST(msg->querytsig == NULL);
519 msg->querytsig = msg->tsig;
521 dns__message_putassociatedrdataset(msg, &msg->tsig);
522 if (msg->querytsig != NULL) {
524 msg, &msg->querytsig);
527 dns_message_puttempname(msg, &msg->tsigname);
528 msg->tsig = NULL;
529 } else if (msg->querytsig != NULL && !replying) {
530 dns__message_putassociatedrdataset(msg, &msg->querytsig);
531 msg->querytsig = NULL;
533 if (msg->sig0 != NULL) {
534 dns__message_putassociatedrdataset(msg, &msg->sig0);
535 msg->sig0 = NULL;
537 if (msg->sig0name != NULL) {
538 dns_message_puttempname(msg, &msg->sig0name);
547 msgreset(dns_message_t *msg, bool everything) {
553 msgresetnames(msg, 0);
554 msgresetopt(msg);
555 msgresetsigs(msg, false);
566 rdata = ISC_LIST_HEAD(msg->freerdata);
568 ISC_LIST_UNLINK(msg->freerdata, rdata, link);
569 rdata = ISC_LIST_HEAD(msg->freerdata);
571 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
573 ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
574 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
577 dynbuf = ISC_LIST_HEAD(msg->scratchpad);
585 ISC_LIST_UNLINK(msg->scratchpad, dynbuf, link);
590 msgblock = ISC_LIST_HEAD(msg->rdatas);
597 ISC_LIST_UNLINK(msg->rdatas, msgblock, link);
598 msgblock_free(msg->mctx, msgblock, sizeof(dns_rdata_t));
606 msgblock = ISC_LIST_HEAD(msg->rdatalists);
613 ISC_LIST_UNLINK(msg->rdatalists, msgblock, link);
614 msgblock_free(msg->mctx, msgblock, sizeof(dns_rdatalist_t));
618 msgblock = ISC_LIST_HEAD(msg->offsets);
625 ISC_LIST_UNLINK(msg->offsets, msgblock, link);
626 msgblock_free(msg->mctx, msgblock, sizeof(dns_offsets_t));
630 if (msg->tsigkey != NULL) {
631 dns_tsigkey_detach(&msg->tsigkey);
632 msg->tsigkey = NULL;
635 if (msg->tsigctx != NULL) {
636 dst_context_destroy(&msg->tsigctx);
639 if (msg->query.base != NULL) {
640 if (msg->free_query != 0) {
641 isc_mem_put(msg->mctx, msg->query.base,
642 msg->query.length);
644 msg->query.base = NULL;
645 msg->query.length = 0;
648 if (msg->saved.base != NULL) {
649 if (msg->free_saved != 0) {
650 isc_mem_put(msg->mctx, msg->saved.base,
651 msg->saved.length);
653 msg->saved.base = NULL;
654 msg->saved.length = 0;
660 dynbuf = ISC_LIST_HEAD(msg->cleanup);
663 ISC_LIST_UNLINK(msg->cleanup, dynbuf, link);
668 if (msg->order_arg.env != NULL) {
669 dns_aclenv_detach(&msg->order_arg.env);
671 if (msg->order_arg.acl != NULL) {
672 dns_acl_detach(&msg->order_arg.acl);
679 msginit(msg);
735 dns_message_t *msg = isc_mem_get(mctx, sizeof(dns_message_t));
736 *msg = (dns_message_t){
752 isc_mem_attach(mctx, &msg->mctx);
754 if (msg->free_pools) {
755 dns_message_createpools(mctx, &msg->namepool, &msg->rdspool);
758 msginit(msg);
761 ISC_LIST_INIT(msg->sections[i]);
766 ISC_LIST_APPEND(msg->scratchpad, dynbuf, link);
768 *msgp = msg;
772 dns_message_reset(dns_message_t *msg, dns_message_intent_t intent) {
773 REQUIRE(DNS_MESSAGE_VALID(msg));
777 msgreset(msg, false);
778 msg->from_to_wire = intent;
782 dns__message_destroy(dns_message_t *msg) {
783 REQUIRE(msg != NULL);
784 REQUIRE(DNS_MESSAGE_VALID(msg));
786 msgreset(msg, true);
788 msg->magic = 0;
790 if (msg->free_pools) {
791 dns_message_destroypools(&msg->namepool, &msg->rdspool);
794 isc_mem_putanddetach(&msg->mctx, msg, sizeof(dns_message_t));
869 getname(dns_name_t *name, isc_buffer_t *source, dns_message_t *msg,
875 scratch = currentbuffer(msg);
888 result = newbuffer(msg, SCRATCHPAD_SIZE);
893 scratch = currentbuffer(msg);
904 getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx,
912 scratch = currentbuffer(msg);
945 result = newbuffer(msg, trysize);
950 scratch = currentbuffer(msg);
978 getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx,
989 dns_namelist_t *section = &msg->sections[DNS_SECTION_QUESTION];
996 if (msg->counts[DNS_SECTION_QUESTION] > 1) {
997 isc_hashmap_create(msg->mctx, 1, &name_map);
1000 for (count = 0; count < msg->counts[DNS_SECTION_QUESTION]; count++) {
1002 dns_message_gettempname(msg, &name);
1003 name->offsets = (unsigned char *)newoffsets(msg);
1011 result = getname(name, source, msg, dctx);
1051 dns_message_puttempname(msg, &name);
1076 if (msg->rdclass_set == 0) {
1077 msg->rdclass = rdclass;
1078 msg->rdclass_set = 1;
1079 } else if (msg->rdclass != rdclass) {
1087 msg->tkey = 1;
1093 rdatalist = newrdatalist(msg);
1102 dns_message_gettemprdataset(msg, &rdataset);
1119 isc_hashmap_create(msg->mctx, 1, &name->hashmap);
1156 dns_message_puttemprdataset(msg, &rdataset);
1160 dns_message_puttempname(msg, &name);
1238 getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx,
1252 dns_namelist_t *section = &msg->sections[sectionid];
1260 if (msg->counts[sectionid] > 1) {
1261 isc_hashmap_create(msg->mctx, 1, &name_map);
1264 for (count = 0; count < msg->counts[sectionid]; count++) {
1276 dns_message_gettempname(msg, &name);
1277 name->offsets = (unsigned char *)newoffsets(msg);
1285 result = getname(name, source, msg, dctx);
1307 if (msg->rdclass_set == 0 &&
1312 msg->rdclass = rdclass;
1313 msg->rdclass_set = 1;
1320 if (msg->opcode != dns_opcode_update &&
1326 msg->rdclass != dns_rdataclass_any &&
1327 msg->rdclass != rdclass)
1336 if (msg->opcode != dns_opcode_update && !msg->tkey &&
1338 msg->rdclass != dns_rdataclass_any &&
1339 msg->rdclass != rdclass)
1354 count != msg->counts[sectionid] - 1)
1370 msg->opt != NULL)
1388 if ((msg->flags & DNS_MESSAGEFLAG_QR) == 0) {
1417 rdata = newrdata(msg);
1418 if (msg->opcode == dns_opcode_update &&
1439 msg->opcode == dns_opcode_update &&
1442 result = getrdata(source, msg, dctx, msg->rdclass,
1445 result = getrdata(source, msg, dctx, rdclass, rdtype,
1463 count != msg->counts[sectionid] - 1 ||
1473 if (msg->rdclass != dns_rdataclass_any &&
1474 msg->rdclass != rdclass)
1488 !dns_rdata_checkowner(name, msg->rdclass, rdtype, false))
1499 if (preserve_order || msg->opcode == dns_opcode_update ||
1531 dns_message_puttempname(msg, &name);
1541 rdatalist = newrdatalist(msg);
1547 dns_message_gettemprdataset(msg, &rdataset);
1558 } else if (preserve_order || msg->opcode == dns_opcode_update ||
1579 isc_hashmap_create(msg->mctx, 1,
1618 dns__message_putassociatedrdataset(msg,
1667 * Note msg->opt, msg->sig0 and msg->tsig will only be
1674 msg->opt = rdataset;
1675 ercode = (dns_rcode_t)((msg->opt->ttl &
1678 msg->rcode |= ercode;
1679 dns_message_puttempname(msg, &name);
1682 msg->sig0 = rdataset;
1683 msg->sig0name = name;
1684 msg->sigstart = recstart;
1687 msg->tsig = rdataset;
1688 msg->tsigname = name;
1689 msg->sigstart = recstart;
1693 msg->tsigname->attributes.nocompress = true;
1701 dns_message_puttempname(msg, &name);
1714 msg->opcode == dns_opcode_query &&
1715 ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) &&
1716 ((msg->flags & DNS_MESSAGEFLAG_TC) == 0) && !preserve_order &&
1729 dns__message_putassociatedrdataset(msg, &rdataset);
1732 dns_message_puttempname(msg, &name);
1747 dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
1757 REQUIRE(DNS_MESSAGE_VALID(msg));
1759 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
1766 msg->header_ok = 0;
1767 msg->question_ok = 0;
1770 isc_buffer_usedregion(&origsource, &msg->saved);
1772 msg->saved.length = isc_buffer_usedlength(&origsource);
1773 msg->saved.base = isc_mem_get(msg->mctx, msg->saved.length);
1774 memmove(msg->saved.base, isc_buffer_base(&origsource),
1775 msg->saved.length);
1776 msg->free_saved = 1;
1784 msg->id = isc_buffer_getuint16(source);
1786 msg->opcode = ((tmpflags & DNS_MESSAGE_OPCODE_MASK) >>
1788 msg->rcode = (dns_rcode_t)(tmpflags & DNS_MESSAGE_RCODE_MASK);
1789 msg->flags = (tmpflags & DNS_MESSAGE_FLAG_MASK);
1790 msg->counts[DNS_SECTION_QUESTION] = isc_buffer_getuint16(source);
1791 msg->counts[DNS_SECTION_ANSWER] = isc_buffer_getuint16(source);
1792 msg->counts[DNS_SECTION_AUTHORITY] = isc_buffer_getuint16(source);
1793 msg->counts[DNS_SECTION_ADDITIONAL] = isc_buffer_getuint16(source);
1795 msg->header_ok = 1;
1796 msg->state = DNS_SECTION_QUESTION;
1800 ret = getquestions(source, msg, dctx, options);
1812 msg->question_ok = 1;
1814 ret = getsection(source, msg, dctx, DNS_SECTION_ANSWER, options);
1826 ret = getsection(source, msg, dctx, DNS_SECTION_AUTHORITY, options);
1838 ret = getsection(source, msg, dctx, DNS_SECTION_ADDITIONAL, options);
1870 dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx,
1874 REQUIRE(DNS_MESSAGE_VALID(msg));
1877 REQUIRE(msg->buffer == NULL);
1878 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
1880 msg->cctx = cctx;
1896 if (r.length - DNS_MESSAGE_HEADERLEN < msg->reserved) {
1905 msg->buffer = buffer;
1911 dns_message_renderchangebuffer(dns_message_t *msg, isc_buffer_t *buffer) {
1914 REQUIRE(DNS_MESSAGE_VALID(msg));
1916 REQUIRE(msg->buffer != NULL);
1925 isc_buffer_usedregion(msg->buffer, &r);
1934 msg->buffer = buffer;
1940 dns_message_renderrelease(dns_message_t *msg, unsigned int space) {
1941 REQUIRE(DNS_MESSAGE_VALID(msg));
1942 REQUIRE(space <= msg->reserved);
1944 msg->reserved -= space;
1948 dns_message_renderreserve(dns_message_t *msg, unsigned int space) {
1951 REQUIRE(DNS_MESSAGE_VALID(msg));
1953 if (msg->buffer != NULL) {
1954 isc_buffer_availableregion(msg->buffer, &r);
1955 if (r.length < (space + msg->reserved)) {
1960 msg->reserved += space;
2022 maybe_clear_ad(dns_message_t *msg, dns_section_t sectionid) {
2023 if (msg->counts[sectionid] == 0 &&
2026 msg->counts[DNS_SECTION_ANSWER] == 0)))
2028 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2033 update_min_section_ttl(dns_message_t *restrict msg,
2036 if (!msg->minttl[sectionid].is_set ||
2037 rdataset->ttl < msg->minttl[sectionid].ttl)
2039 msg->minttl[sectionid].is_set = true;
2040 msg->minttl[sectionid].ttl = rdataset->ttl;
2045 dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid,
2058 REQUIRE(DNS_MESSAGE_VALID(msg));
2059 REQUIRE(msg->buffer != NULL);
2062 section = &msg->sections[sectionid];
2089 if (msg->buffer->length - msg->buffer->used < msg->reserved) {
2092 msg->buffer->length -= msg->reserved;
2095 if (msg->reserved == 0 && (options & DNS_MESSAGERENDER_PARTIAL) != 0) {
2110 const void *order_arg = &msg->order_arg;
2111 st = *(msg->buffer);
2115 rdataset, name, msg->cctx, msg->buffer,
2116 msg->order, order_arg, rd_options,
2120 rdataset, name, msg->cctx, msg->buffer,
2121 msg->order, order_arg, rd_options,
2126 msg->flags |= DNS_MESSAGEFLAG_TC;
2127 msg->buffer->length += msg->reserved;
2128 msg->counts[sectionid] += total;
2132 msg->flags |= DNS_MESSAGEFLAG_TC;
2135 dns_compress_rollback(msg->cctx, st.used);
2136 *(msg->buffer) = st; /* rollback */
2137 msg->buffer->length += msg->reserved;
2138 msg->counts[sectionid] += total;
2142 update_min_section_ttl(msg, sectionid, rdataset);
2151 msg->buffer->length += msg->reserved;
2152 msg->counts[sectionid] += total;
2178 st = *(msg->buffer);
2183 rdataset, name, msg->cctx,
2184 msg->buffer, msg->order,
2185 &msg->order_arg, rd_options,
2189 rdataset, name, msg->cctx,
2190 msg->buffer, msg->order,
2191 &msg->order_arg, rd_options,
2211 msg->buffer->length += msg->reserved;
2212 msg->counts[sectionid] += total;
2218 msg->cctx, (uint16_t)st.used);
2219 *(msg->buffer) = st; /* rollback */
2220 msg->buffer->length += msg->reserved;
2221 msg->counts[sectionid] += total;
2222 maybe_clear_ad(msg, sectionid);
2234 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2237 msg->flags &= ~DNS_MESSAGEFLAG_AD;
2240 update_min_section_ttl(msg, sectionid,
2254 msg->buffer->length += msg->reserved;
2255 msg->counts[sectionid] += total;
2261 dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target) {
2265 REQUIRE(DNS_MESSAGE_VALID(msg));
2271 isc_buffer_putuint16(target, msg->id);
2273 tmp = ((msg->opcode << DNS_MESSAGE_OPCODE_SHIFT) &
2275 tmp |= (msg->rcode & DNS_MESSAGE_RCODE_MASK);
2276 tmp |= (msg->flags & DNS_MESSAGE_FLAG_MASK);
2278 INSIST(msg->counts[DNS_SECTION_QUESTION] < 65536 &&
2279 msg->counts[DNS_SECTION_ANSWER] < 65536 &&
2280 msg->counts[DNS_SECTION_AUTHORITY] < 65536 &&
2281 msg->counts[DNS_SECTION_ADDITIONAL] < 65536);
2285 (uint16_t)msg->counts[DNS_SECTION_QUESTION]);
2286 isc_buffer_putuint16(target, (uint16_t)msg->counts[DNS_SECTION_ANSWER]);
2288 (uint16_t)msg->counts[DNS_SECTION_AUTHORITY]);
2290 (uint16_t)msg->counts[DNS_SECTION_ADDITIONAL]);
2294 dns_message_renderend(dns_message_t *msg) {
2300 REQUIRE(DNS_MESSAGE_VALID(msg));
2301 REQUIRE(msg->buffer != NULL);
2303 if ((msg->rcode & ~DNS_MESSAGE_RCODE_MASK) != 0 && msg->opt == NULL) {
2316 if ((msg->tsigkey != NULL || msg->sig0key != NULL || msg->opt) &&
2317 (msg->flags & DNS_MESSAGEFLAG_TC) != 0)
2321 msgresetnames(msg, DNS_SECTION_ANSWER);
2322 buf = msg->buffer;
2323 dns_message_renderreset(msg);
2324 msg->buffer = buf;
2325 isc_buffer_clear(msg->buffer);
2326 isc_buffer_add(msg->buffer, DNS_MESSAGE_HEADERLEN);
2327 dns_compress_rollback(msg->cctx, 0);
2328 result = dns_message_rendersection(msg, DNS_SECTION_QUESTION,
2338 if (msg->opt != NULL) {
2339 dns_message_renderrelease(msg, msg->opt_reserved);
2340 msg->opt_reserved = 0;
2342 * Set the extended rcode. Cast msg->rcode to dns_ttl_t
2345 msg->opt->ttl &= ~DNS_MESSAGE_EDNSRCODE_MASK;
2346 msg->opt->ttl |= (((dns_ttl_t)(msg->rcode) << 20) &
2352 result = renderset(msg->opt, dns_rootname, msg->cctx,
2353 msg->buffer, msg->reserved, 0, &count);
2354 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2366 if (msg->padding_off > 0) {
2367 unsigned char *cp = isc_buffer_used(msg->buffer);
2384 used = isc_buffer_usedlength(msg->buffer);
2385 if (msg->padding != 0) {
2386 padsize = ((uint16_t)used + msg->reserved) %
2387 msg->padding;
2390 padsize = msg->padding - padsize;
2393 remaining = isc_buffer_availablelength(msg->buffer);
2398 isc_buffer_add(msg->buffer, padsize);
2402 cp -= msg->padding_off;
2413 if (msg->tsigkey != NULL) {
2414 dns_message_renderrelease(msg, msg->sig_reserved);
2415 msg->sig_reserved = 0;
2416 result = dns_tsig_sign(msg);
2421 result = renderset(msg->tsig, msg->tsigname, msg->cctx,
2422 msg->buffer, msg->reserved, 0, &count);
2423 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2432 if (msg->sig0key != NULL) {
2433 dns_message_renderrelease(msg, msg->sig_reserved);
2434 msg->sig_reserved = 0;
2435 result = dns_dnssec_signmessage(msg, msg->sig0key);
2441 * Note: dns_rootname is used here, not msg->sig0name, since
2445 result = renderset(msg->sig0, dns_rootname, msg->cctx,
2446 msg->buffer, msg->reserved, 0, &count);
2447 msg->counts[DNS_SECTION_ADDITIONAL] += count;
2453 isc_buffer_usedregion(msg->buffer, &r);
2456 dns_message_renderheader(msg, &tmpbuf);
2458 msg->buffer = NULL; /* forget about this buffer only on success XXX */
2464 dns_message_renderreset(dns_message_t *msg) {
2469 REQUIRE(DNS_MESSAGE_VALID(msg));
2470 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2472 msg->buffer = NULL;
2477 msg->cursors[i] = NULL;
2478 msg->counts[i] = 0;
2479 ISC_LIST_FOREACH (msg->sections[i], name, link) {
2486 if (msg->tsigname != NULL) {
2487 dns_message_puttempname(msg, &msg->tsigname);
2489 if (msg->tsig != NULL) {
2490 dns__message_putassociatedrdataset(msg, &msg->tsig);
2492 if (msg->sig0name != NULL) {
2493 dns_message_puttempname(msg, &msg->sig0name);
2495 if (msg->sig0 != NULL) {
2496 dns__message_putassociatedrdataset(msg, &msg->sig0);
2501 dns_message_firstname(dns_message_t *msg, dns_section_t section) {
2502 REQUIRE(DNS_MESSAGE_VALID(msg));
2505 msg->cursors[section] = ISC_LIST_HEAD(msg->sections[section]);
2507 if (msg->cursors[section] == NULL) {
2515 dns_message_nextname(dns_message_t *msg, dns_section_t section) {
2516 REQUIRE(DNS_MESSAGE_VALID(msg));
2518 REQUIRE(msg->cursors[section] != NULL);
2520 msg->cursors[section] = ISC_LIST_NEXT(msg->cursors[section], link);
2522 if (msg->cursors[section] == NULL) {
2530 dns_message_currentname(dns_message_t *msg, dns_section_t section,
2532 REQUIRE(DNS_MESSAGE_VALID(msg));
2535 REQUIRE(msg->cursors[section] != NULL);
2537 *name = msg->cursors[section];
2541 dns_message_findname(dns_message_t *msg, dns_section_t section,
2554 REQUIRE(msg != NULL);
2565 result = findname(&foundname, target, &msg->sections[section]);
2593 dns_message_addname(dns_message_t *msg, dns_name_t *name,
2595 REQUIRE(msg != NULL);
2596 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2600 ISC_LIST_APPEND(msg->sections[section], name, link);
2604 dns_message_removename(dns_message_t *msg, dns_name_t *name,
2606 REQUIRE(msg != NULL);
2607 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2611 ISC_LIST_UNLINK(msg->sections[section], name, link);
2615 dns_message_gettempname(dns_message_t *msg, dns_name_t **item) {
2618 REQUIRE(DNS_MESSAGE_VALID(msg));
2621 fn = isc_mempool_get(msg->namepool);
2626 dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item) {
2627 REQUIRE(DNS_MESSAGE_VALID(msg));
2630 *item = newrdata(msg);
2634 dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
2635 REQUIRE(DNS_MESSAGE_VALID(msg));
2638 *item = isc_mempool_get(msg->rdspool);
2643 dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2644 REQUIRE(DNS_MESSAGE_VALID(msg));
2647 *item = newrdatalist(msg);
2651 dns_message_puttempname(dns_message_t *msg, dns_name_t **itemp) {
2654 REQUIRE(DNS_MESSAGE_VALID(msg));
2671 dns_name_free(item, msg->mctx);
2679 isc_mempool_put(msg->namepool, item);
2683 dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item) {
2684 REQUIRE(DNS_MESSAGE_VALID(msg));
2687 releaserdata(msg, *item);
2692 dns__message_putassociatedrdataset(dns_message_t *msg, dns_rdataset_t **item) {
2694 dns_message_puttemprdataset(msg, item);
2698 dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
2699 REQUIRE(DNS_MESSAGE_VALID(msg));
2703 isc_mempool_put(msg->rdspool, *item);
2708 dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2709 REQUIRE(DNS_MESSAGE_VALID(msg));
2712 releaserdatalist(msg, *item);
2744 dns_message_reply(dns_message_t *msg, bool want_question_section) {
2748 REQUIRE(DNS_MESSAGE_VALID(msg));
2749 REQUIRE((msg->flags & DNS_MESSAGEFLAG_QR) == 0);
2751 if (!msg->header_ok) {
2754 if (msg->opcode != dns_opcode_query && msg->opcode != dns_opcode_notify)
2758 if (msg->opcode == dns_opcode_update) {
2761 if (!msg->question_ok) {
2768 msg->from_to_wire = DNS_MESSAGE_INTENTRENDER;
2769 msgresetnames(msg, clear_from);
2770 msgresetopt(msg);
2771 msgresetsigs(msg, true);
2772 msginitprivate(msg);
2777 if (msg->opcode == dns_opcode_query) {
2778 msg->flags &= DNS_MESSAGE_REPLYPRESERVE;
2780 msg->flags = 0;
2782 msg->flags |= DNS_MESSAGEFLAG_QR;
2788 if (msg->tsigkey != NULL) {
2790 msg->querytsigstatus = msg->tsigstatus;
2791 msg->tsigstatus = dns_rcode_noerror;
2792 if (msg->querytsigstatus == dns_tsigerror_badtime) {
2795 msg->sig_reserved = spacefortsig(msg->tsigkey, otherlen);
2796 result = dns_message_renderreserve(msg, msg->sig_reserved);
2798 msg->sig_reserved = 0;
2802 if (msg->saved.base != NULL) {
2803 msg->query.base = msg->saved.base;
2804 msg->query.length = msg->saved.length;
2805 msg->free_query = msg->free_saved;
2806 msg->saved.base = NULL;
2807 msg->saved.length = 0;
2808 msg->free_saved = 0;
2815 dns_message_getopt(dns_message_t *msg) {
2817 * Get the OPT record for 'msg'.
2820 REQUIRE(DNS_MESSAGE_VALID(msg));
2822 return msg->opt;
2826 dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt) {
2831 * Set the OPT record for 'msg'.
2848 REQUIRE(DNS_MESSAGE_VALID(msg));
2851 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2852 REQUIRE(msg->state == DNS_SECTION_ANY);
2854 msgresetopt(msg);
2865 msg->opt_reserved = 11 + rdata.length;
2866 result = dns_message_renderreserve(msg, msg->opt_reserved);
2868 msg->opt_reserved = 0;
2872 msg->opt = opt;
2877 dns__message_putassociatedrdataset(msg, &opt);
2882 dns_message_gettsig(dns_message_t *msg, const dns_name_t **owner) {
2884 * Get the TSIG record and owner for 'msg'.
2887 REQUIRE(DNS_MESSAGE_VALID(msg));
2890 SET_IF_NOT_NULL(owner, msg->tsigname);
2891 return msg->tsig;
2895 dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key) {
2899 * Set the TSIG key for 'msg'
2902 REQUIRE(DNS_MESSAGE_VALID(msg));
2904 if (key == NULL && msg->tsigkey != NULL) {
2905 if (msg->sig_reserved != 0) {
2906 dns_message_renderrelease(msg, msg->sig_reserved);
2907 msg->sig_reserved = 0;
2909 dns_tsigkey_detach(&msg->tsigkey);
2912 REQUIRE(msg->tsigkey == NULL && msg->sig0key == NULL);
2913 dns_tsigkey_attach(key, &msg->tsigkey);
2914 if (msg->from_to_wire == DNS_MESSAGE_INTENTRENDER) {
2915 msg->sig_reserved = spacefortsig(msg->tsigkey, 0);
2916 result = dns_message_renderreserve(msg,
2917 msg->sig_reserved);
2919 dns_tsigkey_detach(&msg->tsigkey);
2920 msg->sig_reserved = 0;
2929 dns_message_gettsigkey(dns_message_t *msg) {
2931 * Get the TSIG key for 'msg'
2934 REQUIRE(DNS_MESSAGE_VALID(msg));
2936 return msg->tsigkey;
2940 dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) {
2947 REQUIRE(DNS_MESSAGE_VALID(msg));
2948 REQUIRE(msg->querytsig == NULL);
2954 dns_message_gettemprdata(msg, &rdata);
2956 dns_message_gettemprdatalist(msg, &list);
2957 dns_message_gettemprdataset(msg, &set);
2960 isc_buffer_allocate(msg->mctx, &buf, r.length);
2965 dns_message_takebuffer(msg, &buf);
2969 msg->querytsig = set;
2973 dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx,
2979 REQUIRE(DNS_MESSAGE_VALID(msg));
2983 if (msg->tsig == NULL) {
2987 result = dns_rdataset_first(msg->tsig);
2991 dns_rdataset_current(msg->tsig, &rdata);
3000 dns_message_getsig0(dns_message_t *msg, const dns_name_t **owner) {
3002 * Get the SIG(0) record for 'msg'.
3005 REQUIRE(DNS_MESSAGE_VALID(msg));
3008 if (msg->sig0 != NULL && owner != NULL) {
3013 if (msg->sig0name == NULL) {
3016 *owner = msg->sig0name;
3019 return msg->sig0;
3023 dns_message_setsig0key(dns_message_t *msg, dst_key_t *key) {
3029 * Set the SIG(0) key for 'msg'
3051 REQUIRE(DNS_MESSAGE_VALID(msg));
3052 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
3053 REQUIRE(msg->state == DNS_SECTION_ANY);
3056 REQUIRE(msg->sig0key == NULL && msg->tsigkey == NULL);
3060 msg->sig_reserved = 0;
3063 msg->sig_reserved = 27 + r.length + x;
3064 result = dns_message_renderreserve(msg, msg->sig_reserved);
3066 msg->sig_reserved = 0;
3069 msg->sig0key = key;
3075 dns_message_getsig0key(dns_message_t *msg) {
3077 * Get the SIG(0) key for 'msg'
3080 REQUIRE(DNS_MESSAGE_VALID(msg));
3082 return msg->sig0key;
3086 dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer) {
3087 REQUIRE(DNS_MESSAGE_VALID(msg));
3091 ISC_LIST_APPEND(msg->cleanup, *buffer, link);
3096 dns_message_signer(dns_message_t *msg, dns_name_t *signer) {
3100 REQUIRE(DNS_MESSAGE_VALID(msg));
3102 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
3104 if (msg->tsig == NULL && msg->sig0 == NULL) {
3108 if (msg->verify_attempted == 0) {
3114 isc_buffer_allocate(msg->mctx, &dynbuf, 512);
3116 dns_message_takebuffer(msg, &dynbuf);
3119 if (msg->sig0 != NULL) {
3122 result = dns_rdataset_first(msg->sig0);
3124 dns_rdataset_current(msg->sig0, &rdata);
3131 if (msg->verified_sig && msg->sig0status == dns_rcode_noerror) {
3142 result = dns_rdataset_first(msg->tsig);
3144 dns_rdataset_current(msg->tsig, &rdata);
3148 if (msg->verified_sig && msg->tsigstatus == dns_rcode_noerror &&
3152 } else if ((!msg->verified_sig) ||
3153 (msg->tsigstatus != dns_rcode_noerror))
3162 if (msg->tsigkey == NULL) {
3164 * If msg->tsigstatus & tsig.error are both
3166 * verified, which means msg->tsigkey will be
3171 identity = dns_tsigkey_identity(msg->tsigkey);
3176 identity = msg->tsigkey->name;
3186 dns_message_resetsig(dns_message_t *msg) {
3187 REQUIRE(DNS_MESSAGE_VALID(msg));
3188 msg->verified_sig = 0;
3189 msg->verify_attempted = 0;
3190 msg->tsigstatus = dns_rcode_noerror;
3191 msg->sig0status = dns_rcode_noerror;
3192 msg->timeadjust = 0;
3193 if (msg->tsigkey != NULL) {
3194 dns_tsigkey_detach(&msg->tsigkey);
3195 msg->tsigkey = NULL;
3201 dns_message_dumpsig(dns_message_t *msg, char *txt1) {
3206 if (msg->tsig != NULL) {
3207 result = dns_rdataset_first(msg->tsig);
3209 dns_rdataset_current(msg->tsig, &querytsigrdata);
3215 if (msg->querytsig != NULL) {
3216 result = dns_rdataset_first(msg->querytsig);
3218 dns_rdataset_current(msg->querytsig, &querytsigrdata);
3234 chsigctx->result = dns_message_checksig(chsigctx->msg, chsigctx->view);
3242 dns_message_t *msg = chsigctx->msg;
3248 isc_mem_put(msg->mctx, chsigctx, sizeof(*chsigctx));
3249 dns_message_detach(&msg);
3253 dns_message_checksig_async(dns_message_t *msg, dns_view_t *view,
3255 REQUIRE(DNS_MESSAGE_VALID(msg));
3260 checksig_ctx_t *chsigctx = isc_mem_get(msg->mctx, sizeof(*chsigctx));
3267 dns_message_attach(msg, &chsigctx->msg);
3270 dns_message_clonebuffer(msg);
3277 dns_message_checksig(dns_message_t *msg, dns_view_t *view) {
3280 REQUIRE(DNS_MESSAGE_VALID(msg));
3282 if (msg->tsigkey == NULL && msg->tsig == NULL && msg->sig0 == NULL) {
3286 INSIST(msg->saved.base != NULL);
3287 isc_buffer_init(&msgb, msg->saved.base, msg->saved.length);
3288 isc_buffer_add(&msgb, msg->saved.length);
3289 if (msg->tsigkey != NULL || msg->tsig != NULL) {
3291 dns_message_dumpsig(msg, "dns_message_checksig#1");
3294 return dns_view_checksig(view, &msgb, msg);
3296 return dns_tsig_verify(&msgb, msg, NULL, NULL);
3310 result = dns_rdataset_first(msg->sig0);
3312 dns_rdataset_current(msg->sig0, &rdata);
3372 result = dns_dnssec_verifymessage(&msgb, msg, key);
3400 for (__i = 0; __i < msg->indent.count; __i++) { \
3401 ADD_STRING(target, msg->indent.string); \
3406 dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
3415 REQUIRE(DNS_MESSAGE_VALID(msg));
3419 saved_count = msg->indent.count;
3421 if (ISC_LIST_EMPTY(msg->sections[section])) {
3429 if (msg->opcode != dns_opcode_update) {
3437 if (msg->opcode != dns_opcode_update) {
3446 result = dns_message_firstname(msg, section);
3451 msg->indent.count++;
3455 dns_message_currentname(msg, section, &name);
3482 name, rds, style, &msg->indent, target);
3488 result = dns_message_nextname(msg, section);
3491 msg->indent.count--;
3505 msg->indent.count = saved_count;
3613 dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section,
3629 REQUIRE(DNS_MESSAGE_VALID(msg));
3633 saved_count = msg->indent.count;
3637 ps = dns_message_getopt(msg);
3644 msg->indent.count++;
3648 indent = ++msg->indent.count;
3695 msg->indent.count = indent;
3827 msg->indent.count++;
3910 if (msg->cc_ok && optlen >= 16) {
3917 if (msg->cc_ok && optlen < 16) {
3924 if (msg->cc_bad) {
3968 msg->indent.count = indent;
3972 ps = dns_message_gettsig(msg, &name);
3980 &msg->indent, target);
3984 ps = dns_message_getsig0(msg, &name);
3992 &msg->indent, target);
4004 msg->indent.count = saved_count;
4009 dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section,
4023 REQUIRE(DNS_MESSAGE_VALID(msg));
4028 return dns_message_pseudosectiontoyaml(msg, section, style,
4034 ps = dns_message_getopt(msg);
4296 if (msg->cc_ok && optlen >= 16) {
4303 if (msg->cc_ok && optlen < 16) {
4310 if (msg->cc_bad) {
4355 ps = dns_message_gettsig(msg, &name);
4364 &msg->indent, target);
4372 ps = dns_message_getsig0(msg, &name);
4381 &msg->indent, target);
4395 dns_message_headertotext(dns_message_t *msg, const dns_master_style_t *style,
4400 REQUIRE(DNS_MESSAGE_VALID(msg));
4410 ADD_STRING(target, opcodetext[msg->opcode]);
4414 result = dns_rcode_totext(msg->rcode, target);
4421 snprintf(buf, sizeof(buf), "%u", msg->id);
4426 if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
4429 if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
4432 if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
4435 if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
4438 if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
4441 if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
4444 if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
4451 if ((msg->flags & 0x0040U) != 0) {
4456 if (msg->opcode != dns_opcode_update) {
4464 msg->counts[DNS_SECTION_QUESTION]);
4467 if (msg->opcode != dns_opcode_update) {
4475 msg->counts[DNS_SECTION_ANSWER]);
4478 if (msg->opcode != dns_opcode_update) {
4486 msg->counts[DNS_SECTION_AUTHORITY]);
4492 msg->counts[DNS_SECTION_ADDITIONAL]);
4498 ADD_STRING(target, opcodetext[msg->opcode]);
4500 result = dns_rcode_totext(msg->rcode, target);
4505 snprintf(buf, sizeof(buf), "%6u", msg->id);
4510 if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
4513 if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
4516 if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
4519 if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
4522 if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
4525 if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
4528 if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
4534 if ((msg->flags & 0x0040U) != 0) {
4538 if (msg->opcode != dns_opcode_update) {
4546 msg->counts[DNS_SECTION_QUESTION]);
4548 if (msg->opcode != dns_opcode_update) {
4554 msg->counts[DNS_SECTION_ANSWER]);
4556 if (msg->opcode != dns_opcode_update) {
4562 msg->counts[DNS_SECTION_AUTHORITY]);
4566 msg->counts[DNS_SECTION_ADDITIONAL]);
4576 dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
4580 REQUIRE(DNS_MESSAGE_VALID(msg));
4583 result = dns_message_headertotext(msg, style, flags, target);
4588 result = dns_message_pseudosectiontotext(msg, DNS_PSEUDOSECTION_OPT,
4594 result = dns_message_sectiontotext(msg, DNS_SECTION_QUESTION, style,
4600 result = dns_message_sectiontotext(msg, DNS_SECTION_ANSWER, style,
4606 result = dns_message_sectiontotext(msg, DNS_SECTION_AUTHORITY, style,
4612 result = dns_message_sectiontotext(msg, DNS_SECTION_ADDITIONAL, style,
4618 result = dns_message_pseudosectiontotext(msg, DNS_PSEUDOSECTION_TSIG,
4624 result = dns_message_pseudosectiontotext(msg, DNS_PSEUDOSECTION_SIG0,
4630 dns_message_getrawmessage(dns_message_t *msg) {
4631 REQUIRE(DNS_MESSAGE_VALID(msg));
4632 return &msg->saved;
4636 dns_message_setsortorder(dns_message_t *msg, dns_rdatasetorderfunc_t order,
4639 REQUIRE(DNS_MESSAGE_VALID(msg));
4643 msg->order = order;
4645 dns_aclenv_attach(env, &msg->order_arg.env);
4648 dns_acl_attach(acl, &msg->order_arg.acl);
4650 msg->order_arg.element = elem;
4654 dns_message_settimeadjust(dns_message_t *msg, int timeadjust) {
4655 REQUIRE(DNS_MESSAGE_VALID(msg));
4656 msg->timeadjust = timeadjust;
4660 dns_message_gettimeadjust(dns_message_t *msg) {
4661 REQUIRE(DNS_MESSAGE_VALID(msg));
4662 return msg->timeadjust;
4843 dns_message_setclass(dns_message_t *msg, dns_rdataclass_t rdclass) {
4844 REQUIRE(DNS_MESSAGE_VALID(msg));
4845 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
4846 REQUIRE(msg->state == DNS_SECTION_ANY);
4847 REQUIRE(msg->rdclass_set == 0);
4849 msg->rdclass = rdclass;
4850 msg->rdclass_set = 1;
4854 dns_message_setpadding(dns_message_t *msg, uint16_t padding) {
4855 REQUIRE(DNS_MESSAGE_VALID(msg));
4861 msg->padding = padding;
4865 dns_message_clonebuffer(dns_message_t *msg) {
4866 REQUIRE(DNS_MESSAGE_VALID(msg));
4868 if (msg->free_saved == 0 && msg->saved.base != NULL) {
4869 msg->saved.base =
4870 memmove(isc_mem_get(msg->mctx, msg->saved.length),
4871 msg->saved.base, msg->saved.length);
4872 msg->free_saved = 1;
4874 if (msg->free_query == 0 && msg->query.base != NULL) {
4875 msg->query.base =
4876 memmove(isc_mem_get(msg->mctx, msg->query.length),
4877 msg->query.base, msg->query.length);
4878 msg->free_query = 1;
4931 message_authority_soa_min(dns_message_t *msg, dns_ttl_t *ttlp) {
4934 if (msg->counts[DNS_SECTION_AUTHORITY] == 0) {
4938 for (result = dns_message_firstname(msg, DNS_SECTION_AUTHORITY);
4940 result = dns_message_nextname(msg, DNS_SECTION_AUTHORITY))
4943 dns_message_currentname(msg, DNS_SECTION_AUTHORITY, &name);
4963 dns_message_minttl(dns_message_t *msg, const dns_section_t sectionid,
4965 REQUIRE(DNS_MESSAGE_VALID(msg));
4968 if (!msg->minttl[sectionid].is_set) {
4972 *pttl = msg->minttl[sectionid].ttl;
4977 dns_message_response_minttl(dns_message_t *msg, dns_ttl_t *pttl) {
4980 REQUIRE(DNS_MESSAGE_VALID(msg));
4983 result = dns_message_minttl(msg, DNS_SECTION_ANSWER, pttl);
4985 return message_authority_soa_min(msg, pttl);