]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: remove ifdef DEBUG pollution
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 22 Aug 2017 16:19:12 +0000 (18:19 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 23 Aug 2017 21:42:33 +0000 (23:42 +0200)
Get rid of lots of ifdef DEBUG pollution in the code.

The --debug= option is useful to get feedback from users, so it should
be always there. And we really save nothing from keeping this code away
from the control plane with a compile time option. Just running
tests/shell/ before and after this patch, time shows almost no
difference.

So this patch leaves --enable-debug around to add debugging symbols in
your builds, this is left set on by default.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
configure.ac
include/utils.h
src/evaluate.c
src/main.c
src/mnl.c
src/netlink.c
src/parser_bison.y
src/proto.c
src/segtree.c

index bef6c0b631df9b5dc44fcf453440bce36a77512f..2570b03a91ef1f7fb1a884ed0055cefaf98f0e4e 100644 (file)
@@ -23,7 +23,7 @@ AC_DEFINE([_GNU_SOURCE], [], [Enable various GNU extensions])
 AC_DEFINE([_STDC_FORMAT_MACROS], [], [printf-style format macros])
 
 AC_ARG_ENABLE([debug],
-             AS_HELP_STRING([--enable-debug], [Disable debugging]),
+             AS_HELP_STRING([--enable-debug], [Disable debugging symbols]),
              AS_IF([test "x$enable_debug" = "xno"], [with_debug=no], [with_debug=yes]),
              [with_debug=yes])
 AC_SUBST(with_debug)
@@ -155,7 +155,7 @@ AC_OUTPUT
 echo "
 nft configuration:
   cli support:                 ${with_cli}
-  enable debugging:            ${with_debug}
+  enable debugging symbols:    ${with_debug}
   use mini-gmp:                        ${with_mini_gmp}
   enable pdf documentation:    ${enable_pdf_doc}
   libxtables support:          ${with_libxtables}"
index 0605eeed3b06f4ac02b445e1d383295167b0276e..369195240e2431d0000fa34f628f2e220c3dc852 100644 (file)
 
 #define BITS_PER_BYTE  8
 
-#if defined(DEBUG)
 #define pr_debug(fmt, arg...) printf(fmt, ##arg)
-#else
-#define pr_debug(fmt, arg...) ({ if (false) {}; 0; })
-#endif
 
-#if defined(DEBUG) && defined(HAVE_LIBGMP)
 #define pr_gmp_debug(fmt, arg...) gmp_printf(fmt, ##arg)
-#else
-#define pr_gmp_debug(fmt, arg...) ({ if (false) {}; 0; })
-#endif
 
 #define __fmtstring(x, y)      __attribute__((format(printf, x, y)))
 #if 0
 #define __must_check           __attribute__((warn_unused_result))
 #define __noreturn             __attribute__((__noreturn__))
 
-#ifdef DEBUG
 #define BUG(fmt, arg...)       ({ fprintf(stderr, "BUG: " fmt, ##arg); assert(0); })
-#else
-#define BUG(fmt, arg...)       assert(0)
-#endif
 
 #define BUILD_BUG_ON(condition)        ((void)sizeof(char[1 - 2*!!(condition)]))
 #define BUILD_BUG_ON_ZERO(e)   (sizeof(char[1 - 2 * !!(e)]) - 1)
index 3989d5e31f56a013956dbcf954d3e70430505342..e3c8e1dc777b46d7c617930f0735bafddeef81bf 100644 (file)
@@ -1708,7 +1708,6 @@ static int expr_evaluate_meta(struct eval_ctx *ctx, struct expr **exprp)
 
 static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
 {
-#ifdef DEBUG
        if (debug_level & DEBUG_EVALUATION) {
                struct error_record *erec;
                erec = erec_create(EREC_INFORMATIONAL, &(*expr)->location,
@@ -1717,7 +1716,6 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
                expr_print(*expr, &octx_debug_dummy);
                printf("\n\n");
        }
-#endif
 
        switch ((*expr)->ops->type) {
        case EXPR_SYMBOL:
@@ -2691,7 +2689,6 @@ static int stmt_evaluate_objref(struct eval_ctx *ctx, struct stmt *stmt)
 
 int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
 {
-#ifdef DEBUG
        if (debug_level & DEBUG_EVALUATION) {
                struct error_record *erec;
                erec = erec_create(EREC_INFORMATIONAL, &stmt->location,
@@ -2699,7 +2696,6 @@ int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
                erec_print(stdout, erec); stmt_print(stmt, &octx_debug_dummy);
                printf("\n\n");
        }
-#endif
 
        switch (stmt->ops->type) {
        case STMT_COUNTER:
@@ -3341,7 +3337,6 @@ static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
        return cache_update(ctx->nf_sock, ctx->cache, cmd->op, ctx->msgs);
 }
 
-#ifdef DEBUG
 static const char *cmd_op_name[] = {
        [CMD_INVALID]   = "invalid",
        [CMD_ADD]       = "add",
@@ -3364,11 +3359,9 @@ static const char *cmd_op_to_name(enum cmd_ops op)
 
        return cmd_op_name[op];
 }
-#endif
 
 int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
 {
-#ifdef DEBUG
        if (debug_level & DEBUG_EVALUATION) {
                struct error_record *erec;
 
@@ -3376,7 +3369,6 @@ int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
                                   "Evaluate %s", cmd_op_to_name(cmd->op));
                erec_print(stdout, erec); printf("\n\n");
        }
-#endif
 
        ctx->cmd = cmd;
        switch (cmd->op) {
index fc44b186d5f0b8048b79803aa6d025ce98e7790e..4c74bdce282422898015c53efda88096fedae924 100644 (file)
@@ -29,9 +29,7 @@
 #include <cli.h>
 
 static struct nft_ctx nft;
-#ifdef DEBUG
 unsigned int debug_level;
-#endif
 
 enum opt_vals {
        OPT_HELP                = 'h',
@@ -90,13 +88,11 @@ static const struct option options[] = {
                .val            = OPT_INCLUDEPATH,
                .has_arg        = 1,
        },
-#ifdef DEBUG
        {
                .name           = "debug",
                .val            = OPT_DEBUG,
                .has_arg        = 1,
        },
-#endif
        {
                .name           = "handle",
                .val            = OPT_HANDLE_OUTPUT,
@@ -131,14 +127,11 @@ static void show_help(const char *name)
 "  -a, --handle                        Output rule handle.\n"
 "  -e, --echo                  Echo what has been added, inserted or replaced.\n"
 "  -I, --includepath <directory>       Add <directory> to the paths searched for include files. Default is: %s\n"
-#ifdef DEBUG
 "  --debug <level [,level...]> Specify debugging level (scanner, parser, eval, netlink, mnl, proto-ctx, segtree, all)\n"
-#endif
 "\n",
        name, DEFAULT_INCLUDE_PATH);
 }
 
-#ifdef DEBUG
 static const struct {
        const char              *name;
        enum debug_level        level;
@@ -176,7 +169,6 @@ static const struct {
                .level          = ~0,
        },
 };
-#endif
 
 static const struct input_descriptor indesc_cmdline = {
        .type   = INDESC_BUFFER,
@@ -359,7 +351,6 @@ int main(int argc, char * const *argv)
                case OPT_IP2NAME:
                        nft.output.ip2name++;
                        break;
-#ifdef DEBUG
                case OPT_DEBUG:
                        for (;;) {
                                unsigned int i;
@@ -387,7 +378,6 @@ int main(int argc, char * const *argv)
                                optarg = end + 1;
                        }
                        break;
-#endif
                case OPT_HANDLE_OUTPUT:
                        nft.output.handle++;
                        break;
index f5859c989f3c93b7b99af420f050feb39f8bc89e..f57982da1bc5f4cdcb8567101872a021406d2663 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -72,10 +72,8 @@ nft_mnl_talk(struct mnl_socket *nf_sock, const void *data,
 {
        uint32_t portid = mnl_socket_get_portid(nf_sock);
 
-#ifdef DEBUG
        if (debug_level & DEBUG_MNL)
                mnl_nlmsg_fprintf(stdout, data, len, sizeof(struct nfgenmsg));
-#endif
 
        if (mnl_socket_sendto(nf_sock, data, len) < 0)
                return -1;
@@ -223,14 +221,11 @@ static ssize_t mnl_nft_socket_sendmsg(const struct mnl_socket *nl,
                .msg_iov        = iov,
                .msg_iovlen     = iov_len,
        };
-#ifdef DEBUG
        uint32_t i;
-#endif
 
        mnl_set_sndbuffer(nl, batch);
        nftnl_batch_iovec(batch, iov, iov_len);
 
-#ifdef DEBUG
        for (i = 0; i < iov_len; i++) {
                if (debug_level & DEBUG_MNL) {
                        mnl_nlmsg_fprintf(stdout,
@@ -238,7 +233,6 @@ static ssize_t mnl_nft_socket_sendmsg(const struct mnl_socket *nl,
                                          sizeof(struct nfgenmsg));
                }
        }
-#endif
 
        return sendmsg(mnl_socket_get_fd(nl), &msg, 0);
 }
@@ -1072,12 +1066,10 @@ int mnl_nft_event_listener(struct mnl_socket *nf_sock,
                        }
                }
 
-#ifdef DEBUG
                if (debug_level & DEBUG_MNL) {
                        mnl_nlmsg_fprintf(stdout, buf, sizeof(buf),
                                          sizeof(struct nfgenmsg));
                }
-#endif /* DEBUG */
                ret = mnl_cb_run(buf, ret, 0, 0, cb, cb_data);
                if (ret <= 0)
                        break;
index f6eb08fd8d4189b4fe7b04c1f538a01ac0da74df..7730b724d4ac23f9341041471d7d2e798d9408e6 100644 (file)
@@ -504,7 +504,6 @@ int netlink_del_rule_batch(struct netlink_ctx *ctx, const struct handle *h,
 
 void netlink_dump_rule(const struct nftnl_rule *nlr)
 {
-#ifdef DEBUG
        char buf[4096];
 
        if (!(debug_level & DEBUG_NETLINK))
@@ -512,12 +511,10 @@ void netlink_dump_rule(const struct nftnl_rule *nlr)
 
        nftnl_rule_snprintf(buf, sizeof(buf), nlr, 0, 0);
        fprintf(stdout, "%s\n", buf);
-#endif
 }
 
 void netlink_dump_expr(const struct nftnl_expr *nle)
 {
-#ifdef DEBUG
        char buf[4096];
 
        if (!(debug_level & DEBUG_NETLINK))
@@ -525,7 +522,6 @@ void netlink_dump_expr(const struct nftnl_expr *nle)
 
        nftnl_expr_snprintf(buf, sizeof(buf), nle, 0, 0);
        fprintf(stdout, "%s\n", buf);
-#endif
 }
 
 static int list_rule_cb(struct nftnl_rule *nlr, void *arg)
@@ -579,7 +575,6 @@ static int netlink_flush_rules(struct netlink_ctx *ctx, const struct handle *h,
 
 void netlink_dump_chain(const struct nftnl_chain *nlc)
 {
-#ifdef DEBUG
        char buf[4096];
 
        if (!(debug_level & DEBUG_NETLINK))
@@ -587,7 +582,6 @@ void netlink_dump_chain(const struct nftnl_chain *nlc)
 
        nftnl_chain_snprintf(buf, sizeof(buf), nlc, 0, 0);
        fprintf(stdout, "%s\n", buf);
-#endif
 }
 
 static int netlink_add_chain_compat(struct netlink_ctx *ctx,
@@ -1036,7 +1030,6 @@ static const struct datatype *dtype_map_from_kernel(enum nft_data_types type)
 
 void netlink_dump_set(const struct nftnl_set *nls)
 {
-#ifdef DEBUG
        char buf[4096];
 
        if (!(debug_level & DEBUG_NETLINK))
@@ -1044,7 +1037,6 @@ void netlink_dump_set(const struct nftnl_set *nls)
 
        nftnl_set_snprintf(buf, sizeof(buf), nls, 0, 0);
        fprintf(stdout, "%s\n", buf);
-#endif
 }
 
 static int set_parse_udata_cb(const struct nftnl_udata *attr, void *data)
@@ -1661,7 +1653,6 @@ out:
 
 void netlink_dump_obj(struct nftnl_obj *nln)
 {
-#ifdef DEBUG
        char buf[4096];
 
        if (!(debug_level & DEBUG_NETLINK))
@@ -1669,7 +1660,6 @@ void netlink_dump_obj(struct nftnl_obj *nln)
 
        nftnl_obj_snprintf(buf, sizeof(buf), nln, 0, 0);
        fprintf(stdout, "%s\n", buf);
-#endif
 }
 
 int netlink_add_obj(struct netlink_ctx *ctx, const struct handle *h,
@@ -2854,7 +2844,6 @@ static int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
        return MNL_CB_OK;
 }
 
-#ifdef DEBUG
 /* only those which could be useful listening to events */
 static const char *const nftnl_msg_types[NFT_MSG_MAX] = {
        [NFT_MSG_NEWTABLE]      = "NFT_MSG_NEWTABLE",
@@ -2880,16 +2869,13 @@ static const char *nftnl_msgtype2str(uint16_t type)
 
        return nftnl_msg_types[type];
 }
-#endif /* DEBUG */
 
 static void netlink_events_debug(uint16_t type)
 {
-#ifdef DEBUG
        if (!(debug_level & DEBUG_NETLINK))
                return;
 
        printf("netlink event: %s\n", nftnl_msgtype2str(type));
-#endif /* DEBUG */
 }
 
 static int netlink_events_newgen_cb(const struct nlmsghdr *nlh, int type,
index a187d0981ae3f159d9093a0f48068b30d5c3c49c..c2fd67de1e3b8a1e5599644e1434ac6dd270aa57 100644 (file)
@@ -118,12 +118,10 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 
 %initial-action {
        location_init(scanner, state, &yylloc);
-#ifdef DEBUG
        if (debug_level & DEBUG_SCANNER)
                nft_set_debug(1, scanner);
        if (debug_level & DEBUG_PARSER)
                yydebug = 1;
-#endif
 }
 
 %union {
index 7ac0ee03191ac29b5d3ef36c63817f4fbeaf1b18..045f2d811969fbf9c696f9c60c0081df0446eae7 100644 (file)
@@ -140,7 +140,6 @@ const struct hook_proto_desc hook_proto_desc[] = {
 
 static void proto_ctx_debug(const struct proto_ctx *ctx, enum proto_bases base)
 {
-#ifdef DEBUG
        unsigned int i;
 
        if (!(debug_level & DEBUG_PROTO_CTX))
@@ -159,7 +158,6 @@ static void proto_ctx_debug(const struct proto_ctx *ctx, enum proto_bases base)
                pr_debug("\n");
        }
        pr_debug("\n");
-#endif
 }
 
 /**
index 34a001613eabac2ef57ebb5793bea689e44b661c..8623e862cf7797d513e98b7f4aeac24d5c7dc8cd 100644 (file)
@@ -163,10 +163,9 @@ static void __ei_insert(struct seg_tree *tree, struct elementary_interval *new)
 
 static bool segtree_debug(void)
 {
-#ifdef DEBUG
        if (debug_level & DEBUG_SEGTREE)
                return true;
-#endif
+
        return false;
 }