From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org
Subject: [libnftables PATCH 14/21] data_reg: xml: fix bytes movements
Date: Wed, 26 Jun 2013 13:37:13 +0200 [thread overview]
Message-ID: <20130626113713.23511.47779.stgit@nfdev.cica.es> (raw)
In-Reply-To: <20130626113509.23511.14359.stgit@nfdev.cica.es>
Fix wrong arithmetics when printing and parsing data registers in XML:
Previous to this patch, a uin32_t containing the number 2864434397
(0xaabbccdd) will be printed this way under some circumstances:
<data>0xddccbbaa</data>
Now, the data is ordered, the MSB position is controlled and snprintf prints:
<data>0xaabbccdd</data>
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
src/expr/data_reg.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index b8b8d66..c123d88 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -15,6 +15,7 @@
#include <limits.h>
#include <arpa/inet.h>
#include <errno.h>
+#include <netinet/in.h>
#include <libmnl/libmnl.h>
#include <linux/netfilter.h>
@@ -205,7 +206,6 @@ static int nft_data_reg_value_xml_parse(union nft_data_reg *reg, char *xml)
reg->val[i] = utmp;
}
-
mxmlDelete(tree);
return 0;
}
@@ -258,6 +258,7 @@ int nft_data_reg_value_snprintf_xml(char *buf, size_t size,
union nft_data_reg *reg, uint32_t flags)
{
int len = size, offset = 0, ret, i, j;
+ uint32_t be;
uint8_t *tmp;
int data_len = reg->len/sizeof(uint32_t);
@@ -271,9 +272,10 @@ int nft_data_reg_value_snprintf_xml(char *buf, size_t size,
ret = snprintf(buf+offset, len, "<data%d>0x", i);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- tmp = (uint8_t *)®->val[i];
+ be = htonl(reg->val[i]);
+ tmp = (uint8_t *)&be;
- for (j=0; j<sizeof(int); j++) {
+ for (j = 0; j < sizeof(uint32_t); j++) {
ret = snprintf(buf+offset, len, "%.02x", tmp[j]);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
next prev parent reply other threads:[~2013-06-26 11:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-26 11:36 [libnftables PATCH 00/21] Small fixes for XML Arturo Borrero Gonzalez
2013-06-26 11:36 ` [libnftables PATCH 01/21] chain: add hooknum2str Arturo Borrero Gonzalez
2013-06-26 11:36 ` [libnftables PATCH 02/21] src: xml: convert family values to string Arturo Borrero Gonzalez
2013-06-26 11:36 ` [libnftables PATCH 03/21] rule: xml: conditional compat info Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 04/21] bitwise: xml: mask and xor use same number of data registers Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 05/21] expr: xml: validate registers < NFT_REG_MAX Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 06/21] nat: xml: change nat types string to dnat/snat Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 07/21] nat: xml: change IP range node names Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 08/21] byteorder: xml: op as string Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 09/21] ct: xml: add extra dir check Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 10/21] ct: xml: use key's name string instead of numbers Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 11/21] exthdr: xml: fix mandatory elements Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 12/21] chain: xml: use string for policy Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 13/21] data_reg: xml: len node shows byte length Arturo Borrero Gonzalez
2013-06-26 11:37 ` Arturo Borrero Gonzalez [this message]
2013-06-26 11:37 ` [libnftables PATCH 15/21] target&match: xml: don't print rev number Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 16/21] payload: xml: use string for base attribute Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 17/21] exthdr: xml: use string for type node Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 18/21] meta: xml: use string to represent key attribute Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 19/21] nat: snprintf: fix buffer offset Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 20/21] nat: xml: rename node type to nat_type Arturo Borrero Gonzalez
2013-06-26 11:37 ` [libnftables PATCH 21/21] exthdr: xml: rename type node to exthdr_type Arturo Borrero Gonzalez
2013-06-27 17:58 ` [libnftables PATCH 00/21] Small fixes for XML 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=20130626113713.23511.47779.stgit@nfdev.cica.es \
--to=arturo.borrero.glez@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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.