netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft] evaluate: display expression, statement and command name on debug
@ 2016-08-31 16:27 Pablo Neira Ayuso
  0 siblings, 0 replies; only message in thread
From: Pablo Neira Ayuso @ 2016-08-31 16:27 UTC (permalink / raw)
  To: netfilter-devel

Extend debugging knob for evaluation to display the command, the
expression and statement names.

 # nft --debug=eval add rule x y ip saddr 1.1.1.1 counter
 <cmdline>:1:1-37: Evaluate add
 add rule x y ip saddr 1.1.1.1 counter
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 <cmdline>:1:14-29: Evaluate expression
 add rule x y ip saddr 1.1.1.1 counter
              ^^^^^^^^^^^^^^^^
 ip saddr $1.1.1.1

 <cmdline>:1:14-29: Evaluate relational
 add rule x y ip saddr 1.1.1.1 counter
              ^^^^^^^^^^^^^^^^
 ip saddr $1.1.1.1

 <cmdline>:1:14-21: Evaluate payload
 add rule x y ip saddr 1.1.1.1 counter
              ^^^^^^^^
 ip saddr

 <cmdline>:1:23-29: Evaluate symbol
 add rule x y ip saddr 1.1.1.1 counter
                       ^^^^^^^

 <cmdline>:1:23-29: Evaluate value
 add rule x y ip saddr 1.1.1.1 counter
                       ^^^^^^^
 1.1.1.1

 <cmdline>:1:31-37: Evaluate counter
 add rule x y ip saddr 1.1.1.1 counter
                               ^^^^^^^
 counter packets 0 bytes 0

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/evaluate.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index 7eb28f2..89e40ca 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1585,7 +1585,8 @@ 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, "Evaluate");
+		erec = erec_create(EREC_INFORMATIONAL, &(*expr)->location,
+				   "Evaluate %s", (*expr)->ops->name);
 		erec_print(stdout, erec); expr_print(*expr); printf("\n\n");
 	}
 #endif
@@ -2430,7 +2431,8 @@ 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, "Evaluate");
+		erec = erec_create(EREC_INFORMATIONAL, &stmt->location,
+				   "Evaluate %s", stmt->ops->name);
 		erec_print(stdout, erec); stmt_print(stmt); printf("\n\n");
 	}
 #endif
@@ -2932,12 +2934,38 @@ static int cmd_evaluate_export(struct eval_ctx *ctx, struct cmd *cmd)
 	return cache_update(cmd->op, ctx->msgs);
 }
 
+#ifdef DEBUG
+static const char *cmd_op_name[] = {
+	[CMD_INVALID]	= "invalid",
+	[CMD_ADD]	= "add",
+	[CMD_REPLACE]	= "replace",
+	[CMD_CREATE]	= "create",
+	[CMD_INSERT]	= "insert",
+	[CMD_DELETE]	= "delete",
+	[CMD_LIST]	= "list",
+	[CMD_FLUSH]	= "flush",
+	[CMD_RENAME]	= "rename",
+	[CMD_EXPORT]	= "export",
+	[CMD_MONITOR]	= "monitor",
+	[CMD_DESCRIBE]	= "describe",
+};
+
+static const char *cmd_op_to_name(enum cmd_ops op)
+{
+	if (op > CMD_DESCRIBE)
+		return "unknown";
+
+	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;
-		erec = erec_create(EREC_INFORMATIONAL, &cmd->location, "Evaluate");
+		erec = erec_create(EREC_INFORMATIONAL, &cmd->location,
+				   "Evaluate %s", cmd_op_to_name(cmd->op));
 		erec_print(stdout, erec); printf("\n\n");
 	}
 #endif
-- 
2.1.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-08-31 16:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-31 16:27 [PATCH nft] evaluate: display expression, statement and command name on debug Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).