diff --git a/src/dns_client.c b/src/dns_client.c index 87b258c..ffacc8b 100644 --- a/src/dns_client.c +++ b/src/dns_client.c @@ -1843,7 +1843,8 @@ static int _dns_client_create_socket_udp(struct dns_server_info *server_info) server_info->status = DNS_SERVER_STATUS_CONNECTIONLESS; if (connect(fd, &server_info->addr, server_info->ai_addrlen) != 0) { - if (errno == ENETUNREACH || errno == EHOSTUNREACH || errno == ECONNREFUSED) { + if (errno == ENETUNREACH || errno == EHOSTUNREACH || errno == ECONNREFUSED || errno == EPERM || + errno == EACCES) { tlog(TLOG_INFO, "connect %s failed, %s", server_info->ip, strerror(errno)); goto errout; } @@ -3567,7 +3568,8 @@ static int _dns_client_send_packet(struct dns_query_struct *query, void *packet, time(&now); if (now - lastlog > 120) { lastlog = now; - tlog(TLOG_WARN, "Send query %s to upstream server failed, total server number %d", query->domain, total_server); + tlog(TLOG_WARN, "Send query %s to upstream server failed, total server number %d", query->domain, + total_server); } return -1; } diff --git a/src/dns_conf.c b/src/dns_conf.c index b6c331a..b791145 100644 --- a/src/dns_conf.c +++ b/src/dns_conf.c @@ -83,7 +83,7 @@ static struct config_enum_list dns_conf_response_mode_enum[] = { enum response_mode_type dns_conf_response_mode; /* cache */ -int dns_conf_cachesize = -1; +ssize_t dns_conf_cachesize = -1; int dns_conf_prefetch = 0; int dns_conf_serve_expired = 1; int dns_conf_serve_expired_ttl = 24 * 3600 * 3; /* 3 days */ @@ -3250,7 +3250,7 @@ static struct config_item _config_item[] = { CONF_CUSTOM("nftset-no-speed", _config_nftset_no_speed, NULL), CONF_CUSTOM("speed-check-mode", _config_speed_check_mode, NULL), CONF_INT("tcp-idle-time", &dns_conf_tcp_idle_time, 0, 3600), - CONF_INT("cache-size", &dns_conf_cachesize, 0, CONF_INT_MAX), + CONF_SSIZE("cache-size", &dns_conf_cachesize, 0, CONF_INT_MAX), CONF_CUSTOM("cache-file", _config_option_parser_filepath, (char *)&dns_conf_cache_file), CONF_YESNO("cache-persist", &dns_conf_cache_persist), CONF_YESNO("prefetch-domain", &dns_conf_prefetch), diff --git a/src/dns_conf.h b/src/dns_conf.h index eb8b69c..a7c1a48 100644 --- a/src/dns_conf.h +++ b/src/dns_conf.h @@ -434,7 +434,7 @@ extern char dns_conf_bind_ca_key_pass[DNS_MAX_PATH]; extern char dns_conf_need_cert; extern int dns_conf_tcp_idle_time; -extern int dns_conf_cachesize; +extern ssize_t dns_conf_cachesize; extern int dns_conf_prefetch; extern int dns_conf_serve_expired; extern int dns_conf_serve_expired_ttl; diff --git a/src/include/conf.h b/src/include/conf.h index 538c21c..e201662 100644 --- a/src/include/conf.h +++ b/src/include/conf.h @@ -71,6 +71,12 @@ struct config_item_size { size_t max; }; +struct config_item_ssize { + ssize_t *data; + ssize_t min; + ssize_t max; +}; + struct config_enum_list { char *name; int id; @@ -116,6 +122,13 @@ struct config_enum { .data = value, .min = min_value, .max = max_value \ } \ } +#define CONF_SSIZE(key, value, min_value, max_value) \ + { \ + key, conf_ssize, &(struct config_item_ssize) \ + { \ + .data = value, .min = min_value, .max = max_value \ + } \ + } #define CONF_ENUM(key, value, enum) \ { \ @@ -153,6 +166,8 @@ extern int conf_yesno(const char *item, void *data, int argc, char *argv[]); extern int conf_size(const char *item, void *data, int argc, char *argv[]); +extern int conf_ssize(const char *item, void *data, int argc, char *argv[]); + extern int conf_enum(const char *item, void *data, int argc, char *argv[]); /* diff --git a/src/lib/conf.c b/src/lib/conf.c index b64303a..3980143 100644 --- a/src/lib/conf.c +++ b/src/lib/conf.c @@ -189,6 +189,39 @@ int conf_size(const char *item, void *data, int argc, char *argv[]) return 0; } +int conf_ssize(const char *item, void *data, int argc, char *argv[]) +{ + int base = 1; + ssize_t size = 0; + int num = 0; + struct config_item_ssize *item_size = data; + char *value = argv[1]; + + if (strstr(value, "k") || strstr(value, "K")) { + base = 1024; + } else if (strstr(value, "m") || strstr(value, "M")) { + base = 1024 * 1024; + } else if (strstr(value, "g") || strstr(value, "G")) { + base = 1024 * 1024 * 1024; + } + + num = atoi(value); + if (num < 0) { + return -1; + } + + size = num * base; + if (size > item_size->max) { + size = item_size->max; + } else if (size < item_size->min) { + size = item_size->min; + } + + *(item_size->data) = size; + + return 0; +} + int conf_enum(const char *item, void *data, int argc, char *argv[]) { struct config_enum *item_enum = data;