diff options
Diffstat (limited to '')
-rw-r--r-- | src/dnsperf.c | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/src/dnsperf.c b/src/dnsperf.c index c3466ee..0f312ce 100644 --- a/src/dnsperf.c +++ b/src/dnsperf.c @@ -52,7 +52,8 @@ #define DEFAULT_SERVER_NAME "127.0.0.1" #define DEFAULT_SERVER_PORT 53 #define DEFAULT_SERVER_DOT_PORT 853 -#define DEFAULT_SERVER_PORTS "udp/tcp 53 or DoT 853" +#define DEFAULT_SERVER_DOH_PORT 443 +#define DEFAULT_SERVER_PORTS "udp/tcp 53, DoT 853 or DoH 443" #define DEFAULT_LOCAL_PORT 0 #define DEFAULT_MAX_OUTSTANDING 100 #define DEFAULT_TIMEOUT 5 @@ -407,6 +408,8 @@ setup(int argc, char** argv, config_t* config) const char* edns_option = NULL; const char* tsigkey = NULL; const char* mode = 0; + const char* doh_uri = DEFAULT_DOH_URI; + const char* doh_method = DEFAULT_DOH_METHOD; memset(config, 0, sizeof(*config)); config->argc = argc; @@ -422,7 +425,7 @@ setup(int argc, char** argv, config_t* config) perf_opt_add('f', perf_opt_string, "family", "address family of DNS transport, inet or inet6", "any", &family); - perf_opt_add('m', perf_opt_string, "mode", "set transport mode: udp, tcp or dot", "udp", &mode); + perf_opt_add('m', perf_opt_string, "mode", "set transport mode: udp, tcp, dot or doh", "udp", &mode); perf_opt_add('s', perf_opt_string, "server_addr", "the server to query", DEFAULT_SERVER_NAME, &server_name); perf_opt_add('p', perf_opt_port, "port", @@ -480,6 +483,11 @@ setup(int argc, char** argv, config_t* config) perf_opt_add('v', perf_opt_boolean, NULL, "verbose: report each query and additional information to stdout", NULL, &config->verbose); + perf_long_opt_add("doh-uri", perf_opt_string, "doh_uri", + "the URI to use for DNS-over-HTTPS", DEFAULT_DOH_URI, &doh_uri); + perf_long_opt_add("doh-method", perf_opt_string, "doh_method", + "the HTTP method to use for DNS-over-HTTPS: GET or POST", DEFAULT_DOH_METHOD, &doh_method); + bool log_stdout = false; perf_opt_add('W', perf_opt_boolean, NULL, "log warnings and errors to stdout instead of stderr", NULL, &log_stdout); @@ -493,9 +501,27 @@ setup(int argc, char** argv, config_t* config) config->mode = perf_net_parsemode(mode); if (!server_port) { - server_port = config->mode == sock_dot ? DEFAULT_SERVER_DOT_PORT : DEFAULT_SERVER_PORT; + switch (config->mode) { + case sock_doh: + server_port = DEFAULT_SERVER_DOH_PORT; + break; + case sock_dot: + server_port = DEFAULT_SERVER_DOT_PORT; + break; + default: + server_port = DEFAULT_SERVER_PORT; + break; + } } + if (doh_uri) { + perf_net_doh_parse_uri(doh_uri); + } + if (doh_method) { + perf_net_doh_parse_method(doh_method); + } + perf_net_doh_set_max_concurrent_streams(config->max_outstanding); + if (family != NULL) config->family = perf_net_parsefamily(family); perf_net_parseserver(config->family, server_name, server_port, @@ -1181,13 +1207,11 @@ threadinfo_init(threadinfo_t* tinfo, const config_t* config, tinfo->socks[i] = perf_net_opensocket(config->mode, &config->server_addr, &config->local_addr, socket_offset++, - config->bufsize); + config->bufsize, + tinfo, perf__net_sent, perf__net_event); if (!tinfo->socks[i]) { perf_log_fatal("perf_net_opensocket(): no socket returned, out of memory?"); } - tinfo->socks[i]->data = tinfo; - tinfo->socks[i]->sent = perf__net_sent; - tinfo->socks[i]->event = perf__net_event; } tinfo->current_sock = 0; @@ -1204,14 +1228,16 @@ threadinfo_stop(threadinfo_t* tinfo) } static void -threadinfo_cleanup(threadinfo_t* tinfo, times_t* times) +threadinfo_cleanup(config_t* config, threadinfo_t* tinfo, times_t* times) { unsigned int i; if (interrupted) cancel_queries(tinfo); - for (i = 0; i < tinfo->nsocks; i++) + for (i = 0; i < tinfo->nsocks; i++) { + perf_net_stats_compile(config->mode, tinfo->socks[i]); perf_net_close(tinfo->socks[i]); + } if (tinfo->last_recv > times->end_time) times->end_time = tinfo->last_recv; } @@ -1246,6 +1272,7 @@ int main(int argc, char** argv) switch (config.mode) { case sock_tcp: case sock_dot: + case sock_doh: // block SIGPIPE for TCP/DOT mode, if connection is closed it will generate a signal perf_os_blocksignal(SIGPIPE, true); break; @@ -1296,13 +1323,16 @@ int main(int argc, char** argv) if (config.stats_interval > 0) PERF_JOIN(stats_thread.sender, NULL); + perf_net_stats_init(config.mode); + for (i = 0; i < config.threads; i++) - threadinfo_cleanup(&threads[i], ×); + threadinfo_cleanup(&config, &threads[i], ×); print_final_status(&config); sum_stats(&config, &total_stats); print_statistics(&config, ×, &total_stats); + perf_net_stats_print(config.mode); cleanup(&config); #if OPENSSL_VERSION_NUMBER < 0x10100000L |