[or-cvs] parameterize the loudness of resolve_my_address(), and call...

arma at seul.org arma at seul.org
Sat Jul 15 20:26:08 UTC 2006


Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or

Modified Files:
	config.c dirserv.c or.h router.c routerlist.c 
Log Message:
parameterize the loudness of resolve_my_address(), and call things
IP addresses, not IPs.


Index: config.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.571
retrieving revision 1.572
diff -u -p -d -r1.571 -r1.572
--- config.c	8 Jul 2006 17:38:46 -0000	1.571
+++ config.c	15 Jul 2006 20:26:04 -0000	1.572
@@ -1583,8 +1583,8 @@ print_usage(void)
  * public IP address.
  */
 int
-resolve_my_address(or_options_t *options, uint32_t *addr_out,
-                   char **hostname_out)
+resolve_my_address(int warn_severity, or_options_t *options,
+                   uint32_t *addr_out, char **hostname_out)
 {
   struct in_addr in;
   struct hostent *rent;
@@ -1594,6 +1594,8 @@ resolve_my_address(or_options_t *options
   char tmpbuf[INET_NTOA_BUF_LEN];
   static uint32_t old_addr=0;
   const char *address = options->Address;
+  int notice_severity = warn_severity <= LOG_NOTICE ?
+                          LOG_NOTICE : warn_severity;
 
   tor_assert(addr_out);
 
@@ -1604,13 +1606,13 @@ resolve_my_address(or_options_t *options
     explicit_hostname = 0; /* it's implicit */
 
     if (gethostname(hostname, sizeof(hostname)) < 0) {
-      log_warn(LD_NET,"Error obtaining local hostname");
+      log_fn(warn_severity, LD_NET,"Error obtaining local hostname");
       return -1;
     }
     log_debug(LD_CONFIG,"Guessed local host name as '%s'",hostname);
   }
 
-  /* now we know hostname. resolve it and keep only the IP */
+  /* now we know hostname. resolve it and keep only the IP address */
 
   if (tor_inet_aton(hostname, &in) == 0) {
     /* then we have to resolve it */
@@ -1620,21 +1622,22 @@ resolve_my_address(or_options_t *options
       uint32_t interface_ip;
 
       if (explicit_hostname) {
-        log_warn(LD_CONFIG,"Could not resolve local Address '%s'. Failing.",
-                 hostname);
+        log_fn(warn_severity, LD_CONFIG,
+               "Could not resolve local Address '%s'. Failing.", hostname);
         return -1;
       }
-      log_notice(LD_CONFIG, "Could not resolve guessed local hostname '%s'. "
-                            "Trying something else.", hostname);
+      log_fn(notice_severity, LD_CONFIG,
+             "Could not resolve guessed local hostname '%s'. "
+             "Trying something else.", hostname);
       if (get_interface_address(&interface_ip)) {
-        log_warn(LD_CONFIG, "Could not get local interface IP address. "
-                 "Failing.");
+        log_fn(warn_severity, LD_CONFIG,
+               "Could not get local interface IP address. Failing.");
         return -1;
       }
       in.s_addr = htonl(interface_ip);
       tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
-      log_notice(LD_CONFIG, "Learned IP address '%s' for local interface."
-               " Using that.", tmpbuf);
+      log_fn(notice_severity, LD_CONFIG, "Learned IP address '%s' for "
+             "local interface. Using that.", tmpbuf);
       strlcpy(hostname, "<guessed from interfaces>", sizeof(hostname));
     } else {
       tor_assert(rent->h_length == 4);
@@ -1645,24 +1648,26 @@ resolve_my_address(or_options_t *options
         uint32_t interface_ip;
 
         tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
-        log_notice(LD_CONFIG, "Guessed local hostname '%s' resolves to a "
-          "private IP address (%s).  Trying something else.", hostname,
-          tmpbuf);
+        log_fn(notice_severity, LD_CONFIG, "Guessed local hostname '%s' "
+               "resolves to a private IP address (%s).  Trying something "
+               "else.", hostname, tmpbuf);
 
         if (get_interface_address(&interface_ip)) {
-          log_warn(LD_CONFIG, "Could not get local interface IP address. "
-                              "Too bad.");
+          log_fn(warn_severity, LD_CONFIG,
+                 "Could not get local interface IP address. Too bad.");
         } else if (is_internal_IP(interface_ip, 0)) {
           struct in_addr in2;
           in2.s_addr = htonl(interface_ip);
           tor_inet_ntoa(&in2,tmpbuf,sizeof(tmpbuf));
-          log_notice(LD_CONFIG, "Interface IP '%s' is a private address "
-                                "too.  Ignoring.", tmpbuf);
+          log_fn(notice_severity, LD_CONFIG,
+                 "Interface IP address '%s' is a private address too. "
+                 "Ignoring.", tmpbuf);
         } else {
           in.s_addr = htonl(interface_ip);
           tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
-          log_notice(LD_CONFIG, "Learned IP address '%s' for local interface."
-                                " Using that.", tmpbuf);
+          log_fn(notice_severity, LD_CONFIG,
+                 "Learned IP address '%s' for local interface."
+                 " Using that.", tmpbuf);
           strlcpy(hostname, "<guessed from interfaces>", sizeof(hostname));
         }
       }
@@ -1676,18 +1681,18 @@ resolve_my_address(or_options_t *options
     if (!options->DirServers) {
       /* if they are using the default dirservers, disallow internal IPs
        * always. */
-      log_warn(LD_CONFIG,"Address '%s' resolves to private IP '%s'. "
-               "Tor servers that use the default DirServers must have public "
-               "IP addresses.",
-               hostname, tmpbuf);
+      log_fn(warn_severity, LD_CONFIG,
+             "Address '%s' resolves to private IP address '%s'. "
+             "Tor servers that use the default DirServers must have public "
+             "IP addresses.", hostname, tmpbuf);
       return -1;
     }
     if (!explicit_ip) {
       /* even if they've set their own dirservers, require an explicit IP if
        * they're using an internal address. */
-      log_warn(LD_CONFIG,"Address '%s' resolves to private IP '%s'. Please "
-               "set the Address config option to be the IP you want to use.",
-               hostname, tmpbuf);
+      log_fn(warn_severity, LD_CONFIG, "Address '%s' resolves to private "
+             "IP address '%s'. Please set the Address config option to be "
+             "the IP address you want to use.", hostname, tmpbuf);
       return -1;
     }
   }
@@ -1695,7 +1700,9 @@ resolve_my_address(or_options_t *options
   log_debug(LD_CONFIG, "Resolved Address to '%s'.", tmpbuf);
   *addr_out = ntohl(in.s_addr);
   if (old_addr && old_addr != *addr_out) {
-    log_notice(LD_NET, "Your IP seems to have changed. Updating.");
+    /* Leave this as a notice, regardless of the requested severity,
+     * at least until dynamic IP address support becomes bulletproof. */
+    log_notice(LD_NET, "Your IP address seems to have changed. Updating.");
     server_has_changed_ip();
   }
   old_addr = *addr_out;
@@ -2125,7 +2132,7 @@ options_validate(or_options_t *old_optio
   if (server_mode(options)) {
     /* confirm that our address isn't broken, so we can complain now */
     uint32_t tmp;
-    if (resolve_my_address(options, &tmp, NULL) < 0)
+    if (resolve_my_address(LOG_WARN, options, &tmp, NULL) < 0)
       REJECT("Failed to resolve/guess local address. See logs for details.");
   }
 

Index: dirserv.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.355
retrieving revision 1.356
diff -u -p -d -r1.355 -r1.356
--- dirserv.c	14 Jul 2006 03:14:02 -0000	1.355
+++ dirserv.c	15 Jul 2006 20:26:05 -0000	1.356
@@ -1347,7 +1347,7 @@ generate_v2_networkstatus(void)
   int versioning = options->VersioningAuthoritativeDir;
   const char *contact;
 
-  if (resolve_my_address(options, &addr, &hostname)<0) {
+  if (resolve_my_address(LOG_WARN, options, &addr, &hostname)<0) {
     log_warn(LD_NET, "Couldn't resolve my hostname");
     goto done;
   }

Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.848
retrieving revision 1.849
diff -u -p -d -r1.848 -r1.849
--- or.h	7 Jul 2006 17:33:30 -0000	1.848
+++ or.h	15 Jul 2006 20:26:05 -0000	1.849
@@ -1631,8 +1631,8 @@ int config_get_lines(char *string, confi
 void config_free_lines(config_line_t *front);
 int options_trial_assign(config_line_t *list, int use_defaults,
                          int clear_first, char **msg);
-int resolve_my_address(or_options_t *options, uint32_t *addr,
-                       char **hostname_out);
+int resolve_my_address(int warn_severity, or_options_t *options,
+                       uint32_t *addr, char **hostname_out);
 void options_init(or_options_t *options);
 int options_init_from_torrc(int argc, char **argv);
 int options_init_logs(or_options_t *options, int validate_only);

Index: router.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.268
retrieving revision 1.269
diff -u -p -d -r1.268 -r1.269
--- router.c	4 Jul 2006 03:31:27 -0000	1.268
+++ router.c	15 Jul 2006 20:26:05 -0000	1.269
@@ -752,7 +752,7 @@ router_rebuild_descriptor(int force)
   if (desc_clean_since && !force)
     return 0;
 
-  if (resolve_my_address(options, &addr, NULL) < 0) {
+  if (resolve_my_address(LOG_WARN, options, &addr, NULL) < 0) {
     log_warn(LD_CONFIG,"options->Address didn't resolve into an IP.");
     return -1;
   }
@@ -908,7 +908,7 @@ check_descriptor_ipaddress_changed(time_
     return;
 
   prev = desc_routerinfo->addr;
-  if (resolve_my_address(options, &cur, NULL) < 0) {
+  if (resolve_my_address(LOG_WARN, options, &cur, NULL) < 0) {
     log_warn(LD_CONFIG,"options->Address didn't resolve into an IP.");
     return;
   }

Index: routerlist.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.531
retrieving revision 1.532
diff -u -p -d -r1.531 -r1.532
--- routerlist.c	9 Jul 2006 22:28:12 -0000	1.531
+++ routerlist.c	15 Jul 2006 20:26:05 -0000	1.532
@@ -2645,7 +2645,7 @@ add_trusted_dir_server(const char *nickn
     trusted_dir_servers = smartlist_create();
 
   if (!address) { /* The address is us; we should guess. */
-    if (resolve_my_address(get_options(), &a, &hostname) < 0) {
+    if (resolve_my_address(LOG_WARN, get_options(), &a, &hostname) < 0) {
       log_warn(LD_CONFIG,
                "Couldn't find a suitable address when adding ourself as a "
                "trusted directory server.");



More information about the tor-commits mailing list