diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2019-02-06 12:31:02 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2019-02-06 12:31:02 +0000 |
| commit | 9c9d011eed674ddd7e4a0a148691887afb9e75cd (patch) | |
| tree | cd45bceeed24e66e5b2838e8589d2c111cf691c6 /testcode | |
| parent | 089d83fbd0b24f957b753d440f188ddadaabf4ff (diff) | |
Diffstat (limited to 'testcode')
| -rw-r--r-- | testcode/checklocks.c | 3 | ||||
| -rw-r--r-- | testcode/fake_event.c | 24 | ||||
| -rw-r--r-- | testcode/perf.c | 10 | ||||
| -rw-r--r-- | testcode/petal.c | 14 | ||||
| -rw-r--r-- | testcode/replay.c | 1 | ||||
| -rw-r--r-- | testcode/streamtcp.1 | 5 | ||||
| -rw-r--r-- | testcode/streamtcp.c | 69 | ||||
| -rw-r--r-- | testcode/testbound.c | 1 | ||||
| -rw-r--r-- | testcode/testpkts.c | 9 | ||||
| -rw-r--r-- | testcode/testpkts.h | 2 | ||||
| -rw-r--r-- | testcode/unitauth.c | 8 | ||||
| -rw-r--r-- | testcode/unitecs.c | 2 |
12 files changed, 127 insertions, 21 deletions
diff --git a/testcode/checklocks.c b/testcode/checklocks.c index 7e6f0bb5db57..1b5ef282b5e4 100644 --- a/testcode/checklocks.c +++ b/testcode/checklocks.c @@ -71,6 +71,9 @@ static pid_t check_lock_pid; /** print all possible debug info on the state of the system */ static void total_debug_info(void); +/** print pretty lock error and exit (decl for NORETURN attribute) */ +static void lock_error(struct checked_lock* lock, const char* func, + const char* file, int line, const char* err) ATTR_NORETURN; /** print pretty lock error and exit */ static void lock_error(struct checked_lock* lock, diff --git a/testcode/fake_event.c b/testcode/fake_event.c index 777ed7355ed7..4fb9bc8ed683 100644 --- a/testcode/fake_event.c +++ b/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/testcode/perf.c b/testcode/perf.c index 32a5307edb15..d6d2b05298e8 100644 --- a/testcode/perf.c +++ b/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/testcode/petal.c b/testcode/petal.c index e1f5f43417e3..a733017a470b 100644 --- a/testcode/petal.c +++ b/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/testcode/replay.c b/testcode/replay.c index 93a600425ca1..84ce50441b1e 100644 --- a/testcode/replay.c +++ b/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/testcode/streamtcp.1 b/testcode/streamtcp.1 index 526c8e1699d4..f02b168d2ac8 100644 --- a/testcode/streamtcp.1 +++ b/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/testcode/streamtcp.c b/testcode/streamtcp.c index 497e3d2888fe..668d6360bb9a 100644 --- a/testcode/streamtcp.c +++ b/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/testcode/testbound.c b/testcode/testbound.c index cea74c593540..246bc6735b45 100644 --- a/testcode/testbound.c +++ b/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/testcode/testpkts.c b/testcode/testpkts.c index 01f23e48ed2e..6c90567aa321 100644 --- a/testcode/testpkts.c +++ b/testcode/testpkts.c @@ -236,6 +236,8 @@ static void adjustline(char* line, struct entry* e, e->copy_query = 1; } else if(str_keyword(&parse, "copy_ednsdata_assume_clientsubnet")) { e->copy_ednsdata_assume_clientsubnet = 1; + } else if(str_keyword(&parse, "increment_ecs_scope")) { + e->increment_ecs_scope = 1; } else if(str_keyword(&parse, "sleep=")) { e->sleeptime = (unsigned int) strtol(parse, (char**)&parse, 10); while(isspace((unsigned char)*parse)) @@ -274,6 +276,7 @@ static struct entry* new_entry(void) e->copy_id = 0; e->copy_query = 0; e->copy_ednsdata_assume_clientsubnet = 0; + e->increment_ecs_scope = 0; e->sleeptime = 0; e->next = NULL; return e; @@ -510,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); } @@ -1593,6 +1597,9 @@ adjust_packet(struct entry* match, uint8_t** answer_pkt, size_t *answer_len, if(walk_qlen >= 15 && walk_plen >= 15) { walk_p[15] = walk_q[14]; } + if(match->increment_ecs_scope) { + walk_p[15]++; + } } if(match->sleeptime > 0) { diff --git a/testcode/testpkts.h b/testcode/testpkts.h index b175cab066ab..6e032fa90a65 100644 --- a/testcode/testpkts.h +++ b/testcode/testpkts.h @@ -208,6 +208,8 @@ struct entry { /** copy ednsdata to reply, assume it is clientsubnet and * adjust scopemask to match sourcemask */ uint8_t copy_ednsdata_assume_clientsubnet; + /** increment the ECS scope copied from the sourcemask by one */ + uint8_t increment_ecs_scope; /** in seconds */ unsigned int sleeptime; diff --git a/testcode/unitauth.c b/testcode/unitauth.c index c162e7ef9648..4b3410c9ef7c 100644 --- a/testcode/unitauth.c +++ b/testcode/unitauth.c @@ -42,6 +42,7 @@ #include "testcode/unitmain.h" #include "util/regional.h" #include "util/net_help.h" +#include "util/config_file.h" #include "util/data/msgreply.h" #include "services/cache/dns.h" #include "sldns/str2wire.h" @@ -522,6 +523,7 @@ addzone(struct auth_zones* az, const char* name, char* fname) struct auth_zone* z; size_t nmlen; uint8_t* nm = sldns_str2wire_dname(name, &nmlen); + struct config_file* cfg; if(!nm) fatal_exit("out of memory"); lock_rw_wrlock(&az->lock); z = auth_zone_create(az, nm, nmlen, LDNS_RR_CLASS_IN); @@ -529,12 +531,16 @@ addzone(struct auth_zones* az, const char* name, char* fname) if(!z) fatal_exit("cannot find zone"); auth_zone_set_zonefile(z, fname); z->for_upstream = 1; + cfg = config_create(); + free(cfg->chrootdir); + cfg->chrootdir = NULL; - if(!auth_zone_read_zonefile(z)) { + if(!auth_zone_read_zonefile(z, cfg)) { fatal_exit("parse failure for auth zone %s", name); } lock_rw_unlock(&z->lock); free(nm); + config_delete(cfg); return z; } diff --git a/testcode/unitecs.c b/testcode/unitecs.c index 097ae9ebba6a..b240bfcc666e 100644 --- a/testcode/unitecs.c +++ b/testcode/unitecs.c @@ -158,7 +158,7 @@ static void consistency_test(void) { addrlen_t l; time_t i; - unsigned int count; + uint32_t count; addrkey_t *k; struct addrtree* t; struct module_env env; |
