netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Solves Bug 1388 - Combining --terse with --json has no effect
@ 2020-09-11 17:34 Gopal Yadav
  2020-09-14 10:46 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Gopal Yadav @ 2020-09-11 17:34 UTC (permalink / raw)
  To: netfilter-devel

Solves Bug 1388 - Combining --terse with --json has no effect

Signed-off-by: Gopal Yadav <gopunop@gmail.com>
---
 src/json.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/json.c b/src/json.c
index a9f5000f..702cf6eb 100644
--- a/src/json.c
+++ b/src/json.c
@@ -147,7 +147,8 @@ static json_t *set_print_json(struct output_ctx
*octx, const struct set *set)
         list_for_each_entry(i, &set->init->expressions, list)
             json_array_append_new(array, expr_print_json(i, octx));

-        json_object_set_new(root, "elem", array);
+        if (!(octx->flags & NFT_CTX_OUTPUT_TERSE))
+            json_object_set_new(root, "elem", array);
     }

     return json_pack("{s:o}", type, root);
-- 
2.20.1

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

* Re: [PATCH] Solves Bug 1388 - Combining --terse with --json has no effect
  2020-09-11 17:34 [PATCH] Solves Bug 1388 - Combining --terse with --json has no effect Gopal Yadav
@ 2020-09-14 10:46 ` Pablo Neira Ayuso
  2020-09-16 13:37   ` Gopal Yadav
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-09-14 10:46 UTC (permalink / raw)
  To: Gopal Yadav; +Cc: netfilter-devel

Hi Gopal,

On Fri, Sep 11, 2020 at 11:04:57PM +0530, Gopal Yadav wrote:
> Solves Bug 1388 - Combining --terse with --json has no effect
> 
> Signed-off-by: Gopal Yadav <gopunop@gmail.com>
> ---
>  src/json.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/json.c b/src/json.c
> index a9f5000f..702cf6eb 100644
> --- a/src/json.c
> +++ b/src/json.c
> @@ -147,7 +147,8 @@ static json_t *set_print_json(struct output_ctx
> *octx, const struct set *set)
>          list_for_each_entry(i, &set->init->expressions, list)
>              json_array_append_new(array, expr_print_json(i, octx));
> 
> -        json_object_set_new(root, "elem", array);
> +        if (!(octx->flags & NFT_CTX_OUTPUT_TERSE))
> +            json_object_set_new(root, "elem", array);
>      }

I suggest you update your patch and send a v2 using:

        if (!nft_output_terse(octx) && set->init && set->init->size > 0) {
                ...

It would be also good if you can add a test. For instance, have a look at:

        tests/shell/testcases/transactions/0049huge_0

which also adds a shell tests for json. You can just get back the
listing in json and compare it. I suggest you use the
testcases/listing/ folder to store this new test.

Please, also check you MUA, it seems it mangles your attachments.

Thanks.

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

* Re: [PATCH] Solves Bug 1388 - Combining --terse with --json has no effect
  2020-09-14 10:46 ` Pablo Neira Ayuso
@ 2020-09-16 13:37   ` Gopal Yadav
  2020-09-16 14:44     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Gopal Yadav @ 2020-09-16 13:37 UTC (permalink / raw)
  To: Pablo Neira Ayuso, netfilter-devel

On Mon, Sep 14, 2020 at 4:16 PM Pablo Neira Ayuso <pablo@netfilter.org> wrote:

> It would be also good if you can add a test. For instance, have a look at:
>
>         tests/shell/testcases/transactions/0049huge_0
>
> which also adds a shell tests for json. You can just get back the
> listing in json and compare it. I suggest you use the
> testcases/listing/ folder to store this new test.

Do you mean get back the terse json listing with "nft -j -t list
ruleset" and compare it with "nft -j list ruleset" and check if they
are different. And also check if attribute "elem" is present or
something else?

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

* Re: [PATCH] Solves Bug 1388 - Combining --terse with --json has no effect
  2020-09-16 13:37   ` Gopal Yadav
@ 2020-09-16 14:44     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-09-16 14:44 UTC (permalink / raw)
  To: Gopal Yadav; +Cc: netfilter-devel

On Wed, Sep 16, 2020 at 07:07:40PM +0530, Gopal Yadav wrote:
> On Mon, Sep 14, 2020 at 4:16 PM Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> 
> > It would be also good if you can add a test. For instance, have a look at:
> >
> >         tests/shell/testcases/transactions/0049huge_0
> >
> > which also adds a shell tests for json. You can just get back the
> > listing in json and compare it. I suggest you use the
> > testcases/listing/ folder to store this new test.
> 
> Do you mean get back the terse json listing with "nft -j -t list
> ruleset" and compare it with "nft -j list ruleset" and check if they
> are different. And also check if attribute "elem" is present or
> something else?

I think you can add a set with elements, then run "nft -j -t list
ruleset" and check that the elements are not present in the json
output, keep it simple.

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

end of thread, other threads:[~2020-09-16 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 17:34 [PATCH] Solves Bug 1388 - Combining --terse with --json has no effect Gopal Yadav
2020-09-14 10:46 ` Pablo Neira Ayuso
2020-09-16 13:37   ` Gopal Yadav
2020-09-16 14:44     ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).