Skip to content

Commit

Permalink
Basic simplifications related to socks_cfg
Browse files Browse the repository at this point in the history
Plugin code no longer has any use for "num_dns_threads", and the
"threadnum" member of dns_thread_t was unused (write-only).  These
were basically just leftover bits from past refactoring/changes.
  • Loading branch information
blblack committed Jun 4, 2021
1 parent 7c66430 commit 1554722
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 31 deletions.
21 changes: 10 additions & 11 deletions src/conf.c
Expand Up @@ -130,24 +130,23 @@ static bool bad_key(const char* key, unsigned klen V_UNUSED, vscf_data_t* d V_UN
log_fatal("Invalid %s key '%s'", which, key);
}

F_NONNULLX(2)
static void plugin_configure(const unsigned num_dns_threads, const char* name, vscf_data_t* pconf)
F_NONNULLX(1)
static void plugin_configure(const char* name, vscf_data_t* pconf)
{
if (pconf && !vscf_is_hash(pconf))
log_fatal("Config data for plugin '%s' must be a hash", name);

plugin_t* plugin = gdnsd_plugin_find(name);
if (plugin->load_config) {
plugin->load_config(pconf, num_dns_threads);
plugin->load_config(pconf);
plugin->config_loaded = true;
}
}

F_NONNULL
static bool cfg_plugin_iter(const char* name, unsigned namelen V_UNUSED, vscf_data_t* pconf, const void* scfg_asvoid)
static bool cfg_plugin_iter(const char* name, unsigned namelen V_UNUSED, vscf_data_t* pconf, const void* x V_UNUSED)
{
const socks_cfg_t* socks_cfg = scfg_asvoid;
plugin_configure(socks_cfg->num_dns_threads, name, pconf);
plugin_configure(name, pconf);
return true;
}

Expand Down Expand Up @@ -248,7 +247,7 @@ static bool cfg_plugin_iter(const char* name, unsigned namelen V_UNUSED, vscf_da
} while (0)


