Compare commits

..

11 Commits

Author SHA1 Message Date
Nick Peng
f50e4dd081 Revert "http: Fix http overflow bug"
This reverts commit ea8c1f47f8.
2021-08-27 19:22:20 +08:00
Nick Peng
ca6a9613d9 http: Fix http not working issue 2021-08-25 16:59:10 +08:00
Jian Chang
c88b334902 improve #754 (#756)
* improve #754
2021-08-25 16:55:16 +08:00
Jian Chang
017cd5cdc1 fix #689 2021-08-24 21:53:11 +08:00
Nick Peng
0e89d05ee7 Create c-cpp.yml 2021-08-24 16:44:44 +08:00
Nick Peng
772229c826 fast_ping: Avoid ping race condition crash issue 2021-08-23 14:19:22 +08:00
Nick Peng
7f1dc8a311 utils: Add print_stack function for debugging 2021-08-22 16:01:37 +08:00
Nick Peng
eff1f1b4c7 Updat readme 2021-08-21 20:42:25 +08:00
Nick Peng
ea8c1f47f8 http: Fix http overflow bug 2021-08-21 20:38:32 +08:00
Nick Peng
106ec6789c Make: update script mode 2021-08-21 20:38:32 +08:00
Nyaasu
8c271e34c1 Translate: Add units to reduce misunderstandings (#746)
* Translate: Add units to reduce misunderstandings
2021-08-09 22:21:35 +08:00
21 changed files with 139 additions and 30 deletions

17
.github/workflows/c-cpp.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: C/C++ CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: make
run: make

View File

@@ -2,7 +2,7 @@
**[English](ReadMe_en.md)**
![SmartDNS](https://github.com/pymumu/test/releases/download/blob/smartdns-banner.png)
![SmartDNS](doc/smartdns-banner.png)
SmartDNS是一个运行在本地的DNS服务器SmartDNS接受本地客户端的DNS查询请求从多个上游DNS服务器获取DNS查询结果并将访问速度最快的结果返回给客户端提高网络访问速度。
同时支持指定特定域名IP地址并高性匹配达到过滤广告的效果。
与dnsmasq的all-servers不同smartdns返回的是访问速度最快的解析结果。 (详细差异请看[FAQ](#faq))
@@ -11,19 +11,26 @@ SmartDNS是一个运行在本地的DNS服务器SmartDNS接受本地客户端
## 目录
1. [软件效果展示](#软件效果展示)
1. [特性](#特性)
1. [架构](#架构)
1. [使用](#使用)
1. [下载配套安装包](#下载配套安装包)
1. [标准Linux系统安装](#标准linux系统安装树莓派x86_64系统)
1. [openwrt/LEDE](#openwrt)
1. [华硕路由器原生固件/梅林固件](#华硕路由器原生固件梅林固件)
1. [optware/entware](#optwareentware)
1. [Windows 10 WSL安装/WSL ubuntu](#windows-10-wsl安装wsl-ubuntu)
1. [配置参数](#配置参数)
1. [捐助](#donate)
1. [FAQ](#faq)
- [SmartDNS](#smartdns)
- [目录](#目录)
- [软件效果展示](#软件效果展示)
- [特性](#特性)
- [架构](#架构)
- [使用](#使用)
- [下载配套安装包](#下载配套安装包)
- [标准Linux系统安装/树莓派/X86_64系统](#标准linux系统安装树莓派x86_64系统)
- [openwrt](#openwrt)
- [华硕路由器原生固件/梅林固件](#华硕路由器原生固件梅林固件)
- [optware/entware](#optwareentware)
- [Windows 10 WSL安装/WSL ubuntu](#windows-10-wsl安装wsl-ubuntu)
- [配置参数](#配置参数)
- [FAQ](#faq)
- [编译](#编译)
- [Donate](#donate)
- [PayPal](#paypal)
- [Alipay 支付宝](#alipay-支付宝)
- [Wechat 微信](#wechat-微信)
- [开源声明](#开源声明)
## 软件效果展示
@@ -664,11 +671,11 @@ smartdns包含了编译软件包的脚本支持编译lucidebianopenwrt
### Alipay 支付宝
![alipay](https://github.com/pymumu/test/releases/download/blob/alipay_donate.jpg)
![alipay](doc/alipay_donate.jpg)
### Wechat 微信
![wechat](https://github.com/pymumu/test/releases/download/blob/wechat_donate.jpg)
![wechat](doc/wechat_donate.jpg)
## 开源声明

0
package/build-pkg.sh Normal file → Executable file
View File

0
package/debian/make.sh Normal file → Executable file
View File

0
package/linux/make.sh Normal file → Executable file
View File

View File

@@ -104,13 +104,13 @@ msgid "Cache Size"
msgstr "缓存大小"
msgid "DNS domain result cache size"
msgstr "缓存DNS的结果缓存大小配置零则不缓存"
msgstr "缓存DNS的结果缓存大小配置零则不缓存(单位:条)"
msgid "Domain TTL"
msgstr "域名TTL"
msgid "TTL for all domain result."
msgstr "设置所有域名的TTL值"
msgstr "设置所有域名的TTL值(单位:秒,下同)"
msgid "Domain TTL Min"
msgstr "域名TTL最小值"

0
package/luci-compat/make.sh Normal file → Executable file
View File

View File

@@ -110,13 +110,13 @@ msgid "Cache Size"
msgstr "缓存大小"
msgid "DNS domain result cache size"
msgstr "缓存DNS的结果缓存大小配置零则不缓存"
msgstr "缓存DNS的结果缓存大小配置零则不缓存(单位:条)"
msgid "Domain TTL"
msgstr "域名TTL"
msgid "TTL for all domain result."
msgstr "设置所有域名的TTL值"
msgstr "设置所有域名的TTL值(单位:秒,下同)"
msgid "Domain TTL Min"
msgstr "域名TTL最小值"

0
package/luci/make.sh Normal file → Executable file
View File

0
package/openwrt/make.sh Normal file → Executable file
View File

0
package/optware/make.sh Normal file → Executable file
View File

5
src/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.vscode
.o
.DS_Store
.swp.
smartdns

View File

@@ -20,7 +20,7 @@ OBJS=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_co
# cflags
ifndef CFLAGS
CFLAGS =-O2 -g -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing
CFLAGS =-O2 -g -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables
endif
override CFLAGS +=-Iinclude
override CFLAGS += -DBASE_FILE_NAME=\"$(notdir $<)\"
@@ -35,7 +35,7 @@ override CXXFLAGS +=-Iinclude
ifeq ($(STATIC), yes)
override LDFLAGS += -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl -static
else
override LDFLAGS += -lssl -lcrypto -lpthread
override LDFLAGS += -lssl -lcrypto -lpthread -ldl
endif
.PHONY: all clean

View File

@@ -418,7 +418,7 @@ int dns_cache_is_soa(struct dns_cache *dns_cache) {
}
struct dns_cache_addr *cache_addr = (struct dns_cache_addr *)dns_cache_get_data(dns_cache);
if (cache_addr->addr_data.soa) {
if (cache_addr->head.cache_type == CACHE_TYPE_ADDR && cache_addr->addr_data.soa) {
return 1;
}
return 0;

View File

@@ -62,8 +62,8 @@ struct dns_cache_addr {
struct dns_cache_data_head head;
struct dns_cache_addr_data {
unsigned int cname_ttl;
char cname[DNS_MAX_CNAME_LEN];
char soa;
char cname[DNS_MAX_CNAME_LEN];
union {
unsigned char ipv4_addr[DNS_RR_A_LEN];
unsigned char ipv6_addr[DNS_RR_AAAA_LEN];

View File

@@ -1774,10 +1774,10 @@ static int _DNS_client_create_socket_tls(struct dns_server_info *server_info, ch
}
// ? this cause ssl crash ?
// setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
// setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof(yes));
// setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof(yes));
// set_sock_keepalive(fd, 15, 3, 4);
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof(yes));
setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof(yes));
set_sock_keepalive(fd, 15, 3, 4);
setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
setsockopt(fd, IPPROTO_IP, IP_TOS, &ip_tos, sizeof(ip_tos));

View File

@@ -365,7 +365,12 @@ static void _fast_ping_close_host_sock(struct ping_host_struct *ping_host)
static void _fast_ping_host_put(struct ping_host_struct *ping_host)
{
if (!atomic_dec_and_test(&ping_host->ref)) {
int ref_cnt = atomic_dec_and_test(&ping_host->ref);
if (!ref_cnt) {
if (ref_cnt < 0) {
tlog(TLOG_ERROR, "invalid refcount of ping_host %s", ping_host->host);
abort();
}
return;
}
@@ -1081,15 +1086,19 @@ struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int c
pthread_mutex_unlock(&ping.map_lock);
_fast_ping_host_get(ping_host);
_fast_ping_host_get(ping_host);
// for ping race condition, get reference count twice
if (_fast_ping_sendping(ping_host) != 0) {
goto errout_remove;
}
ping_host->run = 1;
freeaddrinfo(gai);
_fast_ping_host_put(ping_host);
return ping_host;
errout_remove:
fast_ping_stop(ping_host);
_fast_ping_host_put(ping_host);
ping_host = NULL;
errout:
if (gai) {

View File

@@ -363,7 +363,7 @@ static void _sig_error_exit(int signo, siginfo_t *siginfo, void *ct)
"%s %s)\n",
signo, siginfo->si_code, siginfo->si_errno, siginfo->si_pid, getpid(), PC, (unsigned long)siginfo->si_addr,
__DATE__, __TIME__, arch);
print_stack();
sleep(1);
_exit(0);
}

View File

@@ -21,7 +21,9 @@
#endif
#include "util.h"
#include "dns_conf.h"
#include "tlog.h"
#include <arpa/inet.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -39,6 +41,7 @@
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <unwind.h>
#define TMP_BUFF_LEN_32 32
@@ -1009,3 +1012,50 @@ uint64_t get_free_space(const char *path)
return size;
}
struct backtrace_state {
void **current;
void **end;
};
static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context *context, void *arg)
{
struct backtrace_state *state = (struct backtrace_state *)(arg);
uintptr_t pc = _Unwind_GetIP(context);
if (pc) {
if (state->current == state->end) {
return _URC_END_OF_STACK;
} else {
*state->current++ = (void *)(pc);
}
}
return _URC_NO_REASON;
}
void print_stack(void)
{
const size_t max_buffer = 30;
void *buffer[max_buffer];
struct backtrace_state state = {buffer, buffer + max_buffer};
_Unwind_Backtrace(unwind_callback, &state);
int frame_num = state.current - buffer;
if (frame_num == 0) {
return;
}
tlog(TLOG_FATAL, "Stack:");
for (int idx = 0; idx < frame_num; ++idx) {
const void *addr = buffer[idx];
const char *symbol = "";
Dl_info info;
memset(&info, 0, sizeof(info));
if (dladdr(addr, &info) && info.dli_sname) {
symbol = info.dli_sname;
}
void *offset = (void *)((char *)(addr) - (char *)(info.dli_fbase));
tlog(TLOG_FATAL, "#%.2d: %p %s from %s+%p", idx + 1, addr, symbol, info.dli_fname, offset);
}
}

View File

@@ -108,6 +108,8 @@ int set_sock_lingertime(int fd, int time);
uint64_t get_free_space(const char *path);
void print_stack(void);
#ifdef __cplusplus
}
#endif /*__cplusplus */

19
systemd/smartdns.service Normal file
View File

@@ -0,0 +1,19 @@
[Unit]
Description=SmartDNS Server
After=network.target
StartLimitBurst=0
StartLimitIntervalSec=60
[Service]
Type=forking
PIDFile=/var/run/smartdns.pid
EnvironmentFile=/etc/default/smartdns
ExecStart=/usr/sbin/smartdns -p /var/run/smartdns.pid $SMART_DNS_OPTS
KillMode=process
Restart=always
RestartSec=2
TimeoutStopSec=5
[Install]
WantedBy=multi-user.target
Alias=smartdns.service