Merge branch 'bug7011'

Conflicts:
	src/or/circuitbuild.c

The conflict was trivial, since no line of code actually changed in
both branches: There was a fmt_addr() that turned into fmt_addrport()
in bug7011, and a "if (!n_conn)" that turned into "if (!n_chan)" in
master.
This commit is contained in:
Nick Mathewson 2012-10-10 22:31:06 -04:00
commit 7ea904cbc0
13 changed files with 117 additions and 98 deletions

6
changes/bug7011 Normal file
View file

@ -0,0 +1,6 @@
o Minor bugfixes:
- Use square brackets around IPv6 addresses in numerous places that needed
them, including log messages, HTTPS CONNECT proxy requests,
TransportProxy statefile entries, and pluggable transport extra-info
lines. Fix for bug 7011; patch by David Fifield.

View file

@ -1006,6 +1006,19 @@ fmt_addr_impl(const tor_addr_t *addr, int decorate)
return "???"; return "???";
} }
/** Return a string representing the pair <b>addr</b> and <b>port</b>.
* This calls fmt_and_decorate_addr internally, so IPv6 addresses will
* have brackets, and the caveats of fmt_addr_impl apply.
*/
const char *
fmt_addrport(const tor_addr_t *addr, uint16_t port)
{
/* Add space for a colon and up to 5 digits. */
static char buf[TOR_ADDR_BUF_LEN + 6];
tor_snprintf(buf, sizeof(buf), "%s:%u", fmt_and_decorate_addr(addr), port);
return buf;
}
/** Like fmt_addr(), but takes <b>addr</b> as a host-order IPv4 /** Like fmt_addr(), but takes <b>addr</b> as a host-order IPv4
* addresses. Also not thread-safe, also clobbers its return buffer on * addresses. Also not thread-safe, also clobbers its return buffer on
* repeated calls. */ * repeated calls. */

View file

@ -145,6 +145,7 @@ char *tor_dup_addr(const tor_addr_t *addr) ATTR_MALLOC;
* addresses. */ * addresses. */
#define fmt_and_decorate_addr(a) fmt_addr_impl((a), 1) #define fmt_and_decorate_addr(a) fmt_addr_impl((a), 1)
const char *fmt_addr_impl(const tor_addr_t *addr, int decorate); const char *fmt_addr_impl(const tor_addr_t *addr, int decorate);
const char *fmt_addrport(const tor_addr_t *addr, uint16_t port);
const char * fmt_addr32(uint32_t addr); const char * fmt_addr32(uint32_t addr);
int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr); int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr);

View file

@ -1979,9 +1979,9 @@ circuit_handle_first_hop(origin_circuit_t *circ)
tor_assert(firsthop->extend_info); tor_assert(firsthop->extend_info);
/* now see if we're already connected to the first OR in 'route' */ /* now see if we're already connected to the first OR in 'route' */
log_debug(LD_CIRC,"Looking for firsthop '%s:%u'", log_debug(LD_CIRC,"Looking for firsthop '%s'",
fmt_addr(&firsthop->extend_info->addr), fmt_addrport(&firsthop->extend_info->addr,
firsthop->extend_info->port); firsthop->extend_info->port));
n_chan = channel_get_for_extend(firsthop->extend_info->identity_digest, n_chan = channel_get_for_extend(firsthop->extend_info->identity_digest,
&firsthop->extend_info->addr, &firsthop->extend_info->addr,
@ -2497,8 +2497,8 @@ circuit_extend(cell_t *cell, circuit_t *circ)
&should_launch); &should_launch);
if (!n_chan) { if (!n_chan) {
log_debug(LD_CIRC|LD_OR,"Next router (%s:%d): %s", log_debug(LD_CIRC|LD_OR,"Next router (%s): %s",
fmt_addr(&n_addr), (int)n_port, msg?msg:"????"); fmt_addrport(&n_addr, n_port), msg?msg:"????");
circ->n_hop = extend_info_new(NULL /*nickname*/, circ->n_hop = extend_info_new(NULL /*nickname*/,
id_digest, id_digest,
@ -3955,8 +3955,8 @@ extend_info_from_node(const node_t *node, int for_direct_connect)
else else
node_get_prim_orport(node, &ap); node_get_prim_orport(node, &ap);
log_debug(LD_CIRC, "using %s:%d for %s", log_debug(LD_CIRC, "using %s for %s",
fmt_and_decorate_addr(&ap.addr), ap.port, fmt_addrport(&ap.addr, ap.port),
node->ri ? node->ri->nickname : node->rs->nickname); node->ri ? node->ri->nickname : node->rs->nickname);
if (node->ri) if (node->ri)
@ -5347,8 +5347,8 @@ learned_router_identity(const tor_addr_t *addr, uint16_t port,
get_configured_bridge_by_addr_port_digest(addr, port, digest); get_configured_bridge_by_addr_port_digest(addr, port, digest);
if (bridge && tor_digest_is_zero(bridge->identity)) { if (bridge && tor_digest_is_zero(bridge->identity)) {
memcpy(bridge->identity, digest, DIGEST_LEN); memcpy(bridge->identity, digest, DIGEST_LEN);
log_notice(LD_DIR, "Learned fingerprint %s for bridge %s:%d", log_notice(LD_DIR, "Learned fingerprint %s for bridge %s",
hex_str(digest, DIGEST_LEN), fmt_addr(addr), port); hex_str(digest, DIGEST_LEN), fmt_addrport(addr, port));
} }
} }
@ -5393,12 +5393,12 @@ bridge_resolve_conflicts(const tor_addr_t *addr, uint16_t port,
strcmp_opt(bridge->transport_name, transport_name)) { strcmp_opt(bridge->transport_name, transport_name)) {
/* warn the user */ /* warn the user */
char *bridge_description_new, *bridge_description_old; char *bridge_description_new, *bridge_description_old;
tor_asprintf(&bridge_description_new, "%s:%u:%s:%s", tor_asprintf(&bridge_description_new, "%s:%s:%s",
fmt_addr(addr), port, fmt_addrport(addr, port),
digest ? hex_str(digest, DIGEST_LEN) : "", digest ? hex_str(digest, DIGEST_LEN) : "",
transport_name ? transport_name : ""); transport_name ? transport_name : "");
tor_asprintf(&bridge_description_old, "%s:%u:%s:%s", tor_asprintf(&bridge_description_old, "%s:%s:%s",
fmt_addr(&bridge->addr), bridge->port, fmt_addrport(&bridge->addr, bridge->port),
tor_digest_is_zero(bridge->identity) ? tor_digest_is_zero(bridge->identity) ?
"" : hex_str(bridge->identity,DIGEST_LEN), "" : hex_str(bridge->identity,DIGEST_LEN),
bridge->transport_name ? bridge->transport_name : ""); bridge->transport_name ? bridge->transport_name : "");
@ -5541,7 +5541,7 @@ launch_direct_bridge_descriptor_fetch(bridge_info_t *bridge)
if (routerset_contains_bridge(options->ExcludeNodes, bridge)) { if (routerset_contains_bridge(options->ExcludeNodes, bridge)) {
download_status_mark_impossible(&bridge->fetch_status); download_status_mark_impossible(&bridge->fetch_status);
log_warn(LD_APP, "Not using bridge at %s: it is in ExcludeNodes.", log_warn(LD_APP, "Not using bridge at %s: it is in ExcludeNodes.",
safe_str_client(fmt_addr(&bridge->addr))); safe_str_client(fmt_and_decorate_addr(&bridge->addr)));
return; return;
} }
@ -5594,7 +5594,7 @@ fetch_bridge_descriptors(const or_options_t *options, time_t now)
if (routerset_contains_bridge(options->ExcludeNodes, bridge)) { if (routerset_contains_bridge(options->ExcludeNodes, bridge)) {
download_status_mark_impossible(&bridge->fetch_status); download_status_mark_impossible(&bridge->fetch_status);
log_warn(LD_APP, "Not using bridge at %s: it is in ExcludeNodes.", log_warn(LD_APP, "Not using bridge at %s: it is in ExcludeNodes.",
safe_str_client(fmt_addr(&bridge->addr))); safe_str_client(fmt_and_decorate_addr(&bridge->addr)));
continue; continue;
} }
@ -5611,9 +5611,9 @@ fetch_bridge_descriptors(const or_options_t *options, time_t now)
if (ask_bridge_directly && if (ask_bridge_directly &&
!fascist_firewall_allows_address_or(&bridge->addr, bridge->port)) { !fascist_firewall_allows_address_or(&bridge->addr, bridge->port)) {
log_notice(LD_DIR, "Bridge at '%s:%d' isn't reachable by our " log_notice(LD_DIR, "Bridge at '%s' isn't reachable by our "
"firewall policy. %s.", fmt_addr(&bridge->addr), "firewall policy. %s.",
bridge->port, fmt_addrport(&bridge->addr, bridge->port),
can_use_bridge_authority ? can_use_bridge_authority ?
"Asking bridge authority instead" : "Skipping"); "Asking bridge authority instead" : "Skipping");
if (can_use_bridge_authority) if (can_use_bridge_authority)
@ -5683,8 +5683,8 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
ri->ipv6_orport = bridge->port; ri->ipv6_orport = bridge->port;
log_info(LD_DIR, log_info(LD_DIR,
"Adjusted bridge routerinfo for '%s' to match configured " "Adjusted bridge routerinfo for '%s' to match configured "
"address %s:%d.", "address %s.",
ri->nickname, fmt_addr(&ri->ipv6_addr), ri->ipv6_orport); ri->nickname, fmt_addrport(&ri->ipv6_addr, ri->ipv6_orport));
} else { } else {
log_err(LD_BUG, "Address family not supported: %d.", log_err(LD_BUG, "Address family not supported: %d.",
tor_addr_family(&bridge->addr)); tor_addr_family(&bridge->addr));
@ -5703,10 +5703,10 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
node_get_pref_orport(node, &ap); node_get_pref_orport(node, &ap);
log_notice(LD_CONFIG, log_notice(LD_CONFIG,
"Bridge '%s' has both an IPv4 and an IPv6 address. " "Bridge '%s' has both an IPv4 and an IPv6 address. "
"Will prefer using its %s address (%s:%d).", "Will prefer using its %s address (%s).",
ri->nickname, ri->nickname,
tor_addr_family(&ap.addr) == AF_INET6 ? "IPv6" : "IPv4", tor_addr_family(&ap.addr) == AF_INET6 ? "IPv6" : "IPv4",
fmt_addr(&ap.addr), ap.port); fmt_addrport(&ap.addr, ap.port));
} }
} }
if (node->rs) { if (node->rs) {
@ -5721,8 +5721,8 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
rs->or_port = bridge->port; rs->or_port = bridge->port;
log_info(LD_DIR, log_info(LD_DIR,
"Adjusted bridge routerstatus for '%s' to match " "Adjusted bridge routerstatus for '%s' to match "
"configured address %s:%d.", "configured address %s.",
rs->nickname, fmt_addr(&bridge->addr), rs->or_port); rs->nickname, fmt_addrport(&bridge->addr, rs->or_port));
} }
} }
} }