cfg_t* conf_load(const vscf_data_t* cfg_root, const socks_cfg_t* socks_cfg, const bool force_zsd)
cfg_t* conf_load(const vscf_data_t* cfg_root, const bool force_zsd)
{
gdnsd_assert(!cfg_root || vscf_is_hash(cfg_root));

Expand Down Expand Up @@ -348,14 +347,14 @@ cfg_t* conf_load(const vscf_data_t* cfg_root, const socks_cfg_t* socks_cfg, cons
// the list of meta-plugins will remain short and in-tree.
vscf_data_t* geoplug = vscf_hash_get_data_byconstkey(plugins_hash, "geoip", true);
if (geoplug)
plugin_configure(socks_cfg->num_dns_threads, "geoip", geoplug);
plugin_configure("geoip", geoplug);
// ditto for "metafo"
// Technically, geoip->metafo synthesis will work, but not metafo->geoip synthesis.
// Both can reference each other directly (%plugin!resource)
vscf_data_t* metaplug = vscf_hash_get_data_byconstkey(plugins_hash, "metafo", true);
if (metaplug)
plugin_configure(socks_cfg->num_dns_threads, "metafo", metaplug);
vscf_hash_iterate_const(plugins_hash, true, cfg_plugin_iter, socks_cfg);
plugin_configure("metafo", metaplug);
vscf_hash_iterate_const(plugins_hash, true, cfg_plugin_iter, NULL);
}

// Any plugins loaded via the plugins hash above will already have had load_config() called
Expand All @@ -364,7 +363,7 @@ cfg_t* conf_load(const vscf_data_t* cfg_root, const socks_cfg_t* socks_cfg, cons
// Because of the possibility of mixed plugins and the configuration ordering above for
// meta-plugins, this must happen at this sequential point (after plugins_hash processing,
// but before stypes_p2())
gdnsd_plugins_configure_all(socks_cfg->num_dns_threads);
gdnsd_plugins_configure_all();

// Phase 2 of service_types config
gdnsd_mon_cfg_stypes_p2(stypes_cfg);
Expand Down
4 changes: 2 additions & 2 deletions src/conf.h
Expand Up @@ -58,7 +58,7 @@ typedef struct {

extern const cfg_t* gcfg;

F_NONNULLX(2) F_RETNN
cfg_t* conf_load(const vscf_data_t* cfg_root, const socks_cfg_t* socks_cfg, const bool force_zsd);
F_RETNN
cfg_t* conf_load(const vscf_data_t* cfg_root, const bool force_zsd);

#endif // GDNSD_CONF_H
2 changes: 1 addition & 1 deletion src/main.c
Expand Up @@ -693,7 +693,7 @@ int main(int argc, char** argv)
}

// Load full configuration and expose through the global "gcfg"
gcfg = conf_load(cfg_root, socks_cfg, copts.force_zsd);
gcfg = conf_load(cfg_root, copts.force_zsd);
vscf_destroy(cfg_root);

// Basic init for the acme challenge code
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/extmon.c
Expand Up @@ -326,7 +326,7 @@ static bool bad_opt(const char* key, unsigned klen V_UNUSED, vscf_data_t* d V_UN
log_fatal("plugin_extmon: bad global option '%s'", key);
}

static void plugin_extmon_load_config(vscf_data_t* config, const unsigned num_threads V_UNUSED)
static void plugin_extmon_load_config(vscf_data_t* config)
{
if (config) {
vscf_data_t* helper_path_cfg = vscf_hash_get_data_byconstkey(config, "helper_path", true);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/meta_core.inc
Expand Up @@ -432,7 +432,7 @@ static int map_res_inner(const char* resname, const uint8_t* zone_name, const ch

/********** Callbacks from gdnsd **************/

static void CB_LOAD_CONFIG(vscf_data_t* config, const unsigned num_threads V_UNUSED)
static void CB_LOAD_CONFIG(vscf_data_t* config)
{
if (!config)
log_fatal("plugin_" PNSTR ": configuration required in 'plugins' stanza");
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/multifo.c
Expand Up @@ -316,7 +316,7 @@ static bool config_res(const char* resname, unsigned resname_len V_UNUSED, vscf_
/* Exported callbacks start here */
/*********************************/

static void plugin_multifo_load_config(vscf_data_t* config, const unsigned num_threads V_UNUSED)
static void plugin_multifo_load_config(vscf_data_t* config)
{
if (!config)
log_fatal("multifo plugin requires a 'plugins' configuration stanza");
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/null.c
Expand Up @@ -30,7 +30,7 @@
#include <string.h>
#include <inttypes.h>

static void plugin_null_load_config(vscf_data_t* config V_UNUSED, const unsigned num_threads V_UNUSED)
static void plugin_null_load_config(vscf_data_t* config V_UNUSED)
{
gdnsd_dyn_addr_max(1, 1); // null only ever returns a single IP from each family
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/plugapi.c
Expand Up @@ -161,11 +161,11 @@ plugin_t* gdnsd_plugin_find(const char* pname)

// The action iterators...

void gdnsd_plugins_configure_all(const unsigned num_threads)
void gdnsd_plugins_configure_all(void)
{
for (unsigned i = 0; i < NUM_PLUGINS; i++) {
if (plugins[i]->used && plugins[i]->load_config && !plugins[i]->config_loaded) {
plugins[i]->load_config(NULL, num_threads);
plugins[i]->load_config(NULL);
plugins[i]->config_loaded = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/plugapi.h
Expand Up @@ -88,7 +88,7 @@ void gdnsd_result_add_scope_mask(dyn_result_t* result, unsigned scope);
/**** Typedefs for plugin callbacks ****/

typedef unsigned(*gdnsd_apiv_cb_t)(void);
typedef void (*gdnsd_load_config_cb_t)(vscf_data_t* pc, const unsigned num_threads);
typedef void (*gdnsd_load_config_cb_t)(vscf_data_t* pc);
typedef int (*gdnsd_map_res_cb_t)(const char* resname, const uint8_t* zone_name);
typedef void (*gdnsd_pre_run_cb_t)(void);
typedef void (*gdnsd_iothread_init_cb_t)(void);
Expand Down Expand Up @@ -172,7 +172,7 @@ size_t gdnsd_result_get_max_response(void);

// call _load_config() for all plugins which are loaded but have not
// yet had that callback called
void gdnsd_plugins_configure_all(const unsigned num_threads);
void gdnsd_plugins_configure_all(void);

// action iterators
void gdnsd_plugins_action_pre_run(void);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/reflect.c
Expand Up @@ -45,7 +45,7 @@ static const char* response_text[NUM_RTYPES] = {
"both"
};

static void plugin_reflect_load_config(vscf_data_t* config V_UNUSED, const unsigned num_threads V_UNUSED)
static void plugin_reflect_load_config(vscf_data_t* config V_UNUSED)
{
gdnsd_dyn_addr_max(2, 2); // up to two (dns+edns) in any address family
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/simplefo.c
Expand Up @@ -189,7 +189,7 @@ static bool config_res(const char* resname, unsigned resname_len V_UNUSED, vscf_
/* Exported callbacks start here */
/*********************************/

static void plugin_simplefo_load_config(vscf_data_t* config, const unsigned num_threads V_UNUSED)
static void plugin_simplefo_load_config(vscf_data_t* config)
{
if (!config)
log_fatal("simplefo plugin requires a 'plugins' configuration stanza");
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/static.c
Expand Up @@ -77,7 +77,7 @@ static bool config_res(const char* resname, unsigned resname_len V_UNUSED, vscf_
return true;
}

static void plugin_static_load_config(vscf_data_t* config, const unsigned num_threads V_UNUSED)
static void plugin_static_load_config(vscf_data_t* config)
{
if (!config)
log_fatal("static plugin requires a 'plugins' configuration stanza");
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/weighted.c
Expand Up @@ -663,7 +663,7 @@ static bool config_res(const char* res_name, unsigned klen V_UNUSED, vscf_data_t

////// exported callbacks start here

static void plugin_weighted_load_config(vscf_data_t* config, const unsigned num_threads V_UNUSED)
static void plugin_weighted_load_config(vscf_data_t* config)
{
gdnsd_assert(config);
gdnsd_assert(vscf_is_hash(config));
Expand Down
6 changes: 2 additions & 4 deletions src/socks.c
Expand Up @@ -246,18 +246,16 @@ static void process_listen(socks_cfg_t* socks_cfg, vscf_data_t* listen_opt, cons
dns_addr_t* a = &socks_cfg->dns_addrs[i];

for (unsigned j = 0; j < a->udp_threads; j++) {
dns_thread_t* t = &socks_cfg->dns_threads[tnum];
dns_thread_t* t = &socks_cfg->dns_threads[tnum++];
t->ac = a;
t->is_udp = true;
t->threadnum = tnum++;
t->sock = -1;
}

for (unsigned j = 0; j < a->tcp_threads; j++) {
dns_thread_t* t = &socks_cfg->dns_threads[tnum];
dns_thread_t* t = &socks_cfg->dns_threads[tnum++];
t->ac = a;
t->is_udp = false;
t->threadnum = tnum++;
t->sock = -1;
}

Expand Down
1 change: 0 additions & 1 deletion src/socks.h
Expand Up @@ -44,7 +44,6 @@ typedef struct {
typedef struct {
dns_addr_t* ac;
pthread_t threadid;
unsigned threadnum;
int sock;
bool is_udp;
} dns_thread_t;
Expand Down

0 comments on commit 1554722

Please sign in to comment.