浏览代码

smartdns: bump copyright to 2023, and fix some typo

Nick Peng 2 年之前
父节点
当前提交
13d028df0d
共有 70 个文件被更改,包括 717 次插入621 次删除
  1. 1 1
      Makefile
  2. 315 261
      ReadMe.md
  3. 149 108
      ReadMe_en.md
  4. 2 2
      etc/init.d/smartdns
  5. 6 4
      etc/smartdns/smartdns.conf
  6. 1 1
      package/debian/make.sh
  7. 1 1
      package/linux/install
  8. 1 1
      package/luci-compat/control/postinst
  9. 1 1
      package/luci-compat/control/prerm
  10. 1 1
      package/luci-compat/files/etc/uci-defaults/50_luci-smartdns
  11. 1 1
      package/luci-compat/files/luci/controller/smartdns.lua
  12. 1 1
      package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua
  13. 1 1
      package/luci-compat/files/luci/model/cbi/smartdns/upstream.lua
  14. 1 1
      package/luci-compat/files/luci/model/smartdns.lua
  15. 1 1
      package/luci-compat/files/luci/view/smartdns/smartdns_status.htm
  16. 1 1
      package/luci-compat/make.sh
  17. 1 1
      package/luci/control/postinst
  18. 1 1
      package/luci/control/prerm
  19. 1 1
      package/luci/files/luci/i18n/smartdns.zh-cn.po
  20. 12 12
      package/luci/files/root/www/luci-static/resources/view/smartdns/smartdns.js
  21. 1 1
      package/luci/make.sh
  22. 1 1
      package/openwrt/control/postinst
  23. 2 1
      package/openwrt/control/prerm
  24. 4 4
      package/openwrt/files/etc/init.d/smartdns
  25. 1 1
      package/openwrt/make.sh
  26. 8 8
      package/optware/S50smartdns
  27. 1 1
      package/optware/control/postinst
  28. 1 1
      package/optware/control/prerm
  29. 1 1
      package/optware/make.sh
  30. 1 1
      package/windows/install.bat
  31. 1 1
      src/Makefile
  32. 8 8
      src/dns.c
  33. 7 7
      src/dns.h
  34. 1 1
      src/dns_cache.c
  35. 1 1
      src/dns_cache.h
  36. 23 23
      src/dns_client.c
  37. 1 1
      src/dns_client.h
  38. 16 15
      src/dns_conf.c
  39. 4 5
      src/dns_conf.h
  40. 34 34
      src/dns_server.c
  41. 1 1
      src/dns_server.h
  42. 14 14
      src/fast_ping.c
  43. 1 1
      src/fast_ping.h
  44. 1 1
      src/http_parse.c
  45. 1 1
      src/http_parse.h
  46. 1 1
      src/include/atomic.h
  47. 1 1
      src/include/bitmap.h
  48. 1 1
      src/include/bitops.h
  49. 1 1
      src/include/conf.h
  50. 1 1
      src/include/findbit.h
  51. 1 1
      src/include/gcc_builtin.h
  52. 1 1
      src/include/hash.h
  53. 1 1
      src/include/hashtable.h
  54. 1 1
      src/include/jhash.h
  55. 1 1
      src/include/list.h
  56. 1 1
      src/include/rbtree.h
  57. 1 1
      src/include/stringutil.h
  58. 1 1
      src/lib/art.c
  59. 2 2
      src/lib/bitops.c
  60. 1 1
      src/lib/conf.c
  61. 4 8
      src/lib/nftset.c
  62. 3 1
      src/lib/radix.c
  63. 1 1
      src/lib/rbtree.c
  64. 1 1
      src/lib/stringutil.c
  65. 21 21
      src/proxy.c
  66. 1 1
      src/smartdns.c
  67. 7 7
      src/tlog.c
  68. 5 5
      src/tlog.h
  69. 19 19
      src/util.c
  70. 5 5
      src/util.h

+ 1 - 1
Makefile

@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 315 - 261
ReadMe.md

@@ -99,31 +99,31 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
 1. **多 DNS 上游服务器**  
    支持配置多个上游 DNS 服务器,并同时进行查询,即使其中有 DNS 服务器异常,也不会影响查询。  
 
-2. **返回最快 IP 地址**  
+1. **返回最快 IP 地址**  
    支持从域名所属 IP 地址列表中查找到访问速度最快的 IP 地址,并返回给客户端,提高网络访问速度。
 
-3. **支持多种查询协议**  
+1. **支持多种查询协议**  
    支持 UDP、TCP、DOT 和 DOH 查询,以及非 53 端口查询;支持通过socks5,HTTP代理查询。
 
-4. **特定域名 IP 地址指定**  
+1. **特定域名 IP 地址指定**  
    支持指定域名的 IP 地址,达到广告过滤效果、避免恶意网站的效果。
 
-5. **域名高性能后缀匹配**  
+1. **域名高性能后缀匹配**  
    支持域名后缀匹配模式,简化过滤配置,过滤 20 万条记录时间 < 1ms。
 
-6. **域名分流**  
+1. **域名分流**  
    支持域名分流,不同类型的域名向不同的 DNS 服务器查询,支持iptable和nftable更好的分流。
 
-7. **Windows / Linux 多平台支持**  
+1. **Windows / Linux 多平台支持**  
    支持标准 Linux 系统(树莓派)、OpenWrt 系统各种固件和华硕路由器原生固件。同时还支持 WSL(Windows Subsystem for Linux,适用于 Linux 的 Windows 子系统)。
 
-8. **支持 IPv4、IPv6 双栈**  
+1. **支持 IPv4、IPv6 双栈**  
    支持 IPv4 和 IPV 6网络,支持查询 A 和 AAAA 记录,支持双栈 IP 速度优化,并支持完全禁用 IPv6 AAAA 解析。
 
-9. **高性能、占用资源少**  
+1. **高性能、占用资源少**  
    多线程异步 IO 模式,cache 缓存查询结果。
 
-10. **主流系统官方支持**
+1. **主流系统官方支持**
    主流路由系统官方软件源安装smartdns。
 
 ## 架构
