Commit Diff
Diff:
d6ba9551cb36818179061562c8d9d62d4317fd4c
457912e12e8118c13e2d1688ec958b8375e87377
Commit:
457912e12e8118c13e2d1688ec958b8375e87377
Tree:
c77340fe1f1c306d910fdbf8a5568f2181ce46ad
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Sun May 18 10:36:53 2014 UTC
Message:
In programming consistency is key, so clean up the prototypes (KNF), and also move code that was duplicated into it's own check_qtype() function. While there clean up this code and make it consistent.
blob - 84db77e188a5fd1c3b2df2d538389059c191f103
blob + 657914523f27ede2723f7809dfecc3ba78d10697
--- main.c
+++ main.c
@@ -34,9 +34,10 @@
struct question * build_question(char *, int, int);
struct question * build_fake_question(char *, int, u_int16_t);
-void mainloop(struct cfg *cfg);
+void mainloop(struct cfg *);
int free_question(struct question *);
int lookup_zone(DB *, struct question *, struct domain *, int *, char *, int);
+u_int16_t check_qtype(struct domain *, u_int16_t, int, int *);
int get_soa(DB *, struct question *, struct domain *, int);
extern void reply_notimpl(struct sreply *);
@@ -57,20 +58,20 @@ extern void reply_any(struct sreply *);
extern void reply_srv(struct sreply *, DB *);
extern void reply_naptr(struct sreply *, DB *);
extern void reply_sshfp(struct sreply *);
-extern u_int8_t find_region(struct sockaddr_storage *sst, int family);
-extern int find_wildcard(struct sockaddr_storage *sst, int family);
-extern int find_filter(struct sockaddr_storage *sst, int family);
+extern u_int8_t find_region(struct sockaddr_storage *, int);
+extern int find_wildcard(struct sockaddr_storage *, int);
+extern int find_filter(struct sockaddr_storage *, int);
extern void init_wildcard(void);
extern void init_recurse(void);
extern void init_region(void);
extern void init_filter(void);
extern void init_notifyslave(void);
extern void collects_init(void);
-extern void recurseloop(int sp, int *raw, DB *db);
+extern void recurseloop(int sp, int *, DB *);
extern int find_recurse(struct sockaddr_storage *, int);
extern int remotelog(int, char *, ...);
-extern void receivelog(char *buf, int len);
-extern void axfrloop(int *afd, int sockcount, char **ident, DB *db);
+extern void receivelog(char *, int);
+extern void axfrloop(int *, int, char **, DB *);
extern void dolog(int, char *, ...);
extern char * rrlimit_setup(int);
extern void add_rrlimit(int, u_int16_t *, int, char *);
@@ -80,7 +81,7 @@ char * dns_label(char *, int *);
int compress_label(u_char *, u_int16_t, int);
int memcasecmp(u_char *, u_char *, int);
char * get_dns_type(int dnstype);
-void build_reply(struct sreply *reply, int so, char *buf, int len, struct question *q, struct sockaddr *sa, socklen_t slen, struct domain *sd1, struct domain *sd2, u_int8_t region, int istcp, int wildcard, struct recurses *sr, char *);
+void build_reply(struct sreply *, int, char *, int, struct question *, struct sockaddr *, socklen_t, struct domain *, struct domain *, u_int8_t, int, int, struct recurses *, char *);
void recurseheader(struct srecurseheader *, int, struct sockaddr_storage *, struct sockaddr_storage *, int);
void setup_master(DB *, DB_ENV *, int, char **);
void master_shutdown(int);
@@ -169,7 +170,7 @@ static struct tcps {
} *tn1, *tnp, *tntmp;
-static const char rcsid[] = "$Id: main.c,v 1.94 2014/05/17 09:18:11 pjp Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.95 2014/05/18 10:36:53 pjp Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -1691,7 +1692,7 @@ lookup_zone(DB *db, struct question *question, struct
int plen, onemore = 0;
int ret = 0;
- int returnval;
+ int returnval, error;
int w = 0;
char *wildlookup = "*";
@@ -1782,131 +1783,11 @@ lookup_zone(DB *db, struct question *question, struct
return (-1);
}
- switch (ntohs(question->hdr->qtype)) {
- case DNS_TYPE_ANY:
- returnval = DNS_TYPE_ANY;
- break;
- case DNS_TYPE_A:
- if ((sd->flags & DOMAIN_HAVE_A) ==
- DOMAIN_HAVE_A) {
- returnval = DNS_TYPE_A;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
+ returnval = check_qtype(sd, ntohs(question->hdr->qtype), 0, &error);
+ if (returnval == 0) {
*lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_AAAA:
- if ((sd->flags & DOMAIN_HAVE_AAAA) ==
- DOMAIN_HAVE_AAAA) {
- returnval = DNS_TYPE_AAAA;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
-
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_MX:
- if ((sd->flags & DOMAIN_HAVE_MX) ==
- DOMAIN_HAVE_MX) {
- returnval = DNS_TYPE_MX;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
-
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_PTR:
- if ((sd->flags & DOMAIN_HAVE_PTR) ==
- DOMAIN_HAVE_PTR) {
- returnval = DNS_TYPE_PTR;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
-
- *lzerrno = ERR_NOERROR;
- return -1;
-
- case DNS_TYPE_SOA:
- if ((sd->flags & DOMAIN_HAVE_SOA) != DOMAIN_HAVE_SOA) {
-
- *lzerrno = ERR_NOERROR; /*pjp,24/07/09*/
- return -1;
- }
- returnval = DNS_TYPE_SOA;
- break;
-
- case DNS_TYPE_SSHFP:
- if ((sd->flags & DOMAIN_HAVE_SSHFP) != DOMAIN_HAVE_SSHFP) {
-
- *lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_SSHFP;
- break;
-
- case DNS_TYPE_SRV:
- if ((sd->flags & DOMAIN_HAVE_SRV) != DOMAIN_HAVE_SRV) {
-
- *lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_SRV;
- break;
-
- case DNS_TYPE_NAPTR:
- if ((sd->flags & DOMAIN_HAVE_NAPTR) != DOMAIN_HAVE_NAPTR) {
-
- *lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_NAPTR;
- break;
-
- case DNS_TYPE_CNAME:
- if ((sd->flags & DOMAIN_HAVE_CNAME) != DOMAIN_HAVE_CNAME) {
-
- *lzerrno = ERR_NOERROR;
- return -1;
- }
-
- returnval = DNS_TYPE_CNAME;
- break;
- case DNS_TYPE_NS:
- if ((sd->flags & DOMAIN_HAVE_NS) != DOMAIN_HAVE_NS) {
- *lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_NS;
- break;
- case DNS_TYPE_TXT:
- if ((sd->flags & DOMAIN_HAVE_TXT) ==
- DOMAIN_HAVE_TXT) {
- returnval = DNS_TYPE_TXT;
- break;
- }
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_SPF:
- if ((sd->flags & DOMAIN_HAVE_SPF) ==
- DOMAIN_HAVE_SPF) {
- returnval = DNS_TYPE_SPF;
- break;
- }
- *lzerrno = ERR_NOERROR;
- return -1;
- default: /* RR's that we don't support, but have a zone for */
- *lzerrno = ERR_NOERROR;
- return -1;
- break;
+ return (-1);
}
break;
@@ -1955,129 +1836,18 @@ lookup_zone(DB *db, struct question *question, struct
goto out;
}
- switch (ntohs(question->hdr->qtype)) {
- case DNS_TYPE_ANY:
- returnval = DNS_TYPE_ANY;
- break;
- case DNS_TYPE_A:
- if ((sd->flags & DOMAIN_HAVE_A) ==
- DOMAIN_HAVE_A) {
- returnval = DNS_TYPE_A;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
-
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_AAAA:
- if ((sd->flags & DOMAIN_HAVE_AAAA) ==
- DOMAIN_HAVE_AAAA) {
- returnval = DNS_TYPE_AAAA;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
-
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_MX:
- if ((sd->flags & DOMAIN_HAVE_MX) ==
- DOMAIN_HAVE_MX) {
- returnval = DNS_TYPE_MX;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
-
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_PTR:
- if ((sd->flags & DOMAIN_HAVE_PTR) ==
- DOMAIN_HAVE_PTR) {
- returnval = DNS_TYPE_PTR;
- break;
- } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
- returnval = DNS_TYPE_CNAME;
- break;
- }
-
- *lzerrno = ERR_NOERROR;
- return -1;
-
- case DNS_TYPE_SOA:
- if ((sd->flags & DOMAIN_HAVE_SOA) != DOMAIN_HAVE_SOA) {
-
+ returnval = check_qtype(sd, ntohs(question->hdr->qtype), 1, &error);
+ if (returnval == 0) {
+ switch (error) {
+ case -2:
*lzerrno = ERR_NXDOMAIN;
- return -1;
- }
- returnval = DNS_TYPE_SOA;
- break;
- case DNS_TYPE_NS:
- if ((sd->flags & DOMAIN_HAVE_NS) != DOMAIN_HAVE_NS) {
-
+ break;
+ case -1:
*lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_NS;
- break;
-
- case DNS_TYPE_SSHFP:
- if ((sd->flags & DOMAIN_HAVE_SSHFP) != DOMAIN_HAVE_SSHFP) {
-
- *lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_SSHFP;
- break;
-
- case DNS_TYPE_SRV:
- if ((sd->flags & DOMAIN_HAVE_SRV) != DOMAIN_HAVE_SRV) {
-
- *lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_SRV;
- break;
-
- case DNS_TYPE_CNAME:
- if ((sd->flags & DOMAIN_HAVE_CNAME) != DOMAIN_HAVE_CNAME) {
- *lzerrno = ERR_NOERROR;
- return -1;
- }
- returnval = DNS_TYPE_CNAME;
- break;
- case DNS_TYPE_TXT:
- if ((sd->flags & DOMAIN_HAVE_TXT) ==
- DOMAIN_HAVE_TXT) {
- returnval = DNS_TYPE_TXT;
break;
}
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_NAPTR:
- if ((sd->flags & DOMAIN_HAVE_NAPTR) ==
- DOMAIN_HAVE_NAPTR) {
- returnval = DNS_TYPE_NAPTR;
- break;
- }
- *lzerrno = ERR_NOERROR;
- return -1;
- case DNS_TYPE_SPF:
- if ((sd->flags & DOMAIN_HAVE_SPF) ==
- DOMAIN_HAVE_SPF) {
- returnval = DNS_TYPE_SPF;
- break;
- }
- *lzerrno = ERR_NOERROR;
- return -1;
- default: /* RR's that we don't support, but have a zone for */
- *lzerrno = ERR_NOERROR;
- return -1;
- break;
+
+ return (-1);
}
snprintf(replystring, DNS_MAXNAME, "*");
@@ -3739,4 +3509,153 @@ void
master_reload(int sig)
{
reload = 1;
+}
+
+/*
+ * CHECK_QTYPE - check the query type and return appropriately if we have
+ * such a record in our DB..
+ * returns 0 on error, or the DNS TYPE from 1 through 65535
+ * when the return is 0 the error variable is set with the error
+ * code (-1 or -2)
+ */
+
+u_int16_t
+check_qtype(struct domain *sd, u_int16_t type, int nxdomain, int *error)
+{
+ u_int16_t returnval;
+
+ switch (type) {
+
+ case DNS_TYPE_ANY:
+ returnval = DNS_TYPE_ANY;
+ break;
+
+ case DNS_TYPE_A:
+ if ((sd->flags & DOMAIN_HAVE_A) == DOMAIN_HAVE_A) {
+ returnval = DNS_TYPE_A;
+ break;
+ } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
+ returnval = DNS_TYPE_CNAME;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+ case DNS_TYPE_AAAA:
+ if ((sd->flags & DOMAIN_HAVE_AAAA) == DOMAIN_HAVE_AAAA) {
+ returnval = DNS_TYPE_AAAA;
+ break;
+ } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
+ returnval = DNS_TYPE_CNAME;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+ case DNS_TYPE_MX:
+ if ((sd->flags & DOMAIN_HAVE_MX) ==
+ DOMAIN_HAVE_MX) {
+ returnval = DNS_TYPE_MX;
+ break;
+ } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
+ returnval = DNS_TYPE_CNAME;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+ case DNS_TYPE_PTR:
+ if ((sd->flags & DOMAIN_HAVE_PTR) == DOMAIN_HAVE_PTR) {
+ returnval = DNS_TYPE_PTR;
+ break;
+ } else if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
+ returnval = DNS_TYPE_CNAME;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+
+ case DNS_TYPE_SOA:
+ if ((sd->flags & DOMAIN_HAVE_SOA) == DOMAIN_HAVE_SOA) {
+
+ returnval = DNS_TYPE_SOA;
+ break;
+ }
+
+ if (nxdomain)
+ *error = -2;
+ else
+ *error = -1;
+
+ return 0;
+
+ case DNS_TYPE_SSHFP:
+ if ((sd->flags & DOMAIN_HAVE_SSHFP) == DOMAIN_HAVE_SSHFP) {
+ returnval = DNS_TYPE_SSHFP;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+
+ case DNS_TYPE_SRV:
+ if ((sd->flags & DOMAIN_HAVE_SRV) == DOMAIN_HAVE_SRV) {
+ returnval = DNS_TYPE_SRV;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+
+ case DNS_TYPE_NAPTR:
+ if ((sd->flags & DOMAIN_HAVE_NAPTR) == DOMAIN_HAVE_NAPTR) {
+ returnval = DNS_TYPE_NAPTR;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+ case DNS_TYPE_CNAME:
+ if ((sd->flags & DOMAIN_HAVE_CNAME) == DOMAIN_HAVE_CNAME) {
+ returnval = DNS_TYPE_CNAME;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+
+ case DNS_TYPE_NS:
+ if ((sd->flags & DOMAIN_HAVE_NS) == DOMAIN_HAVE_NS) {
+ returnval = DNS_TYPE_NS;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+ case DNS_TYPE_TXT:
+ if ((sd->flags & DOMAIN_HAVE_TXT) == DOMAIN_HAVE_TXT) {
+ returnval = DNS_TYPE_TXT;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+ case DNS_TYPE_SPF:
+ if ((sd->flags & DOMAIN_HAVE_SPF) == DOMAIN_HAVE_SPF) {
+ returnval = DNS_TYPE_SPF;
+ break;
+ }
+
+ *error = -1;
+ return 0;
+
+ default: /* RR's that we don't support, but have a zone for */
+
+ *error = -1;
+ return 0;
+ break;
+ }
+
+ return (returnval);
}
repomaster@centroid.eu