Merge branch 'bugfix/mdns_revert_nonstrict_mode' into 'release/v4.1'

mdns: Revert support for queries in responses, mDNS non-strict mode (v4.1)

See merge request espressif/esp-idf!12044
This commit is contained in:
Jiang Jiang Jian
2021-01-20 16:42:58 +08:00
2 changed files with 7 additions and 35 deletions

View File

@@ -1313,17 +1313,6 @@ static void _mdns_create_answer_from_parsed_packet(mdns_parsed_packet_t * parsed
_mdns_free_tx_packet(packet); _mdns_free_tx_packet(packet);
return; return;
} }
#ifdef MDNS_REPEAT_QUERY_IN_RESPONSE
mdns_out_question_t * out_question = malloc(sizeof(mdns_out_question_t));
if (out_question == NULL) {
HOOK_MALLOC_FAILED;
_mdns_free_tx_packet(packet);
return;
}
memcpy(out_question, q, sizeof(mdns_out_question_t));
out_question->next = NULL;
queueToEnd(mdns_out_question_t, packet->questions, out_question);
#endif // MDNS_REPEAT_QUERY_IN_RESPONSE
} else if (!_mdns_alloc_answer(&packet->answers, q->type, NULL, send_flush, false)) { } else if (!_mdns_alloc_answer(&packet->answers, q->type, NULL, send_flush, false)) {
_mdns_free_tx_packet(packet); _mdns_free_tx_packet(packet);
return; return;
@@ -2753,7 +2742,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
} }
} }
if (header.questions && !parsed_packet->questions && !parsed_packet->discovery && !header.answers) { if (header.questions && !parsed_packet->questions && !parsed_packet->discovery) {
goto clear_rx_packet; goto clear_rx_packet;
} else if (header.answers || header.servers || header.additional) { } else if (header.answers || header.servers || header.additional) {
uint16_t recordIndex = 0; uint16_t recordIndex = 0;
@@ -2796,14 +2785,13 @@ 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 (header.questions || !parsed_packet->authoritative || record_type == MDNS_NS) {
//skip this record //skip this record
continue; continue;
} }

View File

@@ -23,22 +23,6 @@
#define _mdns_dbg_printf(...) printf(__VA_ARGS__) #define _mdns_dbg_printf(...) printf(__VA_ARGS__)
#endif #endif
/** mDNS strict mode: Set this to 1 for the mDNS library to strictly follow the RFC6762:
* Strict features:
* - to do not set original questions in response packets per RFC6762, sec 6
*
* The actual 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.
*/
#define MDNS_STRICT_MODE 0
#if !MDNS_STRICT_MODE
/* mDNS responders sometimes repeat queries in responses
* but according to RFC6762, sec 6: Responses MUST NOT contain
* any item in question field */
#define MDNS_REPEAT_QUERY_IN_RESPONSE 1
#endif
/** The maximum number of services */ /** The maximum number of services */
#define MDNS_MAX_SERVICES CONFIG_MDNS_MAX_SERVICES #define MDNS_MAX_SERVICES CONFIG_MDNS_MAX_SERVICES