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

[tor-commits] [tor/master] ipv6: Specialize GETINFO address interface for v4 and v6



commit d1413e04f89213b7eb0ee844491148e7cf7ca45b
Author: Neel Chauhan <neel@xxxxxxxxx>
Date:   Tue Aug 4 13:59:49 2020 -0700

    ipv6: Specialize GETINFO address interface for v4 and v6
---
 changes/ticket40039                   |  5 +++++
 src/feature/control/control_getinfo.c | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/changes/ticket40039 b/changes/ticket40039
new file mode 100644
index 0000000000..41b34c6407
--- /dev/null
+++ b/changes/ticket40039
@@ -0,0 +1,5 @@
+  o Minor features (control port, relay):
+    - Introduce "GETINFO address/v4" and "GETINFO address/v6" in the control
+      port to fetch the Tor host's respective IPv4 or IPv6 address. We keep
+      "GETINFO address" for backwords-compatibility which retains the current
+      behavior. Closes ticket 40039. Patch by Neel Chauhan.
diff --git a/src/feature/control/control_getinfo.c b/src/feature/control/control_getinfo.c
index 3e4feadded..461b8eeb94 100644
--- a/src/feature/control/control_getinfo.c
+++ b/src/feature/control/control_getinfo.c
@@ -131,7 +131,7 @@ getinfo_helper_misc(control_connection_t *conn, const char *question,
     smartlist_free(signal_names);
   } else if (!strcmp(question, "features/names")) {
     *answer = tor_strdup("VERBOSE_NAMES EXTENDED_EVENTS");
-  } else if (!strcmp(question, "address")) {
+  } else if (!strcmp(question, "address") || !strcmp(question, "address/v4")) {
     tor_addr_t addr;
     if (!relay_find_addr_to_publish(get_options(), AF_INET,
                                     RELAY_FIND_ADDR_CACHE_ONLY, &addr)) {
@@ -140,6 +140,15 @@ getinfo_helper_misc(control_connection_t *conn, const char *question,
     }
     *answer = tor_addr_to_str_dup(&addr);
     tor_assert_nonfatal(*answer);
+  } else if (!strcmp(question, "address/v6")) {
+    tor_addr_t addr;
+    if (!relay_find_addr_to_publish(get_options(), AF_INET6,
+                                    RELAY_FIND_ADDR_CACHE_ONLY, &addr)) {
+      *errmsg = "Address unknown";
+      return -1;
+    }
+    *answer = tor_addr_to_str_dup(&addr);
+    tor_assert_nonfatal(*answer);
   } else if (!strcmp(question, "traffic/read")) {
     tor_asprintf(answer, "%"PRIu64, (get_bytes_read()));
   } else if (!strcmp(question, "traffic/written")) {
@@ -1663,6 +1672,10 @@ static const getinfo_item_t getinfo_items[] = {
   DOC("status/version/recommended", "List of currently recommended versions."),
   DOC("status/version/current", "Status of the current version."),
   ITEM("address", misc, "IP address of this Tor host, if we can guess it."),
+  ITEM("address/v4", misc,
+       "IPv4 address of this Tor host, if we can guess it."),
+  ITEM("address/v6", misc,
+       "IPv6 address of this Tor host, if we can guess it."),
   ITEM("traffic/read", misc,"Bytes read since the process was started."),
   ITEM("traffic/written", misc,
        "Bytes written since the process was started."),



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