Commit Diff
Diff:
3ec15a3021a6a47148f98ca2ab167b1a39767dd4
9525851c17a00df1521f629eea694e8c515ec592
Commit:
9525851c17a00df1521f629eea694e8c515ec592 (tags/BETA_2)
Tree:
74b61fe581c2b78ffeb0febbbfe6aa0de569b2ae
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Mon Aug 31 14:03:10 2009 UTC
Message:
* in main.c - remove recvfrom() in favour of recvmsg(), this allows us to turn on reading the time to live of the request. It could be useful for future changes in features. * in parse.c - when stat()'ing files in /dev don't return with failure but log and keep going, this worked on my vps which had something mangled internally
blob - 5c18341e611b1e026a84d844eaa960be929b197e
blob + e2500a14237e93897638559b3e3f763c4ac053d6
--- include.h
+++ include.h
@@ -32,6 +32,7 @@
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/stat.h>
+#include <sys/uio.h>
#include <net/if.h>
#include <netinet/in.h>
blob - 8f18664fc3b2358010d1065085524fb610d995b9
blob + b8775cbaae470c867e6b65d62f6ed5901cfda43e
--- main.c
+++ main.c
@@ -82,7 +82,7 @@ extern char *__progname;
static int Wflag = 0;
static int lflag = 0;
-static const char rcsid[] = "$Id: main.c,v 1.24 2009/07/24 22:16:34 pbug Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.25 2009/08/31 14:03:10 pbug Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -102,6 +102,7 @@ main(int argc, char *argv[])
int bcount = 0, icount = 0;
int found = 0;
u_int16_t port = 53;
+ int on = 1;
static char *ident[DEFAULT_SOCKET];
char *conffile = CONFFILE;
@@ -153,7 +154,7 @@ main(int argc, char *argv[])
Wflag = 1;
break;
default:
- fprintf(stderr, "usage: dnsserver [-i interface] [-b bindaddress] [-f configfile] [-p portnumber] [-W]\n");
+ fprintf(stderr, "usage: dnsserver [-W] [-i interface] [-b bindaddress] [-f configfile] [-p portnumber]\n");
exit (1);
}
}
@@ -253,6 +254,12 @@ main(int argc, char *argv[])
exit(1);
}
+ if (res->ai_family == AF_INET) {
+ if (setsockopt(udp[i], IPPROTO_IP, IP_RECVTTL,
+ &on, sizeof(on)) < 0) {
+ syslog(LOG_INFO, "setsockopt: %m");
+ }
+ }
ident[i] = bind_list[i];
}
@@ -327,6 +334,13 @@ main(int argc, char *argv[])
exit(1);
}
+ if (pifap->ifa_addr->sa_family == AF_INET) {
+ if (setsockopt(udp[i], IPPROTO_IP, IP_RECVTTL,
+ &on, sizeof(on)) < 0) {
+ syslog(LOG_INFO, "setsockopt: %m");
+ }
+ }
+
ident[i] = pifap->ifa_name;
}
@@ -414,11 +428,14 @@ mainloop(int *udp, int *tcp, int sockcount, char **ide
int so;
int type0, type1;
int lzerrno;
+ int received_ttl;
+ int *ttlptr;
char buf[2048];
char address[INET6_ADDRSTRLEN];
char replystring[DNS_MAXNAME + 1];
char fakereplystring[DNS_MAXNAME + 1];
+ char controlbuf[64];
union {
struct sockaddr sa;
@@ -437,6 +454,10 @@ mainloop(int *udp, int *tcp, int sockcount, char **ide
struct domain sd0, sd1;
struct sreply sreply;
+ struct msghdr msgh;
+ struct cmsghdr *cmsg;
+ struct iovec iov;
+
maxso = 0;
for (i = 0; i < sockcount; i++) {
@@ -468,12 +489,41 @@ mainloop(int *udp, int *tcp, int sockcount, char **ide
if (FD_ISSET(udp[i], &rset)) {
so = udp[i];
fromlen = sizeof(sockaddr_large);
- len = recvfrom(so, buf, sizeof(buf), 0, from, (socklen_t *)&fromlen);
+
+ memset(&msgh, 0, sizeof(msgh));
+ iov.iov_base = buf;
+ iov.iov_len = sizeof(buf);
+ msgh.msg_name = from;
+ msgh.msg_namelen = fromlen;
+ msgh.msg_iov = &iov;
+ msgh.msg_iovlen = 1;
+ msgh.msg_control = (struct cmsghdr*)&controlbuf;
+ msgh.msg_controllen = sizeof(controlbuf);
+
+ len = recvmsg(so, &msgh, 0);
if (len < 0) {
- syslog(LOG_INFO, "recvfrom: on descriptor %u interface \"%s\" %m", so, ident[i]);
+ syslog(LOG_INFO, "recvmsg: on descriptor %u interface \"%s\" %m", so, ident[i]);
continue;
}
+ received_ttl = 0;
+
+ for (cmsg = CMSG_FIRSTHDR(&msgh);
+ cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
+ if (cmsg->cmsg_level == IPPROTO_IP
+#ifdef __linux__
+ && cmsg->cmsg_type == IP_TTL) {
+#else
+ && cmsg->cmsg_type == IP_RECVTTL) {
+#endif
+ ttlptr = (int *) CMSG_DATA(cmsg);
+ received_ttl = *ttlptr;
+ break;
+ }
+ }
+
+
if (from->sa_family == AF_INET6) {
is_ipv6 = 1;
@@ -698,7 +748,7 @@ nxdomain:
out:
if (lflag)
- syslog(LOG_INFO, "request on descriptor %u interface \"%s\" from %s for \"%s\" type=%s class=%u, answering \"%s\"", so, ident[i], address, question->converted_name, get_dns_type(ntohs(question->hdr->qtype)), ntohs(question->hdr->qclass), replystring);
+ syslog(LOG_INFO, "request on descriptor %u interface \"%s\" from %s (ttl=%d) for \"%s\" type=%s class=%u, answering \"%s\"", so, ident[i], address, received_ttl, question->converted_name, get_dns_type(ntohs(question->hdr->qtype)), ntohs(question->hdr->qclass), replystring);
if (fakequestion != NULL) {
blob - 922bea9e64714ef3ca2c31316ae0c7e200e89468
blob + 87a98c4d8e0cfafbb5e23add2f7bd826b836e156
--- parse.c
+++ parse.c
@@ -45,7 +45,7 @@ struct myrr_lookup {
{ NULL, 0 },
};
-static const char rcsid[] = "$Id: parse.c,v 1.12 2009/03/25 12:15:55 pbug Exp $";
+static const char rcsid[] = "$Id: parse.c,v 1.13 2009/08/31 14:03:10 pbug Exp $";
/*
* PARSE_FILE - parse the configfile XXX rewrite me in yacc :(
@@ -107,7 +107,6 @@ parse_file(DB *db, char *file)
snprintf(buf, sizeof(buf) - 1, "/dev/%s", dp->d_name);
if (stat(buf, &sb0) < 0) {
syslog(LOG_INFO, "stat: %m");
- return -1;
}
if (sb.st_dev == sb0.st_rdev)
repomaster@centroid.eu