From f92fbb83cefb0446fc5dd1b0cd16fc6b2fc7664c Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Thu, 9 May 2024 05:13:44 +0800 Subject: [PATCH] dns_server: fix mdns lookup ttl issue --- src/dns_client.c | 5 +---- src/dns_server.c | 13 +++++++------ test/cases/test-mdns.cc | 10 ++++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/dns_client.c b/src/dns_client.c index 0ee395be32..f814d4ff90 100644 --- a/src/dns_client.c +++ b/src/dns_client.c @@ -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 */ @@ -2076,9 +2076,6 @@ static int _dns_client_create_socket_udp(struct dns_server_info *server_info) return -1; } -#include -#include - static int _dns_client_create_socket_udp_mdns(struct dns_server_info *server_info) { int fd = 0; diff --git a/src/dns_server.c b/src/dns_server.c index 42be38ad30..976ae8e44b 100644 --- a/src/dns_server.c +++ b/src/dns_server.c @@ -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; } @@ -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; diff --git a/test/cases/test-mdns.cc b/test/cases/test-mdns.cc index a06ade1907..047b3873e2 100644 --- a/test/cases/test-mdns.cc +++ b/test/cases/test-mdns.cc @@ -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);