summaryrefslogtreecommitdiffstats
path: root/src/libutil/upstream.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-15 13:26:52 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-15 13:26:52 +0000
commite7d1c7c1a609761ce46f0a6f7cdc7709a4ba2df8 (patch)
tree12d80438ed46eb3b95e8d269ca8d994fa4b2c840 /src/libutil/upstream.c
parent844e34179a661f0c372ea726adff5776be55bbaa (diff)
downloadrspamd-e7d1c7c1a609761ce46f0a6f7cdc7709a4ba2df8.tar.gz
rspamd-e7d1c7c1a609761ce46f0a6f7cdc7709a4ba2df8.zip
[Feature] Add flags and opaque data to upstreams
Diffstat (limited to 'src/libutil/upstream.c')
-rw-r--r--src/libutil/upstream.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 8bbe48208..3d0121572 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -53,7 +53,7 @@ struct upstream {
struct upstream_inet_addr_entry *new_addrs;
rspamd_mutex_t *lock;
-
+ gpointer data;
ref_entry_t ref;
};
@@ -64,6 +64,7 @@ struct upstream_list {
rspamd_mutex_t *lock;
guint64 hash_seed;
guint cur_elt;
+ enum rspamd_upstream_flag flags;
enum rspamd_upstream_rotation rot_alg;
};
@@ -332,7 +333,8 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *up)
g_ptr_array_remove_index (ls->alive, up->active_idx);
up->active_idx = -1;
- if (up->ctx->res != NULL && up->ctx->configured) {
+ if (up->ctx->res != NULL && up->ctx->configured &&
+ !(ls->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
/* Resolve name of the upstream one more time */
if (up->name[0] != '/') {
@@ -438,7 +440,7 @@ rspamd_upstreams_create (struct upstream_ctx *ctx)
{
struct upstream_list *ls;
- ls = g_slice_alloc (sizeof (*ls));
+ ls = g_slice_alloc0 (sizeof (*ls));
ls->hash_seed = SEED_CONSTANT;
ls->ups = g_ptr_array_new ();
ls->alive = g_ptr_array_new ();
@@ -556,6 +558,13 @@ rspamd_upstreams_add_upstream (struct upstream_list *ups,
return TRUE;
}
+void
+rspamd_upstreams_set_flags (struct upstream_list *ups,
+ enum rspamd_upstream_flag flags)
+{
+ ups->flags = flags;
+}
+
gboolean
rspamd_upstream_add_addr (struct upstream *up, rspamd_inet_addr_t *addr)
{
@@ -834,7 +843,8 @@ rspamd_upstream_reresolve (struct upstream_ctx *ctx)
up = cur->data;
REF_RETAIN (up);
- if (up->name[0] != '/' && ctx->res != NULL) {
+ if (up->name[0] != '/' && ctx->res != NULL &&
+ !(up->ls->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
if (rdns_make_request_full (ctx->res,
rspamd_upstream_dns_cb,
up,
@@ -864,3 +874,18 @@ rspamd_upstream_reresolve (struct upstream_ctx *ctx)
cur = g_list_next (cur);
}
}
+
+gpointer
+rspamd_upstream_set_data (struct upstream *up, gpointer data)
+{
+ gpointer prev_data = up->data;
+ up->data = data;
+
+ return prev_data;
+}
+
+gpointer
+rspamd_upstream_get_data (struct upstream *up)
+{
+ return up->data;
+}