conf: Supports setting the maximum number of IPs returned to the client

This commit is contained in:
Nick Peng
2022-05-21 14:18:28 +08:00
parent 94b84cd32c
commit e6fe6771bf
6 changed files with 19 additions and 3 deletions

View File

@@ -552,6 +552,7 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
| rr-ttl-min | 允许的最小 TTL 值 | 远程查询结果 | 大于 0 的数字 | rr-ttl-min 60 |
| rr-ttl-max | 允许的最大 TTL 值 | 远程查询结果 | 大于 0 的数字 | rr-ttl-max 600 |
| rr-ttl-reply-max | 允许返回给客户端的最大 TTL 值 | 远程查询结果 | 大于 0 的数字 | rr-ttl-reply-max 60 |
| max-reply-ip-num | 允许返回给客户的最大IP数量 | IP数量 | 大于 0 的数字 | max-reply-ip-num 1 |
| log-level | 设置日志级别 | error | fatal、error、warn、notice、info 或 debug | log-level error |
| log-file | 日志文件路径 | /var/log/smartdns.log | 合法路径字符串 | log-file /var/log/smartdns.log |
| log-size | 日志大小 | 128K | 数字 + K、M 或 G | log-size 128K |

View File

@@ -499,6 +499,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|rr-ttl-min|Domain name Minimum TTL|Remote query result|number greater than 0|rr-ttl-min 60
|rr-ttl-reply-max|Domain name Minimum Reply TTL|Remote query result|number greater than 0|rr-ttl-reply-max 60
|rr-ttl-max|Domain name Maximum TTL|Remote query result|number greater than 0|rr-ttl-max 600
|max-reply-ip-num|Maximum number of IPs returned to the client|8|number of IPs, 1~16 |max-reply-ip-num 1
|log-level|log level|error|fatal,error,warn,notice,info,debug|log-level error
|log-file|log path|/var/log/smartdns.log|File Pah|log-file /var/log/smartdns.log
|log-size|log size|128K|number+K,M,G|log-size 128K

View File

@@ -109,6 +109,10 @@ cache-size 4096
# rr-ttl-max 86400
# rr-ttl-reply-max 60
# Maximum number of IPs returned to the client|8|number of IPs, 1~16
# example:
# max-reply-ip-num 1
# set log level
# log-level: [level], level=fatal, error, warn, notice, info, debug
# log-file: file path of log file.
@@ -128,6 +132,9 @@ log-level info
# audit-size 128k
# audit-num 2
# Support reading dnsmasq dhcp file to resolve local hostname
# dnsmasq-lease-file /var/lib/misc/dnsmasq.leases
# certificate file
# ca-file [file]
# ca-file /etc/ssl/certs/ca-certificates.crt

View File

@@ -31,6 +31,7 @@
#include <errno.h>
#define DEFAULT_DNS_CACHE_SIZE 512
#define DNS_MAX_REPLY_IP_NUM 8
/* ipset */
struct dns_ipset_table {
@@ -56,6 +57,8 @@ struct dns_bind_ip dns_conf_bind_ip[DNS_MAX_BIND_IP];
int dns_conf_bind_ip_num = 0;
int dns_conf_tcp_idle_time = 120;
int dns_conf_max_reply_ip_num = DNS_MAX_REPLY_IP_NUM;
/* cache */
int dns_conf_cachesize = DEFAULT_DNS_CACHE_SIZE;
int dns_conf_prefetch = 0;
@@ -1867,6 +1870,7 @@ static struct config_item _config_item[] = {
CONF_INT("rr-ttl-min", &dns_conf_rr_ttl_min, 0, CONF_INT_MAX),
CONF_INT("rr-ttl-max", &dns_conf_rr_ttl_max, 0, CONF_INT_MAX),
CONF_INT("rr-ttl-reply-max", &dns_conf_rr_ttl_reply_max, 0, CONF_INT_MAX),
CONF_INT("max-reply-ip-num", &dns_conf_max_reply_ip_num, 1, CONF_INT_MAX),
CONF_YESNO("force-AAAA-SOA", &dns_conf_force_AAAA_SOA),
CONF_CUSTOM("force-qtype-SOA", _config_qtype_soa, NULL),
CONF_CUSTOM("blacklist-ip", _config_blacklist_ip, NULL),

View File

@@ -290,6 +290,8 @@ extern struct dns_conf_address_rule dns_conf_address_rule;
extern int dns_conf_dualstack_ip_selection;
extern int dns_conf_dualstack_ip_selection_threshold;
extern int dns_conf_max_reply_ip_num;
extern int dns_conf_rr_ttl;
extern int dns_conf_rr_ttl_reply_max;
extern int dns_conf_rr_ttl_min;

View File

@@ -44,7 +44,6 @@
#include <sys/types.h>
#define DNS_MAX_EVENTS 256
#define DNS_SERVER_MAX_REPONSE_IPNUM 10
#define IPV6_READY_CHECK_TIME 180
#define DNS_SERVER_TMOUT_TTL (5 * 60)
#define DNS_CONN_BUFF_SIZE 4096
@@ -532,7 +531,7 @@ static int _dns_rrs_add_all_best_ip(struct dns_server_post_context *context)
int ignore_speed = 0;
int maxhit = 0;
if (context->select_all_best_ip == 0) {
if (context->select_all_best_ip == 0 || dns_conf_max_reply_ip_num - 1 <= 0) {
return 0;
}
@@ -555,7 +554,7 @@ static int _dns_rrs_add_all_best_ip(struct dns_server_post_context *context)
pthread_mutex_lock(&request->ip_map_lock);
hash_for_each_safe(request->ip_map, bucket, tmp, addr_map, node)
{
if (context->ip_num >= DNS_SERVER_MAX_REPONSE_IPNUM) {
if (context->ip_num >= dns_conf_max_reply_ip_num) {
break;
}
@@ -1497,6 +1496,8 @@ static void _dns_server_complete_with_multi_ipaddress(struct dns_request *reques
int do_reply = 0;
if (atomic_inc_return(&request->notified) == 1) {
do_reply = 1;
} else if (dns_conf_max_reply_ip_num == 1) {
return;
}
_dns_server_post_context_init(&context, request);