Add rule match log
This commit is contained in:
12
ReadMe.md
12
ReadMe.md
@@ -123,6 +123,7 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
|
|||||||
|
|
||||||
openwrt系统CPU架构比较多,请查看CPU架构后下载,CPU架构可在路由器管理界面找到,查看方法:
|
openwrt系统CPU架构比较多,请查看CPU架构后下载,CPU架构可在路由器管理界面找到,查看方法:
|
||||||
* 登录路由器,点击`System`->`Software`,点击`Configuration` Tab页面,在opkg安装源中可找到对应软件架构,下载路径中可找到,如下,架构为ar71xx
|
* 登录路由器,点击`System`->`Software`,点击`Configuration` Tab页面,在opkg安装源中可找到对应软件架构,下载路径中可找到,如下,架构为ar71xx
|
||||||
|
|
||||||
```
|
```
|
||||||
src/gz chaos_calmer_base http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/base
|
src/gz chaos_calmer_base http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/packages/base
|
||||||
```
|
```
|
||||||
@@ -133,20 +134,27 @@ src/gz chaos_calmer_base http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/
|
|||||||
--------------
|
--------------
|
||||||
1. 安装
|
1. 安装
|
||||||
下载配套安装包`smartdns.xxxxxxxx.armhf.deb`,并上传到Linux系统中。 执行如下命令安装
|
下载配套安装包`smartdns.xxxxxxxx.armhf.deb`,并上传到Linux系统中。 执行如下命令安装
|
||||||
|
|
||||||
```
|
```
|
||||||
dpkg -i smartdns.xxxxxxxx.armhf.deb
|
dpkg -i smartdns.xxxxxxxx.armhf.deb
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 修改配置
|
2. 修改配置
|
||||||
安装完成后,可配置smartdns的上游服务器信息。具体配置参数参考`配置参数`说明。
|
安装完成后,可配置smartdns的上游服务器信息。具体配置参数参考`配置参数`说明。
|
||||||
一般情况下,只需要增加`server [IP]:port`, `server-tcp [IP]:port`配置项
|
一般情况下,只需要增加`server [IP]:port`, `server-tcp [IP]:port`配置项
|
||||||
|
尽可能配置多个上游DNS服务器,包括国内外的服务器。
|
||||||
|
|
||||||
```
|
```
|
||||||
vi /etc/smartdns/smartdns.conf
|
vi /etc/smartdns/smartdns.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 启动服务
|
3. 启动服务
|
||||||
|
|
||||||
```
|
```
|
||||||
systemctl enable smartdns
|
systemctl enable smartdns
|
||||||
systemctl start smartdns
|
systemctl start smartdns
|
||||||
```
|
```
|
||||||
|
|
||||||
4. 将DNS请求转发的SmartDNS解析。
|
4. 将DNS请求转发的SmartDNS解析。
|
||||||
修改本地路由器的DNS服务器,将DNS服务器配置为SmartDNS。
|
修改本地路由器的DNS服务器,将DNS服务器配置为SmartDNS。
|
||||||
* 登录到本地网络的路由器中,配置树莓派分配静态IP地址。
|
* 登录到本地网络的路由器中,配置树莓派分配静态IP地址。
|
||||||
@@ -189,6 +197,7 @@ opkg install luci-app-smartdns.xxxxxxxx.xxxx.all.ipk
|
|||||||
|
|
||||||
4. 检测服务是否配置成功。
|
4. 检测服务是否配置成功。
|
||||||
使用nslookup查询域名,看命令结果中的`服务器`项目是否显示为`Linux主机名`,如`smartdns`则表示生效
|
使用nslookup查询域名,看命令结果中的`服务器`项目是否显示为`Linux主机名`,如`smartdns`则表示生效
|
||||||
|
|
||||||
```
|
```
|
||||||
C:\Users\meikechong>nslookup www.baidu.com
|
C:\Users\meikechong>nslookup www.baidu.com
|
||||||
服务器: smartdns
|
服务器: smartdns
|
||||||
@@ -219,7 +228,8 @@ SSH登录用户名密码与管理界面相同。
|
|||||||
下载完成后,启用`Download Master`,如果不需要下载功能,此处可以卸载`Download Master`,但要保证卸载前Download Master是启用的。
|
下载完成后,启用`Download Master`,如果不需要下载功能,此处可以卸载`Download Master`,但要保证卸载前Download Master是启用的。
|
||||||
|
|
||||||
3. 安装SmartDNS
|
3. 安装SmartDNS
|
||||||
将软件使用winscp上传到路由器的`/tmp/mnt/sda1`目录。(或网上邻居复制到sda1共享目录)
|
将软件使用winscp上传到路由器的`/tmp/mnt/sda1`目录。(或网上邻居复制到sda1共享目录)
|
||||||
|
|
||||||
```
|
```
|
||||||
ipkg install smartdns.xxxxxxx.mipsbig.ipk
|
ipkg install smartdns.xxxxxxx.mipsbig.ipk
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -741,11 +741,22 @@ errout:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _dns_server_log_rule(char *domain, unsigned char *rule_key, int rule_key_len)
|
||||||
|
{
|
||||||
|
char rule_name[DNS_MAX_CNAME_LEN];
|
||||||
|
reverse_string(rule_name, (char *)rule_key, rule_key_len);
|
||||||
|
rule_name[rule_key_len - 1] = 0;
|
||||||
|
tlog(TLOG_INFO, "RULE-MATCH, domain: %s, rule: %s", domain, rule_name);
|
||||||
|
}
|
||||||
|
|
||||||
static struct dns_address *_dns_server_get_address_by_domain(char *domain, int qtype)
|
static struct dns_address *_dns_server_get_address_by_domain(char *domain, int qtype)
|
||||||
{
|
{
|
||||||
int domain_len;
|
int domain_len;
|
||||||
char domain_key[DNS_MAX_CNAME_LEN];
|
char domain_key[DNS_MAX_CNAME_LEN];
|
||||||
char type = '4';
|
char type = '4';
|
||||||
|
unsigned char matched_key[DNS_MAX_CNAME_LEN];
|
||||||
|
int matched_key_len = DNS_MAX_CNAME_LEN;
|
||||||
|
struct dns_address *address = NULL;
|
||||||
|
|
||||||
switch (qtype) {
|
switch (qtype) {
|
||||||
case DNS_T_A:
|
case DNS_T_A:
|
||||||
@@ -763,7 +774,18 @@ static struct dns_address *_dns_server_get_address_by_domain(char *domain, int q
|
|||||||
domain_key[0] = type;
|
domain_key[0] = type;
|
||||||
domain_len++;
|
domain_len++;
|
||||||
|
|
||||||
return art_substring(&dns_conf_address, (unsigned char *)domain_key, domain_len);
|
if (likely(dns_conf_log_level > TLOG_INFO)) {
|
||||||
|
return art_substring(&dns_conf_address, (unsigned char *)domain_key, domain_len, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
address = art_substring(&dns_conf_address, (unsigned char *)domain_key, domain_len, matched_key, &matched_key_len);
|
||||||
|
if (address == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
_dns_server_log_rule(domain, matched_key, matched_key_len);
|
||||||
|
|
||||||
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _dns_server_process_address(struct dns_request *request, struct dns_packet *packet)
|
static int _dns_server_process_address(struct dns_request *request, struct dns_packet *packet)
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ void* art_search(const art_tree *t, const unsigned char *key, int key_len);
|
|||||||
* @return NULL if the item was not found, otherwise
|
* @return NULL if the item was not found, otherwise
|
||||||
* the value pointer is returned.
|
* the value pointer is returned.
|
||||||
*/
|
*/
|
||||||
void *art_substring(const art_tree *t, const unsigned char *str, int str_len);
|
void *art_substring(const art_tree *t, const unsigned char *str, int str_len, unsigned char *key, int *key_len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the minimum valued leaf
|
* Returns the minimum valued leaf
|
||||||
|
|||||||
@@ -998,7 +998,20 @@ static int str_prefix_matches(const art_leaf *n, const unsigned char *str, int s
|
|||||||
return memcmp(str, n->key, n->key_len);
|
return memcmp(str, n->key, n->key_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *art_substring(const art_tree *t, const unsigned char *str, int str_len)
|
static void art_copy_key(art_leaf *leaf, unsigned char *key, int *key_len)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (key == NULL || key_len == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = leaf->key_len > *key_len ? *key_len : leaf->key_len;
|
||||||
|
memcpy(key, leaf->key, len);
|
||||||
|
*key_len = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *art_substring(const art_tree *t, const unsigned char *str, int str_len, unsigned char *key, int *key_len)
|
||||||
{
|
{
|
||||||
art_node **child;
|
art_node **child;
|
||||||
art_node *n = t->root;
|
art_node *n = t->root;
|
||||||
@@ -1013,7 +1026,8 @@ void *art_substring(const art_tree *t, const unsigned char *str, int str_len)
|
|||||||
// Check if the expanded path matches
|
// Check if the expanded path matches
|
||||||
if (!str_prefix_matches((art_leaf*)n, str, str_len)) {
|
if (!str_prefix_matches((art_leaf*)n, str, str_len)) {
|
||||||
found = (art_leaf*)n;
|
found = (art_leaf*)n;
|
||||||
}
|
art_copy_key(found, key, key_len);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1025,6 +1039,7 @@ void *art_substring(const art_tree *t, const unsigned char *str, int str_len)
|
|||||||
// Check if the expanded path matches
|
// Check if the expanded path matches
|
||||||
if (!str_prefix_matches((art_leaf*)m, str, str_len)) {
|
if (!str_prefix_matches((art_leaf*)m, str, str_len)) {
|
||||||
found = (art_leaf*)m;
|
found = (art_leaf*)m;
|
||||||
|
art_copy_key(found, key, key_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user