]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add flags and opaque data to upstreams
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Mar 2016 13:26:52 +0000 (13:26 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Mar 2016 13:26:52 +0000 (13:26 +0000)
src/libutil/upstream.c
src/libutil/upstream.h

index 8bbe48208d96bda77a221a800e9ad1d9a62f76be..3d01215725f3dff41910cf6a20bb7aabb563af24 100644 (file)
@@ -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;
+}
index 16561a6ac4a244ce4cba5241d346e9e4b570ddcf..79d88802db752df9cf21153c1abe73fc944e9d50 100644 (file)
@@ -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