mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-12-04 16:19:20 +01:00
Merge pull request #959 from david-cermak/fix/mdns_v1.10
[mdns]: v1.10: Fix to keep TXT/SRV in answers to queries
This commit is contained in:
@@ -257,9 +257,20 @@ static bool create_answer_from_service(mdns_tx_packet_t *packet, mdns_service_t
|
||||
{
|
||||
mdns_host_item_t *host = get_host_item(service->hostname);
|
||||
bool is_delegated = (host != mdns_priv_get_self_host());
|
||||
if (question->type == MDNS_TYPE_PTR || question->type == MDNS_TYPE_ANY) {
|
||||
// According to RFC6763-section12.1, for DNS-SD, SRV, TXT and all address records
|
||||
// should be included in additional records.
|
||||
bool is_instance_question = !mdns_utils_str_null_or_empty(question->host);
|
||||
if ((question->type == MDNS_TYPE_ANY) && is_instance_question) {
|
||||
// Instance-scoped ANY queries expect the resolved data (SRV/TXT) to be
|
||||
// part of the answer section so that queriers can stop searching as soon
|
||||
// as they receive this packet (RFC6762 section 6, RFC6763 section 12.1).
|
||||
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_SRV, service, NULL, send_flush, false) ||
|
||||
!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_TXT, service, NULL, send_flush, false) ||
|
||||
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_A, service, host, send_flush, false) ||
|
||||
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_AAAA, service, host, send_flush, false)) {
|
||||
return false;
|
||||
}
|
||||
} else if (question->type == MDNS_TYPE_PTR || (question->type == MDNS_TYPE_ANY && !is_instance_question)) {
|
||||
// For service discovery (PTR or wildcard ANY) RFC6763 section 12.1
|
||||
// requires SRV/TXT/address records to stay in the additional section.
|
||||
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_PTR, service, NULL, false, false) ||
|
||||
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_SRV, service, NULL, send_flush, false) ||
|
||||
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_TXT, service, NULL, send_flush, false) ||
|
||||
|
||||
@@ -76,6 +76,21 @@ def test_ptr_additional_records_for_service(dig_app):
|
||||
dig_app.check_additional(resp, 'TXT', 'test_service._http._tcp.local', expected=True)
|
||||
|
||||
|
||||
def test_instance_any_answer_records(dig_app):
|
||||
"""Query ANY for the service instance and ensure SRV/TXT are in Answer (Q/A path)."""
|
||||
resp = dig_app.run_query('test_service._http._tcp.local', query_type='ANY')
|
||||
|
||||
# Answer section should contain SRV and TXT records for the instance
|
||||
srv_answers = dig_app.parse_section(resp, 'answer', 'SRV')
|
||||
txt_answers = dig_app.parse_section(resp, 'answer', 'TXT')
|
||||
assert any('test_service._http._tcp.local' in a for a in srv_answers)
|
||||
assert any('test_service._http._tcp.local' in a for a in txt_answers)
|
||||
|
||||
# We should not see a PTR for the generic service name in the Answer section
|
||||
ptr_answers = dig_app.parse_section(resp, 'answer', 'PTR')
|
||||
assert not any('_http._tcp.local' in a for a in ptr_answers)
|
||||
|
||||
|
||||
def test_remove_service(mdns_console, dig_app):
|
||||
mdns_console.send_input('mdns_service_remove _http _tcp')
|
||||
mdns_console.send_input('mdns_service_lookup _http _tcp')
|
||||
|
||||
Reference in New Issue
Block a user