From 01918c4846b56d4144e4189f28f3a5ee99c90a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Neira=20Ayuso?= Date: Fri, 9 Aug 2013 13:12:46 +0200 Subject: expr: ct: optional output in ct Display direction and key if available Signed-off-by: Alvaro Neira Ayuso Ayuso Signed-off-by: Pablo Neira Ayuso --- src/expr/ct.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src') 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 @@ -225,6 +225,30 @@ err: #endif } +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, "%u", 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; } -- cgit v1.2.3