summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÁlvaro Neira Ayuso <alvaroneay@gmail.com>2013-08-09 13:12:46 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-08-09 13:22:49 +0200
commit01918c4846b56d4144e4189f28f3a5ee99c90a6f (patch)
tree39e3a8f2279069109977ea4a31076f0e2d0bc0be
parent0491ee36f8f298ec86eeb7e84fa42f296e91a1aa (diff)
expr: ct: optional output in ct
Display direction and key if available Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/expr/ct.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/expr/ct.c b/src/expr/ct.c
index 99448c6..f86fd4d 100644
--- a/src/expr/ct.c
+++ b/src/expr/ct.c
@@ -226,6 +226,30 @@ err:
}
static int
+nft_expr_ct_snprintf_json(char *buf, size_t size, struct nft_rule_expr *e)
+{
+ int ret, len = size, offset = 0;
+ struct nft_expr_ct *ct = nft_expr_data(e);
+
+ ret = snprintf(buf, size, "\"dreg\" : %u", ct->dreg);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+
+ if (e->flags & (1 << NFT_EXPR_CT_KEY)) {
+ ret = snprintf(buf+offset, size, ", \"key\" : \"%s\"",
+ ctkey2str(ct->key));
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
+
+ if (e->flags & (1 << NFT_EXPR_CT_DIR)) {
+ ret = snprintf(buf+offset, size, ", \"dir\" : %u", ct->dir);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
+
+ return offset;
+
+}
+
+static int
nft_rule_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
@@ -241,10 +265,7 @@ nft_rule_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
"<dir>%u</dir>",
ct->dreg, ctkey2str(ct->key), ct->dir);
case NFT_RULE_O_JSON:
- return snprintf(buf, len, "\"dreg\" : %u, "
- "\"key\" : \"%s\", "
- "\"dir\" : %u",
- ct->dreg, ctkey2str(ct->key), ct->dir);
+ return nft_expr_ct_snprintf_json(buf, len, e);
default:
break;
}