Skip to content

Commit

Permalink
dns_server: fix mdns lookup ttl issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed May 8, 2024
1 parent 5276ba5 commit f92fbb8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ static int _dns_client_recv(struct dns_server_info *server_info, unsigned char *
_dns_replied_check_remove(query, from, from_len);
atomic_inc(&query->dns_request_sent);
if (ret == DNS_CLIENT_ACTION_RETRY) {
/*
/*
* retry immdiately
* The socket needs to be re-created to avoid being limited, such as 1.1.1.1
*/
Expand Down Expand Up @@ -2076,9 +2076,6 @@ static int _dns_client_create_socket_udp(struct dns_server_info *server_info)
return -1;
}

#include <net/if.h>
#include <sys/ioctl.h>

static int _dns_client_create_socket_udp_mdns(struct dns_server_info *server_info)
{
int fd = 0;
Expand Down
13 changes: 7 additions & 6 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -6710,7 +6710,7 @@ static void _dns_server_mdns_query_setup_server_group(struct dns_request *reques
}

*group_name = DNS_SERVER_GROUP_MDNS;
safe_strncpy(request->dns_group_name, DNS_SERVER_GROUP_MDNS, sizeof(request->dns_group_name));
safe_strncpy(request->dns_group_name, *group_name, sizeof(request->dns_group_name));
return;
}

Expand Down Expand Up @@ -6949,18 +6949,19 @@ static int _dns_server_do_query(struct dns_request *request, int skip_notify_eve
/* check and set passthrough */
_dns_server_check_set_passthrough(request);

/* process ptr */
if (_dns_server_process_ptr_query(request) == 0) {
goto clean_exit;
}

/* process cache */
if (request->prefetch == 0 && request->dualstack_selection_query == 0) {
_dns_server_mdns_query_setup_server_group(request, &server_group_name);
if (_dns_server_process_cache(request) == 0) {
goto clean_exit;
}
}

/* process ptr */
if (_dns_server_process_ptr_query(request) == 0) {
goto clean_exit;
}

ret = _dns_server_set_to_pending_list(request);
if (ret == 0) {
goto clean_exit;
Expand Down
10 changes: 10 additions & 0 deletions test/cases/test-mdns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ mdns-lookup yes
EXPECT_EQ(client.GetAnswer()[1].GetName(), "host.local");
EXPECT_EQ(client.GetAnswer()[1].GetData(), "1.2.3.4");

ASSERT_TRUE(client.Query("host A", 60053));
std::cout << client.GetResult() << std::endl;
ASSERT_EQ(client.GetAnswerNum(), 2);
EXPECT_EQ(client.GetStatus(), "NOERROR");
EXPECT_EQ(client.GetAnswer()[0].GetName(), "host");
EXPECT_GT(client.GetAnswer()[0].GetTTL(), 60);
EXPECT_EQ(client.GetAnswer()[0].GetData(), "host.local.");
EXPECT_EQ(client.GetAnswer()[1].GetName(), "host.local");
EXPECT_EQ(client.GetAnswer()[1].GetData(), "1.2.3.4");

ASSERT_TRUE(client.Query("host AAAA", 60053));
std::cout << client.GetResult() << std::endl;
ASSERT_EQ(client.GetAnswerNum(), 2);
Expand Down

0 comments on commit f92fbb8

Please sign in to comment.