Skip to content

Commit 0f6235f

Browse files
committed
fix(mdns): Fix to keep TXT/SRV in answers to queries
unlike discoveries, where they need to stay in additional section Quick fix of regression b7b8c5d
1 parent 6c2c2cd commit 0f6235f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

components/mdns/mdns_send.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,20 @@ static bool create_answer_from_service(mdns_tx_packet_t *packet, mdns_service_t
257257
{
258258
mdns_host_item_t *host = get_host_item(service->hostname);
259259
bool is_delegated = (host != mdns_priv_get_self_host());
260-
if (question->type == MDNS_TYPE_PTR || question->type == MDNS_TYPE_ANY) {
261-
// According to RFC6763-section12.1, for DNS-SD, SRV, TXT and all address records
262-
// should be included in additional records.
260+
bool is_instance_question = !mdns_utils_str_null_or_empty(question->host);
261+
if ((question->type == MDNS_TYPE_ANY) && is_instance_question) {
262+
// Instance-scoped ANY queries expect the resolved data (SRV/TXT) to be
263+
// part of the answer section so that queriers can stop searching as soon
264+
// as they receive this packet (RFC6762 section 6, RFC6763 section 12.1).
265+
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_SRV, service, NULL, send_flush, false) ||
266+
!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_TXT, service, NULL, send_flush, false) ||
267+
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_A, service, host, send_flush, false) ||
268+
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_AAAA, service, host, send_flush, false)) {
269+
return false;
270+
}
271+
} else if (question->type == MDNS_TYPE_PTR || (question->type == MDNS_TYPE_ANY && !is_instance_question)) {
272+
// For service discovery (PTR or wildcard ANY) RFC6763 section 12.1
273+
// requires SRV/TXT/address records to stay in the additional section.
263274
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_PTR, service, NULL, false, false) ||
264275
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_SRV, service, NULL, send_flush, false) ||
265276
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_TXT, service, NULL, send_flush, false) ||

0 commit comments

Comments
 (0)