From: Jan Hák Date: Mon, 2 May 2022 12:35:46 +0000 (+0200) Subject: kdig: add quic parameter X-Git-Tag: v3.3.dev~92^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c18d8dd59c3700333bcbb524f1a8d00a450d0a3e;p=thirdparty%2Fknot-dns.git kdig: add quic parameter --- diff --git a/Knot.files b/Knot.files index 788f9dc4cb..3a3e918214 100644 --- a/Knot.files +++ b/Knot.files @@ -561,6 +561,8 @@ src/utils/common/netio.c src/utils/common/netio.h src/utils/common/params.c src/utils/common/params.h +src/utils/common/quic.c +src/utils/common/quic.h src/utils/common/resolv.c src/utils/common/resolv.h src/utils/common/sign.c diff --git a/configure.ac b/configure.ac index b659857ce8..0dff5a67cb 100644 --- a/configure.ac +++ b/configure.ac @@ -818,6 +818,7 @@ result_msg_base=" Knot DNS $VERSION Fast zone parser: ${enable_fastparser} Utilities with IDN: ${with_libidn} Utilities with DoH: ${with_libnghttp2} + Utilities with DoQ: ${with_libngtcp2} Utilities with Dnstap: ${enable_dnstap} MaxMind DB support: ${enable_maxminddb} Systemd integration: ${enable_systemd} diff --git a/src/utils/Makefile.inc b/src/utils/Makefile.inc index 1f84beb81b..efd11dd32f 100644 --- a/src/utils/Makefile.inc +++ b/src/utils/Makefile.inc @@ -34,6 +34,8 @@ libknotus_la_SOURCES = \ utils/common/netio.h \ utils/common/params.c \ utils/common/params.h \ + utils/common/quic.c \ + utils/common/quic.h \ utils/common/resolv.c \ utils/common/resolv.h \ utils/common/sign.c \ diff --git a/src/utils/common/params.h b/src/utils/common/params.h index 6c3cc311f0..f39084bc81 100644 --- a/src/utils/common/params.h +++ b/src/utils/common/params.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 CZ.NIC, z.s.p.o. +/* Copyright (C) 2022 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #define DEFAULT_IPV6_NAME "::1" #define DEFAULT_DNS_PORT "53" #define DEFAULT_DNS_HTTPS_PORT "443" +#define DEFAULT_DNS_QUIC_PORT "853" #define DEFAULT_DNS_TLS_PORT "853" #define DEFAULT_UDP_SIZE 512 #define DEFAULT_EDNS_SIZE 4096 diff --git a/src/utils/common/quic.c b/src/utils/common/quic.c new file mode 100644 index 0000000000..0daa01b5c0 --- /dev/null +++ b/src/utils/common/quic.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2022 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include +#include "libknot/errcode.h" +#include "utils/common/quic.h" + +int quic_params_copy(quic_params_t *dst, const quic_params_t *src) +{ + if (dst == NULL || src == NULL) { + return KNOT_EINVAL; + } + + dst->enable = src->enable; + + return KNOT_EOK; +} + +void quic_params_clean(quic_params_t *params) +{ + if (params == NULL) { + return; + } + + params->enable = false; +} diff --git a/src/utils/common/quic.h b/src/utils/common/quic.h new file mode 100644 index 0000000000..56aee39732 --- /dev/null +++ b/src/utils/common/quic.h @@ -0,0 +1,30 @@ +/* Copyright (C) 2022 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#pragma once + +#include + +/*! \brief QUIC parameters. */ +typedef struct { + /*! Use QUIC indicator. */ + bool enable; +} quic_params_t; + +int quic_params_copy(quic_params_t *dst, const quic_params_t *src); + +void quic_params_clean(quic_params_t *params); + diff --git a/src/utils/kdig/kdig_params.c b/src/utils/kdig/kdig_params.c index 2cef812bcb..b134c6d388 100644 --- a/src/utils/kdig/kdig_params.c +++ b/src/utils/kdig/kdig_params.c @@ -84,6 +84,8 @@ static const style_t DEFAULT_STYLE_DIG = { .show_footer = true }; +static int opt_padding(const char *arg, void *query); + static int opt_multiline(const char *arg, void *query) { query_t *q = query; @@ -929,6 +931,36 @@ static int opt_nohttps_get(const char *arg, void *query) #endif } +static int opt_quic(const char *arg, void *query) +{ +#ifdef LIBNGTCP2 + query_t *q = query; + + q->quic.enable = true; + + opt_tls(arg, query); + opt_notcp(arg, query); + opt_padding(arg, query); + + return KNOT_EOK; +#else + return KNOT_ENOTSUP; +#endif //LIBNGTCP2 +} + +static int opt_noquic(const char *arg, void *query) +{ +#ifdef LIBNGTCP2 + query_t *q = query; + + quic_params_clean(&q->quic); + + return opt_notls(arg, query); +#else + return KNOT_ENOTSUP; +#endif //LIBNGTCP2 +} + static int opt_nsid(const char *arg, void *query) { query_t *q = query; @@ -1441,6 +1473,9 @@ static const param_t kdig_opts2[] = { { "https-get", ARG_NONE, opt_https_get }, { "nohttps-get", ARG_NONE, opt_nohttps_get }, + { "quic", ARG_NONE, opt_quic }, + { "noquic", ARG_NONE, opt_noquic }, + { "nsid", ARG_NONE, opt_nsid }, { "nonsid", ARG_NONE, opt_nonsid }, @@ -1546,6 +1581,7 @@ query_t *query_create(const char *owner, const query_t *conf) query->port = strdup(conf->port); tls_params_copy(&query->tls, &conf->tls); https_params_copy(&query->https, &conf->https); + quic_params_copy(&query->quic, &conf->quic); if (conf->tsig_key.name != NULL) { int ret = knot_tsig_key_copy(&query->tsig_key, &conf->tsig_key); @@ -1608,6 +1644,7 @@ void query_free(query_t *query) tls_params_clean(&query->tls); https_params_clean(&query->https); + quic_params_clean(&query->quic); // Cleanup signing key. knot_tsig_key_deinit(&query->tsig_key); @@ -1990,6 +2027,8 @@ static void complete_servers(query_t *query, const query_t *conf) def_port = conf->port; } else if (query->https.enable) { def_port = DEFAULT_DNS_HTTPS_PORT; + } else if (query->quic.enable) { + def_port = DEFAULT_DNS_QUIC_PORT; } else if (query->tls.enable) { def_port = DEFAULT_DNS_TLS_PORT; } else { @@ -2192,6 +2231,9 @@ static void print_help(void) " +[no]https[=URL] Use HTTPS protocol. It's also possible to specify\n" " URL as [authority][/path] where query will be sent.\n" " +[no]https-get Use HTTPS protocol with GET method instead of POST.\n" +#endif +#ifdef LIBNGTCP2 + " +[no]quic Use QUIC protocol.\n" #endif " +[no]nsid Request NSID.\n" " +[no]bufsize=B Set EDNS buffer size.\n" diff --git a/src/utils/kdig/kdig_params.h b/src/utils/kdig/kdig_params.h index fcc28a5a95..d7b816315f 100644 --- a/src/utils/kdig/kdig_params.h +++ b/src/utils/kdig/kdig_params.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 CZ.NIC, z.s.p.o. +/* Copyright (C) 2022 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include "utils/common/params.h" #include "utils/common/exec.h" #include "utils/common/https.h" +#include "utils/common/quic.h" #include "utils/common/sign.h" #include "libknot/libknot.h" #include "contrib/sockaddr.h" @@ -125,6 +126,8 @@ struct query { tls_params_t tls; /*!< HTTPS parameters. */ https_params_t https; + /*!< QUIC parameters. */ + quic_params_t quic; /*!< Transaction signature. */ knot_tsig_key_t tsig_key; /*!< EDNS client subnet. */