mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-18 21:12:22 +02:00
mdns: fix wrong SRV/PTR record handling
* Original commit: espressif/esp-idf@e6135552d2
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
9fa25ef3b6
commit
402baebfee
@ -1418,7 +1418,7 @@ static void _mdns_create_answer_from_parsed_packet(mdns_parsed_packet_t *parsed_
|
|||||||
if (q->service && q->proto) {
|
if (q->service && q->proto) {
|
||||||
mdns_srv_item_t *service = _mdns_server->services;
|
mdns_srv_item_t *service = _mdns_server->services;
|
||||||
while (service) {
|
while (service) {
|
||||||
if (_mdns_service_match(service->service, q->service, q->proto, q->host)) {
|
if (_mdns_service_match(service->service, q->service, q->proto, NULL)) {
|
||||||
if (!_mdns_create_answer_from_service(packet, service->service, q, shared, send_flush)) {
|
if (!_mdns_create_answer_from_service(packet, service->service, q, shared, send_flush)) {
|
||||||
_mdns_free_tx_packet(packet);
|
_mdns_free_tx_packet(packet);
|
||||||
return;
|
return;
|
||||||
@ -1515,6 +1515,13 @@ static bool _mdns_append_host(mdns_out_answer_t ** destination, mdns_host_item_t
|
|||||||
static bool _mdns_append_host_list_in_services(mdns_out_answer_t ** destination, mdns_srv_item_t * services[],
|
static bool _mdns_append_host_list_in_services(mdns_out_answer_t ** destination, mdns_srv_item_t * services[],
|
||||||
size_t services_len, bool flush, bool bye)
|
size_t services_len, bool flush, bool bye)
|
||||||
{
|
{
|
||||||
|
if (services == NULL) {
|
||||||
|
mdns_host_item_t * host = mdns_get_host_item(_mdns_server->hostname);
|
||||||
|
if (host != NULL) {
|
||||||
|
return _mdns_append_host(destination, host, flush, bye);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
for (size_t i = 0; i < services_len; i++) {
|
for (size_t i = 0; i < services_len; i++) {
|
||||||
mdns_host_item_t *host = mdns_get_host_item(services[i]->service->hostname);
|
mdns_host_item_t *host = mdns_get_host_item(services[i]->service->hostname);
|
||||||
if (!_mdns_append_host(destination, host, flush, bye)) {
|
if (!_mdns_append_host(destination, host, flush, bye)) {
|
||||||
@ -1542,6 +1549,44 @@ static bool _mdns_append_host_list(mdns_out_answer_t ** destination, bool flush,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _mdns_append_host_question(mdns_out_question_t **questions, const char *hostname, bool unicast)
|
||||||
|
{
|
||||||
|
mdns_out_question_t *q = (mdns_out_question_t *)malloc(sizeof(mdns_out_question_t));
|
||||||
|
if (!q) {
|
||||||
|
HOOK_MALLOC_FAILED;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
q->next = NULL;
|
||||||
|
q->unicast = unicast;
|
||||||
|
q->type = MDNS_TYPE_ANY;
|
||||||
|
q->host = hostname;
|
||||||
|
q->service = NULL;
|
||||||
|
q->proto = NULL;
|
||||||
|
q->domain = MDNS_DEFAULT_DOMAIN;
|
||||||
|
q->own_dynamic_memory = false;
|
||||||
|
if (_mdns_question_exists(q, *questions)) {
|
||||||
|
free(q);
|
||||||
|
} else {
|
||||||
|
queueToEnd(mdns_out_question_t, *questions, q);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool _mdns_append_host_questions_for_services(mdns_out_question_t **questions, mdns_srv_item_t *services[],
|
||||||
|
size_t len, bool unicast)
|
||||||
|
{
|
||||||
|
if (!_str_null_or_empty(_mdns_server->hostname) &&
|
||||||
|
!_mdns_append_host_question(questions, _mdns_server->hostname, unicast)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
if (!_mdns_append_host_question(questions, services[i]->service->hostname, unicast)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create probe packet for particular services on particular PCB
|
* @brief Create probe packet for particular services on particular PCB
|
||||||
*/
|
*/
|
||||||
@ -1582,26 +1627,9 @@ static mdns_tx_packet_t * _mdns_create_probe_packet(mdns_if_t tcpip_if, mdns_ip_
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (include_ip) {
|
if (include_ip) {
|
||||||
for (i = 0; i < len; i++) {
|
if (!_mdns_append_host_questions_for_services(&packet->questions, services, len, first)) {
|
||||||
mdns_out_question_t * q = (mdns_out_question_t *)malloc(sizeof(mdns_out_question_t));
|
_mdns_free_tx_packet(packet);
|
||||||
if (!q) {
|
return NULL;
|
||||||
HOOK_MALLOC_FAILED;
|
|
||||||
_mdns_free_tx_packet(packet);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
q->next = NULL;
|
|
||||||
q->unicast = first;
|
|
||||||
q->type = MDNS_TYPE_ANY;
|
|
||||||
q->host = services[i]->service->hostname;
|
|
||||||
q->service = NULL;
|
|
||||||
q->proto = NULL;
|
|
||||||
q->domain = MDNS_DEFAULT_DOMAIN;
|
|
||||||
q->own_dynamic_memory = false;
|
|
||||||
if (_mdns_question_exists(q, packet->questions)) {
|
|
||||||
free(q);
|
|
||||||
} else {
|
|
||||||
queueToEnd(mdns_out_question_t, packet->questions, q);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_mdns_append_host_list_in_services(&packet->servers, services, len, false, false)) {
|
if (!_mdns_append_host_list_in_services(&packet->servers, services, len, false, false)) {
|
||||||
@ -1613,23 +1641,6 @@ static mdns_tx_packet_t * _mdns_create_probe_packet(mdns_if_t tcpip_if, mdns_ip_
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create announce packet for self IP addresses
|
|
||||||
*/
|
|
||||||
static mdns_tx_packet_t * _mdns_create_announce_self_ip(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
|
|
||||||
{
|
|
||||||
mdns_tx_packet_t * packet = _mdns_alloc_packet_default(tcpip_if, ip_protocol);
|
|
||||||
if (!packet) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
mdns_host_item_t * host = mdns_get_host_item(_mdns_server->hostname);
|
|
||||||
if (!_mdns_append_host(&packet->servers, host, true, false)) {
|
|
||||||
_mdns_free_tx_packet(packet);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create announce packet for particular services on particular PCB
|
* @brief Create announce packet for particular services on particular PCB
|
||||||
*/
|
*/
|
||||||
@ -1890,12 +1901,7 @@ static void _mdns_announce_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protoco
|
|||||||
}
|
}
|
||||||
|
|
||||||
_pcb->state = PCB_ANNOUNCE_1;
|
_pcb->state = PCB_ANNOUNCE_1;
|
||||||
mdns_tx_packet_t * p = NULL;
|
mdns_tx_packet_t * p = _mdns_create_announce_packet(tcpip_if, ip_protocol, services, len, include_ip);
|
||||||
if (services != NULL) {
|
|
||||||
p = _mdns_create_announce_packet(tcpip_if, ip_protocol, services, len, include_ip);
|
|
||||||
} else {
|
|
||||||
p = _mdns_create_announce_self_ip(tcpip_if, ip_protocol);
|
|
||||||
}
|
|
||||||
if (p) {
|
if (p) {
|
||||||
_mdns_schedule_tx_packet(p, 0);
|
_mdns_schedule_tx_packet(p, 0);
|
||||||
}
|
}
|
||||||
@ -2646,7 +2652,7 @@ static bool _mdns_name_is_ours(mdns_name_t * name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//find the service
|
//find the service
|
||||||
mdns_srv_item_t * service = _mdns_get_service_item(name->service, name->proto, name->host);
|
mdns_srv_item_t * service = _mdns_get_service_item(name->service, name->proto, NULL);
|
||||||
if (!service) {
|
if (!service) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -3124,7 +3130,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
|||||||
} else if (!name->sub && _mdns_name_is_ours(name)) {
|
} else 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, name->host);
|
service = _mdns_get_service_item(name->service, name->proto, NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!parsed_packet->authoritative || record_type == MDNS_NS) {
|
if (!parsed_packet->authoritative || record_type == MDNS_NS) {
|
||||||
@ -3142,7 +3148,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
|||||||
_mdns_search_result_add_ptr(search_result, name->host, packet->tcpip_if, packet->ip_protocol);
|
_mdns_search_result_add_ptr(search_result, name->host, packet->tcpip_if, packet->ip_protocol);
|
||||||
} else if ((discovery || ours) && !name->sub && _mdns_name_is_ours(name)) {
|
} else if ((discovery || ours) && !name->sub && _mdns_name_is_ours(name)) {
|
||||||
if (discovery) {
|
if (discovery) {
|
||||||
service = _mdns_get_service_item(name->service, name->proto, name->host);
|
service = _mdns_get_service_item(name->service, name->proto, NULL);
|
||||||
_mdns_remove_parsed_question(parsed_packet, MDNS_TYPE_SDPTR, service);
|
_mdns_remove_parsed_question(parsed_packet, MDNS_TYPE_SDPTR, service);
|
||||||
} else if (parsed_packet->questions && !parsed_packet->probe) {
|
} else if (parsed_packet->questions && !parsed_packet->probe) {
|
||||||
_mdns_remove_parsed_question(parsed_packet, type, service);
|
_mdns_remove_parsed_question(parsed_packet, type, service);
|
||||||
|
@ -215,7 +215,7 @@ typedef struct {
|
|||||||
} mdns_header_t;
|
} mdns_header_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char host[MDNS_NAME_BUF_LEN];
|
char host[MDNS_NAME_BUF_LEN]; // hostname for A/AAAA records, instance name for SRV records
|
||||||
char service[MDNS_NAME_BUF_LEN];
|
char service[MDNS_NAME_BUF_LEN];
|
||||||
char proto[MDNS_NAME_BUF_LEN];
|
char proto[MDNS_NAME_BUF_LEN];
|
||||||
char domain[MDNS_NAME_BUF_LEN];
|
char domain[MDNS_NAME_BUF_LEN];
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
CONFIG_MDNS_RESOLVE_TEST_SERVICES=y
|
CONFIG_MDNS_RESOLVE_TEST_SERVICES=y
|
||||||
CONFIG_MDNS_ADD_MAC_TO_HOSTNAME=y
|
CONFIG_MDNS_ADD_MAC_TO_HOSTNAME=y
|
||||||
|
CONFIG_MDNS_PUBLISH_DELEGATE_HOST=y
|
||||||
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
|
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
|
||||||
|
Reference in New Issue
Block a user