Commit Diff
Diff:
1f90620722f1f45e54ba8438f57a88c1aa036d73
1c8eb9edfea9e9acd8909dd52a753903a3d8a0da
Commit:
1c8eb9edfea9e9acd8909dd52a753903a3d8a0da
Tree:
6289868cd64e4b12acbd47ce279fb2d5715ab2c6
Author:
pbug <pbug@delphinusdns.org>
Committer:
pbug <pbug@delphinusdns.org>
Date:
Fri Sep 17 13:24:38 2010 UTC
Message:
* put netlookup() into it's own function, right now this is broken..
blob - 3449ac2a131a69dcdd0f4853377fa6a221765fbf
blob + 9c31d92736589ebac7117ed5c7fa5a44c2dcceb1
--- Makefile.bsd
+++ Makefile.bsd
@@ -4,6 +4,7 @@ SRCS=main.c parse.c reply.c additional.c region.c wild
#CFLAGS= -DDEBUG -g -Wall
CFLAGS= -Wall -g
+LDFLAGS= -Wall -g
#LDADD= -lcrypto -lssl
OBJDIR=.
blob - bb07e0e3071a246f8a3edbaa6bc8e68993dd5bb4
blob + ce3a5e9af87e7f6103b0e75f241b058b6ed722cd
--- recurse.c
+++ recurse.c
@@ -91,8 +91,9 @@ int lookup_ns(DB *, struct recurses *);
int lookup_a(DB *, struct recurses *, struct ns *);
int recurse_parse(DB *db, struct recurses *sr, u_char *buf, u_int16_t offset);
int negative_cache(DB *db, struct recurses *sr);
+int netlookup(DB *db, struct recurses *sr);
-static const char rcsid[] = "$Id: recurse.c,v 1.7 2010/09/17 10:50:23 pbug Exp $";
+static const char rcsid[] = "$Id: recurse.c,v 1.8 2010/09/17 13:24:38 pbug Exp $";
/*
* INIT_RECURSE - initialize the recurse singly linked list
@@ -236,8 +237,8 @@ recurseloop(int sp, int *raw, DB *db)
struct timeval tv;
struct srecurseheader rh;
struct domain sd;
- struct sockaddr_in sin;
struct dns_header *dh;
+ struct sockaddr_in sin;
int type, lzerrno, wildcard = 0;
@@ -306,84 +307,10 @@ recurseloop(int sp, int *raw, DB *db)
type = lookup_zone(db, sr->question, &sd, &lzerrno, (char *)fakereplystring, wildcard);
if (type < 0) {
- /* do the network stuff then */
- /* XXX should be IPv6 ready */
- sr->so = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (sr->so < 0) {
- syslog(LOG_ERR, "socket: %m");
- free_question(sr->question);
- free(sr); /* XXX */
+ if (netlookup(db, sr) < 0)
continue;
- }
-
- sr->port = arc4random() & 0xffff;
- /*
- * we have to avoid picking servers already
- * running ..
- */
- if (sr->port < 1024)
- sr->port += 1024;
- sr->id = arc4random() & 0xffff;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(sr->port);
- sin.sin_addr.s_addr = INADDR_ANY;
-
- if (bind(sr->so, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- syslog(LOG_ERR, "bind: %m");
- close(sr->so);
- free_question(sr->question);
- free(sr);
- continue;
- }
-
- if (lookup_ns(db, sr) <= 0) {
- syslog(LOG_ERR, "can't establish any servers to reach for zone \"%s\"", sr->question->converted_name);
- close(sr->so);
- free_question(sr->question);
- free(sr);
- continue;
- }
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(53);
-
- sin.sin_addr.s_addr = sr->a[0];
-
- /* XXX we use buf here in order to preserve
- * the state of query...
- */
- memcpy(buf, sr->query, sr->len);
- dh = (struct dns_header *)&buf[0];
- NTOHS(dh->query);
- UNSET_DNS_RECURSION(dh);
- HTONS(dh->query);
- dh->id = htons(sr->id);
-
-#if 1
- syslog(LOG_INFO, "sending request with id %u\n", sr->id);
-
-#endif
-
- if (sendto(sr->so, buf, sr->len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- syslog(LOG_ERR, "sendto: %m");
- close(sr->so);
- free_question(sr->question);
- free(sr);
- continue;
- }
-
- sr->sent_last_query = time(NULL);
-
- /*
- * add to our linked list of outstanding
- * lookups
- */
SLIST_INSERT_HEAD(&recurseshead, sr, entries);
-
} else {
#if 0
reply_raw(sr);
@@ -436,6 +363,7 @@ recurseloop(int sp, int *raw, DB *db)
/* XXX */
close(sr1->so);
+ sr1->so = -1;
if (ntohs(dh->query) & DNS_NAMEERR) {
negative_cache(db, sr1);
@@ -446,6 +374,19 @@ recurseloop(int sp, int *raw, DB *db)
recurse_parse(db, sr1, buf, len);
+ type = lookup_zone(db, sr->question, &sd, &lzerrno, (char *)fakereplystring, wildcard);
+ if (type < 0) {
+ if (netlookup(db, sr1) < 0) {
+ syslog(LOG_DEBUG, "subsequent netlookup failed");
+ continue;
+ }
+ } else {
+ /* we've found the record we're looking
+ * for do something with it..
+ */
+
+ syslog(LOG_DEBUG, "record found but no action");
+ }
remove:
SLIST_REMOVE(&recurseshead, sr1, recurses, entries);
free_question(sr1->question);
@@ -1216,4 +1157,95 @@ end:
syslog(LOG_DEBUG, "mangled input packet");
return (-1);
+}
+
+
+/*
+ * NETLOOKUP - do a internet lookup of the requested internet record
+ *
+ */
+
+int
+netlookup(DB *db, struct recurses *sr)
+{
+ struct sockaddr_in sin;
+ struct dns_header *dh;
+
+ char buf[2048];
+
+
+ /* do the network stuff then */
+ /* XXX should be IPv6 ready */
+ sr->so = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (sr->so < 0) {
+ syslog(LOG_ERR, "socket: %m");
+ free_question(sr->question);
+ free(sr); /* XXX */
+ return (-1);
+ }
+
+ sr->port = arc4random() & 0xffff;
+ /*
+ * we have to avoid picking servers already
+ * running ..
+ */
+ if (sr->port < 1024)
+ sr->port += 1024;
+
+ sr->id = arc4random() & 0xffff;
+
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(sr->port);
+ sin.sin_addr.s_addr = INADDR_ANY;
+
+ if (bind(sr->so, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ syslog(LOG_ERR, "bind: %m");
+ close(sr->so);
+ free_question(sr->question);
+ free(sr);
+ return (-1);
+ }
+
+ if (lookup_ns(db, sr) <= 0) {
+ syslog(LOG_ERR, "can't establish any servers to reach for zone \"%s\"", sr->question->converted_name);
+ close(sr->so);
+ free_question(sr->question);
+ free(sr);
+ return (-1);
+ }
+
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(53);
+
+ sin.sin_addr.s_addr = sr->a[0];
+
+ /* XXX we use buf here in order to preserve
+ * the state of query...
+ */
+ memcpy(buf, sr->query, sr->len);
+ dh = (struct dns_header *)&buf[0];
+ NTOHS(dh->query);
+ UNSET_DNS_RECURSION(dh);
+ HTONS(dh->query);
+ dh->id = htons(sr->id);
+
+#if 1
+ syslog(LOG_INFO, "sending request with id %u\n", sr->id);
+
+#endif
+
+ if (sendto(sr->so, buf, sr->len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ syslog(LOG_ERR, "sendto: %m");
+ close(sr->so);
+ free_question(sr->question);
+ free(sr);
+ return (-1);
+ }
+
+ sr->sent_last_query = time(NULL);
+
+
+ return (0);
}
repomaster@centroid.eu