[tor-commits] [tor/master] src/core/mainloop: Put brackets around IPv6 addresses in log messages

asn at torproject.org asn at torproject.org
Tue Feb 2 13:35:37 UTC 2021


commit a82b4eb305f96a7bea8c88eeaa37b4fb404c309f
Author: Neel Chauhan <neel at neelc.org>
Date:   Wed Jan 27 08:23:39 2021 -0800

    src/core/mainloop: Put brackets around IPv6 addresses in log messages
---
 changes/ticket40232            |  4 ++++
 src/core/mainloop/connection.c |  8 +++++---
 src/core/mainloop/mainloop.c   | 12 ++++++------
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/changes/ticket40232 b/changes/ticket40232
new file mode 100644
index 0000000000..ecd25fb3e9
--- /dev/null
+++ b/changes/ticket40232
@@ -0,0 +1,4 @@
+  o Minor features (logging, IPv6):
+    - In src/core/mainloop/mainloop.c and src/core/mainloop/connection.c,
+      put brackets around IPv6 addresses in log messages. Closes ticket
+      40232. Patch by Neel Chauhan.
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index c0c56a8b77..df89145cd4 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -3238,7 +3238,7 @@ retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol)
      * we hit those, bail early so tor can stop. */
     if (!new_conn) {
       log_warn(LD_NET, "Unable to create listener port: %s:%d",
-               fmt_addr(&r->new_port->addr), r->new_port->port);
+               fmt_and_decorate_addr(&r->new_port->addr), r->new_port->port);
       retval = -1;
       break;
     }
@@ -3257,7 +3257,8 @@ retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol)
    * any configured port.  Kill 'em. */
   SMARTLIST_FOREACH_BEGIN(listeners, connection_t *, conn) {
     log_notice(LD_NET, "Closing no-longer-configured %s on %s:%d",
-               conn_type_to_string(conn->type), conn->address, conn->port);
+               conn_type_to_string(conn->type),
+               fmt_and_decorate_addr(&conn->addr), conn->port);
     connection_close_immediate(conn);
     connection_mark_for_close(conn);
   } SMARTLIST_FOREACH_END(conn);
@@ -5852,7 +5853,8 @@ clock_skew_warning, (const connection_t *conn, long apparent_skew, int trusted,
   char *ext_source = NULL, *warn = NULL;
   format_time_interval(dbuf, sizeof(dbuf), apparent_skew);
   if (conn)
-    tor_asprintf(&ext_source, "%s:%s:%d", source, conn->address, conn->port);
+    tor_asprintf(&ext_source, "%s:%s:%d", source,
+                 fmt_and_decorate_addr(&conn->addr), conn->port);
   else
     ext_source = tor_strdup(source);
   log_fn(trusted ? LOG_WARN : LOG_INFO, domain,
diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c
index 3892b2bf49..f30545eef0 100644
--- a/src/core/mainloop/mainloop.c
+++ b/src/core/mainloop/mainloop.c
@@ -1224,7 +1224,7 @@ run_connection_housekeeping(int i, time_t now)
      * mark it now. */
     log_info(LD_OR,
              "Expiring non-used OR connection to fd %d (%s:%d) [Too old].",
-             (int)conn->s, conn->address, conn->port);
+             (int)conn->s, fmt_and_decorate_addr(&conn->addr), conn->port);
     if (conn->state == OR_CONN_STATE_CONNECTING)
       connection_or_connect_failed(TO_OR_CONN(conn),
                                    END_OR_CONN_REASON_TIMEOUT,
@@ -1234,7 +1234,7 @@ run_connection_housekeeping(int i, time_t now)
     if (past_keepalive) {
       /* We never managed to actually get this connection open and happy. */
       log_info(LD_OR,"Expiring non-open OR connection to fd %d (%s:%d).",
-               (int)conn->s,conn->address, conn->port);
+               (int)conn->s, fmt_and_decorate_addr(&conn->addr), conn->port);
       connection_or_close_normally(TO_OR_CONN(conn), 0);
     }
   } else if (we_are_hibernating() &&
@@ -1244,7 +1244,7 @@ run_connection_housekeeping(int i, time_t now)
      * flush.*/
     log_info(LD_OR,"Expiring non-used OR connection to fd %d (%s:%d) "
              "[Hibernating or exiting].",
-             (int)conn->s,conn->address, conn->port);
+             (int)conn->s, fmt_and_decorate_addr(&conn->addr), conn->port);
     connection_or_close_normally(TO_OR_CONN(conn), 1);
   } else if (!have_any_circuits &&
              now - or_conn->idle_timeout >=
@@ -1252,7 +1252,7 @@ run_connection_housekeeping(int i, time_t now)
     log_info(LD_OR,"Expiring non-used OR connection %"PRIu64" to fd %d "
              "(%s:%d) [no circuits for %d; timeout %d; %scanonical].",
              (chan->global_identifier),
-             (int)conn->s, conn->address, conn->port,
+             (int)conn->s, fmt_and_decorate_addr(&conn->addr), conn->port,
              (int)(now - chan->timestamp_last_had_circuits),
              or_conn->idle_timeout,
              or_conn->is_canonical ? "" : "non");
@@ -1264,14 +1264,14 @@ run_connection_housekeeping(int i, time_t now)
     log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,
            "Expiring stuck OR connection to fd %d (%s:%d). (%d bytes to "
            "flush; %d seconds since last write)",
-           (int)conn->s, conn->address, conn->port,
+           (int)conn->s, fmt_and_decorate_addr(&conn->addr), conn->port,
            (int)connection_get_outbuf_len(conn),
            (int)(now-conn->timestamp_last_write_allowed));
     connection_or_close_normally(TO_OR_CONN(conn), 0);
   } else if (past_keepalive && !connection_get_outbuf_len(conn)) {
     /* send a padding cell */
     log_fn(LOG_DEBUG,LD_OR,"Sending keepalive to (%s:%d)",
-           conn->address, conn->port);
+           fmt_and_decorate_addr(&conn->addr), conn->port);
     memset(&cell,0,sizeof(cell_t));
     cell.command = CELL_PADDING;
     connection_or_write_cell_to_buf(&cell, or_conn);





More information about the tor-commits mailing list