View file

@ -3957,8 +3957,8 @@ parse_bridge_line(const char *line, int validate_only)
} }
if (!validate_only) { if (!validate_only) {
log_debug(LD_DIR, "Bridge at %s:%d (transport: %s) (%s)", log_debug(LD_DIR, "Bridge at %s (transport: %s) (%s)",
fmt_addr(&addr), (int)port, fmt_addrport(&addr, port),
transport_name ? transport_name : "no transport", transport_name ? transport_name : "no transport",
fingerprint ? fingerprint : "no key listed"); fingerprint ? fingerprint : "no key listed");
bridge_add_from_config(&addr, port, bridge_add_from_config(&addr, port,
@ -4091,8 +4091,8 @@ parse_client_transport_line(const char *line, int validate_only)
transport_add_from_config(&addr, port, smartlist_get(transport_list, 0), transport_add_from_config(&addr, port, smartlist_get(transport_list, 0),
socks_ver); socks_ver);
log_info(LD_DIR, "Transport '%s' found at %s:%d", log_info(LD_DIR, "Transport '%s' found at %s",
transports, fmt_addr(&addr), (int)port); transports, fmt_addrport(&addr, port));
} }
} }
@ -4211,8 +4211,8 @@ parse_server_transport_line(const char *line, int validate_only)
} }
if (!validate_only) { if (!validate_only) {
log_info(LD_DIR, "Server transport '%s' at %s:%d.", log_info(LD_DIR, "Server transport '%s' at %s.",
transports, fmt_addr(&addr), (int)port); transports, fmt_addrport(&addr, port));
} }
} }
@ -4384,17 +4384,17 @@ warn_nonlocal_client_ports(const smartlist_t *ports, const char *portname)
if (port->is_unix_addr) { if (port->is_unix_addr) {
/* Unix sockets aren't accessible over a network. */ /* Unix sockets aren't accessible over a network. */
} else if (!tor_addr_is_internal(&port->addr, 1)) { } else if (!tor_addr_is_internal(&port->addr, 1)) {
log_warn(LD_CONFIG, "You specified a public address '%s:%d' for %sPort. " log_warn(LD_CONFIG, "You specified a public address '%s' for %sPort. "
"Other people on the Internet might find your computer and " "Other people on the Internet might find your computer and "
"use it as an open proxy. Please don't allow this unless you " "use it as an open proxy. Please don't allow this unless you "
"have a good reason.", "have a good reason.",
fmt_addr(&port->addr), port->port, portname); fmt_addrport(&port->addr, port->port), portname);
} else if (!tor_addr_is_loopback(&port->addr)) { } else if (!tor_addr_is_loopback(&port->addr)) {
log_notice(LD_CONFIG, "You configured a non-loopback address '%s:%d' " log_notice(LD_CONFIG, "You configured a non-loopback address '%s' "
"for %sPort. This allows everybody on your local network to " "for %sPort. This allows everybody on your local network to "
"use your machine as a proxy. Make sure this is what you " "use your machine as a proxy. Make sure this is what you "
"wanted.", "wanted.",
fmt_addr(&port->addr), port->port, portname); fmt_addrport(&port->addr, port->port), portname);
} }
} SMARTLIST_FOREACH_END(port); } SMARTLIST_FOREACH_END(port);
} }

