From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH libnftnl 7/7] quota: support for consumed bytes
Date: Fri, 9 Dec 2016 14:31:59 +0100 [thread overview]
Message-ID: <1481290319-10156-7-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1481290319-10156-1-git-send-email-pablo@netfilter.org>
This patch extends the quota support to account for consumed bytes.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/libnftnl/expr.h | 1 +
src/expr/quota.c | 26 +++++++++++++++++++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/include/libnftnl/expr.h b/include/libnftnl/expr.h
index ee0784928550..74e986de6b4b 100644
--- a/include/libnftnl/expr.h
+++ b/include/libnftnl/expr.h
@@ -196,6 +196,7 @@ enum {
enum {
NFTNL_EXPR_QUOTA_BYTES = NFTNL_EXPR_BASE,
NFTNL_EXPR_QUOTA_FLAGS,
+ NFTNL_EXPR_QUOTA_CONSUMED,
};
enum {
diff --git a/src/expr/quota.c b/src/expr/quota.c
index 7740b24c45f3..667e6e17c28c 100644
--- a/src/expr/quota.c
+++ b/src/expr/quota.c
@@ -22,6 +22,7 @@
struct nftnl_expr_quota {
uint64_t bytes;
+ uint64_t consumed;
uint32_t flags;
};
@@ -34,6 +35,9 @@ static int nftnl_expr_quota_set(struct nftnl_expr *e, uint16_t type,
case NFTNL_EXPR_QUOTA_BYTES:
quota->bytes = *((uint64_t *)data);
break;
+ case NFTNL_EXPR_QUOTA_CONSUMED:
+ quota->consumed = *((uint64_t *)data);
+ break;
case NFTNL_EXPR_QUOTA_FLAGS:
quota->flags = *((uint32_t *)data);
break;
@@ -52,6 +56,9 @@ static const void *nftnl_expr_quota_get(const struct nftnl_expr *e,
case NFTNL_EXPR_QUOTA_BYTES:
*data_len = sizeof(quota->bytes);
return "a->bytes;
+ case NFTNL_EXPR_QUOTA_CONSUMED:
+ *data_len = sizeof(quota->consumed);
+ return "a->consumed;
case NFTNL_EXPR_QUOTA_FLAGS:
*data_len = sizeof(quota->flags);
return "a->flags;
@@ -69,6 +76,7 @@ static int nftnl_expr_quota_cb(const struct nlattr *attr, void *data)
switch(type) {
case NFTA_QUOTA_BYTES:
+ case NFTA_QUOTA_CONSUMED:
if (mnl_attr_validate(attr, MNL_TYPE_U64) < 0)
abi_breakage();
break;
@@ -89,6 +97,8 @@ nftnl_expr_quota_build(struct nlmsghdr *nlh, const struct nftnl_expr *e)
if (e->flags & (1 << NFTNL_EXPR_QUOTA_BYTES))
mnl_attr_put_u64(nlh, NFTA_QUOTA_BYTES, htobe64(quota->bytes));
+ if (e->flags & (1 << NFTNL_EXPR_QUOTA_CONSUMED))
+ mnl_attr_put_u64(nlh, NFTA_QUOTA_CONSUMED, htobe64(quota->consumed));
if (e->flags & (1 << NFTNL_EXPR_QUOTA_FLAGS))
mnl_attr_put_u32(nlh, NFTA_QUOTA_FLAGS, htonl(quota->flags));
}
@@ -106,6 +116,10 @@ nftnl_expr_quota_parse(struct nftnl_expr *e, struct nlattr *attr)
quota->bytes = be64toh(mnl_attr_get_u64(tb[NFTA_QUOTA_BYTES]));
e->flags |= (1 << NFTNL_EXPR_QUOTA_BYTES);
}
+ if (tb[NFTA_QUOTA_CONSUMED]) {
+ quota->consumed = be64toh(mnl_attr_get_u64(tb[NFTA_QUOTA_CONSUMED]));
+ e->flags |= (1 << NFTNL_EXPR_QUOTA_CONSUMED);
+ }
if (tb[NFTA_QUOTA_FLAGS]) {
quota->flags = ntohl(mnl_attr_get_u32(tb[NFTA_QUOTA_FLAGS]));
e->flags |= (1 << NFTNL_EXPR_QUOTA_FLAGS);
@@ -119,12 +133,15 @@ nftnl_expr_quota_json_parse(struct nftnl_expr *e, json_t *root,
struct nftnl_parse_err *err)
{
#ifdef JSON_PARSING
- uint64_t bytes;
+ uint64_t bytes, consumed;
uint32_t flags;
if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &bytes,
err) == 0)
nftnl_expr_set_u64(e, NFTNL_EXPR_QUOTA_BYTES, bytes);
+ if (nftnl_jansson_parse_val(root, "consumed", NFTNL_TYPE_U64, &consumed,
+ err) == 0)
+ nftnl_expr_set_u64(e, NFTNL_EXPR_QUOTA_CONSUMED, consumed);
if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
err) == 0)
nftnl_expr_set_u32(e, NFTNL_EXPR_QUOTA_FLAGS, flags);
@@ -144,6 +161,8 @@ static int nftnl_expr_quota_export(char *buf, size_t size,
if (e->flags & (1 << NFTNL_EXPR_QUOTA_BYTES))
nftnl_buf_u64(&b, type, quota->bytes, BYTES);
+ if (e->flags & (1 << NFTNL_EXPR_QUOTA_CONSUMED))
+ nftnl_buf_u64(&b, type, quota->consumed, CONSUMED);
if (e->flags & (1 << NFTNL_EXPR_QUOTA_FLAGS))
nftnl_buf_u32(&b, type, quota->flags, FLAGS);
@@ -155,8 +174,9 @@ static int nftnl_expr_quota_snprintf_default(char *buf, size_t len,
{
struct nftnl_expr_quota *quota = nftnl_expr_data(e);
- return snprintf(buf, len, "bytes %"PRIu64" flags %u ",
- quota->bytes, quota->flags);
+ return snprintf(buf, len,
+ "bytes %"PRIu64" consumed %"PRIu64" flags %u ",
+ quota->bytes, quota->consumed, quota->flags);
}
static int nftnl_expr_quota_snprintf(char *buf, size_t len, uint32_t type,
--
2.1.4
prev parent reply other threads:[~2016-12-09 13:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-09 13:31 [PATCH libnftnl 1/7] include: fetch stateful object updates for nf_tables.h cache copy Pablo Neira Ayuso
2016-12-09 13:31 ` [PATCH libnftnl 2/7] src: support for stateful objects Pablo Neira Ayuso
2016-12-09 13:31 ` [PATCH libnftnl 3/7] expr: add stateful object reference expression Pablo Neira Ayuso
2016-12-09 13:31 ` [PATCH libnftnl 4/7] set: add NFTNL_SET_OBJ_TYPE attribute Pablo Neira Ayuso
2016-12-09 13:31 ` [PATCH libnftnl 5/7] set_elem: add NFTNL_SET_ELEM_OBJREF attribute Pablo Neira Ayuso
2016-12-09 13:31 ` [PATCH libnftnl 6/7] expr: objref: add support for stateful object maps Pablo Neira Ayuso
2016-12-09 13:31 ` Pablo Neira Ayuso [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481290319-10156-7-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).