Lines Matching defs:msg

169 newbuffer(dns_message_t *msg, unsigned int size) {
178 ISC_LIST_APPEND(msg->scratchpad, dynbuf, link);
183 currentbuffer(dns_message_t *msg) {
186 dynbuf = ISC_LIST_TAIL(msg->scratchpad);
193 releaserdata(dns_message_t *msg, dns_rdata_t *rdata) {
194 ISC_LIST_PREPEND(msg->freerdata, rdata, link);
198 newrdata(dns_message_t *msg) {
202 rdata = ISC_LIST_HEAD(msg->freerdata);
204 ISC_LIST_UNLINK(msg->freerdata, rdata, link);
208 msgblock = ISC_LIST_TAIL(msg->rdatas);
215 ISC_LIST_APPEND(msg->rdatas, msgblock, link);
225 releaserdatalist(dns_message_t *msg, dns_rdatalist_t *rdatalist) {
226 ISC_LIST_PREPEND(msg->freerdatalist, rdatalist, link);
230 newrdatalist(dns_message_t *msg) {
234 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
236 ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
240 msgblock = ISC_LIST_TAIL(msg->rdatalists);
248 ISC_LIST_APPEND(msg->rdatalists, msgblock, link);
260 newoffsets(dns_message_t *msg) {
264 msgblock = ISC_LIST_TAIL(msg->offsets);
272 ISC_LIST_APPEND(msg->offsets, msgblock, link);
348 msgresetnames(dns_message_t *msg, unsigned int first_section) {
357 name = ISC_LIST_HEAD(msg->sections[i]);
360 ISC_LIST_UNLINK(msg->sections[i], name, link);
381 msgresetopt(dns_message_t *msg)
383 if (msg->opt != NULL) {
384 if (msg->opt_reserved > 0) {
385 dns_message_renderrelease(msg, msg->opt_reserved);
386 msg->opt_reserved = 0;
388 INSIST(dns_rdataset_isassociated(msg->opt));
389 dns_rdataset_disassociate(msg->opt);
390 free(msg->opt);
391 msg->opt = NULL;
392 msg->sitok = 0;
393 msg->sitbad = 0;
398 msgresetsigs(dns_message_t *msg, int replying) {
399 if (msg->sig_reserved > 0) {
400 dns_message_renderrelease(msg, msg->sig_reserved);
401 msg->sig_reserved = 0;
403 if (msg->tsig != NULL) {
404 INSIST(dns_rdataset_isassociated(msg->tsig));
406 INSIST(msg->querytsig == NULL);
407 msg->querytsig = msg->tsig;
409 dns_rdataset_disassociate(msg->tsig);
410 free(msg->tsig);
411 if (msg->querytsig != NULL) {
412 dns_rdataset_disassociate(msg->querytsig);
413 free(msg->querytsig);
416 if (dns_name_dynamic(msg->tsigname))
417 dns_name_free(msg->tsigname);
418 free(msg->tsigname);
419 msg->tsig = NULL;
420 msg->tsigname = NULL;
421 } else if (msg->querytsig != NULL && !replying) {
422 dns_rdataset_disassociate(msg->querytsig);
423 free(msg->querytsig);
424 msg->querytsig = NULL;
426 if (msg->sig0 != NULL) {
427 INSIST(dns_rdataset_isassociated(msg->sig0));
428 dns_rdataset_disassociate(msg->sig0);
429 free(msg->sig0);
430 if (msg->sig0name != NULL) {
431 if (dns_name_dynamic(msg->sig0name))
432 dns_name_free(msg->sig0name);
433 free(msg->sig0name);
435 msg->sig0 = NULL;
436 msg->sig0name = NULL;
445 msgreset(dns_message_t *msg, int everything) {
451 msgresetnames(msg, 0);
452 msgresetopt(msg);
453 msgresetsigs(msg, 0);
464 rdata = ISC_LIST_HEAD(msg->freerdata);
466 ISC_LIST_UNLINK(msg->freerdata, rdata, link);
467 rdata = ISC_LIST_HEAD(msg->freerdata);
469 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
471 ISC_LIST_UNLINK(msg->freerdatalist, rdatalist, link);
472 rdatalist = ISC_LIST_HEAD(msg->freerdatalist);
475 dynbuf = ISC_LIST_HEAD(msg->scratchpad);
483 ISC_LIST_UNLINK(msg->scratchpad, dynbuf, link);
488 msgblock = ISC_LIST_HEAD(msg->rdatas);
495 ISC_LIST_UNLINK(msg->rdatas, msgblock, link);
504 msgblock = ISC_LIST_HEAD(msg->rdatalists);
511 ISC_LIST_UNLINK(msg->rdatalists, msgblock, link);
516 msgblock = ISC_LIST_HEAD(msg->offsets);
523 ISC_LIST_UNLINK(msg->offsets, msgblock, link);
528 if (msg->tsigkey != NULL) {
529 dns_tsigkey_detach(&msg->tsigkey);
530 msg->tsigkey = NULL;
533 if (msg->tsigctx != NULL)
534 dst_context_destroy(&msg->tsigctx);
536 if (msg->query.base != NULL) {
537 if (msg->free_query != 0)
538 free(msg->query.base);
539 msg->query.base = NULL;
540 msg->query.length = 0;
543 if (msg->saved.base != NULL) {
544 if (msg->free_saved != 0)
545 free(msg->saved.base);
546 msg->saved.base = NULL;
547 msg->saved.length = 0;
553 dynbuf = ISC_LIST_HEAD(msg->cleanup);
556 ISC_LIST_UNLINK(msg->cleanup, dynbuf, link);
565 msginit(msg);
674 dns_message_t *msg;
678 msg = *msgp;
681 msgreset(msg, 1);
682 free(msg);
754 getname(dns_name_t *name, isc_buffer_t *source, dns_message_t *msg,
761 scratch = currentbuffer(msg);
775 result = newbuffer(msg, SCRATCHPAD_SIZE);
779 scratch = currentbuffer(msg);
791 getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
800 scratch = currentbuffer(msg);
832 result = newbuffer(msg, trysize);
836 scratch = currentbuffer(msg);
854 getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
872 section = &msg->sections[DNS_SECTION_QUESTION];
881 for (count = 0; count < msg->counts[DNS_SECTION_QUESTION]; count++) {
887 offsets = newoffsets(msg);
899 result = getname(name, source, msg, dctx);
948 if (msg->rdclass_set == 0) {
949 msg->rdclass = rdclass;
950 msg->rdclass_set = 1;
951 } else if (msg->rdclass != rdclass)
958 msg->tkey = 1;
970 rdatalist = newrdatalist(msg);
1028 getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx,
1050 section = &msg->sections[sectionid];
1052 for (count = 0; count < msg->counts[sectionid]; count++) {
1061 offsets = newoffsets(msg);
1073 result = getname(name, source, msg, dctx);
1094 if (msg->rdclass_set == 0 &&
1098 msg->rdclass = rdclass;
1099 msg->rdclass_set = 1;
1106 if (msg->opcode != dns_opcode_update
1112 && msg->rdclass != dns_rdataclass_any
1113 && msg->rdclass != rdclass)
1120 if (msg->opcode != dns_opcode_update && !msg->tkey &&
1122 msg->rdclass != dns_rdataclass_any &&
1123 msg->rdclass != rdclass)
1136 count != msg->counts[sectionid] - 1)
1138 msg->sigstart = recstart;
1147 msg->opt != NULL)
1159 if ((msg->flags & DNS_MESSAGEFLAG_QR) == 0)
1185 rdata = newrdata(msg);
1190 if (msg->opcode == dns_opcode_update &&
1210 msg->opcode == dns_opcode_update &&
1212 result = getrdata(source, msg, dctx, msg->rdclass,
1215 result = getrdata(source, msg, dctx, rdclass,
1231 count != msg->counts[sectionid] - 1)
1233 msg->sigstart = recstart;
1236 if (msg->rdclass != dns_rdataclass_any &&
1237 msg->rdclass != rdclass)
1247 !dns_rdata_checkowner_nsec3(name, msg->rdclass, rdtype,
1266 rdatalist = newrdatalist(msg);
1310 * Note msg->opt, msg->sig0 and msg->tsig will only be
1314 if (rdtype == dns_rdatatype_opt && msg->opt == NULL) {
1317 msg->opt = rdataset;
1321 ((msg->opt->ttl & DNS_MESSAGE_EDNSRCODE_MASK)
1323 msg->rcode |= ercode;
1326 } else if (issigzero && msg->sig0 == NULL) {
1327 msg->sig0 = rdataset;
1328 msg->sig0name = name;
1332 } else if (rdtype == dns_rdatatype_tsig && msg->tsig == NULL) {
1333 msg->tsig = rdataset;
1334 msg->tsigname = name;
1336 msg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
1367 dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
1379 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE);
1386 msg->header_ok = 0;
1387 msg->question_ok = 0;
1393 msg->id = isc_buffer_getuint16(source);
1395 msg->opcode = ((tmpflags & DNS_MESSAGE_OPCODE_MASK)
1397 msg->rcode = (dns_rcode_t)(tmpflags & DNS_MESSAGE_RCODE_MASK);
1398 msg->flags = (tmpflags & DNS_MESSAGE_FLAG_MASK);
1399 msg->counts[DNS_SECTION_QUESTION] = isc_buffer_getuint16(source);
1400 msg->counts[DNS_SECTION_ANSWER] = isc_buffer_getuint16(source);
1401 msg->counts[DNS_SECTION_AUTHORITY] = isc_buffer_getuint16(source);
1402 msg->counts[DNS_SECTION_ADDITIONAL] = isc_buffer_getuint16(source);
1404 msg->header_ok = 1;
1405 msg->state = DNS_SECTION_QUESTION;
1414 ret = getquestions(source, msg, &dctx, options);
1423 msg->question_ok = 1;
1425 ret = getsection(source, msg, &dctx, DNS_SECTION_ANSWER, options);
1435 ret = getsection(source, msg, &dctx, DNS_SECTION_AUTHORITY, options);
1445 ret = getsection(source, msg, &dctx, DNS_SECTION_ADDITIONAL, options);
1464 isc_buffer_usedregion(&origsource, &msg->saved);
1474 dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx,
1480 REQUIRE(msg->buffer == NULL);
1481 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
1483 msg->cctx = cctx;
1498 if (r.length - DNS_MESSAGE_HEADERLEN < msg->reserved)
1506 msg->buffer = buffer;
1512 dns_message_renderrelease(dns_message_t *msg, unsigned int space) {
1513 REQUIRE(space <= msg->reserved);
1515 msg->reserved -= space;
1519 dns_message_renderreserve(dns_message_t *msg, unsigned int space) {
1522 if (msg->buffer != NULL) {
1523 isc_buffer_availableregion(msg->buffer, &r);
1524 if (r.length < (space + msg->reserved))
1528 msg->reserved += space;
1584 maybe_clear_ad(dns_message_t *msg, dns_section_t sectionid) {
1585 if (msg->counts[sectionid] == 0 &&
1588 msg->counts[DNS_SECTION_ANSWER] == 0)))
1589 msg->flags &= ~DNS_MESSAGEFLAG_AD;
1593 dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid)
1603 REQUIRE(msg->buffer != NULL);
1606 section = &msg->sections[sectionid];
1616 if (msg->buffer->length - msg->buffer->used < msg->reserved)
1618 msg->buffer->length -= msg->reserved;
1625 msg->buffer->length += msg->reserved;
1626 msg->counts[sectionid] += total;
1645 st = *(msg->buffer);
1651 msg->cctx,
1652 msg->buffer,
1664 dns_compress_rollback(msg->cctx,
1666 *(msg->buffer) = st; /* rollback */
1667 msg->buffer->length += msg->reserved;
1668 msg->counts[sectionid] += total;
1669 maybe_clear_ad(msg, sectionid);
1679 msg->flags &= ~DNS_MESSAGEFLAG_AD;
1692 msg->buffer->length += msg->reserved;
1693 msg->counts[sectionid] += total;
1699 dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target) {
1708 isc_buffer_putuint16(target, msg->id);
1710 tmp = ((msg->opcode << DNS_MESSAGE_OPCODE_SHIFT)
1712 tmp |= (msg->rcode & DNS_MESSAGE_RCODE_MASK);
1713 tmp |= (msg->flags & DNS_MESSAGE_FLAG_MASK);
1715 INSIST(msg->counts[DNS_SECTION_QUESTION] < 65536 &&
1716 msg->counts[DNS_SECTION_ANSWER] < 65536 &&
1717 msg->counts[DNS_SECTION_AUTHORITY] < 65536 &&
1718 msg->counts[DNS_SECTION_ADDITIONAL] < 65536);
1722 (uint16_t)msg->counts[DNS_SECTION_QUESTION]);
1724 (uint16_t)msg->counts[DNS_SECTION_ANSWER]);
1726 (uint16_t)msg->counts[DNS_SECTION_AUTHORITY]);
1728 (uint16_t)msg->counts[DNS_SECTION_ADDITIONAL]);
1732 dns_message_renderend(dns_message_t *msg) {
1738 REQUIRE(msg->buffer != NULL);
1740 if ((msg->rcode & ~DNS_MESSAGE_RCODE_MASK) != 0 && msg->opt == NULL) {
1753 if ((msg->tsigkey != NULL || msg->opt) &&
1754 (msg->flags & DNS_MESSAGEFLAG_TC) != 0)
1758 msgresetnames(msg, DNS_SECTION_ANSWER);
1759 buf = msg->buffer;
1760 dns_message_renderreset(msg);
1761 msg->buffer = buf;
1762 isc_buffer_clear(msg->buffer);
1763 isc_buffer_add(msg->buffer, DNS_MESSAGE_HEADERLEN);
1764 dns_compress_rollback(msg->cctx, 0);
1765 result = dns_message_rendersection(msg, DNS_SECTION_QUESTION);
1773 if (msg->opt != NULL) {
1774 dns_message_renderrelease(msg, msg->opt_reserved);
1775 msg->opt_reserved = 0;
1779 msg->opt->ttl &= ~DNS_MESSAGE_EDNSRCODE_MASK;
1780 msg->opt->ttl |= ((msg->rcode << 20) &
1786 result = renderset(msg->opt, dns_rootname, msg->cctx,
1787 msg->buffer, msg->reserved, &count);
1788 msg->counts[DNS_SECTION_ADDITIONAL] += count;
1796 if (msg->tsigkey != NULL) {
1797 dns_message_renderrelease(msg, msg->sig_reserved);
1798 msg->sig_reserved = 0;
1799 result = dns_tsig_sign(msg);
1803 result = renderset(msg->tsig, msg->tsigname, msg->cctx,
1804 msg->buffer, msg->reserved, &count);
1805 msg->counts[DNS_SECTION_ADDITIONAL] += count;
1810 isc_buffer_usedregion(msg->buffer, &r);
1813 dns_message_renderheader(msg, &tmpbuf);
1815 msg->buffer = NULL; /* forget about this buffer only on success XXX */
1821 dns_message_renderreset(dns_message_t *msg) {
1830 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
1832 msg->buffer = NULL;
1835 msg->cursors[i] = NULL;
1836 msg->counts[i] = 0;
1837 for (name = ISC_LIST_HEAD(msg->sections[i]);
1847 if (msg->tsigname != NULL)
1848 dns_message_puttempname(msg, &msg->tsigname);
1849 if (msg->tsig != NULL) {
1850 dns_rdataset_disassociate(msg->tsig);
1851 dns_message_puttemprdataset(msg, &msg->tsig);
1853 if (msg->sig0 != NULL) {
1854 dns_rdataset_disassociate(msg->sig0);
1855 dns_message_puttemprdataset(msg, &msg->sig0);
1860 dns_message_firstname(dns_message_t *msg, dns_section_t section) {
1863 msg->cursors[section] = ISC_LIST_HEAD(msg->sections[section]);
1865 if (msg->cursors[section] == NULL)
1872 dns_message_nextname(dns_message_t *msg, dns_section_t section) {
1874 REQUIRE(msg->cursors[section] != NULL);
1876 msg->cursors[section] = ISC_LIST_NEXT(msg->cursors[section], link);
1878 if (msg->cursors[section] == NULL)
1885 dns_message_currentname(dns_message_t *msg, dns_section_t section,
1890 REQUIRE(msg->cursors[section] != NULL);
1892 *name = msg->cursors[section];
1896 dns_message_findname(dns_message_t *msg, dns_section_t section,
1910 REQUIRE(msg != NULL);
1922 &msg->sections[section]);
1946 dns_message_addname(dns_message_t *msg, dns_name_t *name,
1949 REQUIRE(msg != NULL);
1950 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
1954 ISC_LIST_APPEND(msg->sections[section], name, link);
1958 dns_message_gettempname(dns_message_t *msg, dns_name_t **item) {
1961 UNUSED(msg);
1972 dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item) {
1975 *item = newrdata(msg);
1983 dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
1986 UNUSED(msg);
1998 dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2001 *item = newrdatalist(msg);
2009 dns_message_puttempname(dns_message_t *msg, dns_name_t **item) {
2012 UNUSED(msg);
2021 dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item) {
2024 releaserdata(msg, *item);
2029 dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item) {
2033 UNUSED(msg);
2040 dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) {
2043 releaserdatalist(msg, *item);
2077 dns_message_getopt(dns_message_t *msg) {
2080 * Get the OPT record for 'msg'.
2082 return (msg->opt);
2086 dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt) {
2091 * Set the OPT record for 'msg'.
2109 REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER);
2110 REQUIRE(msg->state == DNS_SECTION_ANY);
2112 msgresetopt(msg);
2118 msg->opt_reserved = 11 + rdata.length;
2119 result = dns_message_renderreserve(msg, msg->opt_reserved);
2121 msg->opt_reserved = 0;
2125 msg->opt = opt;
2131 dns_message_puttemprdataset(msg, &opt);
2136 dns_message_gettsig(dns_message_t *msg, dns_name_t **owner) {
2139 * Get the TSIG record and owner for 'msg'.
2145 *owner = msg->tsigname;
2146 return (msg->tsig);
2150 dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key) {
2154 * Set the TSIG key for 'msg'
2157 REQUIRE(msg->state == DNS_SECTION_ANY);
2159 if (key == NULL && msg->tsigkey != NULL) {
2160 if (msg->sig_reserved != 0) {
2161 dns_message_renderrelease(msg, msg->sig_reserved);
2162 msg->sig_reserved = 0;
2164 dns_tsigkey_detach(&msg->tsigkey);
2167 REQUIRE(msg->tsigkey == NULL);
2168 dns_tsigkey_attach(key, &msg->tsigkey);
2169 if (msg->from_to_wire == DNS_MESSAGE_INTENTRENDER) {
2170 msg->sig_reserved = spacefortsig(msg->tsigkey, 0);
2171 result = dns_message_renderreserve(msg,
2172 msg->sig_reserved);
2174 dns_tsigkey_detach(&msg->tsigkey);
2175 msg->sig_reserved = 0;
2184 dns_message_gettsigkey(dns_message_t *msg) {
2187 * Get the TSIG key for 'msg'
2189 return (msg->tsigkey);
2193 dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) {
2201 REQUIRE(msg->querytsig == NULL);
2206 result = dns_message_gettemprdata(msg, &rdata);
2210 result = dns_message_gettemprdatalist(msg, &list);
2213 result = dns_message_gettemprdataset(msg, &set);
2225 dns_message_takebuffer(msg, &buf);
2231 msg->querytsig = set;
2237 dns_message_puttemprdata(msg, &rdata);
2239 dns_message_puttemprdatalist(msg, &list);
2241 dns_message_puttemprdataset(msg, &set);
2246 dns_message_getquerytsig(dns_message_t *msg, isc_buffer_t **querytsig) {
2253 if (msg->tsig == NULL)
2256 result = dns_rdataset_first(msg->tsig);
2259 dns_rdataset_current(msg->tsig, &rdata);
2270 dns_message_getsig0(dns_message_t *msg, dns_name_t **owner) {
2273 * Get the SIG(0) record for 'msg'.
2278 if (msg->sig0 != NULL && owner != NULL) {
2283 if (msg->sig0name == NULL)
2286 *owner = msg->sig0name;
2288 return (msg->sig0);
2292 dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer) {
2295 ISC_LIST_APPEND(msg->cleanup, *buffer, link);
2300 dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
2312 if (ISC_LIST_EMPTY(msg->sections[section]))
2317 if (msg->opcode != dns_opcode_update) {
2326 result = dns_message_firstname(msg, section);
2332 dns_message_currentname(msg, section, &name);
2360 result = dns_message_nextname(msg, section);
2518 dns_message_pseudosectiontotext(dns_message_t *msg,
2540 ps = dns_message_getopt(msg);
2724 if (msg->sitok)
2726 if (msg->sitbad)
2758 ps = dns_message_gettsig(msg, &name);
2769 ps = dns_message_getsig0(msg, &name);