From aa56f410581fe3539b3c907c2a2fdec360481d5c Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Sun, 7 Apr 2013 22:30:22 +0000 Subject: expr: basic support for printing nft_data_reg in XML format nft_data_reg now is printed in XML according to what it contains nodes have been also renamed. Arturo Borrero Gonzalez says: ==================== cmp is using has which can also be redundant. But all around the XML printing (including sets, an incoming patch) i've been nesting the data_reg into another XML node, so you could easily see (also the XML parser) the difference between (for example. in set) nft_set_elem->key and nft_set_elem->data. As I needed to nest in nft_set_elem I decided to follow a constant line and do nest all data_reg. ==================== Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/expr/data_reg.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'src/expr/data_reg.c') diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c index 5b14695..78c7d49 100644 --- a/src/expr/data_reg.c +++ b/src/expr/data_reg.c @@ -18,10 +18,105 @@ #include #include #include +#include #include "expr_ops.h" #include "data_reg.h" #include "internal.h" +static int nft_data_reg_value_snprintf_xml(char *buf, size_t size, + union nft_data_reg *reg, + uint32_t flags) +{ + int len = size, offset = 0, ret, i, j; + uint8_t *tmp; + int data_len = reg->len/sizeof(uint32_t); + + ret = snprintf(buf, len, ""); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf+offset, len, "%d", data_len); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + for (i=0; i0x", i); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + tmp = (uint8_t *)®->val[i]; + + for (j=0; j", i); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + } + + ret = snprintf(buf+offset, len, ""); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + return offset; +} + +static int +nft_data_reg_value_snprintf_default(char *buf, size_t size, + union nft_data_reg *reg, uint32_t flags) +{ + int len = size, offset = 0, ret, i; + + for (i=0; ilen/sizeof(uint32_t); i++) { + ret = snprintf(buf+offset, len, "0x%.8x ", reg->val[i]); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + } + + return offset; +} + +int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg, + uint32_t output_format, uint32_t flags, int reg_type) +{ + switch(reg_type) { + case DATA_VALUE: + switch(output_format) { + case NFT_RULE_O_XML: + return nft_data_reg_value_snprintf_xml(buf, size, + reg, flags); + case NFT_RULE_O_DEFAULT: + return nft_data_reg_value_snprintf_default(buf, size, + reg, flags); + default: + break; + } + case DATA_VERDICT: + switch(output_format) { + case NFT_RULE_O_XML: + return snprintf(buf, size, + "" + "%d" + "", reg->verdict); + case NFT_RULE_O_DEFAULT: + return snprintf(buf, size, "verdict=%d", reg->verdict); + default: + break; + } + case DATA_CHAIN: + switch(output_format) { + case NFT_RULE_O_XML: + return snprintf(buf, size, + "" + "%s" + "", reg->chain); + case NFT_RULE_O_DEFAULT: + return snprintf(buf, size, "chain=%s", reg->chain); + default: + break; + } + default: + break; + } + return -1; +} + static int nft_data_parse_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; -- cgit v1.2.3