From e7d1c7c1a609761ce46f0a6f7cdc7709a4ba2df8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 15 Mar 2016 13:26:52 +0000 Subject: [PATCH] [Feature] Add flags and opaque data to upstreams --- src/libutil/upstream.c | 33 +++++++++++++++++++++++++++++---- src/libutil/upstream.h | 27 +++++++++++++++++++++++++++ 2 files changed, 56 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; +} diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index 16561a6ac..79d88802d 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -15,6 +15,9 @@ enum rspamd_upstream_rotation { RSPAMD_UPSTREAM_UNDEF }; +enum rspamd_upstream_flag { + RSPAMD_UPSTREAM_FLAG_NORESOLVE = (1 << 0), +}; struct rspamd_config; /* Opaque upstream structures */ @@ -64,6 +67,15 @@ void rspamd_upstream_ok (struct upstream *up); * @return */ struct upstream_list* rspamd_upstreams_create (struct upstream_ctx *ctx); + +/** + * Sets specific flag to the upstream list + * @param ups + * @param flags + */ +void rspamd_upstreams_set_flags (struct upstream_list *ups, + enum rspamd_upstream_flag flags); + /** * Destroy list of upstreams * @param ups @@ -140,6 +152,21 @@ gboolean rspamd_upstream_add_addr (struct upstream *up, */ const gchar* rspamd_upstream_name (struct upstream *up); +/** + * Sets opaque user data associated with this upstream + * @param up + * @param data + * @return old data + */ +gpointer rspamd_upstream_set_data (struct upstream *up, gpointer data); + +/** + * Gets opaque user data associated with this upstream + * @param up + * @return + */ +gpointer rspamd_upstream_get_data (struct upstream *up); + /** * Get new upstream from the list * @param ups upstream list -- 2.39.5