diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-09-16 00:48:38 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-09-16 00:48:38 +0100 |
commit | 85a1704ee40b0518c5e4d4eabccc6b4a387e2480 (patch) | |
tree | 1cd46e3613c88d939ec4dc058e887ce48c2b0e54 | |
parent | 2fa167601ae2194bbdf4484fe2ad8e3eee813163 (diff) | |
download | rspamd-85a1704ee40b0518c5e4d4eabccc6b4a387e2480.tar.gz rspamd-85a1704ee40b0518c5e4d4eabccc6b4a387e2480.zip |
Allow multiply bind configurations.
-rw-r--r-- | src/cfg_file.h | 14 | ||||
-rw-r--r-- | src/cfg_utils.c | 34 | ||||
-rw-r--r-- | src/cfg_xml.c | 3 | ||||
-rw-r--r-- | src/main.c | 34 |
4 files changed, 42 insertions, 43 deletions
diff --git a/src/cfg_file.h b/src/cfg_file.h index 829b4b453..bfbc0efa9 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -11,6 +11,7 @@ #include "upstream.h" #include "memcached.h" #include "symbols_cache.h" +#include "utlist.h" #define DEFAULT_BIND_PORT 768 #define DEFAULT_CONTROL_PORT 7608 @@ -245,6 +246,12 @@ struct config_scalar { } type; /**< type of data */ }; +struct rspamd_worker_bind_conf { + gchar *bind_host; + guint16 bind_port; + gboolean is_unix; + struct rspamd_worker_bind_conf *next; +}; /** * Config params for rspamd worker @@ -252,10 +259,7 @@ struct config_scalar { struct worker_conf { worker_t *worker; /**< pointer to worker type */ GQuark type; /**< type of worker */ - gchar *bind_host; /**< bind line */ - gchar *bind_addr; /**< bind address in case of TCP socket */ - guint16 bind_port; /**< bind port in case of TCP socket */ - guint16 bind_family; /**< bind type (AF_UNIX or AF_INET) */ + struct rspamd_worker_bind_conf *bind_conf; /**< bind configuration */ guint16 count; /**< number of workers */ GList *listen_socks; /**< listening sockets desctiptors */ guint32 rlimit_nofile; /**< max files limit */ @@ -407,7 +411,7 @@ gboolean parse_host_priority (memory_pool_t *pool, const gchar *str, gchar **add * @param type type of credits * @return 1 if line was successfully parsed and 0 in case of error */ -gint parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str); +gboolean parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str); /** * Init default values diff --git a/src/cfg_utils.c b/src/cfg_utils.c index 6bdb3c8f7..e7e57cd8a 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -163,21 +163,16 @@ parse_host_priority (memory_pool_t *pool, const gchar *str, gchar **addr, guint return parse_host_port_priority (pool, str, addr, NULL, priority); } -gint +gboolean parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str) { - gchar **host; - guint16 *family, *port; - gchar **addr; + struct rspamd_worker_bind_conf *cnf; if (str == NULL) return 0; - host = &cf->bind_host; - port = &cf->bind_port; - *port = DEFAULT_BIND_PORT; - family = &cf->bind_family; - addr = &cf->bind_addr; + cnf = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf)); + cnf->bind_port = DEFAULT_BIND_PORT; if (str[0] == '/' || str[0] == '.') { #ifdef HAVE_DIRNAME @@ -189,7 +184,7 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str) if (errno == ENOENT) { if ((fd = open (str, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR)) == -1) { msg_err ("cannot open path %s for making socket, %s", str, strerror (errno)); - return 0; + return FALSE; } else { close (fd); @@ -208,21 +203,20 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str) } } #endif - *host = memory_pool_strdup (cfg->cfg_pool, str); - *addr = *host; - *family = AF_UNIX; - return 1; + cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str); + cnf->is_unix = TRUE; + LL_PREPEND (cf->bind_conf, cnf); + return TRUE; } else { - if (parse_host_port (cfg->cfg_pool, str, addr, port)) { - *host = memory_pool_strdup (cfg->cfg_pool, str); - *family = AF_INET; - - return 1; + cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str); + if (parse_host_port (cfg->cfg_pool, str, &cnf->bind_host, &cnf->bind_port)) { + LL_PREPEND (cf->bind_conf, cnf); + return TRUE; } } - return 0; + return FALSE; } void diff --git a/src/cfg_xml.c b/src/cfg_xml.c index 0393f026c..fc7245390 100644 --- a/src/cfg_xml.c +++ b/src/cfg_xml.c @@ -2748,9 +2748,6 @@ xml_dump_workers (struct config_file *cfg, FILE *f) rspamd_fprintf (f, "<worker>" EOL); rspamd_fprintf (f, " <type>%s</type>" EOL, g_quark_to_string (wrk->type)); - escaped_str = g_markup_escape_text (wrk->bind_host, -1); - rspamd_fprintf (f, " <bind_socket>%s</bind_socket>" EOL, escaped_str); - g_free (escaped_str); rspamd_fprintf (f, " <count>%ud</count>" EOL, wrk->count); rspamd_fprintf (f, " <maxfiles>%ud</maxfiles>" EOL, wrk->rlimit_nofile); diff --git a/src/main.c b/src/main.c index cab81c10e..6b593f638 100644 --- a/src/main.c +++ b/src/main.c @@ -612,6 +612,7 @@ spawn_workers (struct rspamd_main *rspamd) struct worker_conf *cf; gint i; gpointer p; + struct rspamd_worker_bind_conf *bcf; cur = rspamd->cfg->workers; @@ -623,23 +624,26 @@ spawn_workers (struct rspamd_main *rspamd) } else { if (cf->worker->has_socket) { - if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER ( - make_listen_key (cf->bind_addr, cf->bind_port, cf->bind_family)))) == NULL) { - /* Create listen socket */ - ls = create_listen_socket (cf->bind_addr, cf->bind_port, cf->bind_family, - cf->worker->listen_type); - if (ls == NULL) { - exit (-errno); + LL_FOREACH (cf->bind_conf, bcf) { + if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER ( + make_listen_key (bcf->bind_host, bcf->bind_port, bcf->is_unix)))) == NULL) { + /* Create listen socket */ + ls = create_listen_socket (bcf->bind_host, bcf->bind_port, + bcf->is_unix ? AF_UNIX : AF_INET, + cf->worker->listen_type); + if (ls == NULL) { + exit (-errno); + } + g_hash_table_insert (listen_sockets, GINT_TO_POINTER ( + make_listen_key (bcf->bind_host, bcf->bind_port, bcf->is_unix)), + ls); } - g_hash_table_insert (listen_sockets, GINT_TO_POINTER ( - make_listen_key (cf->bind_addr, cf->bind_port, cf->bind_family)), - ls); - } - else { - /* We had socket for this type of worker */ - ls = p; + else { + /* We had socket for this type of worker */ + ls = p; + } + cf->listen_socks = g_list_prepend (cf->listen_socks, ls); } - cf->listen_socks = ls; } if (cf->worker->unique) { |