aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-01-02 17:43:35 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-01-02 17:43:35 +0000
commitf11da523576c2cc1d07e1d9baa99572479bf42eb (patch)
treefc41e98f9d991fd8ccb6bcd7b5e2f4c082e70b7e
parent5666e4872245117ada3c06b22cc700cf138cd6e4 (diff)
downloadrspamd-f11da523576c2cc1d07e1d9baa99572479bf42eb.tar.gz
rspamd-f11da523576c2cc1d07e1d9baa99572479bf42eb.zip
Add support for edns0 in rspamd.
-rw-r--r--src/dns.c30
-rw-r--r--src/dns.h3
2 files changed, 31 insertions, 2 deletions
diff --git a/src/dns.c b/src/dns.c
index cf70a6a86..f8f444893 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -294,7 +294,8 @@ allocate_packet (struct rspamd_dns_request *req, guint namelen)
{
namelen += 96 /* header */
+ 2 /* Trailing label */
- + 4; /* Resource type */
+ + 4 /* Resource type */
+ + 11; /* EDNS0 RR */
req->packet = memory_pool_alloc (req->pool, namelen);
req->pos = 0;
req->packet_len = namelen;
@@ -311,6 +312,7 @@ make_dns_header (struct rspamd_dns_request *req)
header->qid = dns_permutor_generate_id (req->resolver->permutor);
header->rd = 1;
header->qdcount = htons (1);
+ header->arcount = htons (1);
req->pos += sizeof (struct dns_header);
req->id = header->qid;
}
@@ -575,6 +577,29 @@ make_spf_req (struct rspamd_dns_request *req, const gchar *name)
req->requested_name = name;
}
+static void
+rspamd_dns_add_edns0 (struct rspamd_dns_request *req)
+{
+ guint8 *p8;
+ guint16 *p16;
+
+ p8 = (guint8 *)(req->packet + req->pos);
+ *p8 = '\0'; /* Name is root */
+ p16 = (guint16 *)(req->packet + req->pos + 1);
+ *p16++ = htons (DNS_T_OPT);
+ /* UDP packet length */
+ *p16++ = htons (UDP_PACKET_SIZE);
+ /* Extended rcode 00 00 */
+ *p16++ = 0;
+ /* Z 10000000 00000000 to allow dnssec */
+ p8 = (guint8 *)p16++;
+ /* Not a good time for DNSSEC */
+ *p8 = 0x00;
+ /* Length */
+ *p16 = 0;
+ req->pos += sizeof (guint8) + sizeof (guint16) * 5;
+}
+
static gint
send_dns_request (struct rspamd_dns_request *req)
{
@@ -1294,6 +1319,9 @@ make_dns_request (struct rspamd_dns_resolver *resolver,
}
va_end (args);
+ /* Add EDNS RR */
+ rspamd_dns_add_edns0 (req);
+
req->retransmits = 0;
req->time = time (NULL);
if (resolver->is_master_slave) {
diff --git a/src/dns.h b/src/dns.h
index 68aa17e82..1c88e5a18 100644
--- a/src/dns.h
+++ b/src/dns.h
@@ -36,7 +36,7 @@
#define DNS_D_MAXLABEL 63 /* + 1 '\0' */
#define DNS_D_MAXNAME 255 /* + 1 '\0' */
-#define MAX_ADDRS 1
+#define MAX_ADDRS 10
struct rspamd_dns_reply;
struct config_file;
@@ -240,6 +240,7 @@ enum dns_type {
DNS_T_TXT = 16,
DNS_T_AAAA = 28,
DNS_T_SRV = 33,
+ DNS_T_OPT = 41,
DNS_T_SSHFP = 44,
DNS_T_SPF = 99,