netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH] src: add support for listing the entire ruleset
Date: Sat, 4 Jan 2014 02:30:51 +0100	[thread overview]
Message-ID: <20140104013051.GA5504@localhost> (raw)
In-Reply-To: <20131231184002.25829.99216.stgit@nfdev.cica.es>

Hi Arturo,

On Tue, Dec 31, 2013 at 07:40:02PM +0100, Arturo Borrero Gonzalez wrote:
> This patch add the following operation:
> 
>  :~# nft list ruleset [xml|json]
> 
> With this, you can backup your current ruleset in 3 formats:
>  * nft standar/default
>  * xml
>  * json

This feature is nice, I prefer if we use the following syntax:

nft export <xml|json>

So you can implement:

nft import <xml|json> filename

with the new nft_*_parse_file() function that you posted.

> The XML/JSON output is provided raw by libnftables, thus without format.
> In case of XML, you can give format with the `xmllint' tool from libxml2-tools:
>  :~# nft list ruleset xml | xmllint --format -
> In case of JSON, you can use `json_pp' from perl standar package:
>  :~# nft list ruleset json | json_pp
> 
> Exporting your ruleset gives the possibility of a later import. In default
> nft format, the workflow is as follow:
> 
>  :~# nft list ruleset > ruleset.nft
>  :~# nft -f ruleset.nft
> 
> In XML/JSON format, the import operation is currently under development.
> 
> About this implementation:
> 
> By now, `struct netlink_ctx' can't handle a complete ruleset, so the ruleset
> listing operation is done as follow.
> 
> if XML/JSON:
>  * Obtain the ruleset from the kernel, 4 queries (one per object type),
>    using NFPROTO_UNSPEC. Note that this requires sets to be fetched with
>    NFPROTO_UNSPECT. This is an incoming kernel patch.
>  * Call libnftables's nft_ruleset_fprintf() directly.
> 
> if default nft format:
>  * Obtain tables from kernel, using NFPROTO_UNSPEC (one netlink query).
>  * Iterate these obtained tables calling recursively do_command_list(). This is
>    done by filling a temporal netlink_ctx, and using it as an index.
>  * Proceed normally as when listing one single table (several netlink queries).
> 
> I would prefer to have just one path to print the ruleset, but I can't avoid
> modifying netlink_ctx, and seems a major change to me.

This patch looks relatively small and non-intrusive to the nft
internal structure, I think this is the way to go.

      reply	other threads:[~2014-01-04  1:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-31 18:40 [nft PATCH] src: add support for listing the entire ruleset Arturo Borrero Gonzalez
2014-01-04  1:30 ` Pablo Neira Ayuso [this message]

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=20140104013051.GA5504@localhost \
    --to=pablo@netfilter.org \
    --cc=arturo.borrero.glez@gmail.com \
    --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 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).