Skip to content

Commit 3e48a94

Browse files
committed
dns_conf: server name support i18n
1 parent 9b57a83 commit 3e48a94

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

src/dns_conf/dns_conf.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "smartdns/dns_conf.h"
20+
#include "smartdns/lib/idna.h"
2021
#include "smartdns/tlog.h"
2122
#include "smartdns/util.h"
2223

@@ -121,8 +122,20 @@ static int _dns_conf_setup_mdns(void)
121122
return _conf_domain_rule_nameserver(DNS_SERVER_GROUP_LOCAL, DNS_SERVER_GROUP_MDNS);
122123
}
123124

125+
static int _config_server_name(void *data, int argc, char *argv[])
126+
{
127+
if (argc <= 1) {
128+
tlog(TLOG_ERROR, "invalid parameter.");
129+
return -1;
130+
}
131+
132+
utf8_to_punycode(argv[1], strlen(argv[1]), dns_conf.server_name, DNS_MAX_SERVER_NAME_LEN);
133+
134+
return 0;
135+
}
136+
124137
static struct config_item _config_item[] = {
125-
CONF_STRING("server-name", (char *)dns_conf.server_name, DNS_MAX_SERVER_NAME_LEN),
138+
CONF_CUSTOM("server-name", _config_server_name, NULL),
126139
CONF_YESNO("resolv-hostname", &dns_conf.resolv_hostname),
127140
CONF_CUSTOM("bind", _config_bind_ip_udp, NULL),
128141
CONF_CUSTOM("bind-tcp", _config_bind_ip_tcp, NULL),

src/dns_server/context.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,10 @@ int _dns_cache_reply_packet(struct dns_server_post_context *context)
995995
return 0;
996996
}
997997

998+
if (context->packet->head.rcode == DNS_RC_NXDOMAIN) {
999+
context->reply_ttl = 0;
1000+
}
1001+
9981002
return _dns_cache_packet(context);
9991003
}
10001004

src/dns_server/rules.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ int _dns_server_get_reply_ttl(struct dns_request *request, int ttl)
427427
int reply_ttl = ttl;
428428

429429
if ((request->passthrough == 0 || request->passthrough == 2) && dns_conf.cachesize > 0 &&
430-
request->check_order_list->orders[0].type != DOMAIN_CHECK_NONE) {
430+
request->check_order_list->orders[0].type != DOMAIN_CHECK_NONE && request->no_serve_expired == 0 && request->has_soa == 0) {
431431
reply_ttl = request->conf->dns_serve_expired_reply_ttl;
432432
if (reply_ttl < 2) {
433433
reply_ttl = 2;

test/cases/test-group.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ server 127.0.0.1:62053
615615
ASSERT_EQ(client.GetAuthorityNum(), 1);
616616
EXPECT_EQ(client.GetStatus(), "NXDOMAIN");
617617
EXPECT_EQ(client.GetAuthority()[0].GetName(), "a.com");
618-
EXPECT_EQ(client.GetAuthority()[0].GetTTL(), 3);
618+
EXPECT_EQ(client.GetAuthority()[0].GetTTL(), 600);
619619
EXPECT_EQ(client.GetAuthority()[0].GetType(), "SOA");
620620
}
621621

test/cases/test-hosts.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ hosts-file /tmp/*.hosts
148148
ASSERT_EQ(client.GetAnswerNum(), 0);
149149
EXPECT_EQ(client.GetStatus(), "NXDOMAIN");
150150
EXPECT_EQ(client.GetAuthority()[0].GetName(), "c.com");
151-
EXPECT_EQ(client.GetAuthority()[0].GetTTL(), 3);
151+
EXPECT_EQ(client.GetAuthority()[0].GetTTL(), 600);
152152
EXPECT_EQ(client.GetAuthority()[0].GetType(), "SOA");
153153

154154
ASSERT_TRUE(client.Query("d.com A", 60053));

test/cases/test-https.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ cache-persist no)""");
260260
ASSERT_EQ(client.GetAuthorityNum(), 1);
261261
EXPECT_EQ(client.GetStatus(), "NXDOMAIN");
262262
EXPECT_EQ(client.GetAuthority()[0].GetName(), "a.com");
263-
EXPECT_EQ(client.GetAuthority()[0].GetTTL(), 3);
263+
EXPECT_GT(client.GetAuthority()[0].GetTTL(), 595);
264264
EXPECT_EQ(client.GetAuthority()[0].GetType(), "SOA");
265265
}
266266

0 commit comments

Comments
 (0)