Netfilter-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH nft] src: fix obj list output when reset command
@ 2020-08-01 21:30 Jose M. Guisado Gomez
  2020-08-03 11:01 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Jose M. Guisado Gomez @ 2020-08-01 21:30 UTC (permalink / raw)
  To: netfilter-devel

This patch enables json output when doing a reset command.

Previously do_list_obj was called at the end of do_command_reset to
list the named object affected by the reset, this function
is for nft output only.

Listing affected objects using do_command_list ensures
output flags will be honored.

Eg: For a ruleset like

table inet x {
	counter user123 {
		packets 12 bytes 1433
	}

	counter user321 {
		packets 0 bytes 0
	}

	quota user123 {
		over 2000 bytes
	}

	quota user124 {
		over 2000 bytes
	}

	set y {
		type ipv4_addr
	}

	...
}

# nft --json reset counters | python -m json.tool
{
    "nftables": [
        {
            "metainfo": {
                "json_schema_version": 1,
                "release_name": "Capital Idea #2",
                "version": "0.9.6"
            }
        },
        {
            "counter": {
                "bytes": 0,
                "family": "inet",
                "handle": 3,
                "name": "user321",
                "packets": 0,
                "table": "x"
            }
        },
        {
            "counter": {
                "bytes": 1433,
                "family": "inet",
                "handle": 2,
                "name": "user123",
                "packets": 12,
                "table": "x"
            }
        }
    ]
}


Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1336

Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
---
 src/rule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/rule.c b/src/rule.c
index fed9e123..6335aa21 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -2682,7 +2682,7 @@ static int do_command_reset(struct netlink_ctx *ctx, struct cmd *cmd)
 	if (ret < 0)
 		return ret;
 
-	return do_list_obj(ctx, cmd, type);
+	return do_command_list(ctx, cmd);
 }
 
 static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH nft] src: fix obj list output when reset command
  2020-08-01 21:30 [PATCH nft] src: fix obj list output when reset command Jose M. Guisado Gomez
@ 2020-08-03 11:01 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2020-08-03 11:01 UTC (permalink / raw)
  To: Jose M. Guisado Gomez; +Cc: netfilter-devel

On Sat, Aug 01, 2020 at 11:30:10PM +0200, Jose M. Guisado Gomez wrote:
> This patch enables json output when doing a reset command.

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01 21:30 [PATCH nft] src: fix obj list output when reset command Jose M. Guisado Gomez
2020-08-03 11:01 ` Pablo Neira Ayuso

Netfilter-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netfilter-devel/0 netfilter-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netfilter-devel netfilter-devel/ https://lore.kernel.org/netfilter-devel \
		netfilter-devel@vger.kernel.org
	public-inbox-index netfilter-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netfilter-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git