[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Add stream ID to ADDRMAP control event



commit 2391c60c5c89b104572323a439e3560a09c1a6e2
Author: Neel Chauhan <neel@xxxxxxxxx>
Date:   Tue Jan 19 14:51:00 2021 -0800

    Add stream ID to ADDRMAP control event
---
 changes/ticket40249                  |  3 +++
 src/app/config/config.c              |  2 +-
 src/core/or/circuituse.c             |  7 ++++++-
 src/core/or/connection_edge.c        | 12 +++++++++---
 src/feature/client/addressmap.c      | 15 ++++++++++-----
 src/feature/client/addressmap.h      |  2 +-
 src/feature/control/control_cmd.c    |  2 +-
 src/feature/control/control_events.c | 29 +++++++++++++++++++----------
 src/feature/control/control_events.h |  2 +-
 src/test/test_entryconn.c            |  4 ++--
 10 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/changes/ticket40249 b/changes/ticket40249
new file mode 100644
index 0000000000..11c40bc5a3
--- /dev/null
+++ b/changes/ticket40249
@@ -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.
diff --git a/src/app/config/config.c b/src/app/config/config.c
index bf2f49ead4..40071cb093 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -4841,7 +4841,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;
 }
diff --git a/src/core/or/circuituse.c b/src/core/or/circuituse.c
index 0f3fc29361..018654769d 100644
--- a/src/core/or/circuituse.c
+++ b/src/core/or/circuituse.c
@@ -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
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index b2390e4f04..e605b5f4e1 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -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);
   }
 }
 
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);
diff --git a/src/test/test_entryconn.c b/src/test/test_entryconn.c
index 9cdd7f6d0e..6a8603cbf8 100644
--- a/src/test/test_entryconn.c
+++ b/src/test/test_entryconn.c
@@ -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));



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits