Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More options #50

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 38 additions & 9 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# 如何安装
# Installation

## 编译
./src目录下执行 make 即可编译出可执行文件
## Compile

Run make in ./src to produce binary

make

## 配置文件
默认配置文件为当前目录下的 sr.conf,也可以在命令行参数中指定
## Command Line Options

* -c
Config file

* -h
Help

* -f
Forward

* -d
Daemon

./dnspod-sr /path/of/sr.conf
* -v
Print version

## config file

当前配置文件中支持为特定域名指定外部递归 DNS,以 xfer 开头,如下:
The default configuration file is sr.conf,other wise you can pass in the command line parameter

./dnspod-sr -c /path/of/sr.conf

In the current configuration file, you can specify external recursive DNS for a specific domain name starting with xfer as follows:

xfer:
googleusercontent.com.:8.8.8.8
Expand All @@ -19,9 +38,19 @@
s-static.ak.facebook.com.edgekey.net.:8.8.8.8
:

最后一行以`:`结束。
The last line ends with a `:`.

配置日志文件目录(可选)
Configure the log directory(optional)

log_path:
./log/

Configure the listen port:
listen:9054

Configure the root file name
root:root.z

Configure the records file name
records:records.z

74 changes: 40 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,69 @@
# DNSPod Security Recursive DNS Server

dnspod-sr is a run on the Linux platform, high-performance recursive DNS server software, high performance, high-load, easy to expand the advantages of non-BIND and other software can match.

## 关于
dnspod-sr 是一个运行在 Linux 平台上的高性能的递归 DNS 服务器软件,具备高性能、高负载、易扩展的优势,非 BIND 等软件可以比拟。
## characteristic

## 特性
1. 高性能,比所有流行的开源 DNS 软件性能高出2倍以上
2. 安全,能抵御一般攻击
3. 稳定,有效降低解析失败率
4. 主动刷新缓存,响应速度更快
5. 易于扩展,非常容易部署
6. 防污染,能够正确解析被污染域名
1. High-performance, than all the popular open source DNS software performance higher than 2 times
2. Security, generally can withstand attacks
3. Stability, reduce the resolution failure rate
4. Initiative to refresh the cache, and faster response
5. Easy to extend, very easy to deploy
6. Pollution, contamination can correctly parse the domain name

## performance

## 性能
dnspod-sr 依托于 DNSPod 多年运营和优化 DNS 服务的经验,针对国内复杂的网络情况,对递归 DNS 进行了一系列的优化,比较其他开源软件,性能得到大幅提升。
dnspod-sr relying on DNSPod years experience operating, and optimizing DNS services, complex network for the domestic situation, a series of recursive DNS optimization, compared with other open source software, performance is greatly improved.

#### 测试环境
千兆网卡,4核 CPU,4G 内存,Linux 64位系统。
#### test environment

#### 性能测试
- dnspod-sr: 15万 qps
- BIND 9.9: 7万 qps
- unbound 4.7: 8万 qps
Gigabit Ethernet, 4-core CPU, 4G memory, Linux 64-bit systems.

#### Performance Testing

dnspod-sr: 15 Wan qps
BIND 9.9: 7 Wan qps
unbound 4.7: 8 Wan qps

