summaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorElise Lennion <elise.lennion@gmail.com>2017-03-02 15:34:13 -0300
committerPablo Neira Ayuso <pablo@netfilter.org>2017-03-03 10:56:26 +0100
commit059b9bf6fb31b971f79f83a01d9794288ab88a6e (patch)
tree6e26652096b4c01d09827b7d9804091386d3ed30 /src/buffer.c
parent1ef9ba3ecb4323a200015cfb5f91c6eb9972d32e (diff)
src: Use nftnl_buf to export XML/JSON rules
This completes the use of nftnl_buf and its auxiliary functions to export XML/JSON rules. Highly based on work from Shivani Bhardwaj <shivanib134@gmail.com>. Signed-off-by: Elise Lennion <elise.lennion@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index d97d517..f9d5a83 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -171,3 +171,49 @@ int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg,
}
return 0;
}
+
+int nftnl_buf_expr_open(struct nftnl_buf *b, int type)
+{
+ switch (type) {
+ case NFTNL_OUTPUT_XML:
+ return 0;
+ case NFTNL_OUTPUT_JSON:
+ return nftnl_buf_put(b, "\"expr\":[");
+ }
+ return 0;
+}
+
+int nftnl_buf_expr_close(struct nftnl_buf *b, int type)
+{
+ switch (type) {
+ case NFTNL_OUTPUT_XML:
+ return 0;
+ case NFTNL_OUTPUT_JSON:
+ nftnl_buf_done(b);
+ return nftnl_buf_put(b, "]");
+ }
+ return 0;
+}
+
+int nftnl_buf_expr(struct nftnl_buf *b, int type, uint32_t flags,
+ struct nftnl_expr *expr)
+{
+ int ret;
+
+ switch (type) {
+ case NFTNL_OUTPUT_XML:
+ return 0;
+ case NFTNL_OUTPUT_JSON:
+ nftnl_buf_put(b, "{");
+ nftnl_buf_str(b, type, expr->ops->name, TYPE);
+ ret = expr->ops->snprintf(b->buf + b->off, b->len, type, flags,
+ expr);
+ if (ret > 0)
+ nftnl_buf_update(b, ret);
+ else
+ nftnl_buf_done(b);
+
+ return nftnl_buf_put(b, "},");
+ }
+ return 0;
+}