42 logmsg(
fatal,111,FATAL,
"out of memory");
47 unsigned int pos, zone;
57 unsigned int boxlen = 0;
58 unsigned int qnamelen = 0;
62 if (len >=
sizeof(buf))
goto NOQ;
72 byte_zero(sandbox,16);
73 byte_zero(nonce + 12,12);
76 logmsg(
fatal,99,WARN,
"can't compute shared secret");
80 logmsg(
fatal,99,WARN,
"can't open cryptobox");
94 if (buf[2] & 1) rd = 1;
97 byte_zero(sandbox,16);
98 byte_zero(nonce + 12,12);
101 logmsg(
fatal,99,WARN,
"can't compute shared secret");
105 logmsg(
fatal,99,WARN,
"can't open cryptobox");
110 byte_copy(qname,qnamelen,buf + 12);
111 byte_copy(tid,2,buf);
119 if (header[2] & 128)
goto NOQ;
120 if (header[4])
goto NOQ;
121 if (header[5] != 1)
goto NOQ;
133 if (byte_diff(qclass,2,
DNS_C_ANY))
goto WEIRDCLASS;
135 if (!(header[2] & 1))
response[2] &= ~1;
137 if (header[2] & 126)
goto NOTIMP;
138 if (byte_equal(qtype,2,
DNS_T_AXFR))
goto NOTIMP;
151 if (r) {
qlog(ip,port,header,q,qtype,
" * ");
return 1; }
152 else {
qlog(ip,port,header,q,qtype,
" ~ ");
return 0; }
154 if (r) {
qlog(ip,port,header,q,qtype,
" + ");
return 1; }
155 else {
qlog(ip,port,header,q,qtype,
" - ");
return 0; }
162 qlog(ip,port,header,q,qtype,
" I ");
168 qlog(ip,port,header,q,qtype,
" C ");
172 qlog(ip,port,
"\0\0",
"",
"\0\0",
" / ");
187 logmsg(
fatal,111,ERROR,
"IP not set");
188 if (case_equals(
x,
"::")) {
190 }
else if (case_equals(
x,
":0")) {
195 logmsg(
fatal,111,FATAL,B(
"unable to parse IPv6 address: ",
x));
199 if (ip6_isv4mapped(
ip))
200 udp53 = socket_udp4();
202 udp53 = socket_udp();
204 logmsg(
fatal,111,FATAL,
"unable to create UDP socket");
209 logmsg(
fatal,111,FATAL,
"unable to bind to UDP socket");
213 if (!stat(
"env/CURVEDNS_PRIVATE_KEY",&st)) {
214 fd = open_read(
"env/CURVEDNS_PRIVATE_KEY");
215 if (
fd == -1) logmsg(
fatal,111,FATAL,
"unable read CURVEDNS_PRIVATE_KEY");
218 if (
len != 32) logmsg(
fatal,111,FATAL,
"error reading CURVEDNS_PRIVATE_KEY");
219 logmsg(
fatal,0,INFO,
"DNSCurve support enabled");
230 socket_tryreservein(udp53,65536);
236 if (
len < 0)
continue;
237 if (!
doit())
continue;
238 if (ip6_isv4mapped(
ip))
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 *fatal)
void qlog(const char *, uint16, const char *, const char *, const char *, const char *)
void log_start(const char *, const char *, uint32)
void response_id(const char *)
unsigned int response_len
int response_query(const char *, const char *, const char *)
int respond(char *, char *, char *)
unsigned char curvekey[32]