From 36ddca0491edf0c2d6bb9ec1a3a98fa6f42e46f6 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Wed, 6 Feb 2019 16:57:05 +0800 Subject: [PATCH] Add domain prefetch, fix ping issue --- package/luci/files/luci/i18n/smartdns.zh-cn.po | 6 ++++++ .../luci/files/luci/model/cbi/smartdns/smartdns.lua | 8 ++++++++ package/openwrt/files/etc/init.d/smartdns | 5 +++++ src/fast_ping.c | 11 +++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/package/luci/files/luci/i18n/smartdns.zh-cn.po b/package/luci/files/luci/i18n/smartdns.zh-cn.po index 9f85244..4a576a2 100644 --- a/package/luci/files/luci/i18n/smartdns.zh-cn.po +++ b/package/luci/files/luci/i18n/smartdns.zh-cn.po @@ -67,6 +67,12 @@ msgstr "双栈IP优选" msgid "Enable IP selection between IPV4 and IPV6" msgstr "启用或禁用IPV4,IPV6间的IP优选策略。" +msgid "Domain prefetch" +msgstr "域名预加载" + +msgid "Enable domain prefetch, accelerate domain response speed." +msgstr "启用域名预加载,加速域名响应速度。" + msgid "Redirect" msgstr "重定向" diff --git a/package/luci/files/luci/model/cbi/smartdns/smartdns.lua b/package/luci/files/luci/model/cbi/smartdns/smartdns.lua index 0822c41..6abdc6f 100644 --- a/package/luci/files/luci/model/cbi/smartdns/smartdns.lua +++ b/package/luci/files/luci/model/cbi/smartdns/smartdns.lua @@ -60,6 +60,14 @@ o.cfgvalue = function(...) return Flag.cfgvalue(...) or "0" end +---- Domain prefetch load +o = s:taboption("settings", Flag, "prefetch_domain", translate("Domain prefetch"), translate("Enable domain prefetch, accelerate domain response speed.")) +o.rmempty = false +o.default = o.disabled +o.cfgvalue = function(...) + return Flag.cfgvalue(...) or "0" +end + ---- Redirect o = s:taboption("settings", ListValue, "redirect", translate("Redirect"), translate("SmartDNS redirect mode")) o.placeholder = "none" diff --git a/package/openwrt/files/etc/init.d/smartdns b/package/openwrt/files/etc/init.d/smartdns index fba1f47..a9b3706 100644 --- a/package/openwrt/files/etc/init.d/smartdns +++ b/package/openwrt/files/etc/init.d/smartdns @@ -217,6 +217,11 @@ load_service() { conf_append "dualstack-ip-selection" "yes" fi + config_get "prefetch_domain" "$section" "prefetch_domain" "0" + if [ "$prefetch_domain" = "1" ]; then + conf_append "prefetch-domain" "yes" + fi + SMARTDNS_PORT="$port" config_get "cache_size" "$section" "cache_size" "" diff --git a/src/fast_ping.c b/src/fast_ping.c index 962fd57..ea338e3 100644 --- a/src/fast_ping.c +++ b/src/fast_ping.c @@ -351,6 +351,7 @@ static int _fast_ping_sendping_v6(struct ping_host_struct *ping_host) icmp6->icmp6_seq = htons(ping_host->seq); gettimeofday(&packet->msg.tv, 0); + gettimeofday(&ping_host->last, 0); packet->msg.sid = ping_host->sid; packet->msg.cookie = ping_host->cookie; packet->msg.seq = ping_host->seq; @@ -397,6 +398,7 @@ static int _fast_ping_sendping_v4(struct ping_host_struct *ping_host) icmp->icmp_seq = htons(ping_host->seq); gettimeofday(&packet->msg.tv, 0); + gettimeofday(&ping_host->last, 0); packet->msg.sid = ping_host->sid; packet->msg.seq = ping_host->seq; packet->msg.cookie = ping_host->cookie; @@ -447,6 +449,7 @@ static int _fast_ping_sendping_udp(struct ping_host_struct *ping_host) memset(&dns_head, 0, sizeof(dns_head)); dns_head.id = htons(ping_host->sid); dns_head.flag = flag; + gettimeofday(&ping_host->last, 0); len = sendto(fd, &dns_head, sizeof(dns_head), 0, (struct sockaddr *)&ping_host->addr, ping_host->addr_len); if (len < 0 || len != sizeof(dns_head)) { int err = errno; @@ -502,9 +505,10 @@ static int _fast_ping_sendping_tcp(struct ping_host_struct *ping_host) } } + gettimeofday(&ping_host->last, 0); ping_host->fd = fd; memset(&event, 0, sizeof(event)); - event.events = EPOLLIN | EPOLLOUT; + event.events = EPOLLIN | EPOLLOUT | EPOLLERR; event.data.ptr = ping_host; if (epoll_ctl(ping.epoll_fd, EPOLL_CTL_ADD, fd, &event) != 0) { ping_host->fd = -1; @@ -524,6 +528,7 @@ errout: static int _fast_ping_sendping(struct ping_host_struct *ping_host) { int ret = -1; + gettimeofday(&ping_host->last, 0); if (ping_host->type == FAST_PING_ICMP) { ret = _fast_ping_sendping_v4(ping_host); @@ -536,7 +541,6 @@ static int _fast_ping_sendping(struct ping_host_struct *ping_host) } ping_host->send = 1; - gettimeofday(&ping_host->last, 0); if (ret != 0) { return ret; @@ -1148,6 +1152,7 @@ static int _fast_ping_process_tcp(struct ping_host_struct *ping_host, struct epo if (getsockopt(ping_host->fd, SOL_SOCKET, SO_ERROR, (char *)&connect_error, &len) != 0) { goto errout; } + if (connect_error != 0 && connect_error != ECONNREFUSED) { goto errout; } @@ -1160,6 +1165,8 @@ static int _fast_ping_process_tcp(struct ping_host_struct *ping_host, struct epo ping_host->send = 0; + _fast_ping_close_host_sock(ping_host); + if (ping_host->count == 1) { _fast_ping_host_remove(ping_host); }