Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa0ab28bab | ||
|
|
9bca51beaf | ||
|
|
1640e9e6a1 | ||
|
|
33ead3afbd | ||
|
|
1991a0b102 | ||
|
|
1f1fd118de | ||
|
|
8532205844 | ||
|
|
822f02bab9 | ||
|
|
d8c53a6215 | ||
|
|
e13a8c0ec5 | ||
|
|
7c4ce074a5 | ||
|
|
e6d533e2c5 | ||
|
|
7b3dcd31f9 | ||
|
|
0eef67c119 | ||
|
|
455924befe | ||
|
|
b75f7e14fe | ||
|
|
64e5b326cc | ||
|
|
f659cf3725 | ||
|
|
83c8105312 | ||
|
|
fecc313e03 | ||
|
|
145f7cfa42 | ||
|
|
464f2adaa7 | ||
|
|
7c9288f887 | ||
|
|
96d3deb595 | ||
|
|
584480dda1 | ||
|
|
2848aa0ac7 | ||
|
|
c156595f61 | ||
|
|
9dfe51c5ed |
143
ReadMe.md
143
ReadMe.md
@@ -258,92 +258,29 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|
||||
* 在 `Domain Address` 指定特定域名的 IP 地址,可用于广告屏蔽。
|
||||
|
||||
3. 启用服务
|
||||
|
||||
SmartDNS 服务生效方法有两种,一种是**直接作为主 DNS 服务**,另一种是**作为 DNSmasq 的上游**。
|
||||
默认情况下,SmartDNS 采用第一种方式。如下两种方式根据需求选择即可。
|
||||
|
||||
- **方法一:作为主 DNS 服务(默认方案)**
|
||||
|
||||
* 启用 SmartDNS 的 53 端口重定向
|
||||
|
||||
登录 OpenWrt 管理界面,点击 `Services` -> `SmartDNS` -> `redirect`,选择 `重定向 53 端口到 SmartDNS `启用 53 端口转发。
|
||||
|
||||
* 检测转发服务是否配置成功
|
||||
|
||||
执行
|
||||
|
||||
```shell
|
||||
$ nslookup -querytype=ptr smartdns
|
||||
* 替换默认Dndmasq为主DNS。
|
||||
|
||||
登录 OpenWrt 管理界面,点击 `Services` -> `SmartDNS` -> `port`,设置端口号为`53`,smartdns会自动接管主DNS服务器。
|
||||
|
||||
* 检测转发服务是否配置成功
|
||||
|
||||
执行
|
||||
|
||||
```shell
|
||||
$ nslookup -querytype=ptr smartdns
|
||||
```
|
||||
|
||||
查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效
|
||||
|
||||
```shell
|
||||
$ nslookup -querytype=ptr smartdns
|
||||
Server: 192.168.1.1
|
||||
Address: 192.168.1.1#53
|
||||
|
||||
Non-authoritative answer:
|
||||
smartdns name = smartdns.
|
||||
```
|
||||
|
||||
查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效
|
||||
|
||||
```shell
|
||||
$ nslookup -querytype=ptr smartdns
|
||||
Server: 192.168.1.1
|
||||
Address: 192.168.1.1#53
|
||||
|
||||
Non-authoritative answer:
|
||||
smartdns name = smartdns.
|
||||
```
|
||||
|
||||
* 界面提示重定向失败
|
||||
|
||||
* 检查 `iptables` 和/或 `ip6tables` 命令是否正确安装。
|
||||
|
||||
* OpenWrt 15.01 系统不支持 IPv6 重定向,如网络需要支持 IPv6,请将 DNSmasq 上游改为 SmartDNS,或者将 SmartDNS 的端口改为53,并停用 DNSmasq。
|
||||
|
||||
* LEDE 系统请安装 IPv6 的 NAT 转发驱动。点击 `System` -> `Software`,点击 `Update lists` 更新软件列表后,安装 `ip6tables-mod-nat`。
|
||||
|
||||
* 使用如下命令检查路由规则是否生效
|
||||
|
||||
```shell
|
||||
iptables -t nat -L PREROUTING | grep REDIRECT
|
||||
```
|
||||
|
||||
* 如转发功能不正常,请使用**方法二:作为 DNSmasq 的上游**。
|
||||
|
||||
- **方法二:作为 DNSmasq 的上游**
|
||||
|
||||
* **将 DNSmasq 的请求发送到 SmartDNS**
|
||||
|
||||
登录 OpenWrt 管理界面,点击 `Services` -> `SmartDNS` -> `Redirect`,选择`作为 DNSmasq 的上游服务器`,设置 DNSmasq 的上游服务器为 SmartDNS。
|
||||
|
||||
* **检测上游服务是否配置成功**
|
||||
|
||||
执行
|
||||
|
||||
```shell
|
||||
$ nslookup -querytype=ptr smartdns
|
||||
```
|
||||
|
||||
查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效
|
||||
|
||||
```shell
|
||||
$ nslookup -querytype=ptr smartdns
|
||||
Server: 192.168.1.1
|
||||
Address: 192.168.1.1#53
|
||||
|
||||
Non-authoritative answer:
|
||||
smartdns name = smartdns.
|
||||
```
|
||||
|
||||
或执行
|
||||
|
||||
```shell
|
||||
$ nslookup smartdns
|
||||
```
|
||||
|
||||
查看命令结果是否有解析出路由器的IP地址,如果是则表示生效。
|
||||
|
||||
或执行
|
||||
|
||||
```shell
|
||||
ping smartdns.
|
||||
```
|
||||
|
||||
检测ping是否解析对应主机的IP地址。
|
||||
|
||||
|
||||
4. 启动服务
|
||||
|
||||
@@ -352,7 +289,14 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|
||||
5. **注意:**
|
||||
|
||||
* 如已经安装 ChinaDNS,建议将 ChinaDNS 的上游配置为 SmartDNS。
|
||||
* SmartDNS 默认情况下将 53 端口的请求转发到 SmartDNS的 本地端口,此行为由 `Redirect` 配置选项控制。
|
||||
* 当smartdns的端口为53时,将自动接管dnsmasq为主dns。配置其他端口时,会重新启用dnsmasq为主dns。
|
||||
* 若在此过程中发生异常,可使用如下命令还原dnsmasq为主DNS
|
||||
|
||||
```shell
|
||||
uci delete dhcp.@dnsmasq[0].port
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
```
|
||||
|
||||
### 华硕路由器原生固件 / 梅林固件
|
||||
|
||||
@@ -563,6 +507,7 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|
||||
| rr-ttl-min | 允许的最小 TTL 值 | 远程查询结果 | 大于 0 的数字 | rr-ttl-min 60 |
|
||||
| rr-ttl-max | 允许的最大 TTL 值 | 远程查询结果 | 大于 0 的数字 | rr-ttl-max 600 |
|
||||
| rr-ttl-reply-max | 允许返回给客户端的最大 TTL 值 | 远程查询结果 | 大于 0 的数字 | rr-ttl-reply-max 60 |
|
||||
| local-ttl | 本地HOST,address的TTL值 | rr-ttl-min | 大于 0 的数字 | local-ttl 60 |
|
||||
| max-reply-ip-num | 允许返回给客户的最大IP数量 | IP数量 | 大于 0 的数字 | max-reply-ip-num 1 |
|
||||
| log-level | 设置日志级别 | error | fatal、error、warn、notice、info 或 debug | log-level error |
|
||||
| log-file | 日志文件路径 | /var/log/smartdns/smartdns.log | 合法路径字符串 | log-file /var/log/smartdns/smartdns.log |
|
||||
@@ -578,12 +523,13 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|
||||
| server-tls | 上游 TLS DNS | 无 | 可重复。<br>[ip][:port]:服务器 IP:端口(可选)<br>[-spki-pin [sha256-pin]]:TLS 合法性校验 SPKI 值,base64 编码的 sha256 SPKI pin 值<br>[-host-name]:TLS SNI 名称<br>[-tls-host-verify]:TLS 证书主机名校验<br> [-no-check-certificate]:跳过证书校验<br>[-blacklist-ip]:配置 IP 过滤结果<br>[-whitelist-ip]:仅接受参数中配置的 IP 范围<br>[-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br>[-exclude-default-group]:将 DNS 服务器从默认组中排除 | server-tls 8.8.8.8:853 |
|
||||
| server-https | 上游 HTTPS DNS | 无 | 可重复。<br>https://[host][:port]/path:服务器 IP:端口(可选)<br>[-spki-pin [sha256-pin]]:TLS 合法性校验 SPKI 值,base64 编码的 sha256 SPKI pin 值<br>[-host-name]:TLS SNI 名称<br>[-http-host]:http 协议头主机名<br>[-tls-host-verify]:TLS 证书主机名校验<br> [-no-check-certificate]:跳过证书校验<br>[-blacklist-ip]:配置 IP 过滤结果<br>[-whitelist-ip]:仅接受参数中配置的 IP 范围。<br>[-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br>[-exclude-default-group]:将 DNS 服务器从默认组中排除 | server-https https://cloudflare-dns.com/dns-query |
|
||||
| speed-check-mode | 测速模式选择 | 无 | [ping\|tcp:[80]\|none] | speed-check-mode ping,tcp:80,tcp:443 |
|
||||
| response-mode | 首次查询响应模式 | first-ping |模式:[fisrt-ping\|fastest-ip\|first-response]<br> [first-ping]: 最快ping响应地址模式,DNS上游最快查询时延+ping时延最短,查询等待与链接体验最佳;<br>[fastest-ip]: 最快IP地址模式,查询到的所有IP地址中ping最短的IP。需等待IP测速; <br>[first-response]: 最快响应的DNS结果,DNS查询等待时间最短,返回的IP地址可能不是最快。| response-mode first-ping |
|
||||
| response-mode | 首次查询响应模式 | first-ping |模式:[fisrt-ping\|fastest-ip\|fastest-response]<br> [first-ping]: 最快ping响应地址模式,DNS上游最快查询时延+ping时延最短,查询等待与链接体验最佳;<br>[fastest-ip]: 最快IP地址模式,查询到的所有IP地址中ping最短的IP。需等待IP测速; <br>[fastest-response]: 最快响应的DNS结果,DNS查询等待时间最短,返回的IP地址可能不是最快。| response-mode first-ping |
|
||||
| address | 指定域名 IP 地址 | 无 | address /domain/[ip\|-\|-4\|-6\|#\|#4\|#6] <br>- 表示忽略 <br># 表示返回 SOA <br>4 表示 IPv4 <br>6 表示 IPv6 | address /www.example.com/1.2.3.4 |
|
||||
| nameserver | 指定域名使用 server 组解析 | 无 | nameserver /domain/[group\|-], group 为组名,- 表示忽略此规则,配套 server 中的 -group 参数使用 | nameserver /www.example.com/office |
|
||||
| ipset | 域名 ipset | 无 | ipset /domain/[ipset\|-\|#[4\|6]:[ipset\|-][,#[4\|6]:[ipset\|-]]],-表示忽略 | ipset /www.example.com/#4:dns4,#6:- |
|
||||
| ipset-timeout | 设置 ipset 超时功能启用 | 自动 | [yes] | ipset-timeout yes |
|
||||
| domain-rules | 设置域名规则 | 无 | domain-rules /domain/ [-rules...]<br>[-c\|-speed-check-mode]:测速模式,参考 speed-check-mode 配置<br>[-a\|-address]:参考 address 配置<br>[-n\|-nameserver]:参考 nameserver 配置<br>[-p\|-ipset]:参考ipset配置<br>[-d\|-dualstack-ip-selection]:参考 dualstack-ip-selection | domain-rules /www.example.com/ -speed-check-mode none |
|
||||
| domain-set | 设置域名集合 | 无 | domain-set [options...]<br>[-n\|-name]:域名集合名称 <br>[-t\|-type]:域名集合类型,当前仅支持list,格式为域名列表,一行一个域名。<br>[-f\|-file]:域名集合文件路径。<br> 选项需要配合address, nameserver, ipset等需要指定域名的地方使用,使用方式为 /domain-set:[name]/| domain-set -name set -type list -file /path/to/list <br> address /domain-set:set/1.2.4.8 |
|
||||
| bogus-nxdomain | 假冒 IP 地址过滤 | 无 | [ip/subnet],可重复 | bogus-nxdomain 1.2.3.4/16 |
|
||||
| ignore-ip | 忽略 IP 地址 | 无 | [ip/subnet],可重复 | ignore-ip 1.2.3.4/16 |
|
||||
| whitelist-ip | 白名单 IP 地址 | 无 | [ip/subnet],可重复 | whitelist-ip 1.2.3.4/16 |
|
||||
@@ -752,6 +698,31 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|
||||
|
||||
* Windows系统默认使用mDNS解析地址,如需要在windows下用使用smartdns解析,则需要在主机名后面增加`.`,表示使用DNS解析。如`ping smartdns.`
|
||||
|
||||
13. 域名集合如何使用?
|
||||
为方便按集合配置域名,对于有/domain/的配置,可以指定域名集合,方便维护。具体方法为:
|
||||
|
||||
* 使用`domain-set`配置集合文件,如
|
||||
|
||||
```sh
|
||||
domain-set -name ad -file /etc/smartdns/ad-list.conf
|
||||
```
|
||||
|
||||
ad-list.conf的格式为一个域名一行,如
|
||||
|
||||
```
|
||||
ad.com
|
||||
site.com
|
||||
```
|
||||
|
||||
* 在有/domain/配置的选项使用域名集合,只需要将`/domain/`配置为`/domain-set:[集合名称]/`即可,如:
|
||||
|
||||
```sh
|
||||
address /domain-set:ad/#
|
||||
domain-rules /domain-set:ad/ -a #
|
||||
nameserver /domain-set:ad/server
|
||||
...
|
||||
```
|
||||
|
||||
## 编译
|
||||
|
||||
SmartDNS 提供了编译软件包的脚本(`package/build-pkg.sh`),支持编译 LuCI、Debian、OpenWrt 和 Optware 安装包。
|
||||
|
||||
97
ReadMe_en.md
97
ReadMe_en.md
@@ -240,11 +240,11 @@ https://github.com/pymumu/smartdns/releases
|
||||
There are two ways to use the SmartDNS service, `one is directly as the primary DNS service`, `the other is as the upstream of dnsmasq`.
|
||||
By default, SmartDNS uses the first method. You can choose according to your needs in the following two ways.
|
||||
|
||||
1. Method 1: SmartDNS as primary DNS Server (default scheme)
|
||||
1. Method 1: SmartDNS as primary DNS Server
|
||||
|
||||
* **Enable SmartDNS port 53 port redirection**
|
||||
* **Enable SmartDNS as primary DNS Server**
|
||||
|
||||
Log in to the router, click on `Services`->`SmartDNS`->`redirect`, select `Redirect 53 port to SmartDNS` option to enable port 53 forwarding.
|
||||
Log in to the router, click on `Services`->`SmartDNS`->`port`, input port `53`, smartdns will run as primary DNS Server.
|
||||
|
||||
* **Check if the service is configured successfully**
|
||||
|
||||
@@ -260,54 +260,20 @@ https://github.com/pymumu/smartdns/releases
|
||||
smartdns name = smartdns.
|
||||
```
|
||||
|
||||
* **The interface prompts that the redirect failed**
|
||||
|
||||
* Check if iptable, ip6table command is installed correctly.
|
||||
* The openwrt 15.01 system does not support IPV6 redirection. If the network needs to support IPV6, please change DNSMASQ upstream to smartdns, or change the smartdns port to 53, and disable dnsmasq.
|
||||
* After LEDE system, please install IPV6 nat forwarding driver. Click `system`->`Software`, click `update lists` to update the software list, install `ip6tables-mod-nat`
|
||||
* Use the following command to check whether the routing rule takes effect.
|
||||
|
||||
```shell
|
||||
iptables -t nat -L PREROUTING | grep REDIRECT
|
||||
```
|
||||
|
||||
* If the forwarding function is abnormal, please use Method 2: As the upstream of DNSMASQ.
|
||||
|
||||
1. Method 2: SmartDNS as upstream DNS Server of DNSMASQ
|
||||
|
||||
* **Forward dnsmasq's request to SmartDNS**
|
||||
|
||||
Log in to the router, click on `Services`->`SmartDNS`->`redirect`, select `Run as dnsmasq upstream server` option to forwarding dnsmasq request to Smartdns.
|
||||
|
||||
* **Check if the service is configured successfully**
|
||||
|
||||
* Query domain name with `nslookup -querytype=ptr 0.0.0.1`
|
||||
See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns`
|
||||
|
||||
```shell
|
||||
pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns
|
||||
Server: 192.168.1.1
|
||||
Address: 192.168.1.1#53
|
||||
|
||||
Non-authoritative answer:
|
||||
smartdns name = smartdns.
|
||||
```
|
||||
|
||||
* or Query doman name `smartdns `with `nslookup smartdns`
|
||||
```shell
|
||||
$ nslookup smartdns
|
||||
```
|
||||
|
||||
Check whether the command result resolves the IP address of the router, if so, it means it is working.
|
||||
|
||||
1. Start Service
|
||||
|
||||
Check the `Enable' in the configuration page to start SmartDNS server.
|
||||
|
||||
1. Note
|
||||
|
||||
* If chinaDNS is already installed, it is recommended to configure the upstream of chinaDNS as SmartDNS.
|
||||
* SmartDNS defaults to forwarding port 53 requests to the local port of SmartDNS, controlled by the `Redirect` configuration option.
|
||||
* When the port of smartdns is 53, it will automatically take over dnsmasq as the primary dns. When configuring other ports, dnsmasq is re-enabled as primary dns.
|
||||
* If an exception occurs during this process, you can use the following command to restore dnsmasq as the primary DNS
|
||||
|
||||
```shell
|
||||
uci delete dhcp.@dnsmasq[0].port
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
```
|
||||
|
||||
### ASUS router native firmware / Merlin firmware
|
||||
|
||||
@@ -497,6 +463,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
|tcp-idle-time|TCP connection idle timeout|120|integer|tcp-idle-time 120
|
||||
|rr-ttl|Domain name TTL|Remote query result|number greater than 0|rr-ttl 600
|
||||
|rr-ttl-min|Domain name Minimum TTL|Remote query result|number greater than 0|rr-ttl-min 60
|
||||
|local-ttl|ttl for address and host|rr-ttl-min|number greater than 0|local-ttl 600
|
||||
|rr-ttl-reply-max|Domain name Minimum Reply TTL|Remote query result|number greater than 0|rr-ttl-reply-max 60
|
||||
|rr-ttl-max|Domain name Maximum TTL|Remote query result|number greater than 0|rr-ttl-max 600
|
||||
|max-reply-ip-num|Maximum number of IPs returned to the client|8|number of IPs, 1~16 |max-reply-ip-num 1
|
||||
@@ -514,12 +481,13 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
|server-tls|Upstream TLS DNS server|None|Repeatable <br>`[ip][:port]`: Server IP, port optional. <br>`[-spki-pin [sha256-pin]]`: TLS verify SPKI value, a base64 encoded SHA256 hash<br>`[-host-name]`:TLS Server name. <br>`[-tls-host-verify]`: TLS cert hostname to verify. <br>`-no-check-certificate:`: No check certificate. <br>`[-blacklist-ip]`: The "-blacklist-ip" parameter is to filtering IPs which is configured by "blacklist-ip". <br>`[-whitelist-ip]`: whitelist-ip parameter specifies that only the IP range configured in whitelist-ip is accepted. <br>`[-group [group] ...]`: The group to which the DNS server belongs, such as office, foreign, use with nameserver. <br>`[-exclude-default-group]`: Exclude DNS servers from the default group| server-tls 8.8.8.8:853
|
||||
|server-https|Upstream HTTPS DNS server|None|Repeatable <br>`https://[host][:port]/path`: Server IP, port optional. <br>`[-spki-pin [sha256-pin]]`: TLS verify SPKI value, a base64 encoded SHA256 hash<br>`[-host-name]`:TLS Server name<br>`[-http-host]`:http header host. <br>`[-tls-host-verify]`: TLS cert hostname to verify. <br>`-no-check-certificate:`: No check certificate. <br>`[-blacklist-ip]`: The "-blacklist-ip" parameter is to filtering IPs which is configured by "blacklist-ip". <br>`[-whitelist-ip]`: whitelist-ip parameter specifies that only the IP range configured in whitelist-ip is accepted. <br>`[-group [group] ...]`: The group to which the DNS server belongs, such as office, foreign, use with nameserver. <br>`[-exclude-default-group]`: Exclude DNS servers from the default group| server-https https://cloudflare-dns.com/dns-query
|
||||
|speed-check-mode|Speed mode|None|[ping\|tcp:[80]\|none]|speed-check-mode ping,tcp:80,tcp:443
|
||||
|response-mode|First query response mode|first-ping|Mode: [fisrt-ping\|fastest-ip\|first-response]<br> [first-ping]: The fastest dns + ping response mode, DNS query delay + ping delay is the shortest;<br>[fastest-ip]: The fastest IP address mode, return the fastest ip address, may take some time to test speed. <br>[first-response]: The fastest response DNS result mode, the DNS query waiting time is the shortest. | response-mode first-ping |
|
||||
|response-mode|First query response mode|first-ping|Mode: [fisrt-ping\|fastest-ip\|fastest-response]<br> [first-ping]: The fastest dns + ping response mode, DNS query delay + ping delay is the shortest;<br>[fastest-ip]: The fastest IP address mode, return the fastest ip address, may take some time to test speed. <br>[fastest-response]: The fastest response DNS result mode, the DNS query waiting time is the shortest. | response-mode first-ping |
|
||||
|address|Domain IP address|None|address /domain/[ip\|-\|-4\|-6\|#\|#4\|#6], `-` for ignore, `#` for return SOA, `4` for IPV4, `6` for IPV6| address /www.example.com/1.2.3.4
|
||||
|nameserver|To query domain with specific server group|None|nameserver /domain/[group\|-], `group` is the group name, `-` means ignore this rule, use the `-group` parameter in the related server|nameserver /www.example.com/office
|
||||
|ipset|Domain IPSet|None|ipset /domain/[ipset\|-\|#[4\|6]:[ipset\|-][,#[4\|6]:[ipset\|-]]], `-` for ignore|ipset /www.example.com/#4:dns4,#6:-
|
||||
|ipset-timeout|ipset timeout enable|auto|[yes]|ipset-timeout yes
|
||||
|domain-rules|set domain rules|None|domain-rules /domain/ [-rules...]<br>`[-c\|-speed-check-mode]`: set speed check mode,same as parameter `speed-check-mode`<br>`[-a\|-address]`: same as parameter `address` <br>`[-n\|-nameserver]`: same as parameter `nameserver`<br>`[-p\|-ipset]`: same as parameter `ipset`<br>`[-d\|-dualstack-ip-selection]`: same as parameter `dualstack-ip-selection`|domain-rules /www.example.com/ -speed-check-mode none
|
||||
| domain-set | collection of domains|None| domain-set [options...]<br>[-n\|-name]:name of set <br>[-t\|-type] [list]: set type, only support list, one domain per line <br>[-f\|-file]:file path of domain set<br> used with address, nameserver, ipset, example: /domain-set:[name]/ | domain-set -name set -type list -file /path/to/list <br> address /domain-set:set/1.2.4.8 |
|
||||
|bogus-nxdomain|bogus IP address|None|[IP/subnet], Repeatable| bogus-nxdomain 1.2.3.4/16
|
||||
|ignore-ip|ignore ip address|None|[ip/subnet], Repeatable| ignore-ip 1.2.3.4/16
|
||||
|whitelist-ip|ip whitelist|None|[ip/subnet], Repeatable,When the filtering server responds IPs in the IP whitelist, only result in whitelist will be accepted| whitelist-ip 1.2.3.4/16
|
||||
@@ -567,13 +535,13 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
1. How to enable the audit log
|
||||
The audit log records the domain name requested by the client. The record information includes the request time, the request IP address, the request domain name, and the request type. If you want to enable the audit log, configure `audit-enable yes` in the configuration file, `audit-size`, `Audit-file`, `audit-num` configure the audit log file size, the audit log file path, and the number of audit log files. The audit log file will be compressed to save space.
|
||||
|
||||
1. How to avoid DNS privacy leaks
|
||||
1. How to avoid DNS privacy leaks
|
||||
By default, smartdns will send requests to all configured DNS servers. If the upstream DNS servers record DNS logs, it will result in a DNS privacy leak. To avoid privacy leaks, try the following steps:
|
||||
* Use trusted DNS servers.
|
||||
* Use TLS servers.
|
||||
* Set up an upstream DNS server group.
|
||||
|
||||
1. How to block ads
|
||||
1. How to block ads
|
||||
Smartdns has a high-performance domain name matching algorithm. It is very efficient to filter advertisements by domain name. To block ads, you only need to configure records like the following configure. For example, if you block `*.ad.com`, configure as follows:
|
||||
|
||||
```sh
|
||||
@@ -586,7 +554,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
Address /pass.ad.com/-
|
||||
```
|
||||
|
||||
1. DNS query diversion
|
||||
1. DNS query diversion
|
||||
In some cases, some domain names need to be queried using a specific DNS server to do DNS diversion. such as.
|
||||
|
||||
```sh
|
||||
@@ -653,24 +621,49 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
echo | openssl s_client -connect '1.0.0.1:853' 2>/dev/null | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
|
||||
```
|
||||
|
||||
1. How to solve the problem of slow DNS resolution in iOS system?
|
||||
1. How to solve the problem of slow DNS resolution in iOS system?
|
||||
Since iOS14, Apple has supported the resolution of DNS HTTPS (TYPE65) records. This function is used for solving problems related to HTTPS connections, but it is still a draft, and it will cause some functions such as adblocking fail. It is recommended to disable it through the following configuration.
|
||||
|
||||
```sh
|
||||
force-qtype-SOA 65
|
||||
```
|
||||
|
||||
1. How to resolve localhost ip by hostname?
|
||||
1. How to resolve localhost ip by hostname?
|
||||
smartdns can cooperate with the dhcp server of DNSMASQ to support the resolution of local host name to IP address. You can configure smartdns to read the lease file of dnsmasq and support the resolution. The specific configuration parameters are as follows, (note that the DNSMASQ lease file may be different for each system and needs to be configured according to the actual situation)
|
||||
|
||||
```sh
|
||||
dnsmasq-lease-file /var/lib/misc/dnsmasq.leases
|
||||
````\
|
||||
```
|
||||
|
||||
After the configuration is complete, you can directly use the host name to connect to the local machine. But need to pay attention:
|
||||
|
||||
* Windows system uses mDNS to resolve addresses by default. If you need to use smartdns to resolve addresses under Windows, you need to add `.` after the host name, indicating that DNS resolution is used. Such as `ping smartdns.`
|
||||
|
||||
1. How to use the domain set?
|
||||
To facilitate configuring domain names by set, for configurations with /domain/, you can specify a domain name set for easy maintenance. The specific method is:
|
||||
|
||||
* Use `domain-set` configuration domain set file:
|
||||
|
||||
````sh
|
||||
domain-set -name ad -file /etc/smartdns/ad-list.conf
|
||||
````
|
||||
|
||||
The format of ad-list.conf is one domain per line:
|
||||
|
||||
````
|
||||
ad.com
|
||||
site.com
|
||||
````
|
||||
|
||||
* To use the domain set, you only need to configure `/domain/` to `/domain-set:[collection name]/`, such as:
|
||||
|
||||
````sh
|
||||
address /domain-set:ad/#
|
||||
domain-rules /domain-set:ad/ -a #
|
||||
nameserver /domain-set:ad/server
|
||||
...
|
||||
````
|
||||
|
||||
## Compile
|
||||
|
||||
smartdns contains scripts for compiling packages, supports compiling luci, debian, openwrt, opare installation packages, and can execute `package/build-pkg.sh` compilation.
|
||||
|
||||
@@ -219,3 +219,17 @@ log-level info
|
||||
# [-n] -nameserver [group|-]: same as nameserver option
|
||||
# [-p] -ipset [ipset|-]: same as ipset option
|
||||
# [-d] -dualstack-ip-selection [yes|no]: same as dualstack-ip-selection option
|
||||
|
||||
# collection of domains
|
||||
# the domain-set can be used with /domain/ for address, nameserver, ipset, etc.
|
||||
# domain-set -name [set-name] -type list -file [/path/to/file]
|
||||
# [-n] -name [set name]: domain set name
|
||||
# [-t] -type [list]: domain set type, list only now
|
||||
# [-f] -file [path/to/set]: file path of domain set
|
||||
#
|
||||
# example:
|
||||
# domain-set -name domain-list -type list -file /etc/smartdns/domain-list.conf
|
||||
# address /domain-set:domain-list/1.2.3.4
|
||||
# nameserver /domain-set:domain-list/server-group
|
||||
# ipset /domain-set:domain-list/ipset
|
||||
# domain-rules /domain-set:domain-list/ -speed-check-mode ping
|
||||
|
||||
@@ -187,7 +187,7 @@ init_dir()
|
||||
which systemctl >/dev/null 2>&1
|
||||
ISSYSTEMD="$?"
|
||||
# Running under WSL (Windows Subsystem for Linux)?
|
||||
cat /proc/version | grep Microsoft >/dev/null 2>&1;
|
||||
cat /proc/version | grep -E '[Mm]icrosoft' >/dev/null 2>&1;
|
||||
if [ $? -eq 0 ]; then
|
||||
ISSYSTEMD=1
|
||||
ISWSL=0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Package: luci-app-smartdns
|
||||
Version: git-18.201.27126-7bf0367-1
|
||||
Depends: libc, smartdns
|
||||
Depends: libc, smartdns, luci-compat
|
||||
Source: feeds/luci/applications/luci-app-smartdns
|
||||
Section: luci
|
||||
Architecture: all
|
||||
|
||||
@@ -38,46 +38,20 @@ end
|
||||
function act_status()
|
||||
local e={}
|
||||
local ipv6_server;
|
||||
local redirect_mode="none";
|
||||
|
||||
e.ipv6_works = 2;
|
||||
e.ipv4_works = 2;
|
||||
e.ipv6_server = 1;
|
||||
e.dnsmasq_forward = 0;
|
||||
redirect_mode = smartdns.get_config_option("smartdns", "smartdns", "redirect", nil);
|
||||
if redirect_mode == "redirect" then
|
||||
e.redirect = 1
|
||||
elseif redirect_mode == "dnsmasq-upstream" then
|
||||
e.redirect = 2
|
||||
else
|
||||
e.redirect = 0
|
||||
end
|
||||
|
||||
local dnsmasq_server = luci.sys.exec("uci get dhcp.@dnsmasq[0].server")
|
||||
local auto_set_dnsmasq = smartdns.get_config_option("smartdns", "smartdns", "auto_set_dnsmasq", nil);
|
||||
|
||||
e.auto_set_dnsmasq = auto_set_dnsmasq
|
||||
e.dnsmasq_server = dnsmasq_server
|
||||
e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
|
||||
ipv6_server = smartdns.get_config_option("smartdns", "smartdns", "ipv6_server", nil);
|
||||
if e.redirect == 1 then
|
||||
if e.local_port ~= nil and e.local_port ~= "53" then
|
||||
e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING 2>/dev/null | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
||||
if ipv6_server == "1" then
|
||||
e.ipv6_works = luci.sys.call("ip6tables -t nat -nL PREROUTING 2>/dev/null| grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
||||
else
|
||||
e.ipv6_works = 2
|
||||
end
|
||||
else
|
||||
e.redirect = 0
|
||||
end
|
||||
elseif e.redirect == 2 then
|
||||
if e.local_port ~= nil and e.local_port ~= "53" and auto_set_dnsmasq ~= nil and auto_set_dnsmasq == "1" then
|
||||
local str;
|
||||
local dnsmasq_server = luci.sys.exec("uci get dhcp.@dnsmasq[0].server")
|
||||
if e.local_port ~= nil then
|
||||
str = "127.0.0.1#" .. e.local_port
|
||||
if string.sub(dnsmasq_server,1,string.len(str)) == str then
|
||||
e.dnsmasq_forward = 1
|
||||
end
|
||||
str = "127.0.0.1#" .. e.local_port
|
||||
if string.sub(dnsmasq_server,1,string.len(str)) ~= str then
|
||||
e.dnsmasq_redirect_failure = 1
|
||||
end
|
||||
end
|
||||
e.running = is_running()
|
||||
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
@@ -1,302 +1,352 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "SmartDNS"
|
||||
msgstr "SmartDNS"
|
||||
msgid "Additional Args for upstream dns servers"
|
||||
msgstr "额外的上游 DNS 服务器参数"
|
||||
|
||||
msgid "SmartDNS is a local high-performance DNS server"
|
||||
msgstr "SmartDNS是一个本地高性能DNS服务器"
|
||||
|
||||
msgid "SmartDNS Server"
|
||||
msgstr "SmartDNS 服务器"
|
||||
|
||||
msgid "SmartDNS is a local high-performance DNS server, supports finding fastest IP, supports ad filtering, and supports avoiding DNS poisoning."
|
||||
msgstr "SmartDNS是一个本地高性能DNS服务器,支持返回最快IP,支持广告过滤。"
|
||||
|
||||
msgid "Custom Settings"
|
||||
msgstr "自定义设置"
|
||||
|
||||
msgid "General Settings"
|
||||
msgstr "基本设置"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "设置"
|
||||
msgid "Additional Server Args"
|
||||
msgstr "额外的服务器参数"
|
||||
|
||||
msgid "Advanced Settings"
|
||||
msgstr "高级设置"
|
||||
|
||||
msgid "Generate Coredump"
|
||||
msgstr "生成coredump"
|
||||
|
||||
msgid "Generate Coredump file when smartdns crash, coredump file is located at /tmp/smartdns.xxx.core."
|
||||
msgstr "当smartdns异常时生成coredump文件,coredump文件在/tmp/smartdns.xxx.core."
|
||||
|
||||
msgid "Server Name"
|
||||
msgstr "服务器名称"
|
||||
|
||||
msgid "Smartdns server name"
|
||||
msgstr "SmartDNS的服务器名称,默认为smartdns,留空为主机名"
|
||||
|
||||
msgid "SmartDNS is a local dns server to find fastest ip."
|
||||
msgstr "本地高性能服务器,优化网络访问性能。"
|
||||
|
||||
msgid "Enable or disable smartdns server"
|
||||
msgstr "启用或禁用SmartDNS服务"
|
||||
|
||||
msgid "Local Port"
|
||||
msgstr "本地端口"
|
||||
|
||||
msgid "Smartdns local server port"
|
||||
msgstr "SmartDNS本地服务端口"
|
||||
|
||||
msgid "IPV4 53 Port Redirect Failure"
|
||||
msgstr "IPV4 53端口重定向失败"
|
||||
|
||||
msgid "IPV6 53 Port Redirect Failure"
|
||||
msgstr "IPV6 53端口重定向失败"
|
||||
|
||||
msgid "Dnsmasq Forwared To Smartdns Failure"
|
||||
msgstr "重定向dnsmasq到smartdns失败"
|
||||
|
||||
msgid "TCP Server"
|
||||
msgstr "TCP服务器"
|
||||
|
||||
msgid "Enable TCP DNS Server"
|
||||
msgstr "启用TCP服务器"
|
||||
|
||||
msgid "IPV6 Server"
|
||||
msgstr "IPV6服务器"
|
||||
|
||||
msgid "Enable IPV6 DNS Server"
|
||||
msgstr "启用IPV6服务器"
|
||||
|
||||
msgid "Dual-stack IP Selection"
|
||||
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 "Serve expired"
|
||||
msgstr "过期缓存服务"
|
||||
|
||||
msgid "Attempts to serve old responses from cache with a TTL of 0 in the response without waiting for the actual resolution to finish."
|
||||
msgid ""
|
||||
"Attempts to serve old responses from cache with a TTL of 0 in the response "
|
||||
"without waiting for the actual resolution to finish."
|
||||
msgstr "查询性能优化,有请求时尝试回应TTL为0的过期记录,以避免查询等待。"
|
||||
|
||||
msgid "Redirect"
|
||||
msgstr "重定向"
|
||||
msgid "Automatically Set Dnsmasq"
|
||||
msgstr "自动设置Dnsmasq"
|
||||
|
||||
msgid "SmartDNS redirect mode"
|
||||
msgstr "SmartDNS 重定向模式"
|
||||
|
||||
msgid "Run as dnsmasq upstream server"
|
||||
msgstr "作为dnsmasq的上游服务器"
|
||||
|
||||
msgid "Redirect 53 port to SmartDNS"
|
||||
msgstr "重定向53端口到SmartDNS"
|
||||
msgid "Automatically set as upstream of dnsmasq when port changes."
|
||||
msgstr "自动设置为Dnsmasq的上游服务器"
|
||||
|
||||
msgid "Cache Size"
|
||||
msgstr "缓存大小"
|
||||
|
||||
msgid "Collecting data ..."
|
||||
msgstr "正在收集数据..."
|
||||
|
||||
msgid ""
|
||||
"Configure IP blacklists that will be filtered from the results of specific "
|
||||
"DNS server."
|
||||
msgstr "配置需要从指定域名服务器结果过滤的IP黑名单。"
|
||||
|
||||
msgid "Custom Settings"
|
||||
msgstr "自定义设置"
|
||||
|
||||
msgid "DNS Server Name"
|
||||
msgstr "DNS服务器名称"
|
||||
|
||||
msgid ""
|
||||
"DNS Server group belongs to, used with nameserver, such as office, home."
|
||||
msgstr "DNS服务器所属组, 配合nameserver使用,例如:office,home。"
|
||||
|
||||
msgid "DNS Server ip"
|
||||
msgstr "DNS服务器IP"
|
||||
|
||||
msgid "DNS Server port"
|
||||
msgstr "DNS服务器端口"
|
||||
|
||||
msgid "DNS Server type"
|
||||
msgstr "协议类型"
|
||||
|
||||
msgid "DNS domain result cache size"
|
||||
msgstr "缓存DNS的结果,缓存大小,配置零则不缓存(单位:条)"
|
||||
msgstr "缓存DNS的结果,缓存大小,配置零则不缓存"
|
||||
|
||||
msgid "Domain TTL"
|
||||
msgstr "域名TTL"
|
||||
msgid "Dnsmasq Forwared To Smartdns Failure"
|
||||
msgstr "重定向dnsmasq到smartdns失败"
|
||||
|
||||
msgid "TTL for all domain result."
|
||||
msgstr "设置所有域名的TTL值(单位:秒,下同)"
|
||||
|
||||
msgid "Domain TTL Min"
|
||||
msgstr "域名TTL最小值"
|
||||
|
||||
msgid "Minimum TTL for all domain result."
|
||||
msgstr "设置所有域名的TTL最小值"
|
||||
|
||||
msgid "Domain TTL Max"
|
||||
msgstr "域名TTL最大值"
|
||||
|
||||
msgid "Maximum TTL for all domain result."
|
||||
msgstr "设置所有域名的TTL最大值"
|
||||
|
||||
msgid "Maximum Reply TTL for all domain result."
|
||||
msgstr "设置返回给客户端的TTL最大值"
|
||||
|
||||
msgid "smartdns custom settings"
|
||||
msgstr "smartdns 自定义设置,具体配置参数参考指导"
|
||||
|
||||
msgid "Second Server Settings"
|
||||
msgstr "第二DNS服务器"
|
||||
|
||||
msgid "Enable or disable second DNS server."
|
||||
msgstr "是否启用第二DNS服务器。"
|
||||
|
||||
msgid "Skip Speed Check"
|
||||
msgstr "跳过测速"
|
||||
msgid "Do not check certificate."
|
||||
msgstr "不校验证书的合法性。"
|
||||
|
||||
msgid "Do not check speed."
|
||||
msgstr "禁用测速。"
|
||||
|
||||
msgid "Server Group"
|
||||
msgstr "服务器组"
|
||||
msgid "Domain Address"
|
||||
msgstr "域名地址"
|
||||
|
||||
msgid "Domain TTL"
|
||||
msgstr "域名TTL"
|
||||
|
||||
msgid "Domain TTL Max"
|
||||
msgstr "域名TTL最大值"
|
||||
|
||||
msgid "Domain TTL Min"
|
||||
msgstr "域名TTL最小值"
|
||||
|
||||
msgid "Domain prefetch"
|
||||
msgstr "域名预加载"
|
||||
|
||||
msgid "Donate"
|
||||
msgstr "捐助"
|
||||
|
||||
msgid "Donate to smartdns"
|
||||
msgstr "捐助smartdns项目"
|
||||
|
||||
msgid "Dual-stack IP Selection"
|
||||
msgstr "双栈IP优选"
|
||||
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Enable IP selection between IPV4 and IPV6"
|
||||
msgstr "启用 IPV4 和 IPV6 间的 IP 优选策略"
|
||||
|
||||
msgid "Enable IPV6 DNS Server"
|
||||
msgstr "启用IPV6服务器"
|
||||
|
||||
msgid "Enable TCP DNS Server"
|
||||
msgstr "启用TCP服务器"
|
||||
|
||||
msgid "Enable domain prefetch, accelerate domain response speed."
|
||||
msgstr "启用域名预加载,加速域名响应速度。"
|
||||
|
||||
msgid "Enable or disable second DNS server."
|
||||
msgstr "是否启用第二DNS服务器。"
|
||||
|
||||
msgid "Enable or disable smartdns server"
|
||||
msgstr "启用或禁用SmartDNS服务"
|
||||
|
||||
msgid "Filtering IP with blacklist"
|
||||
msgstr "使用IP黑名单过滤"
|
||||
|
||||
msgid "Force AAAA SOA"
|
||||
msgstr "停用IPV6地址解析"
|
||||
|
||||
msgid "Force AAAA SOA."
|
||||
msgstr "停用IPV6地址解析。"
|
||||
|
||||
msgid "Force HTTPS SOA"
|
||||
msgstr "停用HTTPS地址解析"
|
||||
|
||||
msgid "Force HTTPS SOA."
|
||||
msgstr "停用HTTPS地址解析。"
|
||||
|
||||
msgid "General Settings"
|
||||
msgstr "常规设置"
|
||||
|
||||
msgid "Generate Coredump"
|
||||
msgstr "生成coredump"
|
||||
|
||||
msgid ""
|
||||
"Generate Coredump file when smartdns crash, coredump file is located at /tmp/"
|
||||
"smartdns.xxx.core."
|
||||
msgstr ""
|
||||
"当smartdns异常时生成coredump文件,coredump文件在/tmp/smartdns.xxx.core."
|
||||
|
||||
msgid "Grant access to LuCI app smartdns"
|
||||
msgstr "授予访问 LuCI 应用 smartdns 的权限"
|
||||
|
||||
msgid "HTTP Host"
|
||||
msgstr "HTTP主机"
|
||||
|
||||
msgid "IP Blacklist"
|
||||
msgstr "IP黑名单"
|
||||
|
||||
msgid "IP Blacklist Filtering"
|
||||
msgstr "IP黑名单过滤"
|
||||
|
||||
msgid "IPV6 Server"
|
||||
msgstr "IPV6服务器"
|
||||
|
||||
msgid "If you like this software, please buy me a cup of coffee."
|
||||
msgstr "如果本软件对你有帮助,请给作者加个蛋。"
|
||||
|
||||
msgid "Local Port"
|
||||
msgstr "本地端口"
|
||||
|
||||
msgid "Maximum TTL for all domain result."
|
||||
msgstr "所有域名的最大 TTL 值。"
|
||||
|
||||
msgid "Minimum TTL for all domain result."
|
||||
msgstr "所有域名的最小 TTL 值。"
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "No check certificate"
|
||||
msgstr "停用证书校验"
|
||||
|
||||
msgid "Query DNS through specific dns server group, such as office, home."
|
||||
msgstr "使用指定服务器组查询,比如office, home。"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "Reply Domain TTL Max"
|
||||
msgstr "回应的域名TTL最大值"
|
||||
|
||||
msgid "Reply maximum TTL for all domain result."
|
||||
msgstr "设置返回给客户端的域名TTL最大值。"
|
||||
|
||||
msgid "Resolve Local Hostnames"
|
||||
msgstr "解析本地主机名"
|
||||
|
||||
msgid "Resolve local hostnames by reading Dnsmasq lease file."
|
||||
msgstr "读取Dnsmasq的租约文件解析本地主机名。"
|
||||
|
||||
msgid "Second Server Settings"
|
||||
msgstr "第二DNS服务器"
|
||||
|
||||
msgid "Serve expired"
|
||||
msgstr "缓存过期服务"
|
||||
|
||||
msgid "Server Group"
|
||||
msgstr "服务器组"
|
||||
|
||||
msgid "Server Name"
|
||||
msgstr "服务器名称"
|
||||
|
||||
msgid "Set Specific domain ip address."
|
||||
msgstr "设置指定域名的IP地址。"
|
||||
|
||||
msgid "Set Specific ip blacklist."
|
||||
msgstr "设置指定的 IP 黑名单列表。"
|
||||
|
||||
msgid "Set TLS hostname to verify."
|
||||
msgstr "设置校验TLS主机名。"
|
||||
|
||||
msgid ""
|
||||
"Set the HTTP host used for the query. Use this parameter when the host of "
|
||||
"the URL address is an IP address."
|
||||
msgstr "设置查询时使用的HTTP主机,当URL地址的host是IP地址时,使用此参数。"
|
||||
|
||||
msgid "Sets the server name indication for query."
|
||||
msgstr "设置查询时使用的服务器SNI名称。"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "设置"
|
||||
|
||||
msgid "Skip Address Rules"
|
||||
msgstr "跳过address规则"
|
||||
|
||||
msgid "Skip address rules."
|
||||
msgstr "跳过address规则。"
|
||||
|
||||
msgid "Skip Nameserver Rule"
|
||||
msgstr "跳过Nameserver规则"
|
||||
|
||||
msgid "Skip nameserver rules."
|
||||
msgstr "跳过Nameserver规则。"
|
||||
|
||||
msgid "Skip Ipset Rule"
|
||||
msgstr "跳过ipset规则"
|
||||
|
||||
msgid "Skip ipset rules."
|
||||
msgstr "跳过ipset规则。"
|
||||
|
||||
msgid "Skip SOA Address Rule"
|
||||
msgstr "跳过address SOA(#)规则"
|
||||
|
||||
msgid "Skip SOA address rules."
|
||||
msgstr "跳过address SOA(#)规则。"
|
||||
|
||||
msgid "Skip Dualstack Selection"
|
||||
msgstr "跳过双栈优选"
|
||||
|
||||
msgid "Skip Dualstack Selection."
|
||||
msgstr "跳过双栈优选。"
|
||||
|
||||
msgid "Skip Cache"
|
||||
msgstr "跳过cache"
|
||||
|
||||
msgid "Skip Cache."
|
||||
msgstr "跳过cache。"
|
||||
|
||||
msgid "Upstream Servers"
|
||||
msgstr "上游服务器"
|
||||
msgid "Skip Dualstack Selection"
|
||||
msgstr "跳过双栈优选"
|
||||
|
||||
msgid "Upstream Servers, support UDP, TCP protocol. Please configure multiple DNS servers, including multiple foreign DNS servers."
|
||||
msgstr "上游DNS服务器列表,支持UDP,TCP协议,请配置多个上游DNS服务器,包括多个国内外服务器"
|
||||
msgid "Skip Dualstack Selection."
|
||||
msgstr "跳过双栈优选。"
|
||||
|
||||
msgid "DNS Server Name"
|
||||
msgstr "DNS服务器名称"
|
||||
msgid "Skip Ipset Rule"
|
||||
msgstr "跳过ipset规则"
|
||||
|
||||
msgid "port"
|
||||
msgstr "端口"
|
||||
msgid "Skip Nameserver Rule"
|
||||
msgstr "跳过Nameserver规则"
|
||||
|
||||
msgid "DNS Server port"
|
||||
msgstr "DNS服务器端口"
|
||||
msgid "Skip SOA Address Rule"
|
||||
msgstr "跳过address SOA(#)规则"
|
||||
|
||||
msgid "DNS Server ip"
|
||||
msgstr "DNS服务器IP"
|
||||
msgid "Skip SOA address rules."
|
||||
msgstr "跳过address SOA(#)规则。"
|
||||
|
||||
msgid "type"
|
||||
msgstr "类型"
|
||||
msgid "Skip Speed Check"
|
||||
msgstr "跳过测速"
|
||||
|
||||
msgid "DNS Server type"
|
||||
msgstr "协议类型"
|
||||
msgid "Skip address rules."
|
||||
msgstr "跳过address规则。"
|
||||
|
||||
msgid "Domain Address"
|
||||
msgstr "域名地址"
|
||||
msgid "Skip ipset rules."
|
||||
msgstr "跳过ipset规则。"
|
||||
|
||||
msgid "TLS Hostname Verify"
|
||||
msgstr "校验TLS主机名"
|
||||
msgid "Skip nameserver rules."
|
||||
msgstr "跳过Nameserver规则。"
|
||||
|
||||
msgid "Set TLS hostname to verify."
|
||||
msgstr "设置校验TLS主机名。"
|
||||
msgid "SmartDNS"
|
||||
msgstr "SmartDNS"
|
||||
|
||||
msgid "No check certificate"
|
||||
msgstr "停用证书校验"
|
||||
msgid "SmartDNS Server"
|
||||
msgstr "SmartDNS 服务器"
|
||||
|
||||
msgid "Do not check certificate."
|
||||
msgstr "不校验证书的合法性。"
|
||||
|
||||
msgid "TLS SNI name"
|
||||
msgstr "TLS SNI名称"
|
||||
|
||||
msgid "HTTP Host"
|
||||
msgstr "HTTP主机"
|
||||
|
||||
msgid "Sets the server name indication for query."
|
||||
msgstr "设置查询时使用的服务器SNI名称。"
|
||||
|
||||
msgid "Set the HTTP host used for the query. Use this parameter when the host of the URL address is an IP address."
|
||||
msgstr "设置查询时使用的HTTP主机,当URL地址的host是IP地址时,使用此参数。"
|
||||
|
||||
msgid "Server Group"
|
||||
msgstr "服务器组"
|
||||
|
||||
msgid "DNS Server group belongs to, used with nameserver, such as office, home."
|
||||
msgstr "DNS服务器所属组, 配合nameserver使用,例如:office,home。"
|
||||
|
||||
msgid "IP Blacklist Filtering"
|
||||
msgstr "IP黑名单过滤"
|
||||
|
||||
msgid "Anti Answer Forgery"
|
||||
msgstr "反回答伪造"
|
||||
|
||||
msgid "Anti answer forgery, if DNS does not work properly after enabling, please turn off this feature"
|
||||
msgstr "反回答伪造,如果启用后DNS工作不正常,请关闭此功能。"
|
||||
|
||||
msgid "Filtering IP with blacklist"
|
||||
msgstr "使用IP黑名单过滤"
|
||||
|
||||
msgid "TLS SPKI Pinning"
|
||||
msgstr "TLS SPKI 指纹"
|
||||
|
||||
msgid "Used to verify the validity of the TLS server, The value is Base64 encoded SPKI fingerprint, leaving blank to indicate that the validity of TLS is not verified."
|
||||
msgstr "用于校验TLS服务器的有效性,数值为Base64编码的SPKI指纹, 留空表示不验证TLS的合法性"
|
||||
|
||||
msgid "Additional Server Args"
|
||||
msgstr "额外的服务器参数"
|
||||
|
||||
msgid "Additional Args for upstream dns servers"
|
||||
msgstr "额外的上游DNS服务器参数"
|
||||
|
||||
msgid "Upstream DNS Server Configuration"
|
||||
msgstr "上游DNS服务器配置"
|
||||
|
||||
msgid "Set Specific domain ip address."
|
||||
msgstr "指定特定域名的IP地址"
|
||||
|
||||
msgid "Specify an IP address to return for any host in the given domains, Queries in the domains are never forwarded and always replied to with the specified IP address which may be IPv4 or IPv6."
|
||||
msgstr "配置特定域名返回特定的IP地址,域名查询将不到上游服务器请求,直接返回配置的IP地址,可用于广告屏蔽。"
|
||||
|
||||
msgid "IP Blacklist"
|
||||
msgstr "IP黑名单"
|
||||
|
||||
msgid "Set Specific ip blacklist."
|
||||
msgstr "设置IP黑名单列表"
|
||||
|
||||
msgid "Configure IP blacklists that will be filtered from the results of specific DNS server."
|
||||
msgstr "配置需要从指定域名服务器结果过滤的IP黑名单。"
|
||||
|
||||
msgid "Technical Support"
|
||||
msgstr "技术支持"
|
||||
|
||||
msgid "If you like this software, please buy me a cup of coffee."
|
||||
msgstr "如果本软件对你有帮助,请给作者加个蛋。"
|
||||
msgid ""
|
||||
"SmartDNS is a local high-performance DNS server, supports finding fastest "
|
||||
"IP, supports ad filtering, and supports avoiding DNS poisoning."
|
||||
msgstr "SmartDNS是一个本地高性能DNS服务器,支持返回最快IP,支持广告过滤。"
|
||||
|
||||
msgid "SmartDNS official website"
|
||||
msgstr "SmartDNS官方网站"
|
||||
|
||||
msgid "Smartdns local server port"
|
||||
msgstr "SmartDNS本地服务端口"
|
||||
|
||||
msgid ""
|
||||
"Smartdns local server port, smartdns will be automatically set as main dns "
|
||||
"when the port is 53."
|
||||
msgstr "SmartDNS本地服务端口,当端口号设置为53时,smartdns将会自动配置为主dns。"
|
||||
|
||||
msgid "Smartdns server name"
|
||||
msgstr "SmartDNS的服务器名称,默认为smartdns,留空为主机名"
|
||||
|
||||
msgid ""
|
||||
"Specify an IP address to return for any host in the given domains, Queries "
|
||||
"in the domains are never forwarded and always replied to with the specified "
|
||||
"IP address which may be IPv4 or IPv6."
|
||||
msgstr ""
|
||||
"配置特定域名返回特定的IP地址,域名查询将不到上游服务器请求,直接返回配置的IP"
|
||||
"地址,可用于广告屏蔽。"
|
||||
|
||||
msgid "TCP Server"
|
||||
msgstr "TCP服务器"
|
||||
|
||||
msgid "TLS Hostname Verify"
|
||||
msgstr "校验TLS主机名"
|
||||
|
||||
msgid "TLS SNI name"
|
||||
msgstr "TLS SNI名称"
|
||||
|
||||
msgid "TLS SPKI Pinning"
|
||||
msgstr "TLS SPKI 指纹"
|
||||
|
||||
msgid "TTL for all domain result."
|
||||
msgstr "设置所有域名的 TTL 值。"
|
||||
|
||||
msgid "Technical Support"
|
||||
msgstr "技术支持"
|
||||
|
||||
msgid "Upstream Servers"
|
||||
msgstr "上游服务器"
|
||||
|
||||
msgid ""
|
||||
"Upstream Servers, support UDP, TCP protocol. Please configure multiple DNS "
|
||||
"servers, including multiple foreign DNS servers."
|
||||
msgstr ""
|
||||
"上游 DNS 服务器,支持 UDP,TCP 协议。请配置多个上游 DNS 服务器,包括多个国内"
|
||||
"外服务器。"
|
||||
|
||||
msgid ""
|
||||
"Used to verify the validity of the TLS server, The value is Base64 encoded "
|
||||
"SPKI fingerprint, leaving blank to indicate that the validity of TLS is not "
|
||||
"verified."
|
||||
msgstr ""
|
||||
"用于校验 TLS 服务器的有效性,数值为 Base64 编码的 SPKI 指纹,留空表示不验证 "
|
||||
"TLS 的合法性。"
|
||||
|
||||
msgid "https"
|
||||
msgstr "https"
|
||||
|
||||
msgid "ip"
|
||||
msgstr "ip"
|
||||
|
||||
msgid "open website"
|
||||
msgstr "打开网站"
|
||||
|
||||
msgid "Donate to smartdns"
|
||||
msgstr "捐助smartdns项目"
|
||||
msgid "port"
|
||||
msgstr "端口"
|
||||
|
||||
msgid "Donate"
|
||||
msgstr "捐助"
|
||||
msgid "smartdns custom settings"
|
||||
msgstr "smartdns 自定义设置,具体配置参数参考指导"
|
||||
|
||||
msgid "tcp"
|
||||
msgstr "tcp"
|
||||
|
||||
msgid "tls"
|
||||
msgstr "tls"
|
||||
|
||||
msgid "type"
|
||||
msgstr "类型"
|
||||
|
||||
msgid "udp"
|
||||
msgstr "udp"
|
||||
|
||||
@@ -45,9 +45,10 @@ o.datatype = "hostname"
|
||||
o.rempty = false
|
||||
|
||||
---- Port
|
||||
o = s:taboption("settings", Value, "port", translate("Local Port"), translate("Smartdns local server port"))
|
||||
o.placeholder = 6053
|
||||
o.default = 6053
|
||||
o = s:taboption("settings", Value, "port", translate("Local Port"),
|
||||
translate("Smartdns local server port, smartdns will be automatically set as main dns when the port is 53."))
|
||||
o.placeholder = 53
|
||||
o.default = 53
|
||||
o.datatype = "port"
|
||||
o.rempty = false
|
||||
|
||||
@@ -92,19 +93,42 @@ 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"
|
||||
o:value("none", translate("none"))
|
||||
o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
|
||||
o:value("redirect", translate("Redirect 53 port to SmartDNS"))
|
||||
o.default = "none"
|
||||
o.rempty = false
|
||||
|
||||
---- cache-size
|
||||
o = s:taboption("settings", Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size"))
|
||||
o.rempty = true
|
||||
|
||||
-- cache-size
|
||||
o = s:taboption("settings", Flag, "resolve_local_hostnames", translate("Resolve Local Hostnames"), translate("Resolve local hostnames by reading Dnsmasq lease file."));
|
||||
o.rmempty = false
|
||||
o.default = o.enabled
|
||||
o.cfgvalue = function(...)
|
||||
return Flag.cfgvalue(...) or "1"
|
||||
end
|
||||
|
||||
-- Automatically Set Dnsmasq
|
||||
o = s:taboption("settings", Flag, "auto_set_dnsmasq", translate("Automatically Set Dnsmasq"), translate("Automatically set as upstream of dnsmasq when port changes."));
|
||||
o.rmempty = false
|
||||
o.default = o.enabled
|
||||
o.cfgvalue = function(...)
|
||||
return Flag.cfgvalue(...) or "0"
|
||||
end
|
||||
|
||||
-- Force AAAA SOA
|
||||
o = s:taboption("settings", Flag, "force_aaaa_soa", translate("Force AAAA SOA"), translate("Force AAAA SOA."));
|
||||
o.rmempty = false
|
||||
o.default = o.enabled
|
||||
o.cfgvalue = function(...)
|
||||
return Flag.cfgvalue(...) or "0"
|
||||
end
|
||||
|
||||
-- Force HTTPS SOA
|
||||
o = s:taboption("settings", Flag, "force_https_soa", translate("Force HTTPS SOA"), translate("Force HTTPS SOA."));
|
||||
o.rmempty = false
|
||||
o.default = o.enabled
|
||||
o.cfgvalue = function(...)
|
||||
return Flag.cfgvalue(...) or "0"
|
||||
end
|
||||
|
||||
---- rr-ttl
|
||||
o = s:taboption("settings", Value, "rr_ttl", translate("Domain TTL"), translate("TTL for all domain result."))
|
||||
o.rempty = true
|
||||
@@ -121,7 +145,7 @@ o = s:taboption("settings", Value, "rr_ttl_max", translate("Domain TTL Max"), tr
|
||||
o.rempty = true
|
||||
|
||||
---- rr-ttl-reply-max
|
||||
o = s:taboption("settings", Value, "rr_ttl_reply_max", translate("Domain TTL Max"), translate("Maximum Reply TTL for all domain result."))
|
||||
o = s:taboption("settings", Value, "rr_ttl_reply_max", translate("Reply Domain TTL Max"), translate("Reply maximum TTL for all domain result."))
|
||||
o.rempty = true
|
||||
|
||||
---- second dns server
|
||||
@@ -207,7 +231,7 @@ o.cfgvalue = function(...)
|
||||
end
|
||||
|
||||
---- Force AAAA SOA
|
||||
o = s:taboption("seconddns", Flag, "force_aaaa_soa", translate("Force AAAA SOA"), translate("Force AAAA SOA."))
|
||||
o = s:taboption("seconddns", Flag, "seconddns_force_aaaa_soa", translate("Force AAAA SOA"), translate("Force AAAA SOA."))
|
||||
o.rmempty = false
|
||||
o.default = o.disabled
|
||||
o.cfgvalue = function(...)
|
||||
|
||||
@@ -6,22 +6,8 @@ XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "smartdns", "stat
|
||||
var links = "";
|
||||
if (data.running) {
|
||||
links = '<b><font color=green>SmartDNS - <%:RUNNING%></font></b></em>';
|
||||
if (data.redirect) {
|
||||
if (data.redirect == 1) {
|
||||
if (data.ipv4_works == 0) {
|
||||
links += "<br></br><b><font color=red><%:IPV4 53 Port Redirect Failure%></font></b>"
|
||||
}
|
||||
|
||||
if (data.ipv6_works != 2) {
|
||||
if (data.ipv6_works == 0) {
|
||||
links += "<br></br><b><font color=red><%:IPV6 53 Port Redirect Failure%></font></b>"
|
||||
}
|
||||
}
|
||||
} else if (data.redirect == 2) {
|
||||
if (data.dnsmasq_forward == 0) {
|
||||
links += "<br></br><b><font color=red><%:Dnsmasq Forwared To Smartdns Failure%></font></b>"
|
||||
}
|
||||
}
|
||||
if (data.dnsmasq_redirect_failure == 1) {
|
||||
links += "<br></br><b><font color=red><%:Dnsmasq Forwared To Smartdns Failure%></font></b>"
|
||||
}
|
||||
} else {
|
||||
links = '<b><font color=red>SmartDNS - <%:NOT RUNNING%></font></b>';
|
||||
|
||||
@@ -1,194 +1,113 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "SmartDNS"
|
||||
msgstr "SmartDNS"
|
||||
msgid "Additional Args for upstream dns servers"
|
||||
msgstr "额外的上游 DNS 服务器参数"
|
||||
|
||||
msgid "SmartDNS is a local high-performance DNS server"
|
||||
msgstr "SmartDNS是一个本地高性能DNS服务器"
|
||||
|
||||
msgid "SmartDNS Server"
|
||||
msgstr "SmartDNS 服务器"
|
||||
|
||||
msgid "SmartDNS is a local high-performance DNS server, supports finding fastest IP, supports ad filtering, and supports avoiding DNS poisoning."
|
||||
msgstr "SmartDNS是一个本地高性能DNS服务器,支持返回最快IP,支持广告过滤。"
|
||||
|
||||
msgid "Custom Settings"
|
||||
msgstr "自定义设置"
|
||||
|
||||
msgid "General Settings"
|
||||
msgstr "基本设置"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "设置"
|
||||
msgid "Additional Server Args"
|
||||
msgstr "额外的服务器参数"
|
||||
|
||||
msgid "Advanced Settings"
|
||||
msgstr "高级设置"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "Generate Coredump"
|
||||
msgstr "生成coredump"
|
||||
|
||||
msgid "Generate Coredump file when smartdns crash, coredump file is located at /tmp/smartdns.xxx.core."
|
||||
msgstr "当smartdns异常时生成coredump文件,coredump文件在/tmp/smartdns.xxx.core."
|
||||
|
||||
msgid "Server Name"
|
||||
msgstr "服务器名称"
|
||||
|
||||
msgid "Smartdns server name"
|
||||
msgstr "SmartDNS的服务器名称,默认为smartdns,留空为主机名"
|
||||
|
||||
msgid "SmartDNS is a local dns server to find fastest ip."
|
||||
msgstr "本地高性能服务器,优化网络访问性能。"
|
||||
|
||||
msgid "Enable or disable smartdns server"
|
||||
msgstr "启用或禁用SmartDNS服务"
|
||||
|
||||
msgid "Local Port"
|
||||
msgstr "本地端口"
|
||||
|
||||
msgid "Smartdns local server port"
|
||||
msgstr "SmartDNS本地服务端口"
|
||||
|
||||
msgid "IPV4 53 Port Redirect Failure"
|
||||
msgstr "IPV4 53端口重定向失败"
|
||||
|
||||
msgid "IPV6 53 Port Redirect Failure"
|
||||
msgstr "IPV6 53端口重定向失败"
|
||||
|
||||
msgid "Dnsmasq Forwared To Smartdns Failure"
|
||||
msgstr "重定向dnsmasq到smartdns失败"
|
||||
|
||||
msgid "TCP Server"
|
||||
msgstr "TCP服务器"
|
||||
|
||||
msgid "Enable TCP DNS Server"
|
||||
msgstr "启用TCP服务器"
|
||||
|
||||
msgid "IPV6 Server"
|
||||
msgstr "IPV6服务器"
|
||||
|
||||
msgid "Enable IPV6 DNS Server"
|
||||
msgstr "启用IPV6服务器"
|
||||
|
||||
msgid "Dual-stack IP Selection"
|
||||
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 "Serve expired"
|
||||
msgstr "缓存过期服务"
|
||||
|
||||
msgid "Attempts to serve old responses from cache with a TTL of 0 in the response without waiting for the actual resolution to finish."
|
||||
msgid ""
|
||||
"Attempts to serve old responses from cache with a TTL of 0 in the response "
|
||||
"without waiting for the actual resolution to finish."
|
||||
msgstr "查询性能优化,有请求时尝试回应TTL为0的过期记录,以避免查询等待。"
|
||||
|
||||
msgid "Redirect"
|
||||
msgstr "重定向"
|
||||
msgid "Automatically Set Dnsmasq"
|
||||
msgstr "自动设置Dnsmasq"
|
||||
|
||||
msgid "SmartDNS redirect mode"
|
||||
msgstr "SmartDNS 重定向模式"
|
||||
|
||||
msgid "Run as dnsmasq upstream server"
|
||||
msgstr "作为dnsmasq的上游服务器"
|
||||
|
||||
msgid "Redirect 53 port to SmartDNS"
|
||||
msgstr "重定向53端口到SmartDNS"
|
||||
msgid "Automatically set as upstream of dnsmasq when port changes."
|
||||
msgstr "自动设置为Dnsmasq的上游服务器"
|
||||
|
||||
msgid "Cache Size"
|
||||
msgstr "缓存大小"
|
||||
|
||||
msgid "Collecting data ..."
|
||||
msgstr "正在收集数据..."
|
||||
|
||||
msgid ""
|
||||
"Configure IP blacklists that will be filtered from the results of specific "
|
||||
"DNS server."
|
||||
msgstr "配置需要从指定域名服务器结果过滤的IP黑名单。"
|
||||
|
||||
msgid "Custom Settings"
|
||||
msgstr "自定义设置"
|
||||
|
||||
msgid "DNS Server Name"
|
||||
msgstr "DNS服务器名称"
|
||||
|
||||
msgid ""
|
||||
"DNS Server group belongs to, used with nameserver, such as office, home."
|
||||
msgstr "DNS服务器所属组, 配合nameserver使用,例如:office,home。"
|
||||
|
||||
msgid "DNS Server ip"
|
||||
msgstr "DNS服务器IP"
|
||||
|
||||
msgid "DNS Server port"
|
||||
msgstr "DNS服务器端口"
|
||||
|
||||
msgid "DNS Server type"
|
||||
msgstr "协议类型"
|
||||
|
||||
msgid "DNS domain result cache size"
|
||||
msgstr "缓存DNS的结果,缓存大小,配置零则不缓存(单位:条)"
|
||||
msgstr "缓存DNS的结果,缓存大小,配置零则不缓存"
|
||||
|
||||
msgid "Domain TTL"
|
||||
msgstr "域名TTL"
|
||||
msgid "Dnsmasq Forwared To Smartdns Failure"
|
||||
msgstr "重定向dnsmasq到smartdns失败"
|
||||
|
||||
msgid "TTL for all domain result."
|
||||
msgstr "设置所有域名的TTL值(单位:秒,下同)"
|
||||
|
||||
msgid "Domain TTL Min"
|
||||
msgstr "域名TTL最小值"
|
||||
|
||||
msgid "Minimum TTL for all domain result."
|
||||
msgstr "设置所有域名的TTL最小值"
|
||||
|
||||
msgid "Domain TTL Max"
|
||||
msgstr "域名TTL最大值"
|
||||
|
||||
msgid "Maximum TTL for all domain result."
|
||||
msgstr "设置所有域名的TTL最大值"
|
||||
|
||||
msgid "Maximum Reply TTL for all domain result."
|
||||
msgstr "设置返回给客户端的TTL最大值"
|
||||
|
||||
msgid "smartdns custom settings"
|
||||
msgstr "smartdns 自定义设置,具体配置参数参考指导"
|
||||
|
||||
msgid "Second Server Settings"
|
||||
msgstr "第二DNS服务器"
|
||||
|
||||
msgid "Enable or disable second DNS server."
|
||||
msgstr "是否启用第二DNS服务器。"
|
||||
|
||||
msgid "Skip Speed Check"
|
||||
msgstr "跳过测速"
|
||||
msgid "Do not check certificate."
|
||||
msgstr "不校验证书的合法性。"
|
||||
|
||||
msgid "Do not check speed."
|
||||
msgstr "禁用测速。"
|
||||
|
||||
msgid "Server Group"
|
||||
msgstr "服务器组"
|
||||
msgid "Domain Address"
|
||||
msgstr "域名地址"
|
||||
|
||||
msgid "Query DNS through specific dns server group, such as office, home."
|
||||
msgstr "使用指定服务器组查询,比如office, home。"
|
||||
msgid "Domain TTL"
|
||||
msgstr "域名TTL"
|
||||
|
||||
msgid "Skip Address Rules"
|
||||
msgstr "跳过address规则"
|
||||
msgid "Domain TTL Max"
|
||||
msgstr "域名TTL最大值"
|
||||
|
||||
msgid "Skip address rules."
|
||||
msgstr "跳过address规则。"
|
||||
msgid "Domain TTL Min"
|
||||
msgstr "域名TTL最小值"
|
||||
|
||||
msgid "Skip Nameserver Rule"
|
||||
msgstr "跳过Nameserver规则"
|
||||
msgid "Domain prefetch"
|
||||
msgstr "域名预加载"
|
||||
|
||||
msgid "Skip nameserver rules."
|
||||
msgstr "跳过Nameserver规则。"
|
||||
msgid "Donate"
|
||||
msgstr "捐助"
|
||||
|
||||
msgid "Skip Ipset Rule"
|
||||
msgstr "跳过ipset规则"
|
||||
msgid "Donate to smartdns"
|
||||
msgstr "捐助smartdns项目"
|
||||
|
||||
msgid "Skip ipset rules."
|
||||
msgstr "跳过ipset规则。"
|
||||
msgid "Dual-stack IP Selection"
|
||||
msgstr "双栈IP优选"
|
||||
|
||||
msgid "Skip SOA Address Rule"
|
||||
msgstr "跳过address SOA(#)规则"
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "Skip SOA address rules."
|
||||
msgstr "跳过address SOA(#)规则。"
|
||||
msgid "Enable IP selection between IPV4 and IPV6"
|
||||
msgstr "启用 IPV4 和 IPV6 间的 IP 优选策略"
|
||||
|
||||
msgid "Skip Dualstack Selection"
|
||||
msgstr "跳过双栈优选"
|
||||
msgid "Enable IPV6 DNS Server"
|
||||
msgstr "启用IPV6服务器"
|
||||
|
||||
msgid "Skip Dualstack Selection."
|
||||
msgstr "跳过双栈优选。"
|
||||
msgid "Enable TCP DNS Server"
|
||||
msgstr "启用TCP服务器"
|
||||
|
||||
msgid "Skip Cache"
|
||||
msgstr "跳过cache"
|
||||
msgid "Enable domain prefetch, accelerate domain response speed."
|
||||
msgstr "启用域名预加载,加速域名响应速度。"
|
||||
|
||||
msgid "Skip Cache."
|
||||
msgstr "跳过cache。"
|
||||
msgid "Enable or disable second DNS server."
|
||||
msgstr "是否启用第二DNS服务器。"
|
||||
|
||||
msgid "Enable or disable smartdns server"
|
||||
msgstr "启用或禁用SmartDNS服务"
|
||||
|
||||
msgid "Filtering IP with blacklist"
|
||||
msgstr "使用IP黑名单过滤"
|
||||
|
||||
msgid "Force AAAA SOA"
|
||||
msgstr "停用IPV6地址解析"
|
||||
@@ -196,119 +115,238 @@ msgstr "停用IPV6地址解析"
|
||||
msgid "Force AAAA SOA."
|
||||
msgstr "停用IPV6地址解析。"
|
||||
|
||||
msgid "Upstream Servers"
|
||||
msgstr "上游服务器"
|
||||
msgid "Force HTTPS SOA"
|
||||
msgstr "停用HTTPS地址解析"
|
||||
|
||||
msgid "Upstream Servers, support UDP, TCP protocol. Please configure multiple DNS servers, including multiple foreign DNS servers."
|
||||
msgstr "上游DNS服务器列表,支持UDP,TCP协议,请配置多个上游DNS服务器,包括多个国内外服务器"
|
||||
msgid "Force HTTPS SOA."
|
||||
msgstr "停用HTTPS地址解析。"
|
||||
|
||||
msgid "DNS Server Name"
|
||||
msgstr "DNS服务器名称"
|
||||
msgid "General Settings"
|
||||
msgstr "常规设置"
|
||||
|
||||
msgid "port"
|
||||
msgstr "端口"
|
||||
msgid "Generate Coredump"
|
||||
msgstr "生成coredump"
|
||||
|
||||
msgid "DNS Server port"
|
||||
msgstr "DNS服务器端口"
|
||||
msgid ""
|
||||
"Generate Coredump file when smartdns crash, coredump file is located at /tmp/"
|
||||
"smartdns.xxx.core."
|
||||
msgstr ""
|
||||
"当smartdns异常时生成coredump文件,coredump文件在/tmp/smartdns.xxx.core."
|
||||
|
||||
msgid "DNS Server ip"
|
||||
msgstr "DNS服务器IP"
|
||||
|
||||
msgid "type"
|
||||
msgstr "类型"
|
||||
|
||||
msgid "DNS Server type"
|
||||
msgstr "协议类型"
|
||||
|
||||
msgid "Domain Address"
|
||||
msgstr "域名地址"
|
||||
|
||||
msgid "TLS Hostname Verify"
|
||||
msgstr "校验TLS主机名"
|
||||
|
||||
msgid "Set TLS hostname to verify."
|
||||
msgstr "设置校验TLS主机名。"
|
||||
|
||||
msgid "No check certificate"
|
||||
msgstr "停用证书校验"
|
||||
|
||||
msgid "Do not check certificate."
|
||||
msgstr "不校验证书的合法性。"
|
||||
|
||||
msgid "TLS SNI name"
|
||||
msgstr "TLS SNI名称"
|
||||
msgid "Grant access to LuCI app smartdns"
|
||||
msgstr "授予访问 LuCI 应用 smartdns 的权限"
|
||||
|
||||
msgid "HTTP Host"
|
||||
msgstr "HTTP主机"
|
||||
|
||||
msgid "Sets the server name indication for query."
|
||||
msgstr "设置查询时使用的服务器SNI名称。"
|
||||
|
||||
msgid "Set the HTTP host used for the query. Use this parameter when the host of the URL address is an IP address."
|
||||
msgstr "设置查询时使用的HTTP主机,当URL地址的host是IP地址时,使用此参数。"
|
||||
|
||||
msgid "Server Group"
|
||||
msgstr "服务器组"
|
||||
|
||||
msgid "DNS Server group belongs to, used with nameserver, such as office, home."
|
||||
msgstr "DNS服务器所属组, 配合nameserver使用,例如:office,home。"
|
||||
msgid "IP Blacklist"
|
||||
msgstr "IP黑名单"
|
||||
|
||||
msgid "IP Blacklist Filtering"
|
||||
msgstr "IP黑名单过滤"
|
||||
|
||||
msgid "Anti Answer Forgery"
|
||||
msgstr "反回答伪造"
|
||||
|
||||
msgid "Anti answer forgery, if DNS does not work properly after enabling, please turn off this feature"
|
||||
msgstr "反回答伪造,如果启用后DNS工作不正常,请关闭此功能。"
|
||||
|
||||
msgid "Filtering IP with blacklist"
|
||||
msgstr "使用IP黑名单过滤"
|
||||
|
||||
msgid "TLS SPKI Pinning"
|
||||
msgstr "TLS SPKI 指纹"
|
||||
|
||||
msgid "Used to verify the validity of the TLS server, The value is Base64 encoded SPKI fingerprint, leaving blank to indicate that the validity of TLS is not verified."
|
||||
msgstr "用于校验TLS服务器的有效性,数值为Base64编码的SPKI指纹, 留空表示不验证TLS的合法性"
|
||||
|
||||
msgid "Additional Server Args"
|
||||
msgstr "额外的服务器参数"
|
||||
|
||||
msgid "Additional Args for upstream dns servers"
|
||||
msgstr "额外的上游DNS服务器参数"
|
||||
|
||||
msgid "Upstream DNS Server Configuration"
|
||||
msgstr "上游DNS服务器配置"
|
||||
|
||||
msgid "Set Specific domain ip address."
|
||||
msgstr "指定特定域名的IP地址"
|
||||
|
||||
msgid "Specify an IP address to return for any host in the given domains, Queries in the domains are never forwarded and always replied to with the specified IP address which may be IPv4 or IPv6."
|
||||
msgstr "配置特定域名返回特定的IP地址,域名查询将不到上游服务器请求,直接返回配置的IP地址,可用于广告屏蔽。"
|
||||
|
||||
msgid "IP Blacklist"
|
||||
msgstr "IP黑名单"
|
||||
|
||||
msgid "Set Specific ip blacklist."
|
||||
msgstr "设置IP黑名单列表"
|
||||
|
||||
msgid "Configure IP blacklists that will be filtered from the results of specific DNS server."
|
||||
msgstr "配置需要从指定域名服务器结果过滤的IP黑名单。"
|
||||
|
||||
msgid "Technical Support"
|
||||
msgstr "技术支持"
|
||||
msgid "IPV6 Server"
|
||||
msgstr "IPV6服务器"
|
||||
|
||||
msgid "If you like this software, please buy me a cup of coffee."
|
||||
msgstr "如果本软件对你有帮助,请给作者加个蛋。"
|
||||
|
||||
msgid "Local Port"
|
||||
msgstr "本地端口"
|
||||
|
||||
msgid "Maximum TTL for all domain result."
|
||||
msgstr "所有域名的最大 TTL 值。"
|
||||
|
||||
msgid "Minimum TTL for all domain result."
|
||||
msgstr "所有域名的最小 TTL 值。"
|
||||
|
||||
msgid "NOT RUNNING"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "No check certificate"
|
||||
msgstr "停用证书校验"
|
||||
|
||||
msgid "Query DNS through specific dns server group, such as office, home."
|
||||
msgstr "使用指定服务器组查询,比如office, home。"
|
||||
|
||||
msgid "RUNNING"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "Reply Domain TTL Max"
|
||||
msgstr "回应的域名TTL最大值"
|
||||
|
||||
msgid "Reply maximum TTL for all domain result."
|
||||
msgstr "设置返回给客户端的域名TTL最大值。"
|
||||
|
||||
msgid "Resolve Local Hostnames"
|
||||
msgstr "解析本地主机名"
|
||||
|
||||
msgid "Resolve local hostnames by reading Dnsmasq lease file."
|
||||
msgstr "读取Dnsmasq的租约文件解析本地主机名。"
|
||||
|
||||
msgid "Second Server Settings"
|
||||
msgstr "第二DNS服务器"
|
||||
|
||||
msgid "Serve expired"
|
||||
msgstr "缓存过期服务"
|
||||
|
||||
msgid "Server Group"
|
||||
msgstr "服务器组"
|
||||
|
||||
msgid "Server Name"
|
||||
msgstr "服务器名称"
|
||||
|
||||
msgid "Set Specific domain ip address."
|
||||
msgstr "设置指定域名的IP地址。"
|
||||
|
||||
msgid "Set Specific ip blacklist."
|
||||
msgstr "设置指定的 IP 黑名单列表。"
|
||||
|
||||
msgid "Set TLS hostname to verify."
|
||||
msgstr "设置校验TLS主机名。"
|
||||
|
||||
msgid ""
|
||||
"Set the HTTP host used for the query. Use this parameter when the host of "
|
||||
"the URL address is an IP address."
|
||||
msgstr "设置查询时使用的HTTP主机,当URL地址的host是IP地址时,使用此参数。"
|
||||
|
||||
msgid "Sets the server name indication for query."
|
||||
msgstr "设置查询时使用的服务器SNI名称。"
|
||||
|
||||
msgid "Settings"
|
||||
msgstr "设置"
|
||||
|
||||
msgid "Skip Address Rules"
|
||||
msgstr "跳过address规则"
|
||||
|
||||
msgid "Skip Cache"
|
||||
msgstr "跳过cache"
|
||||
|
||||
msgid "Skip Cache."
|
||||
msgstr "跳过cache。"
|
||||
|
||||
msgid "Skip Dualstack Selection"
|
||||
msgstr "跳过双栈优选"
|
||||
|
||||
msgid "Skip Dualstack Selection."
|
||||
msgstr "跳过双栈优选。"
|
||||
|
||||
msgid "Skip Ipset Rule"
|
||||
msgstr "跳过ipset规则"
|
||||
|
||||
msgid "Skip Nameserver Rule"
|
||||
msgstr "跳过Nameserver规则"
|
||||
|
||||
msgid "Skip SOA Address Rule"
|
||||
msgstr "跳过address SOA(#)规则"
|
||||
|
||||
msgid "Skip SOA address rules."
|
||||
msgstr "跳过address SOA(#)规则。"
|
||||
|
||||
msgid "Skip Speed Check"
|
||||
msgstr "跳过测速"
|
||||
|
||||
msgid "Skip address rules."
|
||||
msgstr "跳过address规则。"
|
||||
|
||||
msgid "Skip ipset rules."
|
||||
msgstr "跳过ipset规则。"
|
||||
|
||||
msgid "Skip nameserver rules."
|
||||
msgstr "跳过Nameserver规则。"
|
||||
|
||||
msgid "SmartDNS"
|
||||
msgstr "SmartDNS"
|
||||
|
||||
msgid "SmartDNS Server"
|
||||
msgstr "SmartDNS 服务器"
|
||||
|
||||
msgid ""
|
||||
"SmartDNS is a local high-performance DNS server, supports finding fastest "
|
||||
"IP, supports ad filtering, and supports avoiding DNS poisoning."
|
||||
msgstr "SmartDNS是一个本地高性能DNS服务器,支持返回最快IP,支持广告过滤。"
|
||||
|
||||
msgid "SmartDNS official website"
|
||||
msgstr "SmartDNS官方网站"
|
||||
|
||||
msgid "Smartdns local server port"
|
||||
msgstr "SmartDNS本地服务端口"
|
||||
|
||||
msgid ""
|
||||
"Smartdns local server port, smartdns will be automatically set as main dns "
|
||||
"when the port is 53."
|
||||
msgstr "SmartDNS本地服务端口,当端口号设置为53时,smartdns将会自动配置为主dns。"
|
||||
|
||||
msgid "Smartdns server name"
|
||||
msgstr "SmartDNS的服务器名称,默认为smartdns,留空为主机名"
|
||||
|
||||
msgid ""
|
||||
"Specify an IP address to return for any host in the given domains, Queries "
|
||||
"in the domains are never forwarded and always replied to with the specified "
|
||||
"IP address which may be IPv4 or IPv6."
|
||||
msgstr ""
|
||||
"配置特定域名返回特定的IP地址,域名查询将不到上游服务器请求,直接返回配置的IP"
|
||||
"地址,可用于广告屏蔽。"
|
||||
|
||||
msgid "TCP Server"
|
||||
msgstr "TCP服务器"
|
||||
|
||||
msgid "TLS Hostname Verify"
|
||||
msgstr "校验TLS主机名"
|
||||
|
||||
msgid "TLS SNI name"
|
||||
msgstr "TLS SNI名称"
|
||||
|
||||
msgid "TLS SPKI Pinning"
|
||||
msgstr "TLS SPKI 指纹"
|
||||
|
||||
msgid "TTL for all domain result."
|
||||
msgstr "设置所有域名的 TTL 值。"
|
||||
|
||||
msgid "Technical Support"
|
||||
msgstr "技术支持"
|
||||
|
||||
msgid "Upstream Servers"
|
||||
msgstr "上游服务器"
|
||||
|
||||
msgid ""
|
||||
"Upstream Servers, support UDP, TCP protocol. Please configure multiple DNS "
|
||||
"servers, including multiple foreign DNS servers."
|
||||
msgstr ""
|
||||
"上游 DNS 服务器,支持 UDP,TCP 协议。请配置多个上游 DNS 服务器,包括多个国内"
|
||||
"外服务器。"
|
||||
|
||||
msgid ""
|
||||
"Used to verify the validity of the TLS server, The value is Base64 encoded "
|
||||
"SPKI fingerprint, leaving blank to indicate that the validity of TLS is not "
|
||||
"verified."
|
||||
msgstr ""
|
||||
"用于校验 TLS 服务器的有效性,数值为 Base64 编码的 SPKI 指纹,留空表示不验证 "
|
||||
"TLS 的合法性。"
|
||||
|
||||
msgid "https"
|
||||
msgstr "https"
|
||||
|
||||
msgid "ip"
|
||||
msgstr "ip"
|
||||
|
||||
msgid "open website"
|
||||
msgstr "打开网站"
|
||||
|
||||
msgid "Donate to smartdns"
|
||||
msgstr "捐助smartdns项目"
|
||||
msgid "port"
|
||||
msgstr "端口"
|
||||
|
||||
msgid "Donate"
|
||||
msgstr "捐助"
|
||||
msgid "smartdns custom settings"
|
||||
msgstr "smartdns 自定义设置,具体配置参数参考指导"
|
||||
|
||||
msgid "tcp"
|
||||
msgstr "tcp"
|
||||
|
||||
msgid "tls"
|
||||
msgstr "tls"
|
||||
|
||||
msgid "type"
|
||||
msgstr "类型"
|
||||
|
||||
msgid "udp"
|
||||
msgstr "udp"
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
"read": {
|
||||
"file": {
|
||||
"/etc/smartdns/*": [ "read" ],
|
||||
"/usr/sbin/iptables -t nat -nL PREROUTING": [ "exec" ],
|
||||
"/usr/sbin/ip6tables -t nat -nL PREROUTING": [ "exec" ],
|
||||
"/usr/sbin/smartdns": [ "exec" ]
|
||||
},
|
||||
"ubus": {
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
'require fs';
|
||||
'require uci';
|
||||
'require form';
|
||||
'require view';
|
||||
'require poll';
|
||||
'require rpc';
|
||||
|
||||
var conf = 'smartdns';
|
||||
@@ -31,7 +33,7 @@ var callServiceList = rpc.declare({
|
||||
expect: { '': {} }
|
||||
});
|
||||
|
||||
function getPidOfSmartdns() {
|
||||
function getServiceStatus() {
|
||||
return L.resolveDefault(callServiceList(conf), {})
|
||||
.then(function (res) {
|
||||
var isrunning = false;
|
||||
@@ -42,43 +44,19 @@ function getPidOfSmartdns() {
|
||||
});
|
||||
}
|
||||
|
||||
function getIPTablesRedirect() {
|
||||
return fs.exec('/usr/sbin/iptables', ['-t', 'nat', '-nL', 'PREROUTING']).then(function (res) {
|
||||
if (res.code === 0) {
|
||||
return res.stdout.trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getIP6TablesRedirect() {
|
||||
return fs.exec('/usr/sbin/ip6tables', ['-t', 'nat', '-nL', 'PREROUTING']).then(function (res) {
|
||||
if (res.code === 0) {
|
||||
return res.stdout.trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function smartdnsServiceStatus() {
|
||||
return Promise.all([
|
||||
getPidOfSmartdns(),
|
||||
getIPTablesRedirect(),
|
||||
getIP6TablesRedirect()
|
||||
getServiceStatus()
|
||||
]);
|
||||
}
|
||||
|
||||
function smartdnsRenderStatus(res) {
|
||||
var renderHTML = "";
|
||||
var isRunning = res[0];
|
||||
var ipt = res[1];
|
||||
var ip6t = res[2];
|
||||
|
||||
var serverPort = uci.get_first('smartdns', 'smartdns', 'port');
|
||||
var redirectMode = uci.get_first('smartdns', 'smartdns', 'redirect');
|
||||
var ipv6Enabled = uci.get_first('smartdns', 'smartdns', 'ipv6_server');
|
||||
var autoSetDnsmasq = uci.get_first('smartdns', 'smartdns', 'auto_set_dnsmasq');
|
||||
var smartdnsPort = uci.get_first('smartdns', 'smartdns', 'port');
|
||||
var dnsmasqServer = uci.get_first('dhcp', 'dnsmasq', 'server');
|
||||
|
||||
if (isRunning) {
|
||||
renderHTML += "<span style=\"color:green;font-weight:bold\">SmartDNS - " + _("RUNNING") + "</span>";
|
||||
@@ -87,39 +65,24 @@ function smartdnsRenderStatus(res) {
|
||||
return renderHTML;
|
||||
}
|
||||
|
||||
if (redirectMode === "dnsmasq-upstream") {
|
||||
var matchLine = "127.0.0.1#" + serverPort;
|
||||
var dnsmasqServer = uci.get_first('dhcp', 'dnsmasq', 'server') || "";
|
||||
if (autoSetDnsmasq === '1' && smartdnsPort != '53') {
|
||||
var matchLine = "127.0.0.1#" + smartdnsPort;
|
||||
|
||||
if (dnsmasqServer.indexOf(matchLine) < 0) {
|
||||
uci.unload('dhcp');
|
||||
uci.load('dhcp');
|
||||
if (dnsmasqServer == undefined || dnsmasqServer.indexOf(matchLine) < 0) {
|
||||
renderHTML += "<br /><span style=\"color:red;font-weight:bold\">" + _("Dnsmasq Forwared To Smartdns Failure") + "</span>";
|
||||
}
|
||||
} else if (redirectMode === "redirect") {
|
||||
var redirectRules = (ipt || '').split(/\n/).filter(function (rule) {
|
||||
return rule.match(/REDIRECT/) && rule.match(/dpt:53/) && rule.match("ports " + serverPort);
|
||||
});
|
||||
|
||||
if (redirectRules.length <= 0) {
|
||||
renderHTML += "<br /><span style=\"color:red;font-weight:bold\">" + _("IPV4 53 Port Redirect Failure") + "</span>";
|
||||
if (ipv6Enabled) {
|
||||
var redirectRules = (ip6t || '').split(/\n/).filter(function (rule) {
|
||||
return rule.match(/REDIRECT/) && rule.match(/dpt:53/) && rule.match("ports " + serverPort);
|
||||
});
|
||||
if (redirectRules.length <= 0) {
|
||||
renderHTML += "<br /><span style=\"color:red;font-weight:bold\">" + _("IPV6 53 Port Redirect Failure") + "</span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return renderHTML;
|
||||
}
|
||||
|
||||
return L.view.extend({
|
||||
return view.extend({
|
||||
load: function () {
|
||||
return Promise.all([
|
||||
uci.load('dhcp'),
|
||||
uci.load('smartdns'),
|
||||
uci.load('dhcp')
|
||||
]);
|
||||
},
|
||||
render: function (stats) {
|
||||
@@ -133,12 +96,17 @@ return L.view.extend({
|
||||
s = m.section(form.NamedSection, '_status');
|
||||
s.anonymous = true;
|
||||
s.render = function (section_id) {
|
||||
L.Poll.add(function () {
|
||||
var renderStatus = function () {
|
||||
return L.resolveDefault(smartdnsServiceStatus()).then(function (res) {
|
||||
var view = document.getElementById("service_status");
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
view.innerHTML = smartdnsRenderStatus(res);
|
||||
});
|
||||
});
|
||||
}
|
||||
poll.add(renderStatus, 1);
|
||||
|
||||
return E('div', { class: 'cbi-map' },
|
||||
E('div', { class: 'cbi-section' }, [
|
||||
@@ -156,10 +124,9 @@ return L.view.extend({
|
||||
s.tab("seconddns", _("Second Server Settings"));
|
||||
s.tab("custom", _("Custom Settings"));
|
||||
|
||||
// Eanble;
|
||||
o = s.taboption("settings", form.Flag, "enabled", _("Enable"), _("Enable or disable smartdns server"));
|
||||
o.rmempty = false;
|
||||
o.default = o.disabled;
|
||||
o.rempty = false;
|
||||
|
||||
// server name;
|
||||
o = s.taboption("settings", form.Value, "server_name", _("Server Name"), _("Smartdns server name"));
|
||||
@@ -168,9 +135,10 @@ return L.view.extend({
|
||||
o.rempty = false;
|
||||
|
||||
// Port;
|
||||
o = s.taboption("settings", form.Value, "port", _("Local Port"), _("Smartdns local server port"));
|
||||
o.placeholder = 6053;
|
||||
o.default = 6053;
|
||||
o = s.taboption("settings", form.Value, "port", _("Local Port"),
|
||||
_("Smartdns local server port, smartdns will be automatically set as main dns when the port is 53."));
|
||||
o.placeholder = 53;
|
||||
o.default = 53;
|
||||
o.datatype = "port";
|
||||
o.rempty = false;
|
||||
|
||||
@@ -202,19 +170,30 @@ return L.view.extend({
|
||||
o.rmempty = false;
|
||||
o.default = o.enabled;
|
||||
|
||||
// Redirect;
|
||||
o = s.taboption("settings", form.ListValue, "redirect", _("Redirect"), _("SmartDNS redirect mode"));
|
||||
o.placeholder = "none";
|
||||
o.value("none", _("none"));
|
||||
o.value("dnsmasq-upstream", _("Run as dnsmasq upstream server"));
|
||||
o.value("redirect", _("Redirect 53 port to SmartDNS"));
|
||||
o.default = "none";
|
||||
o.rempty = false;
|
||||
|
||||
// cache-size;
|
||||
o = s.taboption("settings", form.Value, "cache_size", _("Cache Size"), _("DNS domain result cache size"));
|
||||
o.rempty = true;
|
||||
|
||||
// cache-size;
|
||||
o = s.taboption("settings", form.Flag, "resolve_local_hostnames", _("Resolve Local Hostnames"), _("Resolve local hostnames by reading Dnsmasq lease file."));
|
||||
o.rmempty = false;
|
||||
o.default = o.enabled;
|
||||
|
||||
// auto-conf-dnsmasq;
|
||||
o = s.taboption("settings", form.Flag, "auto_set_dnsmasq", _("Automatically Set Dnsmasq"), _("Automatically set as upstream of dnsmasq when port changes."));
|
||||
o.rmempty = false;
|
||||
o.default = o.enabled;
|
||||
|
||||
// Force AAAA SOA
|
||||
o = s.taboption("settings", form.Flag, "force_aaaa_soa", _("Force AAAA SOA"), _("Force AAAA SOA."));
|
||||
o.rmempty = false;
|
||||
o.default = o.disabled;
|
||||
|
||||
// Force HTTPS SOA
|
||||
o = s.taboption("settings", form.Flag, "force_https_soa", _("Force HTTPS SOA"), _("Force HTTPS SOA."));
|
||||
o.rmempty = false;
|
||||
o.default = o.disabled;
|
||||
|
||||
// rr-ttl;
|
||||
o = s.taboption("settings", form.Value, "rr_ttl", _("Domain TTL"), _("TTL for all domain result."));
|
||||
o.rempty = true;
|
||||
@@ -229,14 +208,14 @@ return L.view.extend({
|
||||
|
||||
// rr-ttl-max;
|
||||
o = s.taboption("settings", form.Value, "rr_ttl_max", _("Domain TTL Max"),
|
||||
_("Maximum TTL for all domain result."));
|
||||
_("Maximum TTL for all domain result."));
|
||||
o.rempty = true;
|
||||
|
||||
// rr-ttl-reply-max;
|
||||
o = s.taboption("settings", form.Value, "rr_ttl_reply_max", _("Domain Reply TTL Max"),
|
||||
_("Maximum Reply TTL for all domain result."));
|
||||
o = s.taboption("settings", form.Value, "rr_ttl_reply_max", _("Reply Domain TTL Max"),
|
||||
_("Reply maximum TTL for all domain result."));
|
||||
o.rempty = true;
|
||||
|
||||
|
||||
// second dns server;
|
||||
// Eanble;
|
||||
o = s.taboption("seconddns", form.Flag, "seconddns_enabled", _("Enable"),
|
||||
@@ -304,7 +283,7 @@ return L.view.extend({
|
||||
o.default = o.disabled;
|
||||
|
||||
// Force AAAA SOA
|
||||
o = s.taboption("seconddns", form.Flag, "force_aaaa_soa", _("Force AAAA SOA"), _("Force AAAA SOA."));
|
||||
o = s.taboption("seconddns", form.Flag, "seconddns_force_aaaa_soa", _("Force AAAA SOA"), _("Force AAAA SOA."));
|
||||
o.rmempty = false;
|
||||
o.default = o.disabled;
|
||||
|
||||
|
||||
@@ -36,17 +36,17 @@ set_forward_dnsmasq()
|
||||
{
|
||||
local PORT="$1"
|
||||
addr="127.0.0.1#$PORT"
|
||||
OLD_SERVER="$(uci get dhcp.@dnsmasq[0].server 2>/dev/null)"
|
||||
if echo "$OLD_SERVER" | grep "^$addr" >/dev/null 2>&1; then
|
||||
# space in suffix is important
|
||||
OLD_SERVER="$(uci -q get dhcp.@dnsmasq[0].server) "
|
||||
if echo "$OLD_SERVER" | grep "^$addr " >/dev/null 2>&1; then
|
||||
return
|
||||
fi
|
||||
uci delete dhcp.@dnsmasq[0].server 2>/dev/null
|
||||
uci add_list dhcp.@dnsmasq[0].server="$addr"
|
||||
for server in $OLD_SERVER; do
|
||||
[ "$server" = "$addr" ] && continue
|
||||
uci add_list dhcp.@dnsmasq[0].server="$server"
|
||||
done
|
||||
uci set dhcp.@dnsmasq[0].noresolv=1
|
||||
|
||||
uci -q delete dhcp.@dnsmasq[0].server
|
||||
uci -q add_list dhcp.@dnsmasq[0].server="$addr"
|
||||
uci -q set dhcp.@dnsmasq[0].noresolv=1
|
||||
uci -q set dhcp.@dnsmasq[0].rebind_protection=0
|
||||
uci -q set dhcp.@dnsmasq[0].domainneeded=0
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
}
|
||||
@@ -54,46 +54,59 @@ set_forward_dnsmasq()
|
||||
stop_forward_dnsmasq()
|
||||
{
|
||||
local OLD_PORT="$1"
|
||||
local norestart="$2"
|
||||
addr="127.0.0.1#$OLD_PORT"
|
||||
OLD_SERVER="$(uci get dhcp.@dnsmasq[0].server 2>/dev/null)"
|
||||
if ! echo "$OLD_SERVER" | grep "^$addr" >/dev/null 2>&1; then
|
||||
OLD_SERVER="$(uci -q get dhcp.@dnsmasq[0].server) "
|
||||
if ! echo "$OLD_SERVER" | grep "^$addr " >/dev/null 2>&1; then
|
||||
return
|
||||
fi
|
||||
|
||||
uci -q delete dhcp.@dnsmasq[0].server
|
||||
uci -q delete dhcp.@dnsmasq[0].noresolv
|
||||
uci -q set dhcp.@dnsmasq[0].rebind_protection=1
|
||||
uci -q set dhcp.@dnsmasq[0].domainneeded=1
|
||||
uci commit dhcp
|
||||
[ "$norestart" != "1" ] && /etc/init.d/dnsmasq restart
|
||||
}
|
||||
|
||||
uci del_list dhcp.@dnsmasq[0].server="$addr" 2>/dev/null
|
||||
addrlist="$(uci get dhcp.@dnsmasq[0].server 2>/dev/null)"
|
||||
[ -z "$addrlist" ] && {
|
||||
uci delete dhcp.@dnsmasq[0].noresolv 2>/dev/null
|
||||
set_main_dns()
|
||||
{
|
||||
local hostip
|
||||
hostip="$(uci -q get network.lan.ipaddr)"
|
||||
dnsmasq_port="$(uci -q get dhcp.@dnsmasq[0].port)"
|
||||
[ -z "$dnsmasq_port" ] && dnsmasq_port="53"
|
||||
|
||||
[ -z "$hostip" ] && return
|
||||
[ "$dnsmasq_port" = "53" ] && {
|
||||
uci -q set dhcp.@dnsmasq[0].port=0
|
||||
uci -q set dhcp.lan.dhcp_option="6,$hostip"
|
||||
}
|
||||
|
||||
# for some third-party firmware
|
||||
redir_dns="$(uci -q get dhcp.@dnsmasq[0].dns_redirect)"
|
||||
[ "$redir_dns" = "1" ] && {
|
||||
uci -q set dhcp.@dnsmasq[0].dns_redirect=0
|
||||
uci -q set dhcp.@dnsmasq[0].old_dns_redirect=1
|
||||
}
|
||||
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
}
|
||||
|
||||
set_iptable()
|
||||
stop_main_dns()
|
||||
{
|
||||
local ipv6_server=$1
|
||||
local tcp_server=$2
|
||||
|
||||
IPS="$(ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F : '{print $2}')"
|
||||
for IP in $IPS
|
||||
do
|
||||
if [ "$tcp_server" = "1" ]; then
|
||||
iptables -t nat -A PREROUTING -p tcp -d "$IP" --dport 53 -j REDIRECT --to-ports "$SMARTDNS_PORT" >/dev/null 2>&1
|
||||
fi
|
||||
iptables -t nat -A PREROUTING -p udp -d "$IP" --dport 53 -j REDIRECT --to-ports "$SMARTDNS_PORT" >/dev/null 2>&1
|
||||
done
|
||||
|
||||
[ "$ipv6_server" = 0 ] && return
|
||||
|
||||
IPS="$(ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}')"
|
||||
for IP in $IPS
|
||||
do
|
||||
if [ "$tcp_server" = "1" ]; then
|
||||
ip6tables -t nat -A PREROUTING -p tcp -d "$IP" --dport 53 -j REDIRECT --to-ports "$SMARTDNS_PORT" >/dev/null 2>&1
|
||||
fi
|
||||
ip6tables -t nat -A PREROUTING -p udp -d "$IP" --dport 53 -j REDIRECT --to-ports "$SMARTDNS_PORT" >/dev/null 2>&1
|
||||
done
|
||||
|
||||
local norestart="$1"
|
||||
dnsmasq_port="$(uci -q get dhcp.@dnsmasq[0].port)"
|
||||
redir_dns="$(uci -q get dhcp.@dnsmasq[0].old_dns_redirect)"
|
||||
[ "$dnsmasq_port" != "0" ] && return
|
||||
[ "$redir_dns" = "1" ] && {
|
||||
uci -q set dhcp.@dnsmasq[0].dns_redirect=1
|
||||
uci -q delete dhcp.@dnsmasq[0].old_dns_redirect
|
||||
}
|
||||
uci -q delete dhcp.@dnsmasq[0].port
|
||||
uci -q delete dhcp.lan.dhcp_option
|
||||
uci commit dhcp
|
||||
[ "$norestart" != "1" ] && /etc/init.d/dnsmasq restart
|
||||
}
|
||||
|
||||
clear_iptable()
|
||||
@@ -115,7 +128,6 @@ clear_iptable()
|
||||
ip6tables -t nat -D PREROUTING -p udp -d "$IP" --dport 53 -j REDIRECT --to-ports "$OLD_PORT" >/dev/null 2>&1
|
||||
ip6tables -t nat -D PREROUTING -p tcp -d "$IP" --dport 53 -j REDIRECT --to-ports "$OLD_PORT" >/dev/null 2>&1
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
@@ -241,8 +253,8 @@ load_second_server()
|
||||
config_get_bool seconddns_no_cache "$section" "seconddns_no_cache" "0"
|
||||
[ "$seconddns_no_cache" = "1" ] && ARGS="$ARGS -no-cache"
|
||||
|
||||
config_get_bool force_aaaa_soa "$section" "force_aaaa_soa" "0"
|
||||
[ "$force_aaaa_soa" = "1" ] && ARGS="$ARGS -force-aaaa-soa"
|
||||
config_get_bool seconddns_force_aaaa_soa "$section" "seconddns_force_aaaa_soa" "0"
|
||||
[ "$seconddns_force_aaaa_soa" = "1" ] && ARGS="$ARGS -force-aaaa-soa"
|
||||
|
||||
config_get ipv6_server "$section" "ipv6_server" "1"
|
||||
if [ "$ipv6_server" = "1" ]; then
|
||||
@@ -260,6 +272,14 @@ load_service()
|
||||
{
|
||||
local section="$1"
|
||||
args=""
|
||||
dnsmasq_lease_file="$(uci -q get dhcp.@dnsmasq[0].leasefile)"
|
||||
dnsmasq_port="$(uci -q get dhcp.@dnsmasq[0].port)"
|
||||
resolve_file="$(uci -q get dhcp.@dnsmasq[0].resolvfile)"
|
||||
[ -z "$dnsmasq_lease_file" ] && dnsmasq_lease_file="/tmp/dhcp.leases"
|
||||
[ -z "$dnsmasq_port" ] && dnsmasq_port="53"
|
||||
[ -z "$resolve_file" ] && resolve_file="/tmp/resolv.conf.d/resolv.conf.auto"
|
||||
|
||||
qtype_soa_list=""
|
||||
|
||||
mkdir -p $SMARTDNS_VAR_CONF_DIR
|
||||
rm -f $SMARTDNS_CONF_TMP
|
||||
@@ -272,22 +292,10 @@ load_service()
|
||||
config_get coredump "$section" "coredump" "0"
|
||||
[ "$coredump" = "1" ] && COREDUMP="1"
|
||||
|
||||
config_get port "$section" "port" "6053"
|
||||
config_get port "$section" "port" "53"
|
||||
config_get ipv6_server "$section" "ipv6_server" "1"
|
||||
config_get tcp_server "$section" "tcp_server" "1"
|
||||
if [ "$ipv6_server" = "1" ]; then
|
||||
conf_append "bind" "[::]:$port"
|
||||
else
|
||||
conf_append "bind" ":$port"
|
||||
fi
|
||||
|
||||
[ "$tcp_server" = "1" ] && {
|
||||
if [ "$ipv6_server" = "1" ]; then
|
||||
conf_append "bind-tcp" "[::]:$port"
|
||||
else
|
||||
conf_append "bind-tcp" ":$port"
|
||||
fi
|
||||
}
|
||||
config_get dualstack_ip_selection "$section" "dualstack_ip_selection" "0"
|
||||
[ "$dualstack_ip_selection" = "0" ] && conf_append "dualstack-ip-selection" "no"
|
||||
|
||||
@@ -297,11 +305,20 @@ load_service()
|
||||
config_get serve_expired "$section" "serve_expired" "0"
|
||||
[ "$serve_expired" = "1" ] && conf_append "serve-expired" "yes"
|
||||
|
||||
SMARTDNS_PORT="$port"
|
||||
|
||||
config_get cache_size "$section" "cache_size" ""
|
||||
[ -z "$cache_size" ] || conf_append "cache-size" "$cache_size"
|
||||
|
||||
config_get resolve_local_hostnames "$section" "resolve_local_hostnames" "1"
|
||||
[ "$resolve_local_hostnames" = "1" ] && conf_append "dnsmasq-lease-file" "$dnsmasq_lease_file"
|
||||
|
||||
config_get force_aaaa_soa "$section" "force_aaaa_soa" "0"
|
||||
[ "$force_aaaa_soa" = "1" ] && qtype_soa_list="$qtype_soa_list 28"
|
||||
|
||||
config_get force_https_soa "$section" "force_https_soa" "0"
|
||||
[ "$force_https_soa" = "1" ] && qtype_soa_list="$qtype_soa_list 65"
|
||||
|
||||
config_get auto_set_dnsmasq "$section" "auto_set_dnsmasq" "1"
|
||||
|
||||
config_get rr_ttl "$section" "rr_ttl" ""
|
||||
[ -z "$rr_ttl" ] || conf_append "rr-ttl" "$rr_ttl"
|
||||
|
||||
@@ -326,34 +343,85 @@ load_service()
|
||||
config_get log_file "$section" "log_file" ""
|
||||
[ -z "$log_file" ] || conf_append "log-file" "$log_file"
|
||||
|
||||
config_get redirect "$section" "redirect" "none"
|
||||
config_get old_redirect "$section" "old_redirect" "none"
|
||||
config_get redirect "$section" "redirect" ""
|
||||
config_get old_port "$section" "old_port" "0"
|
||||
config_get old_enabled "$section" "old_enabled" "0"
|
||||
config_get old_auto_set_dnsmasq "$section" "old_auto_set_dnsmasq" "0"
|
||||
|
||||
if [ "$old_redirect" != "$redirect" ] || [ "$old_port" != "$SMARTDNS_PORT" ] || [ "$old_enabled" = "1" -a "$enabled" = "0" ]; then
|
||||
[ "$old_redirect" = "none" ] || {
|
||||
[ "$old_port" = "0" ] || clear_iptable "$old_port" "$ipv6_server"
|
||||
[ "$old_redirect" = "dnsmasq-upstream" ] && stop_forward_dnsmasq "$old_port"
|
||||
[ -z "$qtype_soa_list" ] || conf_append "force-qtype-SOA" "$qtype_soa_list"
|
||||
[ -e "$resolve_file" ] && conf_append "resolv-file" "$resolve_file"
|
||||
|
||||
# upgrade old configuration
|
||||
if [ "$redirect" = "redirect" ] || [ "$redirect" = "dnsmasq-upstream" ] || [ "$redirect" = "none" ]; then
|
||||
[ "$redirect" = "redirect" ] && {
|
||||
clear_iptable "$port"
|
||||
clear_iptable "$old_port"
|
||||
uci -q delete smartdns.@smartdns[0].port
|
||||
port="53"
|
||||
}
|
||||
|
||||
[ "$redirect" = "dnsmasq-upstream" ] && {
|
||||
stop_forward_dnsmasq "$port"
|
||||
stop_forward_dnsmasq "$old_port"
|
||||
auto_set_dnsmasq="1"
|
||||
uci -q set smartdns.@smartdns[0].auto_set_dnsmasq="1"
|
||||
}
|
||||
|
||||
[ "$redirect" = "none" ] && {
|
||||
auto_set_dnsmasq="0"
|
||||
uci -q set smartdns.@smartdns[0].auto_set_dnsmasq="0"
|
||||
}
|
||||
uci -q delete smartdns.@smartdns[0].redirect
|
||||
uci -q delete smartdns.@smartdns[0].old_redirect
|
||||
fi
|
||||
|
||||
uci delete smartdns.@smartdns[0].old_redirect 2>/dev/null
|
||||
uci delete smartdns.@smartdns[0].old_port 2>/dev/null
|
||||
uci delete smartdns.@smartdns[0].old_enabled 2>/dev/null
|
||||
uci add_list smartdns.@smartdns[0].old_redirect="$redirect" 2>/dev/null
|
||||
uci add_list smartdns.@smartdns[0].old_port="$SMARTDNS_PORT" 2>/dev/null
|
||||
uci add_list smartdns.@smartdns[0].old_enabled="$enabled" 2>/dev/null
|
||||
uci -q delete smartdns.@smartdns[0].old_port
|
||||
uci -q delete smartdns.@smartdns[0].old_enabled
|
||||
uci -q delete smartdns.@smartdns[0].old_auto_set_dnsmasq
|
||||
uci -q set smartdns.@smartdns[0].old_port="$port"
|
||||
uci -q set smartdns.@smartdns[0].old_enabled="$enabled"
|
||||
uci -q set smartdns.@smartdns[0].old_auto_set_dnsmasq="$auto_set_dnsmasq"
|
||||
uci commit smartdns
|
||||
|
||||
[ "$enabled" -gt 0 ] || return 1
|
||||
# disable service
|
||||
[ "$enabled" = "0" ] && {
|
||||
[ "$old_enabled" = "0" ] && return 1
|
||||
[ "$old_port" = "53" ] && stop_main_dns "0"
|
||||
[ "$old_port" != "53" ] && [ "$old_auto_set_dnsmasq" = "1" ] && stop_forward_dnsmasq "$old_port" "0"
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ "$redirect" = "redirect" ]; then
|
||||
set_iptable $ipv6_server $tcp_server
|
||||
elif [ "$redirect" = "dnsmasq-upstream" ]; then
|
||||
set_forward_dnsmasq "$SMARTDNS_PORT"
|
||||
# change port
|
||||
[ "$old_port" != "$port" ] && {
|
||||
[ "$old_port" = "53" ] && {
|
||||
no_restart_dnsmasq="1"
|
||||
[ "$auto_set_dnsmasq" = "0" ] && no_restart_dnsmasq="0"
|
||||
stop_main_dns "$no_restart_dnsmasq"
|
||||
}
|
||||
[ "$old_port" != "53" ] && [ "$old_auto_set_dnsmasq" = "1" ] && stop_forward_dnsmasq "$old_port" "1"
|
||||
}
|
||||
|
||||
# start service
|
||||
[ "$port" = "53" ] && set_main_dns
|
||||
[ "$port" != "53" ] && {
|
||||
[ "$auto_set_dnsmasq" = "1" ] && set_forward_dnsmasq "$port"
|
||||
[ "$auto_set_dnsmasq" = "0" ] && [ "$old_auto_set_dnsmasq" = "1" ] && stop_forward_dnsmasq "$old_port" "0"
|
||||
}
|
||||
|
||||
if [ "$ipv6_server" = "1" ]; then
|
||||
conf_append "bind" "[::]:$port"
|
||||
else
|
||||
conf_append "bind" ":$port"
|
||||
fi
|
||||
|
||||
[ "$tcp_server" = "1" ] && {
|
||||
if [ "$ipv6_server" = "1" ]; then
|
||||
conf_append "bind-tcp" "[::]:$port"
|
||||
else
|
||||
conf_append "bind-tcp" ":$port"
|
||||
fi
|
||||
}
|
||||
|
||||
load_second_server $section
|
||||
|
||||
config_foreach load_server "server"
|
||||
@@ -381,6 +449,28 @@ load_service()
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
unload_service()
|
||||
{
|
||||
local section="$1"
|
||||
dnsmasq_port="$(uci -q get dhcp.@dnsmasq[0].port)"
|
||||
config_get port "$section" "port" "53"
|
||||
config_get old_port "$section" "old_port" "0"
|
||||
config_get auto_set_dnsmasq "$section" "auto_set_dnsmasq" "0"
|
||||
[ -z "${dnsmasq_port}" ] && dnsmasq_port="53"
|
||||
|
||||
[ "$enabled" = "1" ] && {
|
||||
[ "$old_enabled" = "0" ] && return 1
|
||||
[ "$old_port" = "53" ] && stop_main_dns "0"
|
||||
[ "$old_port" != "53" ] && [ "$old_auto_set_dnsmasq" = "1" ] && stop_forward_dnsmasq "$old_port" "0"
|
||||
}
|
||||
}
|
||||
|
||||
service_stopped()
|
||||
{
|
||||
config_load "smartdns"
|
||||
config_foreach unload_service "smartdns"
|
||||
}
|
||||
|
||||
start_service()
|
||||
{
|
||||
config_load "smartdns"
|
||||
|
||||
@@ -22,6 +22,7 @@ SMARTDNS_PID=/var/run/smartdns.pid
|
||||
SMARTDNS_PORT=535
|
||||
SMARTDNS_OPT=/opt/etc/smartdns/smartdns-opt.conf
|
||||
# workmode
|
||||
# DO NOT CHANGE THIS, CHANGE MODE IN smartdns-opt.conf
|
||||
# 0: run as port only
|
||||
# 1: redirect port
|
||||
# 2: replace
|
||||
@@ -232,11 +233,11 @@ set_smartdns_port()
|
||||
if [ "$SMARTDNS_WORKMODE" = "0" ]; then
|
||||
return 0
|
||||
elif [ "$SMARTDNS_WORKMODE" = "1" ]; then
|
||||
sed -i "s/^\\(bind .*\\):53 *\\(.*\\)\$/\\1:$SMARTDNS_PORT \\2/g" $SMARTDNS_CONF
|
||||
sed -i "s/^\\(bind-tcp .*\\):53 *\\(.*\\)\$/\\1:$SMARTDNS_PORT \\2/g" $SMARTDNS_CONF
|
||||
sed -i "s/^\(bind .*\):53\( .*\)\?$/\1:$SMARTDNS_PORT \2/g" $SMARTDNS_CONF
|
||||
sed -i "s/^\(bind-tcp .*\):53\( .*\)\?$/\1:$SMARTDNS_PORT \2/g" $SMARTDNS_CONF
|
||||
elif [ "$SMARTDNS_WORKMODE" = "2" ]; then
|
||||
sed -i "s/^\\(bind .*\\):$SMARTDNS_PORT *\\(.*\\)\$/\\1:53 \\2/g" $SMARTDNS_CONF
|
||||
sed -i "s/^\\(bind-tcp .*\\):$SMARTDNS_PORT *\\(.*\\)\$/\\1:53 \\2/g" $SMARTDNS_CONF
|
||||
sed -i "s/^\(bind .*\):$SMARTDNS_PORT\( .*\)\?$/\1:53 \2/g" $SMARTDNS_CONF
|
||||
sed -i "s/^\(bind-tcp .*\):$SMARTDNS_PORT\( .*\)\?$/\1:53 \2/g" $SMARTDNS_CONF
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -23,9 +23,9 @@ ifndef CFLAGS
|
||||
CFLAGS =-O2 -g -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough
|
||||
endif
|
||||
override CFLAGS +=-Iinclude
|
||||
override CFLAGS += -DBASE_FILE_NAME=\"$(notdir $<)\"
|
||||
override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"'
|
||||
ifdef VER
|
||||
override CFLAGS += -DSMARTDNS_VERION=\"$(VER)\"
|
||||
override CFLAGS += -DSMARTDNS_VERION='"$(VER)"'
|
||||
endif
|
||||
|
||||
CXXFLAGS=-O2 -g -Wall -std=c++11
|
||||
|
||||
20
src/dns.c
20
src/dns.c
@@ -43,7 +43,7 @@
|
||||
} while (0)
|
||||
|
||||
/* read short and move pointer */
|
||||
static short _dns_read_short(unsigned char **buffer)
|
||||
static unsigned short _dns_read_short(unsigned char **buffer)
|
||||
{
|
||||
unsigned short value = 0;
|
||||
|
||||
@@ -549,6 +549,10 @@ static int _dns_add_RAW(struct dns_packet *packet, dns_rr_type rrtype, dns_type_
|
||||
struct dns_context context;
|
||||
int ret = 0;
|
||||
|
||||
if (raw_len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* resource record */
|
||||
/* |domain |
|
||||
* |qtype | qclass |
|
||||
@@ -1153,6 +1157,11 @@ static int _dns_decode_rr_head(struct dns_context *context, char *domain, int do
|
||||
*ttl = _dns_read_int(&context->ptr);
|
||||
*rr_len = _dns_read_short(&context->ptr);
|
||||
|
||||
if (*rr_len < 0 || *ttl < 0) {
|
||||
tlog(TLOG_DEBUG, "rr len or ttl is invalid.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1233,7 +1242,7 @@ static int _dns_encode_raw(struct dns_context *context, struct dns_rrs *rrs)
|
||||
|
||||
static int _dns_decode_raw(struct dns_context *context, unsigned char *raw, int len)
|
||||
{
|
||||
if (_dns_left_len(context) < len) {
|
||||
if (_dns_left_len(context) < len || len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1595,6 +1604,11 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
|
||||
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|
||||
*/
|
||||
|
||||
if (rr_len < 0) {
|
||||
tlog(TLOG_DEBUG, "opt len is invalid.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ercode != 0) {
|
||||
tlog(TLOG_ERROR, "extend rcode invalid.");
|
||||
return -1;
|
||||
@@ -1682,7 +1696,7 @@ static int _dns_decode_an(struct dns_context *context, dns_rr_type type)
|
||||
|
||||
/* decode rr head */
|
||||
ret = _dns_decode_rr_head(context, domain, DNS_MAX_CNAME_LEN, &qtype, &qclass, &ttl, &rr_len);
|
||||
if (ret < 0) {
|
||||
if (ret < 0 || qclass < 0) {
|
||||
tlog(TLOG_DEBUG, "decode head failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -128,9 +128,14 @@ enum CACHE_TYPE dns_cache_data_type(struct dns_cache_data *cache_data)
|
||||
return cache_data->head.cache_type;
|
||||
}
|
||||
|
||||
uint32_t dns_cache_get_cache_flag(struct dns_cache_data *cache_data)
|
||||
uint32_t dns_cache_get_query_flag(struct dns_cache_data *cache_data)
|
||||
{
|
||||
return cache_data->head.cache_flag;
|
||||
return cache_data->head.query_flag;
|
||||
}
|
||||
|
||||
const char *dns_cache_get_dns_group_name(struct dns_cache_data *cache_data)
|
||||
{
|
||||
return cache_data->head.dns_group_name;
|
||||
}
|
||||
|
||||
void dns_cache_data_free(struct dns_cache_data *data)
|
||||
@@ -156,7 +161,8 @@ struct dns_cache_data *dns_cache_new_data(void)
|
||||
return (struct dns_cache_data *)cache_addr;
|
||||
}
|
||||
|
||||
void dns_cache_set_data_soa(struct dns_cache_data *dns_cache, int32_t cache_flag, char *cname, int cname_ttl)
|
||||
void dns_cache_set_data_soa(struct dns_cache_data *dns_cache, struct dns_cache_query_option *query_option, char *cname,
|
||||
int cname_ttl)
|
||||
{
|
||||
if (dns_cache == NULL) {
|
||||
goto errout;
|
||||
@@ -179,7 +185,13 @@ void dns_cache_set_data_soa(struct dns_cache_data *dns_cache, int32_t cache_flag
|
||||
cache_addr->addr_data.cname_ttl = cname_ttl;
|
||||
}
|
||||
|
||||
cache_addr->head.cache_flag = cache_flag;
|
||||
if (query_option) {
|
||||
cache_addr->head.query_flag = query_option->query_flag;
|
||||
if (query_option->dns_group_name) {
|
||||
safe_strncpy(cache_addr->head.dns_group_name, query_option->dns_group_name, DNS_CACHE_GROUP_NAME_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
cache_addr->addr_data.soa = 1;
|
||||
cache_addr->head.cache_type = CACHE_TYPE_ADDR;
|
||||
cache_addr->head.size = sizeof(struct dns_cache_addr) - sizeof(struct dns_cache_data_head);
|
||||
@@ -187,8 +199,8 @@ errout:
|
||||
return;
|
||||
}
|
||||
|
||||
void dns_cache_set_data_addr(struct dns_cache_data *dns_cache, uint32_t cache_flag, char *cname, int cname_ttl,
|
||||
unsigned char *addr, int addr_len)
|
||||
void dns_cache_set_data_addr(struct dns_cache_data *dns_cache, struct dns_cache_query_option *query_option, char *cname,
|
||||
int cname_ttl, unsigned char *addr, int addr_len)
|
||||
{
|
||||
if (dns_cache == NULL) {
|
||||
goto errout;
|
||||
@@ -212,14 +224,21 @@ void dns_cache_set_data_addr(struct dns_cache_data *dns_cache, uint32_t cache_fl
|
||||
cache_addr->addr_data.cname_ttl = cname_ttl;
|
||||
}
|
||||
|
||||
cache_addr->head.cache_flag = cache_flag;
|
||||
if (query_option) {
|
||||
cache_addr->head.query_flag = query_option->query_flag;
|
||||
if (query_option->dns_group_name) {
|
||||
safe_strncpy(cache_addr->head.dns_group_name, query_option->dns_group_name, DNS_CACHE_GROUP_NAME_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
cache_addr->head.cache_type = CACHE_TYPE_ADDR;
|
||||
cache_addr->head.size = sizeof(struct dns_cache_addr) - sizeof(struct dns_cache_data_head);
|
||||
errout:
|
||||
return;
|
||||
}
|
||||
|
||||
struct dns_cache_data *dns_cache_new_data_packet(uint32_t cache_flag, void *packet, size_t packet_len)
|
||||
struct dns_cache_data *dns_cache_new_data_packet(struct dns_cache_query_option *query_option, void *packet,
|
||||
size_t packet_len)
|
||||
{
|
||||
struct dns_cache_packet *cache_packet = NULL;
|
||||
size_t data_size = 0;
|
||||
@@ -236,7 +255,12 @@ struct dns_cache_data *dns_cache_new_data_packet(uint32_t cache_flag, void *pack
|
||||
memcpy(cache_packet->data, packet, packet_len);
|
||||
memset(&cache_packet->head, 0, sizeof(cache_packet->head));
|
||||
|
||||
cache_packet->head.cache_flag = cache_flag;
|
||||
if (query_option) {
|
||||
cache_packet->head.query_flag = query_option->query_flag;
|
||||
if (query_option->dns_group_name) {
|
||||
strncpy(cache_packet->head.dns_group_name, query_option->dns_group_name, DNS_CACHE_GROUP_NAME_LEN - 1);
|
||||
}
|
||||
}
|
||||
cache_packet->head.cache_type = CACHE_TYPE_PACKET;
|
||||
cache_packet->head.size = packet_len;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ extern "C" {
|
||||
|
||||
#define DNS_CACHE_TTL_MIN 1
|
||||
#define DNS_CACHE_VERSION_LEN 32
|
||||
#define DNS_CACHE_GROUP_NAME_LEN 32
|
||||
#define MAGIC_NUMBER 0x6548634163536e44
|
||||
#define MAGIC_CACHE_DATA 0x44615461
|
||||
|
||||
@@ -47,9 +48,15 @@ enum CACHE_RECORD_TYPE {
|
||||
CACHE_RECORD_TYPE_INACTIVE,
|
||||
};
|
||||
|
||||
struct dns_cache_query_option {
|
||||
uint32_t query_flag;
|
||||
const char *dns_group_name;
|
||||
};
|
||||
|
||||
struct dns_cache_data_head {
|
||||
uint32_t cache_flag;
|
||||
enum CACHE_TYPE cache_type;
|
||||
uint32_t query_flag;
|
||||
char dns_group_name[DNS_CACHE_GROUP_NAME_LEN];
|
||||
int is_soa;
|
||||
ssize_t size;
|
||||
};
|
||||
@@ -115,11 +122,14 @@ struct dns_cache_file {
|
||||
|
||||
enum CACHE_TYPE dns_cache_data_type(struct dns_cache_data *cache_data);
|
||||
|
||||
uint32_t dns_cache_get_cache_flag(struct dns_cache_data *cache_data);
|
||||
uint32_t dns_cache_get_query_flag(struct dns_cache_data *cache_data);
|
||||
|
||||
const char *dns_cache_get_dns_group_name(struct dns_cache_data *cache_data);
|
||||
|
||||
void dns_cache_data_free(struct dns_cache_data *data);
|
||||
|
||||
struct dns_cache_data *dns_cache_new_data_packet(uint32_t cache_flag, void *packet, size_t packet_len);
|
||||
struct dns_cache_data *dns_cache_new_data_packet(struct dns_cache_query_option *query_option, void *packet,
|
||||
size_t packet_len);
|
||||
|
||||
int dns_cache_init(int size, int enable_inactive, int inactive_list_expired);
|
||||
|
||||
@@ -156,10 +166,11 @@ struct dns_cache_data *dns_cache_new_data(void);
|
||||
|
||||
struct dns_cache_data *dns_cache_get_data(struct dns_cache *dns_cache);
|
||||
|
||||
void dns_cache_set_data_addr(struct dns_cache_data *dns_cache, uint32_t cache_flag, char *cname, int cname_ttl,
|
||||
unsigned char *addr, int addr_len);
|
||||
void dns_cache_set_data_addr(struct dns_cache_data *dns_cache, struct dns_cache_query_option *query_option, char *cname,
|
||||
int cname_ttl, unsigned char *addr, int addr_len);
|
||||
|
||||
void dns_cache_set_data_soa(struct dns_cache_data *dns_cache, int32_t cache_flag, char *cname, int cname_ttl);
|
||||
void dns_cache_set_data_soa(struct dns_cache_data *dns_cache, struct dns_cache_query_option *query_option, char *cname,
|
||||
int cname_ttl);
|
||||
|
||||
void dns_cache_destroy(void);
|
||||
|
||||
|
||||
@@ -1416,10 +1416,6 @@ static void _dns_client_query_remove(struct dns_query_struct *query)
|
||||
{
|
||||
/* remove query from period check list, and release reference*/
|
||||
pthread_mutex_lock(&client.domain_map_lock);
|
||||
if (list_empty(&query->dns_request_list)) {
|
||||
pthread_mutex_unlock(&client.domain_map_lock);
|
||||
return;
|
||||
}
|
||||
list_del_init(&query->dns_request_list);
|
||||
hash_del(&query->domain_node);
|
||||
pthread_mutex_unlock(&client.domain_map_lock);
|
||||
@@ -3014,11 +3010,6 @@ static int _dns_client_query_setup_default_ecs(struct dns_query_struct *query)
|
||||
|
||||
static int _dns_client_query_parser_options(struct dns_query_struct *query, struct dns_query_options *options)
|
||||
{
|
||||
if (options == NULL) {
|
||||
_dns_client_query_setup_default_ecs(query);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (options->enable_flag & DNS_QUEY_OPTION_ECS_IP) {
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
@@ -3073,6 +3064,10 @@ static int _dns_client_query_parser_options(struct dns_query_struct *query, stru
|
||||
query->ecs.enable = 1;
|
||||
}
|
||||
|
||||
if (query->ecs.enable == 0) {
|
||||
_dns_client_query_setup_default_ecs(query);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
445
src/dns_conf.c
445
src/dns_conf.c
@@ -32,6 +32,7 @@
|
||||
|
||||
#define DEFAULT_DNS_CACHE_SIZE 512
|
||||
#define DNS_MAX_REPLY_IP_NUM 8
|
||||
#define DNS_RESOLV_FILE "/etc/resolv.conf"
|
||||
|
||||
/* ipset */
|
||||
struct dns_ipset_table {
|
||||
@@ -41,6 +42,9 @@ static struct dns_ipset_table dns_ipset_table;
|
||||
|
||||
struct dns_qtype_soa_table dns_qtype_soa_table;
|
||||
|
||||
struct dns_domain_set_rule_table dns_domain_set_rule_table;
|
||||
struct dns_domain_set_name_table dns_domain_set_name_table;
|
||||
|
||||
/* dns groups */
|
||||
struct dns_group_table dns_group_table;
|
||||
|
||||
@@ -124,6 +128,7 @@ int dns_conf_rr_ttl;
|
||||
int dns_conf_rr_ttl_reply_max;
|
||||
int dns_conf_rr_ttl_min = 600;
|
||||
int dns_conf_rr_ttl_max;
|
||||
int dns_conf_local_ttl;
|
||||
int dns_conf_force_AAAA_SOA;
|
||||
int dns_conf_force_no_cname;
|
||||
int dns_conf_ipset_timeout_enable;
|
||||
@@ -132,6 +137,7 @@ char dns_conf_user[DNS_CONF_USRNAME_LEN];
|
||||
|
||||
int dns_save_fail_packet;
|
||||
char dns_save_fail_packet_dir[DNS_MAX_PATH];
|
||||
char dns_resolv_file[DNS_MAX_PATH];
|
||||
|
||||
/* ECS */
|
||||
struct dns_edns_client_subnet dns_conf_ipv4_ecs;
|
||||
@@ -139,6 +145,62 @@ struct dns_edns_client_subnet dns_conf_ipv6_ecs;
|
||||
|
||||
char dns_conf_sni_proxy_ip[DNS_MAX_IPLEN];
|
||||
|
||||
static void *_new_dns_rule(enum domain_rule domain_rule)
|
||||
{
|
||||
struct dns_rule *rule;
|
||||
int size = 0;
|
||||
|
||||
if (domain_rule >= DOMAIN_RULE_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (domain_rule) {
|
||||
case DOMAIN_RULE_FLAGS:
|
||||
size = sizeof(struct dns_rule_flags);
|
||||
break;
|
||||
case DOMAIN_RULE_ADDRESS_IPV4:
|
||||
size = sizeof(struct dns_rule_address_IPV4);
|
||||
break;
|
||||
case DOMAIN_RULE_ADDRESS_IPV6:
|
||||
size = sizeof(struct dns_rule_address_IPV6);
|
||||
break;
|
||||
case DOMAIN_RULE_IPSET:
|
||||
case DOMAIN_RULE_IPSET_IPV4:
|
||||
case DOMAIN_RULE_IPSET_IPV6:
|
||||
size = sizeof(struct dns_ipset_rule);
|
||||
break;
|
||||
case DOMAIN_RULE_NAMESERVER:
|
||||
size = sizeof(struct dns_nameserver_rule);
|
||||
break;
|
||||
case DOMAIN_RULE_CHECKSPEED:
|
||||
size = sizeof(struct dns_domain_check_orders);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rule = malloc(size);
|
||||
if (!rule) {
|
||||
return NULL;
|
||||
}
|
||||
memset(rule, 0, size);
|
||||
rule->rule = domain_rule;
|
||||
atomic_set(&rule->refcnt, 1);
|
||||
return rule;
|
||||
}
|
||||
|
||||
static void _dns_rule_get(struct dns_rule *rule)
|
||||
{
|
||||
atomic_inc(&rule->refcnt);
|
||||
}
|
||||
|
||||
static void _dns_rule_put(struct dns_rule *rule)
|
||||
{
|
||||
if (atomic_dec_and_test(&rule->refcnt)) {
|
||||
free(rule);
|
||||
}
|
||||
}
|
||||
|
||||
static int _get_domain(char *value, char *domain, int max_dmain_size, char **ptr_after_domain)
|
||||
{
|
||||
char *begin = NULL;
|
||||
@@ -428,7 +490,8 @@ static int _config_domain_iter_free(void *data, const unsigned char *key, uint32
|
||||
continue;
|
||||
}
|
||||
|
||||
free(domain_rule->rules[i]);
|
||||
_dns_rule_put(domain_rule->rules[i]);
|
||||
domain_rule->rules[i] = NULL;
|
||||
}
|
||||
|
||||
free(domain_rule);
|
||||
@@ -455,6 +518,69 @@ static void _config_address_destroy(radix_node_t *node, void *cbctx)
|
||||
node->data = NULL;
|
||||
}
|
||||
|
||||
static int _config_domain_set_rule_add_ext(char *set_name, enum domain_rule type, void *rule, unsigned int flags, int is_clear_flag)
|
||||
{
|
||||
struct dns_domain_set_rule *set_rule = NULL;
|
||||
struct dns_domain_set_rule_list *set_rule_list = NULL;
|
||||
uint32_t key = 0;
|
||||
|
||||
if (set_name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
set_rule = malloc(sizeof(struct dns_domain_set_rule));
|
||||
if (set_rule == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
memset(set_rule, 0, sizeof(struct dns_domain_set_rule));
|
||||
|
||||
set_rule->type = type;
|
||||
set_rule->rule = rule;
|
||||
set_rule->flags = flags;
|
||||
set_rule->is_clear_flag = is_clear_flag;
|
||||
|
||||
if (rule) {
|
||||
_dns_rule_get(rule);
|
||||
}
|
||||
|
||||
key = hash_string(set_name);
|
||||
hash_for_each_possible(dns_domain_set_rule_table.rule_list, set_rule_list, node, key)
|
||||
{
|
||||
if (strncmp(set_rule_list->domain_set, set_name, DNS_MAX_CNAME_LEN) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (set_rule_list == NULL) {
|
||||
set_rule_list = malloc(sizeof(struct dns_domain_set_rule_list));
|
||||
if (set_rule_list == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
memset(set_rule_list, 0, sizeof(struct dns_domain_set_rule_list));
|
||||
INIT_LIST_HEAD(&set_rule_list->domain_ruls_list);
|
||||
safe_strncpy(set_rule_list->domain_set, set_name, DNS_MAX_CNAME_LEN);
|
||||
hash_add(dns_domain_set_rule_table.rule_list, &set_rule_list->node, key);
|
||||
}
|
||||
|
||||
list_add_tail(&set_rule->list, &set_rule_list->domain_ruls_list);
|
||||
return 0;
|
||||
errout:
|
||||
if (set_rule) {
|
||||
free(set_rule);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int _config_domian_set_rule_flags(char *set_name, unsigned int flags, int is_clear_flag)
|
||||
{
|
||||
return _config_domain_set_rule_add_ext(set_name, DOMAIN_RULE_FLAGS, NULL, flags, is_clear_flag);
|
||||
}
|
||||
|
||||
static int _config_domain_set_rule_add(char *set_name, enum domain_rule type, void *rule)
|
||||
{
|
||||
return _config_domain_set_rule_add_ext(set_name, type, rule, 0, 0);
|
||||
}
|
||||
|
||||
static int _config_domain_rule_add(char *domain, enum domain_rule type, void *rule)
|
||||
{
|
||||
struct dns_domain_rule *domain_rule = NULL;
|
||||
@@ -470,6 +596,11 @@ static int _config_domain_rule_add(char *domain, enum domain_rule type, void *ru
|
||||
tlog(TLOG_ERROR, "domain name %s too long", domain);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (strncmp(domain, "domain-set:", sizeof("domain-set:") - 1) == 0) {
|
||||
return _config_domain_set_rule_add(domain + sizeof("domain-set:") - 1, type, rule);
|
||||
}
|
||||
|
||||
reverse_string(domain_key, domain, len, 1);
|
||||
domain_key[len] = '.';
|
||||
len++;
|
||||
@@ -492,11 +623,12 @@ static int _config_domain_rule_add(char *domain, enum domain_rule type, void *ru
|
||||
|
||||
/* add new rule to domain */
|
||||
if (domain_rule->rules[type]) {
|
||||
free(domain_rule->rules[type]);
|
||||
_dns_rule_put(domain_rule->rules[type]);
|
||||
domain_rule->rules[type] = NULL;
|
||||
}
|
||||
|
||||
domain_rule->rules[type] = rule;
|
||||
_dns_rule_get(rule);
|
||||
|
||||
/* update domain rule */
|
||||
if (add_domain_rule) {
|
||||
@@ -526,6 +658,10 @@ static int _config_domain_rule_flag_set(char *domain, unsigned int flag, unsigne
|
||||
char domain_key[DNS_MAX_CONF_CNAME_LEN];
|
||||
int len = 0;
|
||||
|
||||
if (strncmp(domain, "domain-set:", sizeof("domain-set:") - 1) == 0) {
|
||||
return _config_domian_set_rule_flags(domain + sizeof("domain-set:") - 1, flag, is_clear);
|
||||
}
|
||||
|
||||
len = strlen(domain);
|
||||
if (len >= (int)sizeof(domain_key)) {
|
||||
tlog(TLOG_ERROR, "domain %s too long", domain);
|
||||
@@ -549,13 +685,12 @@ static int _config_domain_rule_flag_set(char *domain, unsigned int flag, unsigne
|
||||
|
||||
/* add new rule to domain */
|
||||
if (domain_rule->rules[DOMAIN_RULE_FLAGS] == NULL) {
|
||||
rule_flags = malloc(sizeof(*rule_flags));
|
||||
memset(rule_flags, 0, sizeof(*rule_flags));
|
||||
rule_flags = _new_dns_rule(DOMAIN_RULE_FLAGS);
|
||||
rule_flags->flags = 0;
|
||||
domain_rule->rules[DOMAIN_RULE_FLAGS] = rule_flags;
|
||||
domain_rule->rules[DOMAIN_RULE_FLAGS] = (struct dns_rule *)rule_flags;
|
||||
}
|
||||
|
||||
rule_flags = domain_rule->rules[DOMAIN_RULE_FLAGS];
|
||||
rule_flags = (struct dns_rule_flags *)domain_rule->rules[DOMAIN_RULE_FLAGS];
|
||||
if (is_clear == false) {
|
||||
rule_flags->flags |= flag;
|
||||
} else {
|
||||
@@ -667,7 +802,7 @@ static int _conf_domain_rule_ipset(char *domain, const char *ipsetname)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ipset_rule = malloc(sizeof(*ipset_rule));
|
||||
ipset_rule = _new_dns_rule(type);
|
||||
if (ipset_rule == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
@@ -677,6 +812,7 @@ static int _conf_domain_rule_ipset(char *domain, const char *ipsetname)
|
||||
if (_config_domain_rule_add(domain, type, ipset_rule) != 0) {
|
||||
goto errout;
|
||||
}
|
||||
_dns_rule_put(&ipset_rule->head);
|
||||
}
|
||||
|
||||
goto clear;
|
||||
@@ -685,7 +821,7 @@ errout:
|
||||
tlog(TLOG_ERROR, "add ipset %s failed", ipsetname);
|
||||
|
||||
if (ipset_rule) {
|
||||
free(ipset_rule);
|
||||
_dns_rule_put(&ipset_rule->head);
|
||||
}
|
||||
|
||||
clear:
|
||||
@@ -717,9 +853,9 @@ errout:
|
||||
|
||||
static int _conf_domain_rule_address(char *domain, const char *domain_address)
|
||||
{
|
||||
struct dns_address_IPV4 *address_ipv4 = NULL;
|
||||
struct dns_address_IPV6 *address_ipv6 = NULL;
|
||||
void *address = NULL;
|
||||
struct dns_rule_address_IPV4 *address_ipv4 = NULL;
|
||||
struct dns_rule_address_IPV6 *address_ipv6 = NULL;
|
||||
struct dns_rule *address = NULL;
|
||||
char ip[MAX_IP_LEN];
|
||||
int port = 0;
|
||||
struct sockaddr_storage addr;
|
||||
@@ -774,7 +910,7 @@ static int _conf_domain_rule_address(char *domain, const char *domain_address)
|
||||
switch (addr.ss_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *addr_in = NULL;
|
||||
address_ipv4 = malloc(sizeof(*address_ipv4));
|
||||
address_ipv4 = _new_dns_rule(DOMAIN_RULE_ADDRESS_IPV4);
|
||||
if (address_ipv4 == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
@@ -782,27 +918,27 @@ static int _conf_domain_rule_address(char *domain, const char *domain_address)
|
||||
addr_in = (struct sockaddr_in *)&addr;
|
||||
memcpy(address_ipv4->ipv4_addr, &addr_in->sin_addr.s_addr, 4);
|
||||
type = DOMAIN_RULE_ADDRESS_IPV4;
|
||||
address = address_ipv4;
|
||||
address = (struct dns_rule *)address_ipv4;
|
||||
} break;
|
||||
case AF_INET6: {
|
||||
struct sockaddr_in6 *addr_in6 = NULL;
|
||||
addr_in6 = (struct sockaddr_in6 *)&addr;
|
||||
if (IN6_IS_ADDR_V4MAPPED(&addr_in6->sin6_addr)) {
|
||||
address_ipv4 = malloc(sizeof(*address_ipv4));
|
||||
address_ipv4 = _new_dns_rule(DOMAIN_RULE_ADDRESS_IPV4);
|
||||
if (address_ipv4 == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
memcpy(address_ipv4->ipv4_addr, addr_in6->sin6_addr.s6_addr + 12, 4);
|
||||
type = DOMAIN_RULE_ADDRESS_IPV4;
|
||||
address = address_ipv4;
|
||||
address = (struct dns_rule *)address_ipv4;
|
||||
} else {
|
||||
address_ipv6 = malloc(sizeof(*address_ipv6));
|
||||
address_ipv6 = _new_dns_rule(DOMAIN_RULE_ADDRESS_IPV6);
|
||||
if (address_ipv6 == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
memcpy(address_ipv6->ipv6_addr, addr_in6->sin6_addr.s6_addr, 16);
|
||||
type = DOMAIN_RULE_ADDRESS_IPV6;
|
||||
address = address_ipv6;
|
||||
address = (struct dns_rule *)address_ipv6;
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
@@ -815,10 +951,11 @@ static int _conf_domain_rule_address(char *domain, const char *domain_address)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
_dns_rule_put(address);
|
||||
return 0;
|
||||
errout:
|
||||
if (address) {
|
||||
free(address);
|
||||
_dns_rule_put(address);
|
||||
}
|
||||
|
||||
tlog(TLOG_ERROR, "add address %s, %s failed", domain, domain_address);
|
||||
@@ -854,7 +991,6 @@ static int _config_speed_check_mode_parser(struct dns_domain_check_orders *check
|
||||
int i = 0;
|
||||
|
||||
safe_strncpy(tmpbuff, mode, DNS_MAX_OPT_LEN);
|
||||
memset(check_orders, 0, sizeof(*check_orders));
|
||||
|
||||
ptr = tmpbuff;
|
||||
do {
|
||||
@@ -1085,7 +1221,7 @@ static int _conf_domain_rule_nameserver(char *domain, const char *group_name)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
nameserver_rule = malloc(sizeof(*nameserver_rule));
|
||||
nameserver_rule = _new_dns_rule(DOMAIN_RULE_NAMESERVER);
|
||||
if (nameserver_rule == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
@@ -1104,10 +1240,12 @@ static int _conf_domain_rule_nameserver(char *domain, const char *group_name)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
_dns_rule_put(&nameserver_rule->head);
|
||||
|
||||
return 0;
|
||||
errout:
|
||||
if (nameserver_rule) {
|
||||
free(nameserver_rule);
|
||||
_dns_rule_put(&nameserver_rule->head);
|
||||
}
|
||||
|
||||
tlog(TLOG_ERROR, "add nameserver %s, %s failed", domain, group_name);
|
||||
@@ -1262,6 +1400,50 @@ static void _config_qtype_soa_table_destroy(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void _config_domain_set_name_table_destroy(void)
|
||||
{
|
||||
struct dns_domain_set_name_list *set_name_list = NULL;
|
||||
struct hlist_node *tmp = NULL;
|
||||
struct dns_domain_set_name *set_name = NULL;
|
||||
struct dns_domain_set_name *tmp1 = NULL;
|
||||
unsigned long i = 0;
|
||||
|
||||
hash_for_each_safe(dns_domain_set_name_table.names, i, tmp, set_name_list, node)
|
||||
{
|
||||
hlist_del_init(&set_name_list->node);
|
||||
list_for_each_entry_safe(set_name, tmp1, &set_name_list->set_name_list, list)
|
||||
{
|
||||
list_del(&set_name->list);
|
||||
free(set_name);
|
||||
}
|
||||
|
||||
free(set_name_list);
|
||||
}
|
||||
}
|
||||
|
||||
static void _config_domain_set_rule_table_destroy(void)
|
||||
{
|
||||
struct dns_domain_set_rule_list *set_rule_list = NULL;
|
||||
struct hlist_node *tmp = NULL;
|
||||
struct dns_domain_set_rule *set_rule = NULL;
|
||||
struct dns_domain_set_rule *tmp1 = NULL;
|
||||
unsigned long i = 0;
|
||||
|
||||
hash_for_each_safe(dns_domain_set_rule_table.rule_list, i, tmp, set_rule_list, node)
|
||||
{
|
||||
hlist_del_init(&set_rule_list->node);
|
||||
list_for_each_entry_safe(set_rule, tmp1, &set_rule_list->domain_ruls_list, list)
|
||||
{
|
||||
list_del(&set_rule->list);
|
||||
if (set_rule->rule) {
|
||||
_dns_rule_put(set_rule->rule);
|
||||
}
|
||||
free(set_rule);
|
||||
}
|
||||
free(set_rule_list);
|
||||
}
|
||||
}
|
||||
|
||||
static int _config_blacklist_ip(void *data, int argc, char *argv[])
|
||||
{
|
||||
if (argc <= 1) {
|
||||
@@ -1352,11 +1534,10 @@ static int _conf_domain_rule_speed_check(char *domain, const char *mode)
|
||||
{
|
||||
struct dns_domain_check_orders *check_orders = NULL;
|
||||
|
||||
check_orders = malloc(sizeof(*check_orders) * DOMAIN_CHECK_NUM);
|
||||
check_orders = _new_dns_rule(DOMAIN_RULE_CHECKSPEED);
|
||||
if (check_orders == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
memset(check_orders, 0, sizeof(*check_orders));
|
||||
|
||||
if (_config_speed_check_mode_parser(check_orders, mode) != 0) {
|
||||
goto errout;
|
||||
@@ -1366,14 +1547,111 @@ static int _conf_domain_rule_speed_check(char *domain, const char *mode)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
_dns_rule_put(&check_orders->head);
|
||||
return 0;
|
||||
errout:
|
||||
if (check_orders) {
|
||||
free(check_orders);
|
||||
_dns_rule_put(&check_orders->head);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _conf_domain_set(void *data, int argc, char *argv[])
|
||||
{
|
||||
int opt = 0;
|
||||
uint32_t key = 0;
|
||||
struct dns_domain_set_name *domain_set = NULL;
|
||||
struct dns_domain_set_name_list *domain_set_name_list = NULL;
|
||||
char set_name[DNS_MAX_CNAME_LEN] = {0};
|
||||
|
||||
/* clang-format off */
|
||||
static struct option long_options[] = {
|
||||
{"name", required_argument, NULL, 'n'},
|
||||
{"type", required_argument, NULL, 't'},
|
||||
{"file", required_argument, NULL, 'f'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
if (argc <= 1) {
|
||||
tlog(TLOG_ERROR, "invalid parameter.");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
domain_set = malloc(sizeof(*domain_set));
|
||||
if (domain_set == NULL) {
|
||||
tlog(TLOG_ERROR, "cannot malloc memory.");
|
||||
goto errout;
|
||||
}
|
||||
memset(domain_set, 0, sizeof(*domain_set));
|
||||
INIT_LIST_HEAD(&domain_set->list);
|
||||
|
||||
optind = 1;
|
||||
while (1) {
|
||||
opt = getopt_long_only(argc, argv, "n:t:f:", long_options, NULL);
|
||||
if (opt == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
safe_strncpy(set_name, optarg, DNS_MAX_CNAME_LEN);
|
||||
break;
|
||||
case 't': {
|
||||
const char *type = optarg;
|
||||
if (strncmp(type, "list", 5) == 0) {
|
||||
domain_set->type = DNS_DOMAIN_SET_LIST;
|
||||
} else if (strncmp(type, "geosite", 7) == 0) {
|
||||
domain_set->type = DNS_DOMAIN_SET_GEOSITE;
|
||||
} else {
|
||||
tlog(TLOG_ERROR, "invalid domain set type.");
|
||||
goto errout;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
conf_get_conf_fullpath(optarg, domain_set->file, DNS_MAX_PATH);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* clang-format on */
|
||||
|
||||
if (set_name[0] == 0 || domain_set->file[0] == 0) {
|
||||
tlog(TLOG_ERROR, "invalid parameter.");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
key = hash_string(set_name);
|
||||
hash_for_each_possible(dns_domain_set_name_table.names, domain_set_name_list, node, key)
|
||||
{
|
||||
if (strcmp(domain_set_name_list->name, set_name) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (domain_set_name_list == NULL) {
|
||||
domain_set_name_list = malloc(sizeof(*domain_set_name_list));
|
||||
if (domain_set_name_list == NULL) {
|
||||
tlog(TLOG_ERROR, "cannot malloc memory.");
|
||||
goto errout;
|
||||
}
|
||||
memset(domain_set_name_list, 0, sizeof(*domain_set_name_list));
|
||||
INIT_LIST_HEAD(&domain_set_name_list->set_name_list);
|
||||
safe_strncpy(domain_set_name_list->name, set_name, DNS_MAX_CNAME_LEN);
|
||||
hash_add(dns_domain_set_name_table.names, &domain_set_name_list->node, key);
|
||||
}
|
||||
|
||||
list_add_tail(&domain_set->list, &domain_set_name_list->set_name_list);
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
if (domain_set) {
|
||||
free(domain_set);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int _conf_domain_rules(void *data, int argc, char *argv[])
|
||||
{
|
||||
int opt = 0;
|
||||
@@ -1749,8 +2027,8 @@ static int _conf_dhcp_lease_dnsmasq_file(void *data, int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
safe_strncpy(dns_conf_dnsmasq_lease_file, argv[1], DNS_MAX_PATH);
|
||||
if (_conf_dhcp_lease_dnsmasq_add(argv[1]) != 0) {
|
||||
conf_get_conf_fullpath(argv[1], dns_conf_dnsmasq_lease_file, sizeof(dns_conf_dnsmasq_lease_file));
|
||||
if (_conf_dhcp_lease_dnsmasq_add(dns_conf_dnsmasq_lease_file) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1907,6 +2185,7 @@ static struct config_item _config_item[] = {
|
||||
CONF_INT("rr-ttl-min", &dns_conf_rr_ttl_min, 0, CONF_INT_MAX),
|
||||
CONF_INT("rr-ttl-max", &dns_conf_rr_ttl_max, 0, CONF_INT_MAX),
|
||||
CONF_INT("rr-ttl-reply-max", &dns_conf_rr_ttl_reply_max, 0, CONF_INT_MAX),
|
||||
CONF_INT("local-ttl", &dns_conf_local_ttl, 0, CONF_INT_MAX),
|
||||
CONF_INT("max-reply-ip-num", &dns_conf_max_reply_ip_num, 1, CONF_INT_MAX),
|
||||
CONF_ENUM("response-mode", &dns_conf_response_mode, &dns_conf_response_mode_enum),
|
||||
CONF_YESNO("force-AAAA-SOA", &dns_conf_force_AAAA_SOA),
|
||||
@@ -1918,12 +2197,14 @@ static struct config_item _config_item[] = {
|
||||
CONF_CUSTOM("ignore-ip", _conf_ip_ignore, NULL),
|
||||
CONF_CUSTOM("edns-client-subnet", _conf_edns_client_subnet, NULL),
|
||||
CONF_CUSTOM("domain-rules", _conf_domain_rules, NULL),
|
||||
CONF_CUSTOM("domain-set", _conf_domain_set, NULL),
|
||||
CONF_CUSTOM("dnsmasq-lease-file", _conf_dhcp_lease_dnsmasq_file, NULL),
|
||||
CONF_CUSTOM("hosts-file", _conf_hosts_file, NULL),
|
||||
CONF_STRING("ca-file", (char *)&dns_conf_ca_file, DNS_MAX_PATH),
|
||||
CONF_STRING("ca-path", (char *)&dns_conf_ca_path, DNS_MAX_PATH),
|
||||
CONF_STRING("user", (char *)&dns_conf_user, sizeof(dns_conf_user)),
|
||||
CONF_YESNO("debug-save-fail-packet", &dns_save_fail_packet),
|
||||
CONF_STRING("resolv-file", (char *)&dns_resolv_file, sizeof(dns_resolv_file)),
|
||||
CONF_STRING("debug-save-fail-packet-dir", (char *)&dns_save_fail_packet_dir, sizeof(dns_save_fail_packet_dir)),
|
||||
CONF_CUSTOM("conf-file", config_addtional_file, NULL),
|
||||
CONF_END(),
|
||||
@@ -1982,6 +2263,96 @@ int config_addtional_file(void *data, int argc, char *argv[])
|
||||
return load_conf(file_path, _config_item, _conf_printf);
|
||||
}
|
||||
|
||||
static int _update_domain_set_from_list(const char *file, struct dns_domain_set_rule_list *set_rule_list)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char line[MAX_LINE_LEN];
|
||||
char domain[DNS_MAX_CNAME_LEN];
|
||||
int ret = 0;
|
||||
int line_no = 0;
|
||||
int filed_num = 0;
|
||||
struct dns_domain_set_rule *set_rule = NULL;
|
||||
|
||||
fp = fopen(file, "r");
|
||||
if (fp == NULL) {
|
||||
tlog(TLOG_WARN, "open file %s error, %s", file, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
line_no = 0;
|
||||
while (fgets(line, MAX_LINE_LEN, fp)) {
|
||||
line_no++;
|
||||
filed_num = sscanf(line, "%256s", domain);
|
||||
if (filed_num <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (domain[0] == '#' || domain[0] == '\n') {
|
||||
continue;
|
||||
}
|
||||
|
||||
list_for_each_entry(set_rule, &set_rule_list->domain_ruls_list, list)
|
||||
{
|
||||
if (set_rule->type == DOMAIN_RULE_FLAGS) {
|
||||
ret = _config_domain_rule_flag_set(domain, set_rule->flags, set_rule->is_clear_flag);
|
||||
} else {
|
||||
ret = _config_domain_rule_add(domain, set_rule->type, set_rule->rule);
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
tlog(TLOG_WARN, "process file %s failed at line %d.", file, line_no);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _update_domain_set(void)
|
||||
{
|
||||
struct dns_domain_set_rule_list *set_rule_list = NULL;
|
||||
|
||||
struct dns_domain_set_name_list *set_name_list = NULL;
|
||||
struct dns_domain_set_name *set_name_item = NULL;
|
||||
|
||||
unsigned long i = 0;
|
||||
uint32_t key = 0;
|
||||
|
||||
hash_for_each(dns_domain_set_rule_table.rule_list, i, set_rule_list, node)
|
||||
{
|
||||
key = hash_string(set_rule_list->domain_set);
|
||||
hash_for_each_possible(dns_domain_set_name_table.names, set_name_list, node, key)
|
||||
{
|
||||
if (strcmp(set_name_list->name, set_rule_list->domain_set) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (set_name_list == NULL) {
|
||||
tlog(TLOG_WARN, "domain set %s not found.", set_rule_list->domain_set);
|
||||
continue;
|
||||
}
|
||||
|
||||
list_for_each_entry(set_name_item, &set_name_list->set_name_list, list)
|
||||
{
|
||||
switch (set_name_item->type) {
|
||||
case DNS_DOMAIN_SET_LIST:
|
||||
_update_domain_set_from_list(set_name_item->file, set_rule_list);
|
||||
break;
|
||||
case DNS_DOMAIN_SET_GEOSITE:
|
||||
break;
|
||||
default:
|
||||
tlog(TLOG_WARN, "domain set %s type %d not support.", set_name_list->name, set_name_item->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _dns_server_load_conf_init(void)
|
||||
{
|
||||
dns_conf_address_rule.ipv4 = New_Radix();
|
||||
@@ -1998,6 +2369,8 @@ static int _dns_server_load_conf_init(void)
|
||||
hash_init(dns_group_table.group);
|
||||
hash_init(dns_hosts_table.hosts);
|
||||
hash_init(dns_ptr_table.ptr);
|
||||
hash_init(dns_domain_set_rule_table.rule_list);
|
||||
hash_init(dns_domain_set_name_table.names);
|
||||
|
||||
_config_setup_smartdns_domain();
|
||||
|
||||
@@ -2091,6 +2464,26 @@ static int _dns_conf_load_post(void)
|
||||
dns_conf_response_mode_enum[dns_conf_response_mode].name);
|
||||
}
|
||||
|
||||
if ((dns_conf_rr_ttl_min > dns_conf_rr_ttl_max) && dns_conf_rr_ttl_max > 0) {
|
||||
dns_conf_rr_ttl_min = dns_conf_rr_ttl_max;
|
||||
}
|
||||
|
||||
if ((dns_conf_rr_ttl_max < dns_conf_rr_ttl_min) && dns_conf_rr_ttl_max > 0) {
|
||||
dns_conf_rr_ttl_max = dns_conf_rr_ttl_min;
|
||||
}
|
||||
|
||||
if (dns_conf_local_ttl == 0) {
|
||||
dns_conf_local_ttl = dns_conf_rr_ttl_min;
|
||||
}
|
||||
|
||||
if (dns_resolv_file[0] == '\0') {
|
||||
safe_strncpy(dns_resolv_file, DNS_RESOLV_FILE, sizeof(dns_resolv_file));
|
||||
}
|
||||
|
||||
_update_domain_set();
|
||||
_config_domain_set_name_table_destroy();
|
||||
_config_domain_set_rule_table_destroy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define _DNS_CONF
|
||||
|
||||
#include "art.h"
|
||||
#include "atomic.h"
|
||||
#include "conf.h"
|
||||
#include "dns.h"
|
||||
#include "dns_client.h"
|
||||
@@ -102,16 +103,25 @@ typedef enum {
|
||||
#define BIND_FLAG_NO_DUALSTACK_SELECTION (1 << 7)
|
||||
#define BIND_FLAG_FORCE_AAAA_SOA (1 << 8)
|
||||
|
||||
struct dns_rule {
|
||||
atomic_t refcnt;
|
||||
enum domain_rule rule;
|
||||
char rule_data[];
|
||||
};
|
||||
|
||||
struct dns_rule_flags {
|
||||
struct dns_rule head;
|
||||
unsigned int flags;
|
||||
unsigned int is_flag_set;
|
||||
};
|
||||
|
||||
struct dns_address_IPV4 {
|
||||
struct dns_rule_address_IPV4 {
|
||||
struct dns_rule head;
|
||||
unsigned char ipv4_addr[DNS_RR_A_LEN];
|
||||
};
|
||||
|
||||
struct dns_address_IPV6 {
|
||||
struct dns_rule_address_IPV6 {
|
||||
struct dns_rule head;
|
||||
unsigned char ipv6_addr[DNS_RR_AAAA_LEN];
|
||||
};
|
||||
|
||||
@@ -121,14 +131,17 @@ struct dns_ipset_name {
|
||||
};
|
||||
|
||||
struct dns_ipset_rule {
|
||||
struct dns_rule head;
|
||||
const char *ipsetname;
|
||||
};
|
||||
|
||||
struct dns_domain_rule {
|
||||
void *rules[DOMAIN_RULE_MAX];
|
||||
struct dns_rule head;
|
||||
struct dns_rule *rules[DOMAIN_RULE_MAX];
|
||||
};
|
||||
|
||||
struct dns_nameserver_rule {
|
||||
struct dns_rule head;
|
||||
const char *group_name;
|
||||
};
|
||||
|
||||
@@ -145,6 +158,7 @@ struct dns_domain_check_order {
|
||||
};
|
||||
|
||||
struct dns_domain_check_orders {
|
||||
struct dns_rule head;
|
||||
struct dns_domain_check_order orders[DOMAIN_CHECK_NUM];
|
||||
};
|
||||
|
||||
@@ -174,7 +188,7 @@ struct dns_hosts {
|
||||
char domain[DNS_MAX_CNAME_LEN];
|
||||
dns_hosts_type host_type;
|
||||
int dns_type;
|
||||
int is_soa;
|
||||
int is_soa;
|
||||
union {
|
||||
unsigned char ipv4_addr[DNS_RR_A_LEN];
|
||||
unsigned char ipv6_addr[DNS_RR_AAAA_LEN];
|
||||
@@ -255,6 +269,46 @@ struct dns_qtype_soa_table {
|
||||
};
|
||||
extern struct dns_qtype_soa_table dns_qtype_soa_table;
|
||||
|
||||
struct dns_domain_set_rule {
|
||||
struct list_head list;
|
||||
enum domain_rule type;
|
||||
void *rule;
|
||||
unsigned int flags;
|
||||
unsigned int is_clear_flag;
|
||||
};
|
||||
|
||||
struct dns_domain_set_rule_list {
|
||||
struct hlist_node node;
|
||||
char domain_set[DNS_MAX_CNAME_LEN];
|
||||
struct list_head domain_ruls_list;
|
||||
};
|
||||
|
||||
struct dns_domain_set_rule_table {
|
||||
DECLARE_HASHTABLE(rule_list, 4);
|
||||
};
|
||||
extern struct dns_domain_set_rule_table dns_domain_set_rule_table;
|
||||
|
||||
enum dns_domain_set_type {
|
||||
DNS_DOMAIN_SET_LIST = 0,
|
||||
DNS_DOMAIN_SET_GEOSITE = 1,
|
||||
};
|
||||
|
||||
struct dns_domain_set_name {
|
||||
struct list_head list;
|
||||
enum dns_domain_set_type type;
|
||||
char file[DNS_MAX_PATH];
|
||||
};
|
||||
|
||||
struct dns_domain_set_name_list {
|
||||
struct hlist_node node;
|
||||
char name[DNS_MAX_CNAME_LEN];
|
||||
struct list_head set_name_list;
|
||||
};
|
||||
struct dns_domain_set_name_table {
|
||||
DECLARE_HASHTABLE(names, 4);
|
||||
};
|
||||
extern struct dns_domain_set_name_table dns_domain_set_name_table;
|
||||
|
||||
extern struct dns_bind_ip dns_conf_bind_ip[DNS_MAX_BIND_IP];
|
||||
extern int dns_conf_bind_ip_num;
|
||||
|
||||
@@ -312,6 +366,7 @@ extern int dns_conf_rr_ttl_min;
|
||||
extern int dns_conf_rr_ttl_max;
|
||||
extern int dns_conf_force_AAAA_SOA;
|
||||
extern int dns_conf_ipset_timeout_enable;
|
||||
extern int dns_conf_local_ttl;
|
||||
|
||||
extern int dns_conf_force_no_cname;
|
||||
|
||||
@@ -324,6 +379,7 @@ extern char dns_conf_sni_proxy_ip[DNS_MAX_IPLEN];
|
||||
|
||||
extern int dns_save_fail_packet;
|
||||
extern char dns_save_fail_packet_dir[DNS_MAX_PATH];
|
||||
extern char dns_resolv_file[DNS_MAX_PATH];
|
||||
|
||||
void dns_server_load_exit(void);
|
||||
|
||||
|
||||
186
src/dns_server.c
186
src/dns_server.c
@@ -163,6 +163,7 @@ struct dns_request {
|
||||
|
||||
struct dns_server_conn_head *conn;
|
||||
uint32_t server_flags;
|
||||
char dns_group_name[DNS_GROUP_NAME_LEN];
|
||||
|
||||
/* dns request list */
|
||||
struct list_head list;
|
||||
@@ -261,8 +262,8 @@ static tlog_log *dns_audit;
|
||||
|
||||
static int is_ipv6_ready;
|
||||
|
||||
static int _dns_server_prefetch_request(char *domain, dns_type_t qtype, int expired_domain, uint32_t server_flags,
|
||||
struct dns_query_options *options);
|
||||
static int _dns_server_prefetch_request(char *domain, dns_type_t qtype, int expired_domain,
|
||||
struct dns_server_query_option *server_query_option);
|
||||
static int _dns_server_get_answer(struct dns_server_post_context *context);
|
||||
static void _dns_server_request_get(struct dns_request *request);
|
||||
static void _dns_server_request_release(struct dns_request *request);
|
||||
@@ -315,6 +316,15 @@ static int _dns_server_epoll_ctl(struct dns_server_conn_head *head, int op, uint
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *_dns_server_get_dns_rule(struct dns_request *request, enum domain_rule rule)
|
||||
{
|
||||
if (rule >= DOMAIN_RULE_MAX || request == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return request->domain_rule.rules[rule];
|
||||
}
|
||||
|
||||
static void _dns_server_set_dualstack_selection(struct dns_request *request)
|
||||
{
|
||||
struct dns_rule_flags *rule_flag = NULL;
|
||||
@@ -324,7 +334,7 @@ static void _dns_server_set_dualstack_selection(struct dns_request *request)
|
||||
return;
|
||||
}
|
||||
|
||||
rule_flag = request->domain_rule.rules[DOMAIN_RULE_FLAGS];
|
||||
rule_flag = _dns_server_get_dns_rule(request, DOMAIN_RULE_FLAGS);
|
||||
if (rule_flag) {
|
||||
if (rule_flag->flags & DOMAIN_FLAG_DUALSTACK_SELECT) {
|
||||
request->dualstack_selection = 1;
|
||||
@@ -360,7 +370,7 @@ static int _dns_server_is_return_soa(struct dns_request *request)
|
||||
}
|
||||
}
|
||||
|
||||
rule_flag = request->domain_rule.rules[DOMAIN_RULE_FLAGS];
|
||||
rule_flag = _dns_server_get_dns_rule(request, DOMAIN_RULE_FLAGS);
|
||||
if (rule_flag) {
|
||||
flags = rule_flag->flags;
|
||||
if (flags & DOMAIN_FLAG_ADDR_SOA) {
|
||||
@@ -732,11 +742,11 @@ static int _dns_add_rrs(struct dns_server_post_context *context)
|
||||
}
|
||||
/* add SOA record */
|
||||
if (has_soa) {
|
||||
ret |= dns_add_SOA(context->packet, DNS_RRS_NS, domain, 0, &request->soa);
|
||||
ret |= dns_add_SOA(context->packet, DNS_RRS_NS, domain, request->ip_ttl, &request->soa);
|
||||
tlog(TLOG_DEBUG, "result: %s, qtype: %d, return SOA", request->domain, context->qtype);
|
||||
} else if (context->do_force_soa == 1) {
|
||||
_dns_server_setup_soa(request);
|
||||
ret |= dns_add_SOA(context->packet, DNS_RRS_NS, domain, 0, &request->soa);
|
||||
ret |= dns_add_SOA(context->packet, DNS_RRS_NS, domain, request->ip_ttl, &request->soa);
|
||||
}
|
||||
|
||||
if (request->has_ecs) {
|
||||
@@ -792,7 +802,7 @@ static int _dns_setup_dns_raw_packet(struct dns_server_post_context *context)
|
||||
/* encode to binary data */
|
||||
int encode_len = dns_encode(context->inpacket, context->inpacket_maxlen, context->packet);
|
||||
if (encode_len <= 0) {
|
||||
tlog(TLOG_ERROR, "encode raw packet failed for %s", context->request->domain);
|
||||
tlog(TLOG_DEBUG, "encode raw packet failed for %s", context->request->domain);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -940,6 +950,8 @@ static int _dns_server_request_update_cache(struct dns_request *request, dns_typ
|
||||
speed = request->ping_time;
|
||||
|
||||
if (has_soa) {
|
||||
struct dns_cache_query_option cache_option;
|
||||
|
||||
if (request->dualstack_selection && request->has_ip && request->qtype == DNS_T_AAAA) {
|
||||
ttl = _dns_server_get_conf_ttl(request->ip_ttl);
|
||||
} else {
|
||||
@@ -948,7 +960,10 @@ static int _dns_server_request_update_cache(struct dns_request *request, dns_typ
|
||||
ttl = DNS_SERVER_TMOUT_TTL;
|
||||
}
|
||||
}
|
||||
dns_cache_set_data_soa(cache_data, request->server_flags, request->cname, request->ttl_cname);
|
||||
|
||||
cache_option.query_flag = request->server_flags;
|
||||
cache_option.dns_group_name = 0;
|
||||
dns_cache_set_data_soa(cache_data, &cache_option, request->cname, request->ttl_cname);
|
||||
}
|
||||
|
||||
tlog(TLOG_DEBUG, "cache %s qtype: %d ttl: %d\n", request->domain, qtype, ttl);
|
||||
@@ -983,6 +998,7 @@ static int _dns_cache_cname_packet(struct dns_server_post_context *context)
|
||||
{
|
||||
struct dns_packet *packet = context->packet;
|
||||
struct dns_packet *cname_packet = NULL;
|
||||
struct dns_cache_query_option cache_option;
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
@@ -1080,7 +1096,10 @@ static int _dns_cache_cname_packet(struct dns_server_post_context *context)
|
||||
if (inpacket_len <= 0) {
|
||||
return -1;
|
||||
}
|
||||
cache_packet = dns_cache_new_data_packet(request->server_flags, inpacket_buff, inpacket_len);
|
||||
|
||||
cache_option.query_flag = request->server_flags;
|
||||
cache_option.dns_group_name = request->dns_group_name;
|
||||
cache_packet = dns_cache_new_data_packet(&cache_option, inpacket_buff, inpacket_len);
|
||||
if (cache_packet == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1123,9 +1142,13 @@ errout:
|
||||
|
||||
static int _dns_cache_packet(struct dns_server_post_context *context)
|
||||
{
|
||||
struct dns_cache_query_option cache_option;
|
||||
struct dns_request *request = context->request;
|
||||
|
||||
cache_option.query_flag = request->server_flags;
|
||||
cache_option.dns_group_name = request->dns_group_name;
|
||||
struct dns_cache_data *cache_packet =
|
||||
dns_cache_new_data_packet(request->server_flags, context->inpacket, context->inpacket_len);
|
||||
dns_cache_new_data_packet(&cache_option, context->inpacket, context->inpacket_len);
|
||||
if (cache_packet == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1249,8 +1272,11 @@ static int _dns_cache_reply_packet(struct dns_server_post_context *context)
|
||||
return _dns_cache_specify_packet(context);
|
||||
}
|
||||
|
||||
struct dns_cache_query_option cache_option;
|
||||
cache_option.query_flag = request->server_flags;
|
||||
cache_option.dns_group_name = request->dns_group_name;
|
||||
struct dns_cache_data *cache_packet =
|
||||
dns_cache_new_data_packet(request->server_flags, context->inpacket, context->inpacket_len);
|
||||
dns_cache_new_data_packet(&cache_option, context->inpacket, context->inpacket_len);
|
||||
if (cache_packet == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1300,15 +1326,15 @@ static int _dns_server_setup_ipset_packet(struct dns_server_post_context *contex
|
||||
}
|
||||
|
||||
/* check ipset rule */
|
||||
rule_flags = request->domain_rule.rules[DOMAIN_RULE_FLAGS];
|
||||
rule_flags = _dns_server_get_dns_rule(request, DOMAIN_RULE_FLAGS);
|
||||
if (!rule_flags || (rule_flags->flags & DOMAIN_FLAG_IPSET_IGN) == 0) {
|
||||
ipset_rule = request->domain_rule.rules[DOMAIN_RULE_IPSET];
|
||||
ipset_rule = _dns_server_get_dns_rule(request, DOMAIN_RULE_IPSET);
|
||||
}
|
||||
if (!rule_flags || (rule_flags->flags & DOMAIN_FLAG_IPSET_IPV4_IGN) == 0) {
|
||||
ipset_rule_v4 = request->domain_rule.rules[DOMAIN_RULE_IPSET_IPV4];
|
||||
ipset_rule_v4 = _dns_server_get_dns_rule(request, DOMAIN_RULE_IPSET_IPV4);
|
||||
}
|
||||
if (!rule_flags || (rule_flags->flags & DOMAIN_FLAG_IPSET_IPV6_IGN) == 0) {
|
||||
ipset_rule_v6 = request->domain_rule.rules[DOMAIN_RULE_IPSET_IPV6];
|
||||
ipset_rule_v6 = _dns_server_get_dns_rule(request, DOMAIN_RULE_IPSET_IPV6);
|
||||
}
|
||||
|
||||
if (!(ipset_rule || ipset_rule_v4 || ipset_rule_v6)) {
|
||||
@@ -1549,6 +1575,7 @@ static int _dns_server_force_dualstack(struct dns_request *request)
|
||||
static int _dns_server_request_complete(struct dns_request *request)
|
||||
{
|
||||
int ttl = DNS_SERVER_TMOUT_TTL;
|
||||
int reply_ttl = ttl;
|
||||
|
||||
if (request->rcode == DNS_RC_SERVFAIL || request->rcode == DNS_RC_NXDOMAIN) {
|
||||
ttl = DNS_SERVER_FAIL_TTL;
|
||||
@@ -1600,6 +1627,15 @@ out:
|
||||
}
|
||||
}
|
||||
|
||||
reply_ttl = ttl;
|
||||
if (request->passthrough == 0 && dns_conf_cachesize > 0 &&
|
||||
request->check_order_list->orders[0].type != DOMAIN_CHECK_NONE) {
|
||||
reply_ttl = dns_conf_serve_expired_reply_ttl;
|
||||
if (reply_ttl < 2) {
|
||||
reply_ttl = 2;
|
||||
}
|
||||
}
|
||||
|
||||
struct dns_server_post_context context;
|
||||
_dns_server_post_context_init(&context, request);
|
||||
context.do_cache = 1;
|
||||
@@ -1607,7 +1643,7 @@ out:
|
||||
context.do_force_soa = request->dualstack_selection_force_soa;
|
||||
context.do_audit = 1;
|
||||
context.do_reply = 1;
|
||||
context.reply_ttl = ttl;
|
||||
context.reply_ttl = reply_ttl;
|
||||
context.skip_notify_count = 1;
|
||||
|
||||
_dns_request_post(&context);
|
||||
@@ -1788,10 +1824,6 @@ static void _dns_server_complete_with_multi_ipaddress(struct dns_request *reques
|
||||
struct dns_server_post_context context;
|
||||
int do_reply = 0;
|
||||
|
||||
if (request->passthrough) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (atomic_read(&request->ip_map_num) > 0) {
|
||||
request->has_soa = 0;
|
||||
}
|
||||
@@ -1801,6 +1833,10 @@ static void _dns_server_complete_with_multi_ipaddress(struct dns_request *reques
|
||||
_dns_server_force_dualstack(request);
|
||||
}
|
||||
|
||||
if (request->passthrough && do_reply == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
_dns_server_post_context_init(&context, request);
|
||||
context.do_cache = 1;
|
||||
context.do_ipset = 1;
|
||||
@@ -2299,6 +2335,7 @@ static int _dns_server_process_answer_A(struct dns_rrs *rrs, struct dns_request
|
||||
if (addr[0] == 0 || addr[0] == 127) {
|
||||
/* If half of the servers return the same result, then ignore this address */
|
||||
if (atomic_inc_return(&request->adblock) <= (dns_server_num() / 2 + dns_server_num() % 2)) {
|
||||
request->rcode = DNS_RC_NOERROR;
|
||||
_dns_server_request_release(request);
|
||||
return -1;
|
||||
}
|
||||
@@ -2375,6 +2412,7 @@ static int _dns_server_process_answer_AAAA(struct dns_rrs *rrs, struct dns_reque
|
||||
if (_dns_server_is_adblock_ipv6(addr) == 0) {
|
||||
/* If half of the servers return the same result, then ignore this address */
|
||||
if (atomic_inc_return(&request->adblock) <= (dns_server_num() / 2 + dns_server_num() % 2)) {
|
||||
request->rcode = DNS_RC_NOERROR;
|
||||
_dns_server_request_release(request);
|
||||
return -1;
|
||||
}
|
||||
@@ -2472,6 +2510,7 @@ static int _dns_server_process_answer(struct dns_request *request, const char *d
|
||||
request->soa.refresh, request->soa.retry, request->soa.expire, request->soa.minimum);
|
||||
int soa_num = atomic_inc_return(&request->soa_num);
|
||||
if ((soa_num >= (dns_server_num() / 3) + 1 || soa_num > 4) && atomic_read(&request->ip_map_num) <= 0) {
|
||||
request->ip_ttl = ttl;
|
||||
_dns_server_request_complete(request);
|
||||
}
|
||||
} break;
|
||||
@@ -3010,7 +3049,7 @@ static int _dns_server_reply_request_eth_ip(struct dns_request *request)
|
||||
}
|
||||
|
||||
request->rcode = DNS_RC_NOERROR;
|
||||
request->ip_ttl = 600;
|
||||
request->ip_ttl = dns_conf_local_ttl;
|
||||
request->has_ip = 1;
|
||||
|
||||
struct dns_server_post_context context;
|
||||
@@ -3311,7 +3350,7 @@ static int _dns_server_pre_process_rule_flags(struct dns_request *request)
|
||||
unsigned int flags = 0;
|
||||
|
||||
/* get domain rule flag */
|
||||
rule_flag = request->domain_rule.rules[DOMAIN_RULE_FLAGS];
|
||||
rule_flag = _dns_server_get_dns_rule(request, DOMAIN_RULE_FLAGS);
|
||||
if (rule_flag == NULL) {
|
||||
goto out;
|
||||
}
|
||||
@@ -3365,14 +3404,15 @@ out:
|
||||
|
||||
soa:
|
||||
/* return SOA */
|
||||
request->ip_ttl = 30;
|
||||
_dns_server_reply_SOA(DNS_RC_NOERROR, request);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _dns_server_process_address(struct dns_request *request)
|
||||
{
|
||||
struct dns_address_IPV4 *address_ipv4 = NULL;
|
||||
struct dns_address_IPV6 *address_ipv6 = NULL;
|
||||
struct dns_rule_address_IPV4 *address_ipv4 = NULL;
|
||||
struct dns_rule_address_IPV6 *address_ipv6 = NULL;
|
||||
|
||||
if (_dns_server_has_bind_flag(request, BIND_FLAG_NO_RULE_ADDR) == 0) {
|
||||
goto errout;
|
||||
@@ -3384,14 +3424,14 @@ static int _dns_server_process_address(struct dns_request *request)
|
||||
if (request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV4] == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
address_ipv4 = request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV4];
|
||||
address_ipv4 = _dns_server_get_dns_rule(request, DOMAIN_RULE_ADDRESS_IPV4);
|
||||
memcpy(request->ip_addr, address_ipv4->ipv4_addr, DNS_RR_A_LEN);
|
||||
break;
|
||||
case DNS_T_AAAA:
|
||||
if (request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV6] == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
address_ipv6 = request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV6];
|
||||
address_ipv6 = _dns_server_get_dns_rule(request, DOMAIN_RULE_ADDRESS_IPV6);
|
||||
memcpy(request->ip_addr, address_ipv6->ipv6_addr, DNS_RR_AAAA_LEN);
|
||||
break;
|
||||
default:
|
||||
@@ -3400,7 +3440,7 @@ static int _dns_server_process_address(struct dns_request *request)
|
||||
}
|
||||
|
||||
request->rcode = DNS_RC_NOERROR;
|
||||
request->ip_ttl = 600;
|
||||
request->ip_ttl = dns_conf_local_ttl;
|
||||
request->has_ip = 1;
|
||||
|
||||
struct dns_server_post_context context;
|
||||
@@ -3439,7 +3479,7 @@ static void _dns_server_process_speed_check_rule(struct dns_request *request)
|
||||
struct dns_domain_check_orders *check_order = NULL;
|
||||
|
||||
/* get domain rule flag */
|
||||
check_order = request->domain_rule.rules[DOMAIN_RULE_CHECKSPEED];
|
||||
check_order = _dns_server_get_dns_rule(request, DOMAIN_RULE_CHECKSPEED);
|
||||
if (check_order == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -3647,18 +3687,21 @@ reply_cache:
|
||||
|
||||
out_update_cache:
|
||||
if (dns_cache_get_ttl(dns_cache) == 0) {
|
||||
uint32_t server_flags = request->server_flags;
|
||||
struct dns_query_options options;
|
||||
struct dns_server_query_option dns_query_options;
|
||||
dns_query_options.server_flags = request->server_flags;
|
||||
dns_query_options.dns_group_name = request->dns_group_name;
|
||||
if (request->conn == NULL) {
|
||||
server_flags = dns_cache_get_cache_flag(dns_cache->cache_data);
|
||||
dns_query_options.server_flags = dns_cache_get_query_flag(dns_cache->cache_data);
|
||||
dns_query_options.dns_group_name = dns_cache_get_dns_group_name(dns_cache->cache_data);
|
||||
}
|
||||
|
||||
options.enable_flag = 0;
|
||||
dns_query_options.ecs_enable_flag = 0;
|
||||
if (request->has_ecs) {
|
||||
options.enable_flag |= DNS_QUEY_OPTION_ECS_DNS;
|
||||
memcpy(&options.ecs_dns, &request->ecs, sizeof(options.ecs_dns));
|
||||
dns_query_options.ecs_enable_flag |= DNS_QUEY_OPTION_ECS_DNS;
|
||||
memcpy(&dns_query_options.ecs_dns, &request->ecs, sizeof(dns_query_options.ecs_dns));
|
||||
}
|
||||
_dns_server_prefetch_request(request->domain, request->qtype, 0, server_flags, &options);
|
||||
|
||||
_dns_server_prefetch_request(request->domain, request->qtype, 0, &dns_query_options);
|
||||
} else {
|
||||
dns_cache_update(dns_cache);
|
||||
}
|
||||
@@ -3780,7 +3823,7 @@ static int _dns_server_process_smartdns_domain(struct dns_request *request)
|
||||
unsigned int flags = 0;
|
||||
|
||||
/* get domain rule flag */
|
||||
rule_flag = request->domain_rule.rules[DOMAIN_RULE_FLAGS];
|
||||
rule_flag = _dns_server_get_dns_rule(request, DOMAIN_RULE_FLAGS);
|
||||
if (rule_flag == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -3797,10 +3840,6 @@ static int _dns_server_process_special_query(struct dns_request *request)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (_dns_server_process_smartdns_domain(request) == 0) {
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
switch (request->qtype) {
|
||||
case DNS_T_PTR:
|
||||
/* return PTR record */
|
||||
@@ -3842,7 +3881,7 @@ static const char *_dns_server_get_request_groupname(struct dns_request *request
|
||||
|
||||
/* Get the nameserver rule */
|
||||
if (request->domain_rule.rules[DOMAIN_RULE_NAMESERVER]) {
|
||||
struct dns_nameserver_rule *nameserver_rule = request->domain_rule.rules[DOMAIN_RULE_NAMESERVER];
|
||||
struct dns_nameserver_rule *nameserver_rule = _dns_server_get_dns_rule(request, DOMAIN_RULE_NAMESERVER);
|
||||
return nameserver_rule->group_name;
|
||||
}
|
||||
|
||||
@@ -3918,7 +3957,7 @@ static int _dns_server_process_host(struct dns_request *request)
|
||||
}
|
||||
|
||||
request->rcode = DNS_RC_NOERROR;
|
||||
request->ip_ttl = 600;
|
||||
request->ip_ttl = dns_conf_local_ttl;
|
||||
request->has_ip = 1;
|
||||
|
||||
struct dns_server_post_context context;
|
||||
@@ -3969,6 +4008,7 @@ static int _dns_server_query_dualstack(struct dns_request *request)
|
||||
}
|
||||
|
||||
request_dualstack->server_flags = request->server_flags;
|
||||
safe_strncpy(request_dualstack->dns_group_name, request->dns_group_name, sizeof(request->dns_group_name));
|
||||
safe_strncpy(request_dualstack->domain, request->domain, sizeof(request->domain));
|
||||
request_dualstack->qtype = qtype;
|
||||
request_dualstack->dualstack_selection_query = 1;
|
||||
@@ -4013,13 +4053,14 @@ static int _dns_server_do_query(struct dns_request *request)
|
||||
|
||||
/* lookup domain rule */
|
||||
_dns_server_get_domain_rule(request);
|
||||
group_name = _dns_server_get_request_groupname(request);
|
||||
if (group_name == NULL) {
|
||||
group_name = dns_group;
|
||||
}
|
||||
|
||||
if (_dns_server_process_host(request) == 0) {
|
||||
goto clean_exit;
|
||||
group_name = request->dns_group_name;
|
||||
if (request->dns_group_name[0] == '\0') {
|
||||
group_name = _dns_server_get_request_groupname(request);
|
||||
if (group_name == NULL) {
|
||||
group_name = dns_group;
|
||||
}
|
||||
safe_strncpy(request->dns_group_name, group_name, DNS_GROUP_NAME_LEN);
|
||||
}
|
||||
|
||||
_dns_server_set_dualstack_selection(request);
|
||||
@@ -4038,6 +4079,14 @@ static int _dns_server_do_query(struct dns_request *request)
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
if (_dns_server_process_smartdns_domain(request) == 0) {
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
if (_dns_server_process_host(request) == 0) {
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
/* process qtype soa */
|
||||
if (_dns_server_qtype_soa(request) == 0) {
|
||||
goto clean_exit;
|
||||
@@ -4206,22 +4255,28 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _dns_server_prefetch_setup_options(struct dns_request *request, struct dns_query_options *options)
|
||||
static int _dns_server_setup_server_query_options(struct dns_request *request,
|
||||
struct dns_server_query_option *server_query_option)
|
||||
{
|
||||
if (options == NULL) {
|
||||
if (server_query_option == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (options->enable_flag & DNS_QUEY_OPTION_ECS_DNS) {
|
||||
request->server_flags = server_query_option->server_flags;
|
||||
if (server_query_option->dns_group_name) {
|
||||
safe_strncpy(request->dns_group_name, server_query_option->dns_group_name, DNS_GROUP_NAME_LEN);
|
||||
}
|
||||
|
||||
if (server_query_option->ecs_enable_flag & DNS_QUEY_OPTION_ECS_DNS) {
|
||||
request->has_ecs = 1;
|
||||
memcpy(&request->ecs, &options->ecs_dns, sizeof(request->ecs));
|
||||
memcpy(&request->ecs, &server_query_option->ecs_dns, sizeof(request->ecs));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _dns_server_prefetch_request(char *domain, dns_type_t qtype, int expired_domain, uint32_t server_flags,
|
||||
struct dns_query_options *options)
|
||||
static int _dns_server_prefetch_request(char *domain, dns_type_t qtype, int expired_domain,
|
||||
struct dns_server_query_option *server_query_option)
|
||||
{
|
||||
int ret = -1;
|
||||
struct dns_request *request = NULL;
|
||||
@@ -4234,8 +4289,7 @@ static int _dns_server_prefetch_request(char *domain, dns_type_t qtype, int expi
|
||||
|
||||
safe_strncpy(request->domain, domain, sizeof(request->domain));
|
||||
request->qtype = qtype;
|
||||
request->server_flags = server_flags;
|
||||
_dns_server_prefetch_setup_options(request, options);
|
||||
_dns_server_setup_server_query_options(request, server_query_option);
|
||||
_dns_server_request_set_enable_prefetch(request, expired_domain);
|
||||
ret = _dns_server_do_query(request);
|
||||
if (ret != 0) {
|
||||
@@ -4253,7 +4307,8 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dns_server_query(const char *domain, int qtype, uint32_t server_flags, dns_result_callback callback, void *user_ptr)
|
||||
int dns_server_query(const char *domain, int qtype, struct dns_server_query_option *server_query_option,
|
||||
dns_result_callback callback, void *user_ptr)
|
||||
{
|
||||
int ret = -1;
|
||||
struct dns_request *request = NULL;
|
||||
@@ -4264,9 +4319,9 @@ int dns_server_query(const char *domain, int qtype, uint32_t server_flags, dns_r
|
||||
goto errout;
|
||||
}
|
||||
|
||||
request->server_flags = server_flags;
|
||||
safe_strncpy(request->domain, domain, sizeof(request->domain));
|
||||
request->qtype = qtype;
|
||||
_dns_server_setup_server_query_options(request, server_query_option);
|
||||
_dns_server_request_set_callback(request, callback, user_ptr);
|
||||
ret = _dns_server_do_query(request);
|
||||
if (ret != 0) {
|
||||
@@ -4662,6 +4717,7 @@ static int _dns_server_second_ping_check(struct dns_request *request)
|
||||
static void _dns_server_prefetch_domain(struct dns_cache *dns_cache)
|
||||
{
|
||||
/* If there are still hits, continue pre-fetching */
|
||||
struct dns_server_query_option server_query_option;
|
||||
int hitnum = dns_cache_hitnum_dec_get(dns_cache);
|
||||
if (hitnum <= 0) {
|
||||
return;
|
||||
@@ -4670,8 +4726,10 @@ static void _dns_server_prefetch_domain(struct dns_cache *dns_cache)
|
||||
/* start prefetch domain */
|
||||
tlog(TLOG_DEBUG, "prefetch by cache %s, qtype %d, ttl %d, hitnum %d", dns_cache->info.domain, dns_cache->info.qtype,
|
||||
dns_cache->info.ttl, hitnum);
|
||||
if (_dns_server_prefetch_request(dns_cache->info.domain, dns_cache->info.qtype, 0,
|
||||
dns_cache_get_cache_flag(dns_cache->cache_data), NULL) != 0) {
|
||||
server_query_option.dns_group_name = dns_cache_get_dns_group_name(dns_cache->cache_data);
|
||||
server_query_option.server_flags = dns_cache_get_query_flag(dns_cache->cache_data);
|
||||
server_query_option.ecs_enable_flag = 0;
|
||||
if (_dns_server_prefetch_request(dns_cache->info.domain, dns_cache->info.qtype, 0, &server_query_option) != 0) {
|
||||
tlog(TLOG_ERROR, "prefetch domain %s, qtype %d, failed.", dns_cache->info.domain, dns_cache->info.qtype);
|
||||
}
|
||||
}
|
||||
@@ -4682,8 +4740,12 @@ static void _dns_server_prefetch_expired_domain(struct dns_cache *dns_cache)
|
||||
tlog(TLOG_DEBUG, "expired domain, prefetch by cache %s, qtype %d, ttl %d", dns_cache->info.domain,
|
||||
dns_cache->info.qtype, dns_cache->info.ttl);
|
||||
|
||||
if (_dns_server_prefetch_request(dns_cache->info.domain, dns_cache->info.qtype, 1,
|
||||
dns_cache_get_cache_flag(dns_cache->cache_data), NULL) != 0) {
|
||||
struct dns_server_query_option server_query_option;
|
||||
server_query_option.dns_group_name = dns_cache_get_dns_group_name(dns_cache->cache_data);
|
||||
server_query_option.server_flags = dns_cache_get_query_flag(dns_cache->cache_data);
|
||||
server_query_option.ecs_enable_flag = 0;
|
||||
|
||||
if (_dns_server_prefetch_request(dns_cache->info.domain, dns_cache->info.qtype, 1, &server_query_option) != 0) {
|
||||
tlog(TLOG_ERROR, "prefetch domain %s, qtype %d, failed.", dns_cache->info.domain, dns_cache->info.qtype);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,20 @@
|
||||
|
||||
#include "dns.h"
|
||||
#include <stdint.h>
|
||||
#include "dns_client.h"
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dns_server_query_option {
|
||||
uint32_t server_flags;
|
||||
const char *dns_group_name;
|
||||
unsigned long ecs_enable_flag;
|
||||
struct dns_opt_ecs ecs_dns;
|
||||
struct dns_query_ecs_ip ecs_ip;
|
||||
};
|
||||
|
||||
int dns_server_init(void);
|
||||
|
||||
int dns_server_run(void);
|
||||
@@ -41,7 +50,8 @@ typedef int (*dns_result_callback)(const char *domain, dns_rtcode_t rtcode, dns_
|
||||
unsigned int ping_time, void *user_ptr);
|
||||
|
||||
/* query domain */
|
||||
int dns_server_query(const char *domain, int qtype, uint32_t server_flags, dns_result_callback callback, void *user_ptr);
|
||||
int dns_server_query(const char *domain, int qtype, struct dns_server_query_option *server_query_option,
|
||||
dns_result_callback callback, void *user_ptr);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -1112,10 +1112,6 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
|
||||
tlog(TLOG_DEBUG, "ping %s, id = %d", host, ping_host->sid);
|
||||
|
||||
addrkey = _fast_ping_hash_key(ping_host->sid, &ping_host->addr);
|
||||
pthread_mutex_lock(&ping.map_lock);
|
||||
_fast_ping_host_get(ping_host);
|
||||
hash_add(ping.addrmap, &ping_host->addr_node, addrkey);
|
||||
pthread_mutex_unlock(&ping.map_lock);
|
||||
|
||||
_fast_ping_host_get(ping_host);
|
||||
_fast_ping_host_get(ping_host);
|
||||
@@ -1124,7 +1120,11 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
|
||||
goto errout_remove;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&ping.map_lock);
|
||||
_fast_ping_host_get(ping_host);
|
||||
hash_add(ping.addrmap, &ping_host->addr_node, addrkey);
|
||||
ping_host->run = 1;
|
||||
pthread_mutex_unlock(&ping.map_lock);
|
||||
freeaddrinfo(gai);
|
||||
_fast_ping_host_put(ping_host);
|
||||
return ping_host;
|
||||
|
||||
@@ -160,4 +160,6 @@ void load_exit(void);
|
||||
|
||||
const char *conf_get_conf_file(void);
|
||||
|
||||
const char *conf_get_conf_fullpath(const char *path, char *fullpath, size_t path_len);
|
||||
|
||||
#endif // !_GENERIC_CONF_H
|
||||
|
||||
@@ -24,6 +24,15 @@
|
||||
|
||||
static inline char *safe_strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
if (src == NULL) {
|
||||
dest[0] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
if (n <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if __GNUC__ > 7
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
|
||||
@@ -18,16 +18,46 @@
|
||||
|
||||
#include "conf.h"
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
#include <linux/limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char *currrent_conf_file = NULL;
|
||||
static const char *current_conf_file = NULL;
|
||||
|
||||
const char *conf_get_conf_file(void)
|
||||
{
|
||||
return currrent_conf_file;
|
||||
return current_conf_file;
|
||||
}
|
||||
|
||||
const char *conf_get_conf_fullpath(const char *path, char *fullpath, size_t path_len)
|
||||
{
|
||||
char file_path_dir[PATH_MAX];
|
||||
|
||||
if (path_len < 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (path[0] == '/') {
|
||||
strncpy(fullpath, path, path_len);
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
strncpy(file_path_dir, conf_get_conf_file(), PATH_MAX - 1);
|
||||
file_path_dir[PATH_MAX - 1] = 0;
|
||||
dirname(file_path_dir);
|
||||
if (file_path_dir[0] == '\0') {
|
||||
strncpy(fullpath, path, path_len);
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
if (snprintf(fullpath, PATH_MAX, "%s/%s", file_path_dir, path) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
int conf_custom(const char *item, void *data, int argc, char *argv[])
|
||||
@@ -303,7 +333,7 @@ static int load_conf_file(const char *file, struct config_item *items, conf_erro
|
||||
|
||||
conf_getopt_reset();
|
||||
/* call item function */
|
||||
currrent_conf_file = file;
|
||||
current_conf_file = file;
|
||||
call_ret = items[i].item_func(items[i].item, items[i].data, argc, argv);
|
||||
ret = handler(file, line_no, call_ret);
|
||||
if (ret != 0) {
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <ucontext.h>
|
||||
|
||||
#define RESOLVE_FILE "/etc/resolv.conf"
|
||||
#define MAX_LINE_LEN 1024
|
||||
#define MAX_KEY_LEN 64
|
||||
#define SMARTDNS_PID_FILE "/var/run/smartdns.pid"
|
||||
@@ -82,6 +81,11 @@ static int get_uid_gid(int *uid, int *gid)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (result == NULL) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*uid = result->pw_uid;
|
||||
*gid = result->pw_gid;
|
||||
|
||||
@@ -97,7 +101,11 @@ static int drop_root_privilege(void)
|
||||
{
|
||||
struct __user_cap_data_struct cap;
|
||||
struct __user_cap_header_struct header;
|
||||
#ifdef _LINUX_CAPABILITY_VERSION_3
|
||||
header.version = _LINUX_CAPABILITY_VERSION_3;
|
||||
#else
|
||||
header.version = _LINUX_CAPABILITY_VERSION;
|
||||
#endif
|
||||
header.pid = 0;
|
||||
int uid = 0;
|
||||
int gid = 0;
|
||||
@@ -173,9 +181,9 @@ static int _smartdns_load_from_resolv(void)
|
||||
int filed_num = 0;
|
||||
int line_num = 0;
|
||||
|
||||
fp = fopen(RESOLVE_FILE, "r");
|
||||
fp = fopen(dns_resolv_file, "r");
|
||||
if (fp == NULL) {
|
||||
tlog(TLOG_ERROR, "open %s failed, %s", RESOLVE_FILE, strerror(errno));
|
||||
tlog(TLOG_ERROR, "open %s failed, %s", dns_resolv_file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -496,7 +504,7 @@ static int _smartdns_create_logdir(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
chown(logdir, uid, gid);
|
||||
unused = chown(logdir, uid, gid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user