From 1a492f7dc05545cc6b57ea3645124f74976be30b Mon Sep 17 00:00:00 2001 From: Frand Ren Date: Tue, 12 Sep 2023 03:43:11 +0800 Subject: [PATCH] add domain rule "root or sub" --- src/dns_conf.c | 4 ++++ src/dns_server.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/dns_conf.c b/src/dns_conf.c index 224ac1664f..70afaab8a6 100644 --- a/src/dns_conf.c +++ b/src/dns_conf.c @@ -917,6 +917,10 @@ static int _config_domain_rule_add(const char *domain, enum domain_rule type, vo len--; if (domain[1] == '.') { sub_rule_only = 1; + } else if ((domain[1] == '-') && (domain[2] == '.')) { + len--; + sub_rule_only = 1; + root_rule_only = 1; } } else if (domain[0] == '-') { /* root match only */ diff --git a/src/dns_server.c b/src/dns_server.c index e630e61b6c..f7b87cf4f9 100644 --- a/src/dns_server.c +++ b/src/dns_server.c @@ -4046,14 +4046,16 @@ static int _dns_server_get_rules(unsigned char *key, uint32_t key_len, int is_su return 0; } - /* only subkey rule */ - if (domain_rule->sub_rule_only == 1 && is_subkey == 0) { - return 0; - } + if (domain_rule->sub_rule_only != domain_rule->root_rule_only) { + /* only subkey rule */ + if (domain_rule->sub_rule_only == 1 && is_subkey == 0) { + return 0; + } - /* only root key rule */ - if (domain_rule->root_rule_only == 1 && is_subkey == 1) { - return 0; + /* only root key rule */ + if (domain_rule->root_rule_only == 1 && is_subkey == 1) { + return 0; + } } for (i = 0; i < DOMAIN_RULE_MAX; i++) {