summaryrefslogtreecommitdiffstats
path: root/src/expr/limit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/limit.c')
-rw-r--r--src/expr/limit.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/expr/limit.c b/src/expr/limit.c
index 336bdb0..d65c0a9 100644
--- a/src/expr/limit.c
+++ b/src/expr/limit.c
@@ -118,6 +118,30 @@ nft_rule_expr_limit_parse(struct nft_rule_expr *e, struct nlattr *attr)
return 0;
}
+static int nft_rule_expr_limit_json_parse(struct nft_rule_expr *e, json_t *root)
+{
+#ifdef JSON_PARSING
+ uint64_t uval64;
+
+ if (nft_jansson_value_parse_val(root, "rate", NFT_TYPE_U64,
+ &uval64) != 0)
+ return -1;
+
+ nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_RATE, uval64);
+
+ if (nft_jansson_value_parse_val(root, "depth", NFT_TYPE_U64,
+ &uval64) != 0)
+ return -1;
+
+ nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_DEPTH, uval64);
+
+ return 0;
+#else
+ errno = EOPNOTSUPP;
+ return -1;
+#endif
+}
+
static int nft_rule_expr_limit_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
@@ -176,6 +200,7 @@ struct expr_ops expr_ops_limit = {
.build = nft_rule_expr_limit_build,
.snprintf = nft_rule_expr_limit_snprintf,
.xml_parse = nft_rule_expr_limit_xml_parse,
+ .json_parse = nft_rule_expr_limit_json_parse,
};
static void __init expr_limit_init(void)