diff --git a/src/dns_conf.c b/src/dns_conf.c index 2137d11489..cb2a52e87d 100644 --- a/src/dns_conf.c +++ b/src/dns_conf.c @@ -1221,6 +1221,10 @@ static struct dns_conf_group *_config_rule_group_get(const char *group_name) struct dns_conf_group *dns_server_get_rule_group(const char *group_name) { + if (dns_conf_rule.group_num <= 1) { + return dns_conf_rule.default_conf; + } + struct dns_conf_group *rule_group = _config_rule_group_get(group_name); if (rule_group) { return rule_group; @@ -1239,6 +1243,10 @@ static struct dns_conf_group *_config_rule_group_new(const char *group_name) struct dns_conf_group *rule_group = NULL; uint32_t key = 0; + if (group_name == NULL) { + return NULL; + } + rule_group = malloc(sizeof(*rule_group)); if (rule_group == NULL) { return NULL; @@ -1255,6 +1263,7 @@ static struct dns_conf_group *_config_rule_group_new(const char *group_name) key = hash_string(group_name); hash_add(dns_conf_rule.group, &rule_group->node, key); + dns_conf_rule.group_num++; return rule_group; } @@ -1267,6 +1276,7 @@ static void _config_rule_group_remove(struct dns_conf_group *rule_group) Destroy_Radix(rule_group->address_rule.ipv4, _config_ip_iter_free, NULL); Destroy_Radix(rule_group->address_rule.ipv6, _config_ip_iter_free, NULL); free(rule_group->soa_table); + dns_conf_rule.group_num--; free(rule_group); } diff --git a/src/dns_conf.h b/src/dns_conf.h index 61b88ff0d0..e719264e9f 100644 --- a/src/dns_conf.h +++ b/src/dns_conf.h @@ -454,6 +454,7 @@ struct dns_conf_group { struct dns_conf_rule { struct dns_conf_group *default_conf; DECLARE_HASHTABLE(group, 8); + int group_num; }; struct dns_client_rule {