Commit Diff
Diff:
ece0cc95dce68c596cdd9ce929fa0be438f34a31
a2b189d48a0c3f883b33a641053ab8513c25e89f
Commit:
a2b189d48a0c3f883b33a641053ab8513c25e89f
Tree:
2aa5b9c44a61069619451ba7e853dba94e81f0a4
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Wed Oct 8 21:00:55 2014 UTC
Message:
After talking about a DDOS attack that I saw in my logs with my friend, I decided to log received bytes and sent bytes. Much useless typing for this but I got it.
blob - 4549e08c386f77d29d3dd7b12967646e83849b31
blob + 890f8dd2ae6f640598e8702cc660d41e91d59575
--- main.c
+++ main.c
@@ -50,24 +50,24 @@ extern void init_notifyslave(void);
extern void init_whitelist(void);
extern void recurseloop(int sp, int *, DB *);
extern void receivelog(char *, int);
-extern void reply_a(struct sreply *, DB *);
-extern void reply_aaaa(struct sreply *, DB *);
-extern void reply_any(struct sreply *);
-extern void reply_cname(struct sreply *);
-extern void reply_fmterror(struct sreply *);
-extern void reply_notimpl(struct sreply *);
-extern void reply_nxdomain(struct sreply *);
-extern void reply_noerror(struct sreply *);
-extern void reply_soa(struct sreply *);
-extern void reply_mx(struct sreply *, DB *);
-extern void reply_naptr(struct sreply *, DB *);
-extern void reply_ns(struct sreply *, DB *);
-extern void reply_ptr(struct sreply *);
-extern void reply_refused(struct sreply *);
-extern void reply_spf(struct sreply *);
-extern void reply_srv(struct sreply *, DB *);
-extern void reply_sshfp(struct sreply *);
-extern void reply_txt(struct sreply *);
+extern int reply_a(struct sreply *, DB *);
+extern int reply_aaaa(struct sreply *, DB *);
+extern int reply_any(struct sreply *);
+extern int reply_cname(struct sreply *);
+extern int reply_fmterror(struct sreply *);
+extern int reply_notimpl(struct sreply *);
+extern int reply_nxdomain(struct sreply *);
+extern int reply_noerror(struct sreply *);
+extern int reply_soa(struct sreply *);
+extern int reply_mx(struct sreply *, DB *);
+extern int reply_naptr(struct sreply *, DB *);
+extern int reply_ns(struct sreply *, DB *);
+extern int reply_ptr(struct sreply *);
+extern int reply_refused(struct sreply *);
+extern int reply_spf(struct sreply *);
+extern int reply_srv(struct sreply *, DB *);
+extern int reply_sshfp(struct sreply *);
+extern int reply_txt(struct sreply *);
extern int remotelog(int, char *, ...);
extern char *rrlimit_setup(int);
@@ -172,7 +172,7 @@ static struct tcps {
} *tn1, *tnp, *tntmp;
-static const char rcsid[] = "$Id: main.c,v 1.100 2014/09/29 16:38:31 pjp Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.101 2014/10/08 21:00:55 pjp Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -1969,7 +1969,7 @@ mainloop(struct cfg *cfg)
{
fd_set rset;
int sel;
- int len;
+ int len, slen;
int is_ipv6;
int i;
int istcp = 1;
@@ -2314,7 +2314,7 @@ mainloop(struct cfg *cfg)
from, fromlen, NULL, NULL, tnp->region,
istcp, tnp->wildcard, NULL, replybuf);
- reply_fmterror(&sreply);
+ slen = reply_fmterror(&sreply);
dolog(LOG_INFO, "TCP question on descriptor %d interface \"%s\" from %s, did not have question of 1 replying format error\n", tnp->so, tnp->ident, tnp->address);
goto drop;
}
@@ -2359,7 +2359,7 @@ mainloop(struct cfg *cfg)
&sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_noerror(&sreply);
+ slen = reply_noerror(&sreply);
goto tcpout;
}
@@ -2386,7 +2386,7 @@ tcpnxdomain:
tnp->region, istcp, tnp->wildcard, NULL,
replybuf);
- reply_nxdomain(&sreply);
+ slen = reply_nxdomain(&sreply);
goto tcpout;
case DNS_TYPE_CNAME:
fakequestion = build_fake_question(sd0.cname, sd0.cnamelen, question->hdr->qtype);
@@ -2420,7 +2420,7 @@ tcpnxdomain:
from, fromlen, NULL, NULL, tnp->region,
istcp, tnp->wildcard, NULL, replybuf);
- reply_notimpl(&sreply);
+ slen = reply_notimpl(&sreply);
snprintf(replystring, DNS_MAXNAME, "NOTIMPL");
goto tcpout;
}
@@ -2431,7 +2431,7 @@ tcpnxdomain:
build_reply(&sreply, tnp->so, pbuf, len, question, from, \
fromlen, &sd0, ((type1 > 0) ? &sd1 : NULL), \
tnp->region, istcp, tnp->wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, tnp->so, pbuf, len, question,
@@ -2439,13 +2439,13 @@ tcpnxdomain:
tnp->region, istcp, tnp->wildcard, NULL,
replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_A) {
build_reply(&sreply, tnp->so, pbuf, len, question, from, \
fromlen, &sd0, NULL, tnp->region, istcp, tnp->wildcard,
NULL, replybuf);
- reply_a(&sreply, cfg->db);
+ slen = reply_a(&sreply, cfg->db);
break; /* must break here */
}
@@ -2456,7 +2456,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp, tnp->wildcard,
NULL, replybuf);
- reply_any(&sreply);
+ slen = reply_any(&sreply);
break; /* must break here */
case DNS_TYPE_AAAA:
@@ -2465,20 +2465,20 @@ tcpnxdomain:
build_reply(&sreply, tnp->so, pbuf, len, question, from, \
fromlen, &sd0, ((type1 > 0) ? &sd1 : NULL), \
tnp->region, istcp, tnp->wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, tnp->so, pbuf, len, question, from, \
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_AAAA) {
build_reply(&sreply, tnp->so, pbuf, len, question, from,
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_aaaa(&sreply, cfg->db);
+ slen = reply_aaaa(&sreply, cfg->db);
break; /* must break here */
}
@@ -2490,14 +2490,14 @@ tcpnxdomain:
fromlen, &sd0, ((type1 > 0) ? &sd1 : NULL), \
tnp->region, istcp, tnp->wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, tnp->so, pbuf, len, question, from, \
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_MX) {
@@ -2505,7 +2505,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_mx(&sreply, cfg->db);
+ slen = reply_mx(&sreply, cfg->db);
break; /* must break here */
}
@@ -2516,13 +2516,13 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_soa(&sreply);
+ slen = reply_soa(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, tnp->so, pbuf, len, question, from, \
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
}
break;
@@ -2532,7 +2532,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
}
break;
@@ -2542,7 +2542,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_sshfp(&sreply);
+ slen = reply_sshfp(&sreply);
}
break;
@@ -2553,7 +2553,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_srv(&sreply, cfg->db);
+ slen = reply_srv(&sreply, cfg->db);
}
break;
@@ -2563,7 +2563,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_naptr(&sreply, cfg->db);
+ slen = reply_naptr(&sreply, cfg->db);
}
break;
@@ -2573,13 +2573,13 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, tnp->so, pbuf, len, question, from, \
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
}
break;
@@ -2591,7 +2591,7 @@ tcpnxdomain:
, tnp->region, istcp, tnp->wildcard, NULL,
replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
@@ -2599,7 +2599,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_PTR) {
@@ -2608,7 +2608,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ptr(&sreply);
+ slen = reply_ptr(&sreply);
break; /* must break here */
}
break;
@@ -2620,7 +2620,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_txt(&sreply);
+ slen = reply_txt(&sreply);
}
break;
@@ -2631,7 +2631,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_spf(&sreply);
+ slen = reply_spf(&sreply);
}
break;
@@ -2651,7 +2651,7 @@ tcpnxdomain:
fromlen, &sd0, NULL, aregion, istcp,
tnp->wildcard, NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
} else {
@@ -2659,7 +2659,7 @@ tcpnxdomain:
fromlen, NULL, NULL, tnp->region, istcp,
tnp->wildcard, NULL, replybuf);
- reply_notimpl(&sreply);
+ slen = reply_notimpl(&sreply);
snprintf(replystring, DNS_MAXNAME, "NOTIMPL");
}
break;
@@ -2837,7 +2837,7 @@ axfrentry:
/* format error */
build_reply(&sreply, so, buf, len, NULL, from, fromlen, NULL, NULL, aregion, istcp, wildcard, NULL, replybuf);
- reply_fmterror(&sreply);
+ slen = reply_fmterror(&sreply);
dolog(LOG_INFO, "question on descriptor %d interface \"%s\" from %s, did not have question of 1 replying format error\n", so, cfg->ident[i], address);
goto drop;
}
@@ -2845,7 +2845,7 @@ axfrentry:
if (filter) {
build_reply(&sreply, so, buf, len, NULL, from, fromlen, NULL, NULL, aregion, istcp, wildcard, NULL, replybuf);
- reply_refused(&sreply);
+ slen = reply_refused(&sreply);
dolog(LOG_INFO, "UDP connection refused on descriptor %u interface \"%s\" from %s (ttl=%d, region=%d) replying REFUSED, filter policy\n", so, cfg->ident[i], address, received_ttl, aregion);
goto drop;
@@ -2854,7 +2854,7 @@ axfrentry:
if (whitelist && blacklist == 0) {
build_reply(&sreply, so, buf, len, NULL, from, fromlen, NULL, NULL, aregion, istcp, wildcard, NULL, replybuf);
- reply_refused(&sreply);
+ slen = reply_refused(&sreply);
dolog(LOG_INFO, "UDP connection refused on descriptor %u interface \"%s\" from %s (ttl=%d, region=%d) replying REFUSED, whitelist policy\n", so, cfg->ident[i], address, received_ttl, aregion);
goto drop;
@@ -2915,7 +2915,7 @@ axfrentry:
fromlen, &sd0, NULL, aregion, istcp, wildcard,
NULL, replybuf);
- reply_noerror(&sreply);
+ slen = reply_noerror(&sreply);
goto udpout;
} /* else rflag */
}
@@ -2950,7 +2950,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, \
wildcard, NULL, replybuf);
- reply_nxdomain(&sreply);
+ slen = reply_nxdomain(&sreply);
goto udpout;
} /* else rflag */
case DNS_TYPE_CNAME:
@@ -2985,7 +2985,7 @@ udpnxdomain:
fromlen, NULL, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_notimpl(&sreply);
+ slen = reply_notimpl(&sreply);
snprintf(replystring, DNS_MAXNAME, "NOTIMPL");
goto udpout;
}
@@ -2998,14 +2998,14 @@ udpnxdomain:
fromlen, &sd0, ((type1 > 0) ? &sd1 : NULL), \
aregion, istcp, wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, buf, len, question, from, \
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_A) {
@@ -3013,7 +3013,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard,
NULL, replybuf);
- reply_a(&sreply, cfg->db);
+ slen = reply_a(&sreply, cfg->db);
break; /* must break here */
}
@@ -3025,7 +3025,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, NULL,
replybuf);
- reply_any(&sreply);
+ slen = reply_any(&sreply);
break; /* must break here */
case DNS_TYPE_AAAA:
@@ -3036,14 +3036,14 @@ udpnxdomain:
fromlen, &sd0, ((type1 > 0) ? &sd1 : NULL), \
aregion, istcp, wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, buf, len, question, from, \
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_AAAA) {
@@ -3051,7 +3051,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard,
NULL, replybuf);
- reply_aaaa(&sreply, cfg->db);
+ slen = reply_aaaa(&sreply, cfg->db);
break; /* must break here */
}
@@ -3064,20 +3064,20 @@ udpnxdomain:
fromlen, &sd0, ((type1 > 0) ? &sd1 : NULL), \
aregion, istcp, wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, buf, len, question, from, \
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_MX) {
build_reply(&sreply, so, buf, len, question, from, \
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_mx(&sreply, cfg->db);
+ slen = reply_mx(&sreply, cfg->db);
break; /* must break here */
}
@@ -3089,14 +3089,14 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_soa(&sreply);
+ slen = reply_soa(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, buf, len, question, from, \
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
}
break;
@@ -3107,7 +3107,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
}
break;
@@ -3117,7 +3117,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_sshfp(&sreply);
+ slen = reply_sshfp(&sreply);
}
break;
@@ -3129,7 +3129,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_srv(&sreply, cfg->db);
+ slen = reply_srv(&sreply, cfg->db);
}
break;
@@ -3140,7 +3140,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_naptr(&sreply, cfg->db);
+ slen = reply_naptr(&sreply, cfg->db);
}
break;
@@ -3151,14 +3151,14 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, buf, len, question, from, \
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
}
break;
@@ -3170,14 +3170,14 @@ udpnxdomain:
fromlen, &sd0, ((type1 > 0) ? &sd1 : NULL) \
, aregion, istcp, wildcard, NULL, replybuf);
- reply_cname(&sreply);
+ slen = reply_cname(&sreply);
} else if (type0 == DNS_TYPE_NS) {
build_reply(&sreply, so, buf, len, question, from, \
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
break;
} else if (type0 == DNS_TYPE_PTR) {
@@ -3185,7 +3185,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ptr(&sreply);
+ slen = reply_ptr(&sreply);
break; /* must break here */
}
break;
@@ -3196,7 +3196,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_txt(&sreply);
+ slen = reply_txt(&sreply);
}
break;
case DNS_TYPE_SPF:
@@ -3206,7 +3206,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_spf(&sreply);
+ slen = reply_spf(&sreply);
}
break;
default:
@@ -3224,7 +3224,7 @@ udpnxdomain:
fromlen, &sd0, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_ns(&sreply, cfg->db);
+ slen = reply_ns(&sreply, cfg->db);
} else {
@@ -3232,7 +3232,7 @@ udpnxdomain:
fromlen, NULL, NULL, aregion, istcp, wildcard, \
NULL, replybuf);
- reply_notimpl(&sreply);
+ slen = reply_notimpl(&sreply);
snprintf(replystring, DNS_MAXNAME, "NOTIMPL");
}
break;
@@ -3240,12 +3240,12 @@ udpnxdomain:
udpout:
if (lflag) {
- dolog(LOG_INFO, "request on descriptor %u interface \"%s\" from %s (ttl=%u, region=%d) for \"%s\" type=%s class=%u, %s%sanswering \"%s\"\n", so, cfg->ident[i], address, received_ttl, aregion, question->converted_name, get_dns_type(ntohs(question->hdr->qtype)), ntohs(question->hdr->qclass), (question->edns0len ? "edns0, " : ""), (question->dnssecok ? "dnssecok, " : "") , replystring);
+ dolog(LOG_INFO, "request on descriptor %u interface \"%s\" from %s (ttl=%u, region=%d) for \"%s\" type=%s class=%u, %s%sanswering \"%s\" (%d/%d)\n", so, cfg->ident[i], address, received_ttl, aregion, question->converted_name, get_dns_type(ntohs(question->hdr->qtype)), ntohs(question->hdr->qclass), (question->edns0len ? "edns0, " : ""), (question->dnssecok ? "dnssecok, " : "") , replystring, len, slen);
}
if (logging.active == 1 && logging.bind == 0) {
- remotelog(lfd, "request on descriptor %u interface \"%s\" from %s (ttl=%u, region=%d) for \"%s\" type=%s class=%u, %s%sanswering \"%s\"", so, cfg->ident[i], address, received_ttl, aregion, question->converted_name, get_dns_type(ntohs(question->hdr->qtype)), ntohs(question->hdr->qclass), (question->edns0len ? "edns0, ": ""), (question->dnssecok ? "dnssecok" : ""), replystring);
+ remotelog(lfd, "request on descriptor %u interface \"%s\" from %s (ttl=%u, region=%d) for \"%s\" type=%s class=%u, %s%sanswering \"%s\" (%d/%d)", so, cfg->ident[i], address, received_ttl, aregion, question->converted_name, get_dns_type(ntohs(question->hdr->qtype)), ntohs(question->hdr->qclass), (question->edns0len ? "edns0, ": ""), (question->dnssecok ? "dnssecok" : ""), replystring, len, slen);
}
if (fakequestion != NULL) {
blob - e66391521f464284b18d61e12b51317fc7db5300
blob + 42d21bf1baaf42bc9e3a7c3372c53105d4aeb015
--- reply.c
+++ reply.c
@@ -48,26 +48,26 @@ struct domain *Lookup_zone(DB *, char *, u_int16_t, u
void collects_init(void);
u_int16_t create_anyreply(struct sreply *, char *, int, int, int);
u_short in_cksum(const u_short *, register int, int);
-void reply_a(struct sreply *, DB *);
-void reply_aaaa(struct sreply *, DB *);
-void reply_mx(struct sreply *, DB *);
-void reply_ns(struct sreply *, DB *);
-void reply_notimpl(struct sreply *);
-void reply_nxdomain(struct sreply *);
-void reply_noerror(struct sreply *);
-void reply_soa(struct sreply *);
-void reply_ptr(struct sreply *);
-void reply_txt(struct sreply *);
-void reply_spf(struct sreply *);
-void reply_srv(struct sreply *, DB *);
-void reply_naptr(struct sreply *, DB *);
-void reply_sshfp(struct sreply *);
-void reply_cname(struct sreply *);
-void reply_any(struct sreply *);
-void reply_refused(struct sreply *);
-void reply_fmterror(struct sreply *);
-void reply_raw2(int, char *, int, struct recurses *);
-void reply_raw6(int, char *, int, struct recurses *);
+int reply_a(struct sreply *, DB *);
+int reply_aaaa(struct sreply *, DB *);
+int reply_mx(struct sreply *, DB *);
+int reply_ns(struct sreply *, DB *);
+int reply_notimpl(struct sreply *);
+int reply_nxdomain(struct sreply *);
+int reply_noerror(struct sreply *);
+int reply_soa(struct sreply *);
+int reply_ptr(struct sreply *);
+int reply_txt(struct sreply *);
+int reply_spf(struct sreply *);
+int reply_srv(struct sreply *, DB *);
+int reply_naptr(struct sreply *, DB *);
+int reply_sshfp(struct sreply *);
+int reply_cname(struct sreply *);
+int reply_any(struct sreply *);
+int reply_refused(struct sreply *);
+int reply_fmterror(struct sreply *);
+int reply_raw2(int, char *, int, struct recurses *);
+int reply_raw6(int, char *, int, struct recurses *);
void update_db(DB *, struct domain *);
#ifdef __linux__
@@ -89,14 +89,14 @@ struct collects {
extern int debug, verbose;
-static const char rcsid[] = "$Id: reply.c,v 1.59 2014/05/18 17:14:05 pjp Exp $";
+static const char rcsid[] = "$Id: reply.c,v 1.60 2014/10/08 21:00:55 pjp Exp $";
/*
* REPLY_A() - replies a DNS question (*q) on socket (so)
*
*/
-void
+int
reply_a(struct sreply *sreply, DB *db)
{
char *reply = sreply->replybuf;
@@ -128,6 +128,7 @@ reply_a(struct sreply *sreply, DB *db)
u_int8_t region = sreply->region;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -141,7 +142,7 @@ reply_a(struct sreply *sreply, DB *db)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
@@ -230,7 +231,7 @@ reply_a(struct sreply *sreply, DB *db)
out:
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -245,12 +246,12 @@ out:
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
@@ -264,7 +265,7 @@ out:
sd->a_count = mod; /* I know I know */
update_db(db, sd);
- return;
+ return (retlen);
}
/*
@@ -272,7 +273,7 @@ out:
*
*/
-void
+int
reply_aaaa(struct sreply *sreply, DB *db)
{
char *reply = sreply->replybuf;
@@ -301,6 +302,7 @@ reply_aaaa(struct sreply *sreply, DB *db)
struct domain *sd = sreply->sd1;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -315,7 +317,7 @@ reply_aaaa(struct sreply *sreply, DB *db)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
@@ -382,7 +384,7 @@ reply_aaaa(struct sreply *sreply, DB *db)
out:
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -397,12 +399,12 @@ out:
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
@@ -412,7 +414,7 @@ out:
sd->aaaa_count = mod;
update_db(db, sd);
- return;
+ return (retlen);
}
/*
@@ -420,7 +422,7 @@ out:
*
*/
-void
+int
reply_mx(struct sreply *sreply, DB *db)
{
char *reply = sreply->replybuf;
@@ -455,6 +457,7 @@ reply_mx(struct sreply *sreply, DB *db)
int istcp = sreply->istcp;
int wildcard = sreply->wildcard;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -468,7 +471,7 @@ reply_mx(struct sreply *sreply, DB *db)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
@@ -601,7 +604,7 @@ reply_mx(struct sreply *sreply, DB *db)
out:
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -614,18 +617,18 @@ out:
*plen = htons(outlen);
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/*
@@ -633,7 +636,7 @@ out:
*
*/
-void
+int
reply_ns(struct sreply *sreply, DB *db)
{
char *reply = sreply->replybuf;
@@ -669,6 +672,7 @@ reply_ns(struct sreply *sreply, DB *db)
int istcp = sreply->istcp;
int wildcard = sreply->wildcard;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -682,7 +686,7 @@ reply_ns(struct sreply *sreply, DB *db)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
@@ -847,7 +851,7 @@ reply_ns(struct sreply *sreply, DB *db)
out:
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -860,12 +864,12 @@ out:
*plen = htons(outlen);
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
@@ -876,7 +880,7 @@ out:
update_db(db, sd);
- return;
+ return (retlen);
}
@@ -886,7 +890,7 @@ out:
*/
-void
+int
reply_cname(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -920,6 +924,7 @@ reply_cname(struct sreply *sreply)
struct domain *sd1 = sreply->sd2;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -932,7 +937,7 @@ reply_cname(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -986,7 +991,7 @@ reply_cname(struct sreply *sreply)
}
if (i >= replysize)
- return ;
+ return (retlen);
outlen = i;
@@ -1047,7 +1052,7 @@ reply_cname(struct sreply *sreply)
}
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -1061,18 +1066,18 @@ reply_cname(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/*
@@ -1080,7 +1085,7 @@ reply_cname(struct sreply *sreply)
*
*/
-void
+int
reply_ptr(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -1111,6 +1116,7 @@ reply_ptr(struct sreply *sreply)
struct domain *sd = sreply->sd1;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -1124,7 +1130,7 @@ reply_ptr(struct sreply *sreply)
if (len > replysize) {
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -1177,7 +1183,7 @@ reply_ptr(struct sreply *sreply)
}
if (i >= replysize) {
- return ;
+ return (retlen);
}
outlen = i;
@@ -1199,7 +1205,7 @@ reply_ptr(struct sreply *sreply)
}
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -1214,18 +1220,18 @@ reply_ptr(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/*
@@ -1234,7 +1240,7 @@ reply_ptr(struct sreply *sreply)
*/
-void
+int
reply_soa(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -1277,6 +1283,7 @@ reply_soa(struct sreply *sreply)
struct domain *sd = sreply->sd1;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -1291,7 +1298,7 @@ reply_soa(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -1345,7 +1352,7 @@ reply_soa(struct sreply *sreply)
}
if (i >= replysize) {
- return ;
+ return (retlen);
}
outlen = i;
@@ -1367,7 +1374,7 @@ reply_soa(struct sreply *sreply)
}
if (i >= replysize) {
- return ;
+ return (retlen);
}
outlen = i;
@@ -1382,7 +1389,7 @@ reply_soa(struct sreply *sreply)
/* XXX */
if ((outlen + sizeof(sd->soa.serial)) > replysize) {
/* XXX server error reply? */
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.serial);
@@ -1390,28 +1397,28 @@ reply_soa(struct sreply *sreply)
/* XXX */
if ((outlen + sizeof(sd->soa.refresh)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.refresh);
outlen += sizeof(sd->soa.refresh); /* XXX */
if ((outlen + sizeof(sd->soa.retry)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.retry);
outlen += sizeof(sd->soa.retry); /* XXX */
if ((outlen + sizeof(sd->soa.expire)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.expire);
outlen += sizeof(sd->soa.expire);
if ((outlen + sizeof(sd->soa.minttl)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.minttl);
@@ -1429,7 +1436,7 @@ reply_soa(struct sreply *sreply)
}
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -1444,18 +1451,18 @@ reply_soa(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/*
@@ -1464,7 +1471,7 @@ reply_soa(struct sreply *sreply)
*/
-void
+int
reply_spf(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -1492,6 +1499,7 @@ reply_spf(struct sreply *sreply)
struct domain *sd = sreply->sd1;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -1506,7 +1514,7 @@ reply_spf(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -1561,7 +1569,7 @@ reply_spf(struct sreply *sreply)
}
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -1576,18 +1584,18 @@ reply_spf(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/*
@@ -1596,7 +1604,7 @@ reply_spf(struct sreply *sreply)
*/
-void
+int
reply_txt(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -1624,6 +1632,7 @@ reply_txt(struct sreply *sreply)
struct domain *sd = sreply->sd1;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -1638,7 +1647,7 @@ reply_txt(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -1693,7 +1702,7 @@ reply_txt(struct sreply *sreply)
}
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -1708,18 +1717,18 @@ reply_txt(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/*
@@ -1728,7 +1737,7 @@ reply_txt(struct sreply *sreply)
*/
-void
+int
reply_sshfp(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -1760,6 +1769,7 @@ reply_sshfp(struct sreply *sreply)
int istcp = sreply->istcp;
int typelen = 0;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -1774,7 +1784,7 @@ reply_sshfp(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
@@ -1820,7 +1830,7 @@ reply_sshfp(struct sreply *sreply)
break;
default:
dolog(LOG_ERR, "oops bad sshfp type? not returning a packet!\n");
- return;
+ return (retlen);
}
answer->rdlength = htons((2 * sizeof(u_int8_t)) + typelen);
@@ -1853,7 +1863,7 @@ reply_sshfp(struct sreply *sreply)
out:
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -1866,18 +1876,18 @@ out:
*plen = htons(outlen);
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
@@ -1887,7 +1897,7 @@ out:
*/
-void
+int
reply_naptr(struct sreply *sreply, DB *db)
{
char *reply = sreply->replybuf;
@@ -1925,6 +1935,7 @@ reply_naptr(struct sreply *sreply, DB *db)
int replysize = 512;
int tmplen, savelen;
char *p;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -1938,7 +1949,7 @@ reply_naptr(struct sreply *sreply, DB *db)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
@@ -2102,7 +2113,7 @@ reply_naptr(struct sreply *sreply, DB *db)
out:
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -2115,18 +2126,18 @@ out:
*plen = htons(outlen);
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
@@ -2136,7 +2147,7 @@ out:
*/
-void
+int
reply_srv(struct sreply *sreply, DB *db)
{
char *reply = sreply->replybuf;
@@ -2173,6 +2184,7 @@ reply_srv(struct sreply *sreply, DB *db)
int istcp = sreply->istcp;
int wildcard = sreply->wildcard;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -2186,7 +2198,7 @@ reply_srv(struct sreply *sreply, DB *db)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, sizeof(struct dns_header) + q->hdr->namelen + 4);
@@ -2322,7 +2334,7 @@ reply_srv(struct sreply *sreply, DB *db)
out:
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -2335,18 +2347,18 @@ out:
*plen = htons(outlen);
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
@@ -2356,7 +2368,7 @@ out:
*/
-void
+int
reply_notimpl(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -2370,6 +2382,7 @@ reply_notimpl(struct sreply *sreply)
int salen = sreply->salen;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -2385,7 +2398,7 @@ reply_notimpl(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy(reply, buf, len);
@@ -2411,17 +2424,17 @@ reply_notimpl(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, len, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, len, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
- return;
+ return (retlen);
}
/*
@@ -2429,7 +2442,7 @@ reply_notimpl(struct sreply *sreply)
*
*/
-void
+int
reply_nxdomain(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -2472,6 +2485,7 @@ reply_nxdomain(struct sreply *sreply)
struct domain *sd = sreply->sd1;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -2481,7 +2495,7 @@ reply_nxdomain(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
@@ -2506,7 +2520,7 @@ reply_nxdomain(struct sreply *sreply)
HTONS(odh->query);
if (sreply->sr != NULL) {
- reply_raw2(so, reply, len, sreply->sr);
+ retlen = reply_raw2(so, reply, len, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -2521,18 +2535,18 @@ reply_nxdomain(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, len);
- if (send(so, tmpbuf, len + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, len + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, len, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, len, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -2576,7 +2590,7 @@ reply_nxdomain(struct sreply *sreply)
#if 0
label = dns_label((char *)mysoa.nsserver, &labellen);
if (label == NULL)
- return;
+ return (retlen);
#endif
label = &sd->soa.nsserver[0];
@@ -2593,7 +2607,7 @@ reply_nxdomain(struct sreply *sreply)
}
if (i >= replysize) {
- return ;
+ return (retlen);
}
outlen = i;
@@ -2615,7 +2629,7 @@ reply_nxdomain(struct sreply *sreply)
}
if (i >= replysize) {
- return ;
+ return (retlen);
}
outlen = i;
@@ -2630,35 +2644,35 @@ reply_nxdomain(struct sreply *sreply)
/* XXX */
if ((outlen + sizeof(sd->soa.serial)) > replysize) {
/* XXX server error reply? */
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.serial);
outlen += sizeof(sd->soa.serial);
if ((outlen + sizeof(sd->soa.refresh)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.refresh);
outlen += sizeof(sd->soa.refresh);
if ((outlen + sizeof(sd->soa.retry)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.retry);
outlen += sizeof(sd->soa.retry);
if ((outlen + sizeof(sd->soa.expire)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.expire);
outlen += sizeof(sd->soa.expire);
if ((outlen + sizeof(sd->soa.minttl)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.minttl);
@@ -2667,7 +2681,7 @@ reply_nxdomain(struct sreply *sreply)
answer->rdlength = htons(&reply[outlen] - &answer->rdata);
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
@@ -2683,18 +2697,18 @@ reply_nxdomain(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
} /* sreply->sr.. */
- return;
+ return (retlen);
}
/*
@@ -2702,7 +2716,7 @@ reply_nxdomain(struct sreply *sreply)
*
*/
-void
+int
reply_refused(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -2716,6 +2730,7 @@ reply_refused(struct sreply *sreply)
int salen = sreply->salen;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -2728,7 +2743,7 @@ reply_refused(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy((char *)&odh->id, buf, sizeof(u_int16_t));
@@ -2752,17 +2767,17 @@ reply_refused(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, sizeof(struct dns_header), 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, sizeof(struct dns_header), 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
- return;
+ return (retlen);
}
/*
@@ -2770,7 +2785,7 @@ reply_refused(struct sreply *sreply)
*
*/
-void
+int
reply_fmterror(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -2784,6 +2799,7 @@ reply_fmterror(struct sreply *sreply)
int salen = sreply->salen;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -2796,7 +2812,7 @@ reply_fmterror(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
memcpy((char *)&odh->id, buf, sizeof(u_int16_t));
@@ -2820,17 +2836,17 @@ reply_fmterror(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, sizeof(struct dns_header), 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, sizeof(struct dns_header), 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
- return;
+ return (retlen);
}
/*
@@ -2839,7 +2855,7 @@ reply_fmterror(struct sreply *sreply)
*
*/
-void
+int
reply_noerror(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -2882,6 +2898,7 @@ reply_noerror(struct sreply *sreply)
struct domain *sd = sreply->sd1;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -2894,7 +2911,7 @@ reply_noerror(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
@@ -2927,17 +2944,17 @@ reply_noerror(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, len);
- if (send(so, tmpbuf, len + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, len + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, len, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, len, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -2991,7 +3008,7 @@ reply_noerror(struct sreply *sreply)
}
if (i >= replysize) {
- return ;
+ return (retlen);
}
outlen = i;
@@ -3013,7 +3030,7 @@ reply_noerror(struct sreply *sreply)
}
if (i >= replysize) {
- return ;
+ return (retlen);
}
outlen = i;
@@ -3028,35 +3045,35 @@ reply_noerror(struct sreply *sreply)
/* XXX */
if ((outlen + sizeof(sd->soa.serial)) > replysize) {
/* XXX server error reply? */
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.serial);
outlen += sizeof(sd->soa.serial);
if ((outlen + sizeof(sd->soa.refresh)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.refresh);
outlen += sizeof(sd->soa.refresh);
if ((outlen + sizeof(sd->soa.retry)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.retry);
outlen += sizeof(sd->soa.retry);
if ((outlen + sizeof(sd->soa.expire)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.expire);
outlen += sizeof(sd->soa.expire);
if ((outlen + sizeof(sd->soa.minttl)) > replysize) {
- return;
+ return (retlen);
}
soa_val = (u_int32_t *)&reply[outlen];
*soa_val = htonl(sd->soa.minttl);
@@ -3074,7 +3091,7 @@ reply_noerror(struct sreply *sreply)
}
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -3089,18 +3106,18 @@ reply_noerror(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
void
@@ -3178,7 +3195,7 @@ collects_init(void)
SLIST_INIT(&collectshead);
}
-void
+int
reply_raw2(int so, char *reply, int outlen, struct recurses *sr)
{
char buf[2048];
@@ -3190,10 +3207,11 @@ reply_raw2(int so, char *reply, int outlen, struct rec
struct udphdr *udp;
int udplen = outlen + sizeof(struct udphdr);
struct sockaddr_in *sin_src, *sin_dst;
+ int retlen = -1;
if (sr->af == AF_INET6) {
- reply_raw6(so, reply, outlen, sr);
- return;
+ retlen = reply_raw6(so, reply, outlen, sr);
+ return (retlen);
}
#ifdef __linux__
@@ -3273,12 +3291,14 @@ reply_raw2(int so, char *reply, int outlen, struct rec
#endif
#ifdef __linux__
- if (sendto(so, buf, sizeof(struct iphdr) + udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr)) < 0) {
+ if ((retlen = sendto(so, buf, sizeof(struct iphdr) + udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr))) < 0) {
#else
- if (sendto(so, buf, sizeof(struct ip) + udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr)) < 0) {
+ if ((retlen = sendto(so, buf, sizeof(struct ip) + udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr))) < 0) {
#endif
dolog(LOG_ERR, "sendto: %s\n", strerror(errno));
}
+
+ return (retlen);
}
/*
@@ -3286,7 +3306,7 @@ reply_raw2(int so, char *reply, int outlen, struct rec
*
*/
-void
+int
reply_raw6(int so, char *reply, int outlen, struct recurses *sr)
{
char buf[2048];
@@ -3298,6 +3318,7 @@ reply_raw6(int so, char *reply, int outlen, struct rec
struct sockaddr_in6 sin6;
struct ip6_hdr_pseudo *pseudo;
+ int retlen = -1;
udp = (struct udphdr *)&buf[0];
memcpy(&buf[sizeof(struct udphdr)], reply, outlen);
@@ -3323,7 +3344,7 @@ reply_raw6(int so, char *reply, int outlen, struct rec
if (bind(so, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
dolog(LOG_ERR, "bind6: %s\n", strerror(errno));
- return;
+ return (retlen);
}
memset(&sin6, 0, sizeof(sin6));
@@ -3349,9 +3370,11 @@ reply_raw6(int so, char *reply, int outlen, struct rec
#endif
- if (sendto(so, buf, udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr_in6)) < 0) {
+ if ((retlen = sendto(so, buf, udplen, 0, (struct sockaddr *)(&sr->dest), sizeof(struct sockaddr_in6))) < 0) {
dolog(LOG_ERR, "sendto: %s\n", strerror(errno));
}
+
+ return (retlen);
}
@@ -3448,7 +3471,7 @@ in_cksum(const u_short *addr, register int len, int cs
return (answer);
}
-void
+int
reply_any(struct sreply *sreply)
{
char *reply = sreply->replybuf;
@@ -3463,6 +3486,7 @@ reply_any(struct sreply *sreply)
int salen = sreply->salen;
int istcp = sreply->istcp;
int replysize = 512;
+ int retlen = -1;
if (istcp) {
replysize = 65535;
@@ -3477,7 +3501,7 @@ reply_any(struct sreply *sreply)
outlen = sizeof(struct dns_header);
if (len > replysize) {
- return;
+ return (retlen);
}
/* copy question to reply */
@@ -3502,7 +3526,7 @@ reply_any(struct sreply *sreply)
outlen = create_anyreply(sreply, (char *)reply, replysize, outlen, 1);
if (outlen == 0) {
- return;
+ return (retlen);
}
if (q->edns0len) {
@@ -3515,7 +3539,7 @@ reply_any(struct sreply *sreply)
}
if (sreply->sr != NULL) {
- reply_raw2(so, reply, outlen, sreply->sr);
+ retlen = reply_raw2(so, reply, outlen, sreply->sr);
} else {
if (istcp) {
char *tmpbuf;
@@ -3530,18 +3554,18 @@ reply_any(struct sreply *sreply)
memcpy(&tmpbuf[2], reply, outlen);
- if (send(so, tmpbuf, outlen + 2, 0) < 0) {
+ if ((retlen = send(so, tmpbuf, outlen + 2, 0)) < 0) {
dolog(LOG_INFO, "send: %s\n", strerror(errno));
}
free(tmpbuf);
} else {
- if (sendto(so, reply, outlen, 0, sa, salen) < 0) {
+ if ((retlen = sendto(so, reply, outlen, 0, sa, salen)) < 0) {
dolog(LOG_INFO, "sendto: %s\n", strerror(errno));
}
}
}
- return;
+ return (retlen);
}
/*
repomaster@centroid.eu