summaryrefslogtreecommitdiffstats
path: root/src/expr/lookup.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/lookup.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/lookup.c')
-rw-r--r--src/expr/lookup.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 8e533c4..550c850 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -17,6 +17,7 @@
#include <arpa/inet.h>
#include <libmnl/libmnl.h>
#include <linux/netfilter/nf_tables.h>
+#include <libnftables/rule.h>
#include <libnftables/expr.h>
#include "data_reg.h"
#include "expr_ops.h"
@@ -150,19 +151,48 @@ nft_rule_expr_lookup_parse(struct nft_rule_expr *e, struct nlattr *attr)
}
static int
-nft_rule_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, struct nft_rule_expr *e)
+nft_rule_expr_lookup_snprintf_xml(char *buf, size_t size,
+ struct nft_expr_lookup *l)
+{
+ int len = size, offset = 0, ret;
+
+ ret = snprintf(buf, len, "<set>%s</set><sreg>%u</sreg><dreg>%u</dreg>\n",
+ l->set_name, l->sreg, l->dreg);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+
+ return offset;
+}
+
+static int
+nft_rule_expr_lookup_snprintf_default(char *buf, size_t size,
+ struct nft_expr_lookup *l)
{
- struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
int len = size, offset = 0, ret;
ret = snprintf(buf, len, "set=%s sreg=%u dreg=%u\n",
- lookup->set_name, lookup->sreg, lookup->dreg);
+ l->set_name, l->sreg, l->dreg);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
return offset;
}
+static int
+nft_rule_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
+ uint32_t flags, struct nft_rule_expr *e)
+{
+ struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
+
+ switch(type) {
+ case NFT_RULE_O_XML:
+ return nft_rule_expr_lookup_snprintf_xml(buf, size, lookup);
+ case NFT_RULE_O_DEFAULT:
+ return nft_rule_expr_lookup_snprintf_default(buf, size, lookup);
+ default:
+ break;
+ }
+ return -1;
+}
+
struct expr_ops expr_ops_lookup = {
.name = "lookup",
.alloc_len = sizeof(struct nft_expr_lookup),