All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chander Govindarajan <mail@chandergovind.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] nft: update json output ordering to place rules after chains
Date: Mon, 23 May 2022 15:37:11 +0530	[thread overview]
Message-ID: <1dcae0aa-466d-41bf-b050-9684e4b043cc@chandergovind.org> (raw)

Currently the json output of `nft -j list ruleset` interleaves rules
with chains

As reported in this bug,
https://bugzilla.netfilter.org/show_bug.cgi?id=1580
the json cannot be fed into `nft -j -f <file>` since rules may
reference chains that are created later

Instead create rules after all chains are output

Signed-off-by: ChanderG <mail@chandergovind.org>
---
  src/json.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/json.c b/src/json.c
index 0b7224c2..a525fd1b 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1587,7 +1587,7 @@ json_t *optstrip_stmt_json(const struct stmt 
*stmt, struct output_ctx *octx)
  static json_t *table_print_json_full(struct netlink_ctx *ctx,
  				     struct table *table)
  {
-	json_t *root = json_array(), *tmp;
+	json_t *root = json_array(), *rules = json_array(), *tmp;
  	struct flowtable *flowtable;
  	struct chain *chain;
  	struct rule *rule;
@@ -1617,10 +1617,13 @@ static json_t *table_print_json_full(struct 
netlink_ctx *ctx,

  		list_for_each_entry(rule, &chain->rules, list) {
  			tmp = rule_print_json(&ctx->nft->output, rule);
-			json_array_append_new(root, tmp);
+			json_array_append_new(rules, tmp);
  		}
  	}

+	json_array_extend(root, rules);
+	json_decref(rules);
+
  	return root;
  }

-- 
2.27.0

             reply	other threads:[~2022-05-23 10:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 10:07 Chander Govindarajan [this message]
2022-05-24  8:29 ` [PATCH] nft: update json output ordering to place rules after chains Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1dcae0aa-466d-41bf-b050-9684e4b043cc@chandergovind.org \
    --to=mail@chandergovind.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.