diff --git a/components/mdns/Kconfig b/components/mdns/Kconfig index 72800aaa2a..38dec76287 100644 --- a/components/mdns/Kconfig +++ b/components/mdns/Kconfig @@ -56,6 +56,17 @@ menu "mDNS" Configures timeout for adding a new mDNS service. Adding a service fails if could not be completed within this time. + config MDNS_STRICT_MODE + bool "mDNS strict mode" + default "n" + help + Configures strict mode. Set this to 1 for the mDNS library to strictly follow the RFC6762: + Currently the only strict feature: Do not repeat original questions in response packets + (defined in RFC6762 sec. 6). + Default configuration is 0, i.e. non-strict mode, since some implementations, + such as lwIP mdns resolver (used by standard POSIX API like getaddrinfo, gethostbyname) + could not correctly resolve advertised names. + config MDNS_TIMER_PERIOD_MS int "mDNS timer period (ms)" range 10 10000 diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 401d931225..6d47084314 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -2679,7 +2679,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet) } //if we have not set the hostname, we can not answer questions - if (header.questions && _str_null_or_empty(_mdns_server->hostname)) { + if (header.questions && !header.answers && _str_null_or_empty(_mdns_server->hostname)) { free(parsed_packet); return; } @@ -2815,13 +2815,12 @@ void mdns_parse_packet(mdns_rx_packet_t * packet) if (parsed_packet->discovery && _mdns_name_is_discovery(name, type)) { discovery = true; - } else { - if (!name->sub && _mdns_name_is_ours(name)) { - ours = true; - if (name->service && name->service[0] && name->proto && name->proto[0]) { - service = _mdns_get_service_item(name->service, name->proto); - } + } else if (!name->sub && _mdns_name_is_ours(name)) { + ours = true; + if (name->service && name->service[0] && name->proto && name->proto[0]) { + service = _mdns_get_service_item(name->service, name->proto); } + } else { if (!parsed_packet->authoritative || record_type == MDNS_NS) { //skip this record continue; diff --git a/components/mdns/mdns_networking.c b/components/mdns/mdns_networking.c index 152ab2798e..48d11918ba 100644 --- a/components/mdns/mdns_networking.c +++ b/components/mdns/mdns_networking.c @@ -38,7 +38,7 @@ static esp_err_t _udp_pcb_main_init(void) _pcb_main = NULL; return ESP_ERR_INVALID_STATE; } - _pcb_main->mcast_ttl = 1; + _pcb_main->mcast_ttl = 255; _pcb_main->remote_port = MDNS_SERVICE_PORT; ip_addr_copy(_pcb_main->remote_ip, *(IP_ANY_TYPE)); udp_recv(_pcb_main, &_udp_recv, _mdns_server); diff --git a/components/mdns/private_include/mdns_private.h b/components/mdns/private_include/mdns_private.h index 60dfeb4ee5..9ed0dcfbd1 100644 --- a/components/mdns/private_include/mdns_private.h +++ b/components/mdns/private_include/mdns_private.h @@ -32,7 +32,11 @@ * such as lwIP mdns resolver (used by standard POSIX API like getaddrinfo, gethostbyname) * could not correctly resolve advertised names. */ +#ifndef CONFIG_MDNS_STRICT_MODE #define MDNS_STRICT_MODE 0 +#else +#define MDNS_STRICT_MODE 1 +#endif #if !MDNS_STRICT_MODE /* mDNS responders sometimes repeat queries in responses