Skip to content

Commit 5c2c597

Browse files
committed
fix(mdns): Cleanup mdns sender
1 parent c41424e commit 5c2c597

File tree

6 files changed

+36
-41
lines changed

6 files changed

+36
-41
lines changed

components/mdns/mdns_receive.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,9 @@ static void mdns_parse_packet(mdns_rx_packet_t *packet)
736736
question->type = type;
737737
question->sub = name->sub;
738738
if (strdup_check(&(question->host), name->host)
739-
|| strdup_check(&(question->service), name->service)
740-
|| strdup_check(&(question->proto), name->proto)
741-
|| strdup_check(&(question->domain), name->domain)) {
739+
|| strdup_check(&(question->service), name->service)
740+
|| strdup_check(&(question->proto), name->proto)
741+
|| strdup_check(&(question->domain), name->domain)) {
742742
goto clear_rx_packet;
743743
}
744744
}

components/mdns/mdns_responder.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ bool mdns_priv_delegate_hostname_add(const char *hostname, mdns_ip_addr_t *addre
424424
static bool delegate_hostname_set_address(const char *hostname, mdns_ip_addr_t *address_list)
425425
{
426426
if (!mdns_utils_str_null_or_empty(s_server->hostname) &&
427-
strcasecmp(hostname, s_server->hostname) == 0) {
427+
strcasecmp(hostname, s_server->hostname) == 0) {
428428
return false;
429429
}
430430
mdns_host_item_t *host = s_server->host_list;
@@ -520,15 +520,15 @@ void mdns_priv_responder_action(mdns_action_t *action, mdns_action_subtype_t typ
520520
send_bye_all_pcbs_no_instance(true);
521521
mdns_priv_remap_self_service_hostname(s_server->hostname, action->data.hostname_set.hostname);
522522
mdns_mem_free((char *)s_server->hostname);
523-
s_server->hostname = action->data.hostname_set.hostname;
523+
s_server->hostname = action->data.hostname_set.hostname;
524524
s_server->self_host.hostname = action->data.hostname_set.hostname;
525525
mdns_priv_restart_all_pcbs();
526526
xSemaphoreGive(s_server->action_sema);
527527
break;
528528
case ACTION_INSTANCE_SET:
529529
send_bye_all_pcbs_no_instance(false);
530530
mdns_mem_free((char *)s_server->instance);
531-
s_server->instance = action->data.instance;
531+
s_server->instance = action->data.instance;
532532
mdns_priv_restart_all_pcbs_no_instance();
533533
break;
534534
case ACTION_DELEGATE_HOSTNAME_ADD:

components/mdns/mdns_send.c

+26-27
Original file line numberDiff line numberDiff line change
@@ -250,30 +250,30 @@ static mdns_host_item_t *get_host_item(const char *hostname)
250250
}
251251

252252
static bool create_answer_from_service(mdns_tx_packet_t *packet, mdns_service_t *service,
253-
mdns_parsed_question_t *question, bool shared, bool send_flush)
253+
mdns_parsed_question_t *question, bool shared, bool send_flush)
254254
{
255255
mdns_host_item_t *host = get_host_item(service->hostname);
256256
bool is_delegated = (host != mdns_priv_get_self_host());
257257
if (question->type == MDNS_TYPE_PTR || question->type == MDNS_TYPE_ANY) {
258258
// According to RFC6763-section12.1, for DNS-SD, SRV, TXT and all address records
259259
// should be included in additional records.
260260
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_PTR, service, NULL, false, false) ||
261-
!mdns_priv_create_answer(is_delegated ? &packet->additional : &packet->answers, MDNS_TYPE_SRV, service,
262-
NULL, send_flush, false) ||
263-
!mdns_priv_create_answer(is_delegated ? &packet->additional : &packet->answers, MDNS_TYPE_TXT, service,
264-
NULL, send_flush, false) ||
265-
!mdns_priv_create_answer((shared || is_delegated) ? &packet->additional : &packet->answers, MDNS_TYPE_A,
261+
!mdns_priv_create_answer(is_delegated ? &packet->additional : &packet->answers, MDNS_TYPE_SRV, service,
262+
NULL, send_flush, false) ||
263+
!mdns_priv_create_answer(is_delegated ? &packet->additional : &packet->answers, MDNS_TYPE_TXT, service,
264+
NULL, send_flush, false) ||
265+
!mdns_priv_create_answer((shared || is_delegated) ? &packet->additional : &packet->answers, MDNS_TYPE_A,
266266
service, host, send_flush,
267267
false) ||
268-
!mdns_priv_create_answer((shared || is_delegated) ? &packet->additional : &packet->answers,
268+
!mdns_priv_create_answer((shared || is_delegated) ? &packet->additional : &packet->answers,
269269
MDNS_TYPE_AAAA, service, host,
270270
send_flush, false)) {
271271
return false;
272272
}
273273
} else if (question->type == MDNS_TYPE_SRV) {
274274
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_SRV, service, NULL, send_flush, false) ||
275-
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_A, service, host, send_flush, false) ||
276-
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_AAAA, service, host, send_flush, false)) {
275+
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_A, service, host, send_flush, false) ||
276+
!mdns_priv_create_answer(&packet->additional, MDNS_TYPE_AAAA, service, host, send_flush, false)) {
277277
return false;
278278
}
279279
} else if (question->type == MDNS_TYPE_TXT) {
@@ -292,7 +292,7 @@ static bool create_answer_from_hostname(mdns_tx_packet_t *packet, const char *ho
292292
{
293293
mdns_host_item_t *host = get_host_item(hostname);
294294
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_A, NULL, host, send_flush, false) ||
295-
!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_AAAA, NULL, host, send_flush, false)) {
295+
!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_AAAA, NULL, host, send_flush, false)) {
296296
return false;
297297
}
298298
return true;
@@ -411,7 +411,7 @@ static bool append_host_question(mdns_out_question_t **questions, const char *ho
411411
}
412412

