[tor-commits] [tor/master] Add policy_using_default_exit_options() to determine if we're using the default exit options

nickm at torproject.org nickm at torproject.org
Tue Apr 23 19:39:29 UTC 2019


commit e7c22e6e4882332cc0e3377f0d3494f3bf47ad96
Author: Neel Chauhan <neel at neelc.org>
Date:   Tue Apr 16 08:19:44 2019 -0400

    Add policy_using_default_exit_options() to determine if we're using the default exit options
---
 src/core/or/policies.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/core/or/policies.c b/src/core/or/policies.c
index ab320dd2c..41d221b19 100644
--- a/src/core/or/policies.c
+++ b/src/core/or/policies.c
@@ -1164,6 +1164,15 @@ authdir_policy_badexit_address(uint32_t addr, uint16_t port)
 #define REJECT(arg) \
   STMT_BEGIN *msg = tor_strdup(arg); goto err; STMT_END
 
+/** Check <b>or_options</b> to determine whether or not we are using the
+ * default options for exit policy. Return true if so, false otherwise. */
+static int
+policy_using_default_exit_options(const or_options_t *or_options)
+{
+  return (or_options->ExitPolicy == NULL && or_options->ExitRelay == -1 &&
+          or_options->ReducedExitPolicy == 0 && or_options->IPv6Exit == 0);
+}
+
 /** Config helper: If there's any problem with the policy configuration
  * options in <b>options</b>, return -1 and set <b>msg</b> to a newly
  * allocated description of the error. Else return 0. */
@@ -1183,8 +1192,7 @@ validate_addr_policies(const or_options_t *options, char **msg)
   static int warned_about_nonexit = 0;
 
   if (public_server_mode(options) && !warned_about_nonexit &&
-      options->ExitPolicy == NULL && options->ExitRelay == -1 &&
-      options->ReducedExitPolicy == 0 && options->IPv6Exit == 0) {
+      policy_using_default_exit_options(options)) {
     warned_about_nonexit = 1;
     log_notice(LD_CONFIG, "By default, Tor does not run as an exit relay. "
                "If you want to be an exit relay, "
@@ -2143,8 +2151,7 @@ policies_parse_exit_policy_from_options(const or_options_t *or_options,
   /* Short-circuit for non-exit relays, or for relays where we didn't specify
    * ExitPolicy or ReducedExitPolicy and ExitRelay is auto. */
   if (or_options->ExitRelay == 0 ||
-      (or_options->ExitPolicy == NULL && or_options->ExitRelay == -1 &&
-       or_options->ReducedExitPolicy == 0 && or_options->IPv6Exit == 0)) {
+      policy_using_default_exit_options(or_options)) {
     append_exit_policy_string(result, "reject *4:*");
     append_exit_policy_string(result, "reject *6:*");
     return 0;





More information about the tor-commits mailing list