瀏覽代碼

r9007@Kushana: nickm | 2006-09-29 13:17:32 -0400
Make eventdns give strings for DNS errors, not just error numbers.


svn:r8535

Nick Mathewson 17 年之前
父節點
當前提交
b21e656eaf
共有 3 個文件被更改,包括 24 次插入3 次删除
  1. 1 0
      ChangeLog
  2. 22 3
      src/or/eventdns.c
  3. 1 0
      src/or/eventdns.h

+ 1 - 0
ChangeLog

@@ -85,6 +85,7 @@ Changes in version 0.1.2.2-alpha - 2006-??-??
       by us right now' with 'listed as down by the directory authorities'.
       With the old code, if a guard was unreachable by us but listed as
       running, it would clog our guard list forever.
+    - Make eventdns give strings for DNS errors, not just error numbers.
 
   o Documentation
     - Documented (and renamed) ServerDNSSearchDomains and

+ 22 - 3
src/or/eventdns.c

@@ -785,8 +785,9 @@ reply_handle(struct request *const req,
 			// we regard these errors as marking a bad nameserver
 			if (req->reissue_count < global_max_reissues) {
 				char msg[64];
-				snprintf(msg, sizeof(msg), "Bad response %d",
-					 error);
+
+				snprintf(msg, sizeof(msg), "Bad response %d (%s)",
+						 error, evdns_err_to_string(error));
 				nameserver_failed(req->ns, msg);
 				if (!request_reissue(req)) return;
 			}
@@ -2292,6 +2293,7 @@ main(int c, char **v) {
 	event_dispatch();
 	return 0;
 }
+#endif
 
 int
 evdns_init(void)
@@ -2306,7 +2308,24 @@ evdns_init(void)
         return (res);
 }
 
-#endif
+const char *
+evdns_err_to_string(int err)
+{
+    switch (err) {
+	case DNS_ERR_NONE: return "no error";
+	case DNS_ERR_FORMAT: return "misformatted query";
+	case DNS_ERR_SERVERFAILED: return "server failed";
+	case DNS_ERR_NOTEXIST: return "name does not exist";
+	case DNS_ERR_NOTIMPL: return "query not implemented";
+	case DNS_ERR_REFUSED: return "refused";
+
+	case DNS_ERR_TRUNCATED: return "reply truncated or ill-formed";
+	case DNS_ERR_UNKNOWN: return "unknown";
+	case DNS_ERR_TIMEOUT: return "request timed out";
+	case DNS_ERR_SHUTDOWN: return "dns subsystem shut down";
+	default: return "[Unknown error code]";
+	}
+}
 
 void
 evdns_shutdown(int fail_requests)

+ 1 - 0
src/or/eventdns.h

@@ -53,6 +53,7 @@ typedef void (*evdns_callback_type) (int result, char type, int count, int ttl,
 
 int evdns_init(void);
 void evdns_shutdown(int fail_requests);
+const char * evdns_err_to_string(int err);
 int evdns_nameserver_add(unsigned long int address);
 int evdns_count_nameservers(void);
 int evdns_clear_nameservers_and_suspend(void);