From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: arturo.borrero.glez@gmail.com, netfilter-devel@vger.kernel.org
Subject: [PATCH 2/2] gmputil: use MSF/LSF in import/export functions dependant on host byte order
Date: Sat, 12 Apr 2014 11:09:59 +0200 [thread overview]
Message-ID: <1397293799-2600-3-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1397293799-2600-1-git-send-email-kaber@trash.net>
For data of byteorder BYTEORDER_HOST_ENDIAN we need to set the word order
dependant on the host byte order.
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
include/gmputil.h | 9 +++++++++
src/gmputil.c | 7 +++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/gmputil.h b/include/gmputil.h
index 88be697..63eb0ba 100644
--- a/include/gmputil.h
+++ b/include/gmputil.h
@@ -2,12 +2,21 @@
#define NFTABLES_GMPUTIL_H
#include <gmp.h>
+#include <asm/byteorder.h>
enum mpz_word_order {
MPZ_MSWF = 1,
MPZ_LSWF = -1,
};
+#ifdef __LITTLE_ENDIAN_BITFIELD
+#define MPZ_HWO MPZ_LSWF
+#elif defined(__BIG_ENDIAN_BITFIELD)
+#define MPZ_HWO MPZ_MSWF
+#else
+#error "byteorder undefined"
+#endif
+
enum mpz_byte_order {
MPZ_BIG_ENDIAN = 1,
MPZ_HOST_ENDIAN = 0,
diff --git a/src/gmputil.c b/src/gmputil.c
index f34c077..cb46445 100644
--- a/src/gmputil.c
+++ b/src/gmputil.c
@@ -98,20 +98,23 @@ void *mpz_export_data(void *data, const mpz_t op,
enum byteorder byteorder,
unsigned int len)
{
+ enum mpz_word_order order;
enum mpz_byte_order endian;
switch (byteorder) {
case BYTEORDER_BIG_ENDIAN:
default:
+ order = MPZ_MSWF;
endian = MPZ_BIG_ENDIAN;
break;
case BYTEORDER_HOST_ENDIAN:
+ order = MPZ_HWO;
endian = MPZ_HOST_ENDIAN;
break;
}
memset(data, 0, len);
- mpz_export(data, NULL, MPZ_MSWF, len, endian, 0, op);
+ mpz_export(data, NULL, order, len, endian, 0, op);
return data;
}
@@ -129,7 +132,7 @@ void mpz_import_data(mpz_t rop, const void *data,
endian = MPZ_BIG_ENDIAN;
break;
case BYTEORDER_HOST_ENDIAN:
- order = MPZ_LSWF;
+ order = MPZ_HWO;
endian = MPZ_HOST_ENDIAN;
break;
}
--
1.9.0
prev parent reply other threads:[~2014-04-12 9:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-12 9:09 [PATCH 0/2] nftables: fix big endian bugs Patrick McHardy
2014-04-12 9:09 ` [PATCH 1/2] expression: fix constant expression allocation on big endian Patrick McHardy
2014-04-12 9:09 ` Patrick McHardy [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=1397293799-2600-3-git-send-email-kaber@trash.net \
--to=kaber@trash.net \
--cc=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 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).