Bladeren bron

[Feature] Store SPF records digests

tags/1.9.2
Vsevolod Stakhov 5 jaren geleden
bovenliggende
commit
48f02cfd4d
3 gewijzigde bestanden met toevoegingen van 49 en 2 verwijderingen
  1. 35
    1
      src/libserver/spf.c
  2. 1
    0
      src/libserver/spf.h
  3. 13
    1
      src/plugins/spf.c

+ 35
- 1
src/libserver/spf.c Bestand weergeven

* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <contrib/librdns/rdns.h>
#include "config.h" #include "config.h"
#include "dns.h" #include "dns.h"
#include "spf.h" #include "spf.h"
#include "message.h" #include "message.h"
#include "utlist.h" #include "utlist.h"
#include "libserver/mempool_vars_internal.h" #include "libserver/mempool_vars_internal.h"
#include "contrib/librdns/rdns.h"
#include "contrib/mumhash/mum.h"


#define SPF_VER1_STR "v=spf1" #define SPF_VER1_STR "v=spf1"
#define SPF_VER2_STR "spf2." #define SPF_VER2_STR "spf2."
DL_FOREACH (cur, cur_addr) { DL_FOREACH (cur, cur_addr) {
memcpy (&taddr, cur_addr, sizeof (taddr)); memcpy (&taddr, cur_addr, sizeof (taddr));
taddr.spf_string = g_strdup (cur_addr->spf_string); taddr.spf_string = g_strdup (cur_addr->spf_string);

if (cur_addr->flags & RSPAMD_SPF_FLAG_IPV6) {
guint64 t[3];

memcpy (t, cur_addr->addr6, sizeof (guint64) * 2);
t[2] = ((guint64)(cur_addr->mech)) << 48;
t[2] |= cur_addr->m.dual.mask_v6;

for (guint j = 0; j < G_N_ELEMENTS (t); j ++) {
target->digest = mum_hash_step (target->digest, t[j]);
}
}
else if (cur_addr->flags & RSPAMD_SPF_FLAG_IPV4) {
guint64 t;

memcpy (&t, cur_addr->addr4, sizeof (guint32));
t |= ((guint64)(cur_addr->mech)) << 48;
t |= ((guint64)cur_addr->m.dual.mask_v4) << 32;

target->digest = mum_hash_step (target->digest, t);
}
else {
guint64 t = 0;

t |= ((guint64)(cur_addr->mech)) << 48;
target->digest = mum_hash_step (target->digest, t);
}

g_array_append_val (target->elts, taddr); g_array_append_val (target->elts, taddr);
} }
} }
rec->resolved->len); rec->resolved->len);
res->domain = g_strdup (rec->sender_domain); res->domain = g_strdup (rec->sender_domain);
res->ttl = rec->ttl; res->ttl = rec->ttl;
res->digest = mum_hash_init (0xa4aa40bbeec59e2bULL);
REF_INIT_RETAIN (res, rspamd_flatten_record_dtor); REF_INIT_RETAIN (res, rspamd_flatten_record_dtor);


if (rec->resolved->len > 0) { if (rec->resolved->len > 0) {
rspamd_spf_process_reference (res, NULL, rec, TRUE); rspamd_spf_process_reference (res, NULL, rec, TRUE);
} }

res->digest = mum_hash_finish (res->digest);
} }
else { else {
res = g_malloc0 (sizeof (*res)); res = g_malloc0 (sizeof (*res));
res->elts = g_array_new (FALSE, FALSE, sizeof (struct spf_addr)); res->elts = g_array_new (FALSE, FALSE, sizeof (struct spf_addr));
res->domain = g_strdup (rec->sender_domain); res->domain = g_strdup (rec->sender_domain);
res->ttl = rec->ttl; res->ttl = rec->ttl;
res->digest = mum_hash_init (0xa4aa40bbeec59e2bULL);
REF_INIT_RETAIN (res, rspamd_flatten_record_dtor); REF_INIT_RETAIN (res, rspamd_flatten_record_dtor);
} }



+ 1
- 0
src/libserver/spf.h Bestand weergeven

gboolean temp_failed; gboolean temp_failed;
gboolean na; gboolean na;
gboolean perm_failed; gboolean perm_failed;
guint64 digest;
GArray *elts; /* Flat list of struct spf_addr */ GArray *elts; /* Flat list of struct spf_addr */
ref_entry_t ref; /* Refcounting */ ref_entry_t ref; /* Refcounting */
}; };

+ 13
- 1
src/plugins/spf.c Bestand weergeven

{ {
guint i; guint i;
struct spf_addr *addr; struct spf_addr *addr;
struct spf_ctx *spf_module_ctx = spf_get_context (task->cfg);

if (cached) {
msg_info_task ("use cached record for %s (0x%xuL) in LRU cache for %d seconds, "
"%d/%d elements in the cache",
rec->domain,
rec->digest,
rec->ttl,
rspamd_lru_hash_size (spf_module_ctx->spf_hash),
rspamd_lru_hash_capacity (spf_module_ctx->spf_hash));
}


for (i = 0; i < rec->elts->len; i ++) { for (i = 0; i < rec->elts->len; i ++) {
addr = &g_array_index (rec->elts, struct spf_addr, i); addr = &g_array_index (rec->elts, struct spf_addr, i);
record->domain, spf_record_ref (l), record->domain, spf_record_ref (l),
task->tv.tv_sec, record->ttl); task->tv.tv_sec, record->ttl);


msg_info_task ("stored record for %s in LRU cache for %d seconds, "
msg_info_task ("stored record for %s (0x%xuL) in LRU cache for %d seconds, "
"%d/%d elements in the cache", "%d/%d elements in the cache",
record->domain, record->domain,
record->digest,
record->ttl, record->ttl,
rspamd_lru_hash_size (spf_module_ctx->spf_hash), rspamd_lru_hash_size (spf_module_ctx->spf_hash),
rspamd_lru_hash_capacity (spf_module_ctx->spf_hash)); rspamd_lru_hash_capacity (spf_module_ctx->spf_hash));

Laden…
Annuleren
Opslaan