summaryrefslogtreecommitdiffstats
path: root/include/obj.h
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2016-11-27 23:26:56 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2016-12-09 14:50:53 +0100
commit5573d0146c1ae71ac5b3e4ba6a12c00585646a1a (patch)
treed6e4938b3a51d5973b7ac6c1a21f2705f5ad10c1 /include/obj.h
parent85894febe35d223c0478dfac56dcd7366609f981 (diff)
src: support for stateful objects
This patch allows you to add, to delete and to get stateful objects, this support two object types: counter and quota. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/obj.h')
-rw-r--r--include/obj.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/include/obj.h b/include/obj.h
new file mode 100644
index 0000000..edbf023
--- /dev/null
+++ b/include/obj.h
@@ -0,0 +1,55 @@
+#ifndef _OBJ_OPS_H_
+#define _OBJ_OPS_H_
+
+#include <stdint.h>
+#include "internal.h"
+
+struct nlattr;
+struct nlmsghdr;
+struct nftnl_obj;
+
+struct nftnl_obj {
+ struct list_head head;
+ struct obj_ops *ops;
+
+ const char *table;
+ const char *name;
+
+ uint32_t family;
+ uint32_t use;
+
+ uint32_t flags;
+
+ union {
+ struct nftnl_obj_counter {
+ uint64_t pkts;
+ uint64_t bytes;
+ } counter;
+ struct nftnl_obj_quota {
+ uint64_t bytes;
+ uint64_t consumed;
+ uint32_t flags;
+ } quota;
+ } data;
+};
+
+struct obj_ops {
+ const char *name;
+ uint32_t type;
+ size_t alloc_len;
+ int max_attr;
+ int (*set)(struct nftnl_obj *e, uint16_t type, const void *data, uint32_t data_len);
+ const void *(*get)(const struct nftnl_obj *e, uint16_t type, uint32_t *data_len);
+ int (*parse)(struct nftnl_obj *e, struct nlattr *attr);
+ void (*build)(struct nlmsghdr *nlh, const struct nftnl_obj *e);
+ int (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_obj *e);
+ int (*json_parse)(struct nftnl_obj *e, json_t *data,
+ struct nftnl_parse_err *err);
+};
+
+extern struct obj_ops obj_ops_counter;
+extern struct obj_ops obj_ops_quota;
+
+#define nftnl_obj_data(obj) (void *)&obj->data
+
+#endif