From 8e116df6662a79abed5bf6888db47eff2307a2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= <vladimir.cunat@nic.cz> Date: Mon, 19 Oct 2020 16:24:09 +0200 Subject: [PATCH] treewide: unify ENABLE_* defines Two styles were used: (un)defined and 0/1. We switch to 0/1. Advantage: it can be used also like `if (ENABLE_FOO)` (outside preprocessor). Except for ./meson.build it's sed \ -e 's/#ifdef ENABLE_CAP_NG/#if ENABLE_CAP_NG/g' \ -e 's/#ifdef ENABLE_DOH2/#if ENABLE_DOH2/g' \ -e 's/defined(ENABLE_COOKIES)/ENABLE_COOKIES/g' \ -e 's/#ifdef ENABLE_COOKIES/#if ENABLE_COOKIES/g' \ -i $(git grep -l ENABLE_) --- daemon/engine.c | 2 +- daemon/http.h | 4 ++-- daemon/io.c | 10 +++++----- daemon/main.c | 4 ++-- daemon/session.c | 8 ++++---- daemon/session.h | 2 +- daemon/worker.c | 6 +++--- lib/cookies/lru_cache.h | 4 ++-- lib/resolve.c | 16 ++++++++-------- meson.build | 6 +++--- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/daemon/engine.c b/daemon/engine.c index 52894f891..0023696d5 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -36,7 +36,7 @@ #define LRU_REP_SIZE (LRU_RTT_SIZE / 4) /**< NS reputation cache size */ #endif #ifndef LRU_COOKIES_SIZE - #ifdef ENABLE_COOKIES + #if ENABLE_COOKIES #define LRU_COOKIES_SIZE LRU_RTT_SIZE /**< DNS cookies cache size. */ #else #define LRU_COOKIES_SIZE LRU_ASSOC /* simpler than guards everywhere */ diff --git a/daemon/http.h b/daemon/http.h index d2c440c4c..367181efe 100644 --- a/daemon/http.h +++ b/daemon/http.h @@ -11,7 +11,7 @@ #include <uv.h> #include <libknot/packet/pkt.h> -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 #include <nghttp2/nghttp2.h> #endif @@ -38,7 +38,7 @@ struct http_ctx { ssize_t buf_size; }; -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 struct http_ctx* http_new(struct session *session, http_send_callback send_cb); ssize_t http_process_input_data(struct session *session, const uint8_t *buf, ssize_t nread); int http_write(uv_write_t *req, uv_handle_t *handle, knot_pkt_t* pkt, int32_t stream_id, diff --git a/daemon/io.c b/daemon/io.c index ce4c46df6..2552ba107 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -306,7 +306,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) data = session_wirebuf_get_free_start(s); data_len = consumed; } -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 if (session_flags(s)->has_http) { consumed = http_process_input_data(s, data, data_len); if (consumed < 0) { @@ -341,7 +341,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) mp_flush(the_worker->pkt_pool.ctx); } -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 static ssize_t tls_send(const uint8_t *buf, const size_t len, struct session *session) { struct tls_ctx *ctx = session_tls_get_server_ctx(session); @@ -456,7 +456,7 @@ static void _tcp_accept(uv_stream_t *master, int status, bool tls, bool http) session_tls_set_server_ctx(s, ctx); } } -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 if (http) { struct http_ctx *ctx = session_http_get_server_ctx(s); if (!ctx) { @@ -487,7 +487,7 @@ static void tls_accept(uv_stream_t *master, int status) _tcp_accept(master, status, true, false); } -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 static void https_accept(uv_stream_t *master, int status) { _tcp_accept(master, status, true, true); @@ -505,7 +505,7 @@ int io_listen_tcp(uv_loop_t *loop, uv_tcp_t *handle, int fd, int tcp_backlog, bo if (ret) return ret; if (has_tls && has_http) { -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 connection = https_accept; #else kr_log_error("[ io ] kresd was compiled without libnghttp2 support\n"); diff --git a/daemon/main.c b/daemon/main.c index 535691d18..f464effbd 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -28,7 +28,7 @@ #include <sys/resource.h> #include <unistd.h> -#ifdef ENABLE_CAP_NG +#if ENABLE_CAP_NG #include <cap-ng.h> #endif @@ -495,7 +495,7 @@ static int start_listening(struct network *net, flagged_fd_array_t *fds) { /* Drop POSIX 1003.1e capabilities. */ static void drop_capabilities(void) { -#ifdef ENABLE_CAP_NG +#if ENABLE_CAP_NG /* Drop all capabilities when running under non-root user. */ if (geteuid() == 0) { kr_log_verbose("[system] running as root, no capabilities dropped\n"); diff --git a/daemon/session.c b/daemon/session.c index 41ae34358..9aa53f214 100644 --- a/daemon/session.c +++ b/daemon/session.c @@ -36,7 +36,7 @@ struct session { struct tls_ctx *tls_ctx; /**< server side tls-related data. */ struct tls_client_ctx *tls_client_ctx; /**< client side tls-related data. */ -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 struct http_ctx *http_ctx; /**< server side http-related data. */ #endif @@ -89,7 +89,7 @@ void session_clear(struct session *session) queue_deinit(session->waiting); tls_free(session->tls_ctx); tls_client_ctx_free(session->tls_client_ctx); -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 http_free(session->http_ctx); #endif memset(session, 0, sizeof(*session)); @@ -295,7 +295,7 @@ struct tls_common_ctx *session_tls_get_common_ctx(const struct session *session) return tls_ctx; } -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 struct http_ctx *session_http_get_server_ctx(const struct session *session) { return session->http_ctx; @@ -337,7 +337,7 @@ struct session *session_new(uv_handle_t *handle, bool has_tls, bool has_http) wire_buffer_size += TLS_CHUNK_SIZE; session->sflags.has_tls = true; } -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 if (has_http) { /* When decoding large packets, * HTTP/2 frames can be up to 16 KB by default. */ diff --git a/daemon/session.h b/daemon/session.h index 3e651ebee..773180e7e 100644 --- a/daemon/session.h +++ b/daemon/session.h @@ -96,7 +96,7 @@ void session_tls_set_client_ctx(struct session *session, struct tls_client_ctx * * server and client. */ struct tls_common_ctx *session_tls_get_common_ctx(const struct session *session); -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 /** Get pointer to server-side http-related data. */ struct http_ctx *session_http_get_server_ctx(const struct session *session); /** Set pointer to server-side http-related data. */ diff --git a/daemon/worker.c b/daemon/worker.c index 796e2cdb0..6a9f0baf6 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -299,7 +299,7 @@ static struct request_ctx *request_create(struct worker_ctx *worker, req->qsource.flags.tls = session_flags(session)->has_tls; req->qsource.flags.http = session_flags(session)->has_http; req->qsource.stream_id = -1; -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 if (req->qsource.flags.http) { struct http_ctx *http_ctx = session_http_get_server_ctx(session); req->qsource.stream_id = queue_head(http_ctx->streams); @@ -617,7 +617,7 @@ static int qr_task_send(struct qr_task *task, struct session *session, /* Send using given protocol */ assert(!session_flags(session)->closing); if (session_flags(session)->has_http) { -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 uv_write_t *write_req = (uv_write_t *)ioreq; write_req->data = task; ret = http_write(write_req, handle, pkt, ctx->req.qsource.stream_id, &on_write); @@ -1612,7 +1612,7 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt const bool is_outgoing = session_flags(session)->outgoing; struct http_ctx *http_ctx = NULL; -#ifdef ENABLE_DOH2 +#if ENABLE_DOH2 http_ctx = session_http_get_server_ctx(session); #endif diff --git a/lib/cookies/lru_cache.h b/lib/cookies/lru_cache.h index 9f97c7795..3594ee136 100644 --- a/lib/cookies/lru_cache.h +++ b/lib/cookies/lru_cache.h @@ -7,13 +7,13 @@ #include <netinet/in.h> #include <stdint.h> -#if defined(ENABLE_COOKIES) +#if ENABLE_COOKIES #include <libknot/rrtype/opt.h> #include <libknot/rrtype/opt-cookie.h> #else #define KNOT_OPT_COOKIE_CLNT 8 #define KNOT_OPT_COOKIE_SRVR_MAX 32 -#endif /* defined(ENABLE_COOKIES) */ +#endif /* ENABLE_COOKIES */ #include "lib/defines.h" #include "lib/generic/lru.h" diff --git a/lib/resolve.c b/lib/resolve.c index 9828cbfa5..fb53b6198 100644 --- a/lib/resolve.c +++ b/lib/resolve.c @@ -18,13 +18,13 @@ #include "lib/layer/iterate.h" #include "lib/dnssec/ta.h" #include "lib/dnssec.h" -#if defined(ENABLE_COOKIES) +#if ENABLE_COOKIES #include "lib/cookies/control.h" #include "lib/cookies/helper.h" #include "lib/cookies/nonce.h" #else /* Define compatibility macros */ #define KNOT_EDNS_OPTION_COOKIE 10 -#endif /* defined(ENABLE_COOKIES) */ +#endif /* ENABLE_COOKIES */ #define VERBOSE_MSG(qry, ...) QRVERBOSE((qry), "resl", __VA_ARGS__) @@ -424,12 +424,12 @@ static int edns_create(knot_pkt_t *pkt, knot_pkt_t *template, struct kr_request { pkt->opt_rr = knot_rrset_copy(req->ctx->upstream_opt_rr, &pkt->mm); size_t wire_size = knot_edns_wire_size(pkt->opt_rr); -#if defined(ENABLE_COOKIES) +#if ENABLE_COOKIES if (req->ctx->cookie_ctx.clnt.enabled || req->ctx->cookie_ctx.srvr.enabled) { wire_size += KR_COOKIE_OPT_MAX_LEN; } -#endif /* defined(ENABLE_COOKIES) */ +#endif /* ENABLE_COOKIES */ if (req->qsource.flags.tls) { if (req->ctx->tls_padding == -1) /* FIXME: we do not know how to reserve space for the @@ -1508,7 +1508,7 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t return request->state; } -#if defined(ENABLE_COOKIES) +#if ENABLE_COOKIES /** Update DNS cookie data in packet. */ static bool outbound_request_update_cookies(struct kr_request *req, const struct sockaddr *src, @@ -1538,7 +1538,7 @@ static bool outbound_request_update_cookies(struct kr_request *req, return true; } -#endif /* defined(ENABLE_COOKIES) */ +#endif /* ENABLE_COOKIES */ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src, struct sockaddr *dst, int type, knot_pkt_t *packet) @@ -1557,7 +1557,7 @@ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src, } struct kr_query *qry = array_tail(rplan->pending); -#if defined(ENABLE_COOKIES) +#if ENABLE_COOKIES /* Update DNS cookies in request. */ if (type == SOCK_DGRAM) { /* @todo: Add cookies also over TCP? */ /* @@ -1569,7 +1569,7 @@ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src, return kr_error(EINVAL); } } -#endif /* defined(ENABLE_COOKIES) */ +#endif /* ENABLE_COOKIES */ int ret = query_finalize(request, qry, packet); if (ret != 0) { diff --git a/meson.build b/meson.build index f618f420b..8c2f2cc36 100644 --- a/meson.build +++ b/meson.build @@ -168,11 +168,11 @@ conf_data.set_quoted('libzscanner_SONAME', libzscanner.get_pkgconfig_variable('soname')) conf_data.set_quoted('libknot_SONAME', libknot.get_pkgconfig_variable('soname')) -conf_data.set('ENABLE_LIBSYSTEMD', libsystemd.found() ? 1 : 0) +conf_data.set('ENABLE_LIBSYSTEMD', libsystemd.found().to_int()) conf_data.set('NOVERBOSELOG', not verbose_log) conf_data.set('ENABLE_SENDMMSG', sendmmsg.to_int()) -conf_data.set('ENABLE_CAP_NG', capng.found()) -conf_data.set('ENABLE_DOH2', nghttp2.found()) +conf_data.set('ENABLE_CAP_NG', capng.found().to_int()) +conf_data.set('ENABLE_DOH2', nghttp2.found().to_int()) kresconfig = configure_file( output: 'kresconfig.h', -- GitLab