View file

@ -916,8 +916,8 @@ connection_listener_new(const struct sockaddr *listensockaddr,
tor_addr_from_sockaddr(&addr, listensockaddr, &usePort); tor_addr_from_sockaddr(&addr, listensockaddr, &usePort);
log_notice(LD_NET, "Opening %s on %s:%d", log_notice(LD_NET, "Opening %s on %s",
conn_type_to_string(type), fmt_addr(&addr), usePort); conn_type_to_string(type), fmt_addrport(&addr, usePort));
s = tor_open_socket(tor_addr_family(&addr), s = tor_open_socket(tor_addr_family(&addr),
is_tcp ? SOCK_STREAM : SOCK_DGRAM, is_tcp ? SOCK_STREAM : SOCK_DGRAM,
@ -1232,7 +1232,7 @@ connection_handle_listener_read(connection_t *conn, int new_type)
if (socks_policy_permits_address(&addr) == 0) { if (socks_policy_permits_address(&addr) == 0) {
log_notice(LD_APP, log_notice(LD_APP,
"Denying socks connection from untrusted address %s.", "Denying socks connection from untrusted address %s.",
fmt_addr(&addr)); fmt_and_decorate_addr(&addr));
tor_close_socket(news); tor_close_socket(news);
return 0; return 0;
} }
@ -1241,7 +1241,7 @@ connection_handle_listener_read(connection_t *conn, int new_type)
/* check dirpolicy to see if we should accept it */ /* check dirpolicy to see if we should accept it */
if (dir_policy_permits_address(&addr) == 0) { if (dir_policy_permits_address(&addr) == 0) {
log_notice(LD_DIRSERV,"Denying dir connection from address %s.", log_notice(LD_DIRSERV,"Denying dir connection from address %s.",
fmt_addr(&addr)); fmt_and_decorate_addr(&addr));
tor_close_socket(news); tor_close_socket(news);
return 0; return 0;
} }
@ -1414,12 +1414,12 @@ connection_connect(connection_t *conn, const char *address,
if (ext_addr_len == 0) { if (ext_addr_len == 0) {
log_warn(LD_NET, log_warn(LD_NET,
"Error converting OutboundBindAddress %s into sockaddr. " "Error converting OutboundBindAddress %s into sockaddr. "
"Ignoring.", fmt_addr(ext_addr)); "Ignoring.", fmt_and_decorate_addr(ext_addr));
} else { } else {
if (bind(s, (struct sockaddr *) &ext_addr_sa, ext_addr_len) < 0) { if (bind(s, (struct sockaddr *) &ext_addr_sa, ext_addr_len) < 0) {
*socket_error = tor_socket_errno(s); *socket_error = tor_socket_errno(s);
log_warn(LD_NET,"Error binding network socket to %s: %s", log_warn(LD_NET,"Error binding network socket to %s: %s",
fmt_addr(ext_addr), fmt_and_decorate_addr(ext_addr),
tor_socket_strerror(*socket_error)); tor_socket_strerror(*socket_error));
tor_close_socket(s); tor_close_socket(s);
return -1; return -1;
@ -1530,17 +1530,17 @@ connection_proxy_connect(connection_t *conn, int type)
} }
if (base64_authenticator) { if (base64_authenticator) {
const char *addr = fmt_addr(&conn->addr); const char *addrport = fmt_addrport(&conn->addr, conn->port);
tor_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.1\r\n" tor_snprintf(buf, sizeof(buf), "CONNECT %s HTTP/1.1\r\n"
"Host: %s:%d\r\n" "Host: %s\r\n"
"Proxy-Authorization: Basic %s\r\n\r\n", "Proxy-Authorization: Basic %s\r\n\r\n",
addr, conn->port, addrport,
addr, conn->port, addrport,
base64_authenticator); base64_authenticator);
tor_free(base64_authenticator); tor_free(base64_authenticator);
} else { } else {
tor_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.0\r\n\r\n", tor_snprintf(buf, sizeof(buf), "CONNECT %s HTTP/1.0\r\n\r\n",
fmt_addr(&conn->addr), conn->port); fmt_addrport(&conn->addr, conn->port));
} }
connection_write_to_buf(buf, strlen(buf), conn); connection_write_to_buf(buf, strlen(buf), conn);
@ -4272,10 +4272,10 @@ log_failed_proxy_connection(connection_t *conn)
return; /* if we have no proxy set up, leave this function. */ return; /* if we have no proxy set up, leave this function. */
log_warn(LD_NET, log_warn(LD_NET,
"The connection to the %s proxy server at %s:%u just failed. " "The connection to the %s proxy server at %s just failed. "
"Make sure that the proxy server is up and running.", "Make sure that the proxy server is up and running.",
proxy_type_to_string(get_proxy_type()), fmt_addr(&proxy_addr), proxy_type_to_string(get_proxy_type()),
proxy_port); fmt_addrport(&proxy_addr, proxy_port));
} }
/** Return string representation of <b>proxy_type</b>. */ /** Return string representation of <b>proxy_type</b>. */

