[tor-commits] [tor/master] Implement a PreferIPv6 flag for SocksPorts

nickm at torproject.org nickm at torproject.org
Thu Nov 15 19:47:53 UTC 2012


commit 363cf024553741524c0c8cb9fa8b9226863c903b
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Nov 14 10:09:06 2012 -0500

    Implement a PreferIPv6 flag for SocksPorts
---
 src/or/config.c          |    6 +++++-
 src/or/connection.c      |    2 ++
 src/or/connection_edge.c |    7 +++++++
 src/or/or.h              |    7 +++++++
 4 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 98fbb6e..e069c7c 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -4605,7 +4605,7 @@ parse_port_config(smartlist_t *out,
     int ok;
     int no_listen = 0, no_advertise = 0, all_addrs = 0,
       bind_ipv4_only = 0, bind_ipv6_only = 0,
-      ipv4_traffic = 1, ipv6_traffic = 0;
+      ipv4_traffic = 1, ipv6_traffic = 0, prefer_ipv6 = 0;
 
     smartlist_split_string(elts, ports->value, NULL,
                            SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@@ -4737,6 +4737,9 @@ parse_port_config(smartlist_t *out,
           } else if (!strcasecmp(elt, "IPv6Traffic")) {
             ipv6_traffic = ! no;
             continue;
+          } else if (!strcasecmp(elt, "PreferIPv6")) {
+            prefer_ipv6 = ! no;
+            continue;
           }
         }
 
@@ -4785,6 +4788,7 @@ parse_port_config(smartlist_t *out,
       cfg->bind_ipv6_only = bind_ipv6_only;
       cfg->ipv4_traffic = ipv4_traffic;
       cfg->ipv6_traffic = ipv6_traffic;
+      cfg->prefer_ipv6 = prefer_ipv6;
 
       smartlist_add(out, cfg);
     }
diff --git a/src/or/connection.c b/src/or/connection.c
index 89ac8f5..ecfb8a9 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -1118,6 +1118,7 @@ connection_listener_new(const struct sockaddr *listensockaddr,
   if (type == CONN_TYPE_AP) {
     lis_conn->socks_ipv4_traffic = port_cfg->ipv4_traffic;
     lis_conn->socks_ipv6_traffic = port_cfg->ipv6_traffic;
+    lis_conn->socks_prefer_ipv6 = port_cfg->prefer_ipv6;
   } else {
     lis_conn->socks_ipv4_traffic = 1;
     lis_conn->socks_ipv6_traffic = 1;
@@ -1357,6 +1358,7 @@ connection_init_accepted_conn(connection_t *conn,
       TO_ENTRY_CONN(conn)->socks_request->listener_type = listener->base_.type;
       TO_ENTRY_CONN(conn)->ipv4_traffic_ok = listener->socks_ipv4_traffic;
       TO_ENTRY_CONN(conn)->ipv6_traffic_ok = listener->socks_ipv6_traffic;
+      TO_ENTRY_CONN(conn)->prefer_ipv6_traffic = listener->socks_prefer_ipv6;
       switch (TO_CONN(listener)->type) {
         case CONN_TYPE_AP_LISTENER:
           conn->state = AP_CONN_STATE_SOCKS_WAIT;
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 758d8f5..4f3dda2 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -1682,6 +1682,13 @@ connection_ap_get_begincell_flags(entry_connection_t *ap_conn)
     }
   }
 
+  if (flags == BEGIN_FLAG_IPV6_OK) {
+    /* When IPv4 and IPv6 are both allowed, consider whether to say we
+     * prefer IPv6.  Otherwise there's no point in declaring a preference */
+    if (ap_conn->prefer_ipv6_traffic)
+      flags |= BEGIN_FLAG_IPV6_PREFERRED;
+  }
+
   if (flags == BEGIN_FLAG_IPV4_NOT_OK) {
     log_warn(LD_BUG, "Hey; I'm about to ask a node for a connection that I "
              "am telling it to fulfil with neither IPv4 nor IPv6. That's "
diff --git a/src/or/or.h b/src/or/or.h
index f22c7df..4566f91 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1233,6 +1233,10 @@ typedef struct listener_connection_t {
   unsigned int socks_ipv4_traffic : 1;
   unsigned int socks_ipv6_traffic : 1;
   /** @} */
+  /** For a socks listener: should we tell the exit that we prefer IPv6
+   * addresses? */
+  unsigned int socks_prefer_ipv6 : 1;
+
 
 } listener_connection_t;
 
@@ -1539,6 +1543,8 @@ typedef struct entry_connection_t {
   unsigned int ipv4_traffic_ok : 1;
   unsigned int ipv6_traffic_ok : 1;
   /** @} */
+  /** Should we say we prefer IPv6 traffic? */
+  unsigned int prefer_ipv6_traffic : 1;
 
 } entry_connection_t;
 
@@ -3064,6 +3070,7 @@ typedef struct port_cfg_t {
   unsigned int bind_ipv6_only : 1;
   unsigned int ipv4_traffic : 1;
   unsigned int ipv6_traffic : 1;
+  unsigned int prefer_ipv6 : 1;
 
   /* Unix sockets only: */
   /** Path for an AF_UNIX address */





More information about the tor-commits mailing list