Merge branch 'bug40249_squashed'

This commit is contained in:
Nick Mathewson 2021-02-08 10:31:30 -05:00
commit 90add50550
10 changed files with 53 additions and 25 deletions

3
changes/ticket40249 Normal file
View File

@ -0,0 +1,3 @@
o Minor features (control port, stream handling):
- Add the stream ID argument to the event line in the ADDRMAP control
event. Closes ticket 40249. Patch by Neel Chauhan.

View File

@ -4826,7 +4826,7 @@ addressmap_register_auto(const char *from, const char *to,
}
addressmap_register(from, tor_strdup(to), expires, addrmap_source,
from_wildcard, to_wildcard);
from_wildcard, to_wildcard, 0);
return 0;
}

View File

@ -2733,6 +2733,11 @@ consider_recording_trackhost(const entry_connection_t *conn,
const or_options_t *options = get_options();
char *new_address = NULL;
char fp[HEX_DIGEST_LEN+1];
uint64_t stream_id = 0;
if (conn) {
stream_id = ENTRY_TO_CONN(conn)->global_identifier;
}
/* Search the addressmap for this conn's destination. */
/* If they're not in the address map.. */
@ -2756,7 +2761,7 @@ consider_recording_trackhost(const entry_connection_t *conn,
addressmap_register(conn->socks_request->address, new_address,
time(NULL) + options->TrackHostExitsExpire,
ADDRMAPSRC_TRACKEXIT, 0, 0);
ADDRMAPSRC_TRACKEXIT, 0, 0, stream_id);
}
/** Attempt to attach the connection <b>conn</b> to <b>circ</b>, and send a

View File

@ -3519,22 +3519,28 @@ tell_controller_about_resolved_result(entry_connection_t *conn,
int ttl,
time_t expires)
{
uint64_t stream_id = 0;
if (conn) {
stream_id = ENTRY_TO_CONN(conn)->global_identifier;
}
expires = time(NULL) + ttl;
if (answer_type == RESOLVED_TYPE_IPV4 && answer_len >= 4) {
char *cp = tor_dup_ip(ntohl(get_uint32(answer)));
if (cp)
control_event_address_mapped(conn->socks_request->address,
cp, expires, NULL, 0);
cp, expires, NULL, 0, stream_id);
tor_free(cp);
} else if (answer_type == RESOLVED_TYPE_HOSTNAME && answer_len < 256) {
char *cp = tor_strndup(answer, answer_len);
control_event_address_mapped(conn->socks_request->address,
cp, expires, NULL, 0);
cp, expires, NULL, 0, stream_id);
tor_free(cp);
} else {
control_event_address_mapped(conn->socks_request->address,
"<error>", time(NULL)+ttl,
"error=yes", 0);
"error=yes", 0, stream_id);
}
}

View File

@ -576,7 +576,7 @@ void
addressmap_register(const char *address, char *new_address, time_t expires,
addressmap_entry_source_t source,
const int wildcard_addr,
const int wildcard_new_addr)
const int wildcard_new_addr, uint64_t stream_id)
{
addressmap_entry_t *ent;
@ -626,7 +626,8 @@ addressmap_register(const char *address, char *new_address, time_t expires,
log_info(LD_CONFIG, "Addressmap: (re)mapped '%s' to '%s'",
safe_str_client(address),
safe_str_client(ent->new_address));
control_event_address_mapped(address, ent->new_address, expires, NULL, 1);
control_event_address_mapped(address, ent->new_address,
expires, NULL, 1, stream_id);
}
/** An attempt to resolve <b>address</b> failed at some OR.
@ -680,11 +681,15 @@ client_dns_set_addressmap_impl(entry_connection_t *for_conn,
int ttl)
{
char *extendedaddress=NULL, *extendedval=NULL;
(void)for_conn;
uint64_t stream_id = 0;
tor_assert(address);
tor_assert(name);
if (for_conn) {
stream_id = ENTRY_TO_CONN(for_conn)->global_identifier;
}
if (ttl<0)
ttl = DEFAULT_DNS_TTL;
else
@ -705,7 +710,7 @@ client_dns_set_addressmap_impl(entry_connection_t *for_conn,
"%s", name);
}
addressmap_register(extendedaddress, extendedval,
time(NULL) + ttl, ADDRMAPSRC_DNS, 0, 0);
time(NULL) + ttl, ADDRMAPSRC_DNS, 0, 0, stream_id);
tor_free(extendedaddress);
}
@ -1043,7 +1048,7 @@ addressmap_register_virtual_address(int type, char *new_address)
log_info(LD_APP, "Registering map from %s to %s", *addrp, new_address);
if (vent_needs_to_be_added)
strmap_set(virtaddress_reversemap, new_address, vent);
addressmap_register(*addrp, new_address, 2, ADDRMAPSRC_AUTOMAP, 0, 0);
addressmap_register(*addrp, new_address, 2, ADDRMAPSRC_AUTOMAP, 0, 0, 0);
/* FFFF register corresponding reverse mapping. */

