]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: Order output like nft_cmd_expand()
authorPhil Sutter <phil@nwl.cc>
Thu, 7 Mar 2024 17:40:12 +0000 (18:40 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 19 Mar 2024 17:24:47 +0000 (18:24 +0100)
Print empty chain add commands early in list so following verdict maps
and rules referring to them won't cause spurious errors when loading the
resulting ruleset dump.

Signed-off-by: Phil Sutter <phil@nwl.cc>
src/json.c

index b3e1e4e14a5f92a878d633a00e59aa1d3af8d7d1..bb515164d258797f9ec7c3a9cc1b04be949824e3 100644 (file)
@@ -1704,6 +1704,11 @@ static json_t *table_print_json_full(struct netlink_ctx *ctx,
        tmp = table_print_json(table);
        json_array_append_new(root, tmp);
 
+       /* both maps and rules may refer to chains, list them first */
+       list_for_each_entry(chain, &table->chain_cache.list, cache.list) {
+               tmp = chain_print_json(chain);
+               json_array_append_new(root, tmp);
+       }
        list_for_each_entry(obj, &table->obj_cache.list, cache.list) {
                tmp = obj_print_json(obj);
                json_array_append_new(root, tmp);
@@ -1719,9 +1724,6 @@ static json_t *table_print_json_full(struct netlink_ctx *ctx,
                json_array_append_new(root, tmp);
        }
        list_for_each_entry(chain, &table->chain_cache.list, cache.list) {
-               tmp = chain_print_json(chain);
-               json_array_append_new(root, tmp);
-
                list_for_each_entry(rule, &chain->rules, list) {
                        tmp = rule_print_json(&ctx->nft->output, rule);
                        json_array_append_new(rules, tmp);