aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/spf.h
blob: 2a844e9982ab60cbb0c08632e464bc5ff4d60855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef RSPAMD_SPF_H
#define RSPAMD_SPF_H

#include "config.h"
#include "ref.h"
#include "addr.h"

struct rspamd_task;
struct spf_resolved;

typedef void (*spf_cb_t)(struct spf_resolved *record,
		struct rspamd_task *task, gpointer cbdata);

typedef enum spf_mech_e {
	SPF_FAIL,
	SPF_SOFT_FAIL,
	SPF_PASS,
	SPF_NEUTRAL
} spf_mech_t;

typedef enum spf_action_e {
	SPF_RESOLVE_MX,
	SPF_RESOLVE_A,
	SPF_RESOLVE_PTR,
	SPF_RESOLVE_AAA,
	SPF_RESOLVE_REDIRECT,
	SPF_RESOLVE_INCLUDE,
	SPF_RESOLVE_EXISTS,
	SPF_RESOLVE_EXP
} spf_action_t;

#define RSPAMD_SPF_FLAG_IPV6 (1 << 0)
#define RSPAMD_SPF_FLAG_IPV4 (1 << 1)
#define RSPAMD_SPF_FLAG_PROCESSED (1 << 2)
#define RSPAMD_SPF_FLAG_ANY (1 << 3)
#define RSPAMD_SPF_FLAG_PARSED (1 << 4)
#define RSPAMD_SPF_FLAG_INVALID (1 << 5)
#define RSPAMD_SPF_FLAG_REFERENCE (1 << 6)
#define RSPAMD_SPF_FLAG_REDIRECT (1 << 7)
#define RSPAMD_SPF_FLAG_TEMPFAIL (1 << 8)
#define RSPAMD_SPF_FLAG_NA (1 << 9)
#define RSPAMD_SPF_FLAG_PERMFAIL (1 << 10)
#define RSPAMD_SPF_FLAG_RESOLVED (1 << 11)

struct spf_addr {
	guchar addr6[sizeof (struct in6_addr)];
	guchar addr4[sizeof (struct in_addr)];
	union {
		struct {
			guint16 mask_v4;
			guint16 mask_v6;
		} dual;
		guint32 idx;
	} m;
	guint flags;
	spf_mech_t mech;
	gchar *spf_string;
	struct spf_addr *prev, *next;
};

struct spf_resolved {
	gchar *domain;
	guint ttl;
	gboolean temp_failed;
	gboolean na;
	gboolean perm_failed;
	GArray *elts; /* Flat list of struct spf_addr */
	ref_entry_t ref; /* Refcounting */
};


/*
 * Resolve spf record for specified task and call a callback after resolution fails/succeed
 */
gboolean rspamd_spf_resolve (struct rspamd_task *task, spf_cb_t callback,
		gpointer cbdata);

/*
 * Get a domain for spf for specified task
 */
const gchar * rspamd_spf_get_domain (struct rspamd_task *task);


/*
 * Increase refcount
 */
struct spf_resolved * spf_record_ref (struct spf_resolved *rec);

/*
 * Decrease refcount
 */
void spf_record_unref (struct spf_resolved *rec);

#endif