Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(mdns): Resolve conflicts only on self hosted items
Skip solving conflicts for delegated names and delegated services

Closes #185
  • Loading branch information
david-cermak committed Mar 20, 2023
commit e69a9ebb3d8a2f085aa6b618db300337c37b48e0
37 changes: 36 additions & 1 deletion components/mdns/mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down