Patchwork [libnftables] src: rule: fix compat XML output

login
register
mail settings
Submitter Arturo Borrero
Date April 8, 2013, 8:35 a.m.
Message ID <20130408083502.9509.95918.stgit@nfdev.cica.es>
Download mbox | patch
Permalink /patch/234601/
State RFC
Headers show

Comments

Arturo Borrero - April 8, 2013, 8:35 a.m.
The compat struct was not printed in XML. So, I think give output format is the first step to parse it.
---
 src/rule.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)


--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pablo Neira - April 9, 2013, 7:49 p.m.
Hi Arturo,

On Mon, Apr 08, 2013 at 10:35:02AM +0200, Arturo Borrero wrote:
> The compat struct was not printed in XML. So, I think give output
> format is the first step to parse it.
> ---
>  src/rule.c |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/rule.c b/src/rule.c
> index 57b849d..e419b0a 100644
> --- a/src/rule.c
> +++ b/src/rule.c
> @@ -445,11 +445,18 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r,
>  
>  	ret = snprintf(buf, size,
>  		"<rule family=\"%u\" table=\"%s\" "
> -			"chain=\"%s\" handle=\"%llu\"> ",
> +			"chain=\"%s\" handle=\"%llu\">\n ",
                                                      ^^^

We don't need the space after ">" and the \n and the extra formatting.

As example, check the output of conntrack in XML:

# conntrack -L -o xml
<?xml version="1.0" encoding="utf-8"?>
<conntrack>
<flow type="new"><meta direction="original"><layer3 protonum="2" protoname="ipv4"><src>77.209.70.77</src><dst>150.214.142.14</dst></layer3><layer4 protonum="1" protoname="icmp"></layer4></meta><meta direction="reply"><layer3 protonum="2" protoname="ipv4"><src>150.214.142.14</src><dst>77.209.70.77</dst></layer3><layer4 protonum="1" protoname="icmp"></layer4></meta><meta direction="independent"><timeout>30</timeout><id>830164440</id><unreplied/></meta></flow>
<flow type="update"><meta direction="original"><layer3 protonum="2" protoname="ipv4"><src>77.209.70.77</src><dst>150.214.142.14</dst></layer3><layer4 protonum="1" protoname="icmp"></layer4></meta><meta direction="reply"><layer3 protonum="2" protoname="ipv4"><src>150.214.142.14</src><dst>77.209.70.77</dst></layer3><layer4 protonum="1" protoname="icmp"></layer4></meta><meta direction="independent"><timeout>29</timeout><id>830164440</id></meta></flow>
</conntrack>

Note that every flow is expressed in one single line in XML.

Now do:

# conntrack -L -o xml > /tmp/x.xml

And have a look at some XML visualizer, eg:

$ firefox /tmp/x.xml

Does it clarify?
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Arturo Borrero - April 9, 2013, 8:34 p.m.
2013/4/9 Pablo Neira Ayuso <pablo@netfilter.org>:
>
> Does it clarify?

I agree with you.

If you choose to commit this, I will patch (out) all XML extra
formatting (newlines, tabs...).

--
Arturo Borrero González
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pablo Neira - April 18, 2013, 11:29 p.m.
On Tue, Apr 09, 2013 at 10:34:17PM +0200, Arturo Borrero Gonzalez wrote:
> 2013/4/9 Pablo Neira Ayuso <pablo@netfilter.org>:
> >
> > Does it clarify?
> 
> I agree with you.
> 
> If you choose to commit this, I will patch (out) all XML extra
> formatting (newlines, tabs...).

I have applied this, as you sent already a major follow-up to address
all formatting XML issues.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/src/rule.c b/src/rule.c
index 57b849d..e419b0a 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -445,11 +445,18 @@  static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r,
 
 	ret = snprintf(buf, size,
 		"<rule family=\"%u\" table=\"%s\" "
-			"chain=\"%s\" handle=\"%llu\"> ",
+			"chain=\"%s\" handle=\"%llu\">\n ",
 				r->family, r->table, r->chain,
 				(unsigned long long)r->handle);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
+	ret = snprintf(buf+offset, len, "<rule_flags>%u</rule_flags>"
+					"<compat_flags>%u</compat_flags>"
+					"<compat_proto>%u</compat_proto>",
+					r->rule_flags,
+					r->compat.flags, r->compat.proto);
+	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+
 	list_for_each_entry(expr, &r->expr_list, head) {
 		ret = snprintf(buf+offset, len,
 				"\n\t<expr type=\"%s\">\n", expr->ops->name);