[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Add config object for dirauth; move one option there.



commit ffa3499d81823eb21811a479c31b59f1bfb5bc61
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Sun Dec 15 11:46:55 2019 -0500

    Add config object for dirauth; move one option there.
    
    I've chosen the "AuthDirMaxServersPerAddr" option here for
    simplicity, since it is used literally nowhere else besides the dirauth
    module.  Once we have all the infrastructure in place for this, we
    can move more options into this structure.
---
 src/app/config/config.c                  |  1 -
 src/app/config/or_options_st.h           |  2 --
 src/core/include.am                      |  2 ++
 src/feature/dirauth/.may_include         |  1 +
 src/feature/dirauth/dirauth_config.c     | 22 ++++++++++++++++++++++
 src/feature/dirauth/dirauth_config.h     |  2 ++
 src/feature/dirauth/dirauth_options.inc  | 18 ++++++++++++++++++
 src/feature/dirauth/dirauth_options_st.h | 22 ++++++++++++++++++++++
 src/feature/dirauth/dirauth_stub.c       | 14 ++++++++++++++
 src/feature/dirauth/dirauth_sys.c        | 24 ++++++++++++++++++++++++
 src/feature/dirauth/dirauth_sys.h        |  3 +++
 src/feature/dirauth/dirvote.c            |  4 +++-
 12 files changed, 111 insertions(+), 4 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 5ea8cec6a..680a7eeef 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -337,7 +337,6 @@ static const config_var_t option_vars_[] = {
   OBSOLETE("AuthDirRejectUnlisted"),
   OBSOLETE("AuthDirListBadDirs"),
   V(AuthDirListBadExits,         BOOL,     "0"),
-  V(AuthDirMaxServersPerAddr,    POSINT,     "2"),
   OBSOLETE("AuthDirMaxServersPerAuthAddr"),
   V(AuthDirHasIPv6Connectivity,  BOOL,     "0"),
   VAR("AuthoritativeDirectory",  BOOL, AuthoritativeDir,    "0"),
diff --git a/src/app/config/or_options_st.h b/src/app/config/or_options_st.h
index a3d63d920..e63ae2510 100644
--- a/src/app/config/or_options_st.h
+++ b/src/app/config/or_options_st.h
@@ -467,8 +467,6 @@ struct or_options_t {
 
   int AuthDirListBadExits; /**< True iff we should list bad exits,
                             * and vote for all other exits as good. */
-  int AuthDirMaxServersPerAddr; /**< Do not permit more than this
-                                 * number of servers per IP address. */
   int AuthDirHasIPv6Connectivity; /**< Boolean: are we on IPv6?  */
   int AuthDirPinKeys; /**< Boolean: Do we enforce key-pinning? */
 
diff --git a/src/core/include.am b/src/core/include.am
index ab4adeaf6..911932d46 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -355,6 +355,8 @@ noinst_HEADERS +=					\
 	src/feature/dirauth/bridgeauth.h		\
 	src/feature/dirauth/bwauth.h			\
 	src/feature/dirauth/dirauth_config.h		\
+	src/feature/dirauth/dirauth_options.inc		\
+	src/feature/dirauth/dirauth_options_st.h	\
 	src/feature/dirauth/dirauth_periodic.h		\
 	src/feature/dirauth/dirauth_sys.h		\
 	src/feature/dirauth/dircollate.h		\
diff --git a/src/feature/dirauth/.may_include b/src/feature/dirauth/.may_include
index 424c745c1..a9bb27469 100644
--- a/src/feature/dirauth/.may_include
+++ b/src/feature/dirauth/.may_include
@@ -1 +1,2 @@
 *.h
+feature/dirauth/*.inc
diff --git a/src/feature/dirauth/dirauth_config.c b/src/feature/dirauth/dirauth_config.c
index 552f85146..b7e160c24 100644
--- a/src/feature/dirauth/dirauth_config.c
+++ b/src/feature/dirauth/dirauth_config.c
@@ -15,6 +15,7 @@
 
 #include "lib/encoding/confline.h"
 #include "lib/confmgt/confmgt.h"
+#include "lib/conf/confdecl.h"
 
 /* Required for dirinfo_type_t in or_options_t */
 #include "core/or/or.h"
@@ -28,6 +29,7 @@
 #include "feature/dirauth/dirauth_periodic.h"
 #include "feature/dirauth/dirvote.h"
 #include "feature/dirauth/guardfraction.h"
+#include "feature/dirauth/dirauth_options_st.h"
 
 /* Copied from config.c, we will refactor later in 29211. */
 #define REJECT(arg) \
@@ -438,3 +440,23 @@ options_act_dirauth_stats(const or_options_t *old_options,
 
   return 0;
 }
+
+/* Declare the options field table for dirauth_options */
+#define CONF_CONTEXT TABLE
+#include "feature/dirauth/dirauth_options.inc"
+#undef CONF_CONTEXT
+
+/** Magic number for dirauth_options_t. */
+#define DIRAUTH_OPTIONS_MAGIC 0x41757448
+
+/**
+ * Declare the configuration options for the dirauth module.
+ **/
+const config_format_t dirauth_options_fmt = {
+  .size = sizeof(dirauth_options_t),
+  .magic = { "dirauth_options_t",
+             DIRAUTH_OPTIONS_MAGIC,
+             offsetof(dirauth_options_t, magic) },
+  .vars = dirauth_options_t_vars,
+};
+
diff --git a/src/feature/dirauth/dirauth_config.h b/src/feature/dirauth/dirauth_config.h
index b494ca685..d21fb69d1 100644
--- a/src/feature/dirauth/dirauth_config.h
+++ b/src/feature/dirauth/dirauth_config.h
@@ -39,6 +39,8 @@ int options_act_dirauth_mtbf(const struct or_options_t *old_options);
 int options_act_dirauth_stats(const struct or_options_t *old_options,
                               bool *print_notice_out);
 
+extern const struct config_format_t dirauth_options_fmt;
+
 #else /* !defined(HAVE_MODULE_DIRAUTH) */
 
 /** When tor is compiled with the dirauth module disabled, it can't be
diff --git a/src/feature/dirauth/dirauth_options.inc b/src/feature/dirauth/dirauth_options.inc
new file mode 100644
index 000000000..6b66f1e28
--- /dev/null
+++ b/src/feature/dirauth/dirauth_options.inc
@@ -0,0 +1,18 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2019, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * @file dirauth_options.inc
+ * @brief Declare configuration options for the crypto_ops module.
+ **/
+
+/** Holds configuration about our directory authority options. */
+BEGIN_CONF_STRUCT(dirauth_options_t)
+
+/** Do not permit more than this number of servers per IP address. */
+CONF_VAR(AuthDirMaxServersPerAddr, POSINT, 0, "2")
+
+END_CONF_STRUCT(dirauth_options_t)
diff --git a/src/feature/dirauth/dirauth_options_st.h b/src/feature/dirauth/dirauth_options_st.h
new file mode 100644
index 000000000..93b9cb45b
--- /dev/null
+++ b/src/feature/dirauth/dirauth_options_st.h
@@ -0,0 +1,22 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2019, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * @file dirauth_options_st.h
+ * @brief Structure dirauth_options_t to hold directory authority options.
+ **/
+
+#ifndef TOR_FEATURE_DIRAUTH_DIRAUTH_OPTIONS_ST_H
+#define TOR_FEATURE_DIRAUTH_DIRAUTH_OPTIONS_ST_H
+
+#include "lib/conf/confdecl.h"
+#define CONF_CONTEXT STRUCT
+#include "feature/dirauth/dirauth_options.inc"
+#undef CONF_CONTEXT
+
+typedef struct dirauth_options_t dirauth_options_t;
+
+#endif /* !defined(TOR_FEATURE_DIRAUTH_DIRAUTH_OPTIONS_ST_H) */
diff --git a/src/feature/dirauth/dirauth_stub.c b/src/feature/dirauth/dirauth_stub.c
index fac68edd0..b0b4f987f 100644
--- a/src/feature/dirauth/dirauth_stub.c
+++ b/src/feature/dirauth/dirauth_stub.c
@@ -11,9 +11,23 @@
 
 #include "orconfig.h"
 #include "feature/dirauth/dirauth_sys.h"
+#include "lib/conf/conftypes.h"
+#include "lib/conf/confdecl.h"
+#include "lib/subsys/subsys.h"
+
+/* Declare the options field table for dirauth_options */
+#define CONF_CONTEXT STUB_TABLE
+#include "feature/dirauth/dirauth_options.inc"
+#undef CONF_CONTEXT
+
+static const config_format_t dirauth_options_stub_fmt = {
+  .vars = dirauth_options_t_vars,
+};
 
 const struct subsys_fns_t sys_dirauth = {
   .name = "dirauth",
   .supported = false,
   .level = 70,
+
+  .options_format = &dirauth_options_stub_fmt
 };
diff --git a/src/feature/dirauth/dirauth_sys.c b/src/feature/dirauth/dirauth_sys.c
index 090e9129f..8a4b1abaa 100644
--- a/src/feature/dirauth/dirauth_sys.c
+++ b/src/feature/dirauth/dirauth_sys.c
@@ -17,9 +17,14 @@
 #include "feature/dirauth/dirauth_periodic.h"
 #include "feature/dirauth/keypin.h"
 #include "feature/dirauth/process_descs.h"
+#include "feature/dirauth/dirauth_config.h"
+
+#include "feature/dirauth/dirauth_options_st.h"
 
 #include "lib/subsys/subsys.h"
 
+static const dirauth_options_t *global_dirauth_options;
+
 static int
 subsys_dirauth_initialize(void)
 {
@@ -34,6 +39,22 @@ subsys_dirauth_shutdown(void)
   dirvote_free_all();
   dirserv_clear_measured_bw_cache();
   keypin_close_journal();
+  global_dirauth_options = NULL;
+}
+
+const dirauth_options_t *
+dirauth_get_options(void)
+{
+  tor_assert(global_dirauth_options);
+  return global_dirauth_options;
+}
+
+static int
+dirauth_set_options(void *arg)
+{
+  dirauth_options_t *opts = arg;
+  global_dirauth_options = opts;
+  return 0;
 }
 
 const struct subsys_fns_t sys_dirauth = {
@@ -42,4 +63,7 @@ const struct subsys_fns_t sys_dirauth = {
   .level = 70,
   .initialize = subsys_dirauth_initialize,
   .shutdown = subsys_dirauth_shutdown,
+
+  .options_format = &dirauth_options_fmt,
+  .set_options = dirauth_set_options,
 };
diff --git a/src/feature/dirauth/dirauth_sys.h b/src/feature/dirauth/dirauth_sys.h
index 2d5a0cb3e..4c09ff64f 100644
--- a/src/feature/dirauth/dirauth_sys.h
+++ b/src/feature/dirauth/dirauth_sys.h
@@ -12,6 +12,9 @@
 #ifndef DIRAUTH_SYS_H
 #define DIRAUTH_SYS_H
 
+struct dirauth_options_t;
+const struct dirauth_options_t *dirauth_get_options(void);
+
 extern const struct subsys_fns_t sys_dirauth;
 
 #endif /* !defined(DIRAUTH_SYS_H) */
diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c
index 043bbfc22..13003bf63 100644
--- a/src/feature/dirauth/dirvote.c
+++ b/src/feature/dirauth/dirvote.c
@@ -41,10 +41,12 @@
 #include "feature/dirauth/dirvote.h"
 #include "feature/dirauth/authmode.h"
 #include "feature/dirauth/shared_random_state.h"
+#include "feature/dirauth/dirauth_sys.h"
 
 #include "feature/nodelist/authority_cert_st.h"
 #include "feature/dircache/cached_dir_st.h"
 #include "feature/dirclient/dir_server_st.h"
+#include "feature/dirauth/dirauth_options_st.h"
 #include "feature/nodelist/document_signature_st.h"
 #include "feature/nodelist/microdesc_st.h"
 #include "feature/nodelist/networkstatus_st.h"
@@ -4228,7 +4230,7 @@ compare_routerinfo_by_ip_and_bw_(const void **a, const void **b)
 static digestmap_t *
 get_possible_sybil_list(const smartlist_t *routers)
 {
-  const or_options_t *options = get_options();
+  const dirauth_options_t *options = dirauth_get_options();
   digestmap_t *omit_as_sybil;
   smartlist_t *routers_by_ip = smartlist_new();
   uint32_t last_addr;



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits