浏览代码

conf: add config: dualstack-ip-allow-force-AAAA

Nick Peng 3 年之前
父节点
当前提交
e3436263d9
共有 3 个文件被更改,包括 12 次插入0 次删除
  1. 2 0
      src/dns_conf.c
  2. 1 0
      src/dns_conf.h
  3. 9 0
      src/dns_server.c

+ 2 - 0
src/dns_conf.c

@@ -108,6 +108,7 @@ struct dns_conf_address_rule dns_conf_address_rule;
 
 /* dual-stack selection */
 int dns_conf_dualstack_ip_selection = 1;
+int dns_conf_dualstack_ip_allow_force_AAAA;
 int dns_conf_dualstack_ip_selection_threshold = 15;
 
 /* TTL */
@@ -1878,6 +1879,7 @@ static struct config_item _config_item[] = {
 	CONF_INT("serve-expired-reply-ttl", &dns_conf_serve_expired_reply_ttl, 0, CONF_INT_MAX),
 	CONF_INT("serve-expired-prefetch-time", &dns_conf_serve_expired_prefetch_time, 0, CONF_INT_MAX),
 	CONF_YESNO("dualstack-ip-selection", &dns_conf_dualstack_ip_selection),
+	CONF_YESNO("dualstack-ip-allow-force-AAAA", &dns_conf_dualstack_ip_allow_force_AAAA),
 	CONF_INT("dualstack-ip-selection-threshold", &dns_conf_dualstack_ip_selection_threshold, 0, 1000),
 	CONF_CUSTOM("log-level", _config_log_level, NULL),
 	CONF_STRING("log-file", (char *)dns_conf_log_file, DNS_MAX_PATH),

+ 1 - 0
src/dns_conf.h

@@ -293,6 +293,7 @@ extern art_tree dns_conf_domain_rule;
 extern struct dns_conf_address_rule dns_conf_address_rule;
 
 extern int dns_conf_dualstack_ip_selection;
+extern int dns_conf_dualstack_ip_allow_force_AAAA;
 extern int dns_conf_dualstack_ip_selection_threshold;
 
 extern int dns_conf_max_reply_ip_num;

+ 9 - 0
src/dns_server.c

@@ -1500,6 +1500,10 @@ static int _dns_server_force_dualstack(struct dns_request *request)
 		}
 	}
 
+	if (request->qtype == DNS_T_A && dns_conf_dualstack_ip_allow_force_AAAA == 0) {
+		return -1;
+	}
+
 	/* if ipv4 is fasting than ipv6, add ipv4 to cache, and return SOA for AAAA request */
 	tlog(TLOG_INFO, "result: %s, qtype: %d, force %s perfered, id: %d, time1: %d, time2: %d", request->domain,
 		 request->qtype, request->qtype == DNS_T_AAAA ? "IPv4" : "IPv6", request->id, request->ping_time,
@@ -3449,6 +3453,10 @@ static int _dns_server_process_cache(struct dns_request *request)
 		goto out;
 	}
 
+	if (request->qtype == DNS_T_A && dns_conf_dualstack_ip_allow_force_AAAA == 0) {
+		goto reply_cache;
+	}
+
 	if (request->dualstack_selection) {
 		int dualstack_qtype;
 		if (request->qtype == DNS_T_A) {
@@ -3480,6 +3488,7 @@ static int _dns_server_process_cache(struct dns_request *request)
 		}
 	}
 
+reply_cache:
 	if (dns_cache_is_soa(dns_cache)) {
 		if (dns_cache_get_ttl(dns_cache) > 0) {
 			ret = _dns_server_process_cache_packet(request, dns_cache);