summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2014-11-09 19:26:48 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2014-11-10 18:42:37 +0100
commit5a2a1e0447bc9dc3defe6dca75e6a54312bbb045 (patch)
tree0b6d6fc52096aef745f8598588fd64826d584315 /include
parent88e823f8dcb24b5201f2fe4f4d5ec5d277bd24b2 (diff)
src: consolidate XML/JSON exportation
Add new buffer class to consolidate the existing code to export objects in XML/JSON and use it. We save ~700 LOC with this change. The rule and set objects are not yet consolidated. It seems this would require some specific glue code per representation type since lists are arranged differently. This also consolidates the tag names, so we make sure the same are used from XML and JSON by placing them in include/buffer.h. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am3
-rw-r--r--include/buffer.h80
2 files changed, 82 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 5976bbd..102d5ab 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,3 +1,4 @@
SUBDIRS = libnftnl linux
-noinst_HEADERS = linux_list.h
+noinst_HEADERS = linux_list.h \
+ buffer.h
diff --git a/include/buffer.h b/include/buffer.h
new file mode 100644
index 0000000..2b497f2
--- /dev/null
+++ b/include/buffer.h
@@ -0,0 +1,80 @@
+#ifndef _NFT_BUFFER_H_
+#define _NFT_BUFFER_H_
+
+#include <stdint.h>
+#include <stdbool.h>
+
+struct nft_buf {
+ char *buf;
+ size_t size;
+ size_t len;
+ uint32_t off;
+ bool fail;
+};
+
+#define NFT_BUF_INIT(__b, __buf, __len) \
+ struct nft_buf __b = { \
+ .buf = __buf, \
+ .len = __len, \
+ };
+
+int nft_buf_update(struct nft_buf *b, int ret);
+int nft_buf_done(struct nft_buf *b);
+
+union nft_data_reg;
+
+int nft_buf_open(struct nft_buf *b, int type, const char *tag);
+int nft_buf_close(struct nft_buf *b, int type, const char *tag);
+
+int nft_buf_u32(struct nft_buf *b, int type, uint32_t value, const char *tag);
+int nft_buf_s32(struct nft_buf *b, int type, uint32_t value, const char *tag);
+int nft_buf_u64(struct nft_buf *b, int type, uint64_t value, const char *tag);
+int nft_buf_str(struct nft_buf *b, int type, const char *str, const char *tag);
+int nft_buf_reg(struct nft_buf *b, int type, union nft_data_reg *reg,
+ int reg_type, const char *tag);
+
+#define BASE "base"
+#define BYTES "bytes"
+#define CHAIN "chain"
+#define CODE "code"
+#define DATA "data"
+#define DIR "dir"
+#define DREG "dreg"
+#define EXTHDR_TYPE "exthdr_type"
+#define FAMILY "family"
+#define FLAGS "flags"
+#define GROUP "group"
+#define HANDLE "handle"
+#define HOOKNUM "hooknum"
+#define KEY "key"
+#define LEN "len"
+#define LEVEL "level"
+#define MASK "mask"
+#define NAT_TYPE "nat_type"
+#define NAME "name"
+#define NUM "num"
+#define OFFSET "offset"
+#define OP "op"
+#define PACKETS "packets"
+#define PKTS "pkts"
+#define POLICY "policy"
+#define PREFIX "prefix"
+#define PRIO "prio"
+#define QTHRESH "qthreshold"
+#define RATE "rate"
+#define SET "set"
+#define SIZE "size"
+#define SNAPLEN "snaplen"
+#define SREG_ADDR_MAX "sreg_addr_max"
+#define SREG_ADDR_MIN "sreg_addr_min"
+#define SREG_PROTO_MAX "sreg_proto_max"
+#define SREG_PROTO_MIN "sreg_proto_min"
+#define SREG "sreg"
+#define TABLE "table"
+#define TOTAL "total"
+#define TYPE "type"
+#define UNIT "unit"
+#define USE "use"
+#define XOR "xor"
+
+#endif