From 723eff91623a682dc245fe95bf14d8edfb04ac7d Mon Sep 17 00:00:00 2001 From: Sam Trenholme Date: Thu, 24 Nov 2022 01:57:20 -0800 Subject: [PATCH] Add RFC8482 support to Deadwood Here in the 2020s, ANY queries are no more, as per RFC8482. Make it so in Deadwood. Related: https://github.com/samboy/MaraDNS/discussions/116 --- deadwood-github/src/DwSocket.h | 5 ++- deadwood-github/src/DwUdpSocket.c | 61 +++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/deadwood-github/src/DwSocket.h b/deadwood-github/src/DwSocket.h index b61b16c0..1479f20a 100644 --- a/deadwood-github/src/DwSocket.h +++ b/deadwood-github/src/DwSocket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2007-2019 Sam Trenholme +/* Copyright (c) 2007-2022 Sam Trenholme * * TERMS * @@ -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__ */ diff --git a/deadwood-github/src/DwUdpSocket.c b/deadwood-github/src/DwUdpSocket.c index 6bb04c94..2e002c1d 100644 --- a/deadwood-github/src/DwUdpSocket.c +++ b/deadwood-github/src/DwUdpSocket.c @@ -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; @@ -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; } @@ -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;