]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
debug: properly parse debug levels
authorPatrick McHardy <kaber@trash.net>
Tue, 6 Jul 2010 03:57:20 +0000 (05:57 +0200)
committerPatrick McHardy <kaber@trash.net>
Tue, 6 Jul 2010 03:57:20 +0000 (05:57 +0200)
Signed-off-by: Patrick McHardy <kaber@trash.net>
include/nftables.h
src/evaluate.c
src/main.c
src/parser.y

index fd958dce0a3086718df17f58c03907013c0410cf..66bfab300f939dfe500ca2942f1112e9dea52760 100644 (file)
@@ -12,7 +12,10 @@ enum numeric_level {
 };
 
 enum debug_level {
-       DEBUG_NETLINK           = 0x1,
+       DEBUG_SCANNER           = 0x1,
+       DEBUG_PARSER            = 0x2,
+       DEBUG_EVALUATION        = 0x4,
+       DEBUG_NETLINK           = 0x8,
 };
 
 #define INCLUDE_PATHS_MAX      16
index f3723779d13b1537fbad37b8df257d410dc5174f..6330a806d3a6de784f126080642a2c15fbc6bda9 100644 (file)
@@ -23,8 +23,6 @@
 #include <gmputil.h>
 #include <utils.h>
 
-#define TRACE  0
-
 static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr);
 static int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt);
 
@@ -963,10 +961,12 @@ range:
 
 static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
 {
-#if TRACE
-       struct error_record *erec;
-       erec = erec_create(EREC_INFORMATIONAL, &(*expr)->location, "Evaluate");
-       erec_print(stdout, erec); expr_print(*expr); printf("\n\n");
+#ifdef DEBUG
+       if (debug_level & DEBUG_EVALUATION) {
+               struct error_record *erec;
+               erec = erec_create(EREC_INFORMATIONAL, &(*expr)->location, "Evaluate");
+               erec_print(stdout, erec); expr_print(*expr); printf("\n\n");
+       }
 #endif
 
        switch ((*expr)->ops->type) {
@@ -1074,10 +1074,12 @@ static int stmt_evaluate_nat(struct eval_ctx *ctx, struct stmt *stmt)
 
 static int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
 {
-#if TRACE
-       struct error_record *erec;
-       erec = erec_create(EREC_INFORMATIONAL, &stmt->location, "Evaluate");
-       erec_print(stdout, erec); stmt_print(stmt); printf("\n\n");
+#ifdef DEBUG
+       if (debug_level & DEBUG_EVALUATION) {
+               struct error_record *erec;
+               erec = erec_create(EREC_INFORMATIONAL, &stmt->location, "Evaluate");
+               erec_print(stdout, erec); stmt_print(stmt); printf("\n\n");
+       }
 #endif
 
        switch (stmt->ops->type) {
@@ -1241,10 +1243,12 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)
 
 static int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
 {
-#if TRACE
-       struct error_record *erec;
-       erec = erec_create(EREC_INFORMATIONAL, &cmd->location, "Evaluate");
-       erec_print(stdout, erec); printf("\n\n");
+#ifdef DEBUG
+       if (debug_level & DEBUG_EVALUATION) {
+               struct error_record *erec;
+               erec = erec_create(EREC_INFORMATIONAL, &cmd->location, "Evaluate");
+               erec_print(stdout, erec); printf("\n\n");
+       }
 #endif
 
        ctx->cmd = cmd;
index 21606ee7cbdb2b3d59ef364a0ed9de9a4c5faade..8c970b52f165748ec6da5599c31cc8e7891445c6 100644 (file)
@@ -102,12 +102,40 @@ static void show_help(const char *name)
 "                              Internet services, user IDs and group IDs numerically.\n"
 "  -i/--includepath <directory>        Add <directory> to the paths searched for include files.\n"
 #ifdef DEBUG
-"  --debug <level>             Specify debugging level\n"
+"  --debug <level [,level...]> Specify debugging level (scanner, parser, eval, netlink, all)\n"
 #endif
 "\n",
        name);
 }
 
+#ifdef DEBUG
+static const struct {
+       const char              *name;
+       enum debug_level        level;
+} debug_param[] = {
+       {
+               .name           = "scanner",
+               .level          = DEBUG_SCANNER,
+       },
+       {
+               .name           = "parser",
+               .level          = DEBUG_PARSER,
+       },
+       {
+               .name           = "eval",
+               .level          = DEBUG_EVALUATION,
+       },
+       {
+               .name           = "netlink",
+               .level          = DEBUG_NETLINK,
+       },
+       {
+               .name           = "all",
+               .level          = ~0,
+       },
+};
+#endif
+
 static const struct input_descriptor indesc_cmdline = {
        .type   = INDESC_BUFFER,
        .name   = "<cmdline>",
@@ -158,7 +186,31 @@ int main(int argc, char * const *argv)
                        break;
 #ifdef DEBUG
                case OPT_DEBUG:
-                       debug_level |= DEBUG_NETLINK;
+                       for (;;) {
+                               unsigned int i;
+                               char *end;
+
+                               end = strchr(optarg, ',');
+                               if (end)
+                                       *end = '\0';
+
+                               for (i = 0; i < array_size(debug_param); i++) {
+                                       if (strcmp(debug_param[i].name, optarg))
+                                               continue;
+                                       debug_level |= debug_param[i].level;
+                                       break;
+                               }
+
+                               if (i == array_size(debug_param)) {
+                                       fprintf(stderr, "invalid debug parameter `%s'\n",
+                                               optarg);
+                                       exit(NFT_EXIT_FAILURE);
+                               }
+
+                               if (end == NULL)
+                                       break;
+                               optarg = end + 1;
+                       }
                        break;
 #endif
                case OPT_INVALID:
index 7668cbf2cacfa17cc9b6f1a9fea8bb6fae313ce2..f70b505dbdfcc96cca0808fee0ec32b6a94de841 100644 (file)
@@ -101,9 +101,11 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 
 %initial-action {
        location_init(scanner, state, &yylloc);
-#if 0
-       nft_set_debug(1, scanner);
-       yydebug = 1;
+#ifdef DEBUG
+       if (debug_level & DEBUG_SCANNER)
+               nft_set_debug(1, scanner);
+       if (debug_level & DEBUG_PARSER)
+               yydebug = 1;
 #endif
 }