View File

@ -36,7 +36,7 @@ int addressmap_have_mapping(const char *address, int update_timeout);
void addressmap_register(const char *address, char *new_address,
time_t expires, addressmap_entry_source_t source,
const int address_wildcard,
const int new_address_wildcard);
const int new_address_wildcard, uint64_t stream_id);
int parse_virtual_addr_network(const char *val,
sa_family_t family, int validate_only,
char **msg);

View File

@ -1233,7 +1233,7 @@ handle_control_resolve(control_connection_t *conn,
send_control_done(conn);
SMARTLIST_FOREACH(failed, const char *, arg, {
control_event_address_mapped(arg, arg, time(NULL),
"internal", 0);
"internal", 0, 0);
});
smartlist_free(failed);

View File

@ -1477,31 +1477,40 @@ control_event_descriptors_changed(smartlist_t *routers)
* mode of the mapping.
*/
int
control_event_address_mapped(const char *from, const char *to, time_t expires,
const char *error, const int cached)
control_event_address_mapped(const char *from, const char *to,
time_t expires, const char *error,
const int cached, uint64_t stream_id)
{
char *stream_id_str = NULL;
if (!EVENT_IS_INTERESTING(EVENT_ADDRMAP))
return 0;
if (stream_id) {
tor_asprintf(&stream_id_str, " STREAMID=%"PRIu64"", stream_id);
}
if (expires < 3 || expires == TIME_MAX)
send_control_event(EVENT_ADDRMAP,
"650 ADDRMAP %s %s NEVER %s%s"
"CACHED=\"%s\"\r\n",
from, to, error?error:"", error?" ":"",
cached?"YES":"NO");
"CACHED=\"%s\"%s\r\n",
from, to, error ? error : "", error ? " " : "",
cached ? "YES" : "NO",
stream_id ? stream_id_str : "");
else {
char buf[ISO_TIME_LEN+1];
char buf2[ISO_TIME_LEN+1];
format_local_iso_time(buf,expires);
format_iso_time(buf2,expires);
send_control_event(EVENT_ADDRMAP,
"650 ADDRMAP %s %s \"%s\""
" %s%sEXPIRES=\"%s\" CACHED=\"%s\"\r\n",
from, to, buf,
error?error:"", error?" ":"",
buf2, cached?"YES":"NO");
"650 ADDRMAP %s %s \"%s\" %s%sEXPIRES=\"%s\" "
"CACHED=\"%s\"%s\r\n",
from, to, buf, error ? error : "",
error ? " " : "", buf2, cached ? "YES" : "NO",
stream_id ? stream_id_str: "");
}
tor_free(stream_id_str);
return 0;
}
/** The network liveness has changed; this is called from circuitstats.c

View File

@ -137,7 +137,7 @@ void control_event_logmsg_pending(void);
int control_event_descriptors_changed(smartlist_t *routers);
int control_event_address_mapped(const char *from, const char *to,
time_t expires, const char *error,
const int cached);
const int cached, uint64_t stream_id);
int control_event_my_descriptor_changed(void);
int control_event_network_liveness_update(int liveness);
int control_event_networkstatus_changed(smartlist_t *statuses);

View File

@ -307,7 +307,7 @@ test_entryconn_rewrite_cached_dns_ipv4(void *arg)
tor_strdup("240.240.241.241"),
expires,
ADDRMAPSRC_DNS,
0, 0);
0, 0, 0);
strlcpy(ec->socks_request->address, "www.friendly.example.com",
sizeof(ec->socks_request->address));
@ -359,7 +359,7 @@ test_entryconn_rewrite_cached_dns_ipv6(void *arg)
tor_strdup("[::f00f]"),
expires,
ADDRMAPSRC_DNS,
0, 0);
0, 0, 0);
strlcpy(ec->socks_request->address, "www.friendly.example.com",
sizeof(ec->socks_request->address));