View file

@ -407,7 +407,7 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn)
log_info(LD_EXIT,"Exit connection to %s:%u (%s) established.", log_info(LD_EXIT,"Exit connection to %s:%u (%s) established.",
escaped_safe_str(conn->address), conn->port, escaped_safe_str(conn->address), conn->port,
safe_str(fmt_addr(&conn->addr))); safe_str(fmt_and_decorate_addr(&conn->addr)));
rep_hist_note_exit_stream_opened(conn->port); rep_hist_note_exit_stream_opened(conn->port);

View file

@ -1086,17 +1086,17 @@ connection_or_connect(const tor_addr_t *_addr, uint16_t port,
TO_CONN(conn)->port); TO_CONN(conn)->port);
if (transport_name) { if (transport_name) {
log_warn(LD_GENERAL, "We were supposed to connect to bridge '%s:%u' " log_warn(LD_GENERAL, "We were supposed to connect to bridge '%s' "
"using pluggable transport '%s', but we can't find a pluggable " "using pluggable transport '%s', but we can't find a pluggable "
"transport proxy supporting '%s'. This can happen if you " "transport proxy supporting '%s'. This can happen if you "
"haven't provided a ClientTransportPlugin line, or if " "haven't provided a ClientTransportPlugin line, or if "
"your pluggable transport proxy stopped running.", "your pluggable transport proxy stopped running.",
fmt_addr(&TO_CONN(conn)->addr), TO_CONN(conn)->port, fmt_addrport(&TO_CONN(conn)->addr, TO_CONN(conn)->port),
transport_name, transport_name); transport_name, transport_name);
} else { } else {
log_warn(LD_GENERAL, "Tried to connect to '%s:%u' through a proxy, but " log_warn(LD_GENERAL, "Tried to connect to '%s' through a proxy, but "
"the proxy address could not be found.", "the proxy address could not be found.",
fmt_addr(&TO_CONN(conn)->addr), TO_CONN(conn)->port); fmt_addrport(&TO_CONN(conn)->addr, TO_CONN(conn)->port));
} }
connection_free(TO_CONN(conn)); connection_free(TO_CONN(conn));

