Fix potential race bug

This commit is contained in:
Nick Peng
2018-08-10 18:29:17 +08:00
parent 56a273e3ed
commit 8bdb6362b4
4 changed files with 51 additions and 39 deletions

View File

@@ -115,6 +115,7 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|标准Linux系统(x86_64)| smartdns.xxxxxxxx.x86_64..tar.gz|支持x86_64系统。
|华硕原生固件(optware)|smartdns.xxxxxxx.mipsbig.ipk|支持MIPS大端架构的系统如RT-AC55U, RT-AC66U.
|华硕原生固件(optware)|smartdns.xxxxxxx.mipsel.ipk|支持MIPS小端架构的系统如RT-AC68U。
|华硕原生固件(optware)|smartdns.xxxxxxx.arm.ipk|支持arm小端架构的系统如RT-AC88U。
|openwrt 15.01|smartdns.xxxxxxxx.ar71xx.ipk|支持AR71XX MIPS系统。
|openwrt 15.01|smartdns.xxxxxxxx.ramips_24kec.ipk|支持MT762X等小端路由器
|openwrt 15.01(潘多拉)|smartdns.xxxxxxxx.mipsel_24kec_dsp.ipk|支持MT7620系列的潘多拉固件
@@ -125,9 +126,10 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|openwrt LEDE|smartdns.xxxxxxxxx.arm_cortex-a7_neon-vfpv4.ipk|支持arm A7核心CPU的路由器
|openwrt LUCI|luci-app-smartdns.xxxxxxxxx.xxxx.all.ipk|openwrt管理统一界面
openwrt系统CPU架构比较多上述表格未列出所有支持系统请查看CPU架构后下载。
CPU架构可在路由器管理界面找到查看方法
* 登录路由器,点击`System`->`Software`,点击`Configuration` Tab页面在opkg安装源中可找到对应软件架构下载路径中可找到如下架构为ar71xx
* openwrt系统CPU架构比较多上述表格未列出所有支持系统请查看CPU架构后下载。
* merlin梅林固件理论和华硕固件一直所以根据硬件类型安装相应的ipk包即可。梅林暂时未验证有问题提交issue
* CPU架构可在路由器管理界面找到查看方法
登录路由器,点击`System`->`Software`,点击`Configuration` Tab页面在opkg安装源中可找到对应软件架构下载路径中可找到如下架构为ar71xx
```
src/gz chaos_calmer_base http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/base
@@ -217,8 +219,14 @@ Non-authoritative answer:
* SmartDNS默认情况将53端口的请求转发到SmartDNS的本地端口`Redirect`配置选项控制。
6. 界面提示重定向失败:
* 检查iptableip6table命令是否正确安装。
* openwrt 15.01系统不支持IPV6重定向如网络需要支持IPV6请将DNSMASQ上游改为smartdns或者将smartdns的端口改为53并停用dnsmasq。
* LEDE之后系统请安装IPV6的nat转发驱动。点击`system`->`Software`,点击`update lists`更新软件列表后,安装`ip6tables-mod-nat`
* 使用如下命令检查路由规则是否生效。
```
iptables -t nat -L PREROUTING | grep REDIRECT
```
华硕路由器原生固件
--------------
@@ -300,7 +308,7 @@ vi /opt/etc/smartdns/smartdns.conf
|log-file|日志文件路径|/var/log/smartdns.log|路径|log-file /var/log/smartdns.log
|log-size|日志大小|128K|数字+K,M,G|log-size 128K
|log-num|日志归档个数|2|数字|log-num 2
|conf-file|附加日志文件|无|文件路径|conf-file /etc/smartdns/smartdns.more.conf
|conf-file|附加配置文件|无|文件路径|conf-file /etc/smartdns/smartdns.more.conf
|server|上游UDP DNS|114.114.114.114|[ip][:port],可重复| server 8.8.8.8:53
|server-tcp|上游TCP DNS|无|[IP][:port],可重复| server-tcp 8.8.8.8:53
|address|指定域名IP地址|无|address /domain/ip| address /www.example.com/1.2.3.4
@@ -329,12 +337,3 @@ vi /opt/etc/smartdns/smartdns.conf
说明
==============
目前代码未开源,后续根据情况开源。

View File

@@ -1,6 +1,6 @@
SmartDNS
==============
![SmartDNS](doc/smartdns-banner.png)
SmartDNS是一个运行在本地的DNS服务器SmartDNS接受本地客户端的DNS查询请求从多个上游DNS服务器获取DNS查询结果并将访问速度最快的结果返回个客户端避免DNS污染提高网络访问速度。
同时支持指定特定域名IP地址并高性匹配达到过滤广告的效果。
与dnsmasq的all-servers不同smartdns返回的是访问速度最快的解析结果。
@@ -115,6 +115,7 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|标准Linux系统(x86_64)| smartdns.xxxxxxxx.x86_64..tar.gz|支持x86_64系统。
|华硕原生固件(optware)|smartdns.xxxxxxx.mipsbig.ipk|支持MIPS大端架构的系统如RT-AC55U, RT-AC66U.
|华硕原生固件(optware)|smartdns.xxxxxxx.mipsel.ipk|支持MIPS小端架构的系统如RT-AC68U。
|华硕原生固件(optware)|smartdns.xxxxxxx.arm.ipk|支持arm小端架构的系统如RT-AC88U。
|openwrt 15.01|smartdns.xxxxxxxx.ar71xx.ipk|支持AR71XX MIPS系统。
|openwrt 15.01|smartdns.xxxxxxxx.ramips_24kec.ipk|支持MT762X等小端路由器
|openwrt 15.01(潘多拉)|smartdns.xxxxxxxx.mipsel_24kec_dsp.ipk|支持MT7620系列的潘多拉固件
@@ -125,9 +126,10 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|openwrt LEDE|smartdns.xxxxxxxxx.arm_cortex-a7_neon-vfpv4.ipk|支持arm A7核心CPU的路由器
|openwrt LUCI|luci-app-smartdns.xxxxxxxxx.xxxx.all.ipk|openwrt管理统一界面
openwrt系统CPU架构比较多上述表格未列出所有支持系统请查看CPU架构后下载。
CPU架构可在路由器管理界面找到查看方法
* 登录路由器,点击`System`->`Software`,点击`Configuration` Tab页面在opkg安装源中可找到对应软件架构下载路径中可找到如下架构为ar71xx
* openwrt系统CPU架构比较多上述表格未列出所有支持系统请查看CPU架构后下载。
* merlin梅林固件理论和华硕固件一直所以根据硬件类型安装相应的ipk包即可。梅林暂时未验证有问题提交issue
* CPU架构可在路由器管理界面找到查看方法
登录路由器,点击`System`->`Software`,点击`Configuration` Tab页面在opkg安装源中可找到对应软件架构下载路径中可找到如下架构为ar71xx
```
src/gz chaos_calmer_base http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/base
@@ -216,6 +218,15 @@ Non-authoritative answer:
* 如已经安装chinaDNS建议将chinaDNS的上游配置为SmartDNS。
* SmartDNS默认情况将53端口的请求转发到SmartDNS的本地端口`Redirect`配置选项控制。
6. 界面提示重定向失败:
* 检查iptableip6table命令是否正确安装。
* openwrt 15.01系统不支持IPV6重定向如网络需要支持IPV6请将DNSMASQ上游改为smartdns或者将smartdns的端口改为53并停用dnsmasq。
* LEDE之后系统请安装IPV6的nat转发驱动。点击`system`->`Software`,点击`update lists`更新软件列表后,安装`ip6tables-mod-nat`
* 使用如下命令检查路由规则是否生效。
```
iptables -t nat -L PREROUTING | grep REDIRECT
```
华硕路由器原生固件
--------------
@@ -297,6 +308,7 @@ vi /opt/etc/smartdns/smartdns.conf
|log-file|日志文件路径|/var/log/smartdns.log|路径|log-file /var/log/smartdns.log
|log-size|日志大小|128K|数字+K,M,G|log-size 128K
|log-num|日志归档个数|2|数字|log-num 2
|conf-file|附加配置文件|无|文件路径|conf-file /etc/smartdns/smartdns.more.conf
|server|上游UDP DNS|114.114.114.114|[ip][:port],可重复| server 8.8.8.8:53
|server-tcp|上游TCP DNS|无|[IP][:port],可重复| server-tcp 8.8.8.8:53
|address|指定域名IP地址|无|address /domain/ip| address /www.example.com/1.2.3.4
@@ -325,12 +337,3 @@ vi /opt/etc/smartdns/smartdns.conf
说明
==============
目前代码未开源,后续根据情况开源。

