diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2011-12-28 20:16:46 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2011-12-29 15:40:36 +0100 |
commit | 3388d7df304f26617c4487418c05734ae4fce5b8 (patch) | |
tree | c4fe8bb3cd31a8d85a908485e0b79e1817fefdad /include/libnetfilter_acct/libnetfilter_acct.h | |
parent | a69ac90ec039509ef6ec2684bda156ed6d41fc83 (diff) |
src: major API redesign
This patch reworks the initial API. Now it provides functions to:
- allocate/release accounting objects.
- set/unset/get attributes of accounting objects.
- build one netlink message from one accounting object.
- parse one netlink message to one accounting object.
- print one accounting object into a buffer.
Binary layout of nfacct objects are opaque. This is good for
extensibility without breaking backward compatibility.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/libnetfilter_acct/libnetfilter_acct.h')
-rw-r--r-- | include/libnetfilter_acct/libnetfilter_acct.h | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/include/libnetfilter_acct/libnetfilter_acct.h b/include/libnetfilter_acct/libnetfilter_acct.h index f5b0040..d877407 100644 --- a/include/libnetfilter_acct/libnetfilter_acct.h +++ b/include/libnetfilter_acct/libnetfilter_acct.h @@ -4,16 +4,34 @@ #include <sys/types.h> #include <linux/netfilter/nfnetlink_acct.h> -struct nfacct { - char name[NFACCT_NAME_MAX]; - uint64_t pkts; - uint64_t bytes; +struct nfacct; + +enum nfacct_attr_type { + NFACCT_ATTR_NAME = 0, + NFACCT_ATTR_PKTS, + NFACCT_ATTR_BYTES, }; -struct nlmsghdr *nfacct_add(char *buf, struct nfacct *nfacct); -struct nlmsghdr *nfacct_list(char *buf, bool ctrzero); -int nfacct_list_cb(const struct nlmsghdr *nlh, void *data); -struct nlmsghdr *nfacct_flush(char *buf); -struct nlmsghdr *nfacct_delete(char *buf, const char *filter_name); +struct nfacct *nfacct_alloc(void); +void nfacct_free(struct nfacct *nfacct); + +void nfacct_attr_set(struct nfacct *nfacct, enum nfacct_attr_type type, const void *data); +void nfacct_attr_set_str(struct nfacct *nfacct, enum nfacct_attr_type type, const char *name); +void nfacct_attr_set_u64(struct nfacct *nfacct, enum nfacct_attr_type type, uint64_t value); +void nfacct_attr_unset(struct nfacct *nfacct, enum nfacct_attr_type type); + +const void *nfacct_attr_get(struct nfacct *nfacct, enum nfacct_attr_type type); +const char *nfacct_attr_get_str(struct nfacct *nfacct, enum nfacct_attr_type type); +uint64_t nfacct_attr_get_u64(struct nfacct *nfacct, enum nfacct_attr_type type); + +struct nlmsghdr; + +struct nlmsghdr *nfacct_nlmsg_build_hdr(char *buf, uint8_t cmd, uint16_t flags, uint32_t seq); +void nfacct_nlmsg_build_payload(struct nlmsghdr *nlh, struct nfacct *nfacct); +int nfacct_nlmsg_parse_payload(const struct nlmsghdr *nlh, struct nfacct *nfacct); + +#define NFACCT_SNPRINTF_F_FULL (1 << 0) + +int nfacct_snprintf(char *buf, size_t size, struct nfacct *nfacct, unsigned int flags); #endif |