Skip to content

Commit

Permalink
dns_conf: a little performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Jan 21, 2024
1 parent 903c7d5 commit 2778b28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dns_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/dns_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2778b28

Please sign in to comment.