View File

@@ -306,6 +306,11 @@ int config_rr_ttl_max(char *value)
return 0;
}
int conf_bogus_nxdomain(char *value)
{
return 0;
}
int config_addtional_file(char *value)
{
char *file_path = value;
@@ -339,6 +344,7 @@ struct config_item config_item[] = {
{"rr-ttl", config_rr_ttl},
{"rr-ttl-min", config_rr_ttl_min},
{"rr-ttl-max", config_rr_ttl_max},
{"bogus-nxdomain", conf_bogus_nxdomain},
{"conf-file", config_addtional_file},
};
int config_item_num = sizeof(config_item) / sizeof(struct config_item);

View File

@@ -246,6 +246,16 @@ errout:
return -1;
}
static void _dns_client_close_socket(struct dns_server_info *server_info)
{
if (server_info->fd <= 0) {
return;
}
epoll_ctl(client.epoll_fd, EPOLL_CTL_DEL, server_info->fd, NULL);
close(server_info->fd);
server_info->fd = -1;
}
/* remove all servers information */
void _dns_client_server_remove_all(void)
{
@@ -260,9 +270,8 @@ void _dns_client_server_remove_all(void)
tlog(TLOG_ERROR, "stop ping failed.\n");
}
}
if (server_info->fd > 0) {
close(server_info->fd);
}
_dns_client_close_socket(server_info);
free(server_info);
}
pthread_mutex_unlock(&client.server_list_lock);
@@ -459,10 +468,9 @@ void _dns_client_period_run(void)
list_for_each_entry(server_info, &client.dns_server_list, list)
{
if (server_info->last_send - 5 > server_info->last_recv) {
if (server_info->fd > 0) {
close(server_info->fd);
server_info->fd = -1;
}
server_info->recv_buff.len = 0;
server_info->send_buff.len = 0;
_dns_client_close_socket(server_info);
}
}
pthread_mutex_unlock(&client.server_list_lock);
@@ -776,8 +784,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
/* peer server close */
if (len == 0) {
pthread_mutex_lock(&client.server_list_lock);
close(server_info->fd);
server_info->fd = 0;
_dns_client_close_socket(server_info);
server_info->recv_buff.len = 0;
if (server_info->send_buff.len > 0) {
/* still remain request data, reconnect and send*/
@@ -838,10 +845,7 @@ errout:
pthread_mutex_lock(&client.server_list_lock);
server_info->recv_buff.len = 0;
server_info->send_buff.len = 0;
if (server_info->fd > 0) {
close(server_info->fd);
server_info->fd = -1;
}
_dns_client_close_socket(server_info);
pthread_mutex_unlock(&client.server_list_lock);
return -1;