Commit Diff
Diff:
b72a627a761724fcdf27c228a353476a507b38aa
987ce2160c85b95de5b60b891d5f11ebcdb94b6f
Commit:
987ce2160c85b95de5b60b891d5f11ebcdb94b6f
Tree:
77d3763f1d55c7b03c60eb7458e95e30088468a8
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Thu Jul 16 07:27:32 2020 UTC
Message:
last commit was still not fully accurate. move two functions from forward.c to util.c and utilize one of those in util.c, when we build fake questions we should lowercase the hdr->name, this way we can make use of hdr->original_name
blob - 25199cbcce0ac2cedfa8934682b8c494bfa242a5
blob + 2f83d9ba3ca956c6887b8c21ee36a3aa77c9ddc6
--- forward.c
+++ forward.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: forward.c,v 1.29 2020/07/16 07:13:13 pjp Exp $
+ * $Id: forward.c,v 1.30 2020/07/16 07:27:32 pjp Exp $
*/
#include <sys/types.h>
@@ -138,8 +138,6 @@ struct tsig * check_tsig(char *, int, char *);
void fwdparseloop(struct imsgbuf *, struct imsgbuf *, struct cfg *);
void changeforwarder(struct forwardqueue *);
void stirforwarders(void);
-void randomize_dnsname(char *buf, int len);
-void lower_dnsname(char *buf, int len);
extern void dolog(int, char *, ...);
extern void pack(char *, char *, int);
@@ -189,6 +187,8 @@ extern int reply_generic(struct sreply *, ddDB *);
extern struct rbtree * create_rr(ddDB *, char *, int, int, void *, uint32_t, uint16_t);
extern void flag_rr(struct rbtree *rbt);
extern struct rbtree * find_rrset(ddDB *, char *, int);
+extern void randomize_dnsname(char *buf, int len);
+extern void lower_dnsname(char *buf, int len);
/*
* XXX everything but txt and naptr, works...
@@ -806,11 +806,11 @@ forwardthis(ddDB *db, struct cfg *cfg, int so, struct
}
if (sforward->havemac)
- q = build_fake_question(sforward->buf, sforward->buflen,
+ q = build_fake_question(savednsname, sforward->buflen,
sforward->type, sforward->tsigname,
sforward->tsignamelen);
else
- q = build_fake_question(sforward->buf, sforward->buflen,
+ q = build_fake_question(savednsname, sforward->buflen,
sforward->type, NULL, 0);
@@ -2158,58 +2158,4 @@ stirforwarders(void)
count++;
}
-}
-
-/* https://tools.ietf.org/html/draft-vixie-dnsext-dns0x20-00 */
-
-void
-randomize_dnsname(char *buf, int len)
-{
- char randompad[DNS_MAXNAME];
- char *p, *q;
- int offset, labellen;
- int i;
- char ch;
-
- if (len > sizeof(randompad))
- return;
-
- arc4random_buf(randompad, sizeof(randompad));
-
- q = &buf[0];
- for (p = q, offset = 0; *p != 0; offset += (*p + 1), p += (*p + 1)) {
- if (offset > DNS_MAXNAME)
- return;
-
- labellen = *p;
- for (i = 1; i < (1 + labellen); i++) {
- ch = q[offset + i];
- q[offset + i] = (randompad[offset + i] & 1) ? toupper(ch) : ch;
- }
- }
-
- return;
-}
-
-void
-lower_dnsname(char *buf, int len)
-{
- char *p, *q;
- int offset, labellen;
- int i;
- char ch;
-
- q = &buf[0];
- for (p = q, offset = 0; *p != 0; offset += (*p + 1), p += (*p + 1)) {
- if (offset > DNS_MAXNAME)
- return;
-
- labellen = *p;
- for (i = 1; i < (1 + labellen); i++) {
- ch = tolower(q[offset + i]);
- q[offset + i] = ch;
- }
- }
-
- return;
}
blob - 863550133511760af3e545248f9a31c849654c86
blob + 4e34503e48d54a8043846681dc1afc9e821cc324
--- util.c
+++ util.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: util.c,v 1.68 2020/07/16 06:35:55 pjp Exp $
+ * $Id: util.c,v 1.69 2020/07/16 07:27:32 pjp Exp $
*/
#include <sys/types.h>
@@ -90,6 +90,8 @@ void pack8(char *, u_int8_t);
uint32_t unpack32(char *);
uint16_t unpack16(char *);
void unpack(char *, char *, int);
+void lower_dnsname(char *, int);
+void randomize_dnsname(char *, int);
int label_count(char *);
char * dns_label(char *, int *);
@@ -821,8 +823,10 @@ build_fake_question(char *name, int namelen, u_int16_t
/* fill our name into the dns header struct */
- memcpy(q->hdr->name, name, q->hdr->namelen);
memcpy(q->hdr->original_name, name, q->hdr->namelen);
+
+ lower_dnsname(name, namelen);
+ memcpy(q->hdr->name, name, q->hdr->namelen);
q->hdr->qtype = type;
q->hdr->qclass = htons(DNS_CLASS_IN);
@@ -2323,4 +2327,57 @@ void
unpack(char *buf, char *input, int len)
{
memcpy(buf, input, len);
+}
+
+/* https://tools.ietf.org/html/draft-vixie-dnsext-dns0x20-00 */
+void
+randomize_dnsname(char *buf, int len)
+{
+ char randompad[DNS_MAXNAME];
+ char *p, *q;
+ int offset, labellen;
+ int i;
+ char ch;
+
+ if (len > sizeof(randompad))
+ return;
+
+ arc4random_buf(randompad, sizeof(randompad));
+
+ q = &buf[0];
+ for (p = q, offset = 0; *p != 0; offset += (*p + 1), p += (*p + 1)) {
+ if (offset > DNS_MAXNAME)
+ return;
+
+ labellen = *p;
+ for (i = 1; i < (1 + labellen); i++) {
+ ch = q[offset + i];
+ q[offset + i] = (randompad[offset + i] & 1) ? toupper(ch) : ch;
+ }
+ }
+
+ return;
+}
+
+void
+lower_dnsname(char *buf, int len)
+{
+ char *p, *q;
+ int offset, labellen;
+ int i;
+ char ch;
+
+ q = &buf[0];
+ for (p = q, offset = 0; *p != 0; offset += (*p + 1), p += (*p + 1)) {
+ if (offset > DNS_MAXNAME)
+ return;
+
+ labellen = *p;
+ for (i = 1; i < (1 + labellen); i++) {
+ ch = tolower(q[offset + i]);
+ q[offset + i] = ch;
+ }
+ }
+
+ return;
}
repomaster@centroid.eu