Browse Source

r11873@Kushana: nickm | 2007-01-06 02:32:18 -0500
Implement DNS-related status events.


svn:r9285

Nick Mathewson 17 years ago
parent
commit
5239602dbc
2 changed files with 37 additions and 4 deletions
  1. 17 3
      doc/control-spec.txt
  2. 20 1
      src/or/dns.c

+ 17 - 3
doc/control-spec.txt

@@ -1152,14 +1152,28 @@ do for each. -RD]
      // from resolve_my_address() in config.c
      [unimplemented]
 
-     // sketchy libevent, sketchy OS, sketchy threading
+     // sketchy OS, sketchy threading
      [unimplemented]
 
      // too many onions queued. threading problem or slow cpu?
      [unimplemented]
 
-     // eventdns statements. like, hijacked dns.
-     [unimplemented]
+     NAMESERVER_STATUS
+     "NS=addr"
+     "STATUS=" "UP" / "DOWN"
+     "ERR=" message
+        One of our nameservers has changed status.
+
+     NAMESERVER_ALL_DOWN
+        All of our nameservers have gone down.
+
+     DNS_HIJACKED
+        Our DNS provider is providing an address when it should be saying
+        "NOTFOUND"; Tor will treat the address as a synonym for "NOTFOUND".
+
+     DNS_USELESS
+        Our DNS provider is giving a hijacked address instead of well-known
+        websites; Tor will not try to be an exit node.
 
      BAD_SERVER_DESCRIPTOR
      "DIRAUTH=addr:port"

+ 20 - 1
src/or/dns.c

@@ -171,6 +171,7 @@ init_cache_map(void)
 static void
 evdns_log_cb(int warn, const char *msg)
 {
+  const char *cp;
   if (!strcmpstart(msg, "Resolve requested for") &&
       get_options()->SafeLogging) {
     log(LOG_INFO, LD_EXIT, "eventdns: Resolve requested.");
@@ -178,11 +179,25 @@ evdns_log_cb(int warn, const char *msg)
   } else if (!strcmpstart(msg, "Search: ")) {
     return;
   }
-  if (!strcmpstart(msg, "Nameserver ") && strstr(msg, " has failed: ")) {
+  if (!strcmpstart(msg, "Nameserver ") && (cp=strstr(msg, " has failed: "))) {
+    char *ns = tor_strndup(msg+11, cp-(msg+11));
+    const char *err = strchr(cp, ':'+2);
     /* Don't warn about a single failed nameserver; we'll warn with 'all
      * nameservers have failed' if we're completely out of nameservers;
      * otherwise, the situation is tolerable. */
     warn = 0;
+    control_event_server_status(LOG_WARN,
+                                "NAMESERVER_STATUS NS=%s STATUS=DOWN ERR=%s",
+                                ns, escaped(err));
+    tor_free(ns);
+  } else if (!strcmpstart(msg, "Nameserver ") &&
+             (cp=strstr(msg, " is back up"))) {
+    char *ns = tor_strndup(msg+11, cp-(msg+11));
+    control_event_server_status(LOG_NOTICE,
+                                "NAMESERVER_STATUS NS=%s STATUS=UP", ns);
+    tor_free(ns);
+  } else if (!strcmp(msg, "All nameservers have failed")) {
+    control_event_server_status(LOG_WARN, "NAMESERVER_ALL_DOWN");
   }
   log(warn?LOG_WARN:LOG_INFO, LD_EXIT, "eventdns: %s", msg);
 }
@@ -1720,6 +1735,8 @@ wildcard_increment_answer(const char *id)
         "\"%s\" as 'not found'.", id, *ip, id);
       smartlist_add(dns_wildcard_list, tor_strdup(id));
     }
+    if (!dns_wildcard_notice_given)
+      control_event_server_status(LOG_NOTICE, "DNS_HIJACKED");
     dns_wildcard_notice_given = 1;
   }
 }
@@ -1746,6 +1763,8 @@ add_wildcarded_test_address(const char *address)
       dns_is_completely_invalid = 1;
       mark_my_descriptor_dirty();
     }
+    if (!dns_wildcarded_test_address_notice_given)
+      control_event_server_status(LOG_WARN, "DNS_USELESS");
     dns_wildcarded_test_address_notice_given = 1;
   }
 }