46 logmsg(
server,111,FATAL,
"out of memory");
51 unsigned int pos, zone;
61 unsigned int boxlen = 0;
62 unsigned int qnamelen = 0;
66 if (len >=
sizeof(buf))
goto NOQ;
76 byte_zero((
char *)sandbox,16);
77 byte_zero((
char *)nonce + 12,12);
80 logmsg(
server,99,WARN,
"can't compute shared secret");
84 logmsg(
server,99,WARN,
"can't open cryptobox");
97 if (buf[2] & 1) rd = 1;
100 byte_zero((
char *)sandbox,16);
101 byte_zero((
char *)nonce + 12,12);
104 logmsg(
server,99,WARN,
"can't compute shared secret");
108 logmsg(
server,99,WARN,
"can't open cryptobox");
113 byte_copy((
char *)qname,qnamelen,buf + 12);
114 byte_copy(tid,2,buf);
121 if (header[2] & 128)
goto NOQ;
122 if (header[4])
goto NOQ;
123 if (header[5] != 1)
goto NOQ;
135 if (byte_diff(qclass,2,
DNS_C_ANY))
goto WEIRDCLASS;
137 if (!(header[2] & 1))
response[2] &= ~1;
139 if (header[2] & 126)
goto NOTIMP;
140 if (byte_equal(qtype,2,
DNS_T_AXFR))
goto NOTIMP;
153 if (r) {
qlog(ip,port,header,q,qtype,
" * ");
return 1; }
154 else {
qlog(ip,port,header,q,qtype,
" ~ ");
return 0; }
156 if (r) {
qlog(ip,port,header,q,qtype,
" + ");
return 1; }
157 else {
qlog(ip,port,header,q,qtype,
" - ");
return 0; }
164 qlog(ip,port,header,q,qtype,
" I ");
170 qlog(ip,port,header,q,qtype,
" C ");
174 qlog(ip,port,
"\0\0",
"",
"\0\0",
" / ");
189 logmsg(
server,111,ERROR,
"IP not set");
190 if (case_equals(
x,
"::")) {
192 }
else if (case_equals(
x,
":0")) {
197 logmsg(
server,111,FATAL,B(
"unable to parse IPv6 address: ",
x));
201 if (ip6_isv4mapped(
ip))
202 udp53 = socket_udp4();
204 udp53 = socket_udp();
206 logmsg(
server,111,FATAL,
"unable to create UDP socket");
211 logmsg(
server,111,FATAL,
"unable to bind to UDP socket");
216 if (!stat(
"env/CURVEDNS_PRIVATE_KEY",&st)) {
217 fd = open_read(
"env/CURVEDNS_PRIVATE_KEY");
218 if (
fd == -1) logmsg(
server,111,FATAL,
"unable read CURVEDNS_PRIVATE_KEY");
222 else logmsg(
server,111,FATAL,
"error reading CURVEDNS_PRIVATE_KEY");
230 socket_tryreservein(udp53,65536);
237 if (
len < 0)
continue;
238 if (!
doit())
continue;
unsigned int doit(char *buf, unsigned int len, unsigned int pos)
int dns_curve_txtquery(const char *buf, const unsigned int len, const unsigned int pos)
int dns_curve_txtpubkey(uint8 *pubkey, const char *buf, const unsigned int pos)
int dns_curve_cryptobox(uint8 *cryptobox, const char *buf, const unsigned int len, const unsigned int pos)
int dns_curve_pubkey(uint8 *pubkey, const char *buf, const unsigned int pos)
int dns_curve_query(const char *buf, const unsigned int len, const unsigned int pos)
int response_alttxt(const uint8 *secret, const uint8 *nonce, const char id[2], const unsigned char *query, const unsigned int len, const int rd)
int dns_curve_nonce(uint8 *nonce, const char *buf, const unsigned int pos)
int dns_curve_txtqname(uint8 *base32box, const char *buf, const unsigned int len)
int dns_curve_txtnonce(uint8 *nonce, const uint8 *base32box)
int response_stream(const uint8 *secret, const uint8 *nonce)
#define crypto_box_beforenm
#define crypto_box_open_afternm
unsigned int dns_domain_length(const char *dn)
unsigned int dns_packet_getname(const char *buf, unsigned int len, unsigned int pos, char **d)
unsigned int dns_packet_copy(const char *buf, unsigned int len, unsigned int pos, char *out, unsigned int outlen)
void droproot(const char *server)
void qlog(const char[16], uint16, const char[2], const char *, const char[2], const char *)
void log_start(const char[16], const char[16], uint32)
void response_id(const char[2])
unsigned int response_len
int response_query(const char *, const char[2], const char[2])
unsigned char curvekey[KEY_LEN]
int respond(char *, char *, char *)