]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
treewide: unify ENABLE_* defines
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 19 Oct 2020 14:24:09 +0000 (16:24 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 20 Oct 2020 09:10:13 +0000 (11:10 +0200)
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
daemon/http.h
daemon/io.c
daemon/main.c
daemon/session.c
daemon/session.h
daemon/worker.c
lib/cookies/lru_cache.h
lib/resolve.c
meson.build

index 52894f891c6a424ffa1e0e3af14d8dc96c959728..0023696d569169c8372f0a57fa301c8bb96f6405 100644 (file)
@@ -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 */
index d2c440c4c6949eb5be033da5047d0063a8852f6f..367181efe308a3d40ad623c7313421563a44a2c6 100644 (file)
@@ -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,
index ce4c46df6546a0cbce8f8b420b94771abe1533ae..2552ba107e67f38a4d66bbe865f6c1f34b910b49 100644 (file)
@@ -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");
index 535691d181a05ad6de2e4783f40e2aad8c367e5a..f464effbd2fe57aa5cef21f8fea4a7a2624d4148 100644 (file)
@@ -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");
index 41ae34358a692511601281aea029e3d77a7a196d..9aa53f2148333b4a9f37a1034833cd1df0473b0b 100644 (file)
@@ -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. */
index 3e651ebeee25878a9daa10be65ab0126e7017078..773180e7e162f57f2b60a9e87233026a94fa15a3 100644 (file)
@@ -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. */
index 796e2cdb0fe21ef6fe26a02acfe54a137d61bcb9..6a9f0baf6c2ad126360f49c431cbdad9094bc26b 100644 (file)
@@ -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
 
index 9f97c7795bf9aa26b5d7d2c11d3fc22781a6ee11..3594ee13619ddd07cd6e0ec302a49cecd0bb3375 100644 (file)
@@ -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"
index 9828cbfa5e1fae3061c902a7a7a7b0de360c4654..fb53b61988ab4845dc7227ceb0678baf6003a00c 100644 (file)
 #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 @@ ns_election:
        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) {
index f618f420b6d301835277e11b134ac688145c98ab..8c2f2cc36cf477ddb40b4bb98eb8cabb88b1db2c 100644 (file)
@@ -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',