![Benchmark](https://github.com/DNSPod/dnspod-sr/raw/master/benchmark.png)

## 解决方案
1. 架设 dnspod-sr 集群,替换各大运营商目前基于 BIND 的陈旧方案,减少运营成本
2. 公司、学校、政府等组织内部 DNS,解析外部不可见的私有域名,提高上网速度
Benchmark
solution

Setup dnspod-sr cluster, replace implementation based on the current BIND obsolete programs to reduce operating costs
Companies, schools, government and other organizations internal DNS, resolving external invisible private domain, to improve Internet speed

## 快速开始
下载源码:
## Quick Start

Download Source:

git clone https://github.com/DNSPod/dnspod-sr.git
cd dnspod-sr

或者下载压缩包:
## Or download the archive:

https://github.com/DNSPod/dnspod-sr/zipball/master

编译源码:
# Compile the code:

cd src
make

运行
run

./dnspod-sr


## Roadmap
- 支持集群式部署

## 文档 & 反馈
- Wiki: <https://github.com/DNSPod/dnspod-sr/wiki>
- FAQ: <https://github.com/DNSPod/dnspod-sr/wiki/FAQ>
- Issues: <https://github.com/DNSPod/dnspod-sr/issues>
- [提交反馈](https://github.com/DNSPod/dnspod-sr/issues/new)
Support for cluster deployment

## Documentation & Feedback

- Wiki: https://github.com/DNSPod/dnspod-sr/wiki
- FAQ: https://github.com/DNSPod/dnspod-sr/wiki/FAQ
- Issues: https://github.com/DNSPod/dnspod-sr/issues
- Submit feedback https://github.com/DNSPod/dnspod-sr/issues/new

## Open source license

## 开源协议
dnspod-sr 在 BSD License 下发布。
dnspod-sr is licensed under the BSD License.
3 changes: 3 additions & 0 deletions sr.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
listen:9054
root:root.z
records:records.z
xfer:
googleusercontent.com.:8.8.8.8
google.com.:8.8.8.8
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ INSTALL_BIN=$(PREFIX)/bin
INSTALL_ETC=$(PREFIX)/etc
OBJS=utils.o datas.o net.o storage.o dns.o io.o event.o author.o init.o update.o control.o memory.o
LD=-lm -lc
CC = gcc
CC = g++
SERVER_NAME=dnspod-sr


Expand All @@ -16,7 +16,7 @@ CFLAGS=-g -Wall# -O3
# endif

all:$(OBJS)
gcc -o $(SERVER_NAME) $(LD) $(OBJS) -lpthread -g# -O3
g++ -o $(SERVER_NAME) $(LD) $(OBJS) -lpthread -g# -O3
#ltcmalloc

#base 3
Expand Down
10 changes: 5 additions & 5 deletions src/author.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ delete_close_event(int fd, struct fetcher *f)
el = f->el;
if (el == NULL)
return -1;
if ((nd = malloc(sizeof(struct list_node))) == NULL)
if ((nd = (struct list_node*)malloc(sizeof(struct list_node))) == NULL)
return -1;
nd->data = malloc(sizeof(int));
if (nd->data == NULL) {
Expand Down Expand Up @@ -440,7 +440,7 @@ release_qoutinfo(struct author *author, mbuf_type *mbuf, uint32_t idx)
val = htable_delete_list(author->s->qlist, mbuf->lowerdomain.domain, typeoff, id);
if (val == NULL)
{
printf("del list val =0, mbuf:0x%0x\n", mbuf);
printf("del list val =0, mbuf:0x%0lx\n", (long unsigned int)mbuf);
return 0;
}
assert(val == (void *)mbuf);
Expand Down Expand Up @@ -923,19 +923,19 @@ check_ttl_expire(struct author *author)
pthread_spin_lock(&rbt->lock);
pn = min_node(rbt);
while (pn != NULL) {
tn = pn->key;
tn = (ttlnode*)pn->key;
//if exp was 12, now was 11, start
//if exp was 12, now was 5, break
if (tn->exp > (now + TTL_UPDATE)) //3 secs after it will not expire
break;
/* printf("ttl refresh "); */
/* dbg_print_td(tn->data); */
tn = delete_node(rbt, pn);
tn = (ttlnode*)delete_node(rbt, pn);
pthread_spin_unlock(&rbt->lock);
if (tn != NULL) {
memset(mbuf, 0, sizeof(mbuf_type));
mbuf->qname = tn->type; //type
mbuf->qtype = tn->type;
mbuf->qtype = (rrtype)tn->type;
mbuf->dlen = tn->dlen;
memcpy(&(mbuf->lowerdomain), tn->lowerdomain, sizeof(packet_type));
int i;
Expand Down
15 changes: 9 additions & 6 deletions src/author.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@
#ifndef _AUTHOR_H
#define _AUTHOR_H

#define _GNU_SOURCE
//#define _GNU_SOURCE

#include "io.h"
#include <sys/ipc.h>
#include <sys/shm.h>

enum {
FETCHER_NUM = 2,
SERVER_PORT = 53,
DEFAULT_SERVER_PORT = 53,
};
extern int server_port;


enum {
Expand Down Expand Up @@ -168,8 +169,10 @@ struct server {
int is_forward;
};

struct server *global_serv;
char *g_nameservers[2];
extern struct global_query_info *global_out_info;
extern int query_type_map[];
extern char *g_nameservers[];
extern struct server *global_serv;

#define MAX_CPU_NUM 65
struct thread_query_info {
Expand All @@ -183,8 +186,8 @@ struct global_query_info {
struct thread_query_info query_info[MAX_CPU_NUM];
};

struct global_query_info *global_out_info;
int query_type_map[256];



struct seninfo {
uint len;
Expand Down
8 changes: 6 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#define __CONFIG_H__

#define SR_CONFIG_FILE "../sr.conf"
#define SR_ROOT_FILE "../root.z"
#define SR_RECORDS_FILE "../records.z"
#define SR_DEFAULT_ROOT_FILE "../root.z"
#define SR_DEFAULT_RECORDS_FILE "../records.z"


extern char sr_root_file[];
extern char sr_records_file[];

#endif
2 changes: 1 addition & 1 deletion src/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int cache_flush(uchar *domain, uint16_t type, struct htable* ht, struct rbtree *
//if update, we had delete tn in rbt
//else update tn in rbt
if (pn != NULL) {
tmp_tn = delete_node(ttlexp, pn);
tmp_tn = (ttlnode*)delete_node(ttlexp, pn);
if (tmp_tn) {
free(tmp_tn->lowerdomain);
free(tmp_tn);
Expand Down
10 changes: 5 additions & 5 deletions src/datas.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int
insert_node(struct rbtree *rbt, struct rbnode *pnd)
{
struct rbnode *tmp = &rbt->nil, *itor = rbt->root;
struct rbnode *nd = malloc(sizeof(struct rbnode));
struct rbnode *nd = (struct rbnode *)malloc(sizeof(struct rbnode));
if (nd == NULL)
return -1;
*nd = *pnd;
Expand Down Expand Up @@ -285,7 +285,7 @@ delete_node(struct rbtree *rbt, struct rbnode *nd)
struct rbnode *tmp, *itor;
if (nd == NULL || rbt == NULL)
return NULL;
val = nd->key;
val = (ttlnode*)nd->key;
/* printf("delete node ttl: %d ", val->exp); */
/* dbg_print_td(val->data); */
//pthread_mutex_lock(&(rbt->lock));
Expand Down Expand Up @@ -323,7 +323,7 @@ delete_node(struct rbtree *rbt, struct rbnode *nd)
struct rbtree *
create_rbtree(comprbt * c, void *argv)
{
struct rbtree *rbt = malloc(sizeof(struct rbtree));
struct rbtree *rbt = (struct rbtree *)malloc(sizeof(struct rbtree));
if (rbt == NULL)
return NULL;
rbt->argv = argv;
Expand Down Expand Up @@ -374,7 +374,7 @@ rbtree_test(void)
//{
for (j = 0; j < slice; j++) {
len = random() % 30;
tn = malloc(sizeof(struct ttlnode) + len);
tn = (ttlnode*)malloc(sizeof(struct ttlnode) + len);
if (tn == NULL)
printf("oom\n");
tn->exp = j;
Expand All @@ -390,7 +390,7 @@ rbtree_test(void)
for (j = 0; j < slice; j++) {
pn = min_node(rbt);
if (pn != NULL) {
tn = delete_node(rbt, pn);
tn = (ttlnode*)delete_node(rbt, pn);
free(tn);
} else
printf("error\n");
Expand Down
10 changes: 5 additions & 5 deletions src/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ passer_dns_data(mbuf_type *mbuf)
tail += 1;
else
tail += dlen;
mbuf->qtype = ntohs(*(ushort *) tail);
mbuf->qtype = (rrtype)ntohs(*(ushort *) tail);
if (check_support_type(mbuf->qtype) == 0)
mbuf->err = 0;
return;
Expand Down Expand Up @@ -224,9 +224,9 @@ insert_into_ttltree(struct rbtree *rbt, uchar * td, int len, int type, uint ttl,
/* dbg_print_td(td); */
struct rbnode node = { 0 };
struct ttlnode *tn = NULL;
if ((tn = malloc(sizeof(struct ttlnode))) == NULL)
if ((tn = (struct ttlnode*)malloc(sizeof(struct ttlnode))) == NULL)
return -1;
if ((tn->lowerdomain = malloc(sizeof(packet_type))) == NULL) {
if ((tn->lowerdomain = (packet_type*)malloc(sizeof(packet_type))) == NULL) {
free(tn);
return -1;
}
Expand Down Expand Up @@ -539,7 +539,7 @@ insert_kv_mem(struct rbtree *rbt, struct htable *ds, uchar * k, int klen,
return -1;
hashval_t *hash = &(lowerdomain->hash[0]);
idx = get_pre_mem_hash(k, klen, hash);
val = malloc(vlen);
val = (uchar*)malloc(vlen);
if (val == NULL)
return -1;
memcpy(val, v, vlen);
Expand All @@ -561,7 +561,7 @@ insert_kv_mem(struct rbtree *rbt, struct htable *ds, uchar * k, int klen,
//if update, we had delete tn in rbt
//else update tn in rbt
if (pn != NULL) {
tmp_tn = delete_node(rbt, pn);
tmp_tn = (ttlnode*)delete_node(rbt, pn);
if (tmp_tn) {
free(tmp_tn->lowerdomain);
free(tmp_tn);
Expand Down