From 26e06d838d6471f5233c1da3fee012bf113564a5 Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Fri, 8 Feb 2013 17:51:56 +0100 Subject: src: add XML output support Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/expr/match.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/expr/match.c') diff --git a/src/expr/match.c b/src/expr/match.c index 855d210..0c7427d 100644 --- a/src/expr/match.c +++ b/src/expr/match.c @@ -15,6 +15,8 @@ #include #include /* for memcpy */ #include +#include /* bin to hex*/ +#include /* bin to hex*/ #include @@ -23,6 +25,7 @@ #include #include +#include #include "expr_ops.h" @@ -183,14 +186,47 @@ static int nft_rule_expr_match_parse(struct nft_rule_expr *e, struct nlattr *att return 0; } +static +int nft_rule_exp_match_snprintf_xml(char *buf, size_t len, + struct nft_expr_match *mt) +{ + int ret, size=len; + int i; + int offset = 0; + uint8_t *data = (uint8_t *)mt->data; + + ret = snprintf(buf, len, "\t\t%s %u 0x", + mt->name, mt->rev); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + for (i=0; i < mt->data_len; i++) { + ret = snprintf(buf+offset, len, "%x", data[i] & 0xff); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + } + + ret = snprintf(buf+offset, len, "" ); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + return offset; +} + + static int nft_rule_expr_match_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, struct nft_rule_expr *e) { struct nft_expr_match *match = (struct nft_expr_match *)e->data; - return snprintf(buf, len, "name=%s rev=%u ", - match->name, match->rev); + switch(type) { + case NFT_RULE_O_XML: + return nft_rule_exp_match_snprintf_xml(buf, len, match); + case NFT_RULE_O_DEFAULT: + return snprintf(buf, len, "name=%s rev=%u ", + match->name, match->rev); + default: + break; + } + return -1; } struct expr_ops expr_ops_match = { -- cgit v1.2.3