Skip to contentSkip to conversation

json: add inner payload support

PATCH New Pablo Neira Ayuso 1 participant 1 message Jun 20, 2023 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 json: add inner payload support

Add support for vxlan, geneve, gre and gretap.

---
 src/json.c                  |  18 +-
 src/parser_json.c           |  50 +++++-
 tests/py/inet/geneve.t.json | 344 ++++++++++++++++++++++++++++++++++++
 tests/py/inet/gre.t.json    | 177 +++++++++++++++++++
 tests/py/inet/gretap.t.json | 195 ++++++++++++++++++++
 tests/py/inet/vxlan.t.json  | 344 ++++++++++++++++++++++++++++++++++++
 6 files changed, 1122 insertions(+), 6 deletions(-)
 create mode 100644 tests/py/inet/geneve.t.json
 create mode 100644 tests/py/inet/gre.t.json
 create mode 100644 tests/py/inet/gretap.t.json
 create mode 100644 tests/py/inet/vxlan.t.json
src/json.c +13 -5
index 305eb6e397fe..21199ca467d6 100644
@@ -573,15 +573,23 @@ json_t *payload_expr_json(const struct expr *expr, struct output_ctx *octx)
 {
 	json_t *root;
 
-	if (payload_is_known(expr))
-		root = json_pack("{s:s, s:s}",
-				 "protocol", expr->payload.desc->name,
-				 "field", expr->payload.tmpl->token);
-	else
+	if (payload_is_known(expr)) {
+		if (expr->payload.inner_desc) {
+			root = json_pack("{s:s, s:s, s:s}",
+					 "tunnel", expr->payload.inner_desc->name,
+					 "protocol", expr->payload.desc->name,
+					 "field", expr->payload.tmpl->token);
+		} else {
+			root = json_pack("{s:s, s:s}",
+					 "protocol", expr->payload.desc->name,
+					 "field", expr->payload.tmpl->token);
+		}
+	} else {
 		root = json_pack("{s:s, s:i, s:i}",
 				 "base", proto_base_tokens[expr->payload.base],
 				 "offset", expr->payload.offset,
 				 "len", expr->len);
+	}
 
 	return json_pack("{s:o}", "payload", root);
 }
src/parser_json.c +49 -1

68 lines not on this page · raw message

tests/py/inet/geneve.t.json new file +344 -0

344 lines not on this page · raw message

tests/py/inet/gre.t.json new file +177 -0

177 lines not on this page · raw message

tests/py/inet/gretap.t.json new file +195 -0

195 lines not on this page · raw message

tests/py/inet/vxlan.t.json new file +344 -0

344 lines not on this page · raw message

Signature · 1 line
2.30.2