413413
static bool append_host_questions_for_services(mdns_out_question_t **questions, mdns_srv_item_t *services[],
414-
size_t len, bool unicast)
414+
size_t len, bool unicast)
415415
{
416416
if (!mdns_utils_str_null_or_empty(mdns_priv_get_global_hostname()) &&
417417
!append_host_question(questions, mdns_priv_get_global_hostname(), unicast)) {
@@ -491,12 +491,12 @@ static uint8_t append_reverse_ptr_record(uint8_t *packet, uint16_t *index, const
491491
return 0;
492492
}
493493

494-
if (!_mdns_append_type(packet, index, MDNS_ANSWER_PTR, false, 10 /* TTL set to 10s*/)) {
494+
if (!append_type(packet, index, MDNS_ANSWER_PTR, false, 10 /* TTL set to 10s*/)) {
495495
return 0;
496496
}
497497

498498
uint16_t data_len_location = *index - 2; /* store the position of size (2=16bis) of this record */
499-
const char *str[2] = {priv_get_self_host()->hostname, MDNS_UTILS_DEFAULT_DOMAIN };
499+
const char *str[2] = {mdns_priv_get_self_host()->hostname, MDNS_UTILS_DEFAULT_DOMAIN };
500500

501501
int part_length = append_fqdn(packet, index, str, 2, MDNS_MAX_PACKET_SIZE);
502502
if (!part_length) {
@@ -588,8 +588,7 @@ void mdns_priv_create_answer_from_parsed_packet(mdns_parsed_packet_t *parsed_pac
588588
#ifdef CONFIG_MDNS_RESPOND_REVERSE_QUERIES
589589
} else if (q->type == MDNS_TYPE_PTR) {
590590
mdns_host_item_t *host = get_host_item(q->host);
591-
#error
592-
if (!_mdns_alloc_answer(&packet->answers, MDNS_TYPE_PTR, NULL, host, send_flush, false)) {
591+
if (!mdns_priv_create_answer(&packet->answers, MDNS_TYPE_PTR, NULL, host, send_flush, false)) {
593592
mdns_priv_free_tx_packet(packet);
594593
return;
595594
} else {
@@ -829,8 +828,8 @@ static uint16_t append_ptr_record(uint8_t *packet, uint16_t *index, const char *
829828
* @return length of added data: 0 on error or length on success
830829
*/
831830
static uint16_t append_subtype_ptr_record(uint8_t *packet, uint16_t *index, const char *instance,
832-
const char *subtype, const char *service, const char *proto, bool flush,
833-
bool bye)
831+
const char *subtype, const char *service, const char *proto, bool flush,
832+
bool bye)
834833
{
835834
const char *subtype_str[5] = {subtype, MDNS_SUB_STR, service, proto, MDNS_UTILS_DEFAULT_DOMAIN};
836835
const char *instance_str[4] = {instance, service, proto, MDNS_UTILS_DEFAULT_DOMAIN};
@@ -868,12 +867,12 @@ static uint16_t append_subtype_ptr_record(uint8_t *packet, uint16_t *index, cons
868867
* @return number of answers added to the packet
869868
*/
870869
static uint8_t append_service_ptr_answers(uint8_t *packet, uint16_t *index, mdns_service_t *service, bool flush,
871-
bool bye)
870+
bool bye)
872871
{
873872
uint8_t appended_answers = 0;
874873

875874
if (append_ptr_record(packet, index, mdns_utils_get_service_instance_name(service), service->service,
876-
service->proto, flush, bye) <= 0) {
875+
service->proto, flush, bye) <= 0) {
877876
return appended_answers;
878877
}
879878
appended_answers++;
@@ -882,7 +881,7 @@ static uint8_t append_service_ptr_answers(uint8_t *packet, uint16_t *index, mdns
882881
while (subtype) {
883882
appended_answers +=
884883
(append_subtype_ptr_record(packet, index, mdns_utils_get_service_instance_name(service), subtype->subtype,
885-
service->service, service->proto, flush, bye) > 0);
884+
service->service, service->proto, flush, bye) > 0);
886885
subtype = subtype->next;
887886
}
888887

@@ -1180,7 +1179,7 @@ static uint16_t append_aaaa_record(uint8_t *packet, uint16_t *index, const char
11801179
#endif
11811180

11821181
static uint8_t append_host_answer(uint8_t *packet, uint16_t *index, mdns_host_item_t *host,
1183-
uint8_t address_type, bool flush, bool bye)
1182+
uint8_t address_type, bool flush, bool bye)
11841183
{
11851184
mdns_ip_addr_t *addr = host->address_list;
11861185
uint8_t num_records = 0;
@@ -1196,7 +1195,7 @@ static uint8_t append_host_answer(uint8_t *packet, uint16_t *index, mdns_host_it
11961195
#ifdef CONFIG_LWIP_IPV6
11971196
if (address_type == ESP_IPADDR_TYPE_V6 &&
11981197
append_aaaa_record(packet, index, host->hostname, (uint8_t *)addr->addr.u_addr.ip6.addr, flush,
1199-
bye) <= 0) {
1198+
bye) <= 0) {
12001199
break;
12011200
}
12021201
#endif /* CONFIG_LWIP_IPV6 */
@@ -1238,8 +1237,8 @@ static uint8_t append_answer(uint8_t *packet, uint16_t *index, mdns_out_answer_t
12381237
#endif /* CONFIG_MDNS_RESPOND_REVERSE_QUERIES */
12391238
} else {
12401239
return append_ptr_record(packet, index,
1241-
answer->custom_instance, answer->custom_service, answer->custom_proto,
1242-
answer->flush, answer->bye) > 0;
1240+
answer->custom_instance, answer->custom_service, answer->custom_proto,
1241+
answer->flush, answer->bye) > 0;
12431242
}
12441243
} else if (answer->type == MDNS_TYPE_SRV) {
12451244
return append_srv_record(packet, index, answer->service, answer->flush, answer->bye) > 0;
@@ -1294,7 +1293,7 @@ static uint8_t append_answer(uint8_t *packet, uint16_t *index, mdns_out_answer_t
12941293
return 0;
12951294
}
12961295
if (append_aaaa_record(packet, index, mdns_priv_get_global_hostname(), (uint8_t *)if_ip6s[i].addr,
1297-
answer->flush, answer->bye) <= 0) {
1296+
answer->flush, answer->bye) <= 0) {
12981297
return 0;
12991298
}
13001299
}
@@ -1308,13 +1307,13 @@ static uint8_t append_answer(uint8_t *packet, uint16_t *index, mdns_out_answer_t
13081307
return count;
13091308
}
13101309
if (append_aaaa_record(packet, index, mdns_priv_get_global_hostname(), (uint8_t *)other_ip6.addr,
1311-
answer->flush, answer->bye) > 0) {
1310+
answer->flush, answer->bye) > 0) {
13121311
return 1 + count;
13131312
}
13141313
return count;
13151314
} else if (answer->host != NULL) {
13161315
return append_host_answer(packet, index, answer->host, ESP_IPADDR_TYPE_V6, answer->flush,
1317-
answer->bye);
1316+
answer->bye);
13181317
}
13191318
}
13201319
#endif /* CONFIG_LWIP_IPV6 */

components/mdns/tests/host_unit_test/stubs/mdns_engine.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void execute_action(mdns_action_t *action)
2929
break;
3030

3131
case ACTION_TX_HANDLE:
32-
mdns_send_action(action, ACTION_RUN);
32+
mdns_priv_send_action(action, ACTION_RUN);
3333
break;
3434
case ACTION_RX_HANDLE:
3535
mdns_priv_receive_action(action, ACTION_RUN);

components/mdns/tests/host_unit_test/unity/test_receiver/test_receiver.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void setup_cmock(void)
7474
mdns_priv_pcb_check_probing_services_CMockIgnore();
7575
mdns_priv_pcb_is_after_probing_IgnoreAndReturn(true);
7676

77-
_mdns_clear_tx_queue_head_CMockIgnore();
78-
_mdns_remove_scheduled_service_packets_CMockIgnore();
77+
mdns_priv_clear_tx_queue_CMockIgnore();
78+
mdns_priv_remove_scheduled_service_packets_CMockIgnore();
7979
mdns_priv_create_answer_from_parsed_packet_Stub(mdns_priv_create_answer_from_parsed_packet_Callback);
8080
}
8181

components/mdns/tests/host_unit_test/unity/test_sender/test_sender.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ void setup_cmock(void)
1818
mdns_priv_pcb_is_after_probing_IgnoreAndReturn(true);
1919
}
2020

21-
22-
23-
// Example of a more complex test with answers and additional records
2421
static void test_dispatch_tx_packet(void)
2522
{
2623
mdns_tx_packet_t p = {};
27-
_mdns_dispatch_tx_packet(&p);
24+
mdns_priv_dispatch_tx_packet(&p);
2825
}
2926

30-
3127
void run_unity_tests(void)
3228
{
3329
UNITY_BEGIN();

0 commit comments

Comments
 (0)