aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/policies.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-12-01 20:32:18 -0500
committerNick Mathewson <nickm@torproject.org>2018-12-01 20:32:18 -0500
commit2b2b97484ad07c91ac410735a96fe8710e60cf23 (patch)
tree1e484c79478f34faea52da03e7bb262fa421d318 /src/core/or/policies.c
parent701eaef980de4f7dbb5c31c4fee9b7e1e266d7a1 (diff)
parentad031b64ce355ac3af15adb716a4322858dce4a8 (diff)
downloadtor-2b2b97484ad07c91ac410735a96fe8710e60cf23.tar.gz
tor-2b2b97484ad07c91ac410735a96fe8710e60cf23.zip
Merge branch 'ticket27490a_squashed'
Diffstat (limited to 'src/core/or/policies.c')
-rw-r--r--src/core/or/policies.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/core/or/policies.c b/src/core/or/policies.c
index 0eda93c5f3..123fc8566e 100644
--- a/src/core/or/policies.c
+++ b/src/core/or/policies.c
@@ -29,6 +29,7 @@
#include "feature/relay/routermode.h"
#include "lib/geoip/geoip.h"
#include "ht.h"
+#include "lib/crypt_ops/crypto_rand.h"
#include "lib/encoding/confline.h"
#include "core/or/addr_policy_st.h"
@@ -461,7 +462,8 @@ fascist_firewall_use_ipv6(const or_options_t *options)
* ClientPreferIPv6DirPort is deprecated, but check it anyway. */
return (options->ClientUseIPv6 == 1 || options->ClientUseIPv4 == 0 ||
options->ClientPreferIPv6ORPort == 1 ||
- options->ClientPreferIPv6DirPort == 1 || options->UseBridges == 1);
+ options->ClientPreferIPv6DirPort == 1 || options->UseBridges == 1 ||
+ options->ClientAutoIPv6ORPort == 1);
}
/** Do we prefer to connect to IPv6, ignoring ClientPreferIPv6ORPort and
@@ -488,6 +490,15 @@ fascist_firewall_prefer_ipv6_impl(const or_options_t *options)
return -1;
}
+/* Choose whether we prefer IPv4 or IPv6 by randomly choosing an address
+ * family. Return 0 for IPv4, and 1 for IPv6. */
+MOCK_IMPL(int,
+fascist_firewall_rand_prefer_ipv6_addr, (void))
+{
+ /* TODO: Check for failures, and infer our preference based on this. */
+ return crypto_rand_int(2);
+}
+
/** Do we prefer to connect to IPv6 ORPorts?
* Use node_ipv6_or_preferred() whenever possible: it supports bridge client
* per-node IPv6 preferences.
@@ -502,7 +513,10 @@ fascist_firewall_prefer_ipv6_orport(const or_options_t *options)
}
/* We can use both IPv4 and IPv6 - which do we prefer? */
- if (options->ClientPreferIPv6ORPort == 1) {
+ if (options->ClientAutoIPv6ORPort == 1) {
+ /* If ClientAutoIPv6ORPort is 1, we prefer IPv4 or IPv6 at random. */
+ return fascist_firewall_rand_prefer_ipv6_addr();
+ } else if (options->ClientPreferIPv6ORPort == 1) {
return 1;
}