@@ -131,9 +131,9 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
 ![Architecture](https://github.com/pymumu/test/releases/download/blob/architecture.png)
 
 1. SmartDNS 接收本地网络设备的DNS 查询请求,如 PC、手机的查询请求;
-2. 然后将查询请求发送到多个上游 DNS 服务器,可支持 UDP 标准端口或非标准端口查询,以及 TCP 查询;
-3. 上游 DNS 服务器返回域名对应的服务器 IP 地址列表,SmartDNS 则会检测从本地网络访问速度最快的服务器 IP;
-4. 最后将访问速度最快的服务器 IP 返回给本地客户端。
+1. 然后将查询请求发送到多个上游 DNS 服务器,可支持 UDP 标准端口或非标准端口查询,以及 TCP 查询;
+1. 上游 DNS 服务器返回域名对应的服务器 IP 地址列表,SmartDNS 则会检测从本地网络访问速度最快的服务器 IP;
+1. 最后将访问速度最快的服务器 IP 返回给本地客户端。
 
 ## 下载
 
@@ -143,10 +143,10 @@ smartdns已经合入主流系统的软件仓库,可以直接使用系统安装
 
 系统|安装方式|说明|
 --|--|--
-openwrt|opkg update<br>opkg install luci-app-smartdns<br>opkg install smartdns|22.03之后的系统。软件源路径:https://downloads.openwrt.org/releases/
-ddwrt|官方最新固件service页面->SmartDNS Resolver->启用。|选择界面参考:https://forum.dd-wrt.com/demo/Services.html
+openwrt|opkg update<br />opkg install luci-app-smartdns<br />opkg install smartdns|22.03之后的系统。软件源路径:<https://downloads.openwrt.org/releases/>
+ddwrt|官方最新固件service页面->SmartDNS Resolver->启用。|选择界面参考:<https://forum.dd-wrt.com/demo/Services.html>
 debian|apt-get install smartdns|
-entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entware.net/
+entware|ipkg update<br />ipkg install smartdns|软件源路径:<https://bin.entware.net/>
 
 ### 手工下载安装
 
@@ -174,9 +174,9 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 
 **请注意:**
 
-* Release 释出的软件包采取静态编译,无外部依赖,但体积大。若需要小体积软件包,请自行编译或从 OpenWrt / Entware 仓库获取。
+- Release 释出的软件包采取静态编译,无外部依赖,但体积大。若需要小体积软件包,请自行编译或从 OpenWrt / Entware 仓库获取。
 
-* 静态编译的软件包未强制判断 CPU 架构,安装不正确的软件包将会导致服务无法启动,请确保正确安装对应的版本。
+- 静态编译的软件包未强制判断 CPU 架构,安装不正确的软件包将会导致服务无法启动,请确保正确安装对应的版本。
 
 ## 安装和使用
 
@@ -185,44 +185,46 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 --------------
 
 1. 安装
-   
-    下载配套安装包,并上传到 Linux 系统中。 
+
+    下载配套安装包,并上传到 Linux 系统中。
 
     标准 Linux 系统(X86 / X86_64)请执行如下命令安装:
 
     ```shell
-    $ tar zxf smartdns.1.yyyy.MM.dd-REL.x86_64-linux-all.tar.gz
-    $ cd smartdns
-    $ chmod +x ./install
-    $ ./install -i
+    tar zxf smartdns.1.yyyy.MM.dd-REL.x86_64-linux-all.tar.gz
+    cd smartdns
+    chmod +x ./install
+    ./install -i
     ```
 
     树莓派或其他 Debian 系系统(ARM / ARM64)请执行如下命令安装:
 
     ```shell
-    # dpkg -i smartdns.1.yyyy.MM.dd-REL.arm-debian-all.deb
+    dpkg -i smartdns.1.yyyy.MM.dd-REL.arm-debian-all.deb
     ```
 
     **对于Ubuntu系统:**
-    * `systemd-resolved`会占用TCP53和UDP53端口。你需要手动解决端口占用问题或者修改smartdns监听端口
+    - `systemd-resolved`会占用TCP53和UDP53端口。你需要手动解决端口占用问题或者修改smartdns监听端口
+
+    - 日志文件在`/var/log/smartdns/smartdns.log`
+
+1. 修改配置
 
-    * 日志文件在`/var/log/smartdns/smartdns.log`
-2. 修改配置
-   
     安装完成后,可配置 SmartDNS 的上游服务器信息。
 
-    一般情况下,只需要增加 `server `[`IP`]`:port` 和 `server-tcp `[`IP`]`:port` 配置项。
+    一般情况下,只需要增加 `server`[`IP`]`:port` 和 `server-tcp`[`IP`]`:port` 配置项。
 
     请尽可能配置多个上游 DNS 服务器,包括国内外的服务器。
 
     具体配置参数请参考[配置文件说明](#配置文件说明)。  
-   
+
     ```shell
-    # vi /etc/smartdns/smartdns.conf
+    vi /etc/smartdns/smartdns.conf
     ```
 
     `/etc/smartdns/smartdns.conf`配置包含如下基本内容:
-    ```
+
+    ```shell
     # 指定监听的端口号
     bind []:53 
     # 指定上游服务器
@@ -233,33 +235,33 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
     domain-rule /example.com/ -address 1.2.3.4
     ```
 
-3. 启动服务
-   
+1. 启动服务
+
     ```shell
-    # systemctl enable smartdns
-    # systemctl start smartdns
+    systemctl enable smartdns
+    systemctl start smartdns
     ```
 
-4. 将 DNS 请求转发到 SmartDNS 解析
-   
+1. 将 DNS 请求转发到 SmartDNS 解析
+
     修改本地路由器的 DNS 服务器,将 DNS 服务器配置为 SmartDNS。
-   
-   * 登录到本地网络的路由器中,配置树莓派,分配其静态 IP 地址。
-   * 修改 WAN 口或者 DHCP DNS 为树莓派 IP 地址。
+
+   - 登录到本地网络的路由器中,配置树莓派,分配其静态 IP 地址。
+   - 修改 WAN 口或者 DHCP DNS 为树莓派 IP 地址。
      **注意:**
       I. 每款路由器配置方法不尽相同,请在网络上搜索对应配置方法。
       II. 华为等路由器可能不支持配置 DNS 为本地 IP,可修改电脑端或手机端的 DNS 服务器为树莓派 IP。
 
-5. 检测服务是否配置成功
-   
+1. 检测服务是否配置成功
+
     执行
-   
+
    ```shell
-   $ nslookup -querytype=ptr smartdns
+   nslookup -querytype=ptr smartdns
    ```
-   
+
     查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效
-   
+
    ```shell
    $ nslookup -querytype=ptr smartdns
    Server:         192.168.1.1
@@ -274,57 +276,57 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 --------------
 
 1. 安装
-   
+
     将软件包(使用 WinSCP 等)上传到路由器的 `/root` 目录,执行如下命令安装
-   
+
    ```shell
-   # opkg install smartdns.1.yyyy.MM.dd-REL.xxxx.ipk
-   # opkg install luci-app-smartdns.1.yyyy.MM.dd-REL.all.ipk
+   opkg install smartdns.1.yyyy.MM.dd-REL.xxxx.ipk
+   opkg install luci-app-smartdns.1.yyyy.MM.dd-REL.all.ipk
    ```
-   
-   * **注意:** 19.07 之前的版本,请务必安装 `luci-app-smartdns.1.yyyy.MM.dd-REL.all-luci-compat-all.ipk`。
 
-2. 修改配置
-   
+   - **注意:** 19.07 之前的版本,请务必安装 `luci-app-smartdns.1.yyyy.MM.dd-REL.all-luci-compat-all.ipk`。
+
+1. 修改配置
+
     登录 OpenWrt 管理页面,打开 `Services` -> `SmartDNS` 进行配置。
-   
-   * 在 `Upstream Servers` 增加上游 DNS 服务器配置,建议配置多个国内外 DNS 服务器。
-   * 在 `Domain Address` 指定特定域名的 IP 地址,可用于广告屏蔽。
 
-3. 启用服务
-     
-  * 替换默认Dndmasq为主DNS。
-    
-    登录 OpenWrt 管理界面,点击 `Services` -> `SmartDNS` -> `port`,设置端口号为`53`,smartdns会自动接管主DNS服务器。
+   - 在 `Upstream Servers` 增加上游 DNS 服务器配置,建议配置多个国内外 DNS 服务器。
+   - 在 `Domain Address` 指定特定域名的 IP 地址,可用于广告屏蔽。
+
+1. 启用服务
+
+   - 替换默认Dnsmasq为主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.
+     ```
+
+1. 启动服务
 
-  * 检测转发服务是否配置成功
-    
-    执行
-    
-    ```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.
-       ```
-
-4. 启动服务
-   
     勾选配置页面中的 `Enable(启用)`来启动 SmartDNS。
 
-5. **注意:**
-   
-   * 如已经安装 ChinaDNS,建议将 ChinaDNS 的上游配置为 SmartDNS。
-   * 当smartdns的端口为53时,将自动接管dnsmasq为主dns。配置其他端口时,会重新启用dnsmasq为主dns。
-   * 若在此过程中发生异常,可使用如下命令还原dnsmasq为主DNS
+1. **注意:**
+
+   - 如已经安装 ChinaDNS,建议将 ChinaDNS 的上游配置为 SmartDNS。
+   - 当smartdns的端口为53时,将自动接管dnsmasq为主dns。配置其他端口时,会重新启用dnsmasq为主dns。
+   - 若在此过程中发生异常,可使用如下命令还原dnsmasq为主DNS
 
    ```shell
    uci delete dhcp.@dnsmasq[0].port
@@ -339,37 +341,37 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 **说明:** 梅林固件派生自华硕固件,理论上可以直接使用华硕配套的安装包使用。但目前未经验证,如有问题,请提交 Issue。
 
 1. 准备
-   
+
     在使用此软件时,需要确认路由器是否支持 U 盘,并准备好 U 盘一个。
 
-2. 启用 SSH 登录
-   
+1. 启用 SSH 登录
+
     登录管理界面,点击 `系统管理` -> `系统设置`,配置 `Enable SSH` 为 `Lan Only`。  
     SSH 登录用户名密码与管理界面相同。
 
-3. 下载 `Download Master`
-   
+1. 下载 `Download Master`
+
     在管理界面点击 `USB 相关应用` -> `Download Master` 下载。  
     下载完成后,启用 `Download Master`,如果不需要下载功能,此时可以卸载 `Download Master`,但要保证卸载前 `Download Master` 是启用的。  
 
-4. 安装 SmartDNS
-   
+1. 安装 SmartDNS
+
     将软件包(使用 WinSCP 等)上传到路由器的 `/tmp/mnt/sda1` 目录(或网上邻居复制到 sda1 共享目录),执行如下命令安装
-   
+
    ```shell
-   # ipkg install smartdns.1.yyyy.MM.dd-REL.mipsbig.ipk
+   ipkg install smartdns.1.yyyy.MM.dd-REL.mipsbig.ipk
    ```
 
-5. 重启路由器使服务生效
-   
+1. 重启路由器使服务生效
+
     待路由器启动后, 执行
-   
+
    ```shell
-   $ nslookup -querytype=ptr smartdns
+   nslookup -querytype=ptr smartdns
    ```
-   
+
     查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效
-   
+
    ```shell
    $ nslookup -querytype=ptr smartdns
    Server:         192.168.1.1
@@ -379,11 +381,11 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
    smartdns        name = smartdns.
    ```
 
-6. **额外说明**
-   
+1. **额外说明**
+
     上述过程,SmartDNS 将安装到 U 盘根目录,采用 Optware 的模式运行。
-    其目录结构如下(此处仅列出 SmartDNS 相关文件): 
-   
+    其目录结构如下(此处仅列出 SmartDNS 相关文件):
+
    ```shell
    U 盘
    └── asusware.mipsbig
@@ -400,15 +402,16 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
            |          └── smartdns
            ....
    ```
-   
+
     如要修改配置,可以 SSH 登录路由器,使用 vi 命令修改
-   
+
    ```shell
-   # vi /opt/etc/smartdns/smartdns.conf
+   vi /opt/etc/smartdns/smartdns.conf
    ```
 
     `/opt/etc/smartdns/smartdns.conf`配置包含如下基本内容:
-    ```
+
+    ```shell
     # 指定监听的端口号
     bind []:53 
     # 指定上游服务器
@@ -418,9 +421,9 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
     address /example.com/1.2.3.4
     domain-rule /example.com/ -address 1.2.3.4
     ```
-   
+
    也可以通过网上邻居修改,网上邻居共享目录 `sda1` 看不到 `asusware.mipsbig` 目录,但可以直接在`文件管理器`中输入 `asusware.mipsbig\etc\init.d` 访问
-   
+
    ```shell
    \\192.168.1.1\sda1\asusware.mipsbig\etc\init.d
    ```
@@ -430,25 +433,26 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 --------------
 
 1. 准备
-   
+
     在使用此软件时,需要确认路由器是否支持 U 盘,并准备好 U 盘一个。
 
-2. 安装 SmartDNS
-   
+1. 安装 SmartDNS
+
     将软件(使用 WinSCP 等)上传到路由器的 `/tmp` 目录,执行如下命令安装
-   
+
    ```shell
-   # ipkg install smartdns.1.yyyy.MM.dd-REL.mipsbig.ipk
+   ipkg install smartdns.1.yyyy.MM.dd-REL.mipsbig.ipk
    ```
 
-3. 修改 SmartDNS 配置
-   
+1. 修改 SmartDNS 配置
+
    ```shell
-   # vi /opt/etc/smartdns/smartdns.conf
+   vi /opt/etc/smartdns/smartdns.conf
    ```
 
    `/opt/etc/smartdns/smartdns.conf`配置包含如下基本内容:
-    ```
+
+    ```shell
     # 指定监听的端口号
     bind []:53 
     # 指定上游服务器
@@ -458,23 +462,23 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
     address /example.com/1.2.3.4
     domain-rule /example.com/ -address 1.2.3.4
     ```
-   
+
     另外,如需支持 IPv6,可设置工作模式为 `2`,将 DNSmasq 的 DNS 服务禁用,设置 SmartDNS 为主用 DNS 服务器。将文件 `/opt/etc/smartdns/smartdns-opt.conf` 中的 `SMARTDNS_WORKMODE` 的值修改为 `2`
-   
+
    ```shell
    SMARTDNS_WORKMODE="2"
    ```
 
-4. 重启路由器使服务生效
-   
+1. 重启路由器使服务生效
+
     待路由器启动后, 执行
-   
+
    ```shell
-   $ nslookup -querytype=ptr smartdns
+   nslookup -querytype=ptr smartdns
    ```
-   
+
     查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效
-   
+
    ```shell
    $ nslookup -querytype=ptr smartdns
    Server:         192.168.1.1
@@ -483,7 +487,7 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
    Non-authoritative answer:
    smartdns        name = smartdns.
    ```
-   
+
     **注意:** 若服务没有自动启动,则需要设置 Optware / Entware 自动启动,具体方法请参考 Optware/Entware 的文档。
 
 ### WSL
@@ -491,13 +495,13 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 --------------
 
 1. 安装 WSL
-   
+
     安装 WSL 运行环境,发行版本选择 Ubuntu 系统为例。安装步骤请参考 [WSL 安装说明](https://docs.microsoft.com/zh-CN/windows/wsl/install)
 
-2. 安装 SmartDNS
-   
+1. 安装 SmartDNS
+
     下载适用于 WSL 的安装包,并解压到如 D 盘根目录。解压后目录如下:
-   
+
    ```shell
    D:\SMARTDNS
    ├─etc
@@ -509,19 +513,20 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
    ├─src
    └─systemd
    ```
-   
+
      双击 `D:\smartdns\package\windows` 目录下的 `install.bat` 进行安装。要求输入密码时,请输入 `WLS ubuntu` 的密码。
 
-3. 修改配置
-   
+1. 修改配置
+
     用记事本等打开 `D:\smartdns\etc\smartdns` 目录中的 `smartdns.conf` 配置文件配置 SmartDNS。
-   
+
     一般情况下,只需要增加 `server [IP]:port` 和 `server-tcp [IP]:port` 配置项,
     尽可能配置多个上游DNS服务器,包括国内外的服务器。
-   
+
     具体配置请参考[配置文件说明](#配置文件说明)。
      `smartdns.conf` 配置包含如下基本内容:
-    ```
+
+    ```shell
     # 指定监听的端口号
     bind []:53 
     # 指定上游服务器
@@ -532,24 +537,24 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
     domain-rule /example.com/ -address 1.2.3.4
     ```
 
-4. 重新加载配置
-   
+1. 重新加载配置
+
     双击 `D:\smartdns\package\windows` 目录下的 `reload.bat` 进行重新加载。要求输入密码时,请输入 `WLS ubuntu` 的密码。
 
-5. 将 DNS 请求转发到 SmartDNS 解析
-   
+1. 将 DNS 请求转发到 SmartDNS 解析
+
     将 Windows 的默认 DNS 服务器修改为 `127.0.0.1`,具体步骤参考 Windows [更改 TCP/IP 设置](https://support.microsoft.com/zh-cn/help/15089/windows-change-tcp-ip-settings)。
 
-6. 检测服务是否配置成功
-   
+1. 检测服务是否配置成功
+
     执行
-   
+
    ```shell
-   $ nslookup -querytype=ptr smartdns
+   nslookup -querytype=ptr smartdns
    ```
-   
+
     查看命令结果中的 `name` 是否为 `smartdns` 或你的主机名,如果是则表示生效
-   
+
    ```shell
    $ nslookup -querytype=ptr smartdns
    Server:         192.168.1.1
@@ -559,7 +564,6 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
    smartdns        name = smartdns.
    ```
 
-
 ## 配置文件说明
 
 配置建议:**smartdns默认已设置为最优模式,适合大部分场景的DNS查询体验改善,一般情况只需要增加上游服务器地址即可,无需做其他配置修改;如有其他配置修改,请务必了解其用途,避免修改后起到反作用。**
@@ -567,11 +571,11 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 | 键名 | 功能说明 | 默认值 | 可用值/要求 | 举例 |
 | :--- | :--- | :--- | :--- | :--- |
 | server-name | DNS 服务器名称 | 操作系统主机名 / smartdns | 符合主机名规格的字符串 | server-name smartdns |
-| bind | DNS 监听端口号  | [::]:53 | 可绑定多个端口。<br>IP:PORT@DEVICE: 服务器 IP:端口号@设备名<br>[-group]: 请求时使用的 DNS 服务器组<br>[-no-rule-addr]:跳过 address 规则<br>[-no-rule-nameserver]:跳过 Nameserver 规则<br>[-no-rule-ipset]:跳过 ipset 和 nftset 规则<br>[-no-rule-soa]:跳过 SOA(#) 规则<br>[-no-dualstack-selection]:停用双栈测速<br>[-no-speed-check]:停用测速<br>[-no-cache]:停止缓存 | bind :53@eth0 |
-| bind-tcp | DNS TCP 监听端口号 | [::]:53 | 可绑定多个端口。<br>IP:PORT@DEVICE: 服务器 IP:端口号@设备名<br>[-group]: 请求时使用的 DNS 服务器组<br>[-no-rule-addr]:跳过 address 规则<br>[-no-rule-nameserver]:跳过 nameserver 规则<br>[-no-rule-ipset]:跳过 ipset 和 nftset 规则。<br>[-no-rule-soa]:跳过 SOA(#) 规则<br>[-no-dualstack-selection]:停用双栈测速<br>[-no-speed-check]:停用测速<br>[-no-cache]:停止缓存 | bind-tcp :53 |
+| bind | DNS 监听端口号  | [::]:53 | 可绑定多个端口。<br />IP:PORT@DEVICE: 服务器 IP:端口号@设备名<br />[-group]: 请求时使用的 DNS 服务器组<br />[-no-rule-addr]:跳过 address 规则<br />[-no-rule-nameserver]:跳过 Nameserver 规则<br />[-no-rule-ipset]:跳过 ipset 和 nftset 规则<br />[-no-rule-soa]:跳过 SOA(#) 规则<br />[-no-dualstack-selection]:停用双栈测速<br />[-no-speed-check]:停用测速<br />[-no-cache]:停止缓存 | bind :53@eth0 |
+| bind-tcp | DNS TCP 监听端口号 | [::]:53 | 可绑定多个端口。<br />IP:PORT@DEVICE: 服务器 IP:端口号@设备名<br />[-group]: 请求时使用的 DNS 服务器组<br />[-no-rule-addr]:跳过 address 规则<br />[-no-rule-nameserver]:跳过 nameserver 规则<br />[-no-rule-ipset]:跳过 ipset 和 nftset 规则。<br />[-no-rule-soa]:跳过 SOA(#) 规则<br />[-no-dualstack-selection]:停用双栈测速<br />[-no-speed-check]:停用测速<br />[-no-cache]:停止缓存 | bind-tcp :53 |
 | cache-size | 域名结果缓存个数 | 512 | 大于等于 0 的数字 | cache-size 512 |
-| cache-persist | 是否持久化缓存 | 自动。<br>当 cache-file 所在的位置有超过 128 MB 的可用空间时启用,否则禁用。 | [yes\|no] | cache-persist yes |
-| cache-file | 缓存持久化文件路径 | /tmp/smartdns.cache | 合法路径字符串 | cache-file /tmp/smartdns.cache |
+| cache-persist | 是否持久化缓存 | 自动。<br />当 cache-file 所在的位置有超过 128 MB 的可用空间时启用,否则禁用。 | [yes\|no] | cache-persist yes |
+| cache-file | 缓存持久化文件路径 | /tmp/<br />smartdns.cache | 合法路径字符串 | cache-file /tmp/smartdns.cache |
 | tcp-idle-time | TCP 链接空闲超时时间 | 120 | 大于等于 0 的数字 | tcp-idle-time 120 |
 | rr-ttl | 域名结果 TTL | 远程查询结果 | 大于 0 的数字 | rr-ttl 600 |
 | rr-ttl-min | 允许的最小 TTL 值 | 远程查询结果 | 大于 0 的数字 | rr-ttl-min 60 |
@@ -580,38 +584,38 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 | 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 |
+| log-file | 日志文件路径 | /var/log/<br />smartdns/<br />smartdns.log | 合法路径字符串 | log-file /var/log/smartdns/smartdns.log |
 | log-size | 日志大小 | 128K | 数字 + K、M 或 G | log-size 128K |
 | log-num | 日志归档个数 | openwrt为2, 其他系统为8 | 大于等于 0 的数字,0表示禁用日志 | log-num 2 |
 | log-file-mode | 日志归档文件权限 | 0640 | 文件权限 | log-file-mode 644 |
 | audit-enable | 设置审计启用 | no | [yes\|no] | audit-enable yes |
-| audit-file | 审计文件路径 | /var/log/smartdns/smartdns-audit.log | 合法路径字符串 | audit-file /var/log/smartdns/smartdns-audit.log |
+| audit-file | 审计文件路径 | /var/log/<br />smartdns/<br />smartdns-audit.log | 合法路径字符串 | audit-file /var/log/smartdns/smartdns-audit.log |
 | audit-size | 审计大小 | 128K | 数字 + K、M 或 G | audit-size 128K |
 | audit-num | 审计归档个数 | 2 | 大于等于 0 的数字 | audit-num 2 |
 | audit-file-mode | 审计归档文件权限 | 0640 | 文件权限 | log-file-mode 644 |
 | conf-file | 附加配置文件 | 无 | 合法路径字符串 | conf-file /etc/smartdns/smartdns.more.conf |
-| server | 上游 UDP DNS | 无 | 可重复。<br>[ip][:port]\|URL:服务器 IP:端口(可选)或 URL <br>[-blacklist-ip]:配置 IP 过滤结果。<br>[-whitelist-ip]:指定仅接受参数中配置的 IP 范围<br>[-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br>[-exclude-default-group]:将 DNS 服务器从默认组中排除。<br>[-set-mark mark]:设置数据包标记so-mark。<br>[-proxy name]:设置代理服务器。 | server 8.8.8.8:53 -blacklist-ip -group g1 -proxy proxy<br> server tls://8.8.8.8|
-| server-tcp | 上游 TCP DNS | 无 | 可重复。<br>[ip][:port]:服务器 IP:端口(可选)<br>[-blacklist-ip]:配置 IP 过滤结果<br>[-whitelist-ip]:指定仅接受参数中配置的 IP 范围。<br>[-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br>[-exclude-default-group]:将 DNS 服务器从默认组中排除。<br>[-set-mark mark]:设置数据包标记so-mark。<br>[-proxy name]:设置代理服务器。 | server-tcp 8.8.8.8:53 |
-| server-tls | 上游 TLS DNS | 无 | 可重复。<br>[ip][:port]:服务器 IP:端口(可选)<br>[-spki-pin [sha256-pin]]:TLS 合法性校验 SPKI 值,base64 编码的 sha256 SPKI pin 值<br>[-host-name]:TLS SNI 名称, 名称设置为-,表示停用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 服务器从默认组中排除。<br>[-set-mark mark]:设置数据包标记so-mark。<br>[-proxy name]:设置代理服务器。 | 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 服务器从默认组中排除。<br>[-set-mark]:设置数据包标记so-mark。<br>[-proxy name]:设置代理服务器。 | server-https https://cloudflare-dns.com/dns-query |
-| proxy-server | 代理服务器 | 无 | 可重复。<br>proxy-server URL <br>[URL]: [socks5\|http]://[username:password@]host:port<br>[-name]: 代理服务器名称。 |proxy-server socks5://user:[email protected]:1080 -name proxy|
+| server | 上游 UDP DNS | 无 | 可重复。<br />[ip][:port]\|URL:服务器 IP:端口(可选)或 URL <br />[-blacklist-ip]:配置 IP 过滤结果。<br />[-whitelist-ip]:指定仅接受参数中配置的 IP 范围<br />[-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br />[-exclude-default-group]:将 DNS 服务器从默认组中排除。<br />[-set-mark mark]:设置数据包标记so-mark。<br />[-proxy name]:设置代理服务器。 | server 8.8.8.8:53 -blacklist-ip -group g1 -proxy proxy<br /> server tls://8.8.8.8|
+| server-tcp | 上游 TCP DNS | 无 | 可重复。<br />[ip][:port]:服务器 IP:端口(可选)<br />[-blacklist-ip]:配置 IP 过滤结果<br />[-whitelist-ip]:指定仅接受参数中配置的 IP 范围。<br />[-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br />[-exclude-default-group]:将 DNS 服务器从默认组中排除。<br />[-set-mark mark]:设置数据包标记so-mark。<br />[-proxy name]:设置代理服务器。 | server-tcp 8.8.8.8:53 |
+| server-tls | 上游 TLS DNS | 无 | 可重复。<br />[ip][:port]:服务器 IP:端口(可选)<br />[-spki-pin [sha256-pin]]:TLS 合法性校验 SPKI 值,base64 编码的 sha256 SPKI pin 值<br />[-host-name]:TLS SNI 名称, 名称设置为-,表示停用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 服务器从默认组中排除。<br />[-set-mark mark]:设置数据包标记so-mark。<br />[-proxy name]:设置代理服务器。 | 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 服务器从默认组中排除。<br />[-set-mark]:设置数据包标记so-mark。<br />[-proxy name]:设置代理服务器。 | server-https <https://cloudflare-dns.com/dns-query> |
+| proxy-server | 代理服务器 | 无 | 可重复。<br />proxy-server URL <br />[URL]: [socks5\|http]://[username:password@]host:port<br />[-name]: 代理服务器名称。 |proxy-server socks5://user:[email protected]:1080 -name proxy|
 | speed-check-mode | 测速模式选择 | 无 | [ping\|tcp:[80]\|none] | speed-check-mode ping,tcp:80,tcp:443 |
-| 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 |
+| response-mode | 首次查询响应模式 | first-ping |模式:[first-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 超时功能启用  | no | [yes\|no] | ipset-timeout yes |
-| nftset | 域名 nftset | 无 | nftset /domain/[#4\|#6\|-]:[family#nftable#nftset\|-][,#[4\|6]:[family#nftable#nftset\|-]]],-表示忽略;ipv4 地址的 family 只支持 inet 和 ip;ipv6 地址的 family 只支持 inet 和 ip6;由于 nft 限制,两种地址只能分开存放于两个 set 中。| nftset /www.example.com/#4:inet#mytab#dns4,#6:- |
+| nftset | 域名 nftset | 无 | nftset /domain/[#4\|#6\|-]:[family#nftable#nftset\|-][,#[4\|6]:[family#nftable#nftset\|-]]],-表示忽略;ipv4 地址的 family 只支持 inet 和 ip;ipv6 地址的 family 只支持 inet 和 ip6;由于 nft 限制,两种地址只能分开存放于两个 set 中。| nftset /www.example.com/#4:inet#tab#dns4,#6:- |
 | nftset-timeout | 设置 nftset 超时功能启用  | no | [yes\|no] | nftset-timeout yes |
 | nftset-debug | 设置 nftset 调试功能启用  | no | [yes\|no] | nftset-debug 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>[-t\|-nftset]:参考nftset配置<br>[-d\|-dualstack-ip-selection]:参考 dualstack-ip-selection<br> [-no-serve-expired]:禁用过期缓存 | 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, nftset等需要指定域名的地方使用,使用方式为 /domain-set:[name]/| domain-set -name set -type list -file /path/to/list <br> address /domain-set:set/1.2.4.8 |
+| 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 />[-t\|-nftset]:参考nftset配置<br />[-d\|-dualstack-ip-selection]:参考 dualstack-ip-selection<br /> [-no-serve-expired]:禁用过期缓存 | 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, nftset等需要指定域名的地方使用,使用方式为 /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 |
 | blacklist-ip | 黑名单 IP 地址 | 无 | [ip/subnet],可重复 | blacklist-ip 1.2.3.4/16 |
 | force-AAAA-SOA | 强制 AAAA 地址返回 SOA | no | [yes\|no] | force-AAAA-SOA yes |
-| force-qtype-SOA | 强制指定 qtype 返回 SOA | qtype id | [<qtypeid> \| ...] | force-qtype-SOA 65 28
+| force-qtype-SOA | 强制指定 qtype 返回 SOA | qtype id | [qtypeid\|...] | force-qtype-SOA 65 28
 | prefetch-domain | 域名预先获取功能 | no | [yes\|no] | prefetch-domain yes |
 | dnsmasq-lease-file | 支持读取dnsmasq dhcp文件解析本地主机名功能 | 无 | dnsmasq dhcp lease文件路径 | dnsmasq-lease-file /var/lib/misc/dnsmasq.leases |
 | serve-expired | 过期缓存服务功能 | yes | [yes\|no],开启此功能后,如果有请求时尝试回应 TTL 为 0 的过期记录,并发查询记录,以避免查询等待 |
@@ -620,77 +624,77 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
 | dualstack-ip-selection | 双栈 IP 优选 | yes | [yes\|no] | dualstack-ip-selection yes |
 | dualstack-ip-selection-threshold | 双栈 IP 优选阈值 | 15ms | 单位为毫秒(ms) | dualstack-ip-selection-threshold [0-1000] |
 | user | 进程运行用户 | root | user [username] | user nobody |
-| ca-file | 证书文件 | /etc/ssl/certs/ca-certificates.crt | 合法路径字符串 | ca-file /etc/ssl/certs/ca-certificates.crt |
+| ca-file | 证书文件 | /etc/ssl/<br />certs/ca-certificates.crt | 合法路径字符串 | ca-file /etc/ssl/certs/ca-certificates.crt |
 | ca-path | 证书文件路径 | /etc/ssl/certs | 合法路径字符串 | ca-path /etc/ssl/certs |
 
 ## 常见问题
 
 1. SmartDNS 和 DNSmasq 有什么区别?
-   
+
     SmartDNS 在设计上并不是 DNSmasq 的替代品,它的主要功能集中在 DNS 解析增强上,增强部分有:
-   
-   * 多上游服务器并发请求,对结果进行测速后,返回最佳结果;
-   * address、ipset 域名匹配采用高效算法,查询匹配更加快速,即使是路由器设备也依然高效;
-   * 域名匹配支持忽略特定域名,可单独匹配 IPv4 和 IPv6,支持多样化定制;
-   * 针对广告屏蔽功能做增强,返回 SOA,屏蔽广告效果更佳;
-   * IPv4、IPv6 双栈 IP 优选机制,在双网情况下,选择最快的网络通讯;
-   * 支持最新的 TLS 和 HTTPS 协议,提供安全的 DNS 查询能力;
-   * ECS 支持,使查询结果更佳准确;
-   * IP 黑名单和忽略 IP 机制,使域名查询更佳准确;
-   * 域名预查询,访问常用网站更加快速;
-   * 域名 TTL 可指定,使访问更快速;
-   * 高速缓存机制,使访问更快速;
-   * 异步日志,审计机制,在记录信息的同时不影响 DNS 查询性能;
-   * 域名组(group)机制,特定域名使用特定上游服务器组查询,避免隐私泄漏;
-   * 第二 DNS 支持自定义更多行为。
-
-2. 如何配置上游服务器最佳?
-   
+
+   - 多上游服务器并发请求,对结果进行测速后,返回最佳结果;
+   - address、ipset 域名匹配采用高效算法,查询匹配更加快速,即使是路由器设备也依然高效;
+   - 域名匹配支持忽略特定域名,可单独匹配 IPv4 和 IPv6,支持多样化定制;
+   - 针对广告屏蔽功能做增强,返回 SOA,屏蔽广告效果更佳;
+   - IPv4、IPv6 双栈 IP 优选机制,在双网情况下,选择最快的网络通讯;
+   - 支持最新的 TLS 和 HTTPS 协议,提供安全的 DNS 查询能力;
+   - ECS 支持,使查询结果更佳准确;
+   - IP 黑名单和忽略 IP 机制,使域名查询更佳准确;
+   - 域名预查询,访问常用网站更加快速;
+   - 域名 TTL 可指定,使访问更快速;
+   - 高速缓存机制,使访问更快速;
+   - 异步日志,审计机制,在记录信息的同时不影响 DNS 查询性能;
+   - 域名组(group)机制,特定域名使用特定上游服务器组查询,避免隐私泄漏;
+   - 第二 DNS 支持自定义更多行为。
+
+1. 如何配置上游服务器最佳?
+
     SmartDNS 有测速机制,在配置上游服务器时,建议配置多个上游 DNS 服务器,包含多个不同区域的服务器,但总数建议在 10 个左右。推荐搭配
-   
-   * 运营商 DNS。
-   * 国内公共 DNS,如 `119.29.29.29`, `223.5.5.5`。
-   * 国外公共 DNS,如 `8.8.8.8`, `8.8.4.4`。
 
-3. 如何启用审计日志?
-   
+   - 运营商 DNS。
+   - 国内公共 DNS,如 `119.29.29.29`, `223.5.5.5`。
+   - 国外公共 DNS,如 `8.8.8.8`, `8.8.4.4`。
+
+1. 如何启用审计日志?
+
     审计日志记录客户端请求的域名,记录信息包括,请求时间,请求 IP,请求域名,请求类型,如果要启用审计日志,在配置界面配置 `audit-enable yes` 启用,`audit-size`、 `audit-file`、`audit-num` 分别配置审计日志文件大小,审计日志文件路径,和审计日志文件个数。审计日志文件将会压缩存储以节省空间。
 
-4. 如何避免隐私泄漏?
-   
+1. 如何避免隐私泄漏?
+
     默认情况下,SmartDNS 会将请求发送到所有配置的DNS服务器,若上游 DNS 服务器使用DNS,或记录日志,将会导致隐私泄漏。为避免隐私泄漏,请尽量:  
-   
-   * 配置使用可信的DNS服务器。
-   * 优先使用 TLS 查询。
-   * 设置上游 DNS 服务器组。
 
-5. 如何屏蔽广告?
-   
+   - 配置使用可信的DNS服务器。
+   - 优先使用 TLS 查询。
+   - 设置上游 DNS 服务器组。
+
+1. 如何屏蔽广告?
+
     SmartDNS 具备高性能域名匹配算法,通过域名方式过滤广告非常高效,如要屏蔽广告,只需要配置类似如下记录即可,如,屏蔽 `*.ad.com`,则配置:
-   
-   ```sh
+
+   ```shell
    address /ad.com/#
    ```
-   
+
     域名的使后缀模式,过滤 `*.ad.com`,`#` 表示返回 SOA,使屏蔽广告更加高效,如果要单独屏蔽 IPv4 或 IPv6, 在 `#` 后面增加数字,如 `#4` 表示对 IPv4 生效。若想忽略特定子域名的屏蔽,如忽略 `pass.ad.com`,可配置如下:
-   
-   ```sh
+
+   ```shell
    address /pass.ad.com/-
    ```
 
-6. 如何使用 DNS 查询分流?
-   
+1. 如何使用 DNS 查询分流?
+
     某些情况下,需要将有些域名使用特定的 DNS 服务器来查询来做到 DNS 分流。比如
-   
-   ```sh
+
+   ```shell
    .home -> 192.168.1.1 # .home 结尾的域名发送到 192.168.1.1 解析
    .office -> 10.0.0.1  # .office 结尾的域名发送到 10.0.0.1 解析
    ```
-   
+
     其他域名采用默认的模式解析。
     这种情况的分流配置如下:
-   
-   ```sh
+
+   ```shell
    # 配置上游,用 -group 指定组名,用 -exclude-default-group 将服务器从默认组中排除。
    server 192.168.1.1 -group home -exclude-default-group
    server 10.0.0.1 -group office -exclude-default-group
@@ -700,106 +704,156 @@ entware|ipkg update<br>ipkg install smartdns|软件源路径:https://bin.entwa
    nameserver /.home/home
    nameserver /.office/office
    ```
-   
+
     通过上述配置即可实现 DNS 解析分流,如果需要实现按请求端端口分流,可以配置第二 DNS 服务器,`bind` 配置增加 `--group` 参数指定分流名称。
-   
-   ```sh
+
+   ```shell
    bind :7053 -group office
    bind :8053 -group home
    ```
 
-7. IPv4、IPv6 双栈 IP 优选功能如何使用?
-   
+1. IPv4、IPv6 双栈 IP 优选功能如何使用?
+
     目前 IPv6 已经开始普及,但 IPv6 网络在速度上,某些情况下还不如 IPv4。为在双栈网络下获得较好的体验,SmartDNS 提供来双栈IP优选机制,同一个域名,若 IPv4 的速度远快与 IPv6,那么 SmartDNS 就会阻止IPv6的解析、使用 IPv4 访问。可在配置文件中通过设置 `dualstack-ip-selection yes` 启用此功能,通过 `dualstack-ip-selection-threshold [time]` 来修改阈值。如果要完全禁止 IPv6 AAAA记录解析,可设置 `force-AAAA-SOA yes`。
 
-8. 如何提高缓存效率,加快访问速度?
-   
+1. 如何提高缓存效率,加快访问速度?
+
     SmartDNS 提供了域名缓存机制,对查询的域名,进行缓存,缓存时间符合 DNS TTL 规范。为提高缓存命中率,可采用如下措施:  
-   
-   * 适当增大缓存的记录数
-     
+
+   - 适当增大缓存的记录数
+
      通过 `cache-size` 来设置缓存记录数。  
-     
+
      查询压力大的环境下,并且有内存大的机器的情况下,可适当调大。  
-   
-   * 适当设置最小 TTL 值
-     
+
+   - 适当设置最小 TTL 值
+
      通过 `rr-ttl-min` 将最低 DNS TTL 时间设置为一个合理值,延长缓存时间。
-     
+
      建议是超时时间设置在 10~30 分钟,避免服务器域名变化时,查询到失效域名。
-   
-   * 开启域名预获取功能
-     
+
+   - 开启域名预获取功能
+
      通过 `prefetch-domain yes` 来启用域名预先获取功能,提高查询命中率。
-     
+
      配合上述 TTL 超时时间,SmartDNS 将在域名 TTL 即将超时时,再次发送查询请求,并缓存查询结果供后续使用。频繁访问的域名将会持续缓存。此功能将在空闲时消耗更多的 CPU。
-   
-   * 过期缓存服务功能  
-     
+
+   - 过期缓存服务功能  
+
      通过 `serve-expired` 来启用过期缓存服务功能,可提高缓存命中率的同时,降低CPU占用。
-     
+
      此功能会在TTL超时后,将返回 TTL=0 给客户端,并且同时再次发送查询请求,并缓存新的结果给后续使用。
 
-9. 第二 DNS 如何自定义更多行为?
-   
+1. 第二 DNS 如何自定义更多行为?
+
    第二 DNS 可以作为其他 DNS 服务器的上游,提供更多的查询行为,通过 bind 配置支持可以绑定多个端口,不同端口可设置不同的标志,实现不同的功能,如
-   
-   ```sh
+
+   ```shell
    # 绑定 6053 端口,6053 端口的请求将采用配置 office 组的上游查询,且不对结果进行测速,忽略 address 的配置地址
    bind [::]:6053 -no-speed-check -group office -no-rule-addr
    ```
 
-10. DoT 的 SPKI 如何获取?
+1. DoT 的 SPKI 如何获取?
     SPKI 可以通过 DNS 服务商发布的页面获取,如果没有发布,可以通过如下命令获取,其中将对应IP地址更换为要获取 SPKI 的 IP 地址。
 
-    ```sh
-    $ 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
+    ```shell
+    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
     ```
 
-11. iOS系统解析缓慢问题怎么解决?  
+1. iOS系统解析缓慢问题怎么解决?  
     IOS14开始,苹果支持了DNS HTTPS(TYPE65)记录的解析,此功能用于快速DNS查询和解决HTTPS链接相关的问题,但当前还是草案,另外会导致广告屏蔽等功能失效,建议通过如下配置关闭TYPE65记录查询。
 
-    ```sh
+    ```shell
     force-qtype-SOA 65
     ```
 
-12. 如何解析本地主机名称?  
+1. 如何解析本地主机名称?  
     smartdns可以配合DNSMASQ的dhcp lease文件支持本地主机名->IP地址的解析,可以配置smartdns读取dnsmasq的lease文件,并支持解析。具体配置参数如下,(注意,DNSMASQ lease文件每个系统可能不一样,需要按实际情况配置)
 
-    ```
+    ```shell
     dnsmasq-lease-file /var/lib/misc/dnsmasq.leases
     ```
 
     配置完成后,可以直接使用主机名连接对应的机器。但需要注意:
 
-    * Windows系统默认使用mDNS解析地址,如需要在windows下用使用smartdns解析,则需要在主机名后面增加`.`,表示使用DNS解析。如`ping smartdns.`
+    - Windows系统默认使用mDNS解析地址,如需要在windows下用使用smartdns解析,则需要在主机名后面增加`.`,表示使用DNS解析。如`ping smartdns.`
 
-13. 域名集合如何使用?  
+1. 域名集合如何使用?  
     为方便按集合配置域名,对于有/domain/的配置,可以指定域名集合,方便维护。具体方法为:
-    
-    * 使用`domain-set`配置集合文件,如
-    
-    ```sh
+
+    - 使用`domain-set`配置集合文件,如
+
+    ```shell
     domain-set -name ad -file /etc/smartdns/ad-list.conf
     ```
 
     ad-list.conf的格式为一个域名一行,如
-    
-    ```
+
+    ```shell
     ad.com
     site.com
     ```
 
-    * 在有/domain/配置的选项使用域名集合,只需要将`/domain/`配置为`/domain-set:[集合名称]/`即可,如:
+    - 在有/domain/配置的选项使用域名集合,只需要将`/domain/`配置为`/domain-set:[集合名称]/`即可,如:
 
-    ```sh
+    ```shell
     address /domain-set:ad/#
     domain-rules /domain-set:ad/ -a #
     nameserver /domain-set:ad/server
     ...
     ```
 
-14. 更多问题  
+1. 如何使用ipset和nftset  
+    和Dnsmasq类似,smartdns支持ipset和nftset,可以将特定的域名通过TPROXY进行透明转发,透明转发涉工具模式对比如下:
+
+    1. 工具:iptable,nftable
+
+        iptable:成熟的路由规则配置工具。  
+        nftable:更加强大的规则配置工具,正在成为主流。
+
+    1. 模式:TPROXY,REDIRECT
+
+        TPROXY:支持UDP,TCP的转发,配置稍复杂。  
+        REDIRECT:仅支持TCP,配置简单。
+
+    此处仅以最常用的iptable/REDIRECT配合ipset的配置为例,具体转发配置如下:
+
+    - 在smartdns.conf中设置需要透明转发的域名列表,比如要将`example.com`进行透明转发。则使用ipset选项,设置`example.com`的ipset规则为`proxy`。
+
+    ```shell
+    # 设置规则
+    # -ipset proxy: 匹配的域名设置到ipset:tproxy中。
+    # -c none: 停用测速
+    # -address #6: 停用IPV6解析。
+    domain-rules /example.com/ -ipset proxy -c none -address #6
+    ```
+
+    - 执行shell命令,设置iptable规则,将匹配的域名请求进行透明转发,规则参考如下:
+
+    ```shell
+    # 创建ipset集合
+    ipset create proxy hash:net
+    # 设置转发规则,将匹配的请求转发到本机的1081端口
+    iptables -t nat -I PREROUTING -p tcp -m set --match-set proxy dst -j REDIRECT --to-ports 1081
+    ```
+
+    - 在本机1081端口开启REDIRECT模式的转发程序。
+
+    - 额外说明  
+      为保证DNS查询结果的位置亲和性,可以使用smartdns的`server`代理参数,将对应域名的查询请求,通过代理查询,使结果位置更好。如:
+
+      ```shell
+      # 增加DNS上游,并设置通过名称为proxy的代理查询,查询组为pass
+      server 1.2.3.4 -proxy proxy -group pass -exclude-default-group
+      # 设置代理服务器信息,代理的名称为proxy
+      proxy-server socks5://user:[email protected] -name proxy
+      # 设置域名规则,对匹配的域名使用代理查询结果,并将结果设置到ipset中。
+      domain-rules /example.com/ -ipset proxy -c none -address #6 -nameserver pass
+      ```
+
+    如果使用openwrt的luci界面,可以直接在界面配置相关的域名分流规则。
+
+1. 更多问题  
     如有更多问题,请查阅或提交issue: [https://github.com/pymumu/smartdns/issues](https://github.com/pymumu/smartdns/issues)
 
 ## 编译

+ 149 - 108
ReadMe_en.md

@@ -97,28 +97,28 @@ From the comparison, smartdns found the fastest IP address to visit www.baidu.co
 1. **Multiple upstream DNS servers**  
    Support configuring multiple upstream DNS servers and query at the same time.the query will not be affected, Even if there is a DNS server exception.  
 
-2. **Return the fastest IP address**  
+1. **Return the fastest IP address**  
    Supports finding the fastest access IP address from the IP address list of the domain name and returning it to the client to avoid DNS pollution and improve network access speed.
 
-3. **Support for multiple query protocols**  
+1. **Support for multiple query protocols**  
    Support UDP, TCP, DOT(DNS over TLS), DOH(DNS over HTTPS) queries, and non-53 port queries, effectively avoiding DNS pollution and protect privacy, and support query DNS over socks5, http proxy.
 
-4. **Domain IP address specification**  
+1. **Domain IP address specification**  
    Support configuring IP address of specific domain to achieve the effect of advertising filtering, and avoid malicious websites.
 
-5. **Domain name high performance rule filtering**  
+1. **Domain name high performance rule filtering**  
    Support domain name suffix matching mode, simplify filtering configuration, filter 200,000 recording and take time <1ms.
 
-6. **Linux/Windows multi-platform support**  
+1. **Linux/Windows multi-platform support**  
    Support standard Linux system (Raspberry Pi), openwrt system various firmware, ASUS router native firmware. Support Windows 10 WSL (Windows Subsystem for Linux).
 
-7. **Support IPV4, IPV6 dual stack**  
-   Support IPV4, IPV6 network, support query A, AAAA record, dual-stack IP selection, and disale IPV6 AAAA record.
+1. **Support IPV4, IPV6 dual stack**  
+   Support IPV4, IPV6 network, support query A, AAAA record, dual-stack IP selection, and filter IPV6 AAAA record.
 
-8. **High performance, low resource consumption**  
+1. **High performance, low resource consumption**  
    Multi-threaded asynchronous IO mode, cache cache query results.
 
-9. **DNS domain forwarding**
+1. **DNS domain forwarding**
    Support DNS forwarding, ipset and nftables.
 
 ## Architecture
@@ -126,9 +126,9 @@ From the comparison, smartdns found the fastest IP address to visit www.baidu.co
 ![Architecture](doc/architecture.png)
 
 1. SmartDNS receives DNS query requests from local network devices, such as PCs and mobile phone query requests.
-2. SmartDNS sends query requests to multiple upstream DNS servers, using standard UDP queries, non-standard port UDP queries, and TCP queries.
-3. The upstream DNS server returns a list of Server IP addresses corresponding to the domain name. SmartDNS detects the fastest Server IP with local network access.
-4. Return the fastest accessed Server IP to the local client.
+1. SmartDNS sends query requests to multiple upstream DNS servers, using standard UDP queries, non-standard port UDP queries, and TCP queries.
+1. The upstream DNS server returns a list of Server IP addresses corresponding to the domain name. SmartDNS detects the fastest Server IP with local network access.
+1. Return the fastest accessed Server IP to the local client.
 
 ## Usage
 
@@ -138,10 +138,10 @@ smartdns can already be installed using system package management tools.
 
 System|Installation|Instructions|
 --|--|--
-openwrt|opkg update<br>opkg install luci-app-smartdns<br>opkg install smartdns|systems after 22.03. Software source: https://downloads.openwrt.org/releases/
-ddwrt|latest firmware. goto services page abd enable SmartDNS Resolver. |Demo: https://forum.dd-wrt.com/demo/Services.html
+openwrt|opkg update<br />opkg install luci-app-smartdns<br />opkg install smartdns|systems after 22.03. Software source: <https://downloads.openwrt.org/releases/>
+ddwrt|latest firmware. goto services page abd enable SmartDNS Resolver. |Demo: <https://forum.dd-wrt.com/demo/Services.html>
 debian|apt-get install smartdns|
-entware|ipkg update<br>ipkg install smartdns|Software source: https://bin.entware.net/
+entware|ipkg update<br />ipkg install smartdns|Software source: <https://bin.entware.net/>
 
 ### Download the package
 
@@ -165,15 +165,15 @@ Download the matching version of the SmartDNS installation package. The correspo
 |openwrt LUCI|luci-app-smartdns.xxxxxxxxx.all.ipk|Openwrt management interface.
 |openwrt LUCI|luci-app-smartdns.xxxxxxxxx.all-luci-compat-all|Compat Openwrt management interface for early openwrt.
 
-* The released packages are statically compiled. If you need a small size package, please compile it yourself or obtain it from the openwrt / entware repository.
+- The released packages are statically compiled. If you need a small size package, please compile it yourself or obtain it from the openwrt / entware repository.
 
-* **Please download from the Release page: [Download here](https://github.com/pymumu/smartdns/releases)**
+- **Please download from the Release page: [Download here](https://github.com/pymumu/smartdns/releases)**
 
 ```shell
 https://github.com/pymumu/smartdns/releases
 ```
 
-* For the installation procedure, please refer to the following sections.
+- For the installation procedure, please refer to the following sections.
 
 ### Standard Linux system installation/Raspberry Pi, X86_64 system
 
@@ -195,10 +195,11 @@ https://github.com/pymumu/smartdns/releases
     chmod +x ./install
     ./install -i
     ```
+
     **For Ubuntu system:**
-    * `systemd-resolved` occupies TCP53 and UDP53 ports. You need to manually resolve the port occupancy problem or modify the SmartDNS listening port
+    - `systemd-resolved` occupies TCP53 and UDP53 ports. You need to manually resolve the port occupancy problem or modify the SmartDNS listening port
 
-    * Log files in `/var/log/smartdns/smartdns.log`
+    - Log files in `/var/log/smartdns/smartdns.log`
 
 1. Configuration
 
@@ -211,7 +212,8 @@ https://github.com/pymumu/smartdns/releases
     ```
 
     `smartdns.conf` example:
-    ```
+
+    ```shell
     # set listen port
     bind []:53 
     # set upstream servers
@@ -232,8 +234,8 @@ https://github.com/pymumu/smartdns/releases
 1. Forwarding DNS request to SmartDNS
 
     Modify the DNS server of the local router and configure the DNS server as SmartDNS.
-    * Log in to the router on the local network and configure the Raspberry Pi to assign a static IP address.
-    * Modify the WAN port or DHCP DNS to the Raspberry Pi IP address.
+    - Log in to the router on the local network and configure the Raspberry Pi to assign a static IP address.
+    - Modify the WAN port or DHCP DNS to the Raspberry Pi IP address.
     Note:
     I. Each router configuration method is different. Please search Baidu for related configuration methods.
     II. some routers may not support configuring custom DNS server. in this case, please modify the PC's, mobile phone's DNS server to the ip of Raspberry Pi.
@@ -265,26 +267,26 @@ https://github.com/pymumu/smartdns/releases
     opkg install luci-app-smartdns.xxxxxxxx.xxxx.all.ipk
     ```
 
-    * Note: For versions before openwrt 19.07, please install `luci-app-smartdns.xxxxxxxxx.all-luci-compat-all` package.
+    - Note: For versions before openwrt 19.07, please install `luci-app-smartdns.xxxxxxxxx.all-luci-compat-all` package.
 
 1. Configuration
 
     Log in to the openwrt management page and open `Services`->`SmartDNS` to configure SmartDNS.
-    * Add upstream DNS server configuration to `Upstream Servers`. It is recommended to configure multiple DNS servers at home and abroad.
-    * Specify the IP address of a specific domain name in `Domain Address`, which can be used for ad blocking.
+    - Add upstream DNS server configuration to `Upstream Servers`. It is recommended to configure multiple DNS servers at home and abroad.
+    - Specify the IP address of a specific domain name in `Domain Address`, which can be used for ad blocking.
 
 1. Start Service
 
    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 
+1. Method 1: SmartDNS as primary DNS Server
 
-    * **Enable SmartDNS as primary DNS Server**
+    - **Enable SmartDNS as primary DNS Server**
 
         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**
+    - **Check if the service is configured successfully**
 
         Query domain name with `nslookup -querytype=ptr smartdns`
         See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns`
@@ -304,8 +306,8 @@ https://github.com/pymumu/smartdns/releases
 
 1. Note
 
-   * 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
+   - 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
@@ -328,7 +330,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     Log in to the management interface, click `System Management`-> Click `System Settings` and configure `Enable SSH` to `Lan Only`.  
     The SSH login username and password are the same as the management interface.
 
-1. Insstall `Download Master`
+1. Install `Download Master`
 
     In the management interface, click `USB related application`-> click `Download Master` to download.  
     After the download is complete, enable `Download Master`. If you do not need the download function, you can uninstall `Download Master` here, but make sure that Download Master is enabled before uninstalling.  
@@ -382,9 +384,10 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     ```shell
     vi /opt/etc/smartdns/smartdns.conf
     ```
-    
+
     `smartdns.conf` example:
-    ```
+
+    ```shell
     # set listen port
     bind []:53 
     # set upstream servers
@@ -411,7 +414,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 
 1. Install SmartDNS
 
-    Upload the software to `/tmp` directory of the router using winscp, and run the flollowing command to install.
+    Upload the software to `/tmp` directory of the router using winscp, and run the following command to install.
 
     ```shell
     ipkg install smartdns.xxxxxxx.mipsbig.ipk
@@ -424,7 +427,8 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     ```
 
     `smartdns.conf` example:
-    ```
+
+    ```shell
     # set listen port
     bind []:53 
     # set upstream servers
@@ -435,7 +439,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     domain-rule /example.com/ -address 1.2.3.4
     ```
 
-    Note: if you need to support IPV6, you can set the worke-mode to `2`, this will disable the DNS service of dnsmasq, and smartdns run as the primary DNS server. Change `SMARTDNS_WORKMODE` in the file `/opt/etc/smartdns/smartdns-opt.conf` to 2.
+    Note: if you need to support IPV6, you can set the work-mode to `2`, this will disable the DNS service of dnsmasq, and smartdns run as the primary DNS server. Change `SMARTDNS_WORKMODE` in the file `/opt/etc/smartdns/smartdns-opt.conf` to `2`.
 
     ```shell
     SMARTDNS_WORKMODE="2"
@@ -455,7 +459,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     smartdns        name = smartdns.
     ```
 
-    Note: If the service does not start automatically, you need to set optwre/entware to start automatically. For details, see the optware/entware documentation.
+    Note: If the service does not start automatically, you need to set optware/entware to start automatically. For details, see the optware/entware documentation.
 
 ### Windows 10 WSL Installation/WSL ubuntu
 
@@ -467,7 +471,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 
 1. Install smartdns
 
-    download install package `smartdns.xxxxxxxx.x86_64-linux-all.tar.gz`,and unzip to the `D:\` directory, after decompression, the directory is as follows: 
+    download install package `smartdns.xxxxxxxx.x86_64-linux-all.tar.gz`,and unzip to the `D:\` directory, after decompression, the directory is as follows:
 
     ```shell
     D:\SMARTDNS
@@ -491,7 +495,8 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     Configure as many upstream DNS servers as possible, including servers at home and abroad. Please refer to the `Configuration Parameters` section for configuration parameters.  
 
     `smartdns.conf` example:
-    ```
+
+    ```shell
     # set listen port
     bind []:53 
     # set upstream servers
@@ -501,7 +506,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     address /example.com/1.2.3.4
     domain-rule /example.com/ -address 1.2.3.4
     ```
-    
+
 1. Start Service
 
     Double-click `reload.bat` in the `D:\smartdns\package\windows` directory for reload.
@@ -528,12 +533,12 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 
 |parameter|Parameter function|Default value|Value type|Example|
 |--|--|--|--|--|
-|server-name|DNS name|host name/smartdns|any string like hosname|server-name smartdns
-|bind|DNS listening port number|[::]:53|Support binding multiple ports<br>`IP:PORT@DEVICE`: server IP, port number, and device. <br>`[-group]`: The DNS server group used when requesting. <br>`[-no-rule-addr]`: Skip the address rule. <br>`[-no-rule-nameserver]`: Skip the Nameserver rule. <br>`[-no-rule-ipset]`: Skip the Ipset or nftset rules. <br>`[-no-rule-soa]`: Skip address SOA(#) rules.<br>`[-no-dualstack-selection]`: Disable dualstack ip selection.<br>`[-no-speed-check]`: Disable speed measurement. <br>`[-no-cache]`: stop caching |bind :53@eth0
-|bind-tcp|TCP mode DNS listening port number|[::]:53|Support binding multiple ports<br>`IP:PORT@DEVICE`: server IP, port number and device. <br>`[-group]`: The DNS server group used when requesting. <br>`[-no-rule-addr]`: Skip the address rule. <br>`[-no-rule-nameserver]`: Skip the Nameserver rule. <br>`[-no-rule-ipset]`: Skip the Ipset or nftset rules. <br>`[-no-rule-soa]`: Skip address SOA(#) rules.<br>`[-no-dualstack-selection]`: Disable dualstack ip selection.<br>`[-no-speed-check]`: Disable speed measurement. <br>`[-no-cache]`: stop caching |bind-tcp :53
+|server-name|DNS name|host name/smartdns|any string like hostname|server-name smartdns
+|bind|DNS listening port number|[::]:53|Support binding multiple ports<br />`IP:PORT@DEVICE`: server IP, port number, and device. <br />`[-group]`: The DNS server group used when requesting. <br />`[-no-rule-addr]`: Skip the address rule. <br />`[-no-rule-nameserver]`: Skip the Nameserver rule. <br />`[-no-rule-ipset]`: Skip the Ipset or nftset rules. <br />`[-no-rule-soa]`: Skip address SOA(#) rules.<br />`[-no-dualstack-selection]`: Disable dualstack ip selection.<br />`[-no-speed-check]`: Disable speed measurement. <br />`[-no-cache]`: stop caching |bind :53@eth0
+|bind-tcp|TCP mode DNS listening port number|[::]:53|Support binding multiple ports<br />`IP:PORT@DEVICE`: server IP, port number and device. <br />`[-group]`: The DNS server group used when requesting. <br />`[-no-rule-addr]`: Skip the address rule. <br />`[-no-rule-nameserver]`: Skip the Nameserver rule. <br />`[-no-rule-ipset]`: Skip the Ipset or nftset rules. <br />`[-no-rule-soa]`: Skip address SOA(#) rules.<br />`[-no-dualstack-selection]`: Disable dualstack ip selection.<br />`[-no-speed-check]`: Disable speed measurement. <br />`[-no-cache]`: stop caching |bind-tcp :53
 |cache-size|Domain name result cache number|512|integer|cache-size 512
 |cache-persist|enable persist cache|Auto: Enabled if the location of `cache-file` has more than 128MB of free space.|[yes\|no]|cache-persist yes
-|cache-file|cache persist file|/tmp/smartdns.cache|路径|cache-file /tmp/smartdns.cache
+|cache-file|cache persist file|/tmp/<br />smartdns.cache|path|cache-file /tmp/smartdns.cache
 |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
@@ -542,73 +547,73 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 |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
 |log-level|log level|error|fatal,error,warn,notice,info,debug|log-level error
-|log-file|log path|/var/log/smartdns/smartdns.log|File Pah|log-file /var/log/smartdns/smartdns.log
+|log-file|log path|/var/log/<br />smartdns/<br />smartdns.log|File Pah|log-file /var/log/smartdns/smartdns.log
 |log-size|log size|128K|number+K,M,G|log-size 128K
 |log-num|archived log number|2 for openwrt, 8 for other system|Integer, 0 means turn off the log|log-num 2
 |log-file-mode|archived log file mode|0640|Integer|log-file-mode 644
 |audit-enable|audit log enable|no|[yes\|no]|audit-enable yes
-|audit-file|audit log file|/var/log/smartdns/smartdns-audit.log|File Path|audit-file /var/log/smartdns/smartdns-audit.log
+|audit-file|audit log file|/var/log/<br />smartdns/<br />smartdns-audit.log|File Path|audit-file /var/log/smartdns/smartdns-audit.log
 |audit-size|audit log size|128K|number+K,M,G|audit-size 128K
 |audit-num|archived audit log number|2|Integer, 0 means turn off the log|audit-num 2
 |audit-file-mode|archived audit log file mode|0640|Integer|audit-file-mode 644
 |conf-file|additional conf file|None|File path|conf-file /etc/smartdns/smartdns.more.conf
-|server|Upstream UDP DNS server|None|Repeatable <br>`[ip][:port]\|URL`: Server IP, port optional OR URL. <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. <br>`[-set-mark mark]`:set mark on packets <br> `[-proxy name]`: set proxy server| server 8.8.8.8:53 -blacklist-ip<br>server tls://8.8.8.8
-|server-tcp|Upstream TCP DNS server|None|Repeatable <br>`[ip][:port]`: Server IP, port optional. <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 <br>`[-set-mark mark]`:set mark on packets <br> `[-proxy name]`: set proxy server| server-tcp 8.8.8.8:53
-|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. `-` to disable SNI 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 <br> `[-set-mark mark]`:set mark on packets <br> `[-proxy name]`: set proxy server| 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 <br> `[-set-mark mark]`:set mark on packets <br> `[-proxy name]`: set proxy server| server-https https://cloudflare-dns.com/dns-query
-|proxy-server| proxy server | None | Repeatable. <br>`proxy-server URL` <br>[URL]: `[socks5\|http]://[username:password@]host:port`<br>[-name]:  proxy server name. |proxy-server socks5://user:[email protected]:1080 -name proxy|
+|server|Upstream UDP DNS server|None|Repeatable <br />`[ip][:port]\|URL`: Server IP, port optional OR URL. <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. <br />`[-set-mark mark]`:set mark on packets <br /> `[-proxy name]`: set proxy server| server 8.8.8.8:53 -blacklist-ip<br />server tls://8.8.8.8
+|server-tcp|Upstream TCP DNS server|None|Repeatable <br />`[ip][:port]`: Server IP, port optional. <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 <br />`[-set-mark mark]`:set mark on packets <br /> `[-proxy name]`: set proxy server| server-tcp 8.8.8.8:53
+|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. `-` to disable SNI 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 <br /> `[-set-mark mark]`:set mark on packets <br /> `[-proxy name]`: set proxy server| 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 <br /> `[-set-mark mark]`:set mark on packets <br /> `[-proxy name]`: set proxy server| server-https <https://cloudflare-dns.com/dns-query>
+|proxy-server| proxy server | None | Repeatable. <br />`proxy-server URL` <br />[URL]: `[socks5\|http]://[username:password@]host:port`<br />[-name]:  proxy server name. |proxy-server socks5://user:[email protected]:1080 -name proxy|
 |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\|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 |
+|response-mode|First query response mode|first-ping|Mode: [first-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|no|[yes\|no]|ipset-timeout yes
-|nftset|Domain nftset|None|nftset /domain/[#4\|#6\|-]:[family#nftable#nftset\|-][,#[4\|6]:[family#nftable#nftset\|-]]], `-` to ignore; the valid families are inet and ip for ipv4 addresses while the valid ones are inet and ip6 for ipv6 addresses; due to the limitation of nft, two types of addresses have to be stored in two sets|nftset /www.example.com/#4:inet#mytab#dns4,#6:-
+|nftset|Domain nftset|None|nftset /domain/[#4\|#6\|-]:[family#nftable#nftset\|-][,#[4\|6]:[family#nftable#nftset\|-]]], `-` to ignore; the valid families are inet and ip for ipv4 addresses while the valid ones are inet and ip6 for ipv6 addresses; due to the limitation of nft, two types of addresses have to be stored in two sets|nftset /www.example.com/#4:inet#tab#dns4,#6:-
 |nftset-timeout|nftset timeout enable|no|[yes\|no]|nftset-timeout yes
 |nftset-debug|nftset debug enable|no|[yes\|no]|nftset-debug 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 `nftset`<br>[-t\|-nftset]: same as parameter `nftset`<br>[-d\|-dualstack-ip-selection]: same as parameter `dualstack-ip-selection`<br>  [-no-serve-expired]:disable serve expired|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, nftset, example: /domain-set:[name]/ | domain-set -name set -type list -file /path/to/list <br> address /domain-set:set/1.2.4.8 |
+|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 `nftset`<br />[-t\|-nftset]: same as parameter `nftset`<br />[-d\|-dualstack-ip-selection]: same as parameter `dualstack-ip-selection`<br />  [-no-serve-expired]:disable serve expired|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, nftset, 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
 |blacklist-ip|ip blacklist|None|[ip/subnet], Repeatable,When the filtering server responds IPs in the IP blacklist, The result will be discarded directly| blacklist-ip 1.2.3.4/16
 |force-AAAA-SOA|force AAAA query return SOA|no|[yes\|no]|force-AAAA-SOA yes
-|force-qtype-SOA|force specific qtype return SOA|qtype id|[qtypeid | ...]|force-qtype-SOA 65 28
+|force-qtype-SOA|force specific qtype return SOA|qtype id|[qtypeid \| ...]|force-qtype-SOA 65 28
 |prefetch-domain|domain prefetch feature|no|[yes\|no]|prefetch-domain yes
 |dnsmasq-lease-file|Support reading dnsmasq dhcp file to resolve local hostname|None|dnsmasq dhcp lease file| dnsmasq-lease-file /var/lib/misc/dnsmasq.leases
 |serve-expired|Cache serve expired feature|yes|[yes\|no], Attempts to serve old responses from cache with a TTL of 0 in the response without waiting for the actual resolution to finish.|serve-expired yes
-|serve-expired-ttl|Cache serve expired limite TTL|0|second,0:disable,> 0  seconds after expiration|serve-expired-ttl 0
+|serve-expired-ttl|Cache serve expired limit TTL|0|second,0:disable,> 0  seconds after expiration|serve-expired-ttl 0
 |serve-expired-reply-ttl|TTL value to use when replying with expired data|5|second,0:disable,> 0  seconds after expiration|serve-expired-reply-ttl 30
 |dualstack-ip-selection|Dualstack ip selection|yes|[yes\|no]|dualstack-ip-selection yes
-|dualstack-ip-selection-threshold|Dualstack ip select threadhold|15ms|millisecond|dualstack-ip-selection-threshold [0-1000]
+|dualstack-ip-selection-threshold|Dualstack ip select thresholds|15ms|millisecond|dualstack-ip-selection-threshold [0-1000]
 |user|run as user|root|user [username]|user nobody
-|ca-file|certificate file|/etc/ssl/certs/ca-certificates.crt|path|ca-file /etc/ssl/certs/ca-certificates.crt
+|ca-file|certificate file|/etc/ssl/certs/<br />ca-certificates.crt|path|ca-file /etc/ssl/certs/ca-certificates.crt
 |ca-path|certificates path|/etc/ssl/certs|path|ca-path /etc/ssl/certs
 
 ## FAQ
 
 1. What is the difference between SmartDNS and DNSMASQ?  
     Smartdns is not designed to replace DNSMASQ. The main function of Smartdns is focused on DNS resolution enhancement, the difference are:  
-    * Multiple upstream server concurrent requests, after the results are measured, return the best results;
-    * `address`, `ipset` domain name matching uses efficient algorithms, query matching is faster and more efficient, and router devices are still efficient.
-    * Domain name matching supports ignoring specific domain names, and can be individually matched to IPv4, IPV6, and supports diversified customization.
-    * Enhance the ad blocking feature, return SOA record, this block ads better;
-    * IPV4, IPV6 dual stack IP optimization mechanism, in the case of dual network, choose the fastest network.
-    * Supports the latest TLS, HTTPS protocol and provides secure DNS query capabilities.
-    * DNS anti-poison mechanism, and a variety of mechanisms to avoid DNS pollution.
-    * ECS support, the query results are better and more accurate.
-    * IP blacklist support, ignoring the blacklist IP to make domain name queries better and more accurate.
-    * Domain name pre-fetch, more faster to access popular websites.
-    * Domain name TTL can be specified to make access faster.
-    * Cache mechanism to make access faster.
-    * Asynchronous log, audit log mechanism, does not affect DNS query performance while recording information.
-    * Domain group mechanism, specific domain names use specific upstream server group queries to avoid privacy leakage.
-    * The second DNS supports customizing more behavior.
+    - Multiple upstream server concurrent requests, after the results are measured, return the best results;
+    - `address`, `ipset` domain name matching uses efficient algorithms, query matching is faster and more efficient, and router devices are still efficient.
+    - Domain name matching supports ignoring specific domain names, and can be individually matched to IPv4, IPV6, and supports diversified customization.
+    - Enhance the ad blocking feature, return SOA record, this block ads better;
+    - IPV4, IPV6 dual stack IP optimization mechanism, in the case of dual network, choose the fastest network.
+    - Supports the latest TLS, HTTPS protocol and provides secure DNS query capabilities.
+    - DNS anti-poison mechanism, and a variety of mechanisms to avoid DNS pollution.
+    - ECS support, the query results are better and more accurate.
+    - IP blacklist support, ignoring the blacklist IP to make domain name queries better and more accurate.
+    - Domain name pre-fetch, more faster to access popular websites.
+    - Domain name TTL can be specified to make access faster.
+    - Cache mechanism to make access faster.
+    - Asynchronous log, audit log mechanism, does not affect DNS query performance while recording information.
+    - Domain group mechanism, specific domain names use specific upstream server group queries to avoid privacy leakage.
+    - The second DNS supports customizing more behavior.
 
 1. What is the best practices for upstream server configuration?  
     Smartdns has a speed measurement mechanism. When configuring an upstream server, it is recommended to configure multiple upstream DNS servers, including servers in different regions, but the total number is recommended to be around 10. Recommended configuration
-    * Carrier DNS.
-    * Public DNS, such as `8.8.8.8`, `8.8.4.4`, `1.1.1.1`.
+    - Carrier DNS.
+    - Public DNS, such as `8.8.8.8`, `8.8.4.4`, `1.1.1.1`.
 
     For specific domain names, if there is a pollution, you can enable the anti-pollution mechanism.
 
@@ -617,27 +622,27 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 
 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.
+    - Use trusted DNS servers.
+    - Use TLS servers.
+    - Set up an upstream DNS server group.
 
 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
+    ```shell
     Address /ad.com/#
     ```
 
     The suffix mode of the domain name, filtering *.ad.com, `#` means returning SOA record. If you want to only block IPV4 or IPV6 separately, add a number after `#`, such as `#4` is for IPV4 blocking. If you want to ignore some specific subdomains, you can configure it as follows. e.g., if you ignore `pass.ad.com`, you can configure it as follows:
 
-    ```sh
+    ```shell
     Address /pass.ad.com/-
     ```
 
 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
+    ```shell
     .home -> 192.168.1.1
     .office -> 10.0.0.1
     ```
@@ -647,7 +652,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     Other domain names are resolved using the default mode.
     The diversion configuration for this case is as follows:
 
-    ```sh
+    ```shell
     # Upstream configuration, use -group to specify the group name, and -exclude-default-group to exclude the server from the default group.
     Server 192.168.1.1 -group home -exclude-default-group
     Server 10.0.0.1 -group office -exclude-default-group
@@ -660,7 +665,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 
     You can use the above configuration to implement DNS resolution and offload. If you need to implement traffic distribution on the requesting port, you can configure the second DNS server. The bind configuration is added. The group parameter specifies the traffic distribution name.
 
-    ```sh
+    ```shell
     Bind :7053 -group office
     Bind :8053 -group home
     ```
@@ -668,28 +673,28 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 1. How to use the IPV4, IPV6 dual stack IP optimization feature  
     At present, IPV6 network is not as fast as IPV4 in some cases. In order to get a better experience in the dual-stack network, SmartDNS provides a dual-stack IP optimization mechanism, the same domain name, and the speed of IPV4. Far faster than IPV6, then SmartDNS will block the resolution of IPV6, let the PC use IPV4, the feature is enabled by `dualstack-ip-selection yes`, `dualstack-ip-selection-threshold [time]` is for threshold. if you want to disable IPV6 AAAA record complete, please try `force-AAAA-SOA yes`.
 
-1. How to improve cache performace  
+1. How to improve cache performance  
     Smartdns provides a domain name caching mechanism to cache the queried domain name, and the caching time is in accordance with the DNS TTL specification. To increase the cache hit rate, the following configuration can be taken:
-    * Increase the number of cache records appropriately  
+    - Increase the number of cache records appropriately  
     Set the number of cache records by `cache-size`.
     In the case of a query with a high pressure environment and a machine with a large memory, it can be appropriately adjusted.
 
-    * Set the minimum TTL value as appropriate  
+    - Set the minimum TTL value as appropriate  
     Set the minimum DNS TTL time to a appropriate value by `rr-ttl-min` to extend the cache time.
     It is recommended that the timeout period be set to 10 to 30 minutes to avoid then invalid domain names when domain ip changes.
 
-    * Enable domain pre-acquisition  
+    - Enable domain pre-acquisition  
     Enable pre-fetching of domain names with `prefetch-domain yes` to improve query hit rate.
     by default, Smartdns will send domain query request again before cache expire, and cache the result for the next query. Frequently accessed domain names will continue to be cached. This feature will consume more CPU when idle.
 
-    * Cache serve expired feature  
+    - Cache serve expired feature  
     Enable cache serve expired feature with `serve-expired yes` to improve the cache hit rate and reduce the CPU consumption.
     This feature will return TTL = 0 to the client after the TTL timeout, and send a new query request again at the same time, and cache the new results for later query.
 
 1. How does the second DNS customize more behavior?  
     The second DNS can be used as the upstream of other DNS servers to provide more query behaviors. Bind configuration support can bind multiple ports. Different ports can be set with different flags to implement different functions, such as
 
-    ```sh
+    ```shell
     # Binding 6053 port, request for port 6053 will be configured with the upstream query of the office group, and the result will not be measured. The address configuration address is ignored.
     bind [::]:6053 -no-speed-check -group office -no-rule-addr
     ```
@@ -697,61 +702,97 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
 1. How to get SPKI of DOT  
     The SPKI can be obtained from the page published by the DNS service provider. If it is not published, it can be obtained by the following command, replace IP with your own IP.
 
-    ```sh
+    ```shell
     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
+    ```shell
     force-qtype-SOA 65
     ```
 
 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
+    ```shell
     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.`
+    - 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
+
+    - Use `domain-set` configuration domain set file:
+
+    ````shell
     domain-set -name ad -file /etc/smartdns/ad-list.conf
     ````
 
     The format of ad-list.conf is one domain per line:
-    
-    ````
+
+    ```shell
     ad.com
     site.com
-    ````
+    ```
 
-    * To use the domain set, you only need to configure `/domain/` to `/domain-set:[collection name]/`, such as:
+    - To use the domain set, you only need to configure `/domain/` to `/domain-set:[collection name]/`, such as:
 
-    ````sh
+    ````shell
     address /domain-set:ad/#
     domain-rules /domain-set:ad/ -a #
     nameserver /domain-set:ad/server
     ...
     ````
 
-1. More questions    
+1. How to use ipset and nftset
+    Similar to Dnsmasq, smartdns supports ipset and nftset, and can transparently forward specific domain names through TPROXY. The comparison of transparent forwarding and tool modes is as follows:
+
+    1. Tools: iptable, nftable
+
+        iptable: a mature routing rule configuration tool.
+        nftable: A more powerful rule configuration tool that is becoming mainstream.
+
+    1. Mode: TPROXY, REDIRECT
+
+        TPROXY: supports UDP and TCP forwarding, and the configuration is a little complicated.
+        REDIRECT: only supports TCP, easy to configure.
+
+    Here we only take the configuration of the most commonly used iptable/REDIRECT with ipset as an example. The specific forwarding configuration is as follows:
+
+    - Set the list of domain names that need to be transparently forwarded in smartdns.conf, for example, `example.com` needs to be transparently forwarded. Then use the ipset option and set the ipset rule of `example.com` to `proxy`.
+
+    ```shell
+    # set rules
+    # -ipset proxy: The matching domain name is set to ipset:proxy.
+    # -c none: Disable speed check.
+    # -address #6: Filter IPV6 record.
+    domain-rules /example.com/ -ipset proxy -c none -address #6
+    ```
+
+    - Execute shell commands, set iptable rules, and transparently forward matching domain name requests. The rules are as follows:
+
+    ```shell
+    # create ipset
+    ipset create proxy hash:net
+    # Set forwarding rules to forward matching requests to port 1081 of this machine
+    iptables -t nat -I PREROUTING -p tcp -m set --match-set proxy dst -j REDIRECT --to-ports 1081
+    ```
+
+    - Open the forwarding program of REDIRECT mode on port 1081 of this machine.
+
+1. More questions  
     More questions, please read issue: [https://github.com/pymumu/smartdns/issues](https://github.com/pymumu/smartdns/issues)
 
 ## Compile
 
-smartdns contains scripts for compiling packages, supports compiling luci, debian, openwrt, opare installation packages, and can execute `package/build-pkg.sh` compilation.
+smartdns contains scripts for compiling packages, supports compiling luci, debian, openwrt, optware installation packages, and can execute `package/build-pkg.sh` compilation.
 
-## [Donate](#Donate)  
+## [Donate](#donate)  
 
 If you feel that this project is helpful to you, please donate to us so that the project can continue to develop and be more perfect.
 

+ 2 - 2
etc/init.d/smartdns

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -93,7 +93,7 @@ case $1 in
 			exit 1
 		fi
 		echo "smartdns server is running."
-		status=$?
+		status=0
 		;;
 	*)
 		echo "Usage: $0 {start|stop|restart|status}"

+ 6 - 4
etc/smartdns/smartdns.conf

@@ -53,7 +53,7 @@ bind [::]:53
 cache-size 32768
 
 # enable persist cache when restart
-# cache-persist yes
+# cache-persist no
 
 # cache persist file
 # cache-file /tmp/smartdns.cache
@@ -168,7 +168,7 @@ log-level info
 # server [IP]:[PORT]|URL [-blacklist-ip] [-whitelist-ip] [-check-edns] [-group [group] ...] [-exclude-default-group]
 # default port is 53
 #   -blacklist-ip: filter result with blacklist ip
-#   -whitelist-ip: filter result whth whitelist ip,  result in whitelist-ip will be accepted.
+#   -whitelist-ip: filter result with whitelist ip,  result in whitelist-ip will be accepted.
 #   -check-edns: result must exist edns RR, or discard result.
 #   -group [group]: set server to group, use with nameserver /domain/group.
 #   -exclude-default-group: exclude this server from default group.
@@ -235,10 +235,12 @@ log-level info
 # ipset /www.example.com/-, ignore this domain
 
 # enable nftset timeout by ttl feature
-# nftset-timeout [yes]
+# nftset-timeout [yes|no]
+# nftset-timeout yes
 
 # enable nftset debug, check nftset setting result, output log when error.
-# nftset-debug [no]
+# nftset-debug [yes|no]
+# nftset-debug yes
 
 # specific nftset to domain
 # nftset /domain/[#4:ip#table#set,#6:ipv6#table#setv6]

+ 1 - 1
package/debian/make.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/linux/install

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/control/postinst

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/control/prerm

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/files/etc/uci-defaults/50_luci-smartdns

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/files/luci/controller/smartdns.lua

@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+-- Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 --
 -- smartdns is free software: you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua

@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+-- Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 --
 -- smartdns is free software: you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/files/luci/model/cbi/smartdns/upstream.lua

@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+-- Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 --
 -- smartdns is free software: you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/files/luci/model/smartdns.lua

@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+-- Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 --
 -- smartdns is free software: you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci-compat/files/luci/view/smartdns/smartdns_status.htm

@@ -7,7 +7,7 @@ XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "smartdns", "stat
 			if (data.running) {
 				links = '<b><font color=green>SmartDNS - <%:RUNNING%></font></b></em>';
 				if (data.dnsmasq_redirect_failure == 1) {
-					links += "<br></br><b><font color=red><%:Dnsmasq Forwared To Smartdns Failure%></font></b>"
+					links += "<br></br><b><font color=red><%:Dnsmasq Forwarded To Smartdns Failure%></font></b>"
 				}
 			} else {
 				links = '<b><font color=red>SmartDNS - <%:NOT RUNNING%></font></b>';

+ 1 - 1
package/luci-compat/make.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci/control/postinst

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci/control/prerm

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/luci/files/luci/i18n/smartdns.zh-cn.po

@@ -96,7 +96,7 @@ msgstr "默认"
 msgid "Description"
 msgstr "描述"
 
-msgid "Dnsmasq Forwared To Smartdns Failure"
+msgid "Dnsmasq Forwarded To Smartdns Failure"
 msgstr "重定向dnsmasq到smartdns失败"
 
 msgid "Do not check certificate."

+ 12 - 12
package/luci/files/root/www/luci-static/resources/view/smartdns/smartdns.js

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,11 +38,11 @@ var pollAdded = false;
 function getServiceStatus() {
 	return L.resolveDefault(callServiceList(conf), {})
 		.then(function (res) {
-			var isrunning = false;
+			var is_running = false;
 			try {
-				isrunning = res[conf]['instances']['smartdns']['running'];
+				is_running = res[conf]['instances']['smartdns']['running'];
 			} catch (e) { }
-			return isrunning;
+			return is_running;
 		});
 }
 
@@ -73,7 +73,7 @@ function smartdnsRenderStatus(res) {
 		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>";
+			renderHTML += "<br /><span style=\"color:red;font-weight:bold\">" + _("Dnsmasq Forwarded To Smartdns Failure") + "</span>";
 		}
 	}
 
@@ -90,7 +90,7 @@ return view.extend({
 	render: function (stats) {
 		var m, s, o;
 		var ss, so;
-		var servers, downlfiles;
+		var servers, download_files;
 
 		m = new form.Map('smartdns', _('SmartDNS'));
 		m.title = _("SmartDNS Server");
@@ -290,25 +290,25 @@ return view.extend({
 		o.rempty = true;
 
 		// include config
-		downlfiles = uci.sections('smartdns', 'download-file');
+		download_files = uci.sections('smartdns', 'download-file');
 		o = s.taboption("advanced", form.DynamicList, "conf_files", _("Include Config Files<br>/etc/smartdns/conf.d"),
 			_("Include other config files from /etc/smartdns/conf.d or custom path, can be downloaded from the download page."));
-		for (var i = 0; i < downlfiles.length; i++) {
-			if (downlfiles[i].type == undefined) {
+		for (var i = 0; i < download_files.length; i++) {
+			if (download_files[i].type == undefined) {
 				continue;
 			}
 
-			if (downlfiles[i].type != 'config') {
+			if (download_files[i].type != 'config') {
 				continue
 			}
 
-			o.value(downlfiles[i].name);
+			o.value(download_files[i].name);
 		}
 
 		///////////////////////////////////////
 		// second dns server;
 		///////////////////////////////////////
-		// Eanble;
+		// Enable;
 		o = s.taboption("seconddns", form.Flag, "seconddns_enabled", _("Enable"),
 			_("Enable or disable second DNS server."));
 		o.default = o.disabled;

+ 1 - 1
package/luci/make.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/openwrt/control/postinst

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 2 - 1
package/openwrt/control/prerm

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,6 +17,7 @@
 
 . ${IPKG_INSTROOT}/lib/functions.sh
 default_prerm $0 $@
+/etc/init.d/smartdns disable
 rm /var/etc/smartdns.conf -f
 rm /var/etc/smartdns/smartdns.conf -f
 rm /var/log/smartdns/ -fr

+ 4 - 4
package/openwrt/files/etc/init.d/smartdns

@@ -1,6 +1,6 @@
 #!/bin/sh /etc/rc.common
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -239,12 +239,12 @@ restart_crond()
 disable_auto_update()
 {
 	local no_restart="$1"
-	grep "/etc/init.d/smartdns" /etc/crontabs/root 1>/dev/null 2>&1
+	grep "/etc/init.d/smartdns updatefiles" /etc/crontabs/root 1>/dev/null 2>&1
 	if [ $? -ne 0 ]; then
 		return 
 	fi
 
-	sed -i '\@/etc/init.d/smartdns@d' /etc/crontabs/root
+	sed -i '\@/etc/init.d/smartdns updatefiles@d' /etc/crontabs/root
 
 	if [ "$no_restart" = "1" ]; then
 		return
@@ -621,7 +621,7 @@ load_service()
 
 	conf_append_bind "$port" "$device" "$tcp_server" "$ipv6_server" "$ARGS"
 
-	load_second_server $section
+	load_second_server "$section"
 
 	config_foreach load_server "server"
 

+ 1 - 1
package/openwrt/make.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 8 - 8
package/optware/S50smartdns

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@ SMARTDNS_OPT=/opt/etc/smartdns/smartdns-opt.conf
 SMARTDNS_WORKMODE="1"
 
 if [ -f "$SMARTDNS_OPT" ]; then
-. $SMARTDNS_OPT
+. "$SMARTDNS_OPT"
 fi
 
 
@@ -37,7 +37,7 @@ set_iptable()
 {
 	local redirect_tcp
 
-	redirect_tcp=0;
+	redirect_tcp=0
 
 	grep ^bind-tcp $SMARTDNS_CONF > /dev/null 2>&1
 	if [ $? -eq 0 ]; then
@@ -155,7 +155,7 @@ add_dhcp_options6()
 		SERVER_TAG="$(echo "$DHCP_OPTION" | awk -F= '{print $2}' | awk -F, '{print $1}')"
 		LOCAL_SERVER_IP="$IP"
 
-		grep "dhcp-option *= *$SERVER_TAG, *6 *, *$LOCAL_SERVER_IP" $CONF_FILE 1>/dev/null 2>&1
+		grep "dhcp-option *= *$SERVER_TAG, *6 *, *$LOCAL_SERVER_IP" "$CONF_FILE" 1>/dev/null 2>&1
 		if [ $? -eq 0 ]; then
 			continue
 		fi
@@ -182,7 +182,7 @@ clear_dhcp_options6()
 		SERVER_TAG="$(echo "$DHCP_OPTION" | awk -F= '{print $2}' | awk -F, '{print $1}')"
 		LOCAL_SERVER_IP="$IP"
 
-		grep "dhcp-option *= *$SERVER_TAG, *6 *, *$LOCAL_SERVER_IP" $CONF_FILE 1>/dev/null 2>&1
+		grep "dhcp-option *= *$SERVER_TAG, *6 *, *$LOCAL_SERVER_IP" "$CONF_FILE" 1>/dev/null 2>&1
 		if [ $? -ne 0 ]; then
 			continue
 		fi
@@ -201,7 +201,7 @@ set_dnsmasq_conf()
 	local CONF_FILE=$1
 	local DHCP_OPTIONS=""
 
-	add_dhcp_options6 $CONF_FILE
+	add_dhcp_options6 "$CONF_FILE"
 
 	grep "^port *=0" "$CONF_FILE" > /dev/null 2>&1
 	if [ $? -ne 0 ]; then
@@ -340,7 +340,7 @@ case "$1" in
 
 	set_smartdns_port
 	get_tz
-	$SMARTDNS_BIN -c $SMARTDNS_CONF -p $SMARTDNS_PID
+	$SMARTDNS_BIN -c "$SMARTDNS_CONF" -p $SMARTDNS_PID
 	if [ $? -ne 0 ]; then
 		clear_rule
 	fi
@@ -368,7 +368,7 @@ case "$1" in
 	fi
 
 	kill -15 "$pid" 2>/dev/null
-	SLEEP=`which usleep`
+	SLEEP=$(which usleep 2>/dev/null)
 	SLEEPTIME=200000
 	if [ -z "$SLEEP" ]; then
 		SLEEP="sleep"

+ 1 - 1
package/optware/control/postinst

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/optware/control/prerm

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/optware/make.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 1 - 1
package/windows/install.bat

@@ -12,7 +12,7 @@ IF NOT %ERRORLEVEL% == 0 (
 
 copy %CURR_PATH%\wsl-run.vbs "%STARTUP_PATH%/"
 IF NOT %ERRORLEVEL% == 0 (
-  echo Install startupt script failed.
+  echo Install startup script failed.
   pause
   exit 1
 )

+ 1 - 1
src/Makefile

@@ -1,5 +1,5 @@
 
-# Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+# Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
 #
 # smartdns is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by

+ 8 - 8
src/dns.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -889,7 +889,7 @@ int dns_add_SOA(struct dns_packet *packet, dns_rr_type type, const char *domain,
 	/*| mname        |
 	 *| rname        |
 	 *| serial       |
-	 *| refersh      |
+	 *| refresh      |
 	 *| retry        |
 	 *| expire       |
 	 *| minimum      |
@@ -926,7 +926,7 @@ int dns_get_SOA(struct dns_rrs *rrs, char *domain, int maxsize, int *ttl, struct
 	/*| mname        |
 	 *| rname        |
 	 *| serial       |
-	 *| refersh      |
+	 *| refresh      |
 	 *| retry        |
 	 *| expire       |
 	 *| minimum      |
@@ -1017,7 +1017,7 @@ int dns_get_OPT_ECS(struct dns_rrs *rrs, unsigned short *opt_code, unsigned shor
 	return 0;
 }
 
-int dns_add_OPT_TCP_KEEYALIVE(struct dns_packet *packet, unsigned short timeout)
+int dns_add_OPT_TCP_KEEPALIVE(struct dns_packet *packet, unsigned short timeout)
 {
 	unsigned short timeout_net = htons(timeout);
 	int data_len = 0;
@@ -1029,7 +1029,7 @@ int dns_add_OPT_TCP_KEEYALIVE(struct dns_packet *packet, unsigned short timeout)
 	return _dns_add_opt_RAW(packet, DNS_OPT_T_TCP_KEEPALIVE, &timeout_net, data_len);
 }
 
-int dns_get_OPT_TCP_KEEYALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
+int dns_get_OPT_TCP_KEEPALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
 							  unsigned short *timeout)
 {
 	unsigned char opt_data[DNS_MAX_OPT_LEN];
@@ -1528,7 +1528,7 @@ static int _dns_encode_CNAME(struct dns_context *context, struct dns_rrs *rrs)
 		return -1;
 	}
 
-	/* when code domain, len must plus 1, because of length at the begining */
+	/* when code domain, len must plus 1, because of length at the beginning */
 	rr_len = 1;
 	ret = _dns_encode_rr_head(context, domain, qtype, qclass, ttl, rr_len, &rr_len_ptr);
 	if (ret < 0) {
@@ -1815,7 +1815,7 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
 {
 	unsigned short opt_code = 0;
 	unsigned short opt_len = 0;
-	unsigned short ercode = (ttl >> 16) & 0xFFFF;
+	unsigned short errcode = (ttl >> 16) & 0xFFFF;
 	unsigned short ever = (ttl)&0xFFFF;
 	unsigned char *start = context->ptr;
 	struct dns_packet *packet = context->packet;
@@ -1858,7 +1858,7 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
 		return -1;
 	}
 
-	if (ercode != 0) {
+	if (errcode != 0) {
 		tlog(TLOG_ERROR, "extend rcode invalid.");
 		return -1;
 	}

+ 7 - 7
src/dns.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -81,7 +81,7 @@ typedef enum dns_opt_code {
 } dns_opt_code_t;
 
 /* https://datatracker.ietf.org/doc/draft-ietf-dnsop-svcb-https/11/ */
-typedef enum dns_htts_svcparam {
+typedef enum dns_https_svcparam {
 	DNS_HTTPS_T_MANDATORY = 0,
 	DNS_HTTPS_T_ALPN = 1,
 	DNS_HTTPS_T_NO_DEFAULT_ALPN = 2,
@@ -90,7 +90,7 @@ typedef enum dns_htts_svcparam {
 	DNS_HTTPS_T_ECH = 5,
 	DNS_HTTPS_T_IPV6HINT = 6,
 	DNS_HTTPS_T_ALL = 255
-} dns_htts_svcparam_t;
+} dns_https_svcparam_t;
 
 typedef enum dns_opcode {
 	DNS_OP_QUERY = 0,
@@ -129,7 +129,7 @@ struct dns_head {
 	unsigned short qdcount; /* number of question entries */
 	unsigned short ancount; /* number of answer entries */
 	unsigned short nscount; /* number of authority entries */
-	unsigned short nrcount; /* number of addititional resource entries */
+	unsigned short nrcount; /* number of additional resource entries */
 } __attribute__((packed, aligned(2)));
 
 #define DNS_PACKET_DICT_SIZE 16
@@ -143,7 +143,7 @@ struct dns_packet_dict {
 	struct dns_packet_dict_item names[DNS_PACKET_DICT_SIZE];
 };
 
-/* packet haed */
+/* packet head */
 struct dns_packet {
 	struct dns_head head;
 	unsigned short questions;
@@ -272,8 +272,8 @@ int dns_get_OPT_payload_size(struct dns_packet *packet);
 int dns_add_OPT_ECS(struct dns_packet *packet, struct dns_opt_ecs *ecs);
 int dns_get_OPT_ECS(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len, struct dns_opt_ecs *ecs);
 
-int dns_add_OPT_TCP_KEEYALIVE(struct dns_packet *packet, unsigned short timeout);
-int dns_get_OPT_TCP_KEEYALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
+int dns_add_OPT_TCP_KEEPALIVE(struct dns_packet *packet, unsigned short timeout);
+int dns_get_OPT_TCP_KEEPALIVE(struct dns_rrs *rrs, unsigned short *opt_code, unsigned short *opt_len,
 							  unsigned short *timeout);
 
 int dns_add_HTTPS_start(struct dns_rr_nested *svcparam_buffer, struct dns_packet *packet,

+ 1 - 1
src/dns_cache.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/dns_cache.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 23 - 23
src/dns_client.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -199,7 +199,7 @@ struct dns_client {
 	struct dns_client_ecs ecs_ipv4;
 	struct dns_client_ecs ecs_ipv6;
 
-	/* query doman hash table, key: sid + domain */
+	/* query domain hash table, key: sid + domain */
 	pthread_mutex_t domain_map_lock;
 	DECLARE_HASHTABLE(domain_map, 6);
 	DECLARE_HASHTABLE(group, 4);
@@ -632,7 +632,7 @@ errout:
 
 /* add server to group */
 static int _dns_client_add_to_group_pending(const char *group_name, char *server_ip, int port,
-											dns_server_type_t server_type, int ispending)
+											dns_server_type_t server_type, int is_pending)
 {
 	struct dns_server_info *server_info = NULL;
 
@@ -642,7 +642,7 @@ static int _dns_client_add_to_group_pending(const char *group_name, char *server
 
 	server_info = _dns_client_get_server(server_ip, port, server_type);
 	if (server_info == NULL) {
-		if (ispending == 0) {
+		if (is_pending == 0) {
 			tlog(TLOG_ERROR, "add server %s:%d to group %s failed", server_ip, port, group_name);
 			return -1;
 		}
@@ -1345,7 +1345,7 @@ errout:
 }
 
 static int _dns_client_add_server_pending(char *server_ip, char *server_host, int port, dns_server_type_t server_type,
-										  struct client_dns_server_flags *flags, int ispending)
+										  struct client_dns_server_flags *flags, int is_pending)
 {
 	int ret = 0;
 
@@ -1354,7 +1354,7 @@ static int _dns_client_add_server_pending(char *server_ip, char *server_host, in
 		return -1;
 	}
 
-	if (check_is_ipaddr(server_ip) && ispending) {
+	if (check_is_ipaddr(server_ip) && is_pending) {
 		ret = _dns_client_server_pending(server_ip, port, server_type, flags);
 		if (ret == 0) {
 			tlog(TLOG_INFO, "add pending server %s", server_ip);
@@ -1414,7 +1414,7 @@ static void _dns_client_query_release(struct dns_query_struct *query)
 
 	/* notify caller query end */
 	if (query->callback) {
-		tlog(TLOG_DEBUG, "result: %s, qtype: %d, hasresult: %d, id %d", query->domain, query->qtype, query->has_result,
+		tlog(TLOG_DEBUG, "result: %s, qtype: %d, has-result: %d, id %d", query->domain, query->qtype, query->has_result,
 			 query->sid);
 		query->callback(query->domain, DNS_QUERY_END, NULL, NULL, NULL, 0, query->user_ptr);
 	}
@@ -1611,7 +1611,7 @@ static int _dns_client_recv(struct dns_server_info *server_info, unsigned char *
 	if (len != 0) {
 		char host_name[DNS_MAX_CNAME_LEN];
 		tlog(TLOG_INFO, "decode failed, packet len = %d, tc = %d, id = %d, from = %s\n", inpacket_len, packet->head.tc,
-			 packet->head.id, gethost_by_addr(host_name, sizeof(host_name), from));
+			 packet->head.id, get_host_by_addr(host_name, sizeof(host_name), from));
 		if (dns_save_fail_packet) {
 			dns_packet_save(dns_save_fail_packet_dir, "client", host_name, inpacket, inpacket_len);
 		}
@@ -1806,7 +1806,7 @@ static int _dns_client_create_socket_udp(struct dns_server_info *server_info)
 	setsockopt(server_info->fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
 	setsockopt(server_info->fd, IPPROTO_IP, IP_TOS, &ip_tos, sizeof(ip_tos));
 	if (server_info->ai_family == AF_INET6) {
-		/* for recving ip ttl value */
+		/* for receiving ip ttl value */
 		setsockopt(server_info->fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on, sizeof(on));
 		setsockopt(server_info->fd, IPPROTO_IPV6, IPV6_2292HOPLIMIT, &on, sizeof(on));
 		setsockopt(server_info->fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &on, sizeof(on));
@@ -2170,7 +2170,7 @@ static int _dns_client_process_udp_proxy(struct dns_server_info *server_info, st
 	}
 
 	tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d",
-		 gethost_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len);
+		 get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len);
 
 	/* update recv time */
 	time(&server_info->last_recv);
@@ -2249,7 +2249,7 @@ static int _dns_client_process_udp(struct dns_server_info *server_info, struct e
 	}
 
 	tlog(TLOG_DEBUG, "recv udp packet from %s, len: %d, ttl: %d",
-		 gethost_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len, ttl);
+		 get_host_by_addr(from_host, sizeof(from_host), (struct sockaddr *)&from), len, ttl);
 
 	/* update recv time */
 	time(&server_info->last_recv);
@@ -2483,7 +2483,7 @@ static int _dns_client_process_tcp_buff(struct dns_server_info *server_info)
 			}
 
 			if (len > server_info->recv_buff.len - 2) {
-				/* len is not expceded, wait and recv */
+				/* len is not expected, wait and recv */
 				ret = 0;
 				goto out;
 			}
@@ -2619,7 +2619,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
 			return 0;
 		}
 
-		/* clear epllout event */
+		/* clear epollout event */
 		struct epoll_event mod_event;
 		memset(&mod_event, 0, sizeof(mod_event));
 		mod_event.events = EPOLLIN;
@@ -2998,7 +2998,7 @@ static int _dns_client_process(struct dns_server_info *server_info, struct epoll
 		/* receive from tcp */
 		return _dns_client_process_tcp(server_info, event, now);
 	} else if (server_info->type == DNS_SERVER_TLS || server_info->type == DNS_SERVER_HTTPS) {
-		/* recive from tls */
+		/* receive from tls */
 		return _dns_client_process_tls(server_info, event, now);
 	} else {
 		return -1;
@@ -3291,7 +3291,7 @@ static int _dns_client_send_packet(struct dns_query_struct *query, void *packet,
 				send_err = errno;
 				break;
 			default:
-				/* unsupport query type */
+				/* unsupported query type */
 				ret = -1;
 				break;
 			}
@@ -3344,7 +3344,7 @@ static int _dns_client_dns_add_ecs(struct dns_query_struct *query, struct dns_pa
 	return dns_add_OPT_ECS(packet, &query->ecs.ecs);
 }
 
-static int _dns_client_send_query(struct dns_query_struct *query, const char *doamin)
+static int _dns_client_send_query(struct dns_query_struct *query, const char *domain)
 {
 	unsigned char packet_buff[DNS_PACKSIZE];
 	unsigned char inpacket[DNS_IN_PACKSIZE];
@@ -3368,13 +3368,13 @@ static int _dns_client_send_query(struct dns_query_struct *query, const char *do
 	}
 
 	/* add question */
-	if (dns_add_domain(packet, doamin, query->qtype, DNS_C_IN) != 0) {
+	if (dns_add_domain(packet, domain, query->qtype, DNS_C_IN) != 0) {
 		tlog(TLOG_ERROR, "add domain to packet failed.");
 		return -1;
 	}
 
 	dns_set_OPT_payload_size(packet, DNS_IN_PACKSIZE);
-	/* dns_add_OPT_TCP_KEEYALIVE(packet, 600); */
+	/* dns_add_OPT_TCP_KEEPALIVE(packet, 600); */
 	if (_dns_client_dns_add_ecs(query, packet) != 0) {
 		tlog(TLOG_ERROR, "add ecs failed.");
 		return -1;
@@ -3667,8 +3667,8 @@ static void _dns_client_remove_all_pending_servers(void)
 	list_for_each_entry_safe(pending, tmp, &remove_list, retry_list)
 	{
 		list_del_init(&pending->retry_list);
-		_dns_client_server_pending_release(pending);
 		_dns_client_server_pending_remove(pending);
+		_dns_client_server_pending_release(pending);
 	}
 }
 
@@ -3676,14 +3676,14 @@ static void _dns_client_add_pending_servers(void)
 {
 	struct dns_server_pending *pending = NULL;
 	struct dns_server_pending *tmp = NULL;
-	static int dely = 0;
+	static int delay = 0;
 	LIST_HEAD(retry_list);
 
 	/* add pending server after 3 seconds */
-	if (++dely < 3) {
+	if (++delay < 3) {
 		return;
 	}
-	dely = 0;
+	delay = 0;
 
 	pthread_mutex_lock(&pending_server_mutex);
 	if (list_empty(&pending_servers)) {
@@ -4011,7 +4011,7 @@ void dns_client_exit(void)
 		client.tid = 0;
 	}
 
-	/* free all resouces */
+	/* free all resources */
 	_dns_client_remove_all_pending_servers();
 	_dns_client_server_remove_all();
 	_dns_client_query_remove_all();

+ 1 - 1
src/dns_client.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 16 - 15
src/dns_conf.c

@@ -144,7 +144,7 @@ int dns_conf_ipset_timeout_enable;
 int dns_conf_nftset_timeout_enable;
 int dns_conf_nftset_debug_enable;
 
-char dns_conf_user[DNS_CONF_USRNAME_LEN];
+char dns_conf_user[DNS_CONF_USERNAME_LEN];
 
 int dns_save_fail_packet;
 char dns_save_fail_packet_dir[DNS_MAX_PATH];
@@ -216,7 +216,7 @@ static void _dns_rule_put(struct dns_rule *rule)
 	}
 }
 
-static int _get_domain(char *value, char *domain, int max_dmain_size, char **ptr_after_domain)
+static int _get_domain(char *value, char *domain, int max_domain_size, char **ptr_after_domain)
 {
 	char *begin = NULL;
 	char *end = NULL;
@@ -246,7 +246,7 @@ static int _get_domain(char *value, char *domain, int max_dmain_size, char **ptr
 
 	/* Get domain */
 	len = end - begin;
-	if (len >= max_dmain_size) {
+	if (len >= max_domain_size) {
 		tlog(TLOG_ERROR, "domain name %s too long", value);
 		goto errout;
 	}
@@ -469,7 +469,7 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
 		{"tls-host-verify", required_argument, NULL, 'V' }, /* verify tls hostname */
 		{"group", required_argument, NULL, 'g'}, /* add to group */
 		{"proxy", required_argument, NULL, 'P'}, /* proxy server */
-		{"exclude-default-group", no_argument, NULL, 'E'}, /* ecluse this from default group */
+		{"exclude-default-group", no_argument, NULL, 'E'}, /* exclude this from default group */
 		{"set-mark", required_argument, NULL, 254}, /* set mark */
 		{NULL, no_argument, NULL, 0}
 	};
@@ -703,12 +703,12 @@ static int _config_domain_set_rule_add_ext(const char *set_name, enum domain_rul
 			goto errout;
 		}
 		memset(set_rule_list, 0, sizeof(struct dns_domain_set_rule_list));
-		INIT_LIST_HEAD(&set_rule_list->domain_ruls_list);
+		INIT_LIST_HEAD(&set_rule_list->domain_rule_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);
+	list_add_tail(&set_rule->list, &set_rule_list->domain_rule_list);
 	return 0;
 errout:
 	if (set_rule) {
@@ -717,7 +717,7 @@ errout:
 	return -1;
 }
 
-static int _config_domian_set_rule_flags(const char *set_name, unsigned int flags, int is_clear_flag)
+static int _config_domain_set_rule_flags(const 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);
 }
@@ -790,7 +790,7 @@ errout:
 		free(add_domain_rule);
 	}
 
-	tlog(TLOG_ERROR, "add doamin %s rule failed", domain);
+	tlog(TLOG_ERROR, "add domain %s rule failed", domain);
 	return -1;
 }
 
@@ -805,7 +805,7 @@ static int _config_domain_rule_flag_set(const char *domain, unsigned int flag, u
 	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);
+		return _config_domain_set_rule_flags(domain + sizeof("domain-set:") - 1, flag, is_clear);
 	}
 
 	len = strlen(domain);
@@ -858,7 +858,7 @@ errout:
 		free(add_domain_rule);
 	}
 
-	tlog(TLOG_ERROR, "add doamin %s rule failed", domain);
+	tlog(TLOG_ERROR, "add domain %s rule failed", domain);
 	return 0;
 }
 
@@ -959,6 +959,7 @@ static int _conf_domain_rule_ipset(char *domain, const char *ipsetname)
 			goto errout;
 		}
 		_dns_rule_put(&ipset_rule->head);
+		ipset_rule = NULL;
 	}
 
 	goto clear;
@@ -1853,7 +1854,7 @@ static void _config_domain_set_rule_table_destroy(void)
 	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_for_each_entry_safe(set_rule, tmp1, &set_rule_list->domain_rule_list, list)
 		{
 			list_del(&set_rule->list);
 			if (set_rule->rule) {
@@ -2678,7 +2679,7 @@ static struct config_item _config_item[] = {
 	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_CUSTOM("conf-file", config_additional_file, NULL),
 	CONF_END(),
 };
 
@@ -2699,7 +2700,7 @@ static int _conf_printf(const char *file, int lineno, int ret)
 	return 0;
 }
 
-int config_addtional_file(void *data, int argc, char *argv[])
+int config_additional_file(void *data, int argc, char *argv[])
 {
 	char *conf_file = NULL;
 	char file_path[DNS_MAX_PATH];
@@ -2763,7 +2764,7 @@ static int _update_domain_set_from_list(const char *file, struct dns_domain_set_
 			continue;
 		}
 
-		list_for_each_entry(set_rule, &set_rule_list->domain_ruls_list, list)
+		list_for_each_entry(set_rule, &set_rule_list->domain_rule_list, list)
 		{
 			if (set_rule->type == DOMAIN_RULE_FLAGS) {
 				ret = _config_domain_rule_flag_set(domain, set_rule->flags, set_rule->is_clear_flag);
@@ -2900,7 +2901,7 @@ static int _dns_ping_cap_check(void)
 	has_ping = has_unprivileged_ping();
 	if (has_ping == 0) {
 		if (errno == EACCES && has_raw_cap == 0) {
-			tlog(TLOG_WARN, "unpriviledged ping is disabled, please enable by setting net.ipv4.ping_group_range");
+			tlog(TLOG_WARN, "unprivileged ping is disabled, please enable by setting net.ipv4.ping_group_range");
 		}
 	}
 

+ 4 - 5
src/dns_conf.h

@@ -49,7 +49,7 @@ extern "C" {
 #define DNS_NAX_GROUP_NUMBER 16
 #define DNS_MAX_IPLEN 64
 #define DNS_PROXY_MAX_LEN 128
-#define DNS_CONF_USRNAME_LEN 32
+#define DNS_CONF_USERNAME_LEN 32
 #define DNS_MAX_SPKI_LEN 64
 #define DNS_MAX_URL_LEN 256
 #define DNS_MAX_PATH 1024
@@ -120,7 +120,6 @@ typedef enum {
 struct dns_rule {
 	atomic_t refcnt;
 	enum domain_rule rule;
-	char rule_data[];
 };
 
 struct dns_rule_flags {
@@ -332,7 +331,7 @@ struct dns_domain_set_rule {
 struct dns_domain_set_rule_list {
 	struct hlist_node node;
 	char domain_set[DNS_MAX_CNAME_LEN];
-	struct list_head domain_ruls_list;
+	struct list_head domain_rule_list;
 };
 
 struct dns_domain_set_rule_table {
@@ -430,7 +429,7 @@ extern int dns_conf_local_ttl;
 
 extern int dns_conf_force_no_cname;
 
-extern char dns_conf_user[DNS_CONF_USRNAME_LEN];
+extern char dns_conf_user[DNS_CONF_USERNAME_LEN];
 
 extern struct dns_edns_client_subnet dns_conf_ipv4_ecs;
 extern struct dns_edns_client_subnet dns_conf_ipv6_ecs;
@@ -449,7 +448,7 @@ int dns_server_check_update_hosts(void);
 
 struct dns_proxy_names *dns_server_get_proxy_nams(const char *proxyname);
 
-extern int config_addtional_file(void *data, int argc, char *argv[]);
+extern int config_additional_file(void *data, int argc, char *argv[]);
 #ifdef __cpluscplus
 }
 #endif

+ 34 - 34
src/dns_server.c

@@ -60,7 +60,7 @@
 #define SOCKET_IP_TOS (IPTOS_LOWDELAY | IPTOS_RELIABILITY)
 #define SOCKET_PRIORITY (6)
 #define CACHE_AUTO_ENABLE_SIZE (1024 * 1024 * 128)
-#define EXPIRED_DOMAIN_PREFTCH_TIME (3600 * 8)
+#define EXPIRED_DOMAIN_PREFETCH_TIME (3600 * 8)
 #define DNS_MAX_DOMAIN_REFETCH_NUM 16
 
 #define RECV_ERROR_AGAIN 1
@@ -279,10 +279,10 @@ 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);
 static void _dns_server_request_release_complete(struct dns_request *request, int do_complete);
-static int _dns_server_reply_passthrouth(struct dns_server_post_context *context);
+static int _dns_server_reply_passthrough(struct dns_server_post_context *context);
 static int _dns_server_do_query(struct dns_request *request, int skip_notify_event);
 
-static void _dns_server_wakup_thread(void)
+static void _dns_server_wakeup_thread(void)
 {
 	uint64_t u = 1;
 	int unused __attribute__((unused));
@@ -342,7 +342,7 @@ static void *_dns_server_get_dns_rule(struct dns_request *request, enum domain_r
 	return request->domain_rule.rules[rule];
 }
 
-static int _dns_server_is_dns_rule_extact_match(struct dns_request *request, enum domain_rule rule)
+static int _dns_server_is_dns_rule_extract_match(struct dns_request *request, enum domain_rule rule)
 {
 	if (rule >= DOMAIN_RULE_MAX || request == NULL) {
 		return 0;
@@ -604,7 +604,7 @@ static void _dns_server_audit_log(struct dns_server_post_context *context)
 		}
 	}
 
-	gethost_by_addr(req_host, sizeof(req_host), &request->addr);
+	get_host_by_addr(req_host, sizeof(req_host), &request->addr);
 	tlog_localtime(&tm);
 
 	if (req_host[0] == '\0') {
@@ -1595,7 +1595,7 @@ static int _dns_request_post(struct dns_server_post_context *context)
 
 	ret = _dns_reply_inpacket(request, context->inpacket, context->inpacket_len);
 	if (ret != 0) {
-		tlog(TLOG_WARN, "replay raw packet to client failed.");
+		tlog(TLOG_WARN, "reply raw packet to client failed.");
 		return -1;
 	}
 
@@ -1660,7 +1660,7 @@ static int _dns_server_reply_all_pending_list(struct dns_request *request, struc
 		context_pending.do_force_soa = context->do_force_soa;
 		context_pending.do_ipset = 0;
 		context_pending.reply_ttl = request->ip_ttl;
-		_dns_server_reply_passthrouth(&context_pending);
+		_dns_server_reply_passthrough(&context_pending);
 
 		req->request_pending_list = NULL;
 		list_del_init(&req->pending_list);
@@ -1707,7 +1707,7 @@ static int _dns_server_force_dualstack(struct dns_request *request)
 	}
 
 	/* if ipv4 is fasting than ipv6, add ipv4 to cache, and return SOA for AAAA request */
-	tlog(TLOG_INFO, "result: %s, qtype: %d, force %s perfered, id: %d, time1: %d, time2: %d", request->domain,
+	tlog(TLOG_INFO, "result: %s, qtype: %d, force %s preferred, id: %d, time1: %d, time2: %d", request->domain,
 		 request->qtype, request->qtype == DNS_T_AAAA ? "IPv4" : "IPv6", request->id, request->ping_time,
 		 request->dualstack_selection_ping_time);
 	request->dualstack_selection_force_soa = 1;
@@ -1718,7 +1718,7 @@ static int _dns_server_force_dualstack(struct dns_request *request)
 static int _dns_server_request_complete_with_all_IPs(struct dns_request *request, int with_all_ips)
 {
 	int ttl = 0;
-	int reply_ttl = ttl;
+	int reply_ttl = 0;
 
 	if (request->rcode == DNS_RC_SERVFAIL || request->rcode == DNS_RC_NXDOMAIN) {
 		ttl = DNS_SERVER_FAIL_TTL;
@@ -1838,7 +1838,7 @@ static int _dns_ip_address_check_add(struct dns_request *request, char *cname, u
 	addr_map = malloc(sizeof(*addr_map));
 	if (addr_map == NULL) {
 		pthread_mutex_unlock(&request->ip_map_lock);
-		tlog(TLOG_ERROR, "malloc addrmap failed");
+		tlog(TLOG_ERROR, "malloc addr map failed");
 		return -1;
 	}
 	memset(addr_map, 0, sizeof(*addr_map));
@@ -2389,7 +2389,7 @@ static int _dns_server_ip_rule_check(struct dns_request *request, unsigned char
 		goto rule_not_found;
 	}
 
-	/* bogux-nxdomain */
+	/* bogus-nxdomain */
 	rule = node->data;
 	if (rule->bogus) {
 		goto match;
@@ -2507,7 +2507,7 @@ static int _dns_server_process_answer_A(struct dns_rrs *rrs, struct dns_request
 		}
 	}
 
-	/* add this ip to reqeust */
+	/* add this ip to request */
 	if (_dns_ip_address_check_add(request, cname, addr, DNS_T_A) != 0) {
 		_dns_server_request_release(request);
 		return -1;
@@ -2584,7 +2584,7 @@ static int _dns_server_process_answer_AAAA(struct dns_rrs *rrs, struct dns_reque
 		}
 	}
 
-	/* add this ip to reqeust */
+	/* add this ip to request */
 	if (_dns_ip_address_check_add(request, cname, addr, DNS_T_AAAA) != 0) {
 		_dns_server_request_release(request);
 		return -1;
@@ -2871,7 +2871,7 @@ static int _dns_server_get_answer(struct dns_server_post_context *context)
 				}
 
 				memcpy(request->ip_addr, addr, DNS_RR_A_LEN);
-				/* add this ip to reqeust */
+				/* add this ip to request */
 				request->ip_ttl = _dns_server_get_conf_ttl(ttl);
 				request->has_ip = 1;
 				request->rcode = packet->head.rcode;
@@ -2951,7 +2951,7 @@ static int _dns_server_get_answer(struct dns_server_post_context *context)
 	return 0;
 }
 
-static int _dns_server_reply_passthrouth(struct dns_server_post_context *context)
+static int _dns_server_reply_passthrough(struct dns_server_post_context *context)
 {
 	struct dns_request *request = context->request;
 
@@ -3106,7 +3106,7 @@ static int dns_server_resolve_callback(const char *domain, dns_result_type rtype
 			context.do_reply = 1;
 			context.do_ipset = 1;
 			context.reply_ttl = ttl;
-			return _dns_server_reply_passthrouth(&context);
+			return _dns_server_reply_passthrough(&context);
 		}
 
 		if (request->prefetch == 0 && dns_conf_response_mode == DNS_RESPONSE_MODE_FASTEST_RESPONSE &&
@@ -3123,7 +3123,7 @@ static int dns_server_resolve_callback(const char *domain, dns_result_type rtype
 				context.reply_ttl = 2;
 				context.cache_ttl = 2;
 				context.no_check_add_ip = 1;
-				_dns_server_reply_passthrouth(&context);
+				_dns_server_reply_passthrough(&context);
 				request->cname[0] = 0;
 				request->has_ip = 0;
 				request->has_cname = 0;
@@ -3622,7 +3622,7 @@ static int _dns_server_pre_process_rule_flags(struct dns_request *request)
 	switch (request->qtype) {
 	case DNS_T_A:
 		if (flags & DOMAIN_FLAG_ADDR_IPV4_IGN) {
-			/* ignore this domain for A reqeust */
+			/* ignore this domain for A request */
 			goto out;
 		}
 
@@ -3633,7 +3633,7 @@ static int _dns_server_pre_process_rule_flags(struct dns_request *request)
 		break;
 	case DNS_T_AAAA:
 		if (flags & DOMAIN_FLAG_ADDR_IPV6_IGN) {
-			/* ignore this domain for A reqeust */
+			/* ignore this domain for A request */
 			goto out;
 		}
 
@@ -3840,7 +3840,7 @@ static int _dns_server_process_cache_packet(struct dns_request *request, struct
 	context.do_reply = 1;
 	context.reply_ttl = _dns_server_get_expired_ttl_reply(dns_cache);
 
-	return _dns_server_reply_passthrouth(&context);
+	return _dns_server_reply_passthrough(&context);
 }
 
 static int _dns_server_process_cache_data(struct dns_request *request, struct dns_cache *dns_cache)
@@ -3926,7 +3926,7 @@ static int _dns_server_process_cache(struct dns_request *request)
 			if ((dualstack_dns_cache->info.speed + (dns_conf_dualstack_ip_selection_threshold * 10)) <
 					dns_cache->info.speed ||
 				dns_cache->info.speed < 0) {
-				tlog(TLOG_DEBUG, "cache result: %s, qtype: %d, force %s perfered, id: %d, time1: %d, time2: %d",
+				tlog(TLOG_DEBUG, "cache result: %s, qtype: %d, force %s preferred, id: %d, time1: %d, time2: %d",
 					 request->domain, request->qtype, request->qtype == DNS_T_AAAA ? "IPv4" : "IPv6", request->id,
 					 dns_cache->info.speed, dualstack_dns_cache->info.speed);
 				ret = _dns_server_reply_SOA(DNS_RC_NOERROR, request);
@@ -4095,7 +4095,7 @@ static int _dns_server_process_smartdns_domain(struct dns_request *request)
 		return -1;
 	}
 
-	if (_dns_server_is_dns_rule_extact_match(request, DOMAIN_RULE_FLAGS) == 0) {
+	if (_dns_server_is_dns_rule_extract_match(request, DOMAIN_RULE_FLAGS) == 0) {
 		return -1;
 	}
 
@@ -4133,7 +4133,7 @@ static int _dns_server_process_special_query(struct dns_request *request)
 
 		break;
 	default:
-		tlog(TLOG_DEBUG, "unsupport qtype: %d, domain: %s", request->qtype, request->domain);
+		tlog(TLOG_DEBUG, "unsupported qtype: %d, domain: %s", request->qtype, request->domain);
 		request->passthrough = 1;
 		/* pass request to upstream server */
 		break;
@@ -4390,7 +4390,7 @@ static int _dns_server_do_query(struct dns_request *request, int skip_notify_eve
 
 	pthread_mutex_lock(&server.request_list_lock);
 	if (list_empty(&server.request_list) && skip_notify_event == 1) {
-		_dns_server_wakup_thread();
+		_dns_server_wakeup_thread();
 	}
 	list_add_tail(&request->list, &server.request_list);
 	pthread_mutex_unlock(&server.request_list_lock);
@@ -4501,7 +4501,7 @@ static int _dns_server_recv(struct dns_server_conn_head *conn, unsigned char *in
 
 	/* decode packet */
 	tlog(TLOG_DEBUG, "recv query packet from %s, len = %d, type = %d",
-		 gethost_by_addr(name, sizeof(name), (struct sockaddr *)from), inpacket_len, conn->type);
+		 get_host_by_addr(name, sizeof(name), (struct sockaddr *)from), inpacket_len, conn->type);
 	decode_len = dns_decode(packet, DNS_PACKSIZE, inpacket, inpacket_len);
 	if (decode_len < 0) {
 		tlog(TLOG_DEBUG, "decode failed.\n");
@@ -4535,7 +4535,7 @@ static int _dns_server_recv(struct dns_server_conn_head *conn, unsigned char *in
 		goto errout;
 	}
 
-	tlog(TLOG_INFO, "query server %s from %s, qtype = %d\n", request->domain, name, request->qtype);
+	tlog(TLOG_INFO, "query server %s from %s, qtype: %d\n", request->domain, name, request->qtype);
 
 	ret = _dns_server_do_query(request, 1);
 	if (ret != 0) {
@@ -4737,7 +4737,7 @@ static int _dns_server_tcp_accept(struct dns_server_conn_tcp_server *tcpserver,
 		return -1;
 	}
 
-	if (getsocknet_inet(tcpclient->head.fd, (struct sockaddr *)&tcpclient->localaddr, &tcpclient->localaddr_len) != 0) {
+	if (getsocket_inet(tcpclient->head.fd, (struct sockaddr *)&tcpclient->localaddr, &tcpclient->localaddr_len) != 0) {
 		tlog(TLOG_ERROR, "get local addr failed, %s", strerror(errno));
 		goto errout;
 	}
@@ -4952,13 +4952,13 @@ static int _dns_server_process(struct dns_server_conn_head *conn, struct epoll_e
 		if (ret != 0) {
 			char name[DNS_MAX_CNAME_LEN];
 			tlog(TLOG_DEBUG, "process TCP packet from %s failed.",
-				 gethost_by_addr(name, sizeof(name), (struct sockaddr *)&tcpclient->addr));
+				 get_host_by_addr(name, sizeof(name), (struct sockaddr *)&tcpclient->addr));
 		}
 	} else if (conn->type == DNS_CONN_TYPE_TLS_SERVER) {
-		tlog(TLOG_ERROR, "unsupport dns server type %d", conn->type);
+		tlog(TLOG_ERROR, "unsupported dns server type %d", conn->type);
 		ret = -1;
 	} else {
-		tlog(TLOG_ERROR, "unsupport dns server type %d", conn->type);
+		tlog(TLOG_ERROR, "unsupported dns server type %d", conn->type);
 		ret = -1;
 	}
 	_dns_server_conn_release(conn);
@@ -5104,8 +5104,8 @@ static void _dns_server_period_run_second(void)
 
 				if (prefetch_time == 0) {
 					prefetch_time = dns_conf_serve_expired_ttl / 2;
-					if (prefetch_time == 0 || prefetch_time > EXPIRED_DOMAIN_PREFTCH_TIME) {
-						prefetch_time = EXPIRED_DOMAIN_PREFTCH_TIME;
+					if (prefetch_time == 0 || prefetch_time > EXPIRED_DOMAIN_PREFETCH_TIME) {
+						prefetch_time = EXPIRED_DOMAIN_PREFETCH_TIME;
 					}
 				}
 				dns_cache_invalidate(NULL, 0, DNS_MAX_DOMAIN_REFETCH_NUM, _dns_server_prefetch_expired_domain,
@@ -5395,7 +5395,7 @@ static int _dns_create_socket(const char *host_ip, int type)
 		safe_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 		ioctl(fd, SIOCGIFINDEX, &ifr);
 		if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(struct ifreq)) < 0) {
-			tlog(TLOG_ERROR, "bind socket to device %s faild, %s\n", ifr.ifr_name, strerror(errno));
+			tlog(TLOG_ERROR, "bind socket to device %s failed, %s\n", ifr.ifr_name, strerror(errno));
 			goto errout;
 		}
 	}
@@ -5717,7 +5717,7 @@ errout:
 void dns_server_stop(void)
 {
 	atomic_set(&server.run, 0);
-	_dns_server_wakup_thread();
+	_dns_server_wakeup_thread();
 }
 
 void dns_server_exit(void)

+ 1 - 1
src/dns_server.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 14 - 14
src/fast_ping.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -63,8 +63,8 @@ struct ping_dns_head {
 	unsigned short flag;
 	unsigned short qdcount;
 	unsigned short ancount;
-	unsigned short aucount;
-	unsigned short adcount;
+	unsigned short nscount;
+	unsigned short nrcount;
 	char qd_name;
 	unsigned short q_qtype;
 	unsigned short q_qclass;
@@ -171,7 +171,7 @@ static int bool_print_log = 1;
 
 static void _fast_ping_host_put(struct ping_host_struct *ping_host);
 
-static void _fast_ping_wakup_thread(void)
+static void _fast_ping_wakeup_thread(void)
 {
 	uint64_t u = 1;
 	int unused __attribute__((unused));
@@ -534,7 +534,7 @@ static int _fast_ping_sendping_v6(struct ping_host_struct *ping_host)
 
 		char ping_host_name[PING_MAX_HOSTLEN];
 		tlog(TLOG_ERROR, "sendto %s, id %d, %s",
-			 gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
+			 get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
 			 ping_host->sid, strerror(err));
 		goto errout;
 	}
@@ -574,7 +574,7 @@ static int _fast_ping_sendping_v4(struct ping_host_struct *ping_host)
 		}
 		char ping_host_name[PING_MAX_HOSTLEN];
 		tlog(TLOG_ERROR, "sendto %s, id %d, %s",
-			 gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
+			 get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
 			 ping_host->sid, strerror(err));
 		goto errout;
 	}
@@ -626,7 +626,7 @@ static int _fast_ping_sendping_udp(struct ping_host_struct *ping_host)
 		}
 		char ping_host_name[PING_MAX_HOSTLEN];
 		tlog(TLOG_ERROR, "sendto %s, id %d, %s",
-			 gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
+			 get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
 			 ping_host->sid, strerror(err));
 		goto errout;
 	}
@@ -680,7 +680,7 @@ static int _fast_ping_sendping_tcp(struct ping_host_struct *ping_host)
 			}
 
 			tlog(TLOG_ERROR, "connect %s, id %d, %s",
-				 gethost_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
+				 get_host_by_addr(ping_host_name, sizeof(ping_host_name), (struct sockaddr *)&ping_host->addr),
 				 ping_host->sid, strerror(errno));
 			goto errout;
 		}
@@ -1205,7 +1205,7 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
 	pthread_mutex_lock(&ping.map_lock);
 	_fast_ping_host_get(ping_host);
 	if (hash_empty(ping.addrmap)) {
-		_fast_ping_wakup_thread();
+		_fast_ping_wakeup_thread();
 	}
 	hash_add(ping.addrmap, &ping_host->addr_node, addrkey);
 	ping_host->run = 1;
@@ -1326,7 +1326,7 @@ static struct fast_ping_packet *_fast_ping_icmp_packet(struct ping_host_struct *
 
 	if (ping.no_unprivileged_ping) {
 		if (ip->ip_p != IPPROTO_ICMP) {
-			tlog(TLOG_ERROR, "ip type faild, %d:%d", ip->ip_p, IPPROTO_ICMP);
+			tlog(TLOG_ERROR, "ip type failed, %d:%d", ip->ip_p, IPPROTO_ICMP);
 			return NULL;
 		}
 
@@ -1407,7 +1407,7 @@ static int _fast_ping_process_icmp(struct ping_host_struct *ping_host, struct ti
 		}
 
 		tlog(TLOG_DEBUG, "recv ping packet from %s failed.",
-			 gethost_by_addr(name, sizeof(name), (struct sockaddr *)&from));
+			 get_host_by_addr(name, sizeof(name), (struct sockaddr *)&from));
 		goto errout;
 	}
 
@@ -1899,7 +1899,7 @@ int fast_ping_init(void)
 
 	ret = pthread_create(&ping.notify_tid, &attr, _fast_ping_notify_worker, NULL);
 	if (ret != 0) {
-		tlog(TLOG_ERROR, "create ping notifyer work thread failed, %s\n", strerror(ret));
+		tlog(TLOG_ERROR, "create ping notifier work thread failed, %s\n", strerror(ret));
 		goto errout;
 	}
 
@@ -1923,7 +1923,7 @@ errout:
 	if (ping.tid) {
 		void *retval = NULL;
 		atomic_set(&ping.run, 0);
-		_fast_ping_wakup_thread();
+		_fast_ping_wakeup_thread();
 		pthread_join(ping.tid, &retval);
 		ping.tid = 0;
 	}
@@ -1982,7 +1982,7 @@ void fast_ping_exit(void)
 	if (ping.tid) {
 		void *ret = NULL;
 		atomic_set(&ping.run, 0);
-		_fast_ping_wakup_thread();
+		_fast_ping_wakeup_thread();
 		pthread_join(ping.tid, &ret);
 		ping.tid = 0;
 	}

+ 1 - 1
src/fast_ping.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/http_parse.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/http_parse.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/atomic.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/bitmap.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/bitops.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/conf.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/findbit.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/gcc_builtin.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/hash.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/hashtable.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/jhash.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/list.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/rbtree.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/include/stringutil.h

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/lib/art.c

@@ -1090,7 +1090,7 @@ void art_substring_walk(const art_tree *t, const unsigned char *str, int str_len
             // Check if the expanded path matches
             if (!str_prefix_matches((art_leaf*)n, str, str_len)) {
                 found = (art_leaf*)n;
-				stop_search = func(found->key, found->key_len, found->key_len != (uint32_t)str_len, found->value, arg);
+				func(found->key, found->key_len, found->key_len != (uint32_t)str_len, found->value, arg);
 			}
             break;
         }

+ 2 - 2
src/lib/bitops.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
  * find_next_and_bit. The differences are:
  *  - The "invert" argument, which is XORed with each fetched word before
  *    searching it for one bits.
- *  - The optional "addr2", which is anded with "addr1" if present.
+ *  - The optional "addr2", which is addr2 with "addr1" if present.
  */
 static inline unsigned long _find_next_bit(const unsigned long *addr1,
 		const unsigned long *addr2, unsigned long nbits,

+ 1 - 1
src/lib/conf.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 4 - 8
src/lib/nftset.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2022 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -89,7 +89,9 @@ static int _nftset_addattr(struct nlmsghdr *n, int maxlen, __u16 type, const voi
 
 	void *rta_data = RTA_DATA(attr);
 
-	memcpy(rta_data, data, alen);
+	if ((data != NULL) && (alen > 0)) {
+		memcpy(rta_data, data, alen);
+	}
 	memset((uint8_t *)rta_data + alen, 0, RTA_ALIGN(len) - len);
 
 	n->nlmsg_len = newlen;
@@ -202,7 +204,6 @@ static int _nftset_socket_request(void *msg, int msg_len, void *ret_msg, int ret
 	int ret = -1;
 	struct pollfd pfds;
 	int do_recv = 0;
-	int last_errno = 0;
 	int len = 0;
 
 	if (_nftset_socket_init() != 0) {
@@ -260,10 +261,6 @@ static int _nftset_socket_request(void *msg, int msg_len, void *ret_msg, int ret
 				break;
 			}
 
-			if (errno == EAGAIN && last_errno != 0) {
-				errno = last_errno;
-			}
-
 			return -1;
 		}
 
@@ -275,7 +272,6 @@ static int _nftset_socket_request(void *msg, int msg_len, void *ret_msg, int ret
 			struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nlh);
 			if (err->error != 0) {
 				errno = -err->error;
-				last_errno = errno;
 				return -1;
 			}
 

+ 3 - 1
src/lib/radix.c

@@ -436,8 +436,10 @@ radix_node_t
 
 		node->parent = new_node;
 	} else {
-		if ((glue = malloc(sizeof(*glue))) == NULL)
+		if ((glue = malloc(sizeof(*glue))) == NULL) {
+			free(new_node);
 			return (NULL);
+		}
 		memset(glue, '\0', sizeof(*glue));
 		glue->bit = differ_bit;
 		glue->prefix = NULL;

+ 1 - 1
src/lib/rbtree.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 1 - 1
src/lib/stringutil.c

@@ -1,6 +1,6 @@
 /*************************************************************************
  *
- * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
+ * Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  *
  * smartdns is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by

+ 21 - 21
src/proxy.c

@@ -149,7 +149,7 @@ static struct addrinfo *_proxy_getaddr(const char *host, int port, int type, int
 	ret = getaddrinfo(host, port_str, &hints, &result);
 	if (ret != 0) {
 		tlog(TLOG_ERROR, "get addr info failed. %s\n", gai_strerror(ret));
-		tlog(TLOG_ERROR, "host = %s, port = %d, type = %d, protocol = %d", host, port, type, protocol);
+		tlog(TLOG_ERROR, "host: %s, port: %d, type: %d, protocol: %d", host, port, type, protocol);
 		goto errout;
 	}
 
@@ -391,7 +391,7 @@ static proxy_handshake_state _proxy_handshake_socks5_reply_connect_addr(struct p
 	int len = 0;
 	memset(buff, 0, sizeof(buff));
 	struct sockaddr_storage addr;
-	char *ptr = buff;
+	char *ptr = NULL;
 	socklen_t addr_len = sizeof(addr);
 
 	buff[0] = PROXY_SOCKS5_VERSION;
@@ -477,7 +477,7 @@ static proxy_handshake_state _proxy_handshake_socks5_send_auth(struct proxy_conn
 	offset += buff[offset] + 1;
 	len = send(proxy_conn->fd, buff, offset, MSG_NOSIGNAL);
 	if (len != offset) {
-		tlog(TLOG_ERROR, "send auth failed, len = %d, errno = %s", len, strerror(errno));
+		tlog(TLOG_ERROR, "send auth failed, len: %d, %s", len, strerror(errno));
 		return PROXY_HANDSHAKE_ERR;
 	}
 
@@ -499,7 +499,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 		buff[3] = PROXY_SOCKS5_AUTH_USER_PASS;
 		len = send(proxy_conn->fd, buff, 4, MSG_NOSIGNAL);
 		if (len != 4) {
-			tlog(TLOG_ERROR, "init socks5 failed, errno = %s", strerror(errno));
+			tlog(TLOG_ERROR, "init socks5 failed, %s", strerror(errno));
 			return PROXY_HANDSHAKE_ERR;
 		}
 
@@ -514,7 +514,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 				return PROXY_HANDSHAKE_WANT_READ;
 			}
 
-			tlog(TLOG_ERROR, "recv socks5 init ack failed, errno = %s", strerror(errno));
+			tlog(TLOG_ERROR, "recv socks5 init ack failed, %s", strerror(errno));
 			return PROXY_HANDSHAKE_ERR;
 		}
 
@@ -524,23 +524,23 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 		}
 
 		if (proxy_conn->buffer.len > 2) {
-			tlog(TLOG_ERROR, "recv socks5 init ack failed, len = %d", len);
+			tlog(TLOG_ERROR, "recv socks5 init ack failed");
 			return PROXY_HANDSHAKE_ERR;
 		}
 
 		proxy_conn->buffer.len = 0;
 
 		if (proxy_conn->buffer.buffer[0] != PROXY_SOCKS5_VERSION) {
-			tlog(TLOG_ERROR, "Server not support socks5");
+			tlog(TLOG_ERROR, "server not support socks5");
 			return PROXY_HANDSHAKE_ERR;
 		}
 
 		if ((unsigned char)proxy_conn->buffer.buffer[1] == PROXY_SOCKS5_AUTH_NONE) {
-			tlog(TLOG_ERROR, "Server not support auth methods");
+			tlog(TLOG_ERROR, "server not support auth methods");
 			return PROXY_HANDSHAKE_ERR;
 		}
 
-		tlog(TLOG_INFO, "Server select auth method is %d", proxy_conn->buffer.buffer[1]);
+		tlog(TLOG_INFO, "server select auth method is %d", proxy_conn->buffer.buffer[1]);
 		if (proxy_conn->buffer.buffer[1] == PROXY_SOCKS5_AUTH_USER_PASS) {
 			return _proxy_handshake_socks5_send_auth(proxy_conn);
 		}
@@ -549,7 +549,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 			return _proxy_handshake_socks5_reply_connect_addr(proxy_conn);
 		}
 
-		tlog(TLOG_ERROR, "Server select invalid auth method %d", proxy_conn->buffer.buffer[1]);
+		tlog(TLOG_ERROR, "server select invalid auth method %d", proxy_conn->buffer.buffer[1]);
 		return PROXY_HANDSHAKE_ERR;
 		break;
 	case PROXY_CONN_AUTH_ACK:
@@ -560,7 +560,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 				return PROXY_HANDSHAKE_WANT_READ;
 			}
 
-			tlog(TLOG_ERROR, "recv socks5 auth ack failed, errno = %s", strerror(errno));
+			tlog(TLOG_ERROR, "recv socks5 auth ack failed, %s", strerror(errno));
 			return PROXY_HANDSHAKE_ERR;
 		}
 
@@ -570,23 +570,23 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 		}
 
 		if (proxy_conn->buffer.len != 2) {
-			tlog(TLOG_ERROR, "recv socks5 auth ack failed, len = %d", len);
+			tlog(TLOG_ERROR, "recv socks5 auth ack failed");
 			return PROXY_HANDSHAKE_ERR;
 		}
 
 		proxy_conn->buffer.len = 0;
 
 		if (proxy_conn->buffer.buffer[0] != 0x1) {
-			tlog(TLOG_ERROR, "Server not support socks5");
+			tlog(TLOG_ERROR, "server not support socks5");
 			return PROXY_HANDSHAKE_ERR;
 		}
 
 		if (proxy_conn->buffer.buffer[1] != 0x0) {
-			tlog(TLOG_ERROR, "Server auth failed, code = %d", proxy_conn->buffer.buffer[1]);
+			tlog(TLOG_ERROR, "server auth failed, incorrect user or password, code: %d", proxy_conn->buffer.buffer[1]);
 			return PROXY_HANDSHAKE_ERR;
 		}
 
-		tlog(TLOG_INFO, "Server auth success");
+		tlog(TLOG_INFO, "server auth success");
 		proxy_conn->state = PROXY_CONN_CONNECTING;
 		return _proxy_handshake_socks5_reply_connect_addr(proxy_conn);
 	case PROXY_CONN_CONNECTING: {
@@ -603,7 +603,7 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 				return PROXY_HANDSHAKE_WANT_READ;
 			}
 
-			tlog(TLOG_ERROR, "recv socks5 connect ack failed, errno = %s", strerror(errno));
+			tlog(TLOG_ERROR, "recv socks5 connect ack failed, %s", strerror(errno));
 			return PROXY_HANDSHAKE_ERR;
 		}
 
@@ -614,16 +614,16 @@ static proxy_handshake_state _proxy_handshake_socks5(struct proxy_conn *proxy_co
 		recv_buff = proxy_conn->buffer.buffer;
 
 		if (recv_buff[0] != PROXY_SOCKS5_VERSION) {
-			tlog(TLOG_ERROR, "Server not support socks5");
+			tlog(TLOG_ERROR, "server not support socks5");
 			return PROXY_HANDSHAKE_ERR;
 		}
 
 		if (recv_buff[1] != 0) {
 			if ((unsigned char)recv_buff[1] <=
 				(sizeof(proxy_socks5_status_code) / sizeof(proxy_socks5_status_code[0]))) {
-				tlog(TLOG_ERROR, "Server replay failed, error code %s", proxy_socks5_status_code[(int)recv_buff[1]]);
+				tlog(TLOG_ERROR, "server reply failed, error-code: %s", proxy_socks5_status_code[(int)recv_buff[1]]);
 			} else {
-				tlog(TLOG_ERROR, "Server replay failed, error code %x", recv_buff[1]);
+				tlog(TLOG_ERROR, "server reply failed, error-code: %x", recv_buff[1]);
 			}
 			return PROXY_HANDSHAKE_ERR;
 		}
@@ -766,7 +766,7 @@ static int _proxy_handshake_http(struct proxy_conn *proxy_conn)
 
 		len = send(proxy_conn->fd, buff, msglen, MSG_NOSIGNAL);
 		if (len != msglen) {
-			tlog(TLOG_ERROR, "init https failed, len = %d, errno = %s", len, strerror(errno));
+			tlog(TLOG_ERROR, "init https failed, len: %d, %s", len, strerror(errno));
 			goto out;
 		}
 
@@ -786,7 +786,7 @@ static int _proxy_handshake_http(struct proxy_conn *proxy_conn)
 			if (len == 0) {
 				tlog(TLOG_ERROR, "remote server closed.");
 			} else {
-				tlog(TLOG_ERROR, "recv failed, errno = %s", strerror(errno));
+				tlog(TLOG_ERROR, "recv failed, %s", strerror(errno));
 			}
 			goto out;
 		}

+ 1 - 1
src/smartdns.c

@@ -148,7 +148,7 @@ static void _help(void)
 		"  -p [pid]      pid file path, '-' means don't create pid file.\n"
 		"  -S            ignore segment fault signal.\n"
 		"  -x            verbose screen.\n"
-		"  -v            dispaly version.\n"
+		"  -v            display version.\n"
 		"  -h            show this help message.\n"
 
 		"Online help: http://pymumu.github.io/smartdns\n"

+ 7 - 7
src/tlog.c

@@ -1,6 +1,6 @@
 /*
  * tinylog
- * Copyright (C) 2018-2020 Nick Peng <[email protected]>
+ * Copyright (C) 2018-2023 Nick Peng <[email protected]>
  * https://github.com/pymumu/tinylog
  */
 #ifndef _GNU_SOURCE
@@ -442,7 +442,7 @@ static int _tlog_root_log_buffer(char *buff, int maxlen, void *userptr, const ch
         log_len++;
     }
 
-    if (tlog.root->segment_log) {
+    if (tlog.root->segment_log && log_head != NULL) {
         if (len + 1 < maxlen - 1) {
             *(buff + len) = '\0';
             len++;
@@ -920,14 +920,14 @@ static void _tlog_wait_pid(struct tlog_log *log, int wait_hang)
     log->zip_pid = -1;
     char gzip_file[PATH_MAX * 2];
 
-    /* rename ziped file */
+    /* rename zipped file */
     snprintf(gzip_file, sizeof(gzip_file), "%s/%s.pending.gz", log->logdir, log->logname);
     if (_tlog_rename_logfile(log, gzip_file) != 0) {
         _tlog_log_unlock(log);
         return;
     }
 
-    /* remove oldes file */
+    /* remove oldest file */
     _tlog_remove_oldlog(log);
     _tlog_log_unlock(log);
 }
@@ -1090,7 +1090,7 @@ static int _tlog_archive_log_nocompress(struct tlog_log *log)
         goto errout;
     }
 
-    /* remove oldes file */
+    /* remove oldest file */
     _tlog_remove_oldlog(log);
     _tlog_log_unlock(log);
 
@@ -1437,7 +1437,7 @@ static void _tlog_work_write(struct tlog_log *log, int log_len, int log_extlen,
     if (log_dropped > 0) {
         /* if there is dropped log, record dropped log number */
         char dropmsg[TLOG_TMP_LEN];
-        snprintf(dropmsg, sizeof(dropmsg), "[Totoal Dropped %d Messages]\n", log_dropped);
+        snprintf(dropmsg, sizeof(dropmsg), "[Total Dropped %d Messages]\n", log_dropped);
         log->output_func(log, dropmsg, strnlen(dropmsg, sizeof(dropmsg)));
     }
 }
@@ -1845,7 +1845,7 @@ int tlog_init(const char *logfile, int maxlogsize, int maxlogcount, int buffsize
     struct tlog_log *log = NULL;
 
     if (tlog_format != NULL) {
-        fprintf(stderr, "tlog already initilized.\n");
+        fprintf(stderr, "tlog already initialized.\n");
         return -1;
     }
 

+ 5 - 5
src/tlog.h

@@ -52,7 +52,7 @@ struct tlog_time {
 
 /*
  multiwrite: enable multi process write mode.
-            NOTICE: maxlogsize in all prcesses must be same when enable this mode.
+            NOTICE: maxlogsize in all processes must be same when enable this mode.
  */
 #define TLOG_MULTI_WRITE (1 << 2)
 
@@ -62,7 +62,7 @@ struct tlog_time {
 /* enable log to screen */
 #define TLOG_SCREEN (1 << 4)
 
-/* enable suppport fork process */
+/* enable support fork process */
 #define TLOG_SUPPORT_FORK (1 << 5)
 
 struct tlog_loginfo {
@@ -101,10 +101,10 @@ extern tlog_level tlog_getlevel(void);
 /* set log file */
 extern void tlog_set_logfile(const char *logfile);
 
-/* enalbe log to screen */
+/* enable log to screen */
 extern void tlog_setlogscreen(int enable);
 
-/* enalbe early log to screen */
+/* enable early log to screen */
 extern void tlog_set_early_printf(int enable);
 
 /* Get log level in string */
@@ -184,7 +184,7 @@ va_list: args list
 */
 extern int tlog_vprintf(tlog_log *log, const char *format, va_list ap);
 
-/* enalbe log to screen */
+/* enable log to screen */
 extern void tlog_logscreen(tlog_log *log, int enable);
 
 /* register output callback */

+ 19 - 19
src/util.c

@@ -109,7 +109,7 @@ unsigned long get_tick_count(void)
 	return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
 }
 
-char *gethost_by_addr(char *host, int maxsize, struct sockaddr *addr)
+char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr)
 {
 	struct sockaddr_storage *addr_store = (struct sockaddr_storage *)addr;
 	host[0] = 0;
@@ -173,7 +173,7 @@ errout:
 	return -1;
 }
 
-int getsocknet_inet(int fd, struct sockaddr *addr, socklen_t *addr_len)
+int getsocket_inet(int fd, struct sockaddr *addr, socklen_t *addr_len)
 {
 	struct sockaddr_storage addr_store;
 	socklen_t addr_store_len = sizeof(addr_store);
@@ -602,7 +602,7 @@ static int _ipset_support_timeout(void)
 	return -1;
 }
 
-static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int addr_len, unsigned long timeout,
+static int _ipset_operate(const char *ipset_name, const unsigned char addr[], int addr_len, unsigned long timeout,
 						  int operate)
 {
 	struct nlmsghdr *netlink_head = NULL;
@@ -633,7 +633,7 @@ static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int
 		return -1;
 	}
 
-	if (strlen(ipsetname) >= IPSET_MAXNAMELEN) {
+	if (strlen(ipset_name) >= IPSET_MAXNAMELEN) {
 		errno = ENAMETOOLONG;
 		return -1;
 	}
@@ -653,7 +653,7 @@ static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int
 
 	proto = IPSET_PROTOCOL;
 	_ipset_add_attr(netlink_head, IPSET_ATTR_PROTOCOL, sizeof(proto), &proto);
-	_ipset_add_attr(netlink_head, IPSET_ATTR_SETNAME, strlen(ipsetname) + 1, ipsetname);
+	_ipset_add_attr(netlink_head, IPSET_ATTR_SETNAME, strlen(ipset_name) + 1, ipset_name);
 
 	nested[0] = (struct ipset_netlink_attr *)(buffer + NETLINK_ALIGN(netlink_head->nlmsg_len));
 	netlink_head->nlmsg_len += NETLINK_ALIGN(sizeof(struct ipset_netlink_attr));
@@ -692,14 +692,14 @@ static int _ipset_operate(const char *ipsetname, const unsigned char addr[], int
 	return rc;
 }
 
-int ipset_add(const char *ipsetname, const unsigned char addr[], int addr_len, unsigned long timeout)
+int ipset_add(const char *ipset_name, const unsigned char addr[], int addr_len, unsigned long timeout)
 {
-	return _ipset_operate(ipsetname, addr, addr_len, timeout, IPSET_ADD);
+	return _ipset_operate(ipset_name, addr, addr_len, timeout, IPSET_ADD);
 }
 
-int ipset_del(const char *ipsetname, const unsigned char addr[], int addr_len)
+int ipset_del(const char *ipset_name, const unsigned char addr[], int addr_len)
 {
-	return _ipset_operate(ipsetname, addr, addr_len, 0, IPSET_DEL);
+	return _ipset_operate(ipset_name, addr, addr_len, 0, IPSET_DEL);
 }
 
 unsigned char *SSL_SHA256(const unsigned char *d, size_t n, unsigned char *md)
@@ -894,7 +894,7 @@ static int parse_extensions(const char *, size_t, char *, const char **);
 static int parse_server_name_extension(const char *, size_t, char *, const char **);
 
 /* Parse a TLS packet for the Server Name Indication extension in the client
- * hello handshake, returning the first servername found (pointer to static
+ * hello handshake, returning the first server name found (pointer to static
  * array)
  *
  * Returns:
@@ -1023,7 +1023,7 @@ static int parse_extensions(const char *data, size_t data_len, char *hostname, c
 		/* Check if it's a server name extension */
 		if (data[pos] == 0x00 && data[pos + 1] == 0x00) {
 			/* There can be only one extension of each type, so we break
-			 * our state and move p to beinnging of the extension here */
+			 * our state and move p to beginning of the extension here */
 			if (pos + 4 + len > data_len) {
 				return -5;
 			}
@@ -1276,27 +1276,27 @@ int dns_packet_save(const char *dir, const char *type, const char *from, const v
 
 	struct tm *ptm;
 	struct tm tm;
-	struct timeval tmval;
+	struct timeval tm_val;
 	struct stat sb;
 
 	if (stat(dir, &sb) != 0) {
 		mkdir(dir, 0750);
 	}
 
-	if (gettimeofday(&tmval, NULL) != 0) {
+	if (gettimeofday(&tm_val, NULL) != 0) {
 		return -1;
 	}
 
-	ptm = localtime_r(&tmval.tv_sec, &tm);
+	ptm = localtime_r(&tm_val.tv_sec, &tm);
 	if (ptm == NULL) {
 		return -1;
 	}
 
-	ret = snprintf(time_s, sizeof(time_s) - 1, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d.%.3d", ptm->tm_year + 1900,
-				   ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)(tmval.tv_usec / 1000));
-	ret = snprintf(filename, sizeof(filename) - 1, "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%.1d.packet", dir, type,
-				   ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
-				   (int)(tmval.tv_usec / 100000));
+	snprintf(time_s, sizeof(time_s) - 1, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d.%.3d", ptm->tm_year + 1900, ptm->tm_mon + 1,
+			 ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)(tm_val.tv_usec / 1000));
+	snprintf(filename, sizeof(filename) - 1, "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%.1d.packet", dir, type,
+			 ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
+			 (int)(tm_val.tv_usec / 100000));
 
 	data = malloc(PACKET_BUF_SIZE);
 	if (data == NULL) {

+ 5 - 5
src/util.h

@@ -55,11 +55,11 @@ void bug_ext(const char *file, int line, const char *func, const char *errfmt, .
 
 unsigned long get_tick_count(void);
 
-char *gethost_by_addr(char *host, int maxsize, struct sockaddr *addr);
+char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr);
 
 int getaddr_by_host(const char *host, struct sockaddr *addr, socklen_t *addr_len);
 
-int getsocknet_inet(int fd, struct sockaddr *addr, socklen_t *addr_len);
+int getsocket_inet(int fd, struct sockaddr *addr, socklen_t *addr_len);
 
 int fill_sockaddr_by_ip(unsigned char *ip, int ip_len, int port, struct sockaddr *addr, socklen_t *addr_len);
 
@@ -81,9 +81,9 @@ char *to_lower_case(char *output, const char *input, int len);
 
 void print_stack(void);
 
-int ipset_add(const char *ipsetname, const unsigned char addr[], int addr_len, unsigned long timeout);
+int ipset_add(const char *ipset_name, const unsigned char addr[], int addr_len, unsigned long timeout);
 
-int ipset_del(const char *ipsetname, const unsigned char addr[], int addr_len);
+int ipset_del(const char *ipset_name, const unsigned char addr[], int addr_len);
 
 void SSL_CRYPTO_thread_setup(void);
 
@@ -98,7 +98,7 @@ int SSL_base64_encode(const void *in, int in_len, char *out);
 int create_pid_file(const char *pid_file);
 
 /* Parse a TLS packet for the Server Name Indication extension in the client
- * hello handshake, returning the first servername found (pointer to static
+ * hello handshake, returning the first server name found (pointer to static
  * array)
  *
  * Returns: