Skip to content

Commit

Permalink
Add RFC8482 support to Deadwood
Browse files Browse the repository at this point in the history
Here in the 2020s, ANY queries are no more, as per RFC8482.

Make it so in Deadwood.

Related:

#116
  • Loading branch information
Sam Trenholme committed Nov 24, 2022
1 parent a84dfa9 commit 723eff9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
5 changes: 4 additions & 1 deletion deadwood-github/src/DwSocket.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2007-2019 Sam Trenholme
/* Copyright (c) 2007-2022 Sam Trenholme
*
* TERMS
*
Expand Down Expand Up @@ -359,5 +359,8 @@ int inet_pton(int z, char *c, uint8_t *ip);
/* Make the actual answer for a synthetic "not there" reply */
unsigned char *make_synth_not_there_answer(unsigned char *a, int *count,
int type);
/* Make a synthetic RFC8482 answer */
unsigned char *make_synth_rfc8482_answer(unsigned char *a, int *count,
int type);

#endif /* __DW_SOCKET_DEFINED__ */
61 changes: 41 additions & 20 deletions deadwood-github/src/DwUdpSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,19 @@ void get_local_udp_packet(SOCKET sock) {

/* Reject PTR or AAAA queries if not wanted */
if((qtype == 28 /* AAAA */ && key_n[DWM_N_reject_aaaa] == 1) ||
(qtype == 12 /* PTR */ && key_n[DWM_N_reject_ptr] == 1)) {
(qtype == 12 /* PTR */ && key_n[DWM_N_reject_ptr] == 1) ||
qtype == 255 || qtype == 13) {
unsigned char *answer;
answer = make_synth_not_there_answer(packet,&len,0);

if(qtype == 255 || qtype == 13) { /* ANY or HINFO */
answer = make_synth_rfc8482_answer(packet,&len,0);
} else {
answer = make_synth_not_there_answer(packet,&len,0);
}

if(answer == 0) {
goto catch_get_local_udp_packet;
}

/* Flag this as an answer */
answer[2] |= 0x80;
Expand Down Expand Up @@ -982,30 +992,20 @@ int verify_dns_packet(int b, unsigned char *packet, int len) {
return ret;
}

/* Make the actual answer for a synthetic "not there" reply */
unsigned char *make_synth_not_there_answer(unsigned char *a, int *count,
int type) {
/* This is the answer for a "not there" reply */
unsigned char not_there[41] =
"\xc0\x0c" /* Name */
"\0\x06" /* Type */
"\0\x01" /* Class */
"\0\0\0\0" /* TTL (don't cache) */
"\0\x1c" /* RDLENGTH */
"\x01\x7a\xc0\x0c" /* Origin */
"\x01\x79\xc0\x0c" /* Email */
"\0\0\0\x01\0\0\0\x01\0\0\0\x01\0\0\0\x01\0\0\0\x01" /* 5 numbers */;
/* Make the actual answer for a synthetic reply */
unsigned char *make_synth_answer(unsigned char *a, int *count,
int type, unsigned char *synth, int slen) {
unsigned char *answer = 0;
int counter = 0;

answer = dw_malloc(*count + 43);
answer = dw_malloc(*count + slen + 3);
if(answer == 0) {
return 0;
}

if(type == 1) { /* Special case: Return just synth "not there" */
for(counter = 0; counter < 40; counter++) {
answer[counter] = not_there[counter];
for(counter = 0; counter < slen; counter++) {
answer[counter] = synth[counter];
}
return answer;
}
Expand Down Expand Up @@ -1036,14 +1036,35 @@ unsigned char *make_synth_not_there_answer(unsigned char *a, int *count,
}

/* Add the SOA reply to the answer */
for(counter = 0; counter < 40; counter++) {
answer[*count + counter] = not_there[counter];
for(counter = 0; counter < slen; counter++) {
answer[*count + counter] = synth[counter];
}

/* Return the answer */
return answer;
}

unsigned char *make_synth_not_there_answer(unsigned char *a, int *count,
int type) {
/* This is the answer for a "not there" reply */
unsigned char not_there[41] =
"\xc0\x0c" /* Name */
"\0\x06" /* Type */
"\0\x01" /* Class */
"\0\0\0\0" /* TTL (don't cache) */
"\0\x1c" /* RDLENGTH */
"\x01\x7a\xc0\x0c" /* Origin */
"\x01\x79\xc0\x0c" /* Email */
"\0\0\0\x01\0\0\0\x01\0\0\0\x01\0\0\0\x01\0\0\0\x01" /* 5 numbers */;
return make_synth_answer(a, count, type, not_there, 40);
}

unsigned char *make_synth_rfc8482_answer(unsigned char *a, int *count,
int type) {
unsigned char AnyAnswer[22] =
"\xc0\x0c\x00\x0d\x00\x01\x00\x01\x51\x80\x00\x09\x07RFC8482\x00";
return make_synth_answer(a, count, type, AnyAnswer, 21);
}
/* Make a synthetic "not there" reply */
void make_synth_not_there(int b, SOCKET sock, unsigned char *a, int count) {
unsigned char *answer = 0;
Expand Down

0 comments on commit 723eff9

Please sign in to comment.