diff options
author | Neel Chauhan <neel@neelc.org> | 2021-01-19 14:51:00 -0800 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2021-02-08 10:23:41 -0500 |
commit | 2391c60c5c89b104572323a439e3560a09c1a6e2 (patch) | |
tree | 09374510094b2f87717c1535272db4409474deea /src/feature | |
parent | b0af4ddc7c2fe80a79e41e31b7050d949561e044 (diff) | |
download | tor-2391c60c5c89b104572323a439e3560a09c1a6e2.tar.gz tor-2391c60c5c89b104572323a439e3560a09c1a6e2.zip |
Add stream ID to ADDRMAP control event
Diffstat (limited to 'src/feature')
-rw-r--r-- | src/feature/client/addressmap.c | 15 | ||||
-rw-r--r-- | src/feature/client/addressmap.h | 2 | ||||
-rw-r--r-- | src/feature/control/control_cmd.c | 2 | ||||
-rw-r--r-- | src/feature/control/control_events.c | 29 | ||||
-rw-r--r-- | src/feature/control/control_events.h | 2 |
5 files changed, 32 insertions, 18 deletions
diff --git a/src/feature/client/addressmap.c b/src/feature/client/addressmap.c index e5bf2cc49c..316fb7ceaa 100644 --- a/src/feature/client/addressmap.c +++ b/src/feature/client/addressmap.c @@ -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. */ diff --git a/src/feature/client/addressmap.h b/src/feature/client/addressmap.h index 7f1024e09a..681abb714a 100644 --- a/src/feature/client/addressmap.h +++ b/src/feature/client/addressmap.h @@ -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); diff --git a/src/feature/control/control_cmd.c b/src/feature/control/control_cmd.c index 5b75c24692..17d9280200 100644 --- a/src/feature/control/control_cmd.c +++ b/src/feature/control/control_cmd.c @@ -1232,7 +1232,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); diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index 0dd52659ec..6648ffeecd 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -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 diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h index 0ac233cc6e..e499c037ba 100644 --- a/src/feature/control/control_events.h +++ b/src/feature/control/control_events.h @@ -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); |