diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-12-04 19:46:01 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-12-04 19:46:01 +0300 |
commit | 4639b204c25a13638bee42eceb4004e6ba0c67ec (patch) | |
tree | aaa6003dabd6a38b1d00a0ffdd13bf34514ca132 /src/evdns | |
parent | 2f551bd813a96567bac80aeaa186b706571b69f7 (diff) | |
download | rspamd-4639b204c25a13638bee42eceb4004e6ba0c67ec.tar.gz rspamd-4639b204c25a13638bee42eceb4004e6ba0c67ec.zip |
* Updates to spf system:
- add plugin to work with spf records (initial version)
- make all spf types working (except include and redirect that still need some attention)
- add support of MX records to evdns
- some major fixes and testing of the whole spf subsystem
Diffstat (limited to 'src/evdns')
-rw-r--r-- | src/evdns/evdns.c | 39 | ||||
-rw-r--r-- | src/evdns/evdns.h | 16 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/evdns/evdns.c b/src/evdns/evdns.c index 6db223790..4a8a7b650 100644 --- a/src/evdns/evdns.c +++ b/src/evdns/evdns.c @@ -71,6 +71,7 @@ typedef unsigned int uint; #define TYPE_A EVDNS_TYPE_A #define TYPE_CNAME 5 #define TYPE_TXT EVDNS_TYPE_TXT +#define TYPE_MX EVDNS_TYPE_MX #define TYPE_PTR EVDNS_TYPE_PTR #define TYPE_AAAA EVDNS_TYPE_AAAA @@ -133,6 +134,10 @@ struct reply { struct { char name[HOST_NAME_MAX]; } ptr; + struct { + char name[HOST_NAME_MAX]; + u32 priority; + } mx; /* TXT field may be longer than 508 bytes, but UDP packets are limited to 512 octets */ struct { char data[508]; @@ -704,6 +709,18 @@ reply_callback(struct evdns_request *const req, u32 ttl, u32 err, struct reply * req->user_callback(err, 0, 0, 0, NULL, req->user_pointer); } return; + case TYPE_MX: + if (reply) { + struct evdns_mx mx; + mx.host = reply->data.mx.name; + mx.priority = reply->data.mx.priority; + req->user_callback(DNS_ERR_NONE, DNS_MX, 1, ttl, + &mx, req->user_pointer); + } + else { + req->user_callback(err, 0, 0, 0, NULL, req->user_pointer); + } + return; } g_assert(0); } @@ -990,6 +1007,18 @@ reply_parse(struct evdns_base *base, u8 *packet, int length) { ttl_r = MIN(ttl_r, ttl); reply.have_answer = 1; break; + } else if (type == TYPE_MX) { + if (req->request_type != TYPE_MX) { + j += datalength; + continue; + } + GET16(reply.data.mx.priority); + if (name_parse(packet, length, &j, reply.data.mx.name, + sizeof(reply.data.mx.name))<0) + goto err; + ttl_r = MIN(ttl_r, ttl); + reply.have_answer = 1; + break; } else { /* skip over any other type of resource */ j += datalength; @@ -2615,6 +2644,16 @@ evdns_resolve_txt(const char *in, int flags, evdns_callback_type callback, void return 0; } +int +evdns_resolve_mx(const char *in, int flags, evdns_callback_type callback, void *ptr) { + struct evdns_request *req; + g_assert(in); + req = request_new(current_base, TYPE_MX, in, flags, callback, ptr); + if (!req) return 1; + request_submit(req); + return 0; +} + /*/////////////////////////////////////////////////////////////////// */ /* Search support */ diff --git a/src/evdns/evdns.h b/src/evdns/evdns.h index 5d6df1872..ded48f2ac 100644 --- a/src/evdns/evdns.h +++ b/src/evdns/evdns.h @@ -58,6 +58,7 @@ #define DNS_PTR 2 #define DNS_IPv6_AAAA 3 #define DNS_TXT 4 +#define DNS_MX 15 #define DNS_QUERY_NO_SEARCH 1 @@ -78,6 +79,11 @@ typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, struct evdns_base; struct event_base; +struct evdns_mx { + char *host; + int priority; +}; + /** Initialize the asynchronous DNS library. @@ -664,6 +670,16 @@ int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callb */ int evdns_resolve_txt(const char *in, int flags, evdns_callback_type callback, void *ptr); +/** + Lookup a MX entry for a specified DNS name. + @param name a DNS name + @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. + @param callback a callback function to invoke when the request is completed + @param ptr an argument to pass to the callback function + @return 0 if successful, or -1 if an error occurred +*/ +int evdns_resolve_mx(const char *in, int flags, evdns_callback_type callback, void *ptr); + /** Set the value of a configuration option. |