Commit Diff
Diff:
c45084eaeb5abd393561d940a00730926706d812
f665f992b81aec4f83c19b8a31315d1c9c7df32b
Commit:
f665f992b81aec4f83c19b8a31315d1c9c7df32b
Tree:
132841cd7fb75d1104d5449e8ac47f290df3dfd0
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Thu Dec 1 10:35:29 2005 UTC
Message:
* format error support * will reply format error if there is not exactly one question, like most dns servers
blob - 2e4d054ff82e36255fbc3083f5dc12cad974a16c
blob + e7479be304c00c61c5ad48562ff3b6014499ca55
--- dns.h
+++ dns.h
@@ -109,6 +109,7 @@ struct dns_question_hdr {
#define SET_DNS_RCODE_NOTIMPL(x) ((x)->query |= (DNS_NOTIMPL))
#define SET_DNS_RCODE_NAMEERR(x) ((x)->query |= (DNS_NAMEERR))
#define SET_DNS_RCODE_SERVFAIL(x) ((x)->query |= (DNS_SERVFAIL))
+#define SET_DNS_RCODE_FORMATERR(x) ((x)->query |= (DNS_FORMATERR))
#define SET_DNS_RCODE_NOERR(x) ((x)->query |= (DNS_NOERR))
/* DNS types - RFC 1035 page 12 */
blob - 7730ed669959d8ef73da14051d2b4b9e6c611fcf
blob + ca0227f462f1fa467ce26155b57db643f8558f95
--- main.c
+++ main.c
@@ -41,6 +41,7 @@ int lookup_zone(DB *, struct question *, struct domain
extern void reply_notimpl(struct sreply *);
extern void reply_nxdomain(struct sreply *);
+extern void reply_fmterror(struct sreply *);
extern void reply_a(struct sreply *);
extern void reply_aaaa(struct sreply *);
extern void reply_soa(struct sreply *);
@@ -411,11 +412,16 @@ mainloop(int *udp, int *tcp, int sockcount, char **ide
}
/*
- * if no question entry is included drop
+ * if questions aren't exactly 1 then drop
*/
- if (ntohs(dh->question) == 0) {
+ if (ntohs(dh->question) != 1) {
syslog(LOG_INFO, "on descriptor %u interface \"%s\" header from %s has no question, drop", so, ident[i], address);
+
+ /* format error */
+ BUILD_REPLY(sreply, so, buf, len, NULL, from, fromlen, NULL, NULL);
+ reply_fmterror(&sreply);
+ syslog(LOG_INFO, "question on descriptor %d interface \"%s\" from %s, did not have question of 1 replying format error", so, ident[i], address);
goto drop;
}
@@ -767,7 +773,7 @@ free_question(struct question *q)
char *
dns_label(char *name, int *returnlen)
{
- char tname[DNS_MAXNAME + 1]; /* 255 bytes */
+ char tname[DNS_MAXNAME + 1]; /* 255 bytes + 1*/
char *pt = &tname[0];
int len, newlen = 0;
int i, lc = 0; /* lc = label count */
blob - d66dae1521a364f0e97c75135073fe2591f1a123
blob + 33fbcd2a68f23d439c50d1bc896875d47a31cbf0
--- reply.c
+++ reply.c
@@ -38,6 +38,7 @@ void reply_nxdomain(struct sreply *);
void reply_soa(struct sreply *);
void reply_ptr(struct sreply *);
void reply_cname(struct sreply *);
+void reply_fmterror(struct sreply *);
extern int compress_label(char *, int, int);
extern int additional_a(char *, int, struct domain *, char *, int, int, int *);
@@ -1020,6 +1021,47 @@ reply_nxdomain(struct sreply *sreply)
HTONS(odh->query);
if (sendto(so, reply, len, 0, sa, salen) < 0) {
+ syslog(LOG_INFO, "sendto: %m");
+ }
+
+ return;
+}
+
+/*
+ * REPLY_FMTERROR() - replies a DNS question (*q) on socket (so)
+ *
+ */
+
+void
+reply_fmterror(struct sreply *sreply)
+{
+ char reply[512];
+ struct dns_header *odh;
+ int outlen;
+
+ int so = sreply->so;
+ int len = sreply->len;
+ char *buf = sreply->buf;
+ struct sockaddr *sa = sreply->sa;
+ int salen = sreply->salen;
+
+ memset(&reply, 0, sizeof(reply));
+ odh = (struct dns_header *)&reply[0];
+ outlen = sizeof(struct dns_header);
+
+ if (len > sizeof(reply)) {
+ return;
+ }
+
+ memcpy((char *)&odh->id, buf, sizeof(u_int16_t));
+ memset((char *)&odh->query, 0, sizeof(u_int16_t));
+
+ SET_DNS_REPLY(odh);
+ SET_DNS_RCODE_FORMATERR(odh);
+
+ HTONS(odh->query);
+
+ if (sendto(so, reply, sizeof(struct dns_header), 0, sa, salen) < 0) {
syslog(LOG_INFO, "sendto: %m");
}
repomaster@centroid.eu