summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorStuart Henderson <sthen@cvs.openbsd.org>2019-02-08 10:26:34 +0000
committerStuart Henderson <sthen@cvs.openbsd.org>2019-02-08 10:26:34 +0000
commita64bcacf5350b84e7f9a205d6c6771e15acc15fd (patch)
tree0e18bd797fe8eb134a3d5120f1d29695cb70ae8e /usr.sbin
parent885c237bd2d3bafcc5abaababe9e0eb3745a597e (diff)
import unbound 1.9.0, ok florian@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/unbound/testcode/fake_event.c24
-rw-r--r--usr.sbin/unbound/testcode/perf.c10
-rw-r--r--usr.sbin/unbound/testcode/petal.c14
-rw-r--r--usr.sbin/unbound/testcode/replay.c1
-rw-r--r--usr.sbin/unbound/testcode/streamtcp.15
-rw-r--r--usr.sbin/unbound/testcode/streamtcp.c69
-rw-r--r--usr.sbin/unbound/testcode/testbound.c1
-rw-r--r--usr.sbin/unbound/testcode/testpkts.c3
-rw-r--r--usr.sbin/unbound/util/edns.c2
9 files changed, 109 insertions, 20 deletions
diff --git a/usr.sbin/unbound/testcode/fake_event.c b/usr.sbin/unbound/testcode/fake_event.c
index 777ed7355ed..4fb9bc8ed68 100644
--- a/usr.sbin/unbound/testcode/fake_event.c
+++ b/usr.sbin/unbound/testcode/fake_event.c
@@ -385,7 +385,7 @@ answer_callback_from_entry(struct replay_runtime* runtime,
repinfo.addrlen = pend->addrlen;
memcpy(&repinfo.addr, &pend->addr, pend->addrlen);
if(!pend->serviced) {
- if(entry->reply_list->next &&
+ if(entry && entry->reply_list->next &&
pend->tcp_pkt_counter < count_reply_packets(entry)) {
/* go to next packet next time */
pend->tcp_pkt_counter++;
@@ -509,7 +509,7 @@ fake_pending_callback(struct replay_runtime* runtime,
repinfo.addrlen = p->addrlen;
memcpy(&repinfo.addr, &p->addr, p->addrlen);
if(!p->serviced) {
- if(todo->match->reply_list->next && !error &&
+ if(todo->match && todo->match->reply_list->next && !error &&
p->tcp_pkt_counter < count_reply_packets(todo->match)) {
/* go to next packet next time */
p->tcp_pkt_counter++;
@@ -1802,4 +1802,24 @@ int outnet_tcp_connect(int ATTR_UNUSED(s), struct sockaddr_storage* ATTR_UNUSED(
return 0;
}
+int tcp_req_info_add_meshstate(struct tcp_req_info* ATTR_UNUSED(req),
+ struct mesh_area* ATTR_UNUSED(mesh), struct mesh_state* ATTR_UNUSED(m))
+{
+ log_assert(0);
+ return 0;
+}
+
+void
+tcp_req_info_remove_mesh_state(struct tcp_req_info* ATTR_UNUSED(req),
+ struct mesh_state* ATTR_UNUSED(m))
+{
+ log_assert(0);
+}
+
+size_t
+tcp_req_info_get_stream_buffer_size(void)
+{
+ return 0;
+}
+
/*********** End of Dummy routines ***********/
diff --git a/usr.sbin/unbound/testcode/perf.c b/usr.sbin/unbound/testcode/perf.c
index 32a5307edb1..d6d2b05298e 100644
--- a/usr.sbin/unbound/testcode/perf.c
+++ b/usr.sbin/unbound/testcode/perf.c
@@ -513,10 +513,12 @@ qlist_grow_capacity(struct perfinfo* info)
uint8_t** d = (uint8_t**)calloc(sizeof(uint8_t*), newcap);
size_t* l = (size_t*)calloc(sizeof(size_t), newcap);
if(!d || !l) fatal_exit("out of memory");
- memcpy(d, info->qlist_data, sizeof(uint8_t*)*
- info->qlist_capacity);
- memcpy(l, info->qlist_len, sizeof(size_t)*
- info->qlist_capacity);
+ if(info->qlist_data && info->qlist_capacity)
+ memcpy(d, info->qlist_data, sizeof(uint8_t*)*
+ info->qlist_capacity);
+ if(info->qlist_len && info->qlist_capacity)
+ memcpy(l, info->qlist_len, sizeof(size_t)*
+ info->qlist_capacity);
free(info->qlist_data);
free(info->qlist_len);
info->qlist_data = d;
diff --git a/usr.sbin/unbound/testcode/petal.c b/usr.sbin/unbound/testcode/petal.c
index e1f5f43417e..a733017a470 100644
--- a/usr.sbin/unbound/testcode/petal.c
+++ b/usr.sbin/unbound/testcode/petal.c
@@ -323,9 +323,9 @@ file_name_is_safe(char* s)
return 1;
}
-/** adjust host and filename */
+/** adjust host */
static void
-adjust_host_file(char* host, char* file)
+adjust_host(char* host)
{
size_t i, len;
/* remove a port number if present */
@@ -335,6 +335,13 @@ adjust_host_file(char* host, char* file)
len = strlen(host);
for(i=0; i<len; i++)
host[i] = tolower((unsigned char)host[i]);
+}
+
+/** adjust filename */
+static void
+adjust_file(char* file)
+{
+ size_t i, len;
len = strlen(file);
for(i=0; i<len; i++)
file[i] = tolower((unsigned char)file[i]);
@@ -534,7 +541,8 @@ service_ssl(SSL* ssl, struct sockaddr_storage* from, socklen_t falen)
if(!read_http_headers(ssl, file, sizeof(file), host, sizeof(host),
&vs))
return;
- adjust_host_file(host, file);
+ if(host[0] != 0) adjust_host(host);
+ if(file[0] != 0) adjust_file(file);
if(host[0] == 0 || !host_name_is_safe(host))
(void)strlcpy(host, "default", sizeof(host));
if(!file_name_is_safe(file)) {
diff --git a/usr.sbin/unbound/testcode/replay.c b/usr.sbin/unbound/testcode/replay.c
index 93a600425ca..84ce50441b1 100644
--- a/usr.sbin/unbound/testcode/replay.c
+++ b/usr.sbin/unbound/testcode/replay.c
@@ -715,6 +715,7 @@ perform_arith(double x, char op, double y, double* res)
*res = x*y;
break;
default:
+ *res = 0;
return 0;
}
diff --git a/usr.sbin/unbound/testcode/streamtcp.1 b/usr.sbin/unbound/testcode/streamtcp.1
index 526c8e1699d..f02b168d2ac 100644
--- a/usr.sbin/unbound/testcode/streamtcp.1
+++ b/usr.sbin/unbound/testcode/streamtcp.1
@@ -44,6 +44,11 @@ Use UDP instead of TCP. No retries are attempted.
.B \-n
Do not wait for the answer.
.TP
+.B \-a
+Print answers on arrival. This mean queries are sent in sequence without
+waiting for answer but if answers arrive in this time they are printed out.
+After sending queries the program waits and prints the remainder.
+.TP
.B \-s
Use SSL.
.TP
diff --git a/usr.sbin/unbound/testcode/streamtcp.c b/usr.sbin/unbound/testcode/streamtcp.c
index 497e3d2888f..668d6360bb9 100644
--- a/usr.sbin/unbound/testcode/streamtcp.c
+++ b/usr.sbin/unbound/testcode/streamtcp.c
@@ -73,6 +73,7 @@ static void usage(char* argv[])
printf("-f server what ipaddr@portnr to send the queries to\n");
printf("-u use UDP. No retries are attempted.\n");
printf("-n do not wait for an answer.\n");
+ printf("-a print answers as they arrive.\n");
printf("-d secs delay after connection before sending query\n");
printf("-s use ssl\n");
printf("-h this help text\n");
@@ -203,13 +204,22 @@ recv_one(int fd, int udp, SSL* ssl, sldns_buffer* buf)
uint16_t len;
if(!udp) {
if(ssl) {
- if(SSL_read(ssl, (void*)&len, (int)sizeof(len)) <= 0) {
+ int sr = SSL_read(ssl, (void*)&len, (int)sizeof(len));
+ if(sr == 0) {
+ printf("ssl: stream closed\n");
+ exit(1);
+ }
+ if(sr < 0) {
log_crypto_err("could not SSL_read");
exit(1);
}
} else {
- if(recv(fd, (void*)&len, sizeof(len), 0) <
- (ssize_t)sizeof(len)) {
+ ssize_t r = recv(fd, (void*)&len, sizeof(len), 0);
+ if(r == 0) {
+ printf("recv: stream closed\n");
+ exit(1);
+ }
+ if(r < (ssize_t)sizeof(len)) {
#ifndef USE_WINSOCK
perror("read() len failed");
#else
@@ -267,6 +277,37 @@ recv_one(int fd, int udp, SSL* ssl, sldns_buffer* buf)
free(pktstr);
}
+/** see if we can receive any results */
+static void
+print_any_answers(int fd, int udp, SSL* ssl, sldns_buffer* buf,
+ int* num_answers, int wait_all)
+{
+ /* see if the fd can read, if so, print one answer, repeat */
+ int ret;
+ struct timeval tv, *waittv;
+ fd_set rfd;
+ while(*num_answers > 0) {
+ memset(&rfd, 0, sizeof(rfd));
+ memset(&tv, 0, sizeof(tv));
+ FD_ZERO(&rfd);
+ FD_SET(fd, &rfd);
+ if(wait_all) waittv = NULL;
+ else waittv = &tv;
+ ret = select(fd+1, &rfd, NULL, NULL, waittv);
+ if(ret < 0) {
+ if(errno == EINTR || errno == EAGAIN) continue;
+ perror("select() failed");
+ exit(1);
+ }
+ if(ret == 0) {
+ if(wait_all) continue;
+ return;
+ }
+ (*num_answers) -= 1;
+ recv_one(fd, udp, ssl, buf);
+ }
+}
+
static int get_random(void)
{
int r;
@@ -278,12 +319,12 @@ static int get_random(void)
/** send the TCP queries and print answers */
static void
-send_em(const char* svr, int udp, int usessl, int noanswer, int delay,
- int num, char** qs)
+send_em(const char* svr, int udp, int usessl, int noanswer, int onarrival,
+ int delay, int num, char** qs)
{
sldns_buffer* buf = sldns_buffer_new(65553);
int fd = open_svr(svr, udp);
- int i;
+ int i, wait_results = 0;
SSL_CTX* ctx = NULL;
SSL* ssl = NULL;
if(!buf) fatal_exit("out of memory");
@@ -325,9 +366,15 @@ send_em(const char* svr, int udp, int usessl, int noanswer, int delay,
write_q(fd, udp, ssl, buf, (uint16_t)get_random(), qs[i],
qs[i+1], qs[i+2]);
/* print at least one result */
- if(!noanswer)
+ if(onarrival) {
+ wait_results += 1; /* one more answer to fetch */
+ print_any_answers(fd, udp, ssl, buf, &wait_results, 0);
+ } else if(!noanswer) {
recv_one(fd, udp, ssl, buf);
+ }
}
+ if(onarrival)
+ print_any_answers(fd, udp, ssl, buf, &wait_results, 1);
if(usessl) {
SSL_shutdown(ssl);
@@ -368,6 +415,7 @@ int main(int argc, char** argv)
const char* svr = "127.0.0.1";
int udp = 0;
int noanswer = 0;
+ int onarrival = 0;
int usessl = 0;
int delay = 0;
@@ -394,11 +442,14 @@ int main(int argc, char** argv)
if(argc == 1) {
usage(argv);
}
- while( (c=getopt(argc, argv, "f:hnsud:")) != -1) {
+ while( (c=getopt(argc, argv, "af:hnsud:")) != -1) {
switch(c) {
case 'f':
svr = optarg;
break;
+ case 'a':
+ onarrival = 1;
+ break;
case 'n':
noanswer = 1;
break;
@@ -446,7 +497,7 @@ int main(int argc, char** argv)
(void)OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL);
#endif
}
- send_em(svr, udp, usessl, noanswer, delay, argc, argv);
+ send_em(svr, udp, usessl, noanswer, onarrival, delay, argc, argv);
checklock_stop();
#ifdef USE_WINSOCK
WSACleanup();
diff --git a/usr.sbin/unbound/testcode/testbound.c b/usr.sbin/unbound/testcode/testbound.c
index cea74c59354..246bc6735b4 100644
--- a/usr.sbin/unbound/testcode/testbound.c
+++ b/usr.sbin/unbound/testcode/testbound.c
@@ -344,6 +344,7 @@ main(int argc, char* argv[])
/* we do not want the test to depend on the timezone */
(void)putenv("TZ=UTC");
+ memset(pass_argv, 0, sizeof(pass_argv));
log_init(NULL, 0, NULL);
/* determine commandline options for the daemon */
diff --git a/usr.sbin/unbound/testcode/testpkts.c b/usr.sbin/unbound/testcode/testpkts.c
index 1d89c38fc8f..6c90567aa32 100644
--- a/usr.sbin/unbound/testcode/testpkts.c
+++ b/usr.sbin/unbound/testcode/testpkts.c
@@ -513,7 +513,8 @@ add_edns(uint8_t* pktbuf, size_t pktsize, int do_flag, uint8_t *ednsdata,
if(*pktlen + sizeof(edns) + ednslen > pktsize)
error("not enough space for EDNS OPT record");
memmove(pktbuf+*pktlen, edns, sizeof(edns));
- memmove(pktbuf+*pktlen+sizeof(edns), ednsdata, ednslen);
+ if(ednsdata && ednslen)
+ memmove(pktbuf+*pktlen+sizeof(edns), ednsdata, ednslen);
sldns_write_uint16(pktbuf+10, LDNS_ARCOUNT(pktbuf)+1);
*pktlen += (sizeof(edns) + ednslen);
}
diff --git a/usr.sbin/unbound/util/edns.c b/usr.sbin/unbound/util/edns.c
index 2c4e4a1fd27..d19952df094 100644
--- a/usr.sbin/unbound/util/edns.c
+++ b/usr.sbin/unbound/util/edns.c
@@ -40,7 +40,7 @@
*/
#include "config.h"
-
+#include "util/edns.h"
#include "util/config_file.h"
#include "util/netevent.h"
#include "util/regional.h"