mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Implement a PreferIPv6 flag for SocksPorts
This commit is contained in:
parent
c4830bfbe2
commit
363cf02455
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 "
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user