summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/statement.h1
-rw-r--r--src/netlink_delinearize.c2
-rw-r--r--src/netlink_linearize.c1
-rw-r--r--src/parser_bison.y21
-rw-r--r--src/scanner.l1
-rw-r--r--src/statement.c7
6 files changed, 30 insertions, 3 deletions
diff --git a/include/statement.h b/include/statement.h
index 277ff2f4..d317ae36 100644
--- a/include/statement.h
+++ b/include/statement.h
@@ -108,6 +108,7 @@ extern struct stmt *queue_stmt_alloc(const struct location *loc);
struct quota_stmt {
uint64_t bytes;
+ uint64_t used;
uint32_t flags;
};
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index cb0f6ac7..9a16926e 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -777,6 +777,8 @@ static void netlink_parse_quota(struct netlink_parse_ctx *ctx,
stmt = quota_stmt_alloc(loc);
stmt->quota.bytes = nftnl_expr_get_u64(nle, NFTNL_EXPR_QUOTA_BYTES);
+ stmt->quota.used =
+ nftnl_expr_get_u64(nle, NFTNL_EXPR_QUOTA_CONSUMED);
stmt->quota.flags = nftnl_expr_get_u32(nle, NFTNL_EXPR_QUOTA_FLAGS);
ctx->stmt = stmt;
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 0915038f..144068d2 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -734,6 +734,7 @@ netlink_gen_quota_stmt(struct netlink_linearize_ctx *ctx,
nle = alloc_nft_expr("quota");
nftnl_expr_set_u64(nle, NFTNL_EXPR_QUOTA_BYTES, stmt->quota.bytes);
+ nftnl_expr_set_u64(nle, NFTNL_EXPR_QUOTA_CONSUMED, stmt->quota.used);
nftnl_expr_set_u32(nle, NFTNL_EXPR_QUOTA_FLAGS, stmt->quota.flags);
return nle;
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 0f3ad915..aea6e47d 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -378,6 +378,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
%token UNTIL "until"
%token QUOTA "quota"
+%token USED "used"
%token NANOSECOND "nanosecond"
%token MICROSECOND "microsecond"
@@ -427,7 +428,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
%type <string> identifier type_identifier string comment_spec
%destructor { xfree($$); } identifier type_identifier string comment_spec
-%type <val> time_spec
+%type <val> time_spec quota_used
%type <val> type_identifier_list
%type <datatype> data_type
@@ -1636,7 +1637,22 @@ quota_unit : BYTES { $$ = xstrdup("bytes"); }
| STRING { $$ = $1; }
;
-quota_stmt : QUOTA quota_mode NUM quota_unit
+quota_used : /* empty */ { $$ = 0; }
+ | USED NUM quota_unit
+ {
+ struct error_record *erec;
+ uint64_t rate;
+
+ erec = data_unit_parse(&@$, $3, &rate);
+ if (erec != NULL) {
+ erec_queue(erec, state->msgs);
+ YYERROR;
+ }
+ $$ = $2 * rate;
+ }
+ ;
+
+quota_stmt : QUOTA quota_mode NUM quota_unit quota_used
{
struct error_record *erec;
uint64_t rate;
@@ -1648,6 +1664,7 @@ quota_stmt : QUOTA quota_mode NUM quota_unit
}
$$ = quota_stmt_alloc(&@$);
$$->quota.bytes = $3 * rate;
+ $$->quota.used = $5;
$$->quota.flags = $2;
}
;
diff --git a/src/scanner.l b/src/scanner.l
index 625023f5..8aa4b08b 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -312,6 +312,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr})
"over" { return OVER; }
"quota" { return QUOTA; }
+"used" { return USED; }
"nanosecond" { return NANOSECOND; }
"microsecond" { return MICROSECOND; }
diff --git a/src/statement.c b/src/statement.c
index e70eb51e..4d3ca55a 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -352,11 +352,16 @@ static void quota_stmt_print(const struct stmt *stmt)
{
bool inv = stmt->quota.flags & NFT_QUOTA_F_INV;
const char *data_unit;
- uint64_t bytes;
+ uint64_t bytes, used;
data_unit = get_rate(stmt->quota.bytes, &bytes);
printf("quota %s%"PRIu64" %s",
inv ? "over " : "", bytes, data_unit);
+
+ if (stmt->quota.used) {
+ data_unit = get_rate(stmt->quota.used, &used);
+ printf(" used %"PRIu64" %s", used, data_unit);
+ }
}
static const struct stmt_ops quota_stmt_ops = {