summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/rule.c b/src/rule.c
index a85005f..2f92e7d 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -475,22 +475,17 @@ int nft_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_rule *r)
}
EXPORT_SYMBOL(nft_rule_nlmsg_parse);
-static int nft_rule_json_parse(struct nft_rule *r, const char *json)
-{
#ifdef JSON_PARSING
- json_t *root, *node, *array;
- json_error_t error;
+static int nft_jansson_parse_rule(struct nft_rule *r, json_t *tree)
+{
+ json_t *root, *array;
struct nft_rule_expr *e;
const char *str = NULL;
uint64_t uval64;
uint32_t uval32;
int i, family;
- node = nft_jansson_create_root(json, &error);
- if (node == NULL)
- return -1;
-
- root = nft_jansson_get_node(node, "rule");
+ root = nft_jansson_get_node(tree, "rule");
if (root == NULL)
return -1;
@@ -557,11 +552,25 @@ static int nft_rule_json_parse(struct nft_rule *r, const char *json)
nft_rule_add_expr(r, e);
}
- nft_jansson_free_root(node);
+ nft_jansson_free_root(tree);
return 0;
err:
- nft_jansson_free_root(node);
+ nft_jansson_free_root(tree);
return -1;
+}
+#endif
+
+static int nft_rule_json_parse(struct nft_rule *r, const char *json)
+{
+#ifdef JSON_PARSING
+ json_t *tree;
+ json_error_t error;
+
+ tree = nft_jansson_create_root(json, &error);
+ if (tree == NULL)
+ return -1;
+
+ return nft_jansson_parse_rule(r, tree);
#else
errno = EOPNOTSUPP;
return -1;