fix(mdns): Resolve conflicts only on self hosted items

Skip solving conflicts for delegated names and delegated services

Closes https://github.com/espressif/esp-protocols/issues/185
This commit is contained in:
David Cermak
2023-02-17 19:18:43 +01:00
parent 2e607e8ffb
commit e69a9ebb3d

View File

@ -3059,6 +3059,29 @@ static bool _mdns_name_is_discovery(mdns_name_t *name, uint16_t type)
);
}
/**
* @brief Check if the parsed name is self-hosted, i.e. we should resolve conflicts
*/
static bool _mdns_name_is_selfhosted(mdns_name_t *name)
{
if (_str_null_or_empty(_mdns_server->hostname)) { // self-hostname needs to be defined
return false;
}
// hostname only -- check if selfhosted name
if (_str_null_or_empty(name->service) && _str_null_or_empty(name->proto) &&
strcasecmp(name->host, _mdns_server->hostname) == 0 ) {
return true;
}
// service -- check if selfhosted service
mdns_srv_item_t *srv = _mdns_get_service_item(name->service, name->proto, NULL);
if (srv && strcasecmp(_mdns_server->hostname, srv->service->hostname) == 0) {
return true;
}
return false;
}
/**
* @brief Check if the parsed name is ours (matches service or host name)
*/
@ -3667,7 +3690,7 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
}
}
}
bool is_selfhosted = _mdns_name_is_selfhosted(name);
if (!_mdns_parse_fqdn(data, data_ptr + MDNS_SRV_FQDN_OFFSET, name, len)) {
continue;//error
}
@ -3695,6 +3718,9 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
_mdns_remove_scheduled_answer(packet->tcpip_if, packet->ip_protocol, type, service);
continue;
}
if (!is_selfhosted) {
continue;
}
//detect collision (-1=won, 0=none, 1=lost)
int col = 0;
if (mdns_class > 1) {
@ -3785,6 +3811,9 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
_mdns_remove_parsed_question(parsed_packet, type, service);
continue;
}
if (!_mdns_name_is_selfhosted(name)) {
continue;
}
//detect collision (-1=won, 0=none, 1=lost)
int col = 0;
if (mdns_class > 1) {
@ -3819,6 +3848,9 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
_mdns_remove_parsed_question(parsed_packet, type, NULL);
continue;
}
if (!_mdns_name_is_selfhosted(name)) {
continue;
}
//detect collision (-1=won, 0=none, 1=lost)
int col = 0;
if (mdns_class > 1) {
@ -3869,6 +3901,9 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
_mdns_remove_parsed_question(parsed_packet, type, NULL);
continue;
}
if (!_mdns_name_is_selfhosted(name)) {
continue;
}
//detect collision (-1=won, 0=none, 1=lost)
int col = 0;
if (mdns_class > 1) {