From 982002e836e486fb4e360bc10e84e7e7197caf46 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sat, 21 Dec 2019 11:28:37 +0800 Subject: [PATCH] Modify the detection method of smartdns --- ReadMe.md | 36 ++++++++++++++++++------------------ ReadMe_en.md | 34 +++++++++++++++++----------------- src/Makefile | 13 ++++++++++--- src/dns_server.c | 5 +++++ 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 39a60f9..8635875 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -252,16 +252,16 @@ https://github.com/pymumu/smartdns/releases 1. 检测服务是否配置成功。 - 使用`nslookup -querytype=ptr 0.0.0.0`查询域名 + 使用`nslookup -querytype=ptr smartdns`查询域名 看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效 ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` ### openwrt/LEDE @@ -296,16 +296,16 @@ https://github.com/pymumu/smartdns/releases * **检测转发服务是否配置成功** - 使用`nslookup -querytype=ptr 0.0.0.0`查询域名 + 使用`nslookup -querytype=ptr smartdns`查询域名 看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效 ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` * **界面提示重定向失败** @@ -329,16 +329,16 @@ https://github.com/pymumu/smartdns/releases * **检测上游服务是否配置成功** - * 方法一:使用`nslookup -querytype=ptr 0.0.0.0`查询域名 + * 方法一:使用`nslookup -querytype=ptr smartdns`查询域名 看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效 ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` * 方法二:使用`nslookup`查询`www.baidu.com`域名,查看结果中百度的IP地址是否`只有一个`,如有多个IP地址返回,则表示未生效,请多尝试几个域名检查。 @@ -393,16 +393,16 @@ https://github.com/pymumu/smartdns/releases 1. 重启路由器生效服务 - 待路由器启动后,使用`nslookup -querytype=ptr 0.0.0.0`查询域名 + 待路由器启动后,使用`nslookup -querytype=ptr smartdns`查询域名 看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效 ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` 1. 额外说明 @@ -469,16 +469,16 @@ https://github.com/pymumu/smartdns/releases 1. 重启路由器生效服务 - 待路由器启动后,使用`nslookup -querytype=ptr 0.0.0.0`查询域名 + 待路由器启动后,使用`nslookup -querytype=ptr smartdns`查询域名 看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效 ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` 注意:若服务没有自动启动,则需要设置optwre/entware自动启动,具体方法参考optware/entware的文档。 @@ -526,16 +526,16 @@ https://github.com/pymumu/smartdns/releases 1. 检测服务是否配置成功。 - 使用`nslookup -querytype=ptr 0.0.0.0`查询域名 + 使用`nslookup -querytype=ptr smartdns`查询域名 看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效 ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` ## 配置参数 diff --git a/ReadMe_en.md b/ReadMe_en.md index 67ada91..499ef17 100755 --- a/ReadMe_en.md +++ b/ReadMe_en.md @@ -247,16 +247,16 @@ https://github.com/pymumu/smartdns/releases 1. Check if the service is configured successfully - Query domain name with `nslookup -querytype=ptr 0.0.0.0` + Query domain name with `nslookup -querytype=ptr smartdns` Check if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns` ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` ### openwrt/LEDE @@ -291,16 +291,16 @@ https://github.com/pymumu/smartdns/releases * **Check if the service is configured successfully** - Query domain name with `nslookup -querytype=ptr 0.0.0.0` + 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` ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` * **The interface prompts that the redirect failed** @@ -328,12 +328,12 @@ https://github.com/pymumu/smartdns/releases See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns` ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` * Method 2: Use `nslookup` to query the `www.baidu.com` domain name to see if the IP address of Baidu in the result is `only one. If there are multiple IP addresses returned, it means that it is not valid. Please try to check several domain names. @@ -388,16 +388,16 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use 1. Restart router - After the router is started, use `nslookup -querytype=ptr 0.0.0.0` to query the domain name. + After the router is started, use `nslookup -querytype=ptr smartdns` to query the domain name. See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns` ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` 1. Note @@ -464,16 +464,16 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use 1. Restart the router to take effect - After the router is started, use `nslookup -querytype=ptr 0.0.0.0` to query the domain name. + After the router is started, use `nslookup -querytype=ptr smartdns` to query the domain name. See if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns` ```shell - Pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + Pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + 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. @@ -521,16 +521,16 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use 1. Check if the service is configured successfully - Query domain name with `nslookup -querytype=ptr 0.0.0.0` + Query domain name with `nslookup -querytype=ptr smartdns` Check if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns` ```shell - pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0 + pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr smartdns Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: - 0.0.0.0.in-addr.arpa name = smartdns. + smartdns name = smartdns. ``` ## Configuration parameter diff --git a/src/Makefile b/src/Makefile index 4b9b0b9..1a512a8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,18 +17,25 @@ BIN=smartdns OBJS_LIB=lib/rbtree.o lib/art.o lib/bitops.o lib/radix.o lib/conf.o OBJS=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_conf.o dns_cache.o http_parse.o $(OBJS_LIB) -CFLAGS +=-O2 -g -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing + +# cflags +ifndef CFLAGS +CFLAGS =-O2 -g -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing +endif override CFLAGS +=-Iinclude override CFLAGS += -DBASE_FILE_NAME=\"$(notdir $<)\" ifdef VER override CFLAGS += -DSMARTDNS_VERION=\"$(VER)\" endif + CXXFLAGS=-O2 -g -Wall -std=c++11 override CXXFLAGS +=-Iinclude + +# ldflags ifeq ($(STATIC), yes) -LDFLAGS += -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl -static +override LDFLAGS += -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl -static else -LDFLAGS += -lssl -lcrypto -lpthread +override LDFLAGS += -lssl -lcrypto -lpthread endif .PHONY: all diff --git a/src/dns_server.c b/src/dns_server.c index 8dba5cc..cd34896 100644 --- a/src/dns_server.c +++ b/src/dns_server.c @@ -1688,6 +1688,11 @@ static int _dns_server_process_ptr(struct dns_request *request) found = 1; } + /* Determine if the smartdns service is in effect. */ + if (found == 0 && strncmp(request->domain, "smartdns", sizeof("smartdns")) == 0) { + found = 1; + } + if (found == 0) { goto errout; }