View file

@ -2118,11 +2118,9 @@ routerstatus_format_entry(char *buf, size_t buf_len,
/* Possible "a" line. At most one for now. */ /* Possible "a" line. At most one for now. */
if (!tor_addr_is_null(&rs->ipv6_addr)) { if (!tor_addr_is_null(&rs->ipv6_addr)) {
const char *addr_str = fmt_and_decorate_addr(&rs->ipv6_addr);
r = tor_snprintf(cp, buf_len - (cp-buf), r = tor_snprintf(cp, buf_len - (cp-buf),
"a %s:%d\n", "a %s\n",
addr_str, fmt_addrport(&rs->ipv6_addr, rs->ipv6_orport));
(int)rs->ipv6_orport);
if (r<0) { if (r<0) {
log_warn(LD_BUG, "Not enough space in buffer."); log_warn(LD_BUG, "Not enough space in buffer.");
return -1; return -1;

View file

@ -489,10 +489,9 @@ compute_routerstatus_consensus(smartlist_t *votes, int consensus_method,
_compare_orports); _compare_orports);
if (most_alt_orport) { if (most_alt_orport) {
memcpy(best_alt_orport_out, most_alt_orport, sizeof(tor_addr_port_t)); memcpy(best_alt_orport_out, most_alt_orport, sizeof(tor_addr_port_t));
log_debug(LD_DIR, "\"a\" line winner for %s is %s:%d", log_debug(LD_DIR, "\"a\" line winner for %s is %s",
most->status.nickname, most->status.nickname,
fmt_and_decorate_addr(&most_alt_orport->addr), fmt_addrport(&most_alt_orport->addr, most_alt_orport->port));
most_alt_orport->port);
} }
SMARTLIST_FOREACH(alt_orports, tor_addr_port_t *, ap, tor_free(ap)); SMARTLIST_FOREACH(alt_orports, tor_addr_port_t *, ap, tor_free(ap));
@ -3561,9 +3560,8 @@ dirvote_create_microdescriptor(const routerinfo_t *ri, int consensus_method)
if (consensus_method >= MIN_METHOD_FOR_A_LINES && if (consensus_method >= MIN_METHOD_FOR_A_LINES &&
!tor_addr_is_null(&ri->ipv6_addr) && ri->ipv6_orport) !tor_addr_is_null(&ri->ipv6_addr) && ri->ipv6_orport)
smartlist_add_asprintf(chunks, "a %s:%d\n", smartlist_add_asprintf(chunks, "a %s\n",
fmt_and_decorate_addr(&ri->ipv6_addr), fmt_addrport(&ri->ipv6_addr, ri->ipv6_orport));
ri->ipv6_orport);
if (family) if (family)
smartlist_add_asprintf(chunks, "family %s\n", family); smartlist_add_asprintf(chunks, "family %s\n", family);

View file

@ -272,8 +272,8 @@ rend_add_service(rend_service_t *service)
service->directory); service->directory);
for (i = 0; i < smartlist_len(service->ports); ++i) { for (i = 0; i < smartlist_len(service->ports); ++i) {
p = smartlist_get(service->ports, i); p = smartlist_get(service->ports, i);
log_debug(LD_REND,"Service maps port %d to %s:%d", log_debug(LD_REND,"Service maps port %d to %s",
p->virtual_port, fmt_addr(&p->real_addr), p->real_port); p->virtual_port, fmt_addrport(&p->real_addr, p->real_port));
} }
} }
} }

