summaryrefslogtreecommitdiffstats
path: root/src/expr/match.c
diff options
context:
space:
mode:
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>2013-02-08 17:51:56 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2013-02-08 19:12:55 +0100
commit26e06d838d6471f5233c1da3fee012bf113564a5 (patch)
tree0482737475d6dd151cd74a4e94bd82cff9278232 /src/expr/match.c
parent1cef3296c64244736a000ab0d146d05ca1ac4b8b (diff)
src: add XML output support
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expr/match.c')
-rw-r--r--src/expr/match.c40
1 files changed, 38 insertions, 2 deletions
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 <stdint.h>
#include <string.h> /* for memcpy */
#include <arpa/inet.h>
+#include <stdlib.h> /* bin to hex*/
+#include <math.h> /* bin to hex*/
#include <libmnl/libmnl.h>
@@ -23,6 +25,7 @@
#include <linux/netfilter/x_tables.h>
#include <libnftables/expr.h>
+#include <libnftables/rule.h>
#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<name>%s</name> <rev>%u</rev> <info>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, "</info>" );
+ 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 = {