Remove "ADDR_ONLY" mode from channel_get_*_remote_descr.

This mode was only used in one place, and it caused a dangerous
mingling of functionality.  The method is supposed to _describe_ the
peer's address, not give its actual address.  We already had a
function to get the actual address.
This commit is contained in:
Nick Mathewson 2020-07-14 14:08:55 -04:00
parent 0ccdf05dc5
commit db21e91f4b
4 changed files with 7 additions and 32 deletions

View file

@ -2801,19 +2801,6 @@ channel_get_actual_remote_descr(channel_t *chan)
return chan->get_remote_descr(chan, GRD_FLAG_ORIGINAL);
}
/**
* Return the text address of the remote endpoint.
*
* Subsequent calls to channel_get_{actual,canonical}_remote_{address,descr}
* may invalidate the return value from this function.
*/
const char *
channel_get_actual_remote_address(channel_t *chan)
{
/* Param 1 indicates the actual description */
return chan->get_remote_descr(chan, GRD_FLAG_ORIGINAL|GRD_FLAG_ADDR_ONLY);
}
/**
* Return text description of the remote endpoint canonical address.
*

View file

@ -337,12 +337,10 @@ struct channel_t {
int (*get_transport_name)(channel_t *chan, char **transport_out);
#define GRD_FLAG_ORIGINAL 1
#define GRD_FLAG_ADDR_ONLY 2
/**
* Get a text description of the remote endpoint; canonicalized if the flag
* GRD_FLAG_ORIGINAL is not set, or the one we originally connected
* to/received from if it is. If GRD_FLAG_ADDR_ONLY is set, we return only
* the original address.
* to/received from if it is.
*/
const char * (*get_remote_descr)(channel_t *, int);
/** Check if the lower layer has queued writes */
@ -723,7 +721,6 @@ const char * channel_describe_transport(channel_t *chan);
MOCK_DECL(void, channel_dump_statistics, (channel_t *chan, int severity));
void channel_dump_transport_statistics(channel_t *chan, int severity);
const char * channel_get_actual_remote_descr(channel_t *chan);
const char * channel_get_actual_remote_address(channel_t *chan);
MOCK_DECL(int, channel_get_addr_if_possible, (const channel_t *chan,
tor_addr_t *addr_out));
MOCK_DECL(const char *, channel_get_canonical_remote_descr,(channel_t *chan));

View file

@ -601,18 +601,6 @@ channel_tls_get_remote_descr_method(channel_t *chan, int flags)
tor_free(addr_str);
answer = buf;
break;
case GRD_FLAG_ADDR_ONLY:
/* Canonical address, no port */
strlcpy(buf, conn->address, sizeof(buf));
answer = buf;
break;
case GRD_FLAG_ORIGINAL|GRD_FLAG_ADDR_ONLY:
/* Actual address, no port */
addr_str = tor_addr_to_str_dup(&(tlschan->conn->real_addr));
strlcpy(buf, addr_str, sizeof(buf));
tor_free(addr_str);
answer = buf;
break;
default:
/* Something's broken in channel.c */
tor_assert_nonfatal_unreached_once();

View file

@ -3996,10 +3996,13 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
* caller might want to know whether the remote IP address has changed,
* and we might already have corrected base_.addr[ess] for the relay's
* canonical IP address. */
if (or_circ && or_circ->p_chan)
address = tor_strdup(channel_get_actual_remote_address(or_circ->p_chan));
else
tor_addr_t chan_addr;
if (or_circ && or_circ->p_chan &&
channel_get_addr_if_possible(or_circ->p_chan, &chan_addr)) {
address = tor_addr_to_str_dup(&chan_addr);
} else {
address = tor_strdup("127.0.0.1");
}
port = 1; /* XXXX This value is never actually used anywhere, and there
* isn't "really" a connection here. But we
* need to set it to something nonzero. */