View file

@ -553,7 +553,7 @@ save_transport_to_state(const char *transport,
if (transport_line) { /* if transport already exists in state... */ if (transport_line) { /* if transport already exists in state... */
const char *prev_bindaddr = /* get its addrport... */ const char *prev_bindaddr = /* get its addrport... */
get_transport_bindaddr(transport_line->value, transport); get_transport_bindaddr(transport_line->value, transport);
tor_asprintf(&transport_addrport, "%s:%d", fmt_addr(addr), (int)port); transport_addrport = tor_strdup(fmt_addrport(addr, port));
/* if transport in state has the same address as this one, life is good */ /* if transport in state has the same address as this one, life is good */
if (!strcmp(prev_bindaddr, transport_addrport)) { if (!strcmp(prev_bindaddr, transport_addrport)) {
@ -565,9 +565,9 @@ save_transport_to_state(const char *transport,
"address:port. Let's update the state file with the new " "address:port. Let's update the state file with the new "
"address:port"); "address:port");
tor_free(transport_line->value); /* free the old line */ tor_free(transport_line->value); /* free the old line */
tor_asprintf(&transport_line->value, "%s %s:%d", transport, /* replace old addrport line with new line */
fmt_addr(addr), tor_asprintf(&transport_line->value, "%s %s", transport,
(int) port); /* replace old addrport line with new line */ fmt_addrport(addr, port));
} }
} else { /* never seen this one before; save it in state for next time */ } else { /* never seen this one before; save it in state for next time */
log_info(LD_CONFIG, "It's the first time we see this transport. " log_info(LD_CONFIG, "It's the first time we see this transport. "
@ -584,8 +584,7 @@ save_transport_to_state(const char *transport,
/* allocate space for the new line and fill it in */ /* allocate space for the new line and fill it in */
*next = line = tor_malloc_zero(sizeof(config_line_t)); *next = line = tor_malloc_zero(sizeof(config_line_t));
line->key = tor_strdup("TransportProxy"); line->key = tor_strdup("TransportProxy");
tor_asprintf(&line->value, "%s %s:%d", transport, tor_asprintf(&line->value, "%s %s", transport, fmt_addrport(addr, port));
fmt_addr(addr), (int) port);
next = &(line->next); next = &(line->next);
} }

View file

@ -270,24 +270,26 @@ transport_resolve_conflicts(const transport_t *t)
t_tmp->marked_for_removal = 0; t_tmp->marked_for_removal = 0;
return 1; return 1;
} else { /* same name but different addrport */ } else { /* same name but different addrport */
char *new_transport_addr = tor_strdup(fmt_addr(&t->addr)); char *new_transport_addrport =
tor_strdup(fmt_addrport(&t->addr, t->port));
if (t_tmp->marked_for_removal) { /* marked for removal */ if (t_tmp->marked_for_removal) { /* marked for removal */
log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s:%u' " log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s' "
"but there was already a transport marked for deletion at " "but there was already a transport marked for deletion at "
"'%s:%u'. We deleted the old transport and registered the " "'%s'. We deleted the old transport and registered the "
"new one.", t->name, new_transport_addr, t->port, "new one.", t->name, new_transport_addrport,
fmt_addr(&t_tmp->addr), t_tmp->port); fmt_addrport(&t_tmp->addr, t_tmp->port));
smartlist_remove(transport_list, t_tmp); smartlist_remove(transport_list, t_tmp);
transport_free(t_tmp); transport_free(t_tmp);
tor_free(new_transport_addr); tor_free(new_transport_addrport);
} else { /* *not* marked for removal */ } else { /* *not* marked for removal */
log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s:%u' " log_notice(LD_GENERAL, "You tried to add transport '%s' at '%s' "
"but the same transport already exists at '%s:%u'. " "but the same transport already exists at '%s'. "
"Skipping.", t->name, new_transport_addr, t->port, "Skipping.", t->name, new_transport_addrport,
fmt_addr(&t_tmp->addr), t_tmp->port); fmt_addrport(&t_tmp->addr, t_tmp->port));
tor_free(new_transport_addr); tor_free(new_transport_addrport);
return -1; return -1;
} }
tor_free(new_transport_addrport);
} }
} }
@ -332,18 +334,18 @@ transport_add_from_config(const tor_addr_t *addr, uint16_t port,
switch (r) { switch (r) {
case -1: case -1:
default: default:
log_notice(LD_GENERAL, "Could not add transport %s at %s:%u. Skipping.", log_notice(LD_GENERAL, "Could not add transport %s at %s. Skipping.",
t->name, fmt_addr(&t->addr), t->port); t->name, fmt_addrport(&t->addr, t->port));
transport_free(t); transport_free(t);
return -1; return -1;
case 1: case 1:
log_info(LD_GENERAL, "Succesfully registered transport %s at %s:%u.", log_info(LD_GENERAL, "Succesfully registered transport %s at %s.",
t->name, fmt_addr(&t->addr), t->port); t->name, fmt_addrport(&t->addr, t->port));
transport_free(t); /* falling */ transport_free(t); /* falling */
return 0; return 0;
case 0: case 0:
log_info(LD_GENERAL, "Succesfully registered transport %s at %s:%u.", log_info(LD_GENERAL, "Succesfully registered transport %s at %s.",
t->name, fmt_addr(&t->addr), t->port); t->name, fmt_addrport(&t->addr, t->port));
return 0; return 0;
} }
} }
@ -644,8 +646,8 @@ register_server_proxy(const managed_proxy_t *mp)
SMARTLIST_FOREACH_BEGIN(mp->transports, transport_t *, t) { SMARTLIST_FOREACH_BEGIN(mp->transports, transport_t *, t) {
save_transport_to_state(t->name, &t->addr, t->port); save_transport_to_state(t->name, &t->addr, t->port);
log_notice(LD_GENERAL, "Registered server transport '%s' at '%s:%d'", log_notice(LD_GENERAL, "Registered server transport '%s' at '%s'",
t->name, fmt_addr(&t->addr), (int)t->port); t->name, fmt_addrport(&t->addr, t->port));
} SMARTLIST_FOREACH_END(t); } SMARTLIST_FOREACH_END(t);
} }
@ -1382,19 +1384,21 @@ pt_get_extra_info_descriptor_string(void)
/* If the transport proxy returned "0.0.0.0" as its address, and /* If the transport proxy returned "0.0.0.0" as its address, and
* we know our external IP address, use it. Otherwise, use the * we know our external IP address, use it. Otherwise, use the
* returned address. */ * returned address. */
const char *addr_str = fmt_addr(&t->addr); const char *addrport = NULL;
uint32_t external_ip_address = 0; uint32_t external_ip_address = 0;
if (tor_addr_is_null(&t->addr) && if (tor_addr_is_null(&t->addr) &&
router_pick_published_address(get_options(), router_pick_published_address(get_options(),
&external_ip_address) >= 0) { &external_ip_address) >= 0) {
/* returned addr was 0.0.0.0 and we found our external IP tor_addr_t addr;
address: use it. */ tor_addr_from_ipv4h(&addr, external_ip_address);
addr_str = fmt_addr32(external_ip_address); addrport = fmt_addrport(&addr, t->port);
} else {
addrport = fmt_addrport(&t->addr, t->port);
} }
smartlist_add_asprintf(string_chunks, smartlist_add_asprintf(string_chunks,
"transport %s %s:%u", "transport %s %s",
t->name, addr_str, t->port); t->name, addrport);
} SMARTLIST_FOREACH_END(t); } SMARTLIST_FOREACH_END(t);
} SMARTLIST_FOREACH_END(mp); } SMARTLIST_FOREACH_END(mp);