dns_server: fix max ttl reply issue.
This commit is contained in:
@@ -2239,12 +2239,14 @@ static int _dns_client_process_udp_proxy(struct dns_server_info *server_info, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
int latency = get_tick_count() - server_info->send_tick;
|
int latency = get_tick_count() - server_info->send_tick;
|
||||||
|
tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d, latency: %d",
|
||||||
|
get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len, latency);
|
||||||
|
|
||||||
if (latency < server_info->drop_packet_latency_ms) {
|
if (latency < server_info->drop_packet_latency_ms) {
|
||||||
|
tlog(TLOG_DEBUG, "drop packet from %s, latency: %d", from_host, latency);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d",
|
|
||||||
get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len);
|
|
||||||
|
|
||||||
/* update recv time */
|
/* update recv time */
|
||||||
time(&server_info->last_recv);
|
time(&server_info->last_recv);
|
||||||
@@ -2322,14 +2324,15 @@ static int _dns_client_process_udp(struct dns_server_info *server_info, struct e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d, ttl: %d",
|
int latency = get_tick_count() - server_info->send_tick;
|
||||||
get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len, ttl);
|
tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d, ttl: %d, latency: %d",
|
||||||
|
get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len, ttl, latency);
|
||||||
|
|
||||||
/* update recv time */
|
/* update recv time */
|
||||||
time(&server_info->last_recv);
|
time(&server_info->last_recv);
|
||||||
|
|
||||||
int latency = get_tick_count() - server_info->send_tick;
|
|
||||||
if (latency < server_info->drop_packet_latency_ms) {
|
if (latency < server_info->drop_packet_latency_ms) {
|
||||||
|
tlog(TLOG_DEBUG, "drop packet from %s, latency: %d", from_host, latency);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1838,7 +1838,7 @@ static int _dns_request_update_id_ttl(struct dns_server_post_context *context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ttl > dns_conf_rr_ttl_reply_max) {
|
if (ttl > dns_conf_rr_ttl_reply_max) {
|
||||||
ttl %= dns_conf_rr_ttl_reply_max;
|
ttl = dns_conf_rr_ttl_reply_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ttl == 0) {
|
if (ttl == 0) {
|
||||||
|
|||||||
@@ -127,6 +127,16 @@ cache-persist no)""");
|
|||||||
EXPECT_EQ(client.GetAnswer()[0].GetName(), "a.com");
|
EXPECT_EQ(client.GetAnswer()[0].GetName(), "a.com");
|
||||||
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 5);
|
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 5);
|
||||||
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
|
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
ASSERT_TRUE(client.Query("a.com", 60053));
|
||||||
|
std::cout << client.GetResult() << std::endl;
|
||||||
|
ASSERT_EQ(client.GetAnswerNum(), 1);
|
||||||
|
EXPECT_EQ(client.GetStatus(), "NOERROR");
|
||||||
|
EXPECT_EQ(client.GetAnswer()[0].GetName(), "a.com");
|
||||||
|
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 5);
|
||||||
|
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Cache, max_reply_ttl_expired)
|
TEST_F(Cache, max_reply_ttl_expired)
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ TEST_F(Cname, subdomain1)
|
|||||||
if (request->domain == "s.a.com") {
|
if (request->domain == "s.a.com") {
|
||||||
smartdns::MockServer::AddIP(request, request->domain.c_str(), "4.5.6.7", 700);
|
smartdns::MockServer::AddIP(request, request->domain.c_str(), "4.5.6.7", 700);
|
||||||
return smartdns::SERVER_REQUEST_OK;
|
return smartdns::SERVER_REQUEST_OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
smartdns::MockServer::AddIP(request, request->domain.c_str(), "1.2.3.4", 611);
|
smartdns::MockServer::AddIP(request, request->domain.c_str(), "1.2.3.4", 611);
|
||||||
@@ -114,7 +113,6 @@ TEST_F(Cname, subdomain2)
|
|||||||
if (request->domain == "a.s.a.com") {
|
if (request->domain == "a.s.a.com") {
|
||||||
smartdns::MockServer::AddIP(request, request->domain.c_str(), "4.5.6.7", 700);
|
smartdns::MockServer::AddIP(request, request->domain.c_str(), "4.5.6.7", 700);
|
||||||
return smartdns::SERVER_REQUEST_OK;
|
return smartdns::SERVER_REQUEST_OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
smartdns::MockServer::AddIP(request, request->domain.c_str(), "1.2.3.4", 611);
|
smartdns::MockServer::AddIP(request, request->domain.c_str(), "1.2.3.4", 611);
|
||||||
@@ -139,7 +137,6 @@ cache-persist no)""");
|
|||||||
EXPECT_EQ(client.GetAnswer()[1].GetData(), "4.5.6.7");
|
EXPECT_EQ(client.GetAnswer()[1].GetData(), "4.5.6.7");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(Cname, loop)
|
TEST_F(Cname, loop)
|
||||||
{
|
{
|
||||||
smartdns::MockServer server_upstream;
|
smartdns::MockServer server_upstream;
|
||||||
@@ -153,7 +150,6 @@ TEST_F(Cname, loop)
|
|||||||
if (request->domain == "s.a.com") {
|
if (request->domain == "s.a.com") {
|
||||||
smartdns::MockServer::AddIP(request, request->domain.c_str(), "4.5.6.7", 700);
|
smartdns::MockServer::AddIP(request, request->domain.c_str(), "4.5.6.7", 700);
|
||||||
return smartdns::SERVER_REQUEST_OK;
|
return smartdns::SERVER_REQUEST_OK;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
smartdns::MockServer::AddIP(request, request->domain.c_str(), "1.2.3.4", 611);
|
smartdns::MockServer::AddIP(request, request->domain.c_str(), "1.2.3.4", 611);
|
||||||
|
|||||||
@@ -220,7 +220,6 @@ cache-persist no)""");
|
|||||||
EXPECT_EQ(client.GetAnswer()[0].GetData(), "5.6.7.8");
|
EXPECT_EQ(client.GetAnswer()[0].GetData(), "5.6.7.8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(SpeedCheck, tcp_faster_than_ping)
|
TEST_F(SpeedCheck, tcp_faster_than_ping)
|
||||||
{
|
{
|
||||||
smartdns::MockServer server_upstream;
|
smartdns::MockServer server_upstream;
|
||||||
|
|||||||
Reference in New Issue
Block a user