openwrt: save cache to disk when reboot system
This commit is contained in:
@@ -31,6 +31,9 @@ msgstr "绑定到设备"
|
||||
msgid "Bind Device Name"
|
||||
msgstr "绑定的设备名称"
|
||||
|
||||
msgid "Cache Persist"
|
||||
msgstr "持久化缓存"
|
||||
|
||||
msgid "Cache Size"
|
||||
msgstr "缓存大小"
|
||||
|
||||
@@ -502,6 +505,9 @@ msgstr ""
|
||||
"用于校验 TLS 服务器的有效性,数值为 Base64 编码的 SPKI 指纹,留空表示不验证 "
|
||||
"TLS 的合法性。"
|
||||
|
||||
msgid "Write cache to disk on exit and load on startup."
|
||||
msgstr "退出时保存cache到磁盘,启动时加载。"
|
||||
|
||||
msgid "domain list (/etc/smartdns/domain-set)"
|
||||
msgstr "域名列表(/etc/smartdns/domain-set)"
|
||||
|
||||
|
||||
@@ -161,6 +161,14 @@ end
|
||||
o = s:taboption("advanced", Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size"))
|
||||
o.rempty = true
|
||||
|
||||
---- cache-persist;
|
||||
o = s:taboption("advanced", Flag, "cache_persist", translate("Cache Persist"), translate("Write cache to disk on exit and load on startup."))
|
||||
o.rmempty = false;
|
||||
o.default = o.enabled;
|
||||
o.cfgvalue = function(...)
|
||||
return Flag.cfgvalue(...) or "1"
|
||||
end
|
||||
|
||||
-- cache-size
|
||||
o = s:taboption("advanced", Flag, "resolve_local_hostnames", translate("Resolve Local Hostnames"), translate("Resolve local hostnames by reading Dnsmasq lease file."))
|
||||
o.rmempty = false
|
||||
|
||||
@@ -37,6 +37,9 @@ msgstr "屏蔽域名"
|
||||
msgid "Block domain."
|
||||
msgstr "屏蔽域名。"
|
||||
|
||||
msgid "Cache Persist"
|
||||
msgstr "持久化缓存"
|
||||
|
||||
msgid "Cache Size"
|
||||
msgstr "缓存大小"
|
||||
|
||||
@@ -537,6 +540,9 @@ msgstr ""
|
||||
"用于校验 TLS 服务器的有效性,数值为 Base64 编码的 SPKI 指纹,留空表示不验证 "
|
||||
"TLS 的合法性。"
|
||||
|
||||
msgid "Write cache to disk on exit and load on startup."
|
||||
msgstr "退出时保存cache到磁盘,启动时加载。"
|
||||
|
||||
msgid "domain list (/etc/smartdns/domain-set)"
|
||||
msgstr "域名列表(/etc/smartdns/domain-set)"
|
||||
|
||||
|
||||
@@ -242,6 +242,11 @@ return view.extend({
|
||||
o = s.taboption("advanced", form.Value, "cache_size", _("Cache Size"), _("DNS domain result cache size"));
|
||||
o.rempty = true;
|
||||
|
||||
// cache-persist;
|
||||
o = s.taboption("advanced", form.Flag, "cache_persist", _("Cache Persist"), _("Write cache to disk on exit and load on startup."));
|
||||
o.rmempty = false;
|
||||
o.default = o.enabled;
|
||||
|
||||
// cache-size;
|
||||
o = s.taboption("advanced", form.Flag, "resolve_local_hostnames", _("Resolve Local Hostnames"), _("Resolve local hostnames by reading Dnsmasq lease file."));
|
||||
o.rmempty = false;
|
||||
|
||||
@@ -47,10 +47,13 @@ define Package/smartdns/conffiles
|
||||
/etc/smartdns/address.conf
|
||||
/etc/smartdns/blacklist-ip.conf
|
||||
/etc/smartdns/custom.conf
|
||||
/etc/smartdns/domain-block.list
|
||||
/etc/smartdns/domain-forwarding.list
|
||||
endef
|
||||
|
||||
define Package/smartdns/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/config $(1)/etc/init.d $(1)/etc/smartdns
|
||||
$(INSTALL_DIR) $(1)/etc/smartdns/conf.d $(1)/etc/smartdns/domain-set
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/smartdns $(1)/usr/sbin/smartdns
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/package/openwrt/files/etc/init.d/smartdns $(1)/etc/init.d/smartdns
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/package/openwrt/address.conf $(1)/etc/smartdns/address.conf
|
||||
|
||||
@@ -2,3 +2,5 @@
|
||||
/etc/smartdns/address.conf
|
||||
/etc/smartdns/blacklist-ip.conf
|
||||
/etc/smartdns/custom.conf
|
||||
/etc/smartdns/domain-block.list
|
||||
/etc/smartdns/domain-forwarding.list
|
||||
|
||||
@@ -19,4 +19,6 @@
|
||||
default_prerm $0 $@
|
||||
rm /var/etc/smartdns.conf -f
|
||||
rm /var/etc/smartdns/smartdns.conf -f
|
||||
rm /var/log/smartdns/ -fr
|
||||
rm /etc/smartdns/smartdns.cache -f
|
||||
exit 0
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
START=19
|
||||
STOP=82
|
||||
NAME=smartdns
|
||||
USE_PROCD=1
|
||||
SERVICE_USE_PID=1
|
||||
@@ -536,6 +537,19 @@ load_service()
|
||||
config_get bind_device_name "$section" "bind_device_name" "${lan_device}"
|
||||
[ ! -z "$bind_device_name" ] && [ "$bind_device" = "1" ] && device="${bind_device_name}"
|
||||
|
||||
config_get cache_file "$section" "cache_file" "$SMARTDNS_CONF_DIR/smartdns.cache"
|
||||
|
||||
config_get_bool cache_persist "$section" "cache_persist" "0"
|
||||
[ "$cache_persist" = "1" ] && {
|
||||
conf_append "cache-persist" "yes"
|
||||
conf_append "cache-file" "$cache_file"
|
||||
}
|
||||
|
||||
[ "$cache_persist" = "0" ] && {
|
||||
conf_append "cache-persist" "no"
|
||||
[ -f "$cache_file" ] && rm -f "$cache_file"
|
||||
}
|
||||
|
||||
config_get proxy_server "$section" "proxy_server" ""
|
||||
[ -z "$proxy_server" ] || conf_append "proxy-server" "$proxy_server -name default-proxy"
|
||||
|
||||
|
||||
@@ -4811,7 +4811,7 @@ static int _dns_server_tcp_process_one_request(struct dns_server_conn_tcp_client
|
||||
request_len = ntohs(*((unsigned short *)(request_data)));
|
||||
|
||||
if (request_len >= sizeof(tcpclient->recvbuff.buf)) {
|
||||
tlog(TLOG_ERROR, "request length is invalid.");
|
||||
tlog(TLOG_DEBUG, "request length is invalid.");
|
||||
return RECV_ERROR_FAIL;
|
||||
}
|
||||
|
||||
@@ -4864,7 +4864,7 @@ static int _dns_server_tcp_process_requests(struct dns_server_conn_tcp_client *t
|
||||
request_ret = _dns_server_tcp_process_one_request(tcpclient);
|
||||
if (request_ret < 0) {
|
||||
/* failed */
|
||||
tlog(TLOG_ERROR, "process one request failed.");
|
||||
tlog(TLOG_DEBUG, "process one request failed.");
|
||||
return RECV_ERROR_FAIL;
|
||||
}
|
||||
|
||||
|
||||
@@ -380,6 +380,7 @@ static int _smartdns_init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
const char *logfile = _smartdns_log_path();
|
||||
int i = 0;
|
||||
|
||||
ret = tlog_init(logfile, dns_conf_log_size, dns_conf_log_num, 0, 0);
|
||||
if (ret != 0) {
|
||||
@@ -401,11 +402,19 @@ static int _smartdns_init(void)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (dns_conf_server_num <= 0) {
|
||||
if (_smartdns_load_from_resolv() != 0) {
|
||||
tlog(TLOG_ERROR, "load dns from resolv failed.");
|
||||
goto errout;
|
||||
for (i = 0; i < 60 && dns_conf_server_num <= 0; i++) {
|
||||
ret = _smartdns_load_from_resolv();
|
||||
if (ret == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tlog(TLOG_DEBUG, "load dns from resolv failed, retry after 1s, retry times %d.", i + 1);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if (dns_conf_server_num <= 0) {
|
||||
tlog(TLOG_ERROR, "no dns server found, exit...");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = fast_ping_init();
|
||||
|
||||
Reference in New Issue
Block a user