diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-11-14 10:09:06 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-11-14 23:16:40 -0500 |
commit | 363cf024553741524c0c8cb9fa8b9226863c903b (patch) | |
tree | a5b2e300eafa5e01f5e17752c1d19f8425dea278 /src/or | |
parent | c4830bfbe2db333b6550d8b3e98868fa2c808b76 (diff) | |
download | tor-363cf024553741524c0c8cb9fa8b9226863c903b.tar tor-363cf024553741524c0c8cb9fa8b9226863c903b.tar.gz |
Implement a PreferIPv6 flag for SocksPorts
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 6 | ||||
-rw-r--r-- | src/or/connection.c | 2 | ||||
-rw-r--r-- | src/or/connection_edge.c | 7 | ||||
-rw-r--r-- | 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 98fbb6e58..e069c7c52 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 89ac8f5e7..ecfb8a930 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 758d8f5d8..4f3dda284 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 f22c7dffb..4566f9152 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 */ |