struct quota_stmt {
uint64_t bytes;
+ uint64_t used;
uint32_t flags;
};
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;
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;
%token UNTIL "until"
%token QUOTA "quota"
+%token USED "used"
%token NANOSECOND "nanosecond"
%token MICROSECOND "microsecond"
%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
| 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;
}
$$ = quota_stmt_alloc(&@$);
$$->quota.bytes = $3 * rate;
+ $$->quota.used = $5;
$$->quota.flags = $2;
}
;
"over" { return OVER; }
"quota" { return QUOTA; }
+"used" { return USED; }
"nanosecond" { return NANOSECOND; }
"microsecond" { return MICROSECOND; }
{
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 = {