Merge branch 'bugfix/mdns_configure_strict_mode_v4.2' into 'release/v4.2'

mdns: Fix mdns to correctly answer non-strict queries (+ additional fixes) (v4.2)

See merge request espressif/esp-idf!13122
This commit is contained in:
David Čermák
2021-04-22 11:09:58 +00:00
4 changed files with 22 additions and 8 deletions

View File

@ -56,6 +56,17 @@ menu "mDNS"
Configures timeout for adding a new mDNS service. Adding a service Configures timeout for adding a new mDNS service. Adding a service
fails if could not be completed within this time. 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 config MDNS_TIMER_PERIOD_MS
int "mDNS timer period (ms)" int "mDNS timer period (ms)"
range 10 10000 range 10 10000

View File

@ -2665,7 +2665,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
} }
//if we have not set the hostname, we can not answer questions //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); free(parsed_packet);
return; return;
} }
@ -2796,13 +2796,12 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
if (parsed_packet->discovery && _mdns_name_is_discovery(name, type)) { if (parsed_packet->discovery && _mdns_name_is_discovery(name, type)) {
discovery = true; discovery = true;
} else { } else if (!name->sub && _mdns_name_is_ours(name)) {
if (!name->sub && _mdns_name_is_ours(name)) { ours = true;
ours = true; if (name->service && name->service[0] && name->proto && name->proto[0]) {
if (name->service && name->service[0] && name->proto && name->proto[0]) { service = _mdns_get_service_item(name->service, name->proto);
service = _mdns_get_service_item(name->service, name->proto);
}
} }
} else {
if (!parsed_packet->authoritative || record_type == MDNS_NS) { if (!parsed_packet->authoritative || record_type == MDNS_NS) {
//skip this record //skip this record
continue; continue;

View File

@ -38,7 +38,7 @@ static esp_err_t _udp_pcb_main_init(void)
_pcb_main = NULL; _pcb_main = NULL;
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
_pcb_main->mcast_ttl = 1; _pcb_main->mcast_ttl = 255;
_pcb_main->remote_port = MDNS_SERVICE_PORT; _pcb_main->remote_port = MDNS_SERVICE_PORT;
ip_addr_copy(_pcb_main->remote_ip, ip_addr_any_type); ip_addr_copy(_pcb_main->remote_ip, ip_addr_any_type);
udp_recv(_pcb_main, &_udp_recv, _mdns_server); udp_recv(_pcb_main, &_udp_recv, _mdns_server);

View File

@ -31,7 +31,11 @@
* such as lwIP mdns resolver (used by standard POSIX API like getaddrinfo, gethostbyname) * such as lwIP mdns resolver (used by standard POSIX API like getaddrinfo, gethostbyname)
* could not correctly resolve advertised names. * could not correctly resolve advertised names.
*/ */
#ifndef CONFIG_MDNS_STRICT_MODE
#define MDNS_STRICT_MODE 0 #define MDNS_STRICT_MODE 0
#else
#define MDNS_STRICT_MODE 1
#endif
#if !MDNS_STRICT_MODE #if !MDNS_STRICT_MODE
/* mDNS responders sometimes repeat queries in responses /* mDNS responders sometimes repeat queries in responses