]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Parse 'timeout' and 'attempts' from resolv.conf
authorPetr Menšík <pemensik@redhat.com>
Tue, 22 Jun 2021 14:35:46 +0000 (16:35 +0200)
committerEvan Hunt <each@isc.org>
Thu, 12 Aug 2021 16:52:52 +0000 (09:52 -0700)
It was supported by lwres in BIND 9.11, and is still mentioned in
the manual page. Restore support for it by adding it to libirs.

bin/dig/dighost.c
lib/irs/include/irs/resconf.h
lib/irs/resconf.c

index 05c7ed55981111c771c347969ce45e572073aa4e..b6131e0831c12423270316c98ba3235c78b61fd4 100644 (file)
@@ -114,7 +114,7 @@ isc_sockaddr_t localaddr;
 isc_refcount_t sendcount = ATOMIC_VAR_INIT(0);
 isc_refcount_t recvcount = ATOMIC_VAR_INIT(0);
 int ndots = -1;
-int tries = 3;
+int tries = -1;
 int lookup_counter = 0;
 
 static char servercookie[256];
@@ -1276,6 +1276,17 @@ setup_system(bool ipv4only, bool ipv6only) {
                ndots = irs_resconf_getndots(resconf);
                debug("ndots is %d.", ndots);
        }
+       if (timeout == 0) {
+               timeout = irs_resconf_gettimeout(resconf);
+               debug("timeout is %d.", timeout);
+       }
+       if (tries == -1) {
+               tries = irs_resconf_getattempts(resconf);
+               if (tries == 0) {
+                       tries = 3;
+               }
+               debug("retries is %d.", tries);
+       }
 
        /* If user doesn't specify server use nameservers from resolv.conf. */
        if (ISC_LIST_EMPTY(server_list)) {
index d95c150a64c72baae8fce777575e64f0c0014f73..f5ec355765aec9a42f51bf6cd1899a49e7466def 100644 (file)
@@ -115,4 +115,24 @@ irs_resconf_getndots(irs_resconf_t *conf);
  *\li  'conf' is a valid resconf object.
  */
 
+unsigned int
+irs_resconf_getattempts(irs_resconf_t *conf);
+/*%<
+ * Return the 'attempts' value stored in 'conf'.
+ *
+ * Requires:
+ *
+ *\li  'conf' is a valid resconf object.
+ */
+
+unsigned int
+irs_resconf_gettimeout(irs_resconf_t *conf);
+/*%<
+ * Return the 'timeout' value stored in 'conf'.
+ *
+ * Requires:
+ *
+ *\li  'conf' is a valid resconf object.
+ */
+
 ISC_LANG_ENDDECLS
index 8aa723c21c9bde17d06f1510edc4a84d98e556a0..746f65f53415d00784fc4601eae72fd4861fc68e 100644 (file)
 #define RESCONFMAXLINELEN     256U /*%< max size of a line */
 #define RESCONFMAXSORTLIST    10U  /*%< max 10 */
 
+#define CHECK(op)                            \
+       do {                                 \
+               result = (op);               \
+               if (result != ISC_R_SUCCESS) \
+                       goto cleanup;        \
+       } while (0)
+
 /*!
  * configuration data structure
  */
@@ -108,6 +115,10 @@ struct irs_resconf {
        uint8_t resdebug;
        /*%< set to n in 'options ndots:n' */
        uint8_t ndots;
+       /*%< set to n in 'options attempts:n' */
+       uint8_t attempts;
+       /*%< set to n in 'options timeout:n' */
+       uint8_t timeout;
 };
 
 static isc_result_t
@@ -165,8 +176,8 @@ eatwhite(FILE *fp) {
  */
 static int
 getword(FILE *fp, char *buffer, size_t size) {
+       char *p = NULL;
        int ch;
-       char *p;
 
        REQUIRE(buffer != NULL);
        REQUIRE(size > 0U);
@@ -446,11 +457,26 @@ resconf_parsesortlist(irs_resconf_t *conf, FILE *fp) {
        return (ISC_R_SUCCESS);
 }
 
+static isc_result_t
+resconf_optionnumber(const char *word, uint8_t *number) {
+       char *p;
+       long n;
+
+       n = strtol(word, &p, 10);
+       if (*p != '\0') { /* Bad string. */
+               return (ISC_R_UNEXPECTEDTOKEN);
+       }
+       if (n < 0 || n > 0xff) { /* Out of range. */
+               return (ISC_R_RANGE);
+       }
+       *number = n;
+       return (ISC_R_SUCCESS);
+}
+
 static isc_result_t
 resconf_parseoption(irs_resconf_t *conf, FILE *fp) {
        int delim;
-       long ndots;
-       char *p;
+       isc_result_t result = ISC_R_SUCCESS;
        char word[RESCONFMAXLINELEN];
 
        delim = getword(fp, word, sizeof(word));
@@ -462,14 +488,11 @@ resconf_parseoption(irs_resconf_t *conf, FILE *fp) {
                if (strcmp("debug", word) == 0) {
                        conf->resdebug = 1;
                } else if (strncmp("ndots:", word, 6) == 0) {
-                       ndots = strtol(word + 6, &p, 10);
-                       if (*p != '\0') { /* Bad string. */
-                               return (ISC_R_UNEXPECTEDTOKEN);
-                       }
-                       if (ndots < 0 || ndots > 0xff) { /* Out of range. */
-                               return (ISC_R_RANGE);
-                       }
-                       conf->ndots = (uint8_t)ndots;
+                       CHECK(resconf_optionnumber(word + 6, &conf->ndots));
+               } else if (strncmp("attempts:", word, 9) == 0) {
+                       CHECK(resconf_optionnumber(word + 9, &conf->attempts));
+               } else if (strncmp("timeout:", word, 8) == 0) {
+                       CHECK(resconf_optionnumber(word + 8, &conf->timeout));
                }
 
                if (delim == EOF || delim == '\n') {
@@ -479,7 +502,8 @@ resconf_parseoption(irs_resconf_t *conf, FILE *fp) {
                }
        }
 
-       return (ISC_R_SUCCESS);
+cleanup:
+       return (result);
 }
 
 static isc_result_t
@@ -521,6 +545,8 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) {
        conf->sortlistnxt = 0;
        conf->resdebug = 0;
        conf->ndots = 1;
+       conf->attempts = 3;
+       conf->timeout = 0;
        for (i = 0; i < RESCONFMAXSEARCH; i++) {
                conf->search[i] = NULL;
        }
@@ -669,3 +695,17 @@ irs_resconf_getndots(irs_resconf_t *conf) {
 
        return ((unsigned int)conf->ndots);
 }
+
+unsigned int
+irs_resconf_getattempts(irs_resconf_t *conf) {
+       REQUIRE(IRS_RESCONF_VALID(conf));
+
+       return ((unsigned int)conf->attempts);
+}
+
+unsigned int
+irs_resconf_gettimeout(irs_resconf_t *conf) {
+       REQUIRE(IRS_RESCONF_VALID(conf));
+
+       return ((unsigned int)conf->timeout);
+}