|
@@ -295,7 +295,7 @@ static int global_max_nameserver_timeout = 3;
|
|
static const struct timeval global_nameserver_timeouts[] = {{10, 0}, {60, 0}, {300, 0}, {900, 0}, {3600, 0}};
|
|
static const struct timeval global_nameserver_timeouts[] = {{10, 0}, {60, 0}, {300, 0}, {900, 0}, {3600, 0}};
|
|
static const int global_nameserver_timeouts_length = sizeof(global_nameserver_timeouts)/sizeof(struct timeval);
|
|
static const int global_nameserver_timeouts_length = sizeof(global_nameserver_timeouts)/sizeof(struct timeval);
|
|
|
|
|
|
-const char *const evdns_error_strings[] = {"no error", "The name server was unable to interpret the query", "The name server suffered an internal error", "The requested domain name does not exist", "The name server refused to reply to the request"};
|
|
+static const char *const evdns_error_strings[] = {"no error", "The name server was unable to interpret the query", "The name server suffered an internal error", "The requested domain name does not exist", "The name server refused to reply to the request"};
|
|
|
|
|
|
static struct nameserver *nameserver_pick(void);
|
|
static struct nameserver *nameserver_pick(void);
|
|
static void evdns_request_insert(struct request *req, struct request **head);
|
|
static void evdns_request_insert(struct request *req, struct request **head);
|
|
@@ -2490,6 +2490,64 @@ strtoint(const char *const str) {
|
|
return r;
|
|
return r;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+static int
|
|
|
|
+strtoint_clipped(const char *const str, int min, int max)
|
|
|
|
+{
|
|
|
|
+ int r = strtoint(str);
|
|
|
|
+ if (r == -1)
|
|
|
|
+ return r;
|
|
|
|
+ else if (r<min)
|
|
|
|
+ return min;
|
|
|
|
+ else if (r>max)
|
|
|
|
+ return max;
|
|
|
|
+ else
|
|
|
|
+ return r;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+int
|
|
|
|
+evdns_set_option(const char *option, const char *val, int flags)
|
|
|
|
+{
|
|
|
|
+ if (!strncmp(option, "ndots:", 6)) {
|
|
|
|
+ const int ndots = strtoint(val);
|
|
|
|
+ if (ndots == -1) return -1;
|
|
|
|
+ if (!(flags & DNS_OPTION_SEARCH)) return 0;
|
|
|
|
+ log(EVDNS_LOG_DEBUG, "Setting ndots to %d", ndots);
|
|
|
|
+ if (!global_search_state) global_search_state = search_state_new();
|
|
|
|
+ if (!global_search_state) return -1;
|
|
|
|
+ global_search_state->ndots = ndots;
|
|
|
|
+ } else if (!strncmp(option, "timeout:", 8)) {
|
|
|
|
+ const int timeout = strtoint(val);
|
|
|
|
+ if (timeout == -1) return -1;
|
|
|
|
+ if (!(flags & DNS_OPTION_MISC)) return 0;
|
|
|
|
+ log(EVDNS_LOG_DEBUG, "Setting timeout to %d", timeout);
|
|
|
|
+ global_timeout.tv_sec = timeout;
|
|
|
|
+ } else if (!strncmp(option, "max-timeouts:", 12)) {
|
|
|
|
+ const int maxtimeout = strtoint_clipped(val, 1, 255);
|
|
|
|
+ if (maxtimeout == -1) return -1;
|
|
|
|
+ if (!(flags & DNS_OPTION_MISC)) return 0;
|
|
|
|
+ log(EVDNS_LOG_DEBUG, "Setting maximum allowed timeouts to %d",
|
|
|
|
+ maxtimeout);
|
|
|
|
+ global_max_nameserver_timeout = maxtimeout;
|
|
|
|
+ } else if (!strncmp(option, "max-inflight:", 13)) {
|
|
|
|
+ const int maxinflight = strtoint_clipped(val, 1, 65000);
|
|
|
|
+ if (maxinflight == -1) return -1;
|
|
|
|
+ if (!(flags & DNS_OPTION_MISC)) return 0;
|
|
|
|
+ log(EVDNS_LOG_DEBUG, "Setting maximum inflight requests to %d",
|
|
|
|
+ maxinflight);
|
|
|
|
+ global_max_requests_inflight = maxinflight;
|
|
|
|
+ } else if (!strncmp(option, "attempts:", 9)) {
|
|
|
|
+ int retries = strtoint(val);
|
|
|
|
+ if (retries == -1) return -1;
|
|
|
|
+ if (retries > 255) retries = 255;
|
|
|
|
+ if (!(flags & DNS_OPTION_MISC)) return 0;
|
|
|
|
+ log(EVDNS_LOG_DEBUG, "Setting retries to %d", retries);
|
|
|
|
+ global_max_retransmits = retries;
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
static void
|
|
static void
|
|
resolv_conf_parse_line(char *const start, int flags) {
|
|
resolv_conf_parse_line(char *const start, int flags) {
|
|
char *strtok_state;
|
|
char *strtok_state;
|
|
@@ -2523,30 +2581,9 @@ resolv_conf_parse_line(char *const start, int flags) {
|
|
search_reverse();
|
|
search_reverse();
|
|
} else if (!strcmp(first_token, "options")) {
|
|
} else if (!strcmp(first_token, "options")) {
|
|
const char *option;
|
|
const char *option;
|
|
-
|
|
|
|
while ((option = NEXT_TOKEN)) {
|
|
while ((option = NEXT_TOKEN)) {
|
|
- if (!strncmp(option, "ndots:", 6)) {
|
|
+ const char *val = strchr(option, ':');
|
|
- const int ndots = strtoint(&option[6]);
|
|
+ evdns_set_option(option, val ? val+1 : "", flags);
|
|
- if (ndots == -1) continue;
|
|
|
|
- if (!(flags & DNS_OPTION_SEARCH)) continue;
|
|
|
|
- log(EVDNS_LOG_DEBUG, "Setting ndots to %d", ndots);
|
|
|
|
- if (!global_search_state) global_search_state = search_state_new();
|
|
|
|
- if (!global_search_state) return;
|
|
|
|
- global_search_state->ndots = ndots;
|
|
|
|
- } else if (!strncmp(option, "timeout:", 8)) {
|
|
|
|
- const int timeout = strtoint(&option[8]);
|
|
|
|
- if (timeout == -1) continue;
|
|
|
|
- if (!(flags & DNS_OPTION_MISC)) continue;
|
|
|
|
- log(EVDNS_LOG_DEBUG, "Setting timeout to %d", timeout);
|
|
|
|
- global_timeout.tv_sec = timeout;
|
|
|
|
- } else if (!strncmp(option, "attempts:", 9)) {
|
|
|
|
- int retries = strtoint(&option[9]);
|
|
|
|
- if (retries == -1) continue;
|
|
|
|
- if (retries > 255) retries = 255;
|
|
|
|
- if (!(flags & DNS_OPTION_MISC)) continue;
|
|
|
|
- log(EVDNS_LOG_DEBUG, "Setting retries to %d", retries);
|
|
|
|
- global_max_retransmits = retries;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#undef NEXT_TOKEN
|
|
#undef NEXT_TOKEN
|