ip-alias: add option -no-ipalias for domain-rules

This commit is contained in:
Nick Peng
2023-08-30 00:34:27 +08:00
parent 45e3455932
commit 901baf80c0
5 changed files with 97 additions and 3 deletions

View File

@@ -3031,6 +3031,11 @@ static int _conf_domain_rule_no_cache(const char *domain)
return _config_domain_rule_flag_set(domain, DOMAIN_FLAG_NO_CACHE, 0);
}
static int _conf_domain_rule_no_ipalias(const char *domain)
{
return _config_domain_rule_flag_set(domain, DOMAIN_FLAG_NO_IPALIAS, 0);
}
static int _conf_domain_rules(void *data, int argc, char *argv[])
{
int opt = 0;
@@ -3056,6 +3061,7 @@ static int _conf_domain_rules(void *data, int argc, char *argv[])
{"no-serve-expired", no_argument, NULL, 254},
{"delete", no_argument, NULL, 255},
{"no-cache", no_argument, NULL, 256},
{"no-ip-alias", no_argument, NULL, 257},
{NULL, no_argument, NULL, 0}
};
/* clang-format on */
@@ -3211,6 +3217,14 @@ static int _conf_domain_rules(void *data, int argc, char *argv[])
break;
}
case 257: {
if (_conf_domain_rule_no_ipalias(domain) != 0) {
tlog(TLOG_ERROR, "set no-ipalias rule failed.");
goto errout;
}
break;
}
default:
break;
}

View File

@@ -117,6 +117,7 @@ typedef enum {
#define DOMAIN_FLAG_NO_SERVE_EXPIRED (1 << 15)
#define DOMAIN_FLAG_CNAME_IGN (1 << 16)
#define DOMAIN_FLAG_NO_CACHE (1 << 17)
#define DOMAIN_FLAG_NO_IPALIAS (1 << 18)
#define SERVER_FLAG_EXCLUDE_DEFAULT (1 << 0)
#define SERVER_FLAG_HITCHHIKING (1 << 1)

View File

@@ -321,6 +321,7 @@ struct dns_request {
int no_select_possible_ip;
int no_cache_cname;
int no_cache;
int no_ipalias;
int has_cname_loop;
};
@@ -2862,9 +2863,11 @@ static int _dns_server_process_ip_rule(struct dns_request *request, unsigned cha
}
if (rule->ip_alias_enable && alias != NULL) {
*alias = rule->ip_alias;
if (alias == NULL) {
return 0;
if (request->no_ipalias == 0) {
*alias = rule->ip_alias;
if (alias == NULL) {
return 0;
}
}
/* need process ip alias */
@@ -4137,6 +4140,10 @@ static int _dns_server_pre_process_rule_flags(struct dns_request *request)
request->no_cache = 1;
}
if (flags & DOMAIN_FLAG_NO_IPALIAS) {
request->no_ipalias = 1;
}
if (flags & DOMAIN_FLAG_ADDR_IGN) {
/* ignore this domain */
goto skip_soa_out;