src/core/mainloop: Put brackets around IPv6 addresses in log messages

This commit is contained in:
Neel Chauhan 2021-01-27 08:23:39 -08:00
parent 930a17f347
commit a82b4eb305
3 changed files with 15 additions and 9 deletions

4
changes/ticket40232 Normal file
View File

@ -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.

View File

@ -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,

View File

@ -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);