All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft 1/2] json: implement json() hook for "symbol_expr_ops"/"variabl_expr_ops"
@ 2023-11-02 11:20 Thomas Haller
  2023-11-02 11:20 ` [PATCH nft 2/2] json: drop handling missing json() hook for "struct expr_ops" Thomas Haller
  2023-11-02 11:24 ` [PATCH nft 1/2] json: implement json() hook for "symbol_expr_ops"/"variabl_expr_ops" Pablo Neira Ayuso
  0 siblings, 2 replies; 15+ messages in thread
From: Thomas Haller @ 2023-11-02 11:20 UTC (permalink / raw)
  To: NetFilter; +Cc: Thomas Haller

The ultimate goal is that all "struct expr_ops" have a "json()" hook
set.

It's also faster, to just create the JSON node, instead of creating a
memory stream, write there using print only to get the sting.

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
The patches 1/2 and 2/2 replaces

  Subject:	[PATCH nft 2/7] json: drop messages "warning: stmt ops chain have no json callback"
  Date:	Tue, 31 Oct 2023 19:53:28 +0100

 include/json.h   |  4 ++++
 src/expression.c |  2 ++
 src/json.c       | 10 ++++++++++
 3 files changed, 16 insertions(+)

diff --git a/include/json.h b/include/json.h
index 39be8928e8ee..134e503afe54 100644
--- a/include/json.h
+++ b/include/json.h
@@ -49,7 +49,9 @@ json_t *rt_expr_json(const struct expr *expr, struct output_ctx *octx);
 json_t *numgen_expr_json(const struct expr *expr, struct output_ctx *octx);
 json_t *hash_expr_json(const struct expr *expr, struct output_ctx *octx);
 json_t *fib_expr_json(const struct expr *expr, struct output_ctx *octx);
+json_t *symbol_expr_json(const struct expr *expr, struct output_ctx *octx);
 json_t *constant_expr_json(const struct expr *expr, struct output_ctx *octx);
+json_t *variable_expr_json(const struct expr *expr, struct output_ctx *octx);
 json_t *socket_expr_json(const struct expr *expr, struct output_ctx *octx);
 json_t *osf_expr_json(const struct expr *expr, struct output_ctx *octx);
 json_t *xfrm_expr_json(const struct expr *expr, struct output_ctx *octx);
@@ -156,7 +158,9 @@ EXPR_PRINT_STUB(set_elem_catchall_expr)
 EXPR_PRINT_STUB(numgen_expr)
 EXPR_PRINT_STUB(hash_expr)
 EXPR_PRINT_STUB(fib_expr)
+EXPR_PRINT_STUB(symbol_expr)
 EXPR_PRINT_STUB(constant_expr)
+EXPR_PRINT_STUB(variable_expr)
 EXPR_PRINT_STUB(socket_expr)
 EXPR_PRINT_STUB(osf_expr)
 EXPR_PRINT_STUB(xfrm_expr)
diff --git a/src/expression.c b/src/expression.c
index a21dfec25722..d6a2e69db572 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -321,6 +321,7 @@ static const struct expr_ops symbol_expr_ops = {
 	.type		= EXPR_SYMBOL,
 	.name		= "symbol",
 	.print		= symbol_expr_print,
+	.json           = symbol_expr_json,
 	.clone		= symbol_expr_clone,
 	.destroy	= symbol_expr_destroy,
 };
@@ -362,6 +363,7 @@ static const struct expr_ops variable_expr_ops = {
 	.type		= EXPR_VARIABLE,
 	.name		= "variable",
 	.print		= variable_expr_print,
+	.json		= variable_expr_json,
 	.clone		= variable_expr_clone,
 	.destroy	= variable_expr_destroy,
 };
diff --git a/src/json.c b/src/json.c
index 068c423addc7..0fd78b763af7 100644
--- a/src/json.c
+++ b/src/json.c
@@ -982,11 +982,21 @@ static json_t *datatype_json(const struct expr *expr, struct output_ctx *octx)
 	    expr->dtype->name);
 }
 
+json_t *symbol_expr_json(const struct expr *expr, struct output_ctx *octx)
+{
+	return json_string(expr->identifier);
+}
+
 json_t *constant_expr_json(const struct expr *expr, struct output_ctx *octx)
 {
 	return datatype_json(expr, octx);
 }
 
+json_t *variable_expr_json(const struct expr *expr, struct output_ctx *octx)
+{
+	return json_string(expr->sym->identifier);
+}
+
 json_t *socket_expr_json(const struct expr *expr, struct output_ctx *octx)
 {
 	return json_pack("{s:{s:s}}", "socket", "key",
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-11-03 15:16 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-02 11:20 [PATCH nft 1/2] json: implement json() hook for "symbol_expr_ops"/"variabl_expr_ops" Thomas Haller
2023-11-02 11:20 ` [PATCH nft 2/2] json: drop handling missing json() hook for "struct expr_ops" Thomas Haller
2023-11-02 11:27   ` Pablo Neira Ayuso
2023-11-02 14:09     ` Thomas Haller
2023-11-02 15:54       ` Pablo Neira Ayuso
2023-11-02 16:17         ` Thomas Haller
2023-11-02 20:51           ` Pablo Neira Ayuso
2023-11-03  8:45             ` Thomas Haller
2023-11-03 11:53               ` Pablo Neira Ayuso
2023-11-03 12:19                 ` Florian Westphal
2023-11-03 15:16                   ` Pablo Neira Ayuso
2023-11-03 12:14               ` Florian Westphal
2023-11-02 17:39   ` Thomas Haller
2023-11-02 19:49     ` Thomas Haller
2023-11-02 11:24 ` [PATCH nft 1/2] json: implement json() hook for "symbol_expr_ops"/"variabl_expr_ops" Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.