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>
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)
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}"
#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)
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,
expr_print(*expr, &octx_debug_dummy);
printf("\n\n");
}
-#endif
switch ((*expr)->ops->type) {
case EXPR_SYMBOL:
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,
erec_print(stdout, erec); stmt_print(stmt, &octx_debug_dummy);
printf("\n\n");
}
-#endif
switch (stmt->ops->type) {
case STMT_COUNTER:
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",
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;
"Evaluate %s", cmd_op_to_name(cmd->op));
erec_print(stdout, erec); printf("\n\n");
}
-#endif
ctx->cmd = cmd;
switch (cmd->op) {
#include <cli.h>
static struct nft_ctx nft;
-#ifdef DEBUG
unsigned int debug_level;
-#endif
enum opt_vals {
OPT_HELP = 'h',
.val = OPT_INCLUDEPATH,
.has_arg = 1,
},
-#ifdef DEBUG
{
.name = "debug",
.val = OPT_DEBUG,
.has_arg = 1,
},
-#endif
{
.name = "handle",
.val = OPT_HANDLE_OUTPUT,
" -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;
.level = ~0,
},
};
-#endif
static const struct input_descriptor indesc_cmdline = {
.type = INDESC_BUFFER,
case OPT_IP2NAME:
nft.output.ip2name++;
break;
-#ifdef DEBUG
case OPT_DEBUG:
for (;;) {
unsigned int i;
optarg = end + 1;
}
break;
-#endif
case OPT_HANDLE_OUTPUT:
nft.output.handle++;
break;
{
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;
.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,
sizeof(struct nfgenmsg));
}
}
-#endif
return sendmsg(mnl_socket_get_fd(nl), &msg, 0);
}
}
}
-#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;
void netlink_dump_rule(const struct nftnl_rule *nlr)
{
-#ifdef DEBUG
char buf[4096];
if (!(debug_level & DEBUG_NETLINK))
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))
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)
void netlink_dump_chain(const struct nftnl_chain *nlc)
{
-#ifdef DEBUG
char buf[4096];
if (!(debug_level & DEBUG_NETLINK))
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,
void netlink_dump_set(const struct nftnl_set *nls)
{
-#ifdef DEBUG
char buf[4096];
if (!(debug_level & DEBUG_NETLINK))
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)
void netlink_dump_obj(struct nftnl_obj *nln)
{
-#ifdef DEBUG
char buf[4096];
if (!(debug_level & DEBUG_NETLINK))
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,
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",
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,
%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 {
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))
pr_debug("\n");
}
pr_debug("\n");
-#endif
}
/**
static bool segtree_debug(void)
{
-#ifdef DEBUG
if (debug_level & DEBUG_SEGTREE)
return true;
-#endif
+
return false;
}