]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Implement a PreferIPv6 flag for SocksPorts
authorNick Mathewson <nickm@torproject.org>
Wed, 14 Nov 2012 15:09:06 +0000 (10:09 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 15 Nov 2012 04:16:40 +0000 (23:16 -0500)
src/or/config.c
src/or/connection.c
src/or/connection_edge.c
src/or/or.h

index 98fbb6e585a5ec81f2e705641f2d70cacb13f30d..e069c7c528b579a2329f761a2c91a75532a8fe3c 100644 (file)
@@ -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);
     }
index 89ac8f5e7c361390b985d47b7ccdc617fc4bac02..ecfb8a930eb484f74bf42167dec8ea970347cfd0 100644 (file)
@@ -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;
index 758d8f5d876f2bc2667dfc4c8c0096c8035af12b..4f3dda2842024d867bbc0a68405e07e36c4639a8 100644 (file)
@@ -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 "
index f22c7dffbaae86b0de54011435a5a9b6f4f752dc..4566f9152acee275a9fd742a8c60df972d9c8b26 100644 (